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
28 #include "EditorFilepathBar.h"
33 static char THIS_FILE[] = __FILE__;
37 BEGIN_MESSAGE_MAP(CEditorFilePathBar, CDialogBar)
38 ON_NOTIFY_EX (TTN_NEEDTEXT, 0, OnToolTipNotify)
45 CEditorFilePathBar::CEditorFilePathBar()
46 : m_pFont(nullptr), m_nPanes(2)
53 CEditorFilePathBar::~CEditorFilePathBar()
58 * @brief Create the window.
59 * This function subclasses the edit controls.
60 * @param [in] pParentWnd Parent window for edit controls.
61 * @return TRUE if succeeded, FALSE otherwise.
63 BOOL CEditorFilePathBar::Create(CWnd* pParentWnd)
65 if (! CDialogBar::Create(pParentWnd, CEditorFilePathBar::IDD,
66 CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, CEditorFilePathBar::IDD))
69 // subclass the two custom edit boxes
70 for (int pane = 0; pane < countof(m_Edit); pane++)
71 m_Edit[pane].SubClassEdit(IDC_STATIC_TITLE_PANE0 + pane, this);
76 void CEditorFilePathBar::SetPaneCount(int nPanes)
82 * @brief Set look of headerbars similar to other window.
84 * @param [in] pWnd Pointer to window we want to imitate
85 * @return TRUE if parent must recompute layout
87 BOOL CEditorFilePathBar::LookLikeThisWnd(const CWnd * pWnd)
89 // Update font. Note that we must delete previous font
90 // before creating a new one.
91 CFont * pFont = pWnd->GetFont();
94 m_pFont.reset(new CFont);
98 if (pFont->GetLogFont(&lfFont))
100 m_pFont->CreateFontIndirect(&lfFont);
101 for (int pane = 0; pane < m_nPanes; pane++)
103 m_Edit[pane].SetFont(m_pFont.get());
104 m_Edit[pane].SetMargins(4, 4);
110 // Set same dimensions (than window we imitate)
112 pWnd->GetWindowRect(rectNew);
114 GetWindowRect(rectCurrent);
115 if (rectNew != rectCurrent)
117 SetWindowPos(NULL,0,0,rectNew.Width(), rectNew.Height(),
118 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
125 * @brief Resize both controls to an equal size.
127 void CEditorFilePathBar::Resize()
132 WINDOWPLACEMENT infoBar;
133 GetWindowPlacement(&infoBar);
136 for (int pane = 0; pane < m_nPanes; pane++)
137 widths[pane] = (infoBar.rcNormalPosition.right / m_nPanes) - 6;
142 * This function resizes both controls to given size. The width is usually
143 * same as the splitter view width.
144 * @param [in] leftWidth Left-side control width.
145 * @param [in] rightWidth Right-side control width.
147 void CEditorFilePathBar::Resize(int widths[])
152 // resize left filename
156 for (int pane = 0; pane < m_nPanes; pane++)
159 m_Edit[pane].GetClientRect(&rcOld);
161 rc.right = x + widths[pane] + 4;
162 x += widths[pane] + 7;
163 if (rcOld.Width() != rc.Width())
165 m_Edit[pane].MoveWindow(&rc);
166 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 = (TCHAR*) pItem->GetUpdatedTipText(&tempDC, maxWidth);
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, LPCTSTR lpszString)
227 ASSERT (pane >= 0 && pane < countof(m_Edit));
229 // Check for NULL since window may be closing..
233 m_Edit[pane].SetOriginalText(lpszString);
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);