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
25 #include "TortoiseGitBlame.h"
26 #include "MenuEncode.h"
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
)
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
)
54 static UINT indicators
[] =
56 ID_SEPARATOR
, // status line indicator
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)
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
);
103 m_wndToolBar
.SetWindowText(strToolBarName
);
105 CString strCustomize
;
106 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
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");
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();
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
);
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
,
207 IDM_FORMAT_SHIFT_JIS
,
208 IDM_FORMAT_KOREAN_WIN
,
211 IDM_FORMAT_MAC_CYRILLIC
,
212 IDM_FORMAT_KOI8U_CYRILLIC
,
213 IDM_FORMAT_KOI8R_CYRILLIC
,
219 BOOL
CMainFrame::PreCreateWindow(CREATESTRUCT
& cs
)
221 if( !CFrameWndEx::PreCreateWindow(cs
) )
223 // TODO: Modify the Window class or styles here by modifying
224 // the CREATESTRUCT cs
229 BOOL
CMainFrame::CreateDockingWindows()
232 // Create output window
233 CString strOutputWnd
;
234 bNameValid
= strOutputWnd
.LoadString(IDS_OUTPUT_WND
);
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
);
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
);
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
269 void CMainFrame::AssertValid() const
271 CFrameWndEx::AssertValid();
274 void CMainFrame::Dump(CDumpContext
& dc
) const
276 CFrameWndEx::Dump(dc
);
281 // CMainFrame message handlers
283 void CMainFrame::OnViewCustomize()
285 CMFCToolBarsCustomizeDialog
* pDlgCust
= new CMFCToolBarsCustomizeDialog(this, TRUE
/* scan menus */);
286 pDlgCust
->EnableUserDefinedToolbars();
290 LRESULT
CMainFrame::OnToolbarCreateNew(WPARAM wp
,LPARAM lp
)
292 LRESULT lres
= CFrameWndEx::OnToolbarCreateNew(wp
,lp
);
298 CMFCToolBar
* pUserToolbar
= (CMFCToolBar
*)lres
;
299 ASSERT_VALID(pUserToolbar
);
302 CString strCustomize
;
303 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
306 pUserToolbar
->EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);
310 void CMainFrame::OnApplicationLook(UINT id
)
314 theApp
.m_nAppLook
= id
;
316 switch (theApp
.m_nAppLook
)
318 case ID_VIEW_APPLOOK_WIN_2000
:
319 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager
));
322 case ID_VIEW_APPLOOK_OFF_XP
:
323 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP
));
326 case ID_VIEW_APPLOOK_WIN_XP
:
327 CMFCVisualManagerWindows::m_b3DTabsXPTheme
= TRUE
;
328 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows
));
331 case ID_VIEW_APPLOOK_OFF_2003
:
332 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003
));
333 CDockingManager::SetDockingMode(DT_SMART
);
336 case ID_VIEW_APPLOOK_VS_2005
:
337 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005
));
338 CDockingManager::SetDockingMode(DT_SMART
);
342 switch (theApp
.m_nAppLook
)
344 case ID_VIEW_APPLOOK_OFF_2007_BLUE
:
345 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue
);
348 case ID_VIEW_APPLOOK_OFF_2007_BLACK
:
349 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack
);
352 case ID_VIEW_APPLOOK_OFF_2007_SILVER
:
353 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver
);
356 case ID_VIEW_APPLOOK_OFF_2007_AQUA
:
357 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua
);
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
))
384 // enable customization button for all user toolbars
386 CString strCustomize
;
387 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
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
);