+rfc: minor refactoring on UpdateUI

This commit is contained in:
METANEOCORTEX\Kotti 2023-01-04 10:37:41 +01:00
parent ff1f8b2b8d
commit 4f992f7aac
6 changed files with 63 additions and 37 deletions

View File

@ -4703,8 +4703,8 @@ void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode)
Settings.AlwaysOnTop = true;
s_bPrevFullScreenFlag = true;
}
SendWMSize(hwnd, NULL);
UpdateToolbar();
UpdateUI(hwnd);
}

View File

@ -103,9 +103,13 @@ SETTINGS2_T Settings2;
FOCUSEDVIEW_T FocusedView;
FILEWATCHING_T FileWatching;
// set by InitScintillaHandle()
HWND g_hwndEditWindow = NULL;
HANDLE g_hndlScintilla = NULL;
// window positioning
WININFO g_IniWinInfo = INIT_WININFO;
WININFO g_DefWinInfo = INIT_WININFO;
HANDLE g_hndlScintilla = NULL;
COLORREF g_colorCustom[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@ -3334,10 +3338,7 @@ LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam,LPARAM lParam)
EditUpdateVisibleIndicators();
UpdateToolbar();
UpdateStatusbar(true);
UpdateMargins(true);
UpdateUI();
UpdateUI(hwnd);
}
UpdateWindowEx(hwnd);
@ -3395,7 +3396,7 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
DeferWindowPos(hdwp,s_hwndEditFrame,NULL,x,y,cx,cy, SWP_NOZORDER | SWP_NOACTIVATE);
DeferWindowPos(hdwp, Globals.hwndEdit, s_hwndEditFrame,
DeferWindowPos(hdwp, g_hwndEditWindow, s_hwndEditFrame,
x+s_cxEditFrame,y+s_cyEditFrame, cx-2*s_cxEditFrame,cy-2*s_cyEditFrame,
SWP_NOZORDER | SWP_NOACTIVATE);
@ -3407,12 +3408,37 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
UpdateStatusbar(true);
UpdateMargins(true);
UpdateTitlebar(hwnd);
//~UpdateUI();
//~UpdateUI(); ~ recursion
return FALSE;
}
//=============================================================================
//
// UpdateContentArea()
//
void UpdateContentArea()
{
Sci_ForceNotifyUpdateUI(Globals.hwndMain, IDC_EDIT);
}
//=============================================================================
//
// UpdateUI()
//
void UpdateUI(HWND hwnd)
{
//if (hwnd == Globals.hwndMain) {
// UpdateContentArea()
//}
SendWMSize(hwnd, NULL);
PostMessage(hwnd, WM_NCACTIVATE, FALSE, -1); // (!)
PostMessage(hwnd, WM_NCACTIVATE, TRUE, 0);
}
//=============================================================================
//
// MsgDrawItem() - Handles WM_DRAWITEM (needs SBT_OWNERDRAW)
@ -5810,7 +5836,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
SetForegroundWindow(Globals.hwndDlgCustomizeSchemes);
}
SendWMCommand(Globals.hwndDlgCustomizeSchemes, IDC_SETCURLEXERTV);
UpdateUI();
UpdateUI(hwnd);
break;
@ -5820,7 +5846,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
Style_SetDefaultFont(Globals.hwndEdit, (iLoWParam == IDM_VIEW_FONT));
}
UpdateMargins(true);
UpdateUI();
UpdateUI(hwnd);
break;
@ -6248,7 +6274,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_TOOLBAR:
Settings.ShowToolbar = !Settings.ShowToolbar;
ShowWindow(Globals.hwndRebar, (Settings.ShowToolbar ? SW_SHOW : SW_HIDE));
SendWMSize(hwnd, NULL);
UpdateUI(hwnd);
break;
case IDM_VIEW_CUSTOMIZETB:
@ -6258,13 +6284,13 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_TOGGLETB:
Settings.ToolBarTheme = (Settings.ToolBarTheme + 1) % 3;
CreateBars(hwnd, Globals.hInstance);
UpdateUI();
UpdateUI(hwnd);
break;
case IDM_VIEW_LOADTHEMETB:
if (SelectExternalToolBar(hwnd)) {
CreateBars(hwnd, Globals.hInstance);
UpdateUI();
UpdateUI(hwnd);
}
break;
@ -6276,8 +6302,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_STATUSBAR:
Settings.ShowStatusbar = !Settings.ShowStatusbar;
ShowWindow(Globals.hwndStatus, (Settings.ShowStatusbar ? SW_SHOW : SW_HIDE));
UpdateStatusbar(Settings.ShowStatusbar);
SendWMSize(hwnd, NULL);
UpdateUI(hwnd);
break;
@ -10377,23 +10402,6 @@ void UpdateSaveSettingsCmds()
}
//=============================================================================
//
// UpdateUI()
//
void UpdateUI() {
struct SCNotification scn = { 0 };
scn.nmhdr.hwndFrom = Globals.hwndEdit;
scn.nmhdr.idFrom = IDC_EDIT;
scn.nmhdr.code = SCN_UPDATEUI;
scn.updated = SC_UPDATE_CONTENT;
SendMessage(Globals.hwndMain, WM_NOTIFY, IDC_EDIT, (LPARAM)&scn);
SendWMSize(Globals.hwndMain, NULL);
PostMessage(Globals.hwndMain, WM_NCACTIVATE, FALSE, -1); // (!)
PostMessage(Globals.hwndMain, WM_NCACTIVATE, TRUE, 0);
}
//=============================================================================
//
// UndoRedoRecordingStart()

View File

@ -127,13 +127,16 @@ void ShowZoomCallTip();
void ShowWrapAroundCallTip(bool forwardSearch);
void MarkAllOccurrences(const int delay, const bool bForceClear);
void UpdateUI();
void UpdateToolbar();
void UpdateStatusbar(const bool bForceRedraw);
void UpdateMargins(const bool bForce);
void UpdateSaveSettingsCmds();
void ResetMouseDWellTime();
void UpdateTitlebar(const HWND hwnd);
void UpdateContentArea();
void UpdateUI(HWND hwnd);
void ResetMouseDWellTime();
void UndoRedoReset();
LONG BeginUndoActionSelection();

View File

@ -1987,7 +1987,6 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr
}
// prepare buffer for prefix "..\" x dir_cnt
size_t const alloc_add = wcslen(&hto_buf[prefix]) + 1;
size_t const len = (wcslen(PATHPARENT_PREFIX) * dir_cnt) + alloc_add;
LPWSTR const hrecv_buf = StrgWriteAccessBuf(hrecv_str, len);

View File

@ -62,12 +62,16 @@
// Scintilla Window Handle
//
#if defined(__cplusplus)
extern "C" HWND g_hwndEditWindow;
extern "C" HANDLE g_hndlScintilla;
#else
extern HWND g_hwndEditWindow;
extern HANDLE g_hndlScintilla;
#endif
__forceinline void InitScintillaHandle(HWND hwnd) {
g_hwndEditWindow = hwnd;
g_hndlScintilla = (HANDLE)SendMessage(hwnd, SCI_GETDIRECTPOINTER, 0, 0);
}
@ -933,6 +937,18 @@ inline DocPos Sci_ReplaceTargetEx(const int mode, const DocPos length, const cha
// ----------------------------------------------------------------------------
inline LRESULT Sci_ForceNotifyUpdateUI(HWND hwnd, uptr_t idc)
{
struct SCNotification scn = { 0 };
scn.nmhdr.hwndFrom = g_hwndEditWindow;
scn.nmhdr.idFrom = idc;
scn.nmhdr.code = SCN_UPDATEUI;
scn.updated = SC_UPDATE_CONTENT;
return SendMessageW(hwnd, WM_NOTIFY, idc, (LPARAM)&scn);
}
// ----------------------------------------------------------------------------
//=============================================================================
#endif //_NP3_SCICALL_H_

View File

@ -569,7 +569,7 @@ bool Style_DynamicThemesMenuCmd(int cmd)
Style_ResetCurrentLexer(Globals.hwndEdit);
}
UpdateMargins(true);
UpdateUI();
UpdateUI(Globals.hwndMain);
}
return result;
}