comctl32/combo: Simplify rectangles sizing helper.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
35919eb6a1
commit
fc4b06815a
|
@ -307,111 +307,70 @@ static void CBForceDummyResize(
|
||||||
*
|
*
|
||||||
* Set up component coordinates given valid lphc->RectCombo.
|
* Set up component coordinates given valid lphc->RectCombo.
|
||||||
*/
|
*/
|
||||||
static void CBCalcPlacement(
|
static void CBCalcPlacement(HEADCOMBO *combo)
|
||||||
HWND hwnd,
|
|
||||||
LPHEADCOMBO lphc,
|
|
||||||
LPRECT lprEdit,
|
|
||||||
LPRECT lprButton,
|
|
||||||
LPRECT lprLB)
|
|
||||||
{
|
{
|
||||||
/*
|
/* Start with the client rectangle. */
|
||||||
* Again, start with the client rectangle.
|
GetClientRect(combo->self, &combo->textRect);
|
||||||
*/
|
|
||||||
GetClientRect(hwnd, lprEdit);
|
|
||||||
|
|
||||||
/*
|
/* Remove the borders */
|
||||||
* Remove the borders
|
InflateRect(&combo->textRect, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
|
||||||
*/
|
|
||||||
InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
|
|
||||||
|
|
||||||
/*
|
/* Chop off the bottom part to fit with the height of the text area. */
|
||||||
* Chop off the bottom part to fit with the height of the text area.
|
combo->textRect.bottom = combo->textRect.top + CBGetTextAreaHeight(combo->self, combo);
|
||||||
*/
|
|
||||||
lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
|
|
||||||
|
|
||||||
/*
|
/* The button starts the same vertical position as the text area. */
|
||||||
* The button starts the same vertical position as the text area.
|
combo->buttonRect = combo->textRect;
|
||||||
*/
|
|
||||||
CopyRect(lprButton, lprEdit);
|
|
||||||
|
|
||||||
/*
|
/* If the combobox is "simple" there is no button. */
|
||||||
* If the combobox is "simple" there is no button.
|
if (CB_GETTYPE(combo) == CBS_SIMPLE)
|
||||||
*/
|
combo->buttonRect.left = combo->buttonRect.right = combo->buttonRect.bottom = 0;
|
||||||
if( CB_GETTYPE(lphc) == CBS_SIMPLE )
|
else
|
||||||
lprButton->left = lprButton->right = lprButton->bottom = 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Let's assume the combobox button is the same width as the
|
|
||||||
* scrollbar button.
|
|
||||||
* size the button horizontally and cut-off the text area.
|
|
||||||
*/
|
|
||||||
lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
|
|
||||||
lprEdit->right = lprButton->left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* In the case of a dropdown, there is an additional spacing between the
|
|
||||||
* text area and the button.
|
|
||||||
*/
|
|
||||||
if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
|
|
||||||
{
|
|
||||||
lprEdit->right -= COMBO_EDITBUTTONSPACE();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If we have an edit control, we space it away from the borders slightly.
|
|
||||||
*/
|
|
||||||
if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
|
|
||||||
{
|
|
||||||
InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Adjust the size of the listbox popup.
|
|
||||||
*/
|
|
||||||
if( CB_GETTYPE(lphc) == CBS_SIMPLE )
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Use the client rectangle to initialize the listbox rectangle
|
|
||||||
*/
|
|
||||||
GetClientRect(hwnd, lprLB);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Then, chop-off the top part.
|
|
||||||
*/
|
|
||||||
lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Make sure the dropped width is as large as the combobox itself.
|
|
||||||
*/
|
|
||||||
if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
|
|
||||||
{
|
{
|
||||||
lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
|
/*
|
||||||
|
* Let's assume the combobox button is the same width as the
|
||||||
|
* scrollbar button.
|
||||||
|
* size the button horizontally and cut-off the text area.
|
||||||
|
*/
|
||||||
|
combo->buttonRect.left = combo->buttonRect.right - GetSystemMetrics(SM_CXVSCROLL);
|
||||||
|
combo->textRect.right = combo->buttonRect.left;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/* In the case of a dropdown, there is an additional spacing between the text area and the button. */
|
||||||
* In the case of a dropdown, the popup listbox is offset to the right.
|
if (CB_GETTYPE(combo) == CBS_DROPDOWN)
|
||||||
* so, we want to make sure it's flush with the right side of the
|
combo->textRect.right -= COMBO_EDITBUTTONSPACE();
|
||||||
* combobox
|
|
||||||
*/
|
/* If we have an edit control, we space it away from the borders slightly. */
|
||||||
if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
|
if (CB_GETTYPE(combo) != CBS_DROPDOWNLIST)
|
||||||
lprLB->right -= COMBO_EDITBUTTONSPACE();
|
InflateRect(&combo->textRect, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
|
||||||
|
|
||||||
|
/* Adjust the size of the listbox popup. */
|
||||||
|
if (CB_GETTYPE(combo) == CBS_SIMPLE)
|
||||||
|
{
|
||||||
|
GetClientRect(combo->self, &combo->droppedRect);
|
||||||
|
combo->droppedRect.top = combo->textRect.bottom + COMBO_YBORDERSIZE();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
lprLB->right = lprLB->left + lphc->droppedWidth;
|
{
|
||||||
}
|
/* Make sure the dropped width is as large as the combobox itself. */
|
||||||
|
if (combo->droppedWidth < (combo->buttonRect.right + COMBO_XBORDERSIZE()))
|
||||||
|
{
|
||||||
|
combo->droppedRect.right = combo->droppedRect.left + (combo->buttonRect.right + COMBO_XBORDERSIZE());
|
||||||
|
|
||||||
/* don't allow negative window width */
|
/* In the case of a dropdown, the popup listbox is offset to the right. We want to make sure it's flush
|
||||||
if (lprEdit->right < lprEdit->left)
|
with the right side of the combobox */
|
||||||
lprEdit->right = lprEdit->left;
|
if (CB_GETTYPE(combo) == CBS_DROPDOWN)
|
||||||
|
combo->droppedRect.right -= COMBO_EDITBUTTONSPACE();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
combo->droppedRect.right = combo->droppedRect.left + combo->droppedWidth;
|
||||||
|
}
|
||||||
|
|
||||||
TRACE("\ttext\t= (%s)\n", wine_dbgstr_rect(lprEdit));
|
/* Disallow negative window width */
|
||||||
|
if (combo->textRect.right < combo->textRect.left)
|
||||||
|
combo->textRect.right = combo->textRect.left;
|
||||||
|
|
||||||
TRACE("\tbutton\t= (%s)\n", wine_dbgstr_rect(lprButton));
|
TRACE("text %s, button %s, lbox %s.\n", wine_dbgstr_rect(&combo->textRect), wine_dbgstr_rect(&combo->buttonRect),
|
||||||
|
wine_dbgstr_rect(&combo->droppedRect));
|
||||||
TRACE("\tlbox\t= (%s)\n", wine_dbgstr_rect(lprLB));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -472,7 +431,7 @@ static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG
|
||||||
* recalculated.
|
* recalculated.
|
||||||
*/
|
*/
|
||||||
GetClientRect( hwnd, &lphc->droppedRect );
|
GetClientRect( hwnd, &lphc->droppedRect );
|
||||||
CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
|
CBCalcPlacement(lphc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adjust the position of the popup listbox if it's necessary
|
* Adjust the position of the popup listbox if it's necessary
|
||||||
|
@ -1472,11 +1431,7 @@ static void COMBO_Size( LPHEADCOMBO lphc )
|
||||||
SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW);
|
SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBCalcPlacement(lphc->self,
|
CBCalcPlacement(lphc);
|
||||||
lphc,
|
|
||||||
&lphc->textRect,
|
|
||||||
&lphc->buttonRect,
|
|
||||||
&lphc->droppedRect);
|
|
||||||
|
|
||||||
CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
|
CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
|
||||||
}
|
}
|
||||||
|
@ -1504,11 +1459,7 @@ static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
|
||||||
*/
|
*/
|
||||||
if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
|
if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
|
||||||
{
|
{
|
||||||
CBCalcPlacement(lphc->self,
|
CBCalcPlacement(lphc);
|
||||||
lphc,
|
|
||||||
&lphc->textRect,
|
|
||||||
&lphc->buttonRect,
|
|
||||||
&lphc->droppedRect);
|
|
||||||
|
|
||||||
CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
|
CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
|
||||||
}
|
}
|
||||||
|
@ -1537,11 +1488,7 @@ static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
|
||||||
*/
|
*/
|
||||||
if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
|
if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
|
||||||
{
|
{
|
||||||
CBCalcPlacement(lphc->self,
|
CBCalcPlacement(lphc);
|
||||||
lphc,
|
|
||||||
&lphc->textRect,
|
|
||||||
&lphc->buttonRect,
|
|
||||||
&lphc->droppedRect);
|
|
||||||
|
|
||||||
CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
|
CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
|
||||||
}
|
}
|
||||||
|
@ -2049,7 +1996,7 @@ static LRESULT CALLBACK COMBO_WindowProc( HWND hwnd, UINT message, WPARAM wParam
|
||||||
lphc->droppedWidth = 0;
|
lphc->droppedWidth = 0;
|
||||||
|
|
||||||
/* recalculate the combobox area */
|
/* recalculate the combobox area */
|
||||||
CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
|
CBCalcPlacement(lphc);
|
||||||
|
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case CB_GETDROPPEDWIDTH:
|
case CB_GETDROPPEDWIDTH:
|
||||||
|
|
Loading…
Reference in New Issue