From 6e5c2ba80ec20f94540ad4b374c5f225172d0a56 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 4 May 2020 14:25:51 +0300 Subject: NewStory: menu, first version --- plugins/NewStory/res/resource.rc | 7 +-- plugins/NewStory/src/history.cpp | 4 +- plugins/NewStory/src/history_control.cpp | 88 ++++++++++++++------------------ plugins/NewStory/src/resource.h | 1 + plugins/NewStory/src/stdafx.h | 1 + 5 files changed, 45 insertions(+), 56 deletions(-) (limited to 'plugins') diff --git a/plugins/NewStory/res/resource.rc b/plugins/NewStory/res/resource.rc index 94e303e9ee..4172d75491 100644 --- a/plugins/NewStory/res/resource.rc +++ b/plugins/NewStory/res/resource.rc @@ -378,12 +378,13 @@ BEGIN MENUITEM "Options", ID_LOGOPTIONS_OPTIONS MENUITEM "Templates", ID_LOGOPTIONS_TEMPLATES END +END + +IDR_CONTEXTMENU MENU +BEGIN POPUP "" BEGIN - MENUITEM "Cancel", ID_CONTEXT_CANCEL - MENUITEM SEPARATOR MENUITEM "Copy", ID_CONTEXT_COPY - MENUITEM "Export", 65535 MENUITEM "Delete", ID_CONTEXT_DELETE, GRAYED MENUITEM SEPARATOR MENUITEM "Select all", ID_CONTEXT_SELECTALL diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index d34bcf9024..b3230295c9 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -605,7 +605,6 @@ public: DestroyWindow(m_hwndStatus); m_hwndStatus = nullptr; } - } void onClick_Calendar(CCtrlButton *pButton) @@ -722,7 +721,7 @@ public: SetFilePointer(hFile, -3, nullptr, FILE_CURRENT); - //export events + // export events MEVENT hDbEvent = db_event_first(m_hContact); bool bAppendOnly = false; while (hDbEvent != NULL) { @@ -803,7 +802,6 @@ public: m_histControl.SendMsg(NSM_FINDPREV, ptrW(edtSearchText.GetText()), 0); } - void onClick_Message(CCtrlButton *) { CallService(MS_MSG_SENDMESSAGE, m_hContact, 0); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 2d9c07cdf2..7aa6416f75 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -38,9 +38,29 @@ struct NewstoryListData : public MZeroedObject CTimer redrawTimer; - void OnContextMenu(int index) + void OnContextMenu(int index, POINT pt) { ItemData* item = items[index]; + if (item == nullptr) + return; + + HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_CONTEXTMENU)); + TranslateMenu(hMenu); + + int ret = TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, nullptr); + switch(ret) { + case ID_CONTEXT_COPY: + break; + + case ID_CONTEXT_DELETE: + break; + + case ID_CONTEXT_SELECTALL: + SendMessage(hwnd, NSM_SELECTITEMS, 0, items.getCount() - 1); + break; + } + + DestroyMenu(hMenu); } void OnTimer(CTimer *pTimer) @@ -677,47 +697,10 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case WM_ERASEBKGND: return 1; - case WM_PRINTCLIENT: - { - // PaintClc(hwnd, dat, (HDC) wParam, NULL); - break; - } - /* - case WM_NCPAINT: - { - RECT rc; - GetWindowRect(hwnd, &rc); - - HDC hdc; - hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN); - FrameRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); - ReleaseDC(hwnd, hdc); - } - */ - /* - case WM_NCPAINT: - { - if (wParam == 1) - break; - { - POINT ptTopLeft = { 0, 0 }; - HRGN hClientRgn; - ClientToScreen(hwnd, &ptTopLeft); - hClientRgn = CreateRectRgn(0, 0, 1, 1); - CombineRgn(hClientRgn, (HRGN) wParam, NULL, RGN_COPY); - OffsetRgn(hClientRgn, -ptTopLeft.x, -ptTopLeft.y); - InvalidateRgn(hwnd, hClientRgn, FALSE); - DeleteObject(hClientRgn); - UpdateWindow(hwnd); - } - break; - } - */ case WM_PAINT: { - HDC hdcWindow; PAINTSTRUCT ps; - hdcWindow = BeginPaint(hwnd, &ps); + HDC hdcWindow = BeginPaint(hwnd, &ps); /* we get so many InvalidateRect()'s that there is no point painting, Windows in theory shouldn't queue up WM_PAINTs in this case but it does so @@ -761,6 +744,22 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } break; + + case WM_CONTEXTMENU: + { + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + if (pt.x == -1 && pt.y == -1) + GetCursorPos(&pt); + + POINT pt2 = pt; + ScreenToClient(hwnd, &pt2); + + int index = SendMessage(hwnd, NSM_GETITEMFROMPIXEL, pt2.x, pt2.y); + if (index != -1) + data->OnContextMenu(index, pt); + } + break; + case WM_SETFOCUS: return 0; @@ -827,10 +826,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } else if ((ch == 'A') && (GetKeyState(VK_CONTROL) & 0x80)) { SendMessage(hwnd, NSM_SELECTITEMS, 0, data->items.getCount()); - // } else - // if (ch == VK_ESCAPE) - // { - // PostMessage(GetParent(hwnd), WM_CLOSE, 0, 0); } } break; @@ -938,13 +933,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM delete data; SetWindowLongPtr(hwnd, 0, 0); break; - - case WM_CONTEXTMENU: - { - int index = SendMessage(hwnd, NSM_GETITEMFROMPIXEL, LOWORD(lParam), HIWORD(lParam)); - data->OnContextMenu(index); - } - break; } return DefWindowProc(hwnd, msg, wParam, lParam); diff --git a/plugins/NewStory/src/resource.h b/plugins/NewStory/src/resource.h index 445e44c64f..0b4511f7f1 100644 --- a/plugins/NewStory/src/resource.h +++ b/plugins/NewStory/src/resource.h @@ -6,6 +6,7 @@ #define IDD_OPT_TEMPLATES 102 #define IDD_OPT_ADVANCED 103 #define IDD_SEARCH 105 +#define IDR_CONTEXTMENU 106 #define IDD_MESSAGE 112 #define IDR_POPUPS 113 #define IDR_ACCEL 114 diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h index c278cdac34..83ea563746 100644 --- a/plugins/NewStory/src/stdafx.h +++ b/plugins/NewStory/src/stdafx.h @@ -21,6 +21,7 @@ Boston, MA 02111-1307, USA. //Windows headers #include +#include #include #include #include -- cgit v1.2.3