30 #define YUILogComponent "ui" 33 #include "YButtonBox.h" 34 #include "YPushButton.h" 36 #include "YApplication.h" 51 : sanityCheckRelaxed( false )
59 bool sanityCheckRelaxed;
70 YUI_CHECK_NEW( priv );
100 policy.buttonOrder = YKDEButtonOrder;
101 policy.equalSizeButtons =
false;
102 policy.alignment[ YD_HORIZ ] = YAlignCenter;
103 policy.alignment[ YD_VERT ] = YAlignBegin;
114 policy.buttonOrder = YGnomeButtonOrder;
115 policy.equalSizeButtons =
true;
116 policy.alignment[ YD_HORIZ ] = YAlignEnd;
117 policy.alignment[ YD_VERT ] = YAlignBegin;
118 policy.addExcessSpaceToHelpButtonExtraMargin =
true;
134 return _defaultMargins;
148 return priv->margins;
165 if ( buttons.empty() )
173 bool equalSizeButtons = _layoutPolicy.equalSizeButtons;
180 if ( width < prefWidth )
182 if ( equalSizeButtons )
184 int buttonWidthWithoutMargins =
maxChildSize( YD_HORIZ ) * buttons.size();
186 if ( width < buttonWidthWithoutMargins )
201 equalSizeButtons =
false;
209 if ( width < prefWidth )
213 int missing = prefWidth - width;
215 if ( missing <= margins.left + margins.right )
217 margins.left -= missing / 2;
218 margins.right -= missing / 2;
223 missing -= margins.left;
224 missing -= margins.right;
229 if ( missing > 0 && buttons.size() > 1 )
233 int totalSpacing = ( buttons.size() - 1 ) * margins.spacing;
235 if ( missing <= totalSpacing )
237 totalSpacing -= missing;
238 margins.spacing = totalSpacing / ( buttons.size() - 1 );
243 missing -= totalSpacing;
248 if ( missing > 0 && helpButton )
252 if ( missing <= margins.helpButtonExtraSpacing )
254 margins.helpButtonExtraSpacing -= missing;
259 missing -= margins.helpButtonExtraSpacing;
260 margins.helpButtonExtraSpacing = 0;
268 widthLoss = missing / buttons.size();
271 if ( width > prefWidth )
273 int excessWidth = width - prefWidth;
275 if ( _layoutPolicy.addExcessSpaceToHelpButtonExtraMargin && helpButton )
277 margins.helpButtonExtraSpacing += excessWidth;
281 switch ( _layoutPolicy.alignment[ YD_HORIZ ] )
284 margins.left += excessWidth / 2;
285 margins.right += excessWidth / 2;
289 case YAlignUnchanged:
290 margins.right += excessWidth;
294 margins.left += excessWidth;
307 if ( height < prefHeight )
311 int missing = prefHeight - height;
313 if ( missing < margins.top + margins.bottom )
315 margins.top -= missing / 2;
316 margins.bottom -= missing / 2;
325 if ( height < buttonHeight )
327 buttonHeight = height;
330 int y_pos = margins.top;
332 if ( height > prefHeight )
336 int excessHeight = height - buttonHeight;
337 excessHeight -= margins.top;
338 excessHeight -= margins.bottom;
340 switch ( _layoutPolicy.alignment[ YD_VERT ] )
343 case YAlignUnchanged:
347 y_pos += excessHeight / 2;
351 y_pos += excessHeight;
361 int x_pos = margins.left;
364 if ( equalSizeButtons )
367 buttonWidth -= widthLoss;
372 for ( std::vector<YPushButton *>::iterator it = buttons.begin();
381 if ( button == helpButton && button != buttons.front() )
382 x_pos += margins.helpButtonExtraSpacing;
384 if ( ! equalSizeButtons )
387 buttonWidth -= widthLoss;
390 button->
setSize( buttonWidth, buttonHeight );
393 moveChild( button, width - x_pos - buttonWidth, y_pos );
397 x_pos += buttonWidth;
398 x_pos += margins.spacing;
403 if ( button == helpButton )
404 x_pos += margins.helpButtonExtraSpacing;
409 std::vector<YPushButton *>
412 std::vector<YPushButton *> specialButtons( YMaxButtonRole, (
YPushButton *) 0 );
413 std::vector<YPushButton *> customButtons;
424 switch ( button->
role() )
430 case YRelNotesButton:
432 if ( specialButtons[ button->
role() ] )
434 std::string msg =
"Multiple buttons with that role [";
441 specialButtons[ button->
role() ] = button;
446 customButtons.push_back( button );
455 std::vector<YPushButton *> buttons;
457 if ( _layoutPolicy.buttonOrder == YKDEButtonOrder )
459 if ( specialButtons[ YOKButton ] ) buttons.push_back( specialButtons[ YOKButton ] );
460 if ( specialButtons[ YApplyButton ] ) buttons.push_back( specialButtons[ YApplyButton ] );
461 if ( specialButtons[ YCancelButton ] ) buttons.push_back( specialButtons[ YCancelButton ] );
463 buttons.insert( buttons.end(), customButtons.begin(), customButtons.end() );
465 if ( specialButtons[ YHelpButton ] ) buttons.push_back( specialButtons[ YHelpButton ] );
469 if ( specialButtons[ YHelpButton ] ) buttons.push_back( specialButtons[ YHelpButton ] );
471 buttons.insert( buttons.end(), customButtons.begin(), customButtons.end() );
473 if ( specialButtons[ YApplyButton ] ) buttons.push_back( specialButtons[ YApplyButton ] );
474 if ( specialButtons[ YCancelButton ] ) buttons.push_back( specialButtons[ YCancelButton ] );
475 if ( specialButtons[ YOKButton ] ) buttons.push_back( specialButtons[ YOKButton ] );
491 if ( equalSizeButtons )
496 width += priv->margins.left;
497 width += priv->margins.right;
499 if ( priv->margins.helpButtonExtraSpacing )
502 width += priv->margins.helpButtonExtraSpacing;
520 height += priv->margins.top;
521 height += priv->margins.bottom;
536 maxSize = max( maxSize, (*it)->preferredSize( dim ) );
552 totalWidth += (*it)->preferredWidth();
564 case YD_HORIZ:
return true;
565 case YD_VERT :
return false;
583 if ( button && button->
role() == role )
594 priv->sanityCheckRelaxed = relaxed;
601 return priv->sanityCheckRelaxed;
620 switch ( button->
role() )
636 cancelButton = button;
647 if ( ! okButton || ! cancelButton )
Exception class for "value other than YD_HORIZ or YD_VERT used for dimension".
Abstract base template class for children management, such as child widgets.
bool reverseLayout() const
Returns 'true' if widget geometry should be reversed for languages that have right-to-left writing di...
static YApplication * app()
Return the global YApplication object.
Exception class for "invalid child".