forked from WinMerge/winmerge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirFrame.cpp
285 lines (247 loc) · 7.44 KB
/
DirFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/////////////////////////////////////////////////////////////////////////////
// WinMerge: an interactive diff/merge utility
// Copyright (C) 1997-2000 Thingamahoochie Software
// Author: Dean Grimm
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
/////////////////////////////////////////////////////////////////////////////
/**
* @file DirFrame.cpp
*
* @brief Implementation file for CDirFrame
*
*/
#include "stdafx.h"
#include "DirFrame.h"
#include "Merge.h"
#include "OptionsDef.h"
#include "OptionsMgr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
/**
* @brief Statusbar pane indexes
*/
enum
{
PANE_COMPMETHOD = 1,
PANE_FILTER,
PANE_LEFT_RO,
PANE_MIDDLE_RO,
PANE_RIGHT_RO,
};
/**
* @brief Width of compare method name pane in statusbar
*/
const int COMPMETHOD_PANEL_WIDTH = 100;
/**
* @brief Width of filter name pane in statusbar
*/
const int FILTER_PANEL_WIDTH = 100;
/**
* @brief Bottom statusbar panels and indicators
*/
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
};
/**
* @brief RO status panel width
*/
static UINT RO_PANEL_WIDTH = 30;
/////////////////////////////////////////////////////////////////////////////
// CDirFrame
IMPLEMENT_DYNCREATE(CDirFrame, CMDIChildWnd)
CDirFrame::CDirFrame()
: m_hIdentical(nullptr)
, m_hDifferent(nullptr)
{
}
CDirFrame::~CDirFrame()
{
}
BEGIN_MESSAGE_MAP(CDirFrame, CMDIChildWnd)
//{{AFX_MSG_MAP(CDirFrame)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_WM_SIZE()
ON_WM_MDIACTIVATE()
ON_WM_GETMINMAXINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDirFrame message handlers
/**
* @brief Create statusbar
*/
int CDirFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
EnableDocking(CBRS_ALIGN_TOP);
// Dir frame has a header bar at top
if (!m_wndFilePathBar.Create(this))
{
TRACE0("Failed to create header bar\n");
return -1; // fail to create
}
// Directory frame has a status bar
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
String sText = _("RO");
const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX);
auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); };
m_wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_NOBORDERS, 0);
m_wndStatusBar.SetPaneInfo(PANE_COMPMETHOD, ID_STATUS_FILTER, 0, pointToPixel(COMPMETHOD_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_FILTER, ID_STATUS_FILTER, 0, pointToPixel(FILTER_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_LEFT_RO, ID_STATUS_LEFTDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_MIDDLE_RO, ID_STATUS_MIDDLEDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_RIGHT_RO, ID_STATUS_RIGHTDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneText(PANE_LEFT_RO, sText.c_str(), TRUE);
m_wndStatusBar.SetPaneText(PANE_MIDDLE_RO, sText.c_str(), TRUE);
m_wndStatusBar.SetPaneText(PANE_RIGHT_RO, sText.c_str(), TRUE);
m_hIdentical = AfxGetApp()->LoadIcon(IDI_EQUALFOLDER);
m_hDifferent = AfxGetApp()->LoadIcon(IDI_NOTEQUALFOLDER);
return 0;
}
/**
* @brief Set statusbar text
*/
void CDirFrame::SetStatus(LPCTSTR szStatus)
{
m_wndStatusBar.SetPaneText(0, szStatus);
}
/**
* @brief Set current compare method name to statusbar
* @param [in] nCompMethod compare method to show
*/
void CDirFrame::SetCompareMethodStatusDisplay(int nCompMethod)
{
m_wndStatusBar.SetPaneText(PANE_COMPMETHOD, LoadResString(IDS_COMPMETHOD_FULL_CONTENTS + nCompMethod).c_str());
}
/**
* @brief Set active filter name to statusbar
* @param [in] szFilter Filtername to show
*/
void CDirFrame::SetFilterStatusDisplay(LPCTSTR szFilter)
{
m_wndStatusBar.SetPaneText(PANE_FILTER, szFilter);
}
/**
* @brief Get the interface to the header (path) bar
*/
IHeaderBar * CDirFrame::GetHeaderInterface() {
return &m_wndFilePathBar;
}
/**
* @brief Restore maximized state of directory compare window
*/
void CDirFrame::ActivateFrame(int nCmdShow)
{
// load docking positions and sizes
CDockState dockState;
dockState.LoadState(_T("Settings-DirFrame"));
SetDockState(dockState);
// get the active child frame, and a flag whether it is maximized
BOOL bMaximized = FALSE;
CMDIChildWnd * oldActiveFrame = GetMDIFrame()->MDIGetActive(&bMaximized);
if (oldActiveFrame == nullptr)
// for the first frame, get the restored/maximized state from the registry
bMaximized = GetOptionsMgr()->GetBool(OPT_ACTIVE_FRAME_MAX);
if (bMaximized)
nCmdShow = SW_SHOWMAXIMIZED;
else
nCmdShow = SW_SHOWNORMAL;
CMDIChildWnd::ActivateFrame(nCmdShow);
}
/**
* @brief Update any resources necessary after a GUI language change
*/
void CDirFrame::UpdateResources()
{
}
/**
* @brief Reflect comparison result in window's icon.
* @param nResult [in] Last comparison result which the application returns.
*/
void CDirFrame::SetLastCompareResult(int nResult)
{
HICON hCurrent = GetIcon(FALSE);
HICON hReplace = (nResult == 0) ? m_hIdentical : m_hDifferent;
if (hCurrent != hReplace)
{
SetIcon(hReplace, TRUE);
BOOL bMaximized;
GetMDIFrame()->MDIGetActive(&bMaximized);
// When MDI maximized the window icon is drawn on the menu bar, so we
// need to notify it that our icon has changed.
if (bMaximized)
{
GetMDIFrame()->DrawMenuBar();
}
GetMDIFrame()->OnUpdateFrameTitle(FALSE);
}
theApp.SetLastCompareResult(nResult);
}
void CDirFrame::OnClose()
{
CMDIChildWnd::OnClose();
}
/**
* @brief Save maximized state before destroying window
*/
BOOL CDirFrame::DestroyWindow()
{
// If we are active, save the restored/maximized state
// If we are not, do nothing and let the active frame do the job.
if (this->GetParentFrame()->GetActiveFrame() == (CFrameWnd*)this)
{
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(&wp);
GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE));
// save docking positions and sizes
CDockState dockState;
GetDockState(dockState);
dockState.SaveState(_T("Settings-DirFrame"));
}
return CMDIChildWnd::DestroyWindow();
}
void CDirFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWnd::OnSize(nType, cx, cy);
m_wndFilePathBar.Resize();
}
void CDirFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
CMDIChildWnd::OnGetMinMaxInfo(lpMMI);
// [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista]
// https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM
#if _MFC_VER >= 0x0800
lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x);
lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y);
#endif
}