From 2fa4d8fd0f2c29517025dfc3bebc8a5e07c3d380 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 13 Apr 2015 14:39:35 +0000 Subject: - nasty crutch removed from Options_AddPage; - HWND hwndParent removed from the CDlgBase constructor; - method CDlgBase::SetParent() added for the rare occasions where it's needed; git-svn-id: http://svn.miranda-ng.org/main/trunk@12785 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/commonheaders.h | 1 + src/mir_core/src/mir_core.def | 6 +-- src/mir_core/src/mir_core64.def | 7 ++-- src/mir_core/src/ui_utils.cpp | 8 ++-- src/modules/options/options.cpp | 92 ++++++++++++++++++++++------------------- 5 files changed, 61 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/core/commonheaders.h b/src/core/commonheaders.h index d07cae5cd4..d9841639e4 100644 --- a/src/core/commonheaders.h +++ b/src/core/commonheaders.h @@ -95,6 +95,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include "miranda.h" #include "stdplug.h" diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 8ddcd7f9ef..3809861dc2 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -641,9 +641,9 @@ mir_wstrcmpi @280 ??0CDbLink@@QAE@PBD0EK@Z @639 NONAME ??0CDbLink@@QAE@PBD0EPA_W@Z @640 NONAME ??0CDlgBase@@QAE@ABV0@@Z @641 NONAME -??0CDlgBase@@QAE@PAUHINSTANCE__@@HPAUHWND__@@@Z @642 NONAME +??0CDlgBase@@QAE@PAUHINSTANCE__@@H@Z @642 NONAME ??0CProtoIntDlgBase@@QAE@ABV0@@Z @643 NONAME -??0CProtoIntDlgBase@@QAE@PAUPROTO_INTERFACE@@HPAUHWND__@@_N@Z @644 NONAME +??0CProtoIntDlgBase@@QAE@PAUPROTO_INTERFACE@@H_N@Z @644 NONAME ??1CCtrlBase@@UAE@XZ @645 NONAME ??1CCtrlButton@@UAE@XZ @646 NONAME ??1CCtrlCheck@@UAE@XZ @647 NONAME @@ -739,7 +739,7 @@ mir_wstrcmpi @280 ?DlgProc@CDlgBase@@MAEHIIJ@Z @737 NONAME ?DlgProc@CProtoIntDlgBase@@MAEHIIJ@Z @738 NONAME ?DoModal@CDlgBase@@QAEHXZ @739 NONAME -?DynamicDlgProc@CDlgBase@@SGHPAUHWND__@@IIJ@Z @740 NONAME +?SetParent@CDlgBase@@QAEXPAUHWND__@@@Z @740 NONAME ?EditLabel@CCtrlClc@@QAEXPAX@Z @741 NONAME ?EditLabel@CCtrlListView@@QAEPAUHWND__@@H@Z @742 NONAME ?EditLabel@CCtrlTreeView@@QAEPAUHWND__@@PAU_TREEITEM@@@Z @743 NONAME diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index e934009cf4..0308488cca 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -641,9 +641,9 @@ mir_wstrcmpi @280 ??0CDbLink@@QEAA@PEBD0EK@Z @639 NONAME ??0CDbLink@@QEAA@PEBD0EPEA_W@Z @640 NONAME ??0CDlgBase@@QEAA@AEBV0@@Z @641 NONAME -??0CDlgBase@@QEAA@PEAUHINSTANCE__@@HPEAUHWND__@@@Z @642 NONAME +??0CDlgBase@@QEAA@PEAUHINSTANCE__@@H@Z @642 NONAME ??0CProtoIntDlgBase@@QEAA@AEBV0@@Z @643 NONAME -??0CProtoIntDlgBase@@QEAA@PEAUPROTO_INTERFACE@@HPEAUHWND__@@_N@Z @644 NONAME +??0CProtoIntDlgBase@@QEAA@PEAUPROTO_INTERFACE@@H_N@Z @644 NONAME ??1CCtrlBase@@UEAA@XZ @645 NONAME ??1CCtrlButton@@UEAA@XZ @646 NONAME ??1CCtrlCheck@@UEAA@XZ @647 NONAME @@ -739,7 +739,7 @@ mir_wstrcmpi @280 ?DlgProc@CDlgBase@@MEAA_JI_K_J@Z @737 NONAME ?DlgProc@CProtoIntDlgBase@@MEAA_JI_K_J@Z @738 NONAME ?DoModal@CDlgBase@@QEAAHXZ @739 NONAME -?DynamicDlgProc@CDlgBase@@SA_JPEAUHWND__@@I_K_J@Z @740 NONAME +?SetParent@CDlgBase@@QEAAXPEAUHWND__@@@Z @740 NONAME ?EditLabel@CCtrlClc@@QEAAXPEAX@Z @741 NONAME ?EditLabel@CCtrlListView@@QEAAPEAUHWND__@@H@Z @742 NONAME ?EditLabel@CCtrlTreeView@@QEAAPEAUHWND__@@PEAU_TREEITEM@@@Z @743 NONAME @@ -1074,3 +1074,4 @@ ProtoWindowAdd @1071 NONAME ProtoWindowRemove @1072 NONAME Proto_IsProtocolLoaded @1073 NONAME Proto_RegisterModule @1074 NONAME + diff --git a/src/mir_core/src/ui_utils.cpp b/src/mir_core/src/ui_utils.cpp index 22f46ea743..4f574896f8 100644 --- a/src/mir_core/src/ui_utils.cpp +++ b/src/mir_core/src/ui_utils.cpp @@ -29,12 +29,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma comment(lib, "uxtheme") -CDlgBase::CDlgBase(HINSTANCE hInst, int idDialog, HWND hwndParent) : +CDlgBase::CDlgBase(HINSTANCE hInst, int idDialog) : m_controls(1, CCtrlBase::cmp) { m_hInst = hInst; m_idDialog = idDialog; - m_hwndParent = hwndParent; + m_hwndParent = NULL; m_hwnd = NULL; m_first = NULL; m_isModal = false; @@ -1943,8 +1943,8 @@ void CDbLink::SaveText(TCHAR *value) ///////////////////////////////////////////////////////////////////////////////////////// // Base protocol dialog -CProtoIntDlgBase::CProtoIntDlgBase(PROTO_INTERFACE *proto, int idDialog, HWND parent, bool show_label) : - CDlgBase(::ProtoGetInstance(proto->m_szModuleName), idDialog, parent), +CProtoIntDlgBase::CProtoIntDlgBase(PROTO_INTERFACE *proto, int idDialog, bool show_label) : + CDlgBase(::ProtoGetInstance(proto->m_szModuleName), idDialog), m_proto_interface(proto), m_show_label(show_label), m_hwndStatus(NULL) diff --git a/src/modules/options/options.cpp b/src/modules/options/options.cpp index f9ae5965f7..48d33deb80 100644 --- a/src/modules/options/options.cpp +++ b/src/modules/options/options.cpp @@ -80,6 +80,7 @@ struct OptionsPageData int hLangpack; BOOL insideTab; LPARAM dwInitParam; + CDlgBase *pDialog; int offsetX; int offsetY; @@ -187,18 +188,6 @@ static void ThemeDialogBackground(HWND hwnd, BOOL tabbed) EnableThemeDialogTexture(hwnd, (tabbed ? ETDT_ENABLE : ETDT_DISABLE) | ETDT_USETABTEXTURE); } -static int lstrcmpnull(TCHAR *str1, TCHAR *str2) -{ - if (str1 == NULL && str2 == NULL) - return 0; - if (str1 != NULL && str2 == NULL) - return 1; - if (str1 == NULL && str2 != NULL) - return -1; - - return mir_tstrcmp(str1, str2); -} - static TCHAR* GetPluginName(HINSTANCE hInstance, TCHAR *buffer, int size) { TCHAR tszModuleName[MAX_PATH]; @@ -218,6 +207,18 @@ PageHash GetPluginPageHash(const OptionsPageData *page) return mir_hashstrT(page->ptszGroup) + mir_hashstrT(page->ptszTitle) + mir_hashstrT(page->ptszTab); } +static HWND CreateOptionWindow(const OptionsPageData *opd, HWND hWndParent) +{ + if (opd->pDialog != NULL) { + opd->pDialog->SetParent(hWndParent); + opd->pDialog->Create(); + return opd->pDialog->GetHwnd(); + } + + // create the options dialog page so we can parse it; + return CreateDialogIndirectParamA(opd->hInst, opd->pTemplate, hWndParent, opd->dlgProc, opd->dwInitParam); +} + static void FindFilterStrings(int enableKeywordFiltering, int current, HWND hWndParent, const OptionsPageData *page) { HWND hWnd = 0; @@ -225,7 +226,7 @@ static void FindFilterStrings(int enableKeywordFiltering, int current, HWND hWnd if (current) hWnd = page->hwnd; else { - hWnd = CreateDialogIndirectParamA(page->hInst, page->pTemplate, hWndParent, page->dlgProc, page->dwInitParam); //create the options dialog page so we can parse it + hWnd = CreateOptionWindow(page, hWndParent); ShowWindow(hWnd, SW_HIDE); // make sure it's hidden } } @@ -670,7 +671,7 @@ static BOOL IsInsideTab(HWND hdlg, OptionsDlgData *dat, int i) for (int j = 0; j < dat->arOpd.getCount() && pages < 2; j++) { OptionsPageData* opd2 = dat->arOpd[j]; if (!CheckPageShow(hdlg, dat, j)) continue; - if (mir_tstrcmp(opd2->ptszTitle, opd->ptszTitle) || lstrcmpnull(opd2->ptszGroup, opd->ptszGroup)) + if (mir_tstrcmp(opd2->ptszTitle, opd->ptszTitle) || mir_tstrcmp(opd2->ptszGroup, opd->ptszGroup)) continue; pages++; } @@ -680,38 +681,43 @@ static BOOL IsInsideTab(HWND hdlg, OptionsDlgData *dat, int i) static bool LoadOptionsPage(OPTIONSDIALOGPAGE *src, OptionsPageData *dst) { - HRSRC hrsrc = FindResourceA(src->hInstance, src->pszTemplate, MAKEINTRESOURCEA(5)); - if (hrsrc == NULL) - return false; - - HGLOBAL hglb = LoadResource(src->hInstance, hrsrc); - if (hglb == NULL) - return false; - - DWORD resSize = SizeofResource(src->hInstance, hrsrc); - dst->pTemplate = (DLGTEMPLATE*)mir_alloc(resSize); - memcpy(dst->pTemplate, LockResource(hglb), resSize); - DlgTemplateExBegin *dte = (struct DlgTemplateExBegin*)dst->pTemplate; - if (dte->signature == 0xFFFF) { - //this feels like an access violation, and is according to boundschecker - //...but it works - for now - //may well have to remove and sort out the original dialogs - dte->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER); - dte->style |= WS_CHILD; - } - else { - dst->pTemplate->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER); - dst->pTemplate->style |= WS_CHILD; + // old fashioned Windows dialog loading + if (src->hInstance != NULL && src->pszTemplate != NULL) { + HRSRC hrsrc = FindResourceA(src->hInstance, src->pszTemplate, MAKEINTRESOURCEA(5)); + if (hrsrc == NULL) + return false; + + HGLOBAL hglb = LoadResource(src->hInstance, hrsrc); + if (hglb == NULL) + return false; + + DWORD resSize = SizeofResource(src->hInstance, hrsrc); + dst->pTemplate = (DLGTEMPLATE*)mir_alloc(resSize); + memcpy(dst->pTemplate, LockResource(hglb), resSize); + DlgTemplateExBegin *dte = (struct DlgTemplateExBegin*)dst->pTemplate; + if (dte->signature == 0xFFFF) { + //this feels like an access violation, and is according to boundschecker + //...but it works - for now + //may well have to remove and sort out the original dialogs + dte->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER); + dte->style |= WS_CHILD; + } + else { + dst->pTemplate->style &= ~(WS_VISIBLE | WS_CHILD | WS_POPUP | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER); + dst->pTemplate->style |= WS_CHILD; + } + dst->hInst = src->hInstance; + dst->dlgProc = src->pfnDlgProc; + dst->dwInitParam = src->dwInitParam; } - dst->dlgProc = src->pfnDlgProc; - dst->hInst = src->hInstance; + else dst->pDialog = src->pDialog; + dst->hwnd = NULL; dst->changed = 0; dst->height = 0; dst->width = 0; dst->flags = src->flags; dst->hLangpack = src->hLangpack; - dst->dwInitParam = src->dwInitParam; if (src->pszTitle == NULL) dst->ptszTitle = NULL; else if (src->flags & ODPF_UNICODE) @@ -856,8 +862,8 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hdlg, UINT message, WPARAM wParam, L } dat->arOpd.insert(opd); - if (!mir_tstrcmp(lastPage, odp->ptszTitle) && !lstrcmpnull(lastGroup, odp->ptszGroup)) - if ((ood->pszTab == NULL && dat->currentPage == -1) || !lstrcmpnull(lastTab, odp->ptszTab)) + if (!mir_tstrcmp(lastPage, odp->ptszTitle) && !mir_tstrcmp(lastGroup, odp->ptszGroup)) + if ((ood->pszTab == NULL && dat->currentPage == -1) || !mir_tstrcmp(lastTab, odp->ptszTab)) dat->currentPage = (int)i; } @@ -970,7 +976,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hdlg, UINT message, WPARAM wParam, L break; } if (opd->hwnd == NULL) { - opd->hwnd = CreateDialogIndirectParamA(opd->hInst, opd->pTemplate, hdlg, opd->dlgProc, opd->dwInitParam); + opd->hwnd = CreateOptionWindow(opd, hdlg); if (opd->flags & ODPF_BOLDGROUPS) EnumChildWindows(opd->hwnd, BoldGroupTitlesEnumChildren, (LPARAM)dat->hBoldFont); @@ -1012,7 +1018,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hdlg, UINT message, WPARAM wParam, L continue; OptionsPageData *p = dat->arOpd[i]; - if (mir_tstrcmp(opd->ptszTitle, p->ptszTitle) || lstrcmpnull(opd->ptszGroup, p->ptszGroup)) + if (mir_tstrcmp(opd->ptszTitle, p->ptszTitle) || mir_tstrcmp(opd->ptszGroup, p->ptszGroup)) continue; tie.pszText = TranslateTH(p->hLangpack, p->ptszTab); -- cgit v1.2.3