From ebac89ec6ae0aca646420320c019a0e1cbb79d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 3 Aug 2022 22:04:05 +0200 Subject: Use Pascal case for all functions. --- c/datalistview.cpp | 4 ++-- c/episodelistview.cpp | 8 ++++---- c/layout.cpp | 12 ++++++------ c/layout.h | 4 ++-- c/listview.cpp | 4 ++-- c/main.cpp | 40 ++++++++++++++++++++-------------------- c/pl.cpp | 4 ++-- c/pl.h | 8 ++++---- c/wcharptr.cpp | 20 ++++++++++---------- c/wcharptr.h | 26 +++++++++++++------------- c/win.cpp | 4 ++-- c/win.h | 4 ++-- 12 files changed, 69 insertions(+), 69 deletions(-) diff --git a/c/datalistview.cpp b/c/datalistview.cpp index e44592b..bd5c8d9 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -63,8 +63,8 @@ void DataListView::ShowEpisode(const int iEpisode) LVITEM lviValue = {LVIF_TEXT}; for (int i = 0; q.NextSolution(std::nothrow); i++) { - wchar_ptr key; - wchar_ptr value; + WcharPtr key; + WcharPtr value; if (!(PlGet(t+1, &key) && PlGet(t+2, &value))) continue; diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index b3a581d..c278a35 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -89,7 +89,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) { extern HFONT g_hfBold; if (!Pl("track_episodes","watched",nm->nmcd.lItemlParam)) { - require(SelectObject(nm->nmcd.hdc, g_hfBold)); + Require(SelectObject(nm->nmcd.hdc, g_hfBold)); return CDRF_NEWFONT; } break; @@ -117,7 +117,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) { extern HMENU g_hMenuPopup; const DWORD pos = GetMessagePos(); - require(TrackPopupMenu(g_hMenuPopup, TPM_RIGHTBUTTON, + Require(TrackPopupMenu(g_hMenuPopup, TPM_RIGHTBUTTON, LOWORD(pos), HIWORD(pos), 0, m_hWndParent, (const RECT*)NULL)); break; @@ -265,7 +265,7 @@ int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2, case ELVSITITLE: { Mark m; - wchar_ptr s1, s2; + WcharPtr s1, s2; int cch, cch1, cch2; if (!Pl("episode_data","episode_title",lvi1.lParam,&s1)) return 0; @@ -405,7 +405,7 @@ void EpisodeListView::Update() /* Update episode name and rating. */ void EpisodeListView::UpdateItem(const int iItem, const LPARAM lParam) { - wchar_ptr name; + WcharPtr name; if (!Pl("episode_data","episode_title",lParam,&name)) { if (!Pl("episode_data","update_episode_data")) goto r; if (!Pl("episode_data","episode_title",lParam,&name)) goto r; diff --git a/c/layout.cpp b/c/layout.cpp index cbfb831..5fe5da4 100644 --- a/c/layout.cpp +++ b/c/layout.cpp @@ -16,16 +16,16 @@ void UpdateLayout(int w, int h) RECT rc, rrStatus; if (w && h) rc = {0, 0, w, h}; - else require(GetClientRect(g_hWnd, &rc)); - require(GetRelativeRect(g_hWndStatus, &rrStatus)); + else Require(GetClientRect(g_hWnd, &rc)); + Require(GetRelativeRect(g_hWndStatus, &rrStatus)); SendMessage(g_hWnd, WM_SETREDRAW, FALSE, 0); /* Resize list views. */ const long pad = EBIsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */ const long cyDlv = rrStatus.top-g_dlv->Height()-pad; - require(SetWindowRect(g_dlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad)); - require(SetWindowRect(g_elv->hWnd, pad, pad, rc.right-pad, cyDlv-pad)); + Require(SetWindowRect(g_dlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad)); + Require(SetWindowRect(g_elv->hWnd, pad, pad, rc.right-pad, cyDlv-pad)); g_dlv->ResizeColumns(rc.right-pad-pad); g_elv->ResizeColumns(rc.right-pad-pad); @@ -41,7 +41,7 @@ void UpdateLayout(int w, int h) bool DlvDragger::InDragArea(const int x, const int y) { RECT rrDlv; - require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); + Require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); const int pad = EBIsThemeActive()? Dpi(6): 0; const int extra = EBIsThemeActive()? 0: Dpi(2); @@ -53,7 +53,7 @@ bool DlvDragger::InDragArea(const int x, const int y) void DlvDragger::Drag(const int, const int y) { RECT rrDlv; - require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); + Require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); if (y < Dpi(50) || y > rrDlv.bottom-Dpi(20)) return; diff --git a/c/layout.h b/c/layout.h index 578f065..da29d25 100644 --- a/c/layout.h +++ b/c/layout.h @@ -61,7 +61,7 @@ inline bool Dragger::HandleDown() { extern HWND g_hWnd; POINT pt; - require(GetRelativeCursorPos(g_hWnd, &pt)); + Require(GetRelativeCursorPos(g_hWnd, &pt)); if (!InDragArea(pt.x, pt.y)) return false; if (IsDouble()) { @@ -77,7 +77,7 @@ inline bool Dragger::HandleMove() { extern HWND g_hWnd; POINT pt; - require(GetRelativeCursorPos(g_hWnd, &pt)); + Require(GetRelativeCursorPos(g_hWnd, &pt)); extern HCURSOR g_hcSizeNs; bool r = true; diff --git a/c/listview.cpp b/c/listview.cpp index 107d34b..bd92246 100644 --- a/c/listview.cpp +++ b/c/listview.cpp @@ -11,7 +11,7 @@ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); ListView::ListView(const HWND hWndParent, const HMENU hMenu, const DWORD dwStyle) { m_hWndParent = hWndParent; - hWnd = require(CreateWindowEx( + hWnd = Require(CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", @@ -20,7 +20,7 @@ ListView::ListView(const HWND hWndParent, const HMENU hMenu, const DWORD dwStyle hWndParent, hMenu, GetModuleHandle(NULL), this)); m_proc0 = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)::WndProc); - require(SetProp(hWnd, L"this", (HANDLE)this)); + Require(SetProp(hWnd, L"this", (HANDLE)this)); ListView_SetExtendedListViewStyle(hWnd, LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER); SendMessage(hWnd, WM_SETFONT, (WPARAM)g_hfNormal, MAKELPARAM(FALSE, 0)); } diff --git a/c/main.cpp b/c/main.cpp index c237e31..26cc25d 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -58,7 +58,7 @@ static void UpdateTheme(); void OnTerminate() noexcept { const wchar_t* what = L"an exception"; - wchar_ptr why; + WcharPtr why; try { std::rethrow_exception(std::current_exception()); @@ -67,9 +67,9 @@ void OnTerminate() noexcept try { why = PlString(t); } catch (...) {} } catch (const Win32Error& e) { what = L"a Windows error"; - try { why = wchar_ptr::copy(e.What()); } catch (...) {} + try { why = WcharPtr::Copy(e.What()); } catch (...) {} } catch (const std::exception& e) { - try { why = wchar_ptr::from_narrow(e.what()); } catch (...) {} + try { why = WcharPtr::FromNarrow(e.what()); } catch (...) {} } catch (...) {} wchar_t msg[256] = {0}; @@ -99,10 +99,10 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons INITCOMMONCONTROLSEX icc; icc.dwSize = sizeof(icc); icc.dwICC = ICC_WIN95_CLASSES; - require(InitCommonControlsEx(&icc)); + Require(InitCommonControlsEx(&icc)); - g_hMenuPopup = require(LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(IDR_POPUPMENU))); - g_hMenuPopup = require(GetSubMenu(g_hMenuPopup, 0)); + g_hMenuPopup = Require(LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(IDR_POPUPMENU))); + g_hMenuPopup = Require(GetSubMenu(g_hMenuPopup, 0)); WNDCLASSEX wc; memset(&wc, 0, sizeof(WNDCLASSEX)); @@ -115,23 +115,23 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); wc.lpszClassName = L"Episode Browser"; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); - require(RegisterClassEx(&wc)); + Require(RegisterClassEx(&wc)); /* Create window. A CBT hook is used to initialize important * global variables before any messages are sent to the new * window. It is vital that the hook is set up correctly. */ - const HHOOK hHook = require(SetWindowsHookEx(WH_CBT, CBTProc, + const HHOOK hHook = Require(SetWindowsHookEx(WH_CBT, CBTProc, (HINSTANCE)NULL, GetCurrentThreadId())); - const HWND hWnd = require(CreateWindowEx( + const HWND hWnd = Require(CreateWindowEx( 0, L"Episode Browser", L"Episode Browser", WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, (HWND)NULL, (HMENU)NULL, hInstance, (void*)NULL)); - require(UnhookWindowsHookEx(hHook)); + Require(UnhookWindowsHookEx(hHook)); - g_hWndStatus = require(CreateWindowEx( + g_hWndStatus = Require(CreateWindowEx( 0, STATUSCLASSNAME, (const wchar_t*)NULL, @@ -178,16 +178,16 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR lib->GetProcAddress("SystemParametersInfoW")) { NONCLIENTMETRICS m; m.cbSize = sizeof(NONCLIENTMETRICS); - require(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, + Require(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &m, 0)); - g_hfNormal = require(CreateFontIndirect(&m.lfMessageFont)); + g_hfNormal = Require(CreateFontIndirect(&m.lfMessageFont)); } else - g_hfNormal = static_cast(require(GetStockObject(DEFAULT_GUI_FONT))); + g_hfNormal = static_cast(Require(GetStockObject(DEFAULT_GUI_FONT))); LOGFONT lf; - require(GetObject(g_hfNormal, sizeof(LOGFONT), &lf)); + Require(GetObject(g_hfNormal, sizeof(LOGFONT), &lf)); lf.lfWeight = FW_BOLD; - g_hfBold = require(CreateFontIndirect(&lf)); + g_hfBold = Require(CreateFontIndirect(&lf)); /* Load theme functions, if available. */ if (HMODULE hModule = LoadLibrary(L"uxtheme.dll")) { @@ -258,7 +258,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, g_dpi = HIWORD(wParam); Metric = GetSystemMetrics(SM_CXVSCROLL); - prefer(SetWindowPos(hWnd, (HWND)NULL, + Prefer(SetWindowPos(hWnd, (HWND)NULL, r->left, r->top, r->right-r->left, r->bottom-r->top, @@ -500,7 +500,7 @@ void WaitFor(const char* mod, const char* pred) static atom_t aThread; static int bActive; static int iTimer; - static wchar_ptr activePred; + static WcharPtr activePred; if (bActive) { wchar_t msg[256] = {0}; @@ -535,8 +535,8 @@ void WaitFor(const char* mod, const char* pred) Plx(mod,"thread_create",pred,&aThread); SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)L"."); - if (prefer(iTimer = SetTimer(NULL, -1, 500, proc))) { - activePred = wchar_ptr::from_narrow(pred); + if (Prefer(iTimer = SetTimer(NULL, -1, 500, proc))) { + activePred = WcharPtr::FromNarrow(pred); bActive = 1; } } diff --git a/c/pl.cpp b/c/pl.cpp index 8b3fcbe..b0e7f8e 100644 --- a/c/pl.cpp +++ b/c/pl.cpp @@ -90,11 +90,11 @@ int Query::NextSolution() } /* Convert Prolog term to wide characters. */ -wchar_ptr PlString(const term_t t, const int flags) +WcharPtr PlString(const term_t t, const int flags) { char* s; if (PL_get_chars(t, &s, flags)) - return {wchar_ptr::from_narrow(s)}; + return {WcharPtr::FromNarrow(s)}; else return {}; } diff --git a/c/pl.h b/c/pl.h index 670c926..5720eda 100644 --- a/c/pl.h +++ b/c/pl.h @@ -7,7 +7,7 @@ #include "wcharptr.h" -wchar_ptr PlString(const term_t t, const int flags = CVT_WRITE); +WcharPtr PlString(const term_t t, const int flags = CVT_WRITE); struct Frame { @@ -54,7 +54,7 @@ inline int PlPut(term_t, long*) { return -1; } inline int PlPut(term_t, long long*) { return -1; } inline int PlPut(term_t, atom_t*) { return -1; } inline int PlPut(term_t, char**) { return -1; } -inline int PlPut(term_t, wchar_ptr*) { return -1; } +inline int PlPut(term_t, WcharPtr*) { return -1; } inline int PlGet(term_t, int) { return -1; } inline int PlGet(term_t, long) { return -1; } @@ -67,11 +67,11 @@ inline int PlGet(term_t t, long* x) { return PL_get_long(t, x); } inline int PlGet(term_t t, long long* x) { return PL_get_int64(t, x); } inline int PlGet(term_t t, atom_t* x) { return PL_get_atom(t, x); } inline int PlGet(term_t t, char** x) { return PL_get_atom_chars(t, x); } -inline int PlGet(term_t t, wchar_ptr* x) { +inline int PlGet(term_t t, WcharPtr* x) { Mark m; char* s; if (!PlGet(t, &s)) return 0; - *x = wchar_ptr::from_narrow(s); + *x = WcharPtr::FromNarrow(s); return 1; /* or catch potential exception from BstrFromSz? */ } diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp index e406ed1..240fff5 100644 --- a/c/wcharptr.cpp +++ b/c/wcharptr.cpp @@ -4,11 +4,11 @@ #include "wcharptr.h" #include "win.h" -wchar_ptr::wchar_ptr() noexcept {} +WcharPtr::WcharPtr() noexcept {} -wchar_ptr::wchar_ptr(wchar_t* const s) noexcept : m_p(s) {} +WcharPtr::WcharPtr(wchar_t* const s) noexcept : m_p(s) {} -wchar_ptr& wchar_ptr::operator=(wchar_t* const s) noexcept +WcharPtr& WcharPtr::operator=(wchar_t* const s) noexcept { if (m_p != s) { delete m_p; @@ -17,33 +17,33 @@ wchar_ptr& wchar_ptr::operator=(wchar_t* const s) noexcept return *this; } -wchar_ptr::wchar_ptr(wchar_ptr&& other) noexcept +WcharPtr::WcharPtr(WcharPtr&& other) noexcept : m_p(std::exchange(other.m_p, nullptr)) {} -wchar_ptr& wchar_ptr::operator=(wchar_ptr&& other) noexcept +WcharPtr& WcharPtr::operator=(WcharPtr&& other) noexcept { std::swap(m_p, other.m_p); return *this; } -wchar_ptr::operator wchar_t*() noexcept +WcharPtr::operator wchar_t*() noexcept { return m_p; } -wchar_t* wchar_ptr::release() noexcept +wchar_t* WcharPtr::Release() noexcept { wchar_t* p2 = m_p; m_p = nullptr; return p2; } -wchar_ptr::~wchar_ptr() noexcept +WcharPtr::~WcharPtr() noexcept { delete m_p; } -wchar_ptr wchar_ptr::from_narrow(const char* const src, const int cp) +WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp) { int cbMultiByte = strlen(src)+1; int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0); @@ -55,7 +55,7 @@ wchar_ptr wchar_ptr::from_narrow(const char* const src, const int cp) return dst; } -wchar_ptr wchar_ptr::copy(const wchar_t* const src) +WcharPtr WcharPtr::Copy(const wchar_t* const src) { const int cb = wcslen(src)+1; wchar_t* dst = new wchar_t[cb]; diff --git a/c/wcharptr.h b/c/wcharptr.h index 1f579b5..2267017 100644 --- a/c/wcharptr.h +++ b/c/wcharptr.h @@ -3,29 +3,29 @@ #include -/* wchar_ptr: Simple wrapper for wide C strings. */ -struct wchar_ptr +/* WcharPtr: Simple wrapper for wide C strings. */ +struct WcharPtr { /* Named copy constructors (expensive). */ - static wchar_ptr from_narrow(const char* buf, int cp = CP_UTF8); - static wchar_ptr copy(const wchar_t* s); + static WcharPtr FromNarrow(const char* buf, int cp = CP_UTF8); + static WcharPtr Copy(const wchar_t* s); /* Non-explicit copies are disabled. */ - wchar_ptr(wchar_ptr& other) = delete; - wchar_ptr& operator=(wchar_ptr& other) = delete; + WcharPtr(WcharPtr& other) = delete; + WcharPtr& operator=(WcharPtr& other) = delete; - wchar_ptr() noexcept; - ~wchar_ptr(); + WcharPtr() noexcept; + ~WcharPtr(); operator wchar_t*() noexcept; - wchar_ptr(wchar_t* s) noexcept; - wchar_ptr& operator=(wchar_t* s) noexcept; + WcharPtr(wchar_t* s) noexcept; + WcharPtr& operator=(wchar_t* s) noexcept; - wchar_ptr(wchar_ptr&& other) noexcept; - wchar_ptr& operator=(wchar_ptr&& other) noexcept; + WcharPtr(WcharPtr&& other) noexcept; + WcharPtr& operator=(WcharPtr&& other) noexcept; /* Return pointer, releasing ownership. */ - wchar_t *release() noexcept; + wchar_t *Release() noexcept; private: wchar_t* m_p = nullptr; }; diff --git a/c/win.cpp b/c/win.cpp index 435e739..703c011 100644 --- a/c/win.cpp +++ b/c/win.cpp @@ -87,9 +87,9 @@ int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption, return 0; }; - HHOOK hHook = require(SetWindowsHookEx(WH_CBT, proc, (HINSTANCE)NULL, GetCurrentThreadId())); + HHOOK hHook = Require(SetWindowsHookEx(WH_CBT, proc, (HINSTANCE)NULL, GetCurrentThreadId())); int r = MessageBox(g_hWnd, wszText, wszCaption, uType); - require(UnhookWindowsHookEx(hHook)); + Require(UnhookWindowsHookEx(hHook)); return r; } diff --git a/c/win.h b/c/win.h index 038f8ea..1615985 100644 --- a/c/win.h +++ b/c/win.h @@ -45,7 +45,7 @@ auto Metric = GetSystemMetrics(I); /* Check result of Windows API call, throwing error on NULL. */ template -inline T require(const T x) +inline T Require(const T x) { if (!x) throw Win32Error(); return x; @@ -53,7 +53,7 @@ inline T require(const T x) /* Check result of Windows API call, showing a warning on NULL. */ template -inline T prefer(const T x) +inline T Prefer(const T x) { if (!x) { EBMessageBox(Win32Error().What(), L"System Error", MB_ICONWARNING); -- cgit v1.2.3