30 #define YUILogComponent "ui"
33 #include "YButtonBox.h"
34 #include "YPushButton.h"
36 #include "YApplication.h"
52 : sanityCheckRelaxed( false )
60 bool sanityCheckRelaxed;
71 YUI_CHECK_NEW( priv );
101 policy.buttonOrder = YKDEButtonOrder;
102 policy.equalSizeButtons =
false;
103 policy.alignment[ YD_HORIZ ] = YAlignCenter;
104 policy.alignment[ YD_VERT ] = YAlignBegin;
115 policy.buttonOrder = YGnomeButtonOrder;
116 policy.equalSizeButtons =
true;
117 policy.alignment[ YD_HORIZ ] = YAlignEnd;
118 policy.alignment[ YD_VERT ] = YAlignBegin;
119 policy.addExcessSpaceToHelpButtonExtraMargin =
true;
135 return _defaultMargins;
149 return priv->margins;
166 if ( buttons.empty() )
174 bool equalSizeButtons = _layoutPolicy.equalSizeButtons;
181 if ( width < prefWidth )
183 if ( equalSizeButtons )
185 int buttonWidthWithoutMargins =
maxChildSize( YD_HORIZ ) * buttons.size();
187 if ( width < buttonWidthWithoutMargins )
202 equalSizeButtons =
false;
210 if ( width < prefWidth )
214 int missing = prefWidth - width;
230 if ( missing > 0 && buttons.size() > 1 )
234 int totalSpacing = ( buttons.size() - 1 ) *
margins.spacing;
236 if ( missing <= totalSpacing )
238 totalSpacing -= missing;
239 margins.spacing = totalSpacing / ( buttons.size() - 1 );
244 missing -= totalSpacing;
249 if ( missing > 0 && helpButton )
253 if ( missing <=
margins.helpButtonExtraSpacing )
255 margins.helpButtonExtraSpacing -= missing;
260 missing -=
margins.helpButtonExtraSpacing;
261 margins.helpButtonExtraSpacing = 0;
269 widthLoss = missing / buttons.size();
272 if ( width > prefWidth )
274 int excessWidth = width - prefWidth;
276 if ( _layoutPolicy.addExcessSpaceToHelpButtonExtraMargin && helpButton )
278 margins.helpButtonExtraSpacing += excessWidth;
282 switch ( _layoutPolicy.alignment[ YD_HORIZ ] )
285 margins.left += excessWidth / 2;
286 margins.right += excessWidth / 2;
290 case YAlignUnchanged:
308 if ( height < prefHeight )
312 int missing = prefHeight - height;
326 if ( height < buttonHeight )
328 buttonHeight = height;
333 if ( height > prefHeight )
337 int excessHeight = height - buttonHeight;
339 excessHeight -=
margins.bottom;
341 switch ( _layoutPolicy.alignment[ YD_VERT ] )
344 case YAlignUnchanged:
348 y_pos += excessHeight / 2;
352 y_pos += excessHeight;
365 if ( equalSizeButtons )
368 buttonWidth -= widthLoss;
373 for ( vector<YPushButton *>::iterator it = buttons.begin();
382 if ( button == helpButton && button != buttons.front() )
383 x_pos +=
margins.helpButtonExtraSpacing;
385 if ( ! equalSizeButtons )
388 buttonWidth -= widthLoss;
391 button->
setSize( buttonWidth, buttonHeight );
394 moveChild( button, width - x_pos - buttonWidth, y_pos );
398 x_pos += buttonWidth;
404 if ( button == helpButton )
405 x_pos +=
margins.helpButtonExtraSpacing;
410 vector<YPushButton *>
413 vector<YPushButton *> specialButtons( YMaxButtonRole, (
YPushButton *) 0 );
414 vector<YPushButton *> customButtons;
425 switch ( button->
role() )
431 case YRelNotesButton:
433 if ( specialButtons[ button->
role() ] )
435 string msg =
"Multiple buttons with that role [";
442 specialButtons[ button->
role() ] = button;
447 customButtons.push_back( button );
456 vector<YPushButton *> buttons;
458 if ( _layoutPolicy.buttonOrder == YKDEButtonOrder )
460 if ( specialButtons[ YOKButton ] ) buttons.push_back( specialButtons[ YOKButton ] );
461 if ( specialButtons[ YApplyButton ] ) buttons.push_back( specialButtons[ YApplyButton ] );
462 if ( specialButtons[ YCancelButton ] ) buttons.push_back( specialButtons[ YCancelButton ] );
464 buttons.insert( buttons.end(), customButtons.begin(), customButtons.end() );
466 if ( specialButtons[ YHelpButton ] ) buttons.push_back( specialButtons[ YHelpButton ] );
470 if ( specialButtons[ YHelpButton ] ) buttons.push_back( specialButtons[ YHelpButton ] );
472 buttons.insert( buttons.end(), customButtons.begin(), customButtons.end() );
474 if ( specialButtons[ YApplyButton ] ) buttons.push_back( specialButtons[ YApplyButton ] );
475 if ( specialButtons[ YCancelButton ] ) buttons.push_back( specialButtons[ YCancelButton ] );
476 if ( specialButtons[ YOKButton ] ) buttons.push_back( specialButtons[ YOKButton ] );
492 if ( equalSizeButtons )
497 width += priv->margins.left;
498 width += priv->margins.right;
500 if ( priv->margins.helpButtonExtraSpacing )
503 width += priv->margins.helpButtonExtraSpacing;
521 height += priv->margins.top;
522 height += priv->margins.bottom;
537 maxSize = std::max( maxSize, (*it)->preferredSize( dim ) );
553 totalWidth += (*it)->preferredWidth();
565 case YD_HORIZ:
return true;
566 case YD_VERT :
return false;
584 if ( button && button->
role() == role )
595 priv->sanityCheckRelaxed = relaxed;
602 return priv->sanityCheckRelaxed;
621 switch ( button->
role() )
637 cancelButton = button;
648 if ( ! okButton || ! cancelButton )