Migrated container.c and radiobuttons.c.

This commit is contained in:
Pietro Gagliardi 2016-04-22 20:37:28 -04:00
parent 6ec5f4800d
commit 955203bfb8
2 changed files with 26 additions and 26 deletions

View File

@ -1,5 +1,5 @@
// 26 april 2015 // 26 april 2015
#include "uipriv_windows.h" #include "uipriv_windows.hpp"
// Code for the HWND of the following uiControls: // Code for the HWND of the following uiControls:
// - uiBox // - uiBox
@ -17,16 +17,22 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
switch (uMsg) { switch (uMsg) {
case WM_PAINT: case WM_PAINT:
dc = BeginPaint(hwnd, &ps); dc = BeginPaint(hwnd, &ps);
if (dc == NULL) if (dc == NULL) {
logLastError("error beginning container paint in containerWndProc()"); logLastError(L"error beginning container paint");
// bail out; hope DefWindowProc() catches us
break;
}
r = ps.rcPaint; r = ps.rcPaint;
paintContainerBackground(hwnd, dc, &r); paintContainerBackground(hwnd, dc, &r);
EndPaint(hwnd, &ps); EndPaint(hwnd, &ps);
return 0; return 0;
// tab controls use this to draw the background of the tab area // tab controls use this to draw the background of the tab area
case WM_PRINTCLIENT: case WM_PRINTCLIENT:
if (GetClientRect(hwnd, &r) == 0) if (GetClientRect(hwnd, &r) == 0) {
logLastError("error getting client rect in containerWndProc()"); logLastError(L"error getting client rect");
// likewise
break;
}
paintContainerBackground(hwnd, (HDC) wParam, &r); paintContainerBackground(hwnd, (HDC) wParam, &r);
return 0; return 0;
case WM_ERASEBKGND: case WM_ERASEBKGND:

View File

@ -1,5 +1,5 @@
// 20 may 2015 // 20 may 2015
#include "uipriv_windows.h" #include "uipriv_windows.hpp"
// desired behavior: // desired behavior:
// - tab moves between the radio buttons and the adjacent controls // - tab moves between the radio buttons and the adjacent controls
@ -10,8 +10,8 @@
struct uiRadioButtons { struct uiRadioButtons {
uiWindowsControl c; uiWindowsControl c;
HWND hwnd; // of the container HWND hwnd; // of the container
struct ptrArray *hwnds; // of the buttons std::vector<HWND> *hwnds; // of the buttons
}; };
static void onDestroy(uiRadioButtons *); static void onDestroy(uiRadioButtons *);
@ -31,8 +31,7 @@ static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult
if (code != BN_CLICKED) if (code != BN_CLICKED)
return FALSE; return FALSE;
for (i = 0; i < r->hwnds->len; i++) { for (hwnd : *(r->hwnds)) {
hwnd = ptrArrayIndex(r->hwnds, HWND, i);
check = BST_UNCHECKED; check = BST_UNCHECKED;
if (clicked == hwnd) if (clicked == hwnd)
check = BST_CHECKED; check = BST_CHECKED;
@ -46,13 +45,11 @@ static void onDestroy(uiRadioButtons *r)
{ {
HWND hwnd; HWND hwnd;
while (r->hwnds->len != 0) { for (hwnd : *(r->hwnds)) {
hwnd = ptrArrayIndex(r->hwnds, HWND, 0);
ptrArrayDelete(r->hwnds, 0);
uiWindowsUnregisterWM_COMMANDHandler(hwnd); uiWindowsUnregisterWM_COMMANDHandler(hwnd);
uiWindowsEnsureDestroyWindow(hwnd); uiWindowsEnsureDestroyWindow(hwnd);
} }
ptrArrayDestroy(r->hwnds); delete r->hwnds;
} }
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
@ -63,12 +60,11 @@ static void onDestroy(uiRadioButtons *r)
static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height) static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
{ {
uiRadioButtons *r = uiRadioButtons(c); uiRadioButtons *r = uiRadioButtons(c);
uintmax_t i;
intmax_t wid, maxwid; intmax_t wid, maxwid;
maxwid = 0; maxwid = 0;
for (i = 0; i < r->hwnds->len; i++) { for (const HWND &hwnd : *(r->hwnds)) {
wid = uiWindowsWindowTextWidth(ptrArrayIndex(r->hwnds, HWND, i)); wid = uiWindowsWindowTextWidth(hwnd);
if (maxwid < wid) if (maxwid < wid)
maxwid = wid; maxwid = wid;
} }
@ -82,7 +78,6 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in
uiWindowsSizing *d; uiWindowsSizing *d;
intmax_t height1; intmax_t height1;
intmax_t h; intmax_t h;
uintmax_t i;
HWND hwnd; HWND hwnd;
uiWindowsEnsureMoveWindow(r->hwnd, x, y, width, height); uiWindowsEnsureMoveWindow(r->hwnd, x, y, width, height);
@ -92,8 +87,7 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in
d = uiWindowsNewSizing(r->hwnd); d = uiWindowsNewSizing(r->hwnd);
height1 = uiWindowsDlgUnitsToY(radiobuttonHeight, d->BaseY); height1 = uiWindowsDlgUnitsToY(radiobuttonHeight, d->BaseY);
uiWindowsFreeSizing(d); uiWindowsFreeSizing(d);
for (i = 0; i < r->hwnds->len; i++) { for (hwnd : *(r->hwnds)) {
hwnd = ptrArrayIndex(r->hwnds, HWND, i);
h = height1; h = height1;
if (h > height) // clip to height if (h > height) // clip to height
h = height; h = height;
@ -102,6 +96,8 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in
height -= height1; height -= height1;
if (height <= 0) // clip to height if (height <= 0) // clip to height
break; break;
// TODO don't do the above to avoid overlap
// TODO in fact, only do this on add/remove/change labels/etc.
} }
} }
@ -110,14 +106,12 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in
static void redoControlIDsZOrder(uiRadioButtons *r) static void redoControlIDsZOrder(uiRadioButtons *r)
{ {
HWND hwnd; HWND hwnd;
uintmax_t i;
LONG_PTR controlID; LONG_PTR controlID;
HWND insertAfter; HWND insertAfter;
controlID = 100; controlID = 100;
insertAfter = NULL; insertAfter = NULL;
for (i = 0; i < r->hwnds->len; i++) { for (hwnd : *(r->hwnds)) {
hwnd = ptrArrayIndex(r->hwnds, HWND, i);
uiWindowsEnsureAssignControlIDZOrder(hwnd, controlID, insertAfter); uiWindowsEnsureAssignControlIDZOrder(hwnd, controlID, insertAfter);
controlID++; controlID++;
insertAfter = hwnd; insertAfter = hwnd;
@ -133,7 +127,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
// the first radio button gets both WS_GROUP and WS_TABSTOP // the first radio button gets both WS_GROUP and WS_TABSTOP
// successive radio buttons get *neither* // successive radio buttons get *neither*
groupTabStop = 0; groupTabStop = 0;
if (r->hwnds->len == 0) if (r->hwnds->size() == 0)
groupTabStop = WS_GROUP | WS_TABSTOP; groupTabStop = WS_GROUP | WS_TABSTOP;
wtext = toUTF16(text); wtext = toUTF16(text);
@ -145,7 +139,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
uiFree(wtext); uiFree(wtext);
uiWindowsEnsureSetParent(hwnd, r->hwnd); uiWindowsEnsureSetParent(hwnd, r->hwnd);
uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r)); uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r));
ptrArrayAppend(r->hwnds, hwnd); r->hwnds->push_back(hwnd);
redoControlIDsZOrder(r); redoControlIDsZOrder(r);
uiWindowsControlQueueRelayout(uiWindowsControl(r)); uiWindowsControlQueueRelayout(uiWindowsControl(r));
} }
@ -158,7 +152,7 @@ uiRadioButtons *uiNewRadioButtons(void)
r->hwnd = newContainer(); r->hwnd = newContainer();
r->hwnds = newPtrArray(); r->hwnds = new std::vector<HWND>;
uiWindowsFinishNewControl(r, uiRadioButtons); uiWindowsFinishNewControl(r, uiRadioButtons);
uiWindowsControl(r)->Relayout = radiobuttonsRelayout; uiWindowsControl(r)->Relayout = radiobuttonsRelayout;