OSDN Git Service

TortoiseGitBlame Add next & prev toolbar button.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseGitBlame / MainFrm.cpp
1 \r
2 // MainFrm.cpp : implementation of the CMainFrame class\r
3 //\r
4 \r
5 #include "stdafx.h"\r
6 #include "TortoiseGitBlame.h"\r
7 \r
8 #include "MainFrm.h"\r
9 \r
10 #ifdef _DEBUG\r
11 #define new DEBUG_NEW\r
12 #endif\r
13 \r
14 // CMainFrame\r
15 \r
16 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)\r
17 \r
18 const int  iMaxUserToolbars = 10;\r
19 const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;\r
20 const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;\r
21 \r
22 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)\r
23         ON_WM_CREATE()\r
24         // Global help commands\r
25         ON_COMMAND(ID_HELP_FINDER, &CFrameWndEx::OnHelpFinder)\r
26         ON_COMMAND(ID_HELP, &CFrameWndEx::OnHelp)\r
27         ON_COMMAND(ID_CONTEXT_HELP, &CFrameWndEx::OnContextHelp)\r
28         ON_COMMAND(ID_DEFAULT_HELP, &CFrameWndEx::OnHelpFinder)\r
29         ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize)\r
30         ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew)\r
31         ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnApplicationLook)\r
32         ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnUpdateApplicationLook)\r
33 END_MESSAGE_MAP()\r
34 \r
35 static UINT indicators[] =\r
36 {\r
37         ID_SEPARATOR,           // status line indicator\r
38         ID_INDICATOR_CAPS,\r
39         ID_INDICATOR_NUM,\r
40         ID_INDICATOR_SCRL,\r
41 };\r
42 \r
43 // CMainFrame construction/destruction\r
44 \r
45 CMainFrame::CMainFrame()\r
46 {\r
47         // TODO: add member initialization code here\r
48         theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2005);\r
49 }\r
50 \r
51 CMainFrame::~CMainFrame()\r
52 {\r
53 }\r
54 \r
55 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)\r
56 {\r
57         if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)\r
58                 return -1;\r
59 \r
60         BOOL bNameValid;\r
61         // set the visual manager and style based on persisted value\r
62         OnApplicationLook(theApp.m_nAppLook);\r
63 \r
64         if (!m_wndMenuBar.Create(this))\r
65         {\r
66                 TRACE0("Failed to create menubar\n");\r
67                 return -1;      // fail to create\r
68         }\r
69 \r
70         m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);\r
71 \r
72         // prevent the menu bar from taking the focus on activation\r
73         CMFCPopupMenu::SetForceMenuFocus(FALSE);\r
74 \r
75         if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||\r
76                 !m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_TORTOISE_GIT_BLAME_MAINFRAME_256 : IDR_TORTOISE_GIT_BLAME_MAINFRAME))\r
77         {\r
78                 TRACE0("Failed to create toolbar\n");\r
79                 return -1;      // fail to create\r
80         }\r
81 \r
82         CString strToolBarName;\r
83         bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);\r
84         ASSERT(bNameValid);\r
85         m_wndToolBar.SetWindowText(strToolBarName);\r
86 \r
87         CString strCustomize;\r
88         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);\r
89         ASSERT(bNameValid);\r
90         m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);\r
91 \r
92         // Allow user-defined toolbars operations:\r
93         InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);\r
94 \r
95         if (!m_wndStatusBar.Create(this))\r
96         {\r
97                 TRACE0("Failed to create status bar\n");\r
98                 return -1;      // fail to create\r
99         }\r
100         m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));\r
101 \r
102         // TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable\r
103         m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);\r
104         m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);\r
105         EnableDocking(CBRS_ALIGN_ANY);\r
106         DockPane(&m_wndMenuBar);\r
107         DockPane(&m_wndToolBar);\r
108 \r
109 \r
110         // enable Visual Studio 2005 style docking window behavior\r
111         CDockingManager::SetDockingMode(DT_SMART);\r
112         // enable Visual Studio 2005 style docking window auto-hide behavior\r
113         EnableAutoHidePanes(CBRS_ALIGN_ANY);\r
114 \r
115         // create docking windows\r
116         if (!CreateDockingWindows())\r
117         {\r
118                 TRACE0("Failed to create docking windows\n");\r
119                 return -1;\r
120         }\r
121 \r
122         m_wndOutput.EnableDocking(CBRS_ALIGN_ANY);\r
123         DockPane(&m_wndOutput);\r
124         m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);\r
125         DockPane(&m_wndProperties);\r
126 \r
127 \r
128         // Enable toolbar and docking window menu replacement\r
129         EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);\r
130 \r
131         // enable quick (Alt+drag) toolbar customization\r
132         CMFCToolBar::EnableQuickCustomization();\r
133 \r
134         if (CMFCToolBar::GetUserImages() == NULL)\r
135         {\r
136                 // load user-defined toolbar images\r
137                 if (m_UserImages.Load(_T(".\\UserImages.bmp")))\r
138                 {\r
139                         m_UserImages.SetImageSize(CSize(16, 16), FALSE);\r
140                         CMFCToolBar::SetUserImages(&m_UserImages);\r
141                 }\r
142         }\r
143 \r
144         // enable menu personalization (most-recently used commands)\r
145         // TODO: define your own basic commands, ensuring that each pulldown menu has at least one basic command.\r
146         CList<UINT, UINT> lstBasicCommands;\r
147 \r
148         lstBasicCommands.AddTail(ID_FILE_NEW);\r
149         lstBasicCommands.AddTail(ID_FILE_OPEN);\r
150         lstBasicCommands.AddTail(ID_FILE_SAVE);\r
151         lstBasicCommands.AddTail(ID_VIEW_NEXT);\r
152         lstBasicCommands.AddTail(ID_VIEW_PREV);\r
153         lstBasicCommands.AddTail(ID_FILE_PRINT);\r
154         lstBasicCommands.AddTail(ID_APP_EXIT);\r
155         lstBasicCommands.AddTail(ID_EDIT_CUT);\r
156         lstBasicCommands.AddTail(ID_EDIT_PASTE);\r
157         lstBasicCommands.AddTail(ID_EDIT_UNDO);\r
158         lstBasicCommands.AddTail(ID_APP_ABOUT);\r
159         lstBasicCommands.AddTail(ID_VIEW_STATUS_BAR);\r
160         lstBasicCommands.AddTail(ID_VIEW_TOOLBAR);\r
161         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2003);\r
162         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_VS_2005);\r
163         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLUE);\r
164         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_SILVER);\r
165         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLACK);\r
166         lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_AQUA);\r
167 \r
168         CMFCToolBar::SetBasicCommands(lstBasicCommands);\r
169 \r
170         return 0;\r
171 }\r
172 \r
173 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)\r
174 {\r
175         if( !CFrameWndEx::PreCreateWindow(cs) )\r
176                 return FALSE;\r
177         // TODO: Modify the Window class or styles here by modifying\r
178         //  the CREATESTRUCT cs\r
179 \r
180         return TRUE;\r
181 }\r
182 \r
183 BOOL CMainFrame::CreateDockingWindows()\r
184 {\r
185         BOOL bNameValid;\r
186         // Create output window\r
187         CString strOutputWnd;\r
188         bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);\r
189         ASSERT(bNameValid);\r
190         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))\r
191         {\r
192                 TRACE0("Failed to create Output window\n");\r
193                 return FALSE; // failed to create\r
194         }\r
195 \r
196         // Create properties window\r
197         CString strPropertiesWnd;\r
198         bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);\r
199         ASSERT(bNameValid);\r
200         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))\r
201         {\r
202                 TRACE0("Failed to create Properties window\n");\r
203                 return FALSE; // failed to create\r
204         }\r
205 \r
206         SetDockingWindowIcons(theApp.m_bHiColorIcons);\r
207         return TRUE;\r
208 }\r
209 \r
210 void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)\r
211 {\r
212         HICON hOutputBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_OUTPUT_WND_HC : IDI_OUTPUT_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);\r
213         m_wndOutput.SetIcon(hOutputBarIcon, FALSE);\r
214 \r
215         HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);\r
216         m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);\r
217 \r
218 }\r
219 \r
220 // CMainFrame diagnostics\r
221 \r
222 #ifdef _DEBUG\r
223 void CMainFrame::AssertValid() const\r
224 {\r
225         CFrameWndEx::AssertValid();\r
226 }\r
227 \r
228 void CMainFrame::Dump(CDumpContext& dc) const\r
229 {\r
230         CFrameWndEx::Dump(dc);\r
231 }\r
232 #endif //_DEBUG\r
233 \r
234 \r
235 // CMainFrame message handlers\r
236 \r
237 void CMainFrame::OnViewCustomize()\r
238 {\r
239         CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* scan menus */);\r
240         pDlgCust->EnableUserDefinedToolbars();\r
241         pDlgCust->Create();\r
242 }\r
243 \r
244 LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)\r
245 {\r
246         LRESULT lres = CFrameWndEx::OnToolbarCreateNew(wp,lp);\r
247         if (lres == 0)\r
248         {\r
249                 return 0;\r
250         }\r
251 \r
252         CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres;\r
253         ASSERT_VALID(pUserToolbar);\r
254 \r
255         BOOL bNameValid;\r
256         CString strCustomize;\r
257         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);\r
258         ASSERT(bNameValid);\r
259 \r
260         pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);\r
261         return lres;\r
262 }\r
263 \r
264 void CMainFrame::OnApplicationLook(UINT id)\r
265 {\r
266         CWaitCursor wait;\r
267 \r
268         theApp.m_nAppLook = id;\r
269 \r
270         switch (theApp.m_nAppLook)\r
271         {\r
272         case ID_VIEW_APPLOOK_WIN_2000:\r
273                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));\r
274                 break;\r
275 \r
276         case ID_VIEW_APPLOOK_OFF_XP:\r
277                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));\r
278                 break;\r
279 \r
280         case ID_VIEW_APPLOOK_WIN_XP:\r
281                 CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;\r
282                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));\r
283                 break;\r
284 \r
285         case ID_VIEW_APPLOOK_OFF_2003:\r
286                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));\r
287                 CDockingManager::SetDockingMode(DT_SMART);\r
288                 break;\r
289 \r
290         case ID_VIEW_APPLOOK_VS_2005:\r
291                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));\r
292                 CDockingManager::SetDockingMode(DT_SMART);\r
293                 break;\r
294 \r
295         default:\r
296                 switch (theApp.m_nAppLook)\r
297                 {\r
298                 case ID_VIEW_APPLOOK_OFF_2007_BLUE:\r
299                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);\r
300                         break;\r
301 \r
302                 case ID_VIEW_APPLOOK_OFF_2007_BLACK:\r
303                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);\r
304                         break;\r
305 \r
306                 case ID_VIEW_APPLOOK_OFF_2007_SILVER:\r
307                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);\r
308                         break;\r
309 \r
310                 case ID_VIEW_APPLOOK_OFF_2007_AQUA:\r
311                         CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);\r
312                         break;\r
313                 }\r
314 \r
315                 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));\r
316                 CDockingManager::SetDockingMode(DT_SMART);\r
317         }\r
318 \r
319         RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);\r
320 \r
321         theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);\r
322 }\r
323 \r
324 void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)\r
325 {\r
326         pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);\r
327 }\r
328 \r
329 BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) \r
330 {\r
331         // base class does the real work\r
332 \r
333         if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))\r
334         {\r
335                 return FALSE;\r
336         }\r
337 \r
338 \r
339         // enable customization button for all user toolbars\r
340         BOOL bNameValid;\r
341         CString strCustomize;\r
342         bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);\r
343         ASSERT(bNameValid);\r
344 \r
345         for (int i = 0; i < iMaxUserToolbars; i ++)\r
346         {\r
347                 CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);\r
348                 if (pUserToolbar != NULL)\r
349                 {\r
350                         pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);\r
351                 }\r
352         }\r
353 \r
354         return TRUE;\r
355 }\r
356 \r