kdecoration.h

00001 /*****************************************************************
00002 This file is part of the KDE project.
00003 
00004 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the "Software"),
00008 to deal in the Software without restriction, including without limitation
00009 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00010 and/or sell copies of the Software, and to permit persons to whom the
00011 Software is furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00019 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00022 DEALINGS IN THE SOFTWARE.
00023 ******************************************************************/
00024 
00025 #ifndef KDECORATION_H
00026 #define KDECORATION_H
00027 
00028 #include <qcolor.h>
00029 #include <qfont.h>
00030 #include <qobject.h>
00031 #include <qiconset.h>
00032 #include <netwm_def.h>
00033 #include <kdeversion.h>
00034 
00035 class KDecorationOptionsPrivate;
00036 class KDecorationBridge;
00037 class KDecorationPrivate;
00038 class KDecorationFactory;
00039 
00040 #define KWIN_EXPORT KDE_EXPORT
00041 
00047 class KWIN_EXPORT KDecorationDefines
00048 {
00049 public:
00053     enum Position
00054         { // without prefix, they'd conflict with Qt::TopLeft etc. :(
00055         PositionCenter         = 0x00,
00056         PositionLeft           = 0x01,
00057         PositionRight          = 0x02,
00058         PositionTop            = 0x04,
00059         PositionBottom         = 0x08,
00060         PositionTopLeft        = PositionLeft | PositionTop,
00061         PositionTopRight       = PositionRight | PositionTop,
00062         PositionBottomLeft     = PositionLeft | PositionBottom,
00063         PositionBottomRight    = PositionRight | PositionBottom
00064         };
00068     // these values are written to session files, don't change the order
00069     enum MaximizeMode
00070         {
00071     MaximizeRestore    = 0, 
00072     MaximizeVertical   = 1, 
00073     MaximizeHorizontal = 2, 
00074 
00075     MaximizeFull = MaximizeVertical | MaximizeHorizontal 
00076         };
00077 
00078     enum WindowOperation
00079         {
00080         MaximizeOp = 5000,
00081         RestoreOp,
00082         MinimizeOp,
00083         MoveOp,
00084         UnrestrictedMoveOp,
00085         ResizeOp,
00086         UnrestrictedResizeOp,
00087         CloseOp,
00088         OnAllDesktopsOp,
00089         ShadeOp,
00090         KeepAboveOp,
00091         KeepBelowOp,
00092         OperationsOp,
00093         WindowRulesOp,
00094         ToggleStoreSettingsOp = WindowRulesOp, 
00095         HMaximizeOp,
00096         VMaximizeOp,
00097         LowerOp,
00098         FullScreenOp,
00099         NoBorderOp,
00100         NoOp,
00101         SetupWindowShortcutOp,
00102         ApplicationRulesOp     
00103         };
00109     enum ColorType
00110     {
00111     ColorTitleBar,   
00112     ColorTitleBlend, 
00113     ColorFont,       
00114     ColorButtonBg,   
00115     ColorFrame,      
00116     ColorHandle,     
00117     NUM_COLORS
00118     };
00119     
00124     enum
00125         {
00126         SettingDecoration = 1 << 0, 
00127         SettingColors     = 1 << 1, 
00128         SettingFont       = 1 << 2, 
00129         SettingButtons    = 1 << 3, 
00130         SettingTooltips   = 1 << 4, 
00131         SettingBorder     = 1 << 5  
00132         };
00133         
00138     enum BorderSize
00139         {
00140         BorderTiny,      
00141         BorderNormal,    
00142         BorderLarge,     
00143         BorderVeryLarge, 
00144         BorderHuge,      
00145         BorderVeryHuge,  
00146         BorderOversized, 
00147         BordersCount     
00148         };
00149 
00154     enum Ability
00155         {
00156         AbilityAnnounceButtons = 0, 
00157         AbilityButtonMenu = 1000,   
00158         AbilityButtonOnAllDesktops = 1001, 
00159         AbilityButtonSpacer = 1002, 
00160         AbilityButtonHelp = 1003,   
00161         AbilityButtonMinimize = 1004,  
00162         AbilityButtonMaximize = 1005, 
00163         AbilityButtonClose = 1006, 
00164         AbilityButtonAboveOthers = 1007, 
00165         AbilityButtonBelowOthers = 1008, 
00166         AbilityButtonShade = 1009, 
00167         AbilityButtonResize = 1010, 
00168         ABILITY_DUMMY = 10000000
00169         };
00170 
00171     enum Requirement { REQUIREMENT_DUMMY = 1000000 };
00172 };    
00173 
00174 class KDecorationProvides
00175     : public KDecorationDefines
00176     {
00177     public:
00178         virtual bool provides( Requirement req ) = 0;
00179     };
00180 
00187 class KWIN_EXPORT KDecorationOptions : public KDecorationDefines
00188     {
00189 public:
00190     KDecorationOptions();
00191     virtual ~KDecorationOptions();
00199     const QColor& color(ColorType type, bool active=true) const;
00207     const QColorGroup& colorGroup(ColorType type, bool active=true) const;
00215     const QFont& font(bool active=true, bool small = false) const;
00223     bool customButtonPositions() const;
00245     QString titleButtonsLeft() const;
00257     QString titleButtonsRight() const;
00258 
00263     bool showTooltips() const;
00264     
00275     BorderSize preferredBorderSize( KDecorationFactory* factory ) const;
00276 
00277     /*
00278      * When this functions returns false, moving and resizing of maximized windows
00279      * is not allowed, and therefore the decoration is allowed to turn off (some of)
00280      * its borders.
00281      * The changed flags for this setting is SettingButtons.
00282      */
00283     bool moveResizeMaximizedWindows() const;
00284 
00288     WindowOperation operationMaxButtonClick( Qt::ButtonState button ) const;
00289 
00293     virtual unsigned long updateSettings() = 0; // returns SettingXYZ mask
00294 
00295 protected:
00299     KDecorationOptionsPrivate* d;
00300     };
00301 
00302 
00310 class KWIN_EXPORT KDecoration
00311     : public QObject, public KDecorationDefines
00312     {
00313     Q_OBJECT
00314     public:
00320     KDecoration( KDecorationBridge* bridge, KDecorationFactory* factory );
00324     virtual ~KDecoration();
00325     
00326     // requests from decoration
00327     
00332         static const KDecorationOptions* options();
00336     bool isActive() const;
00340     bool isCloseable() const;
00344     bool isMaximizable() const;
00350     MaximizeMode maximizeMode() const;
00354     bool isMinimizable() const;
00359         bool providesContextHelp() const;
00365         int desktop() const;
00370         bool isOnAllDesktops() const; // convenience
00374         bool isModal() const;
00378         bool isShadeable() const;
00387         bool isShade() const;
00395         bool isSetShade() const;
00399         bool keepAbove() const;
00403         bool keepBelow() const;
00407         bool isMovable() const;
00411         bool isResizable() const;
00435         NET::WindowType windowType( unsigned long supported_types ) const;
00439     QIconSet icon() const;
00443     QString caption() const;
00470     void showWindowMenu( const QRect &pos );
00471 
00475     void showWindowMenu( QPoint pos );
00480     void performWindowOperation( WindowOperation op );
00489         void setMask( const QRegion& reg, int mode = 0 );
00493         void clearMask(); // convenience
00499         bool isPreview() const;
00503         QRect geometry() const;
00509         QRect iconGeometry() const;
00518         QRegion unobscuredRegion( const QRegion& r ) const;
00523         QWidget* workspaceWidget() const;
00537         WId windowId() const;
00541         int width() const; // convenience
00545         int height() const;  // convenience
00551     void processMousePressEvent( QMouseEvent* e );
00552 
00553     // requests to decoration
00554 
00560         virtual void init() = 0; // called once right after created
00561     
00567     virtual Position mousePosition( const QPoint& p ) const = 0;
00568 
00581         // mustn't do any repaints, resizes or anything like that
00582     virtual void borders( int& left, int& right, int& top, int& bottom ) const = 0;
00590     virtual void resize( const QSize& s ) = 0;
00596     virtual QSize minimumSize() const = 0;
00601         virtual void activeChange() = 0;
00605         virtual void captionChange() = 0;
00609         virtual void iconChange() = 0;
00614         virtual void maximizeChange() = 0;
00620         virtual void desktopChange() = 0;
00625         virtual void shadeChange() = 0;
00626 #if KDE_IS_VERSION( 3, 90, 0 )
00627 #warning Redo all the XYZChange() virtuals as signals.
00628 #endif
00629     signals:
00634         void keepAboveChanged( bool );
00639         void keepBelowChanged( bool );
00640     public:
00654         virtual bool drawbound( const QRect& geom, bool clear );
00665         virtual bool animateMinimize( bool minimize );
00669         // TODO position will need also values for top+left+bottom etc. docking ?
00670         virtual bool windowDocked( Position side );
00677         virtual void reset( unsigned long changed );
00678 
00679     // special
00680 
00687         void setMainWidget( QWidget* );
00697         void createMainWidget( WFlags flags = 0 );
00701         QWidget* initialParentWidget() const;
00708         WFlags initialWFlags() const;
00715         void helperShowHide( bool show );
00719     QWidget* widget();
00723     const QWidget* widget() const;
00727         KDecorationFactory* factory() const;
00731         void grabXServer();
00735         void ungrabXServer();
00736     public slots:
00737     // requests from decoration
00738 
00746     void closeWindow();
00747         /*
00748          * Changes the maximize mode of the decorated window. This function should
00749          * be preferred to the other maximize() overload for reacting on clicks
00750          * on the maximize titlebar button.
00751          * NOTE: This function is new in KDE3.3. In order to support also KDE3.2,
00752          * it is recommended to use code like this:
00753          * \code
00754          * ButtonState button = ... ;
00755          * #if KDE_IS_VERSION( 3, 3, 0 )
00756          * maximize( button );
00757          * #else
00758          * if( button == MidButton )
00759      *     maximize( maximizeMode() ^ MaximizeVertical );
00760          * else if( button == RightButton )
00761          *     maximize( maximizeMode() ^ MaximizeHorizontal );
00762          * else
00763          *     maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull );
00764          * #endif
00765          * \endcode
00766          * @since 3.3
00767          */
00768 #if KDE_IS_VERSION( 3, 90, 0 )
00769 #warning Update the docs.
00770 #endif
00771         void maximize( ButtonState button );
00776     void maximize( MaximizeMode mode );
00780     void minimize();
00785         void showContextHelp();
00790         void setDesktop( int desktop );
00794         void toggleOnAllDesktops(); // convenience
00799         void titlebarDblClickOperation();
00806         void titlebarMouseWheelOperation( int delta );
00811         void setShade( bool set );
00816         void setKeepAbove( bool set );
00821         void setKeepBelow( bool set );
00825         void emitKeepAboveChanged( bool above ) { emit keepAboveChanged( above ); }
00829         void emitKeepBelowChanged( bool below ) { emit keepBelowChanged( below ); }
00830     private:
00831     KDecorationBridge* bridge_;
00832     QWidget* w_;
00833         KDecorationFactory* factory_;
00834         friend class KDecorationOptions; // for options_
00835         static KDecorationOptions* options_;
00836         KDecorationPrivate* d;
00837     };
00838 
00839 inline
00840 KDecorationDefines::MaximizeMode operator^( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 )
00841     {
00842     return KDecorationDefines::MaximizeMode( int(m1) ^ int(m2) );
00843     }
00844 
00845 inline
00846 KDecorationDefines::MaximizeMode operator&( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 )
00847     {
00848     return KDecorationDefines::MaximizeMode( int(m1) & int(m2) );
00849     }
00850 
00851 inline
00852 KDecorationDefines::MaximizeMode operator|( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 )
00853     {
00854     return KDecorationDefines::MaximizeMode( int(m1) | int(m2) );
00855     }
00856 
00857 inline QWidget* KDecoration::widget()
00858     {
00859     return w_;
00860     }
00861 
00862 inline const QWidget* KDecoration::widget() const
00863     {
00864     return w_;
00865     }
00866 
00867 inline KDecorationFactory* KDecoration::factory() const
00868     {
00869     return factory_;
00870     }
00871 
00872 inline bool KDecoration::isOnAllDesktops() const
00873     {
00874     return desktop() == NET::OnAllDesktops;
00875     }
00876 
00877 inline int KDecoration::width() const
00878     {
00879     return geometry().width();
00880     }
00881     
00882 inline int KDecoration::height() const
00883     {
00884     return geometry().height();
00885     }
00886     
00887 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys