Author: sh-sh-sh
Date: Thu Aug 21 14:47:35 2008
New Revision: 50272
URL: http://svn.opensuse.org/viewcvs/yast?rev=50272&view=rev
Log:
Added ButtonBox
Modified:
trunk/libyui/VERSION
trunk/libyui/src/Makefile.am
trunk/libyui/src/YButtonBox.cc
trunk/libyui/src/YButtonBox.h
trunk/libyui/src/YPushButton.cc
trunk/libyui/src/YPushButton.h
trunk/libyui/src/YTypes.h
trunk/libyui/src/YWidgetFactory.h
Modified: trunk/libyui/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/VERSION?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/VERSION (original)
+++ trunk/libyui/VERSION Thu Aug 21 14:47:35 2008
@@ -1 +1 @@
-2.17.5
+2.17.6
Modified: trunk/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/Makefile.am?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/src/Makefile.am (original)
+++ trunk/libyui/src/Makefile.am Thu Aug 21 14:47:35 2008
@@ -48,6 +48,7 @@
YAlignment.cc \
YBarGraph.cc \
YBusyIndicator.cc \
+ YButtonBox.cc \
YCheckBox.cc \
YCheckBoxFrame.cc \
YComboBox.cc \
@@ -136,6 +137,7 @@
YAlignment.h \
YBarGraph.h \
YBusyIndicator.h \
+ YButtonBox.h \
YCheckBoxFrame.h \
YCheckBox.h \
YComboBox.h \
Modified: trunk/libyui/src/YButtonBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YButtonBox.cc?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/src/YButtonBox.cc (original)
+++ trunk/libyui/src/YButtonBox.cc Thu Aug 21 14:47:35 2008
@@ -44,7 +44,7 @@
* Constructor
**/
YButtonBoxPrivate()
- : margins( _defaultMargins )
+ : margins( YButtonBox::_defaultMargins )
{}
//
@@ -57,7 +57,7 @@
-YButtonBox::YButtonBox()
+YButtonBox::YButtonBox( YWidget * parent )
: YWidget( parent )
, priv( new YButtonBoxPrivate() )
{
@@ -157,12 +157,18 @@
if ( buttons.empty() )
return;
-
+
YPushButton * helpButton = findButton( YHelpButton );
-
+
int prefWidth = preferredWidth();
int prefHeight = preferredHeight();
YButtonBoxMargins margins = priv->margins;
+
+
+ //
+ // Horizontal layout
+ //
+
int widthLoss = 0;
if ( width < prefWidth ) // Not enough horizontal space
@@ -185,16 +191,16 @@
margins.right = 0;
}
- if ( missing > 0 && buttons.count() > 1 )
+ if ( missing > 0 && buttons.size() > 1 )
{
// Try reducing spacing
-
- int totalSpacing = ( buttons.count() - 1 ) * margins.spacing;
+
+ int totalSpacing = ( buttons.size() - 1 ) * margins.spacing;
if ( missing <= totalSpacing )
{
totalSpacing -= missing;
- margins.spacing = totalSpacing / ( buttons.count() - 1 );
+ margins.spacing = totalSpacing / ( buttons.size() - 1 );
missing = 0;
}
else
@@ -207,7 +213,7 @@
if ( missing > 0 && helpButton )
{
// Try reducing help button extra spacing
-
+
if ( missing <= margins.helpButtonExtraSpacing )
{
margins.helpButtonExtraSpacing -= missing;
@@ -220,39 +226,44 @@
}
}
-
+
// Distribute missing width among all buttons
-
+
if ( missing > 0 )
- widthLoss = missing / buttons.count();
+ widthLoss = missing / buttons.size();
}
if ( width > prefWidth ) // Excess horizontal space
{
int excessWidth = width - prefWidth;
-
+
switch ( _layoutPolicy.alignment[ YD_HORIZ ] )
{
case YAlignCenter:
margins.left += excessWidth / 2;
margins.right += excessWidth / 2;
break;
-
+
case YAlignBegin:
+ case YAlignUnchanged:
margins.right += excessWidth;
break;
-
+
case YAlignEnd:
margins.left += excessWidth;
break;
}
}
+
+ //
+ // Vertical layout
+ //
if ( height < prefHeight ) // Not enough vertical space
{
// Reduce margins
-
+
int missing = prefHeight - height;
if ( missing < margins.top + margins.bottom )
@@ -267,25 +278,33 @@
}
}
+
+ //
+ // Set child widget positions and sizes from left to right
+ //
int x_pos = margins.left;
int buttonWidth = 0;
-
+
if ( _layoutPolicy.equalSizeButtons )
{
buttonWidth = maxChildSize( YD_HORIZ );
buttonWidth -= widthLoss;
}
+
for ( vector::iterator it = buttons.begin();
it != buttons.end();
++it )
{
YPushButton * button = *it;
- if ( button == helpButton && button != buttons.front() )
- x_pos += helpButtonExtraSpacing;
+ // Extra spacing left of [Help] button
+ // (Only if this isn't the first button)
+ if ( button == helpButton && button != buttons.front() )
+ x_pos += margins.helpButtonExtraSpacing;
+
if ( ! _layoutPolicy.equalSizeButtons )
{
buttonWidth = button->preferredWidth();
@@ -305,7 +324,7 @@
else // Excess vertical space
{
// Distribute excess vertical space
-
+
int excessHeight = height - buttonHeight;
excessHeight -= margins.top;
excessHeight -= margins.bottom;
@@ -313,8 +332,9 @@
switch ( _layoutPolicy.alignment[ YD_VERT ] )
{
case YAlignBegin: // Align top
+ case YAlignUnchanged:
break;
-
+
case YAlignCenter:
y_pos += excessHeight / 2;
break;
@@ -331,6 +351,9 @@
x_pos += buttonWidth;
x_pos += margins.spacing;
+
+ // Extra spacing right of [Help] button
+
if ( button == helpButton )
x_pos += margins.helpButtonExtraSpacing;
}
@@ -338,7 +361,7 @@
vector
-YButtonBox::buttonsByButtonOrder() const
+YButtonBox::buttonsByButtonOrder()
{
vector specialButtons( YMaxButtonRole, (YPushButton *) 0 );
vector customButtons;
@@ -350,8 +373,8 @@
YPushButton * button = dynamic_cast (*it);
if ( ! button )
- YUI_THROW( YUIInvalidChildException( this, *it ) );
-
+ YUI_THROW( YUIInvalidChildException<YWidget>( this, *it ) );
+
switch ( button->role() )
{
case YOKButton:
@@ -399,7 +422,7 @@
if ( specialButtons[ YHelpButton ] ) buttons.push_back( specialButtons[ YHelpButton ] );
buttons.insert( buttons.end(), customButtons.begin(), customButtons.end() );
-
+
if ( specialButtons[ YApplyButton ] ) buttons.push_back( specialButtons[ YApplyButton ] );
if ( specialButtons[ YCancelButton ] ) buttons.push_back( specialButtons[ YCancelButton ] );
if ( specialButtons[ YOKButton ] ) buttons.push_back( specialButtons[ YOKButton ] );
@@ -415,7 +438,7 @@
if ( childrenCount() < 1 )
return 0;
- int width = ( childrenCount() - 1 ) * priv->spacing;
+ int width = ( childrenCount() - 1 ) * priv->margins.spacing;
if ( _layoutPolicy.equalSizeButtons )
width += maxChildSize( YD_HORIZ ) * childrenCount();
@@ -455,7 +478,7 @@
it != childrenEnd();
++it )
{
- maxChildSize = max( maxChildSize, (*it)->preferredSize( dim ) );
+ maxSize = max( maxSize, (*it)->preferredSize( dim ) );
}
return maxSize;
@@ -481,7 +504,7 @@
bool
YButtonBox::stretchable( YUIDimension dimension ) const
{
- switch ( dim )
+ switch ( dimension )
{
case YD_HORIZ: return true;
case YD_VERT : return false;
@@ -494,7 +517,7 @@
YPushButton *
-YButtonBox::findButton( YButtonRole * role )
+YButtonBox::findButton( YButtonRole role )
{
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
@@ -502,7 +525,7 @@
{
YPushButton * button = dynamic_cast (*it);
- if ( button && button->role == role )
+ if ( button && button->role() == role )
return button;
}
@@ -513,8 +536,8 @@
void
YButtonBox::sanityCheck()
{
- YPushButton okButton = 0;
- YPushButton cancelButton = 0;
+ YPushButton * okButton = 0;
+ YPushButton * cancelButton = 0;
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
@@ -523,7 +546,7 @@
YPushButton * button = dynamic_cast (*it);
if ( ! button )
- YUI_THROW( YUIInvalidChildException( this, *it ) );
+ YUI_THROW( YUIInvalidChildException<YWidget>( this, *it ) );
switch ( button->role() )
{
@@ -555,6 +578,4 @@
if ( ! okButton || ! cancelButton )
YUI_THROW( YUIButtonRoleMismatchException( "Button role mismatch: Must have both [OK] and [Cancel] roles" ) );
}
-
- return 0;
}
Modified: trunk/libyui/src/YButtonBox.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YButtonBox.h?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/src/YButtonBox.h (original)
+++ trunk/libyui/src/YButtonBox.h Thu Aug 21 14:47:35 2008
@@ -139,6 +139,8 @@
**/
class YButtonBox : public YWidget
{
+ friend class YButtonBoxPrivate;
+
protected:
/**
* Constructor.
@@ -221,10 +223,13 @@
* button order is implemented.
*
* This method is called by the default setSize() method. It uses
- * YButtonBox::buttonOrder(), the specified margins (defaultMargins unless
- * changed with setMargins() ) and equalButtonSize(). It should
- * work reasonably in all cases (Qt-UI with KDE button order, Gtk-UI with
- * Gnome button order, NCurses-UI with KDE button order).
+ * YButtonBox::layoutPolicy() and the specified margins (defaultMargins
+ * unless changed with setMargins() ). It moves the buttons to their
+ * position with moveChild().
+ *
+ * This all should work reasonably in all cases (Qt-UI with KDE button
+ * order, Gtk-UI with Gnome button order, NCurses-UI with KDE button
+ * order).
*
* Still, derived classes can reimplement this. It does not make very much
* sense to call this default method in a new implementation.
@@ -235,7 +240,30 @@
* Search the child widgets for the first button with the specified role.
* Return the button or 0 if there is no button with that role.
**/
- YPushButton * findButton( YButtonRole * role );
+ YPushButton * findButton( YButtonRole role );
+
+ /**
+ * Sanity check: Check if all child widgets have the correct widget class
+ * and if the button roles are assigned correctly.
+ *
+ * A YButtonBox with more than one button is required to have one YOKButton
+ * and ony YCancelButton. Neither button role may be assigned more than
+ * once.
+ *
+ * This method may throw exceptions:
+ * - YUIButtonRoleMismatchException
+ * - YUIInvalidChildException (wrong widget class)
+ *
+ * This cannot be done as child widgets are inserted since this is done
+ * from the child widgets' constructors, so virtual methods or dynamic_cast
+ * don't work at that point.
+ *
+ * This is called in the default setSize() method (just before doLayout()),
+ * so any of the above errors are caught only at that time. Applications
+ * are free to call this before that time to make error handling more
+ * transparent.
+ **/
+ void sanityCheck();
/**
* Preferred width of the widget.
@@ -293,7 +321,7 @@
* are multiple buttons with any of the standard button roles (except
* YCustomButton, of course).
**/
- virtual std::vector buttonsByButtonOrder() const;
+ virtual std::vector buttonsByButtonOrder();
/**
* Return the (preferred) size of the biggest child widget in the specified
Modified: trunk/libyui/src/YPushButton.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YPushButton.cc?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/src/YPushButton.cc (original)
+++ trunk/libyui/src/YPushButton.cc Thu Aug 21 14:47:35 2008
@@ -37,7 +37,7 @@
, isDefaultButton( false )
, setDefaultButtonRecursive( false )
, isHelpButton( false )
- , buttonRole( YCustomButton )
+ , role( YCustomButton )
{}
string label;
@@ -130,13 +130,13 @@
}
-void YPushButton::setButtonRole( YButtonRole role )
+void YPushButton::setRole( YButtonRole role )
{
priv->role = role;
}
-YButtonRole YPushButton::buttonRole() const
+YButtonRole YPushButton::role() const
{
return priv->role;
}
@@ -148,7 +148,7 @@
switch ( functionKey() ) // base class method might have changed it
{
- case 10: priv->role = YOkButton; break;
+ case 10: priv->role = YOKButton; break;
case 9: priv->role = YCancelButton; break;
case 1: priv->role = YHelpButton; break;
default: break;
Modified: trunk/libyui/src/YPushButton.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YPushButton.h?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/src/YPushButton.h (original)
+++ trunk/libyui/src/YPushButton.h Thu Aug 21 14:47:35 2008
@@ -102,12 +102,12 @@
* Derived classes are free to reimplement this, but they should call this
* base class function in the overwritten function.
**/
- virtual void setButtonRole( YButtonRole role );
+ virtual void setRole( YButtonRole role );
/**
* Return the role of this button.
**/
- YButtonRole buttonRole() const;
+ YButtonRole role() const;
/**
* Assign a function key to this widget
Modified: trunk/libyui/src/YTypes.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YTypes.h?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/src/YTypes.h (original)
+++ trunk/libyui/src/YTypes.h Thu Aug 21 14:47:35 2008
@@ -74,7 +74,7 @@
enum YButtonRole
{
YCustomButton = 0, // No predefined role
- YOkButton, // [OK], [Continue], [Yes], [Accept], [Next]
+ YOKButton, // [OK], [Continue], [Yes], [Accept], [Next]
YApplyButton, // [Apply]
YCancelButton, // [Cancel]
YHelpButton, // [Help]
Modified: trunk/libyui/src/YWidgetFactory.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YWidgetFactory.h?rev=50272&r1=50271&r2=50272&view=diff
==============================================================================
--- trunk/libyui/src/YWidgetFactory.h (original)
+++ trunk/libyui/src/YWidgetFactory.h Thu Aug 21 14:47:35 2008
@@ -27,6 +27,7 @@
class YWidget;
class YAlignment;
+class YButtonBox;
class YCheckBox;
class YCheckBoxFrame;
class YComboBox;
@@ -85,7 +86,8 @@
YLayoutBox * createVBox ( YWidget * parent );
YLayoutBox * createHBox ( YWidget * parent );
- virtual YLayoutBox * createLayoutBox ( YWidget * parent, YUIDimension dimension ) = 0;
+ virtual YLayoutBox * createLayoutBox ( YWidget * parent, YUIDimension dimension ) = 0;
+ virtual YButtonBox * createButtonBox ( YWidget * parent ) = 0;
//
// Common Leaf Widgets
@@ -150,7 +152,7 @@
YAlignment * createMinWidth ( YWidget * parent, YLayoutSize_t minWidth );
YAlignment * createMinHeight ( YWidget * parent, YLayoutSize_t minHeight );
YAlignment * createMinSize ( YWidget * parent, YLayoutSize_t minWidth, YLayoutSize_t minHeight );
-
+
virtual YAlignment * createAlignment ( YWidget * parent, YAlignmentType horAlignment, YAlignmentType vertAlignment ) = 0;
YSquash * createHSquash ( YWidget * parent );
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org