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();
155 BOOL
CMainFrame::PreCreateWindow(CREATESTRUCT
& cs
)
157 if( !CFrameWndEx::PreCreateWindow(cs
) )
159 // TODO: Modify the Window class or styles here by modifying
160 // the CREATESTRUCT cs
165 BOOL
CMainFrame::CreateDockingWindows()
168 // Create output window
169 CString strOutputWnd
;
170 bNameValid
= strOutputWnd
.LoadString(IDS_OUTPUT_WND
);
172 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
))
174 TRACE0("Failed to create Output window\n");
175 return FALSE
; // failed to create
178 // Create properties window
179 CString strPropertiesWnd
;
180 bNameValid
= strPropertiesWnd
.LoadString(IDS_PROPERTIES_WND
);
182 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
))
184 TRACE0("Failed to create Properties window\n");
185 return FALSE
; // failed to create
188 SetDockingWindowIcons(theApp
.m_bHiColorIcons
);
192 void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons
)
194 HICON hOutputBarIcon
= (HICON
) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons
? IDI_OUTPUT_WND_HC
: IDI_OUTPUT_WND
), IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), 0);
195 m_wndOutput
.SetIcon(hOutputBarIcon
, FALSE
);
197 HICON hPropertiesBarIcon
= (HICON
) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons
? IDI_PROPERTIES_WND_HC
: IDI_PROPERTIES_WND
), IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), 0);
198 m_wndProperties
.SetIcon(hPropertiesBarIcon
, FALSE
);
202 // CMainFrame diagnostics
205 void CMainFrame::AssertValid() const
207 CFrameWndEx::AssertValid();
210 void CMainFrame::Dump(CDumpContext
& dc
) const
212 CFrameWndEx::Dump(dc
);
217 // CMainFrame message handlers
219 void CMainFrame::OnViewCustomize()
221 CMFCToolBarsCustomizeDialog
* pDlgCust
= new CMFCToolBarsCustomizeDialog(this, TRUE
/* scan menus */);
222 pDlgCust
->EnableUserDefinedToolbars();
226 LRESULT
CMainFrame::OnToolbarCreateNew(WPARAM wp
,LPARAM lp
)
228 LRESULT lres
= CFrameWndEx::OnToolbarCreateNew(wp
,lp
);
234 CMFCToolBar
* pUserToolbar
= (CMFCToolBar
*)lres
;
235 ASSERT_VALID(pUserToolbar
);
238 CString strCustomize
;
239 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
242 pUserToolbar
->EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);
246 void CMainFrame::OnApplicationLook(UINT id
)
250 theApp
.m_nAppLook
= id
;
252 switch (theApp
.m_nAppLook
)
254 case ID_VIEW_APPLOOK_WIN_2000
:
255 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager
));
258 case ID_VIEW_APPLOOK_OFF_XP
:
259 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP
));
262 case ID_VIEW_APPLOOK_WIN_XP
:
263 CMFCVisualManagerWindows::m_b3DTabsXPTheme
= TRUE
;
264 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows
));
267 case ID_VIEW_APPLOOK_OFF_2003
:
268 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003
));
269 CDockingManager::SetDockingMode(DT_SMART
);
272 case ID_VIEW_APPLOOK_VS_2005
:
273 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005
));
274 CDockingManager::SetDockingMode(DT_SMART
);
278 switch (theApp
.m_nAppLook
)
280 case ID_VIEW_APPLOOK_OFF_2007_BLUE
:
281 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue
);
284 case ID_VIEW_APPLOOK_OFF_2007_BLACK
:
285 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack
);
288 case ID_VIEW_APPLOOK_OFF_2007_SILVER
:
289 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver
);
292 case ID_VIEW_APPLOOK_OFF_2007_AQUA
:
293 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua
);
297 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007
));
298 CDockingManager::SetDockingMode(DT_SMART
);
301 RedrawWindow(NULL
, NULL
, RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_UPDATENOW
| RDW_FRAME
| RDW_ERASE
);
303 theApp
.WriteInt(_T("ApplicationLook"), theApp
.m_nAppLook
);
306 void CMainFrame::OnUpdateApplicationLook(CCmdUI
* pCmdUI
)
308 pCmdUI
->SetRadio(theApp
.m_nAppLook
== pCmdUI
->m_nID
);
311 BOOL
CMainFrame::LoadFrame(UINT nIDResource
, DWORD dwDefaultStyle
, CWnd
* pParentWnd
, CCreateContext
* pContext
)
313 // base class does the real work
315 if (!CFrameWndEx::LoadFrame(nIDResource
, dwDefaultStyle
, pParentWnd
, pContext
))
320 // enable customization button for all user toolbars
322 CString strCustomize
;
323 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
326 for (int i
= 0; i
< iMaxUserToolbars
; i
++)
328 CMFCToolBar
* pUserToolbar
= GetUserToolBarByIndex(i
);
329 if (pUserToolbar
!= NULL
)
331 pUserToolbar
->EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);