Get rid of magic numbers
[TortoiseGit.git] / src / TortoiseMerge / Settings.cpp
blob3262669fa786e34edccf7289fdd0cfe770756622
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006, 2009-2010, 2014-2015, 2017-2018 - TortoiseSVN
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.
19 #include "stdafx.h"
20 #include "Settings.h"
21 #include "SetMainPage.h"
22 #include "SetColorPage.h"
24 int CALLBACK PropSheetProc(HWND /*hWndDlg*/, UINT uMsg, LPARAM lParam)
26 switch (uMsg)
28 case PSCB_PRECREATE:
30 auto pResource = reinterpret_cast<LPDLGTEMPLATE>(lParam);
31 CDialogTemplate dlgTemplate(pResource);
32 dlgTemplate.SetFont(L"MS Shell Dlg 2", 9);
33 memmove((void*)lParam, dlgTemplate.m_hTemplate, dlgTemplate.m_dwTemplateSize);
35 break;
37 return 0;
40 IMPLEMENT_DYNAMIC(CSettings, CPropertySheet)
41 CSettings::CSettings(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
42 : CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
43 , m_pMainPage(nullptr)
44 , m_pColorPage(nullptr)
48 CSettings::CSettings(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
49 : CPropertySheet(pszCaption, pParentWnd, iSelectPage)
50 , m_pMainPage(nullptr)
51 , m_pColorPage(nullptr)
53 AddPropPages();
56 CSettings::~CSettings()
58 RemovePropPages();
61 void CSettings::AddPropPages()
63 m_pMainPage = new CSetMainPage();
64 m_pColorPage = new CSetColorPage();
66 AddPage(m_pMainPage);
67 AddPage(m_pColorPage);
69 // remove the "apply" button: changes show only after the settings dialog
70 // is closed, so the OK button is enough and the "apply" button only
71 // confuses users.
72 m_psh.dwFlags |= PSH_NOAPPLYNOW;
73 m_psh.pfnCallback = PropSheetProc;
74 m_psh.dwFlags |= PSH_USECALLBACK;
77 void CSettings::RemovePropPages()
79 delete m_pMainPage;
80 m_pMainPage = nullptr;
81 delete m_pColorPage;
82 m_pColorPage = nullptr;
85 void CSettings::SaveData()
87 m_pMainPage->SaveData();
88 m_pColorPage->SaveData();
91 BOOL CSettings::IsReloadNeeded() const
93 BOOL bReload = FALSE;
94 bReload = (m_pMainPage->m_bReloadNeeded || bReload);
95 bReload = (m_pColorPage->m_bReloadNeeded || bReload);
96 return bReload;
99 BEGIN_MESSAGE_MAP(CSettings, CPropertySheet)
100 END_MESSAGE_MAP()
103 // CSettings message handlers
105 BOOL CSettings::OnInitDialog()
107 BOOL bResult = CPropertySheet::OnInitDialog();
108 return bResult;