From fbef8046088df2d5f3a7a1dfc22e159f2e074e91 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 23 Apr 2016 11:22:46 -0400 Subject: [PATCH] Quick and dirty C++ conversions of box.c, tab.c, and window.c. I feel like I need another rewrite... --- windows/{box.c => box.cpp} | 4 +++- windows/{tab.c => tab.cpp} | 6 +++--- windows/{window.c => window.cpp} | 18 +++++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) rename windows/{box.c => box.cpp} (99%) rename windows/{tab.c => tab.cpp} (97%) rename windows/{window.c => window.cpp} (93%) diff --git a/windows/box.c b/windows/box.cpp similarity index 99% rename from windows/box.c rename to windows/box.cpp index 67e2abee..a44892ba 100644 --- a/windows/box.c +++ b/windows/box.cpp @@ -1,5 +1,7 @@ // 7 april 2015 -#include "uipriv_windows.h" +#include "uipriv_windows.hpp" + +// TODO C++-ize struct uiBox { uiWindowsControl c; diff --git a/windows/tab.c b/windows/tab.cpp similarity index 97% rename from windows/tab.c rename to windows/tab.cpp index 55a2d3f4..235dbf46 100644 --- a/windows/tab.c +++ b/windows/tab.cpp @@ -1,5 +1,5 @@ // 16 may 2015 -#include "uipriv_windows.h" +#include "uipriv_windows.hpp" // TODO // - write comment here about how tabs and parents work @@ -191,7 +191,7 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child) wname = toUTF16(name); item.pszText = wname; if (SendMessageW(t->hwnd, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1) - logLastError("error adding tab to uiTab in uiTabInsertAt()"); + logLastError(L"error adding tab to uiTab"); uiFree(wname); // we need to do this because adding the first tab doesn't send a TCN_SELCHANGE; it just shows the page @@ -209,7 +209,7 @@ void uiTabDelete(uiTab *t, uintmax_t n) // first delete the tab from the tab control // if this is the current tab, no tab will be selected, which is good if (SendMessageW(t->hwnd, TCM_DELETEITEM, (WPARAM) n, 0) == FALSE) - logLastError("error deleting uiTab tab in tabDelete()"); + logLastError(L"error deleting uiTab tab"); // now delete the page itself page = ptrArrayIndex(t->pages, struct child *, n); diff --git a/windows/window.c b/windows/window.cpp similarity index 93% rename from windows/window.c rename to windows/window.cpp index 93ee1443..eead3683 100644 --- a/windows/window.c +++ b/windows/window.cpp @@ -1,5 +1,5 @@ // 27 april 2015 -#include "uipriv_windows.h" +#include "uipriv_windows.hpp" #define windowClass L"libui_uiWindowClass" @@ -102,7 +102,7 @@ ATOM registerWindowClass(HICON hDefaultIcon, HCURSOR hDefaultCursor) void unregisterWindowClass(void) { if (UnregisterClassW(windowClass, hInstance) == 0) - logLastError("error unregistering uiWindow window class in unregisterWindowClass()"); + logLastError(L"error unregistering uiWindow window class"); } static int defaultOnClosing(uiWindow *w, void *data) @@ -137,7 +137,7 @@ static void windowCommitShow(uiControl *c) uiWindowsControlQueueRelayout(uiWindowsControl(w)); ShowWindow(w->hwnd, nCmdShow); if (UpdateWindow(w->hwnd) == 0) - logLastError("error calling UpdateWindow() after showing uiWindow for the first time in windowShow()"); + logLastError(L"error calling UpdateWindow() after showing uiWindow for the first time"); } static void windowContainerUpdateState(uiControl *c) @@ -243,7 +243,7 @@ static void setClientSize(uiWindow *w, int width, int height, BOOL hasMenubar, D window.right = width; window.bottom = height; if (AdjustWindowRectEx(&window, style, hasMenubar, exstyle) == 0) - logLastError("error getting real window coordinates in setClientSize()"); + logLastError(L"error getting real window coordinates"); if (hasMenubar) { RECT temp; @@ -253,7 +253,7 @@ static void setClientSize(uiWindow *w, int width, int height, BOOL hasMenubar, D window.bottom += temp.top; } if (SetWindowPos(w->hwnd, NULL, 0, 0, window.right - window.left, window.bottom - window.top, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0) - logLastError("error resizing window in setClientSize()"); + logLastError(L"error resizing window"); } uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) @@ -283,13 +283,13 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) width, height, NULL, NULL, hInstance, w); if (w->hwnd == NULL) - logLastError("error creating window in uiWindow()"); + logLastError(L"error creating window"); uiFree(wtitle); if (hasMenubar) { w->menubar = makeMenubar(); if (SetMenu(w->hwnd, w->menubar) == 0) - logLastError("error giving menu to window in uiNewWindow()"); + logLastError(L"error giving menu to window"); } // and use the proper size @@ -315,12 +315,12 @@ void ensureMinimumWindowSize(uiWindow *w) c = uiWindowsControl(w); (*(c->MinimumSize))(c, NULL, &width, &height); if (GetClientRect(w->hwnd, &r) == 0) - logLastError("error getting client rect in ensureMinimumWindowSize()"); + logLastError(L"error getting client rect"); if (width < (r.right - r.left)) // preserve width if larger width = r.right - r.left; if (height < (r.bottom - r.top)) // preserve height if larger height = r.bottom - r.top; clientSizeToWindowSize(w->hwnd, &width, &height, w->hasMenubar); if (SetWindowPos(w->hwnd, NULL, 0, 0, width, height, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0) - logLastError("error resizing window in ensureMinimumWindowSize()"); + logLastError(L"error resizing window"); }