diff options
author | George Hazan <george.hazan@gmail.com> | 2015-04-22 22:00:24 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-04-22 22:00:24 +0000 |
commit | baea5e8a4a56cb1d9cabd8f35554fd1c4eb24345 (patch) | |
tree | 3a2115658f4b563b8d017ac925ffd9c8d721acf5 | |
parent | d42da082183eb03b61075d4867f7c53bfedc506e (diff) |
- UI Utils not to use GWLP_USERDATA;
- minor improvements
git-svn-id: http://svn.miranda-ng.org/main/trunk@13044 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | bin10/lib/mir_core.lib | bin | 327828 -> 327496 bytes | |||
-rw-r--r-- | bin10/lib/mir_core64.lib | bin | 329558 -> 329216 bytes | |||
-rw-r--r-- | bin12/lib/mir_core.lib | bin | 327828 -> 327496 bytes | |||
-rw-r--r-- | bin12/lib/mir_core64.lib | bin | 329558 -> 329216 bytes | |||
-rw-r--r-- | include/m_gui.h | 47 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 1 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 1 | ||||
-rw-r--r-- | src/mir_core/src/ui_utils.cpp | 87 |
8 files changed, 73 insertions, 63 deletions
diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib Binary files differindex 7535a9fac8..5a9ff0446d 100644 --- a/bin10/lib/mir_core.lib +++ b/bin10/lib/mir_core.lib diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib Binary files differindex d98ec2d567..31c02b4c9e 100644 --- a/bin10/lib/mir_core64.lib +++ b/bin10/lib/mir_core64.lib diff --git a/bin12/lib/mir_core.lib b/bin12/lib/mir_core.lib Binary files differindex 7380ffd3a1..56b61f9db5 100644 --- a/bin12/lib/mir_core.lib +++ b/bin12/lib/mir_core.lib diff --git a/bin12/lib/mir_core64.lib b/bin12/lib/mir_core64.lib Binary files differindex f51de3c69a..b1f52a5f09 100644 --- a/bin12/lib/mir_core64.lib +++ b/bin12/lib/mir_core64.lib diff --git a/include/m_gui.h b/include/m_gui.h index e984743452..c85d53dd29 100644 --- a/include/m_gui.h +++ b/include/m_gui.h @@ -272,19 +272,16 @@ public: __forceinline bool IsInitialized() const { return m_initialized; }
__forceinline void SetParent(HWND hwnd) { m_hwndParent = hwnd; }
__forceinline void Close() { SendMessage(m_hwnd, WM_CLOSE, 0, 0); }
- __forceinline const MSG *ActiveMessage() const { return &m_msg; }
-
- LRESULT m_lresult;
protected:
+ HWND m_hwnd; // must be the first data item
HINSTANCE m_hInst;
- HWND m_hwnd;
HWND m_hwndParent;
int m_idDialog;
- MSG m_msg;
bool m_isModal;
bool m_initialized;
bool m_forceResizable;
+ LRESULT m_lresult;
enum { CLOSE_ON_OK = 0x1, CLOSE_ON_CANCEL = 0x2 };
BYTE m_autoClose; // automatically close dialog on IDOK/CANCEL commands. default: CLOSE_ON_OK|CLOSE_ON_CANCEL
@@ -331,7 +328,7 @@ class MIR_CORE_EXPORT CCtrlBase public:
CCtrlBase(CDlgBase *wnd, int idCtrl);
- virtual ~CCtrlBase() { Unsubclass(); }
+ virtual ~CCtrlBase() { }
__forceinline HWND GetHwnd() const { return m_hwnd; }
__forceinline int GetCtrlId() const { return m_idCtrl; }
@@ -376,7 +373,7 @@ public: }
protected:
- HWND m_hwnd;
+ HWND m_hwnd; // must be the first data item
int m_idCtrl;
CCtrlBase* m_next;
CDlgBase* m_parentWnd;
@@ -386,15 +383,7 @@ protected: void Unsubclass();
private:
- WNDPROC m_wndproc;
- static LRESULT CALLBACK GlobalSubclassWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- if (CCtrlBase *ctrl = (CCtrlBase*)GetWindowLongPtr(hwnd, GWLP_USERDATA))
- if (ctrl)
- return ctrl->CustomWndProc(msg, wParam, lParam);
-
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
+ static LRESULT CALLBACK GlobalSubclassWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -405,7 +394,7 @@ class MIR_CORE_EXPORT CCtrlButton : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlButton(CDlgBase* dlg, int ctrlId);
+ CCtrlButton(CDlgBase *dlg, int ctrlId);
virtual BOOL OnCommand(HWND hwndCtrl, WORD idCtrl, WORD idCode);
@@ -417,8 +406,8 @@ class MIR_CORE_EXPORT CCtrlMButton : public CCtrlButton typedef CCtrlButton CSuper;
public:
- CCtrlMButton(CDlgBase* dlg, int ctrlId, HICON hIcon, const char* tooltip);
- CCtrlMButton(CDlgBase* dlg, int ctrlId, int iCoreIcon, const char* tooltip);
+ CCtrlMButton(CDlgBase *dlg, int ctrlId, HICON hIcon, const char* tooltip);
+ CCtrlMButton(CDlgBase *dlg, int ctrlId, int iCoreIcon, const char* tooltip);
~CCtrlMButton();
void MakeFlat();
@@ -436,7 +425,7 @@ class MIR_CORE_EXPORT CCtrlHyperlink : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlHyperlink(CDlgBase* dlg, int ctrlId, const char* url);
+ CCtrlHyperlink(CDlgBase *dlg, int ctrlId, const char* url);
virtual BOOL OnCommand(HWND hwndCtrl, WORD idCtrl, WORD idCode);
@@ -451,7 +440,7 @@ class MIR_CORE_EXPORT CCtrlClc : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlClc(CDlgBase* dlg, int ctrlId);
+ CCtrlClc(CDlgBase *dlg, int ctrlId);
void AddContact(MCONTACT hContact);
void AddGroup(HANDLE hGroup);
@@ -531,7 +520,7 @@ class MIR_CORE_EXPORT CCtrlData : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlData(CDlgBase* dlg, int ctrlId);
+ CCtrlData(CDlgBase *dlg, int ctrlId);
virtual ~CCtrlData()
{
@@ -570,7 +559,7 @@ class MIR_CORE_EXPORT CCtrlCheck : public CCtrlData typedef CCtrlData CSuper;
public:
- CCtrlCheck(CDlgBase* dlg, int ctrlId);
+ CCtrlCheck(CDlgBase *dlg, int ctrlId);
virtual BOOL OnCommand(HWND /*hwndCtrl*/, WORD /*idCtrl*/, WORD /*idCode*/) { NotifyChange(); return TRUE; }
virtual void OnInit()
{
@@ -598,7 +587,7 @@ class MIR_CORE_EXPORT CCtrlEdit : public CCtrlData typedef CCtrlData CSuper;
public:
- CCtrlEdit(CDlgBase* dlg, int ctrlId);
+ CCtrlEdit(CDlgBase *dlg, int ctrlId);
virtual BOOL OnCommand(HWND /*hwndCtrl*/, WORD /*idCtrl*/, WORD idCode)
{
if (idCode == EN_CHANGE)
@@ -641,7 +630,7 @@ class MIR_CORE_EXPORT CCtrlListBox : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlListBox(CDlgBase* dlg, int ctrlId);
+ CCtrlListBox(CDlgBase *dlg, int ctrlId);
int AddString(TCHAR *text, LPARAM data=0);
void DeleteString(int index);
@@ -679,7 +668,7 @@ class MIR_CORE_EXPORT CCtrlCombo : public CCtrlData typedef CCtrlData CSuper;
public:
- CCtrlCombo(CDlgBase* dlg, int ctrlId);
+ CCtrlCombo(CDlgBase *dlg, int ctrlId);
virtual BOOL OnCommand(HWND /*hwndCtrl*/, WORD /*idCtrl*/, WORD idCode)
{
@@ -757,7 +746,7 @@ class MIR_CORE_EXPORT CCtrlListView : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlListView(CDlgBase* dlg, int ctrlId);
+ CCtrlListView(CDlgBase *dlg, int ctrlId);
// Classic LV interface
DWORD ApproximateViewRect(int cx, int cy, int iCount);
@@ -958,7 +947,7 @@ class MIR_CORE_EXPORT CCtrlTreeView : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlTreeView(CDlgBase* dlg, int ctrlId);
+ CCtrlTreeView(CDlgBase *dlg, int ctrlId);
// Classic TV interface
HIMAGELIST CreateDragImage(HTREEITEM hItem);
@@ -1066,7 +1055,7 @@ class MIR_CORE_EXPORT CCtrlPages : public CCtrlBase typedef CCtrlBase CSuper;
public:
- CCtrlPages(CDlgBase* dlg, int ctrlId);
+ CCtrlPages(CDlgBase *dlg, int ctrlId);
void AddPage(TCHAR *ptszName, HICON hIcon, CCallback<void> onCreate = CCallback<void>(), void *param = NULL);
void AttachDialog(int iPage, CDlgBase *pDlg);
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 8196e031dc..6935548cb0 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -696,7 +696,6 @@ mir_wstrcmpi @280 ??_7CDlgBase@@6B@ @694 NONAME
??_7CProtoIntDlgBase@@6B@ @695 NONAME
?ActivatePage@CCtrlPages@@QAEXH@Z @696 NONAME
-?ActiveMessage@CDlgBase@@QBEPBUtagMSG@@XZ @697 NONAME
?AddColumn@CCtrlListView@@QAEXHPA_WH@Z @698 NONAME
?AddContact@CCtrlClc@@QAEXI@Z @699 NONAME
?AddControl@CDlgBase@@IAEXPAVCCtrlBase@@@Z @700 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 6c7513dbbe..1e5e35b29c 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -696,7 +696,6 @@ mir_wstrcmpi @280 ??_7CDlgBase@@6B@ @694 NONAME
??_7CProtoIntDlgBase@@6B@ @695 NONAME
?ActivatePage@CCtrlPages@@QEAAXH@Z @696 NONAME
-?ActiveMessage@CDlgBase@@QEBAPEBUtagMSG@@XZ @697 NONAME
?AddColumn@CCtrlListView@@QEAAXHPEA_WH@Z @698 NONAME
?AddContact@CCtrlClc@@QEAAXI@Z @699 NONAME
?AddControl@CDlgBase@@IEAAXPEAVCCtrlBase@@@Z @700 NONAME
diff --git a/src/mir_core/src/ui_utils.cpp b/src/mir_core/src/ui_utils.cpp index 3411ada948..6912a5158c 100644 --- a/src/mir_core/src/ui_utils.cpp +++ b/src/mir_core/src/ui_utils.cpp @@ -27,6 +27,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_icolib.h>
#include <m_skin.h>
+static mir_cs csDialogs, csCtrl;
+
+static int CompareDialogs(const CDlgBase *p1, const CDlgBase *p2)
+{ return (INT_PTR)p1->GetHwnd() - (INT_PTR)p2->GetHwnd();
+}
+static LIST<CDlgBase> arDialogs(10, CompareDialogs);
+
+static int CompareDialogs(const CCtrlBase *p1, const CCtrlBase *p2)
+{ return (INT_PTR)p1->GetHwnd() - (INT_PTR)p2->GetHwnd();
+}
+static LIST<CCtrlBase> arControls(10, PtrKeySortT);
+
#pragma comment(lib, "uxtheme")
CDlgBase::CDlgBase(HINSTANCE hInst, int idDialog) :
@@ -180,8 +192,12 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) case WM_DESTROY:
OnDestroy();
NotifyControls(&CCtrlBase::OnDestroy);
-
- SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
+ {
+ mir_cslock lck(csDialogs);
+ int idx = arDialogs.getIndex(this);
+ if (idx != -1)
+ arDialogs.remove(idx);
+ }
m_hwnd = NULL;
if (m_isModal)
m_isModal = false;
@@ -198,19 +214,21 @@ INT_PTR CALLBACK CDlgBase::GlobalDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA {
CDlgBase *wnd = NULL;
if (msg == WM_INITDIALOG) {
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- wnd = (CDlgBase *)lParam;
+ wnd = (CDlgBase*)lParam;
wnd->m_hwnd = hwnd;
+
+ mir_cslock lck(csDialogs);
+ arDialogs.insert(wnd);
+ }
+ else {
+ PVOID bullshit[2]; // vfptr + hwnd
+ bullshit[1] = hwnd;
+ wnd = arDialogs.find((CDlgBase*)&bullshit);
}
- else wnd = (CDlgBase *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (!wnd)
+ if (wnd == NULL)
return FALSE;
- wnd->m_msg.hwnd = hwnd;
- wnd->m_msg.message = msg;
- wnd->m_msg.wParam = wParam;
- wnd->m_msg.lParam = lParam;
return wnd->DlgProc(msg, wParam, lParam);
}
@@ -1512,16 +1530,6 @@ HTREEITEM CCtrlTreeView::InsertItem(TVINSERTSTRUCT *tvis) { return TreeView_InsertItem(m_hwnd, tvis);
}
-/*
-HTREEITEM CCtrlTreeView::MapAccIDToHTREEITEM(UINT id)
-{ return TreeView_MapAccIDToHTREEITEM(m_hwnd, id);
-}
-
-UINT CCtrlTreeView::MapHTREEITEMtoAccID(HTREEITEM hItem)
-{ return TreeView_MapHTREEITEMtoAccID(m_hwnd, hItem);
-}
-
-*/
void CCtrlTreeView::Select(HTREEITEM hItem, DWORD flag)
{ TreeView_Select(m_hwnd, hItem, flag);
}
@@ -1761,8 +1769,7 @@ void CCtrlPages::OnDestroy() CCtrlBase::CCtrlBase(CDlgBase *wnd, int idCtrl) :
m_parentWnd(wnd),
m_idCtrl(idCtrl),
- m_hwnd(NULL),
- m_wndproc(NULL)
+ m_hwnd(NULL)
{
if (wnd) {
m_next = wnd->m_first;
@@ -1778,7 +1785,6 @@ void CCtrlBase::OnInit() void CCtrlBase::OnDestroy()
{
- Unsubclass();
m_hwnd = NULL;
}
@@ -1854,23 +1860,40 @@ int CCtrlBase::GetInt() LRESULT CCtrlBase::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
- if (msg == WM_DESTROY) Unsubclass();
- return CallWindowProc(m_wndproc, m_hwnd, msg, wParam, lParam);
+ return FALSE;
+}
+
+LRESULT CALLBACK CCtrlBase::GlobalSubclassWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ PVOID bullshit[2]; // vfptr + hwnd
+ bullshit[1] = hwnd;
+ CCtrlBase *pCtrl = arControls.find((CCtrlBase*)&bullshit);
+ if (pCtrl) {
+ LRESULT res = pCtrl->CustomWndProc(msg, wParam, lParam);
+ if (msg == WM_DESTROY) {
+ pCtrl->Unsubclass();
+ arControls.remove(pCtrl);
+ }
+
+ if (res != 0)
+ return res;
+ }
+
+ return mir_callNextSubclass(hwnd, GlobalSubclassWndProc, msg, wParam, lParam);
}
void CCtrlBase::Subclass()
{
- SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this);
- m_wndproc = (WNDPROC)SetWindowLongPtr(m_hwnd, GWLP_WNDPROC, (LONG_PTR)GlobalSubclassWndProc);
+ mir_subclassWindow(m_hwnd, GlobalSubclassWndProc);
+
+ mir_cslock lck(csCtrl);
+ arControls.insert(this);
}
void CCtrlBase::Unsubclass()
{
- if (m_wndproc) {
- SetWindowLongPtr(m_hwnd, GWLP_WNDPROC, (LONG_PTR)m_wndproc);
- SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
- m_wndproc = 0;
-} }
+ mir_unsubclassWindow(m_hwnd, GlobalSubclassWndProc);
+}
/////////////////////////////////////////////////////////////////////////////////////////
// CDbLink class
|