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 /////////////////////////////////////////////////////////////////////////////
22 * @file EditorFilepathBar.cpp
24 * @brief Implementation file for CEditorFilepathBar class
28 #include "EditorFilepathBar.h"
35 BEGIN_MESSAGE_MAP(CEditorFilePathBar, CDialogBar)
36 ON_NOTIFY_EX (TTN_NEEDTEXT, 0, OnToolTipNotify)
43 CEditorFilePathBar::CEditorFilePathBar()
44 : m_pFont(nullptr), m_nPanes(2)
51 CEditorFilePathBar::~CEditorFilePathBar()
56 * @brief Create the window.
57 * This function subclasses the edit controls.
58 * @param [in] pParentWnd Parent window for edit controls.
59 * @return TRUE if succeeded, FALSE otherwise.
61 BOOL CEditorFilePathBar::Create(CWnd* pParentWnd)
63 if (! CDialogBar::Create(pParentWnd, CEditorFilePathBar::IDD,
64 CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, CEditorFilePathBar::IDD))
67 // subclass the two custom edit boxes
68 for (int pane = 0; pane < countof(m_Edit); pane++)
69 m_Edit[pane].SubClassEdit(IDC_STATIC_TITLE_PANE0 + pane, this);
74 CSize CEditorFilePathBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
78 CFont *pOldFont = pdc->SelectObject(m_pFont.get());
79 pdc->GetTextMetrics(&tm);
80 pdc->SelectObject(pOldFont);
82 return CSize(SHRT_MAX, tm.tmHeight + 6);
85 void CEditorFilePathBar::SetPaneCount(int nPanes)
91 * @brief Set look of headerbars similar to other window.
93 * @param [in] pWnd Pointer to window we want to imitate
94 * @return TRUE if parent must recompute layout
96 BOOL CEditorFilePathBar::LookLikeThisWnd(const CWnd * pWnd)
98 // Update font. Note that we must delete previous font
99 // before creating a new one.
100 CFont * pFont = pWnd->GetFont();
103 m_pFont.reset(new CFont);
106 LOGFONT lfFont = {0};
107 if (pFont->GetLogFont(&lfFont))
109 m_pFont->CreateFontIndirect(&lfFont);
110 for (int pane = 0; pane < m_nPanes; pane++)
112 m_Edit[pane].SetFont(m_pFont.get());
113 m_Edit[pane].SetMargins(4, 4);
119 // Set same dimensions (than window we imitate)
121 pWnd->GetWindowRect(rectNew);
123 GetWindowRect(rectCurrent);
124 if (rectNew != rectCurrent)
126 SetWindowPos(NULL,0,0,rectNew.Width(), rectNew.Height(),
127 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
134 * @brief Resize both controls to an equal size.
136 void CEditorFilePathBar::Resize()
141 WINDOWPLACEMENT infoBar;
142 GetWindowPlacement(&infoBar);
145 for (int pane = 0; pane < m_nPanes; pane++)
146 widths[pane] = (infoBar.rcNormalPosition.right / m_nPanes) - 6;
151 * This function resizes both controls to given size. The width is usually
152 * same as the splitter view width.
153 * @param [in] leftWidth Left-side control width.
154 * @param [in] rightWidth Right-side control width.
156 void CEditorFilePathBar::Resize(int widths[])
161 // resize left filename
165 for (int pane = 0; pane < m_nPanes; pane++)
168 m_Edit[pane].GetClientRect(&rcOld);
170 rc.right = x + widths[pane] + 4;
171 x += widths[pane] + 7;
172 if (rcOld.Width() != rc.Width())
174 m_Edit[pane].MoveWindow(&rc);
175 m_Edit[pane].RefreshDisplayText();
181 * @brief Called when tooltip is about to be shown.
182 * In this function we set the tooltip text shown.
184 BOOL CEditorFilePathBar::OnToolTipNotify(UINT id, NMHDR * pTTTStruct, LRESULT * pResult)
189 TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pTTTStruct;
190 if (pTTT->uFlags & TTF_IDISHWND)
192 // idFrom is actually the HWND of the CEdit
193 int nID = ::GetDlgCtrlID((HWND)pTTTStruct->idFrom);
194 if(nID == IDC_STATIC_TITLE_PANE0 || nID == IDC_STATIC_TITLE_PANE1 || nID == IDC_STATIC_TITLE_PANE2)
196 // compute max width : 97% of application width or 80% or full screen width
199 int maxWidth = (int)(rect.Width() * .97);
201 SystemParametersInfo(SPI_GETWORKAREA, 0, rectScreen, 0);
202 if (rectScreen.Width() * .8 > maxWidth)
203 maxWidth = (int)(rectScreen.Width() * .8);
205 // use the tooltip font
206 HANDLE hFont = (HANDLE) ::SendMessage(pTTTStruct->hwndFrom, WM_GETFONT, 0, 0);
207 CClientDC tempDC(this);
208 HANDLE hOldFont = ::SelectObject(tempDC.GetSafeHdc(),hFont);
210 // fill in the returned structure
211 CFilepathEdit * pItem = static_cast<CFilepathEdit*>(GetDlgItem(nID));
212 pTTT->lpszText = const_cast<TCHAR *>(pItem->GetUpdatedTipText(&tempDC, maxWidth).c_str());
216 ::SelectObject(tempDC.GetSafeHdc(),hOldFont);
218 // we must set TTM_SETMAXTIPWIDTH to use \n in tooltips
219 // just to do the first time, but how to access the tooltip during init ?
220 ::SendMessage(pTTTStruct->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 5000);
229 * @brief Set the path for one side
231 * @param [in] pane Index (0-based) of pane to update.
232 * @param [in] lpszString New text for pane.
234 void CEditorFilePathBar::SetText(int pane, const String& sString)
236 ASSERT (pane >= 0 && pane < countof(m_Edit));
238 // Check for NULL since window may be closing..
242 m_Edit[pane].SetOriginalText(sString);
246 * @brief Set the active status for one status (change the appearance)
248 * @param [in] pane Index (0-based) of pane to update.
249 * @param [in] bActive If TRUE activates pane, FALSE deactivates.
251 void CEditorFilePathBar::SetActive(int pane, bool bActive)
253 ASSERT (pane >= 0 && pane < countof(m_Edit));
255 // Check for NULL since window may be closing..
259 m_Edit[pane].SetActive(bActive);