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 <tqcolor.h> 00029 #include <tqfont.h> 00030 #include <tqobject.h> 00031 #include <tqiconset.h> 00032 #include <netwm_def.h> 00033 #include <tdeversion.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 ShadowOp, 00104 SuspendWindowOp, 00105 ResumeWindowOp 00106 }; 00112 enum ColorType 00113 { 00114 ColorTitleBar, 00115 ColorTitleBlend, 00116 ColorFont, 00117 ColorButtonBg, 00118 ColorFrame, 00119 ColorHandle, 00120 NUM_COLORS 00121 }; 00122 00127 enum 00128 { 00129 SettingDecoration = 1 << 0, 00130 SettingColors = 1 << 1, 00131 SettingFont = 1 << 2, 00132 SettingButtons = 1 << 3, 00133 SettingTooltips = 1 << 4, 00134 SettingBorder = 1 << 5 00135 }; 00136 00141 enum BorderSize 00142 { 00143 BorderTiny, 00144 BorderNormal, 00145 BorderLarge, 00146 BorderVeryLarge, 00147 BorderHuge, 00148 BorderVeryHuge, 00149 BorderOversized, 00150 BordersCount 00151 }; 00152 00157 enum Ability 00158 { 00159 AbilityAnnounceButtons = 0, 00160 AbilityButtonMenu = 1000, 00161 AbilityButtonOnAllDesktops = 1001, 00162 AbilityButtonSpacer = 1002, 00163 AbilityButtonHelp = 1003, 00164 AbilityButtonMinimize = 1004, 00165 AbilityButtonMaximize = 1005, 00166 AbilityButtonClose = 1006, 00167 AbilityButtonAboveOthers = 1007, 00168 AbilityButtonBelowOthers = 1008, 00169 AbilityButtonShade = 1009, 00170 AbilityButtonResize = 1010, 00171 ABILITY_DUMMY = 10000000 00172 }; 00173 00174 enum Requirement { REQUIREMENT_DUMMY = 1000000 }; 00175 }; 00176 00177 class KDecorationProvides 00178 : public KDecorationDefines 00179 { 00180 public: 00181 virtual bool provides( Requirement req ) = 0; 00182 }; 00183 00190 class KWIN_EXPORT KDecorationOptions : public KDecorationDefines 00191 { 00192 public: 00193 KDecorationOptions(); 00194 virtual ~KDecorationOptions(); 00202 const TQColor& color(ColorType type, bool active=true) const; 00210 const TQColorGroup& colorGroup(ColorType type, bool active=true) const; 00218 const TQFont& font(bool active=true, bool small = false) const; 00226 bool customButtonPositions() const; 00248 TQString titleButtonsLeft() const; 00260 TQString titleButtonsRight() const; 00261 00266 bool showTooltips() const; 00267 00278 BorderSize preferredBorderSize( KDecorationFactory* factory ) const; 00279 00280 /* 00281 * When this functions returns false, moving and resizing of maximized windows 00282 * is not allowed, and therefore the decoration is allowed to turn off (some of) 00283 * its borders. 00284 * The changed flags for this setting is SettingButtons. 00285 */ 00286 bool moveResizeMaximizedWindows() const; 00287 00291 WindowOperation operationMaxButtonClick( TQt::ButtonState button ) const; 00292 00296 virtual unsigned long updateSettings() = 0; // returns SettingXYZ mask 00297 00298 protected: 00302 KDecorationOptionsPrivate* d; 00303 }; 00304 00305 00313 class KWIN_EXPORT KDecoration 00314 : public TQObject, public KDecorationDefines 00315 { 00316 Q_OBJECT 00317 public: 00323 KDecoration( KDecorationBridge* bridge, KDecorationFactory* factory ); 00327 virtual ~KDecoration(); 00328 00329 // requests from decoration 00330 00335 static const KDecorationOptions* options(); 00339 bool isActive() const; 00343 bool isCloseable() const; 00347 bool isMaximizable() const; 00353 MaximizeMode maximizeMode() const; 00357 bool isMinimizable() const; 00362 bool providesContextHelp() const; 00368 int desktop() const; 00373 bool isOnAllDesktops() const; // convenience 00377 bool isModal() const; 00381 bool isShadeable() const; 00390 bool isShade() const; 00398 bool isSetShade() const; 00402 bool keepAbove() const; 00406 bool keepBelow() const; 00410 bool isMovable() const; 00414 bool isResizable() const; 00438 NET::WindowType windowType( unsigned long supported_types ) const; 00442 TQIconSet icon() const; 00446 TQString caption() const; 00473 void showWindowMenu( const TQRect &pos ); 00474 00478 void showWindowMenu( TQPoint pos ); 00483 void performWindowOperation( WindowOperation op ); 00492 void setMask( const TQRegion& reg, int mode = 0 ); 00496 void clearMask(); // convenience 00502 bool isPreview() const; 00506 TQRect geometry() const; 00512 TQRect iconGeometry() const; 00521 TQRegion unobscuredRegion( const TQRegion& r ) const; 00526 TQWidget* workspaceWidget() const; 00540 WId windowId() const; 00544 int width() const; // convenience 00548 int height() const; // convenience 00554 void processMousePressEvent( TQMouseEvent* e ); 00555 00556 // requests to decoration 00557 00563 virtual void init() = 0; // called once right after created 00564 00570 virtual Position mousePosition( const TQPoint& p ) const = 0; 00571 00584 // mustn't do any repaints, resizes or anything like that 00585 virtual void borders( int& left, int& right, int& top, int& bottom ) const = 0; 00593 virtual void resize( const TQSize& s ) = 0; 00599 virtual TQSize minimumSize() const = 0; 00604 virtual void activeChange() = 0; 00608 virtual void captionChange() = 0; 00612 virtual void iconChange() = 0; 00617 virtual void maximizeChange() = 0; 00623 virtual void desktopChange() = 0; 00628 virtual void shadeChange() = 0; 00629 #if KDE_IS_VERSION( 3, 90, 0 ) 00630 #warning Redo all the XYZChange() virtuals as signals. 00631 #endif 00632 signals: 00637 void keepAboveChanged( bool ); 00642 void keepBelowChanged( bool ); 00643 public: 00657 virtual bool drawbound( const TQRect& geom, bool clear ); 00668 virtual bool animateMinimize( bool minimize ); 00672 // TODO position will need also values for top+left+bottom etc. docking ? 00673 virtual bool windowDocked( Position side ); 00680 virtual void reset( unsigned long changed ); 00681 00682 // special 00683 00690 void setMainWidget( TQWidget* ); 00700 void createMainWidget( TQt::WFlags flags = 0 ); 00704 TQWidget* initialParentWidget() const; 00711 TQt::WFlags initialWFlags() const; 00718 void helperShowHide( bool show ); 00722 TQWidget* widget(); 00726 const TQWidget* widget() const; 00730 KDecorationFactory* factory() const; 00734 void grabXServer(); 00738 void ungrabXServer(); 00739 public slots: 00740 // requests from decoration 00741 00749 void closeWindow(); 00750 /* 00751 * Changes the maximize mode of the decorated window. This function should 00752 * be preferred to the other maximize() overload for reacting on clicks 00753 * on the maximize titlebar button. 00754 * NOTE: This function is new in KDE3.3. In order to support also KDE3.2, 00755 * it is recommended to use code like this: 00756 * \code 00757 * ButtonState button = ... ; 00758 * #if KDE_IS_VERSION( 3, 3, 0 ) 00759 * maximize( button ); 00760 * #else 00761 * if( button == MidButton ) 00762 * maximize( maximizeMode() ^ MaximizeVertical ); 00763 * else if( button == RightButton ) 00764 * maximize( maximizeMode() ^ MaximizeHorizontal ); 00765 * else 00766 * maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull ); 00767 * #endif 00768 * \endcode 00769 * @since 3.3 00770 */ 00771 #if KDE_IS_VERSION( 3, 90, 0 ) 00772 #warning Update the docs. 00773 #endif 00774 void maximize( ButtonState button ); 00779 void maximize( MaximizeMode mode ); 00783 void minimize(); 00788 void showContextHelp(); 00793 void setDesktop( int desktop ); 00797 void toggleOnAllDesktops(); // convenience 00802 void titlebarDblClickOperation(); 00809 void titlebarMouseWheelOperation( int delta ); 00814 void setShade( bool set ); 00819 void setKeepAbove( bool set ); 00824 void setKeepBelow( bool set ); 00828 void emitKeepAboveChanged( bool above ) { emit keepAboveChanged( above ); } 00832 void emitKeepBelowChanged( bool below ) { emit keepBelowChanged( below ); } 00833 private: 00834 KDecorationBridge* bridge_; 00835 TQWidget* w_; 00836 KDecorationFactory* factory_; 00837 friend class KDecorationOptions; // for options_ 00838 static KDecorationOptions* options_; 00839 KDecorationPrivate* d; 00840 }; 00841 00842 inline 00843 KDecorationDefines::MaximizeMode operator^( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 ) 00844 { 00845 return KDecorationDefines::MaximizeMode( int(m1) ^ int(m2) ); 00846 } 00847 00848 inline 00849 KDecorationDefines::MaximizeMode operator&( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 ) 00850 { 00851 return KDecorationDefines::MaximizeMode( int(m1) & int(m2) ); 00852 } 00853 00854 inline 00855 KDecorationDefines::MaximizeMode operator|( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 ) 00856 { 00857 return KDecorationDefines::MaximizeMode( int(m1) | int(m2) ); 00858 } 00859 00860 inline TQWidget* KDecoration::widget() 00861 { 00862 return w_; 00863 } 00864 00865 inline const TQWidget* KDecoration::widget() const 00866 { 00867 return w_; 00868 } 00869 00870 inline KDecorationFactory* KDecoration::factory() const 00871 { 00872 return factory_; 00873 } 00874 00875 inline bool KDecoration::isOnAllDesktops() const 00876 { 00877 return desktop() == NET::OnAllDesktops; 00878 } 00879 00880 inline int KDecoration::width() const 00881 { 00882 return geometry().width(); 00883 } 00884 00885 inline int KDecoration::height() const 00886 { 00887 return geometry().height(); 00888 } 00889 00890 #endif