diff options
Diffstat (limited to 'alf/alflayout.cpp')
| -rw-r--r-- | alf/alflayout.cpp | 746 |
1 files changed, 550 insertions, 196 deletions
diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp index b98ae93..ce5909f 100644 --- a/alf/alflayout.cpp +++ b/alf/alflayout.cpp @@ -3,11 +3,76 @@ static void ALF_Layout_CalcSizes(ALFLayout *layout, HWND window); +static void +ALF_Layout_EnsureRowExists(ALFLayout *layout, int rowno); + +static void +ALF_Layout_EnsureColumnExists(ALFLayout *layout, int colno); + +static BOOL +ALF_Layout_GetWidgetPos(ALFLayout *layout, HWND window, HWND needle, POINT *p); + +static BOOL +ALF_Layout_SetWidgetPos(ALFLayout *layout, HWND window, HWND needle, POINT *p); + +static BOOL +ALF_Layout_GetWidgetSize(ALFLayout *layout, HWND window, HWND needle, SIZE *s); + +static BOOL +ALF_Layout_SetWidgetSize(ALFLayout *layout, HWND window, HWND needle, SIZE *s); + +static DWORD +ALF_Layout_GetWidgetFlags(ALFLayout *layout, HWND window, HWND needle); + +static BOOL +ALF_Layout_SetWidgetFlags(ALFLayout *layout, HWND window, HWND needle, DWORD flags); + +static int +ALF_Layout_GetColumnSize(ALFLayout *layout, HWND window, int colno); + +static BOOL +ALF_Layout_SetColumnSize(ALFLayout *layout, HWND window, int colno, int size); + +static int +ALF_Layout_GetColumnExpand(ALFLayout *layout, HWND window, int colno); + +static BOOL +ALF_Layout_SetColumnExpand(ALFLayout *layout, HWND window, int colno, int expand); + +static DWORD +ALF_Layout_GetColumnFlags(ALFLayout *layout, HWND window, int colno); + +static BOOL +ALF_Layout_SetColumnFlags(ALFLayout *layout, HWND window, int colno, DWORD flags); + +static int +ALF_Layout_GetRowSize(ALFLayout *layout, HWND window, int rowno); + +static BOOL +ALF_Layout_SetRowSize(ALFLayout *layout, HWND window, int rowno, int size); + +static int +ALF_Layout_GetRowExpand(ALFLayout *layout, HWND window, int rowno); + +static BOOL +ALF_Layout_SetRowExpand(ALFLayout *layout, HWND window, int rowno, int expand); + +static DWORD +ALF_Layout_GetRowFlags(ALFLayout *layout, HWND window, int rowno); + +static BOOL +ALF_Layout_SetRowFlags(ALFLayout *layout, HWND window, int rowno, DWORD flags); + void ALF_Layout_Init(ALFLayout *layout) { ZeroMemory(layout, sizeof(*layout)); ALF_ListInit(&layout->widgets); + + layout->nRows = 1; + layout->rows = ALF_New(ALFLayoutRowOrColumn, layout->nRows); + layout->nColumns = 1; + layout->columns = ALF_New(ALFLayoutRowOrColumn, layout->nColumns); } void @@ -31,108 +96,148 @@ ALF_Layout_ForwardFont(ALFLayout *layout, HWND window, HFONT font, LPARAM redraw (void)window; ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, i) { - if (i->flags & ALF_INHERITFONT) { + if (i->flags & ALF_LAYOUT_INHERITFONT) { SendMessage(i->hwnd, WM_SETFONT, (WPARAM)font, redraw); } } } void -ALF_Layout_CalcSizes(ALFLayout* layout, HWND window) +ALF_Layout_EnsureRowExists(ALFLayout *layout, int rowno) { - for (int i = 0; i < layout->nColumns; ++i) { - ZeroMemory(&layout->columns[i], sizeof(layout->columns[i])); + while (rowno >= layout->nRows) { + layout->nRows *= 2; + layout->rows = ALF_ReNew(layout->rows, ALFLayoutRowOrColumn, layout->nRows); } - for (int i = 0; i < layout->nRows; ++i) { - ZeroMemory(&layout->rows[i], sizeof(layout->rows[i])); +} + +void +ALF_Layout_EnsureColumnExists(ALFLayout *layout, int colno) +{ + while (colno >= layout->nColumns) { + layout->nColumns *= 2; + layout->columns = ALF_ReNew(layout->columns, ALFLayoutRowOrColumn, layout->nColumns); } +} - ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, c) { - while ((int)c->x >= layout->nColumns) { - // FIXME! overflow, use reallocarray(2) equivalent - if (layout->nColumns == 0) { - layout->nColumns = 1; - layout->columns = ALF_New(ALFLayoutRowOrColumn, layout->nColumns); - } else { - layout->nColumns *= 2; - layout->columns = ALF_ReNew(layout->columns, ALFLayoutRowOrColumn, layout->nColumns); - } - } - while ((int)c->y >= layout->nRows) { - // FIXME! overflow, use reallocarray(2) equivalent - if (layout->nRows == 0) { - layout->nRows = 1; - layout->rows = ALF_New(ALFLayoutRowOrColumn, layout->nRows); - } else { - layout->nRows *= 2; - layout->rows = ALF_ReNew(layout->rows, ALFLayoutRowOrColumn, layout->nRows); - } +static void +ALF_Layout_CalcMinWidgetSize(ALFWidgetPriv *c, HWND window, SIZE *s) +{ + if (c->flags & ALF_LAYOUT_SIZE_PX) { + s->cx = c->width; + s->cy = c->height; + } else { + s->cx = ALF_CentipointsToPixels(window, c->width); + s->cy = ALF_CentipointsToPixels(window, c->height); + } + + switch (c->flags & ALF_LAYOUT_SIZETYPE_MASK) { + case ALF_LAYOUT_SIZE_FIXED: + // already done + break; + case ALF_LAYOUT_SIZE_QUERY: + SendMessage(c->hwnd, ALF_WM_QUERYSIZE, 0, (LPARAM)s); + break; + default: + // FIXME! unimplemented + break; + } +} + +void +ALF_Layout_CalcSizes(ALFLayout* layout, HWND window) +{ + layout->biggestColumnNo = 0; + layout->columnExpandDenominator = 0; + for (int i = 0; i < layout->nColumns; ++i) { + if (layout->columns[i].requestedFlags & ALF_LAYOUT_SIZE_PX) { + layout->columns[i].calculatedMinWidth = layout->columns[i].requestedMinWidth; + } else { + layout->columns[i].calculatedMinWidth = ALF_CentipointsToPixels(window, layout->columns[i].requestedMinWidth); } - // TODO: ignore spanning cell + layout->columns[i].calculatedExpandNumerator = layout->columns[i].requestedExpandNumerator; + layout->columnExpandDenominator += layout->columns[i].requestedExpandNumerator; - SIZE qs = { ALF_CentipointsToPixels(window, c->cptWidth), - ALF_CentipointsToPixels(window, c->cptHeight) }; - if ((c->flags & ALF_QUERYSIZE) == ALF_QUERYSIZE) { - SendMessage(c->hwnd, ALF_WM_QUERYSIZE, 0, (LPARAM)&qs); + if (layout->columns[i].requestedExpandNumerator >= layout->columns[layout->biggestColumnNo].requestedExpandNumerator) + layout->biggestColumnNo = i; + } + layout->biggestRowNo = 0; + layout->rowExpandDenominator = 0; + for (int i = 0; i < layout->nRows; ++i) { + if (layout->rows[i].requestedFlags & ALF_LAYOUT_SIZE_PX) { + layout->rows[i].calculatedMinWidth = layout->rows[i].requestedMinWidth; + } else { + layout->rows[i].calculatedMinWidth = ALF_CentipointsToPixels(window, layout->rows[i].requestedMinWidth); } + layout->rows[i].calculatedExpandNumerator = layout->rows[i].requestedExpandNumerator; + layout->rowExpandDenominator += layout->rows[i].requestedExpandNumerator; + + if (layout->rows[i].requestedExpandNumerator >= layout->rows[layout->biggestRowNo].requestedExpandNumerator) + layout->biggestRowNo = i; + } + + ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, c) { + int col = c->x; // TODO: skip spanning cells + int row = c->y; - qs.cx += ALF_CentipointsToPixels(window, c->cptMarginLeft); - qs.cx += ALF_CentipointsToPixels(window, c->cptMarginRight); - qs.cy += ALF_CentipointsToPixels(window, c->cptMarginTop); - qs.cy += ALF_CentipointsToPixels(window, c->cptMarginBottom); + ALF_Layout_EnsureColumnExists(layout, col); + ALF_Layout_EnsureRowExists(layout, row); - if (qs.cx > layout->columns[c->x].minWidth) - layout->columns[c->x].minWidth = qs.cx; - if (qs.cy > layout->rows[c->y].minWidth) - layout->rows[c->y].minWidth = qs.cy; + SIZE qs = { 0, 0 }; + ALF_Layout_CalcMinWidgetSize(c, window, &qs); - // expand flag - if (c->flags & ALF_HEXPAND) - layout->columns[c->x].expand = 1; - if (c->flags & ALF_VEXPAND) - layout->rows[c->y].expand = 1; + if (qs.cx > layout->columns[col].calculatedMinWidth) + layout->columns[col].calculatedMinWidth = qs.cx; + if (qs.cy > layout->rows[row].calculatedMinWidth) + layout->rows[row].calculatedMinWidth = qs.cy; } // TODO: second pass for spanning cells - // update min width bookkeeping + // total minimum bookkeeping layout->totalMinWidth = 0; - layout->expandoColumnCount = 0; for (int i = 0; i < layout->nColumns; ++i) { - layout->totalMinWidth += layout->columns[i].minWidth; + layout->totalMinWidth += layout->columns[i].calculatedMinWidth; + } - if (layout->columns[i].expand) - layout->expandoColumnCount++; + layout->totalMinHeight = 0; + for (int i = 0; i < layout->nRows; ++i) { + layout->totalMinHeight += layout->rows[i].calculatedMinWidth; } - if (layout->expandoColumnCount == 0) { - // mark all columns as expanding + // expando bookkeeping if no expand numerators specified + if (layout->columnExpandDenominator == 0) { for (int i = 0; i < layout->nColumns; ++i) { - if (layout->columns[i].minWidth > 0) { - layout->columns[i].expand = 1; - layout->expandoColumnCount++; + if (layout->columns[i].calculatedMinWidth > 0) { + layout->columnExpandDenominator += 1; + layout->columns[i].calculatedExpandNumerator = 1; + layout->biggestColumnNo = i; } } - } - - layout->totalMinHeight = 0; - layout->expandoRowCount = 0; - for (int i = 0; i < layout->nRows; ++i) { - layout->totalMinHeight += layout->rows[i].minWidth; - if (layout->rows[i].expand) - layout->expandoRowCount++; + // all columns empty? expand first one then + if (layout->columnExpandDenominator == 0) { + layout->columnExpandDenominator = 1; + layout->columns[0].calculatedExpandNumerator = 1; + layout->biggestColumnNo = 0; + } } - - if (layout->expandoRowCount == 0) { - // mark all rows as expanding + if (layout->rowExpandDenominator == 0) { for (int i = 0; i < layout->nRows; ++i) { - if (layout->rows[i].minWidth > 0) { - layout->rows[i].expand = 1; - layout->expandoRowCount++; + if (layout->rows[i].calculatedMinWidth > 0) { + layout->rowExpandDenominator += 1; + layout->rows[i].calculatedExpandNumerator = 1; + layout->biggestRowNo = i; } } + + // all rows empty? expand first one then + if (layout->rowExpandDenominator == 0) { + layout->rowExpandDenominator = 1; + layout->rows[0].calculatedExpandNumerator = 1; + layout->biggestRowNo = 0; + } } layout->layoutValididityFlags &= ~ALF_LAYOUT_NEED_RECALC; @@ -144,8 +249,7 @@ ALF_Layout_Apply(ALFLayout* layout, HWND window) if (layout->layoutValididityFlags & ALF_LAYOUT_NEED_RECALC) ALF_Layout_CalcSizes(layout, window); - // allocate cell positions - // distribute free space + // distribute extra space int extraWidth = 0; int extraHeight = 0; RECT client; @@ -156,77 +260,64 @@ ALF_Layout_Apply(ALFLayout* layout, HWND window) extraHeight = client.bottom - client.top - layout->totalMinHeight; } - int extraWidthPart = 0; - int extraWidthError = 0; - if (layout->expandoColumnCount) { - extraWidthPart = extraWidth / layout->expandoColumnCount; - extraWidthError = extraWidth - extraWidthPart * layout->expandoColumnCount; - } - + int extraWidthLeft = extraWidth; for (int i = 0; i < layout->nColumns; ++i) { - layout->columns[i].allocatedWidth = layout->columns[i].minWidth; + if (i == layout->biggestColumnNo) + continue; - if (layout->columns[i].expand) { - layout->columns[i].allocatedWidth += extraWidthPart; - if (extraWidthError) { - layout->columns[i].allocatedWidth++; - extraWidthError--; - } - } + int extraHere = MulDiv(extraWidth, layout->columns[i].calculatedExpandNumerator, layout->columnExpandDenominator); + if (extraHere > extraWidthLeft) + extraHere = extraWidthLeft; - if (i == 0) { - layout->columns[i].allocatedPosition = 0; - } else { - layout->columns[i].allocatedPosition = - layout->columns[i-1].allocatedPosition + layout->columns[i-1].allocatedWidth; - } + layout->columns[i].allocatedWidth = layout->columns[i].calculatedMinWidth + extraHere; + extraWidthLeft -= extraHere; } + layout->columns[layout->biggestColumnNo].allocatedWidth = + layout->columns[layout->biggestColumnNo].calculatedMinWidth + extraWidthLeft; + + int extraHeightLeft = extraHeight; + for (int i = 0; i < layout->nRows; ++i) { + if (i == layout->biggestRowNo) + continue; + int extraHere = MulDiv(extraHeight, layout->rows[i].calculatedExpandNumerator, layout->rowExpandDenominator); + if (extraHere > extraHeightLeft) + extraHere = extraHeightLeft; - int extraHeightPart = 0; - int extraHeightError = 0; - if (layout->expandoRowCount) { - extraHeightPart = extraHeight / layout->expandoRowCount; - extraHeightError = extraHeight - extraHeightPart * layout->expandoRowCount; + layout->rows[i].allocatedWidth = layout->rows[i].calculatedMinWidth + extraHere; + extraHeightLeft -= extraHere; } + layout->rows[layout->biggestRowNo].allocatedWidth = + layout->rows[layout->biggestRowNo].calculatedMinWidth + extraHeightLeft; + // set row/column positions + int x = 0; + for (int i = 0; i < layout->nColumns; ++i) { + layout->columns[i].allocatedPosition = x; + x += layout->columns[i].allocatedWidth; + } + int y = 0; for (int i = 0; i < layout->nRows; ++i) { - layout->rows[i].allocatedWidth = layout->rows[i].minWidth; - - if (layout->rows[i].expand) { - layout->rows[i].allocatedWidth += extraHeightPart; - if (extraHeightError) { - layout->rows[i].allocatedWidth++; - extraHeightError--; - } - } - - if (i == 0) { - layout->rows[i].allocatedPosition = 0; - } else { - layout->rows[i].allocatedPosition = - layout->rows[i-1].allocatedPosition + layout->rows[i-1].allocatedWidth; - } + layout->rows[i].allocatedPosition = y; + y += layout->rows[i].allocatedWidth; } + // now apply positions to widgets HDWP hdwp = BeginDeferWindowPos(layout->nColumns * layout->nRows); ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, c) { - if ((int)c->x >= layout->nColumns || (int)c->y >= layout->nRows) - continue; - - int marginleft = ALF_CentipointsToPixels(window, c->cptMarginLeft); - int marginright = ALF_CentipointsToPixels(window, c->cptMarginRight); - int margintop = ALF_CentipointsToPixels(window, c->cptMarginTop); - int marginbottom = ALF_CentipointsToPixels(window, c->cptMarginBottom); + int col = c->x; + int row = c->y; + if (col >= layout->nColumns || row >= layout->nRows) + continue; // FIXME! can that actually happen? RECT r = { 0,0,0,0 }; - r.left = layout->columns[c->x].allocatedPosition + marginleft; - r.right = r.left + layout->columns[c->x].allocatedWidth - marginleft - marginright; - r.top = layout->rows[c->y].allocatedPosition + margintop; - r.bottom = r.top + layout->rows[c->y].allocatedWidth - margintop - marginbottom; + r.left = layout->columns[col].allocatedPosition; + r.right = r.left + layout->columns[col].allocatedWidth; + r.top = layout->rows[row].allocatedPosition; + r.bottom = r.top + layout->rows[row].allocatedWidth; - if (c->flags & ALF_APPLYSIZE) { + if (c->flags & ALF_LAYOUT_CUSTOMPOS) { hdwp = (HDWP)SendMessage(c->hwnd, ALF_WM_APPLYSIZE, (WPARAM)hdwp, (LPARAM)&r); } else { hdwp = DeferWindowPos(hdwp, @@ -242,24 +333,20 @@ ALF_Layout_Apply(ALFLayout* layout, HWND window) } void -ALF_Layout_AddWidget(ALFLayout* layout, HWND window, const ALFWidgetLayoutParams* params) +ALF_Layout_AddWidget(ALFLayout* layout, HWND window, const ALFAddWidgetParams* params) { ALFWidgetPriv *w = ALF_New(ALFWidgetPriv, 1); w->hwnd = params->hwnd; w->x = params->x; w->y = params->y; - w->cptWidth = params->width; - w->cptHeight = params->height; + w->width = params->width; + w->height = params->height; w->flags = params->flags; - w->cptMarginTop = params->margins[0]; - w->cptMarginRight = params->margins[1]; - w->cptMarginBottom = params->margins[2]; - w->cptMarginLeft = params->margins[3]; if (GetParent(w->hwnd) != window) SetParent(w->hwnd, window); - if (w->flags & ALF_INHERITFONT) { + if (w->flags & ALF_LAYOUT_INHERITFONT) { SendMessage(w->hwnd, WM_SETFONT, (WPARAM)SendMessage(window, WM_GETFONT, 0, 0), 0); } @@ -268,59 +355,8 @@ ALF_Layout_AddWidget(ALFLayout* layout, HWND window, const ALFWidgetLayoutParams ALF_InvalidateLayout(window); } -BOOL -ALF_Layout_SetWidgetParams(ALFLayout* layout, HWND window, const ALFWidgetLayoutParams* params, HWND widget) -{ - ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { - if (w->hwnd == widget) { - w->hwnd = params->hwnd; - w->x = params->x; - w->y = params->y; - w->cptWidth = params->width; - w->cptHeight = params->height; - w->flags = params->flags; - w->cptMarginTop = params->margins[0]; - w->cptMarginRight = params->margins[1]; - w->cptMarginBottom = params->margins[2]; - w->cptMarginLeft = params->margins[3]; - - if (w->flags & ALF_INHERITFONT) - SendMessage(w->hwnd, WM_SETFONT, (WPARAM)SendMessage(window, WM_GETFONT, 0, 0), 0); - - ALF_InvalidateLayout(window); - - return TRUE; - } - } - - return FALSE; -} - -BOOL -ALF_Layout_GetWidgetParams(ALFLayout* layout, ALFWidgetLayoutParams* params, HWND widget) -{ - ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { - if (w->hwnd == widget) { - params->hwnd = w->hwnd; - params->x = w->x; - params->y = w->y; - params->width = w->cptWidth; - params->height = w->cptHeight; - params->flags = w->flags; - params->margins[0] = w->cptMarginTop; - params->margins[1] = w->cptMarginRight; - params->margins[2] = w->cptMarginBottom; - params->margins[3] = w->cptMarginLeft; - - return TRUE; - } - } - - return FALSE; -} - HWND -ALF_Layout_WidgetAtPos(ALFLayout* layout, UINT x, UINT y) +ALF_Layout_WidgetAtPos(ALFLayout* layout, int x, int y) { ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { if (w->x == x && w->y == y) { @@ -378,6 +414,244 @@ ALF_Layout_GetMinSize(ALFLayout *layout, HWND window, SIZE *size) } BOOL +ALF_Layout_GetWidgetPos(ALFLayout *layout, HWND window, HWND needle, POINT *p) +{ + (void)window; + + ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { + if (w->hwnd == needle) { + p->x = w->x; + p->y = w->y; + return TRUE; + } + } + + return FALSE; +} + +static BOOL +ALF_Layout_SetWidgetPos(ALFLayout *layout, HWND window, HWND needle, POINT *p) +{ + ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { + if (w->hwnd == needle) { + w->x = p->x; + w->y = p->y; + + ALF_InvalidateLayout(window); + + return TRUE; + } + } + + return FALSE; +} + +static BOOL +ALF_Layout_GetWidgetSize(ALFLayout *layout, HWND window, HWND needle, SIZE *s) +{ + (void)window; + + ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { + if (w->hwnd == needle) { + s->cx = w->width; + s->cy = w->height; + return TRUE; + } + } + + return FALSE; +} + +static BOOL +ALF_Layout_SetWidgetSize(ALFLayout *layout, HWND window, HWND needle, SIZE *s) +{ + ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { + if (w->hwnd == needle) { + w->width = s->cx; + w->height = s->cy; + + ALF_InvalidateLayout(window); + + return TRUE; + } + } + + return FALSE; +} + +static DWORD +ALF_Layout_GetWidgetFlags(ALFLayout *layout, HWND window, HWND needle) +{ + (void)window; + + ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { + if (w->hwnd == needle) { + return w->flags; + } + } + + return 0; +} + +static BOOL +ALF_Layout_SetWidgetFlags(ALFLayout *layout, HWND window, HWND needle, DWORD flags) +{ + ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, w) { + if (w->hwnd == needle) { + w->flags = flags; + + if (flags & ALF_LAYOUT_INHERITFONT) + SendMessage(w->hwnd, WM_SETFONT, (LPARAM)SendMessage(window, WM_GETFONT, 0, 0), 0); + + ALF_InvalidateLayout(window); + + return TRUE; + } + } + + return FALSE; +} + +int +ALF_Layout_GetColumnSize(ALFLayout *layout, HWND window, int colno) +{ + (void)window; + + if (colno >= layout->nColumns) + return 0; + + return layout->columns[colno].requestedMinWidth; +} + +BOOL +ALF_Layout_SetColumnSize(ALFLayout *layout, HWND window, int colno, int size) +{ + ALF_Layout_EnsureColumnExists(layout, colno); + + layout->columns[colno].requestedMinWidth = size; + + ALF_InvalidateLayout(window); + + return TRUE; +} + +int +ALF_Layout_GetColumnExpand(ALFLayout *layout, HWND window, int colno) +{ + (void)window; + + if (colno >= layout->nColumns) + return 0; + + return layout->columns[colno].requestedExpandNumerator; +} + +static BOOL +ALF_Layout_SetColumnExpand(ALFLayout *layout, HWND window, int colno, int expand) +{ + ALF_Layout_EnsureColumnExists(layout, colno); + + layout->columns[colno].requestedExpandNumerator = expand; + + ALF_InvalidateLayout(window); + + return TRUE; +} + +static DWORD +ALF_Layout_GetColumnFlags(ALFLayout *layout, HWND window, int colno) +{ + (void)window; + + if (colno >= layout->nColumns) + return 0; + + return layout->columns[colno].requestedFlags; +} + +static BOOL +ALF_Layout_SetColumnFlags(ALFLayout *layout, HWND window, int colno, DWORD flags) +{ + ALF_Layout_EnsureColumnExists(layout, colno); + + layout->columns[colno].requestedFlags = flags; + + ALF_InvalidateLayout(window); + + return TRUE; +} + +static int +ALF_Layout_GetRowSize(ALFLayout *layout, HWND window, int rowno) +{ + (void)window; + + if (rowno >= layout->nRows) + return 0; + + return layout->rows[rowno].requestedMinWidth; +} + +static BOOL +ALF_Layout_SetRowSize(ALFLayout *layout, HWND window, int rowno, int size) +{ + ALF_Layout_EnsureRowExists(layout, rowno); + + layout->rows[rowno].requestedMinWidth = size; + + ALF_InvalidateLayout(window); + + return TRUE; +} + +static int +ALF_Layout_GetRowExpand(ALFLayout *layout, HWND window, int rowno) +{ + (void)window; + + if (rowno >= layout->nRows) + return 0; + + return layout->rows[rowno].requestedExpandNumerator; +} + +static BOOL +ALF_Layout_SetRowExpand(ALFLayout *layout, HWND window, int rowno, int expand) +{ + ALF_Layout_EnsureRowExists(layout, rowno); + + layout->rows[rowno].requestedExpandNumerator = expand; + + ALF_InvalidateLayout(window); + + return TRUE; +} + +static DWORD +ALF_Layout_GetRowFlags(ALFLayout *layout, HWND window, int rowno) +{ + (void)window; + + if (rowno >= layout->nRows) + return 0; + + return layout->rows[rowno].requestedFlags; +} + +static BOOL +ALF_Layout_SetRowFlags(ALFLayout *layout, HWND window, int rowno, DWORD flags) +{ + ALF_Layout_EnsureRowExists(layout, rowno); + + layout->rows[rowno].requestedFlags = flags; + + ALF_InvalidateLayout(window); + + return TRUE; +} + + +BOOL ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, LRESULT *pRet) { *pRet = 0; @@ -393,22 +667,12 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, } if (msg == ALF_WM_ADDWIDGET) { - ALF_Layout_AddWidget(layout, hwnd, (ALFWidgetLayoutParams *)lparam); - return TRUE; - } - - if (msg == ALF_WM_GETLAYOUTPARAMS) { - *pRet = (LRESULT)ALF_Layout_GetWidgetParams(layout, (ALFWidgetLayoutParams *)lparam, (HWND)wparam); - return TRUE; - } - - if (msg == ALF_WM_SETLAYOUTPARAMS) { - *pRet = (LRESULT)ALF_Layout_SetWidgetParams(layout, hwnd, (const ALFWidgetLayoutParams *)lparam, (HWND)wparam); + ALF_Layout_AddWidget(layout, hwnd, (ALFAddWidgetParams *)lparam); return TRUE; } if (msg == ALF_WM_GETWIDGETATPOS) { - *pRet = (LRESULT)ALF_Layout_WidgetAtPos(layout, ((UINT*)lparam)[0], ((UINT*)lparam)[1]); + *pRet = (LRESULT)ALF_Layout_WidgetAtPos(layout, ((int*)lparam)[0], ((int*)lparam)[1]); return TRUE; } @@ -427,5 +691,95 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, return TRUE; } + if (msg == ALF_WM_LYT_GETWIDGETPOS) { + *pRet = (LRESULT)ALF_Layout_GetWidgetPos(layout, hwnd, (HWND)wparam, (POINT *)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETWIDGETPOS) { + *pRet = (LRESULT)ALF_Layout_SetWidgetPos(layout, hwnd, (HWND)wparam, (POINT *)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETWIDGTSIZE) { + *pRet = (LRESULT)ALF_Layout_GetWidgetSize(layout, hwnd, (HWND)wparam, (SIZE *)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETWIDGTSIZE) { + *pRet = (LRESULT)ALF_Layout_SetWidgetSize(layout, hwnd, (HWND)wparam, (SIZE *)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETWDGTFLAGS) { + *pRet = (LRESULT)ALF_Layout_GetWidgetFlags(layout, hwnd, (HWND)wparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETWDGTFLAGS) { + *pRet = (LRESULT)ALF_Layout_SetWidgetFlags(layout, hwnd, (HWND)wparam, (DWORD)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETCOLSIZE) { + *pRet = (LRESULT)ALF_Layout_GetColumnSize(layout, hwnd, (int)wparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETCOLSIZE) { + *pRet = (LRESULT)ALF_Layout_SetColumnSize(layout, hwnd, (int)wparam, (int)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETCOLEXPAND) { + *pRet = (LRESULT)ALF_Layout_GetColumnExpand(layout, hwnd, (int)wparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETCOLEXPAND) { + *pRet = (LRESULT)ALF_Layout_SetColumnExpand(layout, hwnd, (int)wparam, (int)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETCOLFLAGS) { + *pRet = (LRESULT)ALF_Layout_GetColumnFlags(layout, hwnd, (int)wparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETCOLFLAGS) { + *pRet = (LRESULT)ALF_Layout_SetColumnFlags(layout, hwnd, (int)wparam, (int)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETROWSIZE) { + *pRet = (LRESULT)ALF_Layout_GetRowSize(layout, hwnd, (int)wparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETROWSIZE) { + *pRet = (LRESULT)ALF_Layout_SetRowSize(layout, hwnd, (int)wparam, (int)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETROWEXPAND) { + *pRet = (LRESULT)ALF_Layout_GetRowExpand(layout, hwnd, (int)wparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETROWEXPAND) { + *pRet = (LRESULT)ALF_Layout_SetRowExpand(layout, hwnd, (int)wparam, (int)lparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_GETROWFLAGS) { + *pRet = (LRESULT)ALF_Layout_GetRowFlags(layout, hwnd, (int)wparam); + return TRUE; + } + + if (msg == ALF_WM_LYT_SETROWFLAGS) { + *pRet = (LRESULT)ALF_Layout_SetRowFlags(layout, hwnd, (int)wparam, (int)lparam); + return TRUE; + } + return FALSE; } |
