forked from EasyIME/libIME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyDialog.cpp
88 lines (73 loc) · 2.59 KB
/
PropertyDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Copyright (C) 2013 Hong Jen Yee (PCMan) <[email protected]>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA 02110-1301, USA.
//
#include "PropertyDialog.h"
#include "PropertyPage.h"
#include <assert.h>
#include <algorithm>
using namespace std;
namespace Ime {
//typedef INT_PTR (WINAPI *PropertySheetFunc)(LPCPROPSHEETHEADER lppsph);
//static PropertySheetFunc g_PropertySheetW = NULL;
PropertyDialog::PropertyDialog(void) {
}
PropertyDialog::~PropertyDialog(void) {
if(!pages_.empty()) {
for(vector<PropertyPage*>::iterator it = pages_.begin(); it != pages_.end(); ++it) {
PropertyPage* page = *it;
delete page;
}
}
}
INT_PTR PropertyDialog::showModal(HINSTANCE hInstance, LPCTSTR captionId, LPCTSTR iconId, HWND parent, DWORD flags) {
assert(pages_.size() > 0);
// Windows 8 does not allow linking to comctl32.dll
// when running in app containers.
// We use LoadLibrary here, but this should only be used in desktop app mode.
// if(!g_PropertySheetW) {
// HMODULE mod = ::LoadLibraryW(L"comctl32.dll");
// g_PropertySheetW = (PropertySheetFunc)::GetProcAddress(mod, "PropertySheetW");
// }
PROPSHEETPAGE* pages = new PROPSHEETPAGE[pages_.size()];
for(size_t i = 0; i < pages_.size(); ++i) {
pages_[i]->setup(pages[i]);
pages[i].hInstance = hInstance;
}
PROPSHEETHEADER psh = {0};
psh.dwFlags = flags;
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.hInstance = hInstance;
psh.hwndParent = parent;
psh.pszIcon = (LPCTSTR)iconId;
psh.nPages = pages_.size();
psh.ppsp = pages;
psh.pszCaption = (LPCTSTR)captionId;
// INT_PTR result = g_PropertySheetW(&psh);
INT_PTR result =::PropertySheetW(&psh);
delete []pages;
return result;
}
void PropertyDialog::addPage(PropertyPage* page) {
pages_.push_back(page);
}
void PropertyDialog::removePage(PropertyPage* page) {
vector<PropertyPage*>::iterator it = std::find(pages_.begin(), pages_.end(), page);
if(it != pages_.end())
pages_.erase(it);
}
} // namespace Ime