libyui

/data/gitorious.org/libyui/libyui-master/src/YButtonBox.h

00001 /**************************************************************************
00002 Copyright (C) 2000 - 2010 Novell, Inc.
00003 All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 **************************************************************************/
00020 
00021 
00022 /*---------------------------------------------------------------------\
00023 |                                                                      |
00024 |                      __   __    ____ _____ ____                      |
00025 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00026 |                       \ V / _` \___ \ | |   __) |                    |
00027 |                        | | (_| |___) || |  / __/                     |
00028 |                        |_|\__,_|____/ |_| |_____|                    |
00029 |                                                                      |
00030 |                               core system                            |
00031 |                                                        (C) SuSE GmbH |
00032 \----------------------------------------------------------------------/
00033 
00034   File:         YButtonBox.h
00035 
00036   Author:       Stefan Hundhammer <sh@suse.de>
00037 
00038 /-*/
00039 
00040 #ifndef YButtonBox_h
00041 #define YButtonBox_h
00042 
00043 #include <vector>
00044 
00045 #include "YWidget.h"
00046 #include "YPushButton.h"
00047 
00048 class YButtonBoxPrivate;
00049 class YPushButton;
00050 
00051 
00056 struct YButtonBoxLayoutPolicy
00057 {
00058     YButtonBoxLayoutPolicy()
00059         : buttonOrder( YKDEButtonOrder )
00060         , equalSizeButtons( false )
00061         , addExcessSpaceToHelpButtonExtraMargin( false )
00062     {
00063         alignment[ YD_HORIZ ] = YAlignCenter;
00064         alignment[ YD_VERT  ] = YAlignBegin;    // Align top
00065     }
00066 
00067     YButtonOrder        buttonOrder;      // YKDEButtonOrder / YGnomeButtonOrder
00068     bool                equalSizeButtons; // Make all buttons the same size?
00069     bool                addExcessSpaceToHelpButtonExtraMargin;
00070 
00071     // Alignment for the YButtonBox itself
00072     YAlignmentType      alignment[ YUIAllDimensions ];
00073 };
00074 
00075 
00080 struct YButtonBoxMargins
00081 {
00082     YButtonBoxMargins()
00083         : left( 0 )
00084         , right( 0 )
00085         , top( 0 )
00086         , bottom( 0 )
00087         , spacing( 0 )
00088         , helpButtonExtraSpacing( 0 )
00089         {}
00090 
00091     int left;                   // Left of the leftmost button
00092     int right;                  // Right of the rightmost button
00093     int top;                    // Above the hightest button
00094     int bottom;                 // Below the hightest button
00095 
00096     int spacing;                // Between buttons
00097     int helpButtonExtraSpacing; // Between [Help] and the next button
00098 };                              // (additionally to "spacing"!)
00099 
00100 
00163 class YButtonBox : public YWidget
00164 {
00165     friend class YButtonBoxPrivate;
00166 
00167 protected:
00171     YButtonBox( YWidget * parent );
00172 
00173 public:
00174 
00178     virtual ~YButtonBox();
00179 
00184     virtual const char * widgetClass() const { return "YButtonBox"; }
00185 
00201     static void setLayoutPolicy( const YButtonBoxLayoutPolicy & layoutPolicy );
00202 
00206     static YButtonBoxLayoutPolicy layoutPolicy();
00207 
00211     static YButtonBoxLayoutPolicy kdeLayoutPolicy();
00212 
00216     static YButtonBoxLayoutPolicy gnomeLayoutPolicy();
00217 
00221     static void setDefaultMargins( const YButtonBoxMargins & margins );
00222 
00226     static YButtonBoxMargins defaultMargins();
00227 
00234     virtual void setMargins( const YButtonBoxMargins & margins );
00235 
00242     YButtonBoxMargins margins() const;
00243 
00260     virtual void doLayout( int width, int height );
00261 
00266     YPushButton * findButton( YButtonRole role );
00267 
00289     void sanityCheck();
00290 
00311     void setSanityCheckRelaxed( bool relax = true );
00312 
00316     bool sanityCheckRelaxed() const;
00317 
00328     virtual int preferredWidth();
00329 
00339     virtual int preferredHeight();
00340 
00349     virtual void setSize( int newWidth, int newHeight );
00350 
00358     virtual bool stretchable( YUIDimension dimension ) const;
00359 
00360 
00361 protected:
00362 
00374     virtual std::vector<YPushButton *> buttonsByButtonOrder();
00375 
00380     int maxChildSize( YUIDimension dim ) const;
00381 
00385     int totalChildrenWidth() const;
00386 
00392     virtual void moveChild( YWidget * child, int newX, int newY ) = 0;
00393 
00398     int preferredWidth( bool equalSizeButtons );
00399 
00400 
00401 private:
00402 
00403     ImplPtr<YButtonBoxPrivate> priv;
00404 
00405     static YButtonBoxLayoutPolicy       _layoutPolicy;
00406     static YButtonBoxMargins            _defaultMargins;
00407 };
00408 
00409 
00410 #endif // YButtonBox_h
 All Classes Functions Variables Enumerations Friends