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++)
105 m_Edit[pane].SetFont(m_pFont.get());
106 m_Edit[pane].SetMargins(4, 4);
112 // Set same dimensions (than window we imitate)
114 pWnd->GetWindowRect(rectNew);
116 GetWindowRect(rectCurrent);
117 if (rectNew != rectCurrent)
119 SetWindowPos(NULL,0,0,rectNew.Width(), rectNew.Height(),
120 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
127 * @brief Resize both controls to an equal size.
129 void CEditorFilePathBar::Resize()
134 WINDOWPLACEMENT infoBar;
135 GetWindowPlacement(&infoBar);
138 for (int pane = 0; pane < m_nPanes; pane++)
139 widths[pane] = (infoBar.rcNormalPosition.right / m_nPanes) - 6;
144 * This function resizes both controls to given size. The width is usually
145 * same as the splitter view width.
146 * @param [in] leftWidth Left-side control width.
147 * @param [in] rightWidth Right-side control width.
149 void CEditorFilePathBar::Resize(int widths[])
154 // resize left filename
158 for (int pane = 0; pane < m_nPanes; pane++)
161 m_Edit[pane].GetClientRect(&rcOld);
163 rc.right = x + widths[pane] + 4;
164 x += widths[pane] + 7;
165 if (rcOld.Width() != rc.Width())
167 m_Edit[pane].MoveWindow(&rc);
168 m_Edit[pane].RefreshDisplayText();
174 * @brief Called when tooltip is about to be shown.
175 * In this function we set the tooltip text shown.
177 BOOL CEditorFilePathBar::OnToolTipNotify(UINT id, NMHDR * pTTTStruct, LRESULT * pResult)
182 TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pTTTStruct;
183 if (pTTT->uFlags & TTF_IDISHWND)
185 // idFrom is actually the HWND of the CEdit
186 int nID = ::GetDlgCtrlID((HWND)pTTTStruct->idFrom);
187 if(nID == IDC_STATIC_TITLE_PANE0 || nID == IDC_STATIC_TITLE_PANE1 || nID == IDC_STATIC_TITLE_PANE2)
189 // compute max width : 97% of application width or 80% or full screen width
192 int maxWidth = (int)(rect.Width() * .97);
194 SystemParametersInfo(SPI_GETWORKAREA, 0, rectScreen, 0);
195 if (rectScreen.Width() * .8 > maxWidth)
196 maxWidth = (int)(rectScreen.Width() * .8);
198 // use the tooltip font
199 HANDLE hFont = (HANDLE) ::SendMessage(pTTTStruct->hwndFrom, WM_GETFONT, 0, 0);
200 CClientDC tempDC(this);
201 HANDLE hOldFont = ::SelectObject(tempDC.GetSafeHdc(),hFont);
203 // fill in the returned structure
204 CFilepathEdit * pItem = static_cast<CFilepathEdit*>(GetDlgItem(nID));
205 pTTT->lpszText = const_cast<TCHAR *>(pItem->GetUpdatedTipText(&tempDC, maxWidth).c_str());
209 ::SelectObject(tempDC.GetSafeHdc(),hOldFont);
211 // we must set TTM_SETMAXTIPWIDTH to use \n in tooltips
212 // just to do the first time, but how to access the tooltip during init ?
213 ::SendMessage(pTTTStruct->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 5000);
222 * @brief Set the path for one side
224 * @param [in] pane Index (0-based) of pane to update.
225 * @param [in] lpszString New text for pane.
227 void CEditorFilePathBar::SetText(int pane, const String& sString)
229 ASSERT (pane >= 0 && pane < countof(m_Edit));
231 // Check for NULL since window may be closing..
235 m_Edit[pane].SetOriginalText(sString);
239 * @brief Set the active status for one status (change the appearance)
241 * @param [in] pane Index (0-based) of pane to update.
242 * @param [in] bActive If TRUE activates pane, FALSE deactivates.
244 void CEditorFilePathBar::SetActive(int pane, bool bActive)
246 ASSERT (pane >= 0 && pane < countof(m_Edit));
248 // Check for NULL since window may be closing..
252 m_Edit[pane].SetActive(bActive);