forked from zodiacon/ObjectExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectPropertiesDlg.cpp
95 lines (82 loc) · 2.53 KB
/
ObjectPropertiesDlg.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
89
90
91
92
93
#include "pch.h"
#include "ObjectPropertiesDlg.h"
#include "ResourceManager.h"
#include "AppSettings.h"
bool CObjectPropertiesDlg::AddPage(PCWSTR title, HWND hPage) {
TabItem item;
item.Title = title;
item.win.Attach(hPage);
m_Pages.push_back(item);
return true;
}
bool CObjectPropertiesDlg::AddPage(PCWSTR title, HPROPSHEETPAGE hPage) {
TabItem item;
item.Title = title;
item.page.Attach((HWND)hPage);
m_Pages.push_back(item);
return true;
}
LRESULT CObjectPropertiesDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) {
InitDynamicLayout();
SetDialogIcon(ResourceManager::Get().GetTypeIcon(m_Type));
SetWindowText(m_Title);
m_Tabs.Attach(GetDlgItem(IDC_TABS));
CImageList images;
images.Create(16, 16, ILC_COLOR32 | ILC_MASK, 4, 2);
UINT icons[] = {
IDI_INFO, IDI_MAGNET, IDI_STRUCT,
};
for(auto icon : icons)
images.AddIcon(AtlLoadIconImage(icon, 0, 16, 16));
m_Tabs.SetImageList(images);
for(int i = 0; i < m_Pages.size(); i++) {
auto& page = m_Pages[i];
m_Tabs.AddItem(TCIF_TEXT | TCIF_IMAGE, page.Title, i, 0);
page.win.SetParent(m_hWnd);
}
m_Pages[0].win.ShowWindow(SW_SHOW);
m_Tabs.SetCurSel(m_SelectedPage = 0);
AppSettings::Get().LoadWindowPosition(m_hWnd, L"ObjectPropertiesDialog");
UpdateSize();
return 0;
}
LRESULT CObjectPropertiesDlg::OnTabChanged(int, LPNMHDR, BOOL&) {
int newPage = m_Tabs.GetCurSel();
if (m_SelectedPage >= 0) {
auto& win = m_Pages[m_SelectedPage].win;
win.ShowWindow(SW_HIDE);
}
auto& win = m_Pages[m_SelectedPage = newPage].win;
win.ShowWindow(SW_SHOW);
::SetParent(win.m_hWnd, m_hWnd);
win.UpdateWindow();
return 0;
}
LRESULT CObjectPropertiesDlg::OnOKCancel(WORD, WORD id, HWND, BOOL&) {
AppSettings::Get().SaveWindowPosition(m_hWnd, L"ObjectPropertiesDialog");
EndDialog(id);
return 0;
}
LRESULT CObjectPropertiesDlg::OnSize(UINT code, WPARAM wp, LPARAM lp, BOOL& handled) {
handled = FALSE;
UpdateSize();
return 0;
}
void CObjectPropertiesDlg::UpdateSize() {
if (m_SelectedPage >= 0) {
static int tabHeight = 0;
if (tabHeight == 0) {
CTabView view;
view.m_tab.Attach(m_Tabs);
tabHeight = view.CalcTabHeight();
}
CRect rc;
m_Tabs.GetWindowRect(&rc);
ScreenToClient(&rc);
rc.top += tabHeight;
rc.DeflateRect(2, 0);
rc.bottom -= 6;
for (auto& page : m_Pages)
page.win.MoveWindow(&rc);
}
}