Get rid of magic numbers
[TortoiseGit.git] / src / TortoiseMerge / Settings.h
blob72195a8c814dc334e1946a71bd550cd8700fcd70
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2018 - TortoiseGit
4 // Copyright (C) 2006, 2009, 2015, 2018 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
22 class CSetMainPage;
23 class CSetColorPage;
25 /**
26 * \ingroup TortoiseMerge
27 * This is the container for all settings pages. A setting page is
28 * a class derived from CPropertyPage with an additional method called
29 * SaveData(). The SaveData() method is used by the dialog to save
30 * the settings the user has made - if that method is not called then
31 * it means that the changes are discarded! Each settings page has
32 * to make sure that no changes are saved outside that method.
35 class CSettings : public CPropertySheet
37 DECLARE_DYNAMIC(CSettings)
38 private:
39 /**
40 * Adds all pages to this Settings-Dialog.
42 void AddPropPages();
43 /**
44 * Removes the pages and frees up memory.
46 void RemovePropPages();
48 void BuildPropPageArray() override
50 CPropertySheet::BuildPropPageArray();
52 // create a copy of existing PROPSHEETPAGE array which can be modified
53 int nPages = static_cast<int>(m_pages.GetSize());
54 int nBytes = 0;
55 for (decltype(nPages) i = 0; i < nPages; ++i)
57 auto pPage = GetPage(i);
58 nBytes += pPage->m_psp.dwSize;
60 auto ppsp0 = static_cast<LPPROPSHEETPAGE>(malloc(nBytes));
61 Checked::memcpy_s(ppsp0, nBytes, m_psh.ppsp, nBytes);
62 auto ppsp = ppsp0;
63 for (decltype(nPages) i = 0; i < nPages; ++i)
65 const DLGTEMPLATE* pResource = ppsp->pResource;
66 CDialogTemplate dlgTemplate(pResource);
67 dlgTemplate.SetFont(L"MS Shell Dlg 2", 9);
68 HGLOBAL hNew = GlobalAlloc(GPTR, dlgTemplate.m_dwTemplateSize);
69 ppsp->pResource = (DLGTEMPLATE*)GlobalLock(hNew);
70 Checked::memcpy_s((void*)ppsp->pResource, dlgTemplate.m_dwTemplateSize, dlgTemplate.m_hTemplate, dlgTemplate.m_dwTemplateSize);
71 GlobalUnlock(hNew);
72 (BYTE*&)ppsp += ppsp->dwSize;
74 // free existing PROPSHEETPAGE array and assign the new one
75 free((void*)m_psh.ppsp);
76 m_psh.ppsp = ppsp0;
79 CSetMainPage * m_pMainPage;
80 CSetColorPage * m_pColorPage;
82 public:
83 CSettings(UINT nIDCaption, CWnd* pParentWnd = nullptr, UINT iSelectPage = 0);
84 CSettings(LPCTSTR pszCaption, CWnd* pParentWnd = nullptr, UINT iSelectPage = 0);
85 virtual ~CSettings();
87 /**
88 * Calls the SaveData()-methods of each of the settings pages.
90 void SaveData();
92 BOOL IsReloadNeeded() const;
93 protected:
94 DECLARE_MESSAGE_MAP()
95 virtual BOOL OnInitDialog();