Moved bisect start logic to AppUtils
[TortoiseGit.git] / src / TortoiseGitBlame / MainFrm.cpp
blob841a00e2997e9f905b95089f94d6575435081a53
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // MainFrm.cpp : implementation of the CMainFrame class
24 #include "stdafx.h"
25 #include "TortoiseGitBlame.h"
26 #include "MenuEncode.h"
27 #include "MainFrm.h"
29 #ifdef _DEBUG
30 #define new DEBUG_NEW
31 #endif
33 // CMainFrame
35 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
37 const int iMaxUserToolbars = 10;
38 const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
39 const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;
41 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
42 ON_WM_CREATE()
43 // Global help commands
44 ON_COMMAND(ID_HELP_FINDER, &CFrameWndEx::OnHelpFinder)
45 ON_COMMAND(ID_HELP, &CFrameWndEx::OnHelp)
46 ON_COMMAND(ID_CONTEXT_HELP, &CFrameWndEx::OnContextHelp)
47 ON_COMMAND(ID_DEFAULT_HELP, &CFrameWndEx::OnHelpFinder)
48 ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize)
49 ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew)
50 ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnApplicationLook)
51 ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnUpdateApplicationLook)
52 END_MESSAGE_MAP()
54 static UINT indicators[] =
56 ID_SEPARATOR, // status line indicator
57 ID_INDICATOR_CAPS,
58 ID_INDICATOR_NUM,
59 ID_INDICATOR_SCRL,
62 // CMainFrame construction/destruction
64 CMainFrame::CMainFrame()
66 theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2005);
69 CMainFrame::~CMainFrame()
73 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
75 if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
76 return -1;
78 BOOL bNameValid;
79 // set the visual manager and style based on persisted value
80 OnApplicationLook(theApp.m_nAppLook);
82 if (!m_wndMenuBar.Create(this))
84 TRACE0("Failed to create menubar\n");
85 return -1; // fail to create
88 m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
90 // prevent the menu bar from taking the focus on activation
91 CMFCPopupMenu::SetForceMenuFocus(FALSE);
93 if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
94 !m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_TORTOISE_GIT_BLAME_MAINFRAME_256 : IDR_TORTOISE_GIT_BLAME_MAINFRAME))
96 TRACE0("Failed to create toolbar\n");
97 return -1; // fail to create
100 CString strToolBarName;
101 bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
102 ASSERT(bNameValid);
103 m_wndToolBar.SetWindowText(strToolBarName);
105 CString strCustomize;
106 bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
107 ASSERT(bNameValid);
108 m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
110 // Allow user-defined toolbars operations:
111 InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);
113 if (!m_wndStatusBar.Create(this))
115 TRACE0("Failed to create status bar\n");
116 return -1; // fail to create
118 m_wndStatusBar.SetIndicators(indicators, _countof(indicators));
120 // Delete these five lines if you don't want the toolbar and menubar to be dockable
121 m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
122 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
123 EnableDocking(CBRS_ALIGN_ANY);
124 DockPane(&m_wndMenuBar);
125 DockPane(&m_wndToolBar);
128 // enable Visual Studio 2005 style docking window behavior
129 CDockingManager::SetDockingMode(DT_SMART);
130 // enable Visual Studio 2005 style docking window auto-hide behavior
131 EnableAutoHidePanes(CBRS_ALIGN_ANY);
133 // create docking windows
134 if (!CreateDockingWindows())
136 TRACE0("Failed to create docking windows\n");
137 return -1;
140 m_wndOutput.EnableDocking(CBRS_ALIGN_ANY);
141 DockPane(&m_wndOutput);
142 m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
143 DockPane(&m_wndProperties);
146 // Enable toolbar and docking window menu replacement
147 EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);
149 // enable quick (Alt+drag) toolbar customization
150 CMFCToolBar::EnableQuickCustomization();
152 #if 0
153 if (CMFCToolBar::GetUserImages() == NULL)
155 // load user-defined toolbar images
156 if (m_UserImages.Load(_T(".\\UserImages.bmp")))
158 m_UserImages.SetImageSize(CSize(16, 16), FALSE);
159 CMFCToolBar::SetUserImages(&m_UserImages);
162 #endif
164 int ids[]={
165 IDM_FORMAT_WIN_1250 ,
166 IDM_FORMAT_WIN_1251 ,
167 IDM_FORMAT_WIN_1252 ,
168 IDM_FORMAT_WIN_1253 ,
169 IDM_FORMAT_WIN_1254 ,
170 IDM_FORMAT_WIN_1255 ,
171 IDM_FORMAT_WIN_1256 ,
172 IDM_FORMAT_WIN_1257 ,
173 IDM_FORMAT_WIN_1258 ,
174 IDM_FORMAT_ISO_8859_1 ,
175 IDM_FORMAT_ISO_8859_2 ,
176 IDM_FORMAT_ISO_8859_3 ,
177 IDM_FORMAT_ISO_8859_4 ,
178 IDM_FORMAT_ISO_8859_5 ,
179 IDM_FORMAT_ISO_8859_6 ,
180 IDM_FORMAT_ISO_8859_7 ,
181 IDM_FORMAT_ISO_8859_8 ,
182 IDM_FORMAT_ISO_8859_9 ,
183 IDM_FORMAT_ISO_8859_10 ,
184 IDM_FORMAT_ISO_8859_11 ,
185 IDM_FORMAT_ISO_8859_13 ,
186 IDM_FORMAT_ISO_8859_14 ,
187 IDM_FORMAT_ISO_8859_15 ,
188 IDM_FORMAT_ISO_8859_16 ,
189 IDM_FORMAT_DOS_437 ,
190 IDM_FORMAT_DOS_720 ,
191 IDM_FORMAT_DOS_737 ,
192 IDM_FORMAT_DOS_775 ,
193 IDM_FORMAT_DOS_850 ,
194 IDM_FORMAT_DOS_852 ,
195 IDM_FORMAT_DOS_855 ,
196 IDM_FORMAT_DOS_857 ,
197 IDM_FORMAT_DOS_858 ,
198 IDM_FORMAT_DOS_860 ,
199 IDM_FORMAT_DOS_861 ,
200 IDM_FORMAT_DOS_862 ,
201 IDM_FORMAT_DOS_863 ,
202 IDM_FORMAT_DOS_865 ,
203 IDM_FORMAT_DOS_866 ,
204 IDM_FORMAT_DOS_869 ,
205 IDM_FORMAT_BIG5 ,
206 IDM_FORMAT_GB2312 ,
207 IDM_FORMAT_SHIFT_JIS ,
208 IDM_FORMAT_KOREAN_WIN ,
209 IDM_FORMAT_EUC_KR ,
210 IDM_FORMAT_TIS_620 ,
211 IDM_FORMAT_MAC_CYRILLIC ,
212 IDM_FORMAT_KOI8U_CYRILLIC ,
213 IDM_FORMAT_KOI8R_CYRILLIC ,
216 return 0;
219 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
221 if( !CFrameWndEx::PreCreateWindow(cs) )
222 return FALSE;
223 // TODO: Modify the Window class or styles here by modifying
224 // the CREATESTRUCT cs
226 return TRUE;
229 BOOL CMainFrame::CreateDockingWindows()
231 BOOL bNameValid;
232 // Create output window
233 CString strOutputWnd;
234 bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);
235 ASSERT(bNameValid);
236 if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 100, 100), TRUE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
238 TRACE0("Failed to create Output window\n");
239 return FALSE; // failed to create
242 // Create properties window
243 CString strPropertiesWnd;
244 bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
245 ASSERT(bNameValid);
246 if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
248 TRACE0("Failed to create Properties window\n");
249 return FALSE; // failed to create
252 SetDockingWindowIcons(theApp.m_bHiColorIcons);
253 return TRUE;
256 void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)
258 HICON hOutputBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_OUTPUT_WND_HC : IDI_OUTPUT_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
259 m_wndOutput.SetIcon(hOutputBarIcon, FALSE);
261 HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
262 m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);
266 // CMainFrame diagnostics
268 #ifdef _DEBUG
269 void CMainFrame::AssertValid() const
271 CFrameWndEx::AssertValid();
274 void CMainFrame::Dump(CDumpContext& dc) const
276 CFrameWndEx::Dump(dc);
278 #endif //_DEBUG
281 // CMainFrame message handlers
283 void CMainFrame::OnViewCustomize()
285 CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* scan menus */);
286 pDlgCust->EnableUserDefinedToolbars();
287 pDlgCust->Create();
290 LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)
292 LRESULT lres = CFrameWndEx::OnToolbarCreateNew(wp,lp);
293 if (lres == 0)
295 return 0;
298 CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres;
299 ASSERT_VALID(pUserToolbar);
301 BOOL bNameValid;
302 CString strCustomize;
303 bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
304 ASSERT(bNameValid);
306 pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
307 return lres;
310 void CMainFrame::OnApplicationLook(UINT id)
312 CWaitCursor wait;
314 theApp.m_nAppLook = id;
316 switch (theApp.m_nAppLook)
318 case ID_VIEW_APPLOOK_WIN_2000:
319 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));
320 break;
322 case ID_VIEW_APPLOOK_OFF_XP:
323 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
324 break;
326 case ID_VIEW_APPLOOK_WIN_XP:
327 CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
328 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
329 break;
331 case ID_VIEW_APPLOOK_OFF_2003:
332 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
333 CDockingManager::SetDockingMode(DT_SMART);
334 break;
336 case ID_VIEW_APPLOOK_VS_2005:
337 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
338 CDockingManager::SetDockingMode(DT_SMART);
339 break;
341 default:
342 switch (theApp.m_nAppLook)
344 case ID_VIEW_APPLOOK_OFF_2007_BLUE:
345 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
346 break;
348 case ID_VIEW_APPLOOK_OFF_2007_BLACK:
349 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
350 break;
352 case ID_VIEW_APPLOOK_OFF_2007_SILVER:
353 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
354 break;
356 case ID_VIEW_APPLOOK_OFF_2007_AQUA:
357 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
358 break;
361 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
362 CDockingManager::SetDockingMode(DT_SMART);
365 RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
367 theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
370 void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
372 pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
375 BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
377 // base class does the real work
379 if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
381 return FALSE;
384 // enable customization button for all user toolbars
385 BOOL bNameValid;
386 CString strCustomize;
387 bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
388 ASSERT(bNameValid);
390 for (int i = 0; i < iMaxUserToolbars; i ++)
392 CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);
393 if (pUserToolbar != NULL)
395 pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
399 return TRUE;