1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2016-2018 - 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_REGISTERED_MESSAGE(TaskBarButtonCreated
, &CMainFrame::OnTaskbarButtonCreated
)
55 static UINT indicators
[] =
57 ID_SEPARATOR
, // status line indicator
58 ID_INDICATOR_ENCODING
,
62 // CMainFrame construction/destruction
64 CMainFrame::CMainFrame()
68 CMainFrame::~CMainFrame()
72 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct
)
74 if (CFrameWndEx::OnCreate(lpCreateStruct
) == -1)
79 if (!m_wndMenuBar
.Create(this))
81 TRACE0("Failed to create menubar\n");
82 return -1; // fail to create
85 m_wndMenuBar
.SetPaneStyle(m_wndMenuBar
.GetPaneStyle() | CBRS_SIZE_DYNAMIC
| CBRS_TOOLTIPS
| CBRS_FLYBY
);
87 // prevent the menu bar from taking the focus on activation
88 CMFCPopupMenu::SetForceMenuFocus(FALSE
);
90 if (!m_wndToolBar
.CreateEx(this, TBSTYLE_FLAT
, WS_CHILD
| WS_VISIBLE
| CBRS_TOP
| CBRS_GRIPPER
| CBRS_TOOLTIPS
| CBRS_FLYBY
| CBRS_SIZE_DYNAMIC
) ||
91 !m_wndToolBar
.LoadToolBar(theApp
.m_bHiColorIcons
? IDR_TORTOISE_GIT_BLAME_MAINFRAME_256
: IDR_TORTOISE_GIT_BLAME_MAINFRAME
))
93 TRACE0("Failed to create toolbar\n");
94 return -1; // fail to create
97 CString strToolBarName
;
98 bNameValid
= strToolBarName
.LoadString(IDS_TOOLBAR_STANDARD
);
100 m_wndToolBar
.SetWindowText(strToolBarName
);
102 CString strCustomize
;
103 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
105 m_wndToolBar
.EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);
107 // Allow user-defined toolbars operations:
108 InitUserToolbars(nullptr, uiFirstUserToolBarId
, uiLastUserToolBarId
);
110 if (!m_wndStatusBar
.Create(this))
112 TRACE0("Failed to create status bar\n");
113 return -1; // fail to create
115 m_wndStatusBar
.SetIndicators(indicators
, _countof(indicators
));
117 // Delete these five lines if you don't want the toolbar and menubar to be dockable
118 m_wndMenuBar
.EnableDocking(CBRS_ALIGN_ANY
);
119 m_wndToolBar
.EnableDocking(CBRS_ALIGN_ANY
);
120 EnableDocking(CBRS_ALIGN_ANY
);
121 DockPane(&m_wndMenuBar
);
122 DockPane(&m_wndToolBar
);
125 // enable Visual Studio 2005 style docking window behavior
126 CDockingManager::SetDockingMode(DT_SMART
);
127 // enable Visual Studio 2005 style docking window auto-hide behavior
128 EnableAutoHidePanes(CBRS_ALIGN_ANY
);
130 // create docking windows
131 if (!CreateDockingWindows())
133 TRACE0("Failed to create docking windows\n");
137 m_wndOutput
.EnableDocking(CBRS_ALIGN_ANY
);
138 DockPane(&m_wndOutput
);
139 m_wndProperties
.EnableDocking(CBRS_ALIGN_ANY
);
140 DockPane(&m_wndProperties
);
143 // Enable toolbar and docking window menu replacement
144 EnablePaneMenu(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
, ID_VIEW_TOOLBAR
);
146 // enable quick (Alt+drag) toolbar customization
147 CMFCToolBar::EnableQuickCustomization();
152 LRESULT
CMainFrame::OnTaskbarButtonCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
154 SetUUIDOverlayIcon(m_hWnd
);
158 BOOL
CMainFrame::PreCreateWindow(CREATESTRUCT
& cs
)
160 if( !CFrameWndEx::PreCreateWindow(cs
) )
162 // TODO: Modify the Window class or styles here by modifying
163 // the CREATESTRUCT cs
168 BOOL
CMainFrame::CreateDockingWindows()
171 // Create output window
172 CString strOutputWnd
;
173 bNameValid
= strOutputWnd
.LoadString(IDS_OUTPUT_WND
);
175 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
))
177 TRACE0("Failed to create Output window\n");
178 return FALSE
; // failed to create
181 // Create properties window
182 CString strPropertiesWnd
;
183 bNameValid
= strPropertiesWnd
.LoadString(IDS_PROPERTIES_WND
);
185 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
))
187 TRACE0("Failed to create Properties window\n");
188 return FALSE
; // failed to create
191 SetDockingWindowIcons(theApp
.m_bHiColorIcons
);
195 void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons
)
197 HICON hOutputBarIcon
= (HICON
) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons
? IDI_OUTPUT_WND_HC
: IDI_OUTPUT_WND
), IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), 0);//todo
198 m_wndOutput
.SetIcon(hOutputBarIcon
, FALSE
);
200 HICON hPropertiesBarIcon
= (HICON
) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons
? IDI_PROPERTIES_WND_HC
: IDI_PROPERTIES_WND
), IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), 0);//todo
201 m_wndProperties
.SetIcon(hPropertiesBarIcon
, FALSE
);
204 // CMainFrame diagnostics
207 void CMainFrame::AssertValid() const
209 CFrameWndEx::AssertValid();
212 void CMainFrame::Dump(CDumpContext
& dc
) const
214 CFrameWndEx::Dump(dc
);
219 // CMainFrame message handlers
221 void CMainFrame::OnUpdateHelpFinder(CCmdUI
*pCmdUI
)
223 pCmdUI
->Enable(FALSE
);
226 void CMainFrame::OnViewCustomize()
228 CMFCToolBarsCustomizeDialog
* pDlgCust
= new CMFCToolBarsCustomizeDialog(this, TRUE
/* scan menus */);
229 pDlgCust
->EnableUserDefinedToolbars();
233 LRESULT
CMainFrame::OnToolbarCreateNew(WPARAM wp
,LPARAM lp
)
235 LRESULT lres
= CFrameWndEx::OnToolbarCreateNew(wp
,lp
);
239 CMFCToolBar
* pUserToolbar
= (CMFCToolBar
*)lres
;
240 ASSERT_VALID(pUserToolbar
);
243 CString strCustomize
;
244 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
247 pUserToolbar
->EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);
251 BOOL
CMainFrame::LoadFrame(UINT nIDResource
, DWORD dwDefaultStyle
, CWnd
* pParentWnd
, CCreateContext
* pContext
)
253 // base class does the real work
255 if (!CFrameWndEx::LoadFrame(nIDResource
, dwDefaultStyle
, pParentWnd
, pContext
))
258 // enable customization button for all user toolbars
260 CString strCustomize
;
261 bNameValid
= strCustomize
.LoadString(IDS_TOOLBAR_CUSTOMIZE
);
264 for (int i
= 0; i
< iMaxUserToolbars
; ++i
)
266 CMFCToolBar
* pUserToolbar
= GetUserToolBarByIndex(i
);
268 pUserToolbar
->EnableCustomizeButton(TRUE
, ID_VIEW_CUSTOMIZE
, strCustomize
);