CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/W32Util/DialogManager.cpp
Views: 1401
1
#include "Common/CommonWindows.h"
2
#include <vector>
3
#include <algorithm>
4
#include "Windows/W32Util/DialogManager.h"
5
6
7
Dialog::Dialog(LPCSTR res, HINSTANCE _hInstance, HWND _hParent)
8
{
9
m_hInstance = _hInstance;
10
m_hParent = _hParent;
11
m_hResource = res;
12
m_bValid = true;
13
Create();
14
}
15
16
Dialog::~Dialog()
17
{
18
m_bValid = false;
19
Destroy();
20
}
21
22
void Dialog::Create()
23
{
24
m_hDlg = CreateDialogParam(m_hInstance, (LPCWSTR)m_hResource, m_hParent, DlgProcStatic, (LPARAM)this);
25
SetWindowLongPtr(m_hDlg, GWLP_USERDATA, (LONG_PTR)this);
26
}
27
28
void Dialog::Destroy()
29
{
30
DestroyWindow(m_hDlg);
31
}
32
33
void Dialog::Show(bool _bShow, bool includeToTop)
34
{
35
if (_bShow && includeToTop)
36
m_bShowState = SW_SHOWNORMAL;
37
else if (_bShow)
38
m_bShowState = SW_SHOWNOACTIVATE;
39
else
40
m_bShowState = SW_HIDE;
41
ShowWindow(m_hDlg, m_bShowState);
42
if (_bShow && includeToTop)
43
BringWindowToTop(m_hDlg);
44
}
45
46
INT_PTR Dialog::DlgProcStatic(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
47
{
48
Dialog *dis = (Dialog*)GetWindowLongPtr(hdlg, GWLP_USERDATA);
49
if (dis && dis->m_bValid)
50
return dis->DlgProc(message,wParam,lParam);
51
else
52
{
53
return 0;
54
/*
55
if (message == WM_INITDIALOG)
56
{
57
SetWindowLongPtr(hdlg, GWLP_USERDATA, (LONG_PTR)lParam);
58
return ((Dialog*)lParam)->DlgProc(message,wParam,lParam);
59
}
60
else
61
{
62
return 0;
63
}*/
64
}
65
}
66
67
68
typedef std::vector <Dialog *> WindowList;
69
WindowList dialogs;
70
71
72
void DialogManager::AddDlg(Dialog *dialog)
73
{
74
dialogs.push_back(dialog);
75
}
76
77
void DialogManager::RemoveDlg(Dialog *dialog)
78
{
79
if (!dialog) {
80
return;
81
}
82
dialogs.erase(std::remove(dialogs.begin(), dialogs.end(), dialog), dialogs.end());
83
}
84
85
86
bool DialogManager::IsDialogMessage(LPMSG message)
87
{
88
WindowList::iterator iter;
89
for (iter = dialogs.begin(); iter != dialogs.end(); iter++) {
90
if (::IsDialogMessage((*iter)->GetDlgHandle(), message))
91
return true;
92
}
93
return false;
94
}
95
96
97
void DialogManager::EnableAll(BOOL enable)
98
{
99
WindowList::iterator iter;
100
for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)
101
EnableWindow((*iter)->GetDlgHandle(),enable);
102
}
103
104
void DialogManager::UpdateAll()
105
{
106
WindowList::iterator iter;
107
for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)
108
(*iter)->Update();
109
}
110
111
void DialogManager::DestroyAll()
112
{
113
WindowList::iterator iter;
114
for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)
115
delete (*iter);
116
dialogs.clear();
117
}
118
119