From 5fea43e9b07b966fe023105bfd9a224bfbb00e7b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 10 Dec 2016 15:50:53 +0300 Subject: - ability to pass a button's text to a toolbar button; - common code moved into the core --- bin10/lib/mir_app.lib | Bin 89726 -> 89986 bytes bin10/lib/mir_app64.lib | Bin 85620 -> 85860 bytes bin12/lib/mir_app.lib | Bin 89726 -> 89986 bytes bin12/lib/mir_app64.lib | Bin 85620 -> 85860 bytes bin14/lib/mir_app.lib | Bin 89726 -> 89986 bytes bin14/lib/mir_app64.lib | Bin 85620 -> 85860 bytes include/m_message.h | 22 ++++--- .../MirLua/Modules/m_msg_buttonsbar/src/main.cpp | 4 +- plugins/Scriver/src/chat/window.cpp | 13 +--- plugins/Scriver/src/msgdialog.cpp | 14 +---- plugins/TabSRMM/src/buttonsbar.cpp | 70 +++++++++++---------- src/core/stdmsg/src/chat_window.cpp | 13 +--- src/core/stdmsg/src/msgdialog.cpp | 13 +--- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/srmm_toolbar.cpp | 30 +++++++++ 16 files changed, 89 insertions(+), 92 deletions(-) diff --git a/bin10/lib/mir_app.lib b/bin10/lib/mir_app.lib index 7cb342352d..d3189234bb 100644 Binary files a/bin10/lib/mir_app.lib and b/bin10/lib/mir_app.lib differ diff --git a/bin10/lib/mir_app64.lib b/bin10/lib/mir_app64.lib index 6b78833ac8..7bb2057b6e 100644 Binary files a/bin10/lib/mir_app64.lib and b/bin10/lib/mir_app64.lib differ diff --git a/bin12/lib/mir_app.lib b/bin12/lib/mir_app.lib index 7cb342352d..d3189234bb 100644 Binary files a/bin12/lib/mir_app.lib and b/bin12/lib/mir_app.lib differ diff --git a/bin12/lib/mir_app64.lib b/bin12/lib/mir_app64.lib index 6b78833ac8..7bb2057b6e 100644 Binary files a/bin12/lib/mir_app64.lib and b/bin12/lib/mir_app64.lib differ diff --git a/bin14/lib/mir_app.lib b/bin14/lib/mir_app.lib index 7cb342352d..d3189234bb 100644 Binary files a/bin14/lib/mir_app.lib and b/bin14/lib/mir_app.lib differ diff --git a/bin14/lib/mir_app64.lib b/bin14/lib/mir_app64.lib index 6b78833ac8..7bb2057b6e 100644 Binary files a/bin14/lib/mir_app64.lib and b/bin14/lib/mir_app64.lib differ diff --git a/include/m_message.h b/include/m_message.h index 6136e50676..9df503b6d0 100644 --- a/include/m_message.h +++ b/include/m_message.h @@ -238,14 +238,15 @@ struct StatusIconClickData struct BBButton { - char *pszModuleName; // module name without spaces and underline symbols (e.g. "tabsrmm") - DWORD dwButtonID; // your button ID, will be combined with pszModuleName for storing settings, etc... - - wchar_t *pwszTooltip; - DWORD dwDefPos; // default order pos of button, counted from window edge (left or right) - // use value >100, because internal buttons using 10,20,30... 80, etc - DWORD bbbFlags; // combine of BBBF_ flags above - HANDLE hIcon; // Handle to icolib registered icon + const char *pszModuleName; // module name without spaces and underline symbols (e.g. "tabsrmm") + DWORD dwButtonID; // your button ID, will be combined with pszModuleName for storing settings, etc... + + const wchar_t *pwszText; // button's text, might be NULL + const wchar_t *pwszTooltip; // button's tooltip, might be NULL + DWORD dwDefPos; // default order pos of button, counted from window edge (left or right) + // use value >100, because internal buttons using 10,20,30... 80, etc + DWORD bbbFlags; // combine of BBBF_ flags above + HANDLE hIcon; // Handle to icolib registered icon }; // adds a new toolbar button @@ -272,6 +273,10 @@ EXTERN_C MIR_APP_DLL(int) Srmm_SetButtonState(MCONTACT hContact, BBButton *bbdi) // returns 0 on success and nonzero value otherwise EXTERN_C MIR_APP_DLL(void) Srmm_ResetToolbar(); +// creates toolbar buttons for a SRMM window +// flags might be either BBBF_ISIMBUTTON or BBBF_ISCHATBUTTON, depending on a window type +EXTERN_C MIR_APP_DLL(void) Srmm_CreateToolbarIcons(HWND hwndDlg, int flags); + // updates all toolbar icons in a message dialog EXTERN_C MIR_APP_DLL(void) Srmm_UpdateToolbarIcons(HWND hdlg); @@ -334,6 +339,7 @@ struct CustomButtonData : public MZeroedObject DWORD m_dwButtonCID; DWORD m_dwArrowCID; // only use with BBBF_ISARROWBUTTON flag + ptrW m_pwszText; // button's text ptrW m_pwszTooltip; // button's tooltip int m_iButtonWidth; // must be 22 for regular button and 33 for button with arrow diff --git a/plugins/MirLua/Modules/m_msg_buttonsbar/src/main.cpp b/plugins/MirLua/Modules/m_msg_buttonsbar/src/main.cpp index 2fcbfe320a..d2a35adc46 100644 --- a/plugins/MirLua/Modules/m_msg_buttonsbar/src/main.cpp +++ b/plugins/MirLua/Modules/m_msg_buttonsbar/src/main.cpp @@ -59,8 +59,8 @@ static int lua_ModifyButton(lua_State *L) INT_PTR res = Srmm_ModifyButton(bbb); lua_pushinteger(L, res); - mir_free(bbb->pszModuleName); - mir_free(bbb->pwszTooltip); + mir_free((void*)bbb->pszModuleName); + mir_free((void*)bbb->pwszTooltip); mir_free(bbb); return 1; diff --git a/plugins/Scriver/src/chat/window.cpp b/plugins/Scriver/src/chat/window.cpp index aa3746fb5b..8c503be2c7 100644 --- a/plugins/Scriver/src/chat/window.cpp +++ b/plugins/Scriver/src/chat/window.cpp @@ -941,18 +941,7 @@ static INT_PTR CALLBACK RoomWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR mir_subclassWindow(GetDlgItem(hwndDlg, IDC_CHAT_BKGCOLOR), ButtonSubclassProc); mir_subclassWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), MessageSubclassProc); - CustomButtonData *cbd; - for (int i = 0; cbd = Srmm_GetNthButton(i); i++) { - if (!cbd->m_bChatButton) - continue; - - HWND hwndButton = CreateWindowEx(0, L"MButtonClass", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, cbd->m_iButtonWidth, 22, hwndDlg, (HMENU)cbd->m_dwButtonCID, g_hInst, NULL); - SendMessage(hwndButton, BUTTONSETASFLATBTN, TRUE, 0); - if (cbd->m_pwszTooltip) - SendMessage(hwndButton, BUTTONADDTOOLTIP, LPARAM(cbd->m_pwszTooltip), BATF_UNICODE); - if (cbd->m_hIcon) - SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon)); - } + Srmm_CreateToolbarIcons(hwndDlg, BBBF_ISCHATBUTTON); RECT minEditInit; GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &minEditInit); diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 93d659545d..fd24b73a60 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -755,19 +755,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP PostMessage(GetDlgItem(hwndDlg, IDC_MESSAGE), EM_SETSEL, len, len); } - CustomButtonData *cbd; - for (int i = 0; cbd = Srmm_GetNthButton(i); i++) { - if (!cbd->m_bIMButton) - continue; - - HWND hwndButton = CreateWindowEx(0, L"MButtonClass", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, cbd->m_iButtonWidth, 22, hwndDlg, (HMENU)cbd->m_dwButtonCID, g_hInst, NULL); - SendMessage(hwndButton, BUTTONSETASFLATBTN, TRUE, 0); - if (cbd->m_pwszTooltip) - SendMessage(hwndButton, BUTTONADDTOOLTIP, LPARAM(cbd->m_pwszTooltip), BATF_UNICODE); - if (cbd->m_hIcon) - SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon)); - } - + Srmm_CreateToolbarIcons(hwndDlg, BBBF_ISIMBUTTON); SendMessage(hwndDlg, DM_CHANGEICONS, 0, 0); SendDlgItemMessage(hwndDlg, IDC_LOG, EM_SETOLECALLBACK, 0, (LPARAM)&reOleCallback); diff --git a/plugins/TabSRMM/src/buttonsbar.cpp b/plugins/TabSRMM/src/buttonsbar.cpp index 6d08d323cb..27bbf632c7 100644 --- a/plugins/TabSRMM/src/buttonsbar.cpp +++ b/plugins/TabSRMM/src/buttonsbar.cpp @@ -156,25 +156,23 @@ void BB_InitDlgButtons(TWindowData *dat) HWND hdlg = dat->hwnd; if (hdlg == 0) return; - RECT rect; - RECT rcSplitter; - POINT ptSplitter; - int splitterY; + BYTE gap = DPISCALEX_S(db_get_b(NULL, SRMSGMOD, "ButtonsBarGap", 1)); + RECT rcSplitter; GetWindowRect(GetDlgItem(hdlg, (dat->bType == SESSIONTYPE_IM) ? IDC_SPLITTER : IDC_SPLITTERY), &rcSplitter); - ptSplitter.x = 0; - ptSplitter.y = rcSplitter.top; + POINT ptSplitter = { 0, rcSplitter.top }; ScreenToClient(hdlg, &ptSplitter); + RECT rect; GetClientRect(hdlg, &rect); - splitterY = ptSplitter.y - DPISCALEY_S(1); + int splitterY = ptSplitter.y - DPISCALEY_S(1); - HWND hwndBtn = NULL; dat->bbLSideWidth = dat->bbRSideWidth = 0; CustomButtonData *cbd; for (int i = 0; cbd = Srmm_GetNthButton(i); i++) { + HWND hwndBtn = GetDlgItem(hdlg, cbd->m_dwButtonCID); if (((dat->bType == SESSIONTYPE_IM && cbd->m_bIMButton) || (dat->bType == SESSIONTYPE_CHAT && cbd->m_bChatButton))) { if (!cbd->m_bHidden) { if (cbd->m_bRSided) @@ -184,37 +182,41 @@ void BB_InitDlgButtons(TWindowData *dat) } if (!cbd->m_bHidden && !cbd->m_bCanBeHidden) dat->iButtonBarReallyNeeds += cbd->m_iButtonWidth + gap; - if (!cbd->m_bSeparator && !GetDlgItem(hdlg, cbd->m_dwButtonCID)) { + + if (cbd->m_bSeparator) + continue; + + if (hwndBtn == NULL) { int x = cbd->m_bRSided ? rect.right - dat->bbRSideWidth + gap : 2 + dat->bbLSideWidth; hwndBtn = CreateWindowEx(0, L"MButtonClass", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP, x, splitterY, cbd->m_iButtonWidth, DPISCALEY_S(22), hdlg, (HMENU)cbd->m_dwButtonCID, g_hInst, NULL); + if (hwndBtn == NULL) + continue; CustomizeButton(hwndBtn); } - if (!cbd->m_bSeparator && hwndBtn) { - SendMessage(hwndBtn, BUTTONSETASFLATBTN, TRUE, 0); - SendMessage(hwndBtn, BUTTONSETASTHEMEDBTN, CSkin::IsThemed(), 0); - if (cbd->m_hIcon) - SendMessage(hwndBtn, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon)); - if (cbd->m_pwszTooltip) - SendMessage(hwndBtn, BUTTONADDTOOLTIP, (WPARAM)TranslateW(cbd->m_pwszTooltip), BATF_UNICODE); - SendMessage(hwndBtn, BUTTONSETCONTAINER, (LPARAM)dat->pContainer, 0); - SendMessage(hwndBtn, BUTTONSETASTOOLBARBUTTON, TRUE, 0); - - if (hwndBtn) { - if (cbd->m_dwArrowCID) - SendMessage(hwndBtn, BUTTONSETARROW, cbd->m_dwArrowCID, 0); - if (cbd->m_bPushButton) - SendMessage(hwndBtn, BUTTONSETASPUSHBTN, TRUE, 0); - } - } - } - else if (GetDlgItem(hdlg, cbd->m_dwButtonCID)) - DestroyWindow(GetDlgItem(hdlg, cbd->m_dwButtonCID)); - - if (cbd->m_bDisabled) - EnableWindow(hwndBtn, 0); - if (cbd->m_bHidden) - ShowWindow(hwndBtn, SW_HIDE); + SendMessage(hwndBtn, BUTTONSETASFLATBTN, TRUE, 0); + SendMessage(hwndBtn, BUTTONSETASTHEMEDBTN, CSkin::IsThemed(), 0); + if (cbd->m_hIcon) + SendMessage(hwndBtn, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon)); + if (cbd->m_pwszText) + SetWindowTextW(hwndBtn, cbd->m_pwszText); + if (cbd->m_pwszTooltip) + SendMessage(hwndBtn, BUTTONADDTOOLTIP, (WPARAM)TranslateW(cbd->m_pwszTooltip), BATF_UNICODE); + SendMessage(hwndBtn, BUTTONSETCONTAINER, (LPARAM)dat->pContainer, 0); + SendMessage(hwndBtn, BUTTONSETASTOOLBARBUTTON, TRUE, 0); + + if (cbd->m_dwArrowCID) + SendMessage(hwndBtn, BUTTONSETARROW, cbd->m_dwArrowCID, 0); + if (cbd->m_bPushButton) + SendMessage(hwndBtn, BUTTONSETASPUSHBTN, TRUE, 0); + + if (cbd->m_bDisabled) + EnableWindow(hwndBtn, 0); + if (cbd->m_bHidden) + ShowWindow(hwndBtn, SW_HIDE); + } + else if (hwndBtn) + DestroyWindow(hwndBtn); } } diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index a116e7f577..277f71b0d2 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -1129,18 +1129,7 @@ INT_PTR CALLBACK RoomWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)si); - CustomButtonData *cbd; - for (int i = 0; cbd = Srmm_GetNthButton(i); i++) { - if (!cbd->m_bChatButton) - continue; - - HWND hwndButton = CreateWindowEx(0, L"MButtonClass", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, cbd->m_iButtonWidth, 22, hwndDlg, (HMENU)cbd->m_dwButtonCID, g_hInst, NULL); - SendMessage(hwndButton, BUTTONSETASFLATBTN, TRUE, 0); - if (cbd->m_pwszTooltip) - SendMessage(hwndButton, BUTTONADDTOOLTIP, LPARAM(cbd->m_pwszTooltip), BATF_UNICODE); - if (cbd->m_hIcon) - SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon)); - } + Srmm_CreateToolbarIcons(hwndDlg, BBBF_ISCHATBUTTON); NotifyLocalWinEvent(si->hContact, hwndDlg, MSG_WINDOW_EVT_OPENING); mir_subclassWindow(GetDlgItem(hwndDlg, IDC_SPLITTERX), SplitterSubclassProc); diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 8f715d0cf5..840444681c 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -682,19 +682,10 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l dat->originalSplitterPos = pt.y; if (dat->splitterPos == -1) dat->splitterPos = dat->originalSplitterPos;// + 60; + } - CustomButtonData *cbd; - for (int i = 0; cbd = Srmm_GetNthButton(i); i++) { - if (!cbd->m_bIMButton) - continue; + Srmm_CreateToolbarIcons(hwndDlg, BBBF_ISIMBUTTON); - HWND hwndButton = CreateWindowEx(0, L"MButtonClass", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, cbd->m_iButtonWidth, 22, hwndDlg, (HMENU)cbd->m_dwButtonCID, g_hInst, NULL); - if (cbd->m_pwszTooltip) - SendMessage(hwndButton, BUTTONADDTOOLTIP, LPARAM(cbd->m_pwszTooltip), BATF_UNICODE); - if (cbd->m_hIcon) - SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon)); - } - } WindowList_Add(pci->hWindowList, hwndDlg, dat->hContact); GetWindowRect(GetDlgItem(hwndDlg, IDC_MESSAGE), &dat->minEditInit); SendMessage(hwndDlg, DM_UPDATESIZEBAR, 0, 0); diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index da19c3658d..7ad0d3650d 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -344,3 +344,4 @@ Miranda_OkToExit @344 Miranda_GetVersion @345 Miranda_GetFileVersion @346 Miranda_GetVersionText @347 +Srmm_CreateToolbarIcons @348 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 84a99f806f..68a6b11090 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -344,3 +344,4 @@ Miranda_OkToExit @344 Miranda_GetVersion @345 Miranda_GetFileVersion @346 Miranda_GetVersionText @347 +Srmm_CreateToolbarIcons @348 diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index 988f5d9949..88f79dc544 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -119,6 +119,7 @@ MIR_APP_DLL(int) Srmm_AddButton(const BBButton *bbdi, int _hLang) cbd->m_iButtonWidth = DPISCALEX_S(22); cbd->m_pszModuleName = mir_strdup(bbdi->pszModuleName); + cbd->m_pwszText = mir_wstrdup(bbdi->pwszText); cbd->m_pwszTooltip = mir_wstrdup(bbdi->pwszTooltip); cbd->m_dwButtonOrigID = bbdi->dwButtonID; @@ -314,6 +315,35 @@ MIR_APP_DLL(void) Srmm_ResetToolbar() dwSepCount = 0; } +MIR_APP_DLL(void) Srmm_CreateToolbarIcons(HWND hwndDlg, int flags) +{ + HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hwndDlg, GWLP_HINSTANCE); + + for (int i = 0; i < arButtonsList.getCount(); i++) { + CustomButtonData *cbd = arButtonsList[i]; + if (cbd->m_bSeparator) + continue; + + HWND hwndButton = GetDlgItem(hwndDlg, cbd->m_dwButtonCID); + if ((flags & BBBF_ISIMBUTTON) && cbd->m_bIMButton || (flags & BBBF_ISCHATBUTTON) && cbd->m_bChatButton) { + if (hwndButton == NULL) { + hwndButton = CreateWindowEx(0, L"MButtonClass", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, cbd->m_iButtonWidth, 22, hwndDlg, (HMENU)cbd->m_dwButtonCID, hInstance, NULL); + if (hwndButton == NULL) // smth went wrong + continue; + } + SendMessage(hwndButton, BUTTONSETASFLATBTN, TRUE, 0); + if (cbd->m_pwszText) + SetWindowTextW(hwndButton, cbd->m_pwszText); + if (cbd->m_pwszTooltip) + SendMessage(hwndButton, BUTTONADDTOOLTIP, LPARAM(cbd->m_pwszTooltip), BATF_UNICODE); + if (cbd->m_hIcon) + SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIconByHandle(cbd->m_hIcon)); + } + else if (hwndButton) + DestroyWindow(hwndButton); + } +} + MIR_APP_DLL(void) Srmm_UpdateToolbarIcons(HWND hwndDlg) { for (int i = 0; i < arButtonsList.getCount(); i++) { -- cgit v1.2.3