1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /////////////////////////////////////////////////////////////////////////////
24 * @brief Implementation file for CEditorFilepathBar class
26 // ID line follows -- this is updated by SVN
27 // $Id: EditorFilepathBar.cpp 5401 2008-05-30 12:09:27Z kimmov $
30 #include "EditorFilepathBar.h"
35 static char THIS_FILE[] = __FILE__;
39 BEGIN_MESSAGE_MAP(CEditorFilePathBar, CDialogBar)
40 ON_NOTIFY_EX (TTN_NEEDTEXT, 0, OnToolTipNotify)
47 CEditorFilePathBar::CEditorFilePathBar()
48 : m_pFont(NULL), m_nPanes(2)
55 CEditorFilePathBar::~CEditorFilePathBar()
60 * @brief Create the window.
61 * This function subclasses the edit controls.
62 * @param [in] pParentWnd Parent window for edit controls.
63 * @return TRUE if succeeded, FALSE otherwise.
65 BOOL CEditorFilePathBar::Create(CWnd* pParentWnd)
67 if (! CDialogBar::Create(pParentWnd, CEditorFilePathBar::IDD,
68 CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, CEditorFilePathBar::IDD))
71 // subclass the two custom edit boxes
72 for (int pane = 0; pane < countof(m_Edit); pane++)
73 m_Edit[pane].SubClassEdit(IDC_STATIC_TITLE_PANE0 + pane, this);
78 void CEditorFilePathBar::SetPaneCount(int nPanes)
84 * @brief Set look of headerbars similar to other window.
86 * @param [in] pWnd Pointer to window we want to imitate
87 * @return TRUE if parent must recompute layout
89 BOOL CEditorFilePathBar::LookLikeThisWnd(const CWnd * pWnd)
91 // Update font. Note that we must delete previous font
92 // before creating a new one.
93 CFont * pFont = pWnd->GetFont();
96 m_pFont.reset(new CFont);
100 if (pFont->GetLogFont(&lfFont))
102 m_pFont->CreateFontIndirect(&lfFont);
103 for (int pane = 0; pane < m_nPanes; pane++)
104 m_Edit[pane].SetFont(m_pFont.get());
109 // Set same dimensions (than window we imitate)
111 pWnd->GetWindowRect(rectNew);
113 GetWindowRect(rectCurrent);
114 if (rectNew != rectCurrent)
116 SetWindowPos(NULL,0,0,rectNew.Width(), rectNew.Height(),
117 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
124 * @brief Resize both controls to an equal size.
126 void CEditorFilePathBar::Resize()
131 WINDOWPLACEMENT infoBar;
132 GetWindowPlacement(&infoBar);
136 for (int pane = 0; pane < m_nPanes; pane++)
138 int width = infoBar.rcNormalPosition.right / m_nPanes;
139 rc.left = pane * width;
140 rc.right = rc.left + width;
141 m_Edit[pane].MoveWindow(&rc);
142 m_Edit[pane].RefreshDisplayText();
147 * This function resizes both controls to given size. The width is usually
148 * same as the splitter view width.
149 * @param [in] leftWidth Left-side control width.
150 * @param [in] rightWidth Right-side control width.
152 void CEditorFilePathBar::Resize(int widths[])
157 // resize left filename
161 for (int pane = 0; pane < m_nPanes; pane++)
164 rc.right = x + widths[pane] + 4;
165 x += widths[pane] + 7;
166 m_Edit[pane].MoveWindow(&rc);
167 m_Edit[pane].RefreshDisplayText();
172 * @brief Called when tooltip is about to be shown.
173 * In this function we set the tooltip text shown.
175 BOOL CEditorFilePathBar::OnToolTipNotify(UINT id, NMHDR * pTTTStruct, LRESULT * pResult)
180 TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pTTTStruct;
181 if (pTTT->uFlags & TTF_IDISHWND)
183 // idFrom is actually the HWND of the CEdit
184 int nID = ::GetDlgCtrlID((HWND)pTTTStruct->idFrom);
185 if(nID == IDC_STATIC_TITLE_PANE0 || nID == IDC_STATIC_TITLE_PANE1 || nID == IDC_STATIC_TITLE_PANE2)
187 // compute max width : 97% of application width or 80% or full screen width
190 int maxWidth = (int)(rect.Width() * .97);
192 SystemParametersInfo(SPI_GETWORKAREA, 0, rectScreen, 0);
193 if (rectScreen.Width() * .8 > maxWidth)
194 maxWidth = (int)(rectScreen.Width() * .8);
196 // use the tooltip font
197 HANDLE hFont = (HANDLE) ::SendMessage(pTTTStruct->hwndFrom, WM_GETFONT, 0, 0);
198 CClientDC tempDC(this);
199 HANDLE hOldFont = ::SelectObject(tempDC.GetSafeHdc(),hFont);
201 // fill in the returned structure
202 CFilepathEdit * pItem = static_cast<CFilepathEdit*>(GetDlgItem(nID));
203 pTTT->lpszText = const_cast<TCHAR *>(pItem->GetUpdatedTipText(&tempDC, maxWidth).c_str());
207 ::SelectObject(tempDC.GetSafeHdc(),hOldFont);
209 // we must set TTM_SETMAXTIPWIDTH to use \n in tooltips
210 // just to do the first time, but how to access the tooltip during init ?
211 ::SendMessage(pTTTStruct->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 5000);
220 * @brief Set the path for one side
222 * @param [in] pane Index (0-based) of pane to update.
223 * @param [in] lpszString New text for pane.
225 void CEditorFilePathBar::SetText(int pane, const String& sString)
227 ASSERT (pane >= 0 && pane < countof(m_Edit));
229 // Check for NULL since window may be closing..
233 m_Edit[pane].SetOriginalText(sString);
237 * @brief Set the active status for one status (change the appearance)
239 * @param [in] pane Index (0-based) of pane to update.
240 * @param [in] bActive If TRUE activates pane, FALSE deactivates.
242 void CEditorFilePathBar::SetActive(int pane, bool bActive)
244 ASSERT (pane >= 0 && pane < countof(m_Edit));
246 // Check for NULL since window may be closing..
250 m_Edit[pane].SetActive(bActive);