1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2016 - 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"
28 #include "TaskbarUUID.h"
36 IMPLEMENT_DYNCREATE(CMainFrame
, CFrameWndEx
)
38 const int iMaxUserToolbars
= 10;
39 const UINT uiFirstUserToolBarId
= AFX_IDW_CONTROLBAR_FIRST
+ 40;
40 const UINT uiLastUserToolBarId
= uiFirstUserToolBarId
+ iMaxUserToolbars
- 1;
42 BEGIN_MESSAGE_MAP(CMainFrame
, CFrameWndEx
)
44 // Global help commands
45 ON_COMMAND(ID_HELP_FINDER
, &CFrameWndEx::OnHelpFinder
)
46 ON_UPDATE_COMMAND_UI(ID_HELP_FINDER
, &CMainFrame::OnUpdateHelpFinder
)
47 ON_COMMAND(ID_HELP
, &CFrameWndEx::OnHelp
)
48 ON_COMMAND(ID_CONTEXT_HELP
, &CFrameWndEx::OnContextHelp
)
49 ON_COMMAND(ID_DEFAULT_HELP
, &CFrameWndEx::OnHelpFinder
)
50 ON_COMMAND(ID_VIEW_CUSTOMIZE
, &CMainFrame::OnViewCustomize
)
51 ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR
, &CMainFrame::OnToolbarCreateNew
)
52 ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000
, ID_VIEW_APPLOOK_OFF_2007_AQUA
, &CMainFrame::OnApplicationLook
)
53 ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000
, ID_VIEW_APPLOOK_OFF_2007_AQUA
, &CMainFrame::OnUpdateApplicationLook
)
54 ON_REGISTERED_MESSAGE(TaskBarButtonCreated
, &CMainFrame::OnTaskbarButtonCreated
)
57 static UINT indicators
[] =
59 ID_SEPARATOR
, // status line indicator
60 ID_INDICATOR_ENCODING
,
64 // CMainFrame construction/destruction
66 CMainFrame::CMainFrame()
68 theApp
.m_nAppLook
= theApp
.GetInt(L
"ApplicationLook", ID_VIEW_APPLOOK_VS_2005
);
71 CMainFrame::~CMainFrame()
75 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct
)
77 if (CFrameWndEx::OnCreate(lpCreateStruct
) == -1)
81 // set the visual manager and style based on persisted value
82 OnApplicationLook(theApp
.m_nAppLook
);
84 if (!m_wndMenuBar
.Create(this))
86 TRACE0("Failed to create menubar\n");
87 return -1; // fail to create
90 m_wndMenuBar
.SetPaneStyle(m_wndMenuBar
.GetPaneStyle() | CBRS_SIZE_DYNAMIC
| CBRS_TOOLTIPS
| CBRS_FLYBY
);
92 // prevent the menu bar from taking the focus on activation
93 CMFCPopupMenu::SetForceMenuFocus(FALSE
);
95 if (!m_wndToolBar
.CreateEx(this, TBSTYLE_FLAT
, WS_CHILD
| WS_VISIBLE
| CBRS_TOP
| CBRS_GRIPPER
| CBRS_TOOLTIPS
| CBRS_FLYBY
| CBRS_SIZE_DYNAMIC
) ||
96 !m_wndToolBar
.LoadToolBar(theApp
.m_bHiColorIcons
? IDR_TORTOISE_GIT_BLAME_MAINFRAME_256
: IDR_TORTOISE_GIT_BLAME_MAINFRAME
))
98 TRACE0("Failed to create toolbar\n");
99 return -1; // fail to create
102 CString strToolBarName
;
103 bNameValid
= strToolBarName
.LoadString(IDS_TOOLBAR_STANDARD
);
105 m_wndToolBar
.SetWindowText(strToolBarName
);
107 CString strCustomize
;
108 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
110 m_wndToolBar
.EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);
112 // Allow user-defined toolbars operations:
113 InitUserToolbars(nullptr, uiFirstUserToolBarId
, uiLastUserToolBarId
);
115 if (!m_wndStatusBar
.Create(this))
117 TRACE0("Failed to create status bar\n");
118 return -1; // fail to create
120 m_wndStatusBar
.SetIndicators(indicators
, _countof(indicators
));
122 // Delete these five lines if you don't want the toolbar and menubar to be dockable
123 m_wndMenuBar
.EnableDocking(CBRS_ALIGN_ANY
);
124 m_wndToolBar
.EnableDocking(CBRS_ALIGN_ANY
);
125 EnableDocking(CBRS_ALIGN_ANY
);
126 DockPane(&m_wndMenuBar
);
127 DockPane(&m_wndToolBar
);
130 // enable Visual Studio 2005 style docking window behavior
131 CDockingManager::SetDockingMode(DT_SMART
);
132 // enable Visual Studio 2005 style docking window auto-hide behavior
133 EnableAutoHidePanes(CBRS_ALIGN_ANY
);
135 // create docking windows
136 if (!CreateDockingWindows())
138 TRACE0("Failed to create docking windows\n");
142 m_wndOutput
.EnableDocking(CBRS_ALIGN_ANY
);
143 DockPane(&m_wndOutput
);
144 m_wndProperties
.EnableDocking(CBRS_ALIGN_ANY
);
145 DockPane(&m_wndProperties
);
148 // Enable toolbar and docking window menu replacement
149 EnablePaneMenu(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
, ID_VIEW_TOOLBAR
);
151 // enable quick (Alt+drag) toolbar customization
152 CMFCToolBar::EnableQuickCustomization();
157 LRESULT
CMainFrame::OnTaskbarButtonCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
159 SetUUIDOverlayIcon(m_hWnd
);
163 BOOL
CMainFrame::PreCreateWindow(CREATESTRUCT
& cs
)
165 if( !CFrameWndEx::PreCreateWindow(cs
) )
167 // TODO: Modify the Window class or styles here by modifying
168 // the CREATESTRUCT cs
173 BOOL
CMainFrame::CreateDockingWindows()
176 // Create output window
177 CString strOutputWnd
;
178 bNameValid
= strOutputWnd
.LoadString(IDS_OUTPUT_WND
);
180 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
))
182 TRACE0("Failed to create Output window\n");
183 return FALSE
; // failed to create
186 // Create properties window
187 CString strPropertiesWnd
;
188 bNameValid
= strPropertiesWnd
.LoadString(IDS_PROPERTIES_WND
);
190 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
))
192 TRACE0("Failed to create Properties window\n");
193 return FALSE
; // failed to create
196 SetDockingWindowIcons(theApp
.m_bHiColorIcons
);
200 void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons
)
202 HICON hOutputBarIcon
= (HICON
) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons
? IDI_OUTPUT_WND_HC
: IDI_OUTPUT_WND
), IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), 0);
203 m_wndOutput
.SetIcon(hOutputBarIcon
, FALSE
);
205 HICON hPropertiesBarIcon
= (HICON
) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons
? IDI_PROPERTIES_WND_HC
: IDI_PROPERTIES_WND
), IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), 0);
206 m_wndProperties
.SetIcon(hPropertiesBarIcon
, FALSE
);
209 // CMainFrame diagnostics
212 void CMainFrame::AssertValid() const
214 CFrameWndEx::AssertValid();
217 void CMainFrame::Dump(CDumpContext
& dc
) const
219 CFrameWndEx::Dump(dc
);
224 // CMainFrame message handlers
226 void CMainFrame::OnUpdateHelpFinder(CCmdUI
*pCmdUI
)
228 pCmdUI
->Enable(FALSE
);
231 void CMainFrame::OnViewCustomize()
233 CMFCToolBarsCustomizeDialog
* pDlgCust
= new CMFCToolBarsCustomizeDialog(this, TRUE
/* scan menus */);
234 pDlgCust
->EnableUserDefinedToolbars();
238 LRESULT
CMainFrame::OnToolbarCreateNew(WPARAM wp
,LPARAM lp
)
240 LRESULT lres
= CFrameWndEx::OnToolbarCreateNew(wp
,lp
);
244 CMFCToolBar
* pUserToolbar
= (CMFCToolBar
*)lres
;
245 ASSERT_VALID(pUserToolbar
);
248 CString strCustomize
;
249 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
252 pUserToolbar
->EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);
256 void CMainFrame::OnApplicationLook(UINT id
)
260 theApp
.m_nAppLook
= id
;
262 switch (theApp
.m_nAppLook
)
264 case ID_VIEW_APPLOOK_WIN_2000
:
265 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager
));
268 case ID_VIEW_APPLOOK_OFF_XP
:
269 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP
));
272 case ID_VIEW_APPLOOK_WIN_XP
:
273 CMFCVisualManagerWindows::m_b3DTabsXPTheme
= TRUE
;
274 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows
));
277 case ID_VIEW_APPLOOK_OFF_2003
:
278 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003
));
279 CDockingManager::SetDockingMode(DT_SMART
);
282 case ID_VIEW_APPLOOK_VS_2005
:
283 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005
));
284 CDockingManager::SetDockingMode(DT_SMART
);
287 case ID_VIEW_APPLOOK_VS_2008
:
288 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008
));
289 CDockingManager::SetDockingMode(DT_SMART
);
292 case ID_VIEW_APPLOOK_WIN7
:
293 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7
));
294 CDockingManager::SetDockingMode(DT_SMART
);
298 switch (theApp
.m_nAppLook
)
300 case ID_VIEW_APPLOOK_OFF_2007_BLUE
:
301 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue
);
304 case ID_VIEW_APPLOOK_OFF_2007_BLACK
:
305 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack
);
308 case ID_VIEW_APPLOOK_OFF_2007_SILVER
:
309 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver
);
312 case ID_VIEW_APPLOOK_OFF_2007_AQUA
:
313 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua
);
317 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007
));
318 CDockingManager::SetDockingMode(DT_SMART
);
321 RedrawWindow(nullptr, nullptr, RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_UPDATENOW
| RDW_FRAME
| RDW_ERASE
);
323 theApp
.WriteInt(L
"ApplicationLook", theApp
.m_nAppLook
);
326 void CMainFrame::OnUpdateApplicationLook(CCmdUI
* pCmdUI
)
329 pCmdUI
->SetRadio(theApp
.m_nAppLook
== pCmdUI
->m_nID
);
332 BOOL
CMainFrame::LoadFrame(UINT nIDResource
, DWORD dwDefaultStyle
, CWnd
* pParentWnd
, CCreateContext
* pContext
)
334 // base class does the real work
336 if (!CFrameWndEx::LoadFrame(nIDResource
, dwDefaultStyle
, pParentWnd
, pContext
))
339 // enable customization button for all user toolbars
341 CString strCustomize
;
342 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
345 for (int i
= 0; i
< iMaxUserToolbars
; ++i
)
347 CMFCToolBar
* pUserToolbar
= GetUserToolBarByIndex(i
);
349 pUserToolbar
->EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);