diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000000..eb604e0cab --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,17 @@ +# FRAME libkwin??? +lib_LTLIBRARIES = libkwin.la + +libkwin_la_SOURCES = kdecoration.cpp kdecoration_p.cpp kdecoration_plugins_p.cpp \ + kdecorationfactory.cpp +libkwin_la_LIBADD = $(LIB_KDECORE) +libkwin_la_LDFLAGS = $(all_libraries) -version-info 1:0:0 -no-undefined + +# FRAME +include_HEADERS = kdecoration.h kdecoration_p.h kdecoration_plugins_p.h \ + kdecorationfactory.h + +INCLUDES = $(all_includes) +METASOURCES = AUTO + +include ../../admin/Doxyfile.am + diff --git a/lib/kdecoration.cpp b/lib/kdecoration.cpp new file mode 100644 index 0000000000..f0d3060764 --- /dev/null +++ b/lib/kdecoration.cpp @@ -0,0 +1,381 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#include "kdecoration.h" + +#include +#include +#include +#include + +#include "kdecoration_p.h" +#include "kdecorationfactory.h" + +KDecorationOptions* KDecoration::options_; + +KDecoration::KDecoration( KDecorationBridge* bridge, KDecorationFactory* factory ) + : bridge_( bridge ), + w_( NULL ), + factory_( factory ) + { + factory->addDecoration( this ); + } + +KDecoration::~KDecoration() + { + factory()->removeDecoration( this ); + delete w_; + } + +const KDecorationOptions* KDecoration::options() + { + return options_; + } + +void KDecoration::createMainWidget( WFlags flags ) + { + // FRAME check flags? + setMainWidget( new QWidget( initialParentWidget(), "decoration widget", initialWFlags() | flags )); + } + +void KDecoration::setMainWidget( QWidget* w ) + { + assert( w_ == NULL ); + w_ = w; + widget()->resize( geometry().size()); + } + +QWidget* KDecoration::initialParentWidget() const + { + return bridge_->initialParentWidget(); + } + +Qt::WFlags KDecoration::initialWFlags() const + { + return bridge_->initialWFlags(); + } + +bool KDecoration::isActive() const + { + return bridge_->isActive(); + } + +bool KDecoration::isCloseable() const + { + return bridge_->isCloseable(); + } + +bool KDecoration::isMaximizable() const + { + return bridge_->isMaximizable(); + } + +KDecoration::MaximizeMode KDecoration::maximizeMode() const + { + return bridge_->maximizeMode(); + } + +bool KDecoration::isMinimizable() const + { + return bridge_->isMinimizable(); + } + +bool KDecoration::providesContextHelp() const + { + return bridge_->providesContextHelp(); + } + +int KDecoration::desktop() const + { + return bridge_->desktop(); + } + +bool KDecoration::isModal() const + { + return bridge_->isModal(); + } + +bool KDecoration::isShadeable() const + { + return bridge_->isShadeable(); + } + +bool KDecoration::isShade() const + { + return bridge_->isShade(); + } + +bool KDecoration::keepAbove() const + { + return bridge_->keepAbove(); + } + +bool KDecoration::keepBelow() const + { + return bridge_->keepBelow(); + } + +bool KDecoration::isMovable() const + { + return bridge_->isMovable(); + } + +bool KDecoration::isResizable() const + { + return bridge_->isResizable(); + } + +NET::WindowType KDecoration::windowType( unsigned long supported_types ) const + { + return bridge_->windowType( supported_types ); + } + +QIconSet KDecoration::icon() const + { + return bridge_->icon(); + } + +QString KDecoration::caption() const + { + return bridge_->caption(); + } + +void KDecoration::processMousePressEvent( QMouseEvent* e ) + { + return bridge_->processMousePressEvent( e ); + } + +void KDecoration::showWindowMenu( QPoint pos ) + { + bridge_->showWindowMenu( pos ); + } + +void KDecoration::performWindowOperation( WindowOperation op ) + { + bridge_->performWindowOperation( op ); + } + +void KDecoration::setMask( const QRegion& reg, int mode ) + { + bridge_->setMask( reg, mode ); + } + +void KDecoration::clearMask() + { + bridge_->setMask( QRegion(), 0 ); + } + +bool KDecoration::isPreview() const + { + return bridge_->isPreview(); + } + +QRect KDecoration::geometry() const + { + return bridge_->geometry(); + } + +QRect KDecoration::iconGeometry() const + { + return bridge_->iconGeometry(); + } + +QWidget* KDecoration::workspaceWidget() const + { + return bridge_->workspaceWidget(); + } + +void KDecoration::closeWindow() + { + bridge_->closeWindow(); + } + +void KDecoration::maximize( MaximizeMode mode ) + { + bridge_->maximize( mode ); + } + +void KDecoration::minimize() + { // FRAME tady se da usetrit v bridge_ pouzitim performWindowOperation() + bridge_->minimize(); + } + +void KDecoration::showContextHelp() + { + bridge_->showContextHelp(); + } + +void KDecoration::setDesktop( int desktop ) + { + bridge_->setDesktop( desktop ); + } + +void KDecoration::toggleOnAllDesktops() + { + if( isOnAllDesktops()) + setDesktop( bridge_->currentDesktop()); + else + setDesktop( NET::OnAllDesktops ); + } + +void KDecoration::titlebarDblClickOperation() + { + bridge_->titlebarDblClickOperation(); + } + +void KDecoration::setShade( bool set ) + { + bridge_->setShade( set ); + } + +void KDecoration::setKeepAbove( bool set ) + { + bridge_->setKeepAbove( set ); + } + +void KDecoration::setKeepBelow( bool set ) + { + bridge_->setKeepBelow( set ); + } + +bool KDecoration::drawbound( const QRect&, bool ) + { + return false; + } + +bool KDecoration::animateMinimize( bool ) + { + return false; + } + +void KDecoration::helperShowHide( bool show ) + { + bridge_->helperShowHide( show ); + } + +void KDecoration::reset( unsigned long ) + { + } + +KDecoration::MousePosition KDecoration::mousePosition( const QPoint& p ) const +{ + const int range = 16; + const int border = 4; + + MousePosition m = Nowhere; + + + if ( ( p.x() > border && p.x() < widget()->width() - border ) // FRAME widget()-> ??? + && ( p.y() > border && p.y() < widget()->height() - border ) ) + return Center; + + if ( p.y() <= range && p.x() <= range) + m = TopLeft2; + else if ( p.y() >= widget()->height()-range && p.x() >= widget()->width()-range) + m = BottomRight2; + else if ( p.y() >= widget()->height()-range && p.x() <= range) + m = BottomLeft2; + else if ( p.y() <= range && p.x() >= widget()->width()-range) + m = TopRight2; + else if ( p.y() <= border ) + m = Top; + else if ( p.y() >= widget()->height()-border ) + m = Bottom; + else if ( p.x() <= border ) + m = Left; + else if ( p.x() >= widget()->width()-border ) + m = Right; + else + m = Center; + return m; +} + +KDecorationOptions::KDecorationOptions() + { + assert( KDecoration::options_ == NULL ); + KDecoration::options_ = this; + } + +KDecorationOptions::~KDecorationOptions() + { + assert( KDecoration::options_ == this ); + KDecoration::options_ = NULL; + } + +const QColor& KDecorationOptions::color(ColorType type, bool active) const +{ + return(d->colors[type + (active ? 0 : NUM_COLORS)]); +} + +const QFont& KDecorationOptions::font(bool active, bool small) const +{ + if ( small ) + return(active ? d->activeFontSmall : d->inactiveFontSmall); + else + return(active ? d->activeFont : d->inactiveFont); +} + +const QColorGroup& KDecorationOptions::colorGroup(ColorType type, bool active) const +{ + int idx = type + (active ? 0 : NUM_COLORS); + if(d->cg[idx]) + return(*d->cg[idx]); + d->cg[idx] = new QColorGroup(Qt::black, d->colors[idx], d->colors[idx].light(150), + d->colors[idx].dark(), d->colors[idx].dark(120), + Qt::black, QApplication::palette().active(). + base()); + return(*d->cg[idx]); +} + +bool KDecorationOptions::customButtonPositions() const +{ + return d->custom_button_positions; +} + +QString KDecorationOptions::titleButtonsLeft() const +{ + return d->title_buttons_left; +} + +QString KDecorationOptions::titleButtonsRight() const +{ + return d->title_buttons_right; +} + +bool KDecorationOptions::showTooltips() const +{ + return d->show_tooltips; +} + +KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize() const +{ + return d->border_size; +} + +bool KDecorationOptions::moveResizeMaximizedWindows() const +{ + return d->move_resize_maximized_windows; +} + +#include "kdecoration.moc" diff --git a/lib/kdecoration.h b/lib/kdecoration.h new file mode 100644 index 0000000000..436af0c527 --- /dev/null +++ b/lib/kdecoration.h @@ -0,0 +1,665 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#ifndef KDECORATION_H +#define KDECORATION_H + +#include +#include +#include +#include +#include + +class KDecorationOptionsPrivate; +class KDecorationBridge; +class KDecorationPrivate; +class KDecorationFactory; + +/** + * This class provides a namespace for all decoration related classes. + * All shared types are defined here. + */ +class KDecorationDefines +{ +public: + enum MousePosition { // FRAME nejake lepsi pojmenovani + Nowhere, TopLeft2 , BottomRight2, BottomLeft2, TopRight2, Top, Bottom, Left, Right, Center + }; + /** + * Maximize mode. These values specify how a window is maximized. + */ + // these values are written to session files, don't change the order + enum MaximizeMode { + MaximizeRestore = 0, ///< The window is not maximized in any direction. + MaximizeVertical = 1, ///< The window is maximized vertically. + MaximizeHorizontal = 2, ///< The window is maximized horizontally. + /// Equal to @p MaximizeVertical | @p MaximizeHorizontal + MaximizeFull = MaximizeVertical | MaximizeHorizontal + }; + + enum WindowOperation{ + MaximizeOp = 5000, + RestoreOp, + MinimizeOp, + MoveOp, + UnrestrictedMoveOp, + ResizeOp, + UnrestrictedResizeOp, + CloseOp, + OnAllDesktopsOp, + ShadeOp, + KeepAboveOp, + KeepBelowOp, + OperationsOp, + ToggleStoreSettingsOp, + HMaximizeOp, + VMaximizeOp, + LowerOp, + FullScreenOp, + NoBorderOp, + NoOp + }; + /** + * Basic color types that should be recognized by all decoration styles. + * Decorations are not required to implement all the colors, but for the ones that + * are implemented the color setting for them should be obeyed. + */ + enum ColorType + { + ColorTitleBar, ///< The color for the titlebar + ColorTitleBlend, ///< The blend color for the titlebar + ColorFont, ///< The titlebar text color + ColorButtonBg, ///< The color to use for the titlebar buttons + ColorFrame, ///< The color for the window frame (border) + ColorHandle, ///< The color for the resize handle + NUM_COLORS + }; + + /** + * These flags specify which settings changed when rereading settings. + * Each setting in class KDecorationOptions specifies its matching flag. + */ + enum + { + SettingDecoration = 1 << 0, ///< The decoration was changed + SettingColors = 1 << 1, ///< The color palette was changed + SettingFont = 1 << 2, ///< The titlebar font was changed + SettingButtons = 1 << 3, ///< The button layout was changed + SettingTooltips = 1 << 4, ///< The tooltip setting was changed + SettingBorder = 1 << 5 ///< The border size setting was changed + }; + + /** + * Border size. KDecorationOptions::preferredBorderSize() returns + * one of these values. + */ + enum BorderSize + { + BorderTiny, ///< Minimal borders + BorderNormal, ///< Standard size borders, the default setting + BorderLarge, ///< Larger borders + BorderVeryLarge, ///< Very large borders + BorderHuge ///< Huge borders + }; +}; + +/** + * This class holds various configuration settings for the decoration. + * It is accessible from the decorations either as KDecoration::options() + * or KDecorationFactory::options(). + */ +class KDecorationOptions : public KDecorationDefines + { +public: + KDecorationOptions(); + virtual ~KDecorationOptions(); + /** + * Returns the color that should be used for the given part of the decoration. + * The changed flags for this setting is SettingColors. + * + * @param type The requested color type. + * @param active Whether the color should be for active or inactive windows. + */ + const QColor& color(ColorType type, bool active=true) const; + /** + * Returns a colorgroup using the given decoration color as the background. + * The changed flags for this setting is SettingColors. + * + * @param type The requested color type. + * @param active Whether to return the color for active or inactive windows. + */ + const QColorGroup& colorGroup(ColorType type, bool active=true) const; + /** + * Returns the active or inactive decoration font. + * The changed flags for this setting is SettingFont. + * + * @param active Whether to return the color for active or inactive windows. + * @param small If @a true, returns a font that's suitable for tool windows. + */ + const QFont& font(bool active=true, bool small = false) const; + /** + * @Returns @a true if the style should use custom button positions + * The changed flags for this setting is SettingButtons. + * + * @see titleButtonsLeft + * @see titleButtonsRight + */ + bool customButtonPositions() const; + /** + * If customButtonPositions() returns true, titleButtonsLeft + * returns which buttons should be on the left side of the titlebar from left + * to right. Characters in the returned string have this meaning : + * @li 'M' menu button + * @li 'S' on_all_desktops button + * @li 'H' quickhelp button + * @li 'I' minimize ( iconify ) button + * @li 'A' maximize button + * @li 'X' close button + * @li '_' spacer + * + * The default ( which is also returned if customButtonPositions returns false ) + * is "MS". + * The changed flags for this setting is SettingButtons. + */ + // FRAME vice druhu tlacitek + QString titleButtonsLeft() const; + /** + * If customButtonPositions() returns true, titleButtonsRight + * returns which buttons should be on the right side of the titlebar from left + * to right. Characters in the return string have the same meaning like + * in titleButtonsLeft(). + * + * The default ( which is also returned if customButtonPositions returns false ) + * is "HIAX". + * The changed flags for this setting is SettingButtons. + */ + QString titleButtonsRight() const; + + /** + * @returns true if the style should use tooltips for window buttons + * The changed flags for this setting is SettingTooltips. + */ + bool showTooltips() const; + + /** + * The preferred border size selected by the user, e.g. for accessibility + * reasons, or when using high resolution displays. It's up to the decoration + * to decide which borders or if any borders at all will obey this setting. + * The changed flags for this setting is SettingBorder. + */ + BorderSize preferredBorderSize() const; + + /* + * When this functions returns false, moving and resizing of maximized windows + * is not allowed, and therefore the decoration is allowed to turn off (some of) + * its borders. + * The changed flags for this setting is SettingButtons. + */ + bool moveResizeMaximizedWindows() const; + + /** + * @internal + */ + virtual unsigned long updateSettings() = 0; // returns SettingXYZ mask + +protected: + /** + * @internal + */ + KDecorationOptionsPrivate* d; + }; + + +/** + * This is the base class for a decoration object. It provides functions + * that give various information about the decorated window, and also + * provides pure virtual functions for controlling the decoration that + * every decoration should implement. + */ +class KDecoration + : public QObject, public KDecorationDefines + { + Q_OBJECT + public: + /** + * Constructs a KDecoration object. Both the arguments are passed from + * KDecorationFactory. Note that the initialization code of the decoration + * should be done in the init() method. + */ + KDecoration( KDecorationBridge* bridge, KDecorationFactory* factory ); + /** + * Destroys the KDecoration. + */ + virtual ~KDecoration(); + + // requests from decoration + + /** + * Returns the KDecorationOptions object, which is used to access + * configuration settings for the decoration. + */ + static const KDecorationOptions* options(); + /** + * Returns @a true if the decorated window is currently active. + */ + bool isActive() const; + /** + * Returns @a true if the decoration window can be closed by the user. + */ + bool isCloseable() const; + /** + * Returns @a true if the decorated window can be maximized. + */ + bool isMaximizable() const; + /** + * Returns the current maximization mode of the decorated window. + * Note that only fully maximized windows should be treated + * as "maximized" (e.g. if the maximize button has only two states). + */ + MaximizeMode maximizeMode() const; + /** + * Returns @a true if the decorated window can be minimized by the user. + */ + bool isMinimizable() const; + /** + * Return @a true if the decorated window can show context help + * (i.e. the decoration should provide the context help button). + */ + bool providesContextHelp() const; + /** + * Returns the number of the virtual desktop the decorated window + * is currently on (including NET::OnAllDesktops for being on all + * desktops). + */ + int desktop() const; + /** + * Convenience function that returns @a true if the window is on all + * virtual desktops. + */ + bool isOnAllDesktops() const; // convenience + /** + * Returns @a true if the decoration window is modal (usually a modal dialog). + */ + bool isModal() const; + /** + * Returns @a true if the decorated window can be shaded. + */ + bool isShadeable() const; + /** + * Returns @a true if the decorated window is currently shaded. + */ + bool isShade() const; + /** + * Returns @a true if the decorated window should be kept above other windows. + */ + bool keepAbove() const; + /** + * Returns @a true if the decorated window should be kept below other windows. + */ + bool keepBelow() const; + /** + * Returns @a true if the decorated window can be moved by the user. + */ + bool isMovable() const; + /** + * Returns @a true if the decorated window can be resized by the user. + */ + bool isResizable() const; + /** + * This function returns the window type of the decorated window. + * The argument to this function is a mask of all window types + * the decoration knows about (as the list of valid window types + * is extended over time, and fallback types are specified in order + * to support older code). For a description of all window types, + * see the definition of the NET::WindowType type. Note that + * some window types never have decorated windows. + * + * An example of usage: + * @code + * const unsigned long supported_types = NET::NormalMask | NET::DesktopMask + * | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask + * | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask; + * + * NET::WindowType type = windowType( supported_types ); + * + * if( type == NET::Utility || type == NET::Menu || type == NET::Toolbar ) + * // ... use smaller decorations for tool window types + * else + * // ... use normal decorations + * @endcode + */ + NET::WindowType windowType( unsigned long supported_types ) const; + /** + * Returns an icon set with the decorated window's icon. + */ + QIconSet icon() const; + /** + * Returns the decorated window's caption that should be shown in the titlebar. + */ + QString caption() const; + /** + * This function invokes the window operations menu. + */ + void showWindowMenu( QPoint pos ); + void performWindowOperation( WindowOperation op ); + /** + * If the decoration is non-rectangular, this function needs to be called + * to set the shape of the decoration. + * + * @param reg The shape of the decoration. + * @param mode The X11 values Unsorted, YSorted, YXSorted and YXBanded that specify + * the sorting of the rectangles, default value is Unsorted. + */ + void setMask( const QRegion& reg, int mode = 0 ); + /** + * This convenience function resets the shape mask. + */ + void clearMask(); // convenience + /** + * If this function returns @a true, the decorated window is used as a preview + * e.g. in the configuration module. In such case, the decoration can e.g. + * show some information in the window area. + */ + bool isPreview() const; + /** + * Returns the geometry of the decoration. + */ + QRect geometry() const; + /** + * Returns the icon geometry for the window, i.e. the geometry of the taskbar + * entry. This is used mainly for window minimize animations. Note that + * the geometry may be null. + */ + QRect iconGeometry() const; + /** + * Returns the main workspace widget. The main purpose of this function is to + * allow painting the minimize animation or the transparent move bound on it. + */ + QWidget* workspaceWidget() const; + /** + * Convenience function that returns the width of the decoration. + */ + int width() const; // convenience + /** + * Convenience function that returns the height of the decoration. + */ + int height() const; // convenience + /** + * This function is the default handler for mouse events. All mouse events + * that are not handled by the decoration itself should be passed to it + * in order to make work operations like window resizing by dragging borders etc. + */ + void processMousePressEvent( QMouseEvent* e ); + + // requests to decoration + + /** + * This function is called immediately after the decoration object is created. + * Due to some technical reasons, initialization should be done here + * instead of in the constructor. + */ + virtual void init() = 0; // called once right after created + + virtual MousePosition mousePosition( const QPoint& p ) const = 0; + /** + * This function should return the distance from each window side to the inner + * window. The sizes may depend on the state of the decorated window, such as + * whether it's shaded. Decorations often turn off their bottom border when the + * window is shaded, and turn off their left/right/bottom borders when + * the window is maximized and moving and resizing of maximized windows is disabled. + * This function mustn't do any repaints or resizes. Also, if the sizes returned + * by this function don't match the real values, this may result in drawing errors + * or other problems. + * + * @see KDecorationOptions::moveResizeMaximizedWindows() + */ + // mustn't do any repaints, resizes or anything like that + virtual void borders( int& left, int& right, int& top, int& bottom ) const = 0; + /** + * This method is called by kwin when the style should resize the decoration window. + * The usual implementation is to resize the main widget of the decoration to the + * given size. + * + * @param s Specifies the new size of the decoration window. + */ + virtual void resize( const QSize& s ) = 0; + /** + * This function should return the minimum required size for the decoration. + * Note that the returned size shouldn't be too large, because it will be + * used to keep the decorated window at least as large. + */ + virtual QSize minimumSize() const = 0; + /** + * This function is called whenever the window either becomes or stops being active. + * Use isActive() to find out the current state. + */ + virtual void activeChange() = 0; + /** + * This function is called whenever the caption changes. Use caption() to get it. + */ + virtual void captionChange() = 0; + /** + * This function is called whenever the window icon changes. Use icon() to get it. + */ + virtual void iconChange() = 0; + /** + * This function is called whenever the maximalization state of the window changes. + * Use maximizeMode() to get the current state. + */ + virtual void maximizeChange() = 0; + /** + * This function is called whenever the desktop for the window changes. Use + * desktop() or isOnAllDesktops() to find out the current desktop + * on which the window is. + */ + virtual void desktopChange() = 0; + /** + * This function is called whenever the window is shaded or unshaded. Use + * isShade() to get the current state. + */ + virtual void shadeChange() = 0; + /** + * This function may be reimplemented to provide custom bound drawing + * for transparent moving or resizing of the window. + * @a False should be returned if the default implementation should be used. + * + * @param geom The geometry at this the bound should be drawn + * @param clear @a true if the bound should be cleared + * + * @see workspaceWidget() and geometry(). + */ + virtual bool drawbound( const QRect& geom, bool clear ); + /** + * This function may be reimplemented to provide custom minimize/restore animations + * The reimplementation is allowed to perform X server grabs if necessary, but no + * futher event processing is allowed (i.e. no kapp->processEvents()). + * @a False should be returned if the default implementation should be used. + * Note that you should not use this function to force disabling of the animation. + * + * @see workspaceWidget(), geometry() and helperShowHide(). + */ + virtual bool animateMinimize( bool minimize ); + /** + * This function is called to reset the decoration on settings changes. + * It is usually invoked by calling KDecorationFactory::resetDecorations(). + * + * @param changed Specifies which settings were changed, given by the SettingXXX masks + */ + virtual void reset( unsigned long changed ); + + // special + + /** + * This should be the first function called in init() to specify + * the main widget of the decoration. The widget should be created + * with parent specified by initialParentWidget() and flags + * specified by initialWFlags(). + */ + void setMainWidget( QWidget* ); + /** + * Convenience functions that creates and sets a main widget as necessary. + * In such case, it's usually needed to install an event filter + * on the main widget to receive important events on it. + * + * @param flags Additional widget flags for the main widget. Note that only + * flags that affect widget drawing are allowed. Window type flags + * like WX11BypassWM or WStyle_NoBorder are forbidden. + */ + void createMainWidget( WFlags flags = 0 ); + /** + * The parent widget that should be used for the main widget. + */ + QWidget* initialParentWidget() const; + /** + * The flags that should be used when creating the main widget. + * It is possible to add more flags when creating the main widget, but only flags + * that affect widget drawing are allowed. Window type flags like WX11BypassWM + * or WStyle_NoBorder are forbidden. + */ + WFlags initialWFlags() const; + /** + * This function is only allowed to be called once from animateMinimize(). + * It can be used if the window should be shown or hidden at a specific + * time during the animation. It is forbidden to use this function + * for other purposes. + */ + void helperShowHide( bool show ); + /** + * Returns the main widget for the decoration. + */ + QWidget* widget(); + /** + * Returns the main widget for the decoration. + */ + const QWidget* widget() const; + /** + * Returns the factory that created this decoration. + */ + KDecorationFactory* factory() const; + public slots: + // requests from decoration + + /** + * This function can be called by the decoration to request + * closing of the decorated window. Note that closing the window + * also involves destroying the decoration. + */ + void closeWindow(); + /** + * Set the maximize mode of the decorated window. + * @param mode The maximization mode to be set. + */ + void maximize( MaximizeMode mode ); + /** + * Minimize the decorated window. + */ + void minimize(); + /** + * Start showing context help in the window (i.e. the mouse will enter + * the what's this mode). + */ + void showContextHelp(); + void setDesktop( int desktop ); + /** + * This function toggles the on-all-desktops state of the decorated window. + */ + void toggleOnAllDesktops(); // convenience + /** + * This function performs the operation configured as titlebar double click + * operation. + */ + void titlebarDblClickOperation(); + /** + * Shades or unshades the decorated window. + * @param set Whether the window should be shaded + */ + void setShade( bool set ); + /** + * Sets or reset keeping this window above others. + * @param set Whether to keep the window above others + */ + void setKeepAbove( bool set ); + /** + * Sets or reset keeping this window below others. + * @param set Whether to keep the window below others + */ + void setKeepBelow( bool set ); + private: + KDecorationBridge* bridge_; + QWidget* w_; + KDecorationFactory* factory_; + friend class KDecorationOptions; // for options_ + static KDecorationOptions* options_; + KDecorationPrivate* d; + }; + +inline +KDecorationDefines::MaximizeMode operator^( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 ) + { + return KDecorationDefines::MaximizeMode( int(m1) ^ int(m2) ); + } + +inline +KDecorationDefines::MaximizeMode operator&( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 ) + { + return KDecorationDefines::MaximizeMode( int(m1) & int(m2) ); + } + +inline +KDecorationDefines::MaximizeMode operator|( KDecorationDefines::MaximizeMode m1, KDecorationDefines::MaximizeMode m2 ) + { + return KDecorationDefines::MaximizeMode( int(m1) | int(m2) ); + } + +inline QWidget* KDecoration::widget() + { + return w_; + } + +inline const QWidget* KDecoration::widget() const + { + return w_; + } + +inline KDecorationFactory* KDecoration::factory() const + { + return factory_; + } + +inline bool KDecoration::isOnAllDesktops() const + { + return desktop() == NET::OnAllDesktops; + } + +inline int KDecoration::width() const + { + return geometry().width(); + } + +inline int KDecoration::height() const + { + return geometry().height(); + } + +#endif diff --git a/lib/kdecoration_p.cpp b/lib/kdecoration_p.cpp new file mode 100644 index 0000000000..6a6de19462 --- /dev/null +++ b/lib/kdecoration_p.cpp @@ -0,0 +1,213 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#include "kdecoration_p.h" + +#include +#include +#include + +KDecorationOptionsPrivate::KDecorationOptionsPrivate() +{ + for(int i=0; i < NUM_COLORS*2; ++i) + cg[i] = NULL; +} + +KDecorationOptionsPrivate::~KDecorationOptionsPrivate() +{ + int i; + for(i=0; i < NUM_COLORS*2; ++i){ + if(cg[i]){ + delete cg[i]; + cg[i] = NULL; + } + } +} + +void KDecorationOptionsPrivate::defaultKWinSettings() + { + title_buttons_left = "MS"; + title_buttons_right = "HIAX"; + custom_button_positions = false; + show_tooltips = true; + border_size = BorderNormal; + move_resize_maximized_windows = true; + } + +unsigned long KDecorationOptionsPrivate::updateKWinSettings( KConfig* config ) +{ + unsigned long changed = 0; + QString old_group = config->group(); + config->setGroup( "WM" ); + +// SettingColors + QColor old_colors[NUM_COLORS*2]; + for( int i = 0; + i < NUM_COLORS*2; + ++i ) + old_colors[ i ] = colors[ i ]; + + QPalette pal = QApplication::palette(); + // normal colors + colors[ColorFrame] = pal.active().background(); + colors[ColorFrame] = config->readColorEntry("frame", &colors[ColorFrame]); + colors[ColorHandle] = colors[ColorFrame]; + colors[ColorHandle] = config->readColorEntry("handle", &colors[ColorHandle]); + + // full button configuration (background, blend, and foreground + if(QPixmap::defaultDepth() > 8) + colors[ColorButtonBg] = colors[ColorFrame].light(130); + else + colors[ColorButtonBg] = colors[ColorFrame]; + colors[ColorButtonBg] = config->readColorEntry("activeTitleBtnBg", + &colors[ColorFrame]); + colors[ColorTitleBar] = pal.active().highlight(); + colors[ColorTitleBar] = config->readColorEntry("activeBackground", + &colors[ColorTitleBar]); + if(QPixmap::defaultDepth() > 8) + colors[ColorTitleBlend] = colors[ ColorTitleBar ].dark(110); + else + colors[ColorTitleBlend] = colors[ ColorTitleBar ]; + colors[ColorTitleBlend] = config->readColorEntry("activeBlend", + &colors[ColorTitleBlend]); + + colors[ColorFont] = pal.active().highlightedText(); + colors[ColorFont] = config->readColorEntry("activeForeground", &colors[ColorFont]); + + // inactive + colors[ColorFrame+NUM_COLORS] = config->readColorEntry("inactiveFrame", + &colors[ColorFrame]); + colors[ColorTitleBar+NUM_COLORS] = colors[ColorFrame]; + colors[ColorTitleBar+NUM_COLORS] = config-> + readColorEntry("inactiveBackground", &colors[ColorTitleBar+NUM_COLORS]); + + if(QPixmap::defaultDepth() > 8) + colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ].dark(110); + else + colors[ColorTitleBlend+NUM_COLORS] = colors[ ColorTitleBar+NUM_COLORS ]; + colors[ColorTitleBlend+NUM_COLORS] = + config->readColorEntry("inactiveBlend", &colors[ColorTitleBlend+NUM_COLORS]); + + // full button configuration + if(QPixmap::defaultDepth() > 8) + colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS].light(130); + else + colors[ColorButtonBg+NUM_COLORS] = colors[ColorFrame+NUM_COLORS]; + colors[ColorButtonBg+NUM_COLORS] = + config->readColorEntry("inactiveTitleBtnBg", + &colors[ColorButtonBg]); + + colors[ColorHandle+NUM_COLORS] = colors[ColorFrame]; + config->readColorEntry("inactiveHandle", &colors[ColorHandle]); + + colors[ColorFont+NUM_COLORS] = colors[ColorFrame].dark(); + colors[ColorFont+NUM_COLORS] = config->readColorEntry("inactiveForeground", + &colors[ColorFont+NUM_COLORS]); + + for( int i = 0; + i < NUM_COLORS*2; + ++i ) + if( old_colors[ i ] != colors[ i ] ) + changed |= SettingColors; + +// SettingFont + QFont old_activeFont = activeFont; + QFont old_inactiveFont = inactiveFont; + QFont old_activeFontSmall = activeFontSmall; + QFont old_inactiveFontSmall = inactiveFontSmall; + + // Keep in sync with kglobalsettings. + QFont activeFontGuess("helvetica", 12, QFont::Bold); + activeFontGuess.setPixelSize(12); + + activeFont = config->readFontEntry("activeFont", &activeFontGuess); + inactiveFont = config->readFontEntry("inactiveFont", &activeFont); + + activeFontSmall = activeFont; + activeFontSmall.setPointSize(activeFont.pointSize() - 2); + activeFontSmall = config->readFontEntry("activeFontSmall", &activeFontSmall); + inactiveFontSmall = config->readFontEntry("inactiveFontSmall", &activeFontSmall); + + if( old_activeFont != activeFont + || old_inactiveFont != inactiveFont + || old_activeFontSmall != activeFontSmall + || old_inactiveFontSmall != inactiveFontSmall ) + changed |= SettingFont; + + config->setGroup( "Style" ); +// SettingsButtons + QString old_title_buttons_left = title_buttons_left; + QString old_title_buttons_right = title_buttons_right; + bool old_custom_button_positions = custom_button_positions; + custom_button_positions = config->readBoolEntry("CustomButtonPositions", false); + if (custom_button_positions) { + title_buttons_left = config->readEntry("ButtonsOnLeft", "MS"); + title_buttons_right = config->readEntry("ButtonsOnRight", "HIAX"); + } + else { + title_buttons_left = "MS"; + title_buttons_right = "HIAX"; + } + if( old_custom_button_positions != custom_button_positions + || ( custom_button_positions && + ( old_title_buttons_left != title_buttons_left + || old_title_buttons_right != title_buttons_right ))) + changed |= SettingButtons; + +// SettingTooltips + bool old_show_tooltips = show_tooltips; + show_tooltips = config->readBoolEntry("ShowToolTips", true); + if( old_show_tooltips != show_tooltips ) + changed |= SettingTooltips; + +// SettingBorder + + BorderSize old_border_size = border_size; + int border_size_num = config->readNumEntry( "BorderSize", BorderNormal ); + if( border_size_num >= BorderTiny && border_size_num <= BorderHuge ) + border_size = static_cast< BorderSize >( border_size_num ); + else + border_size = BorderNormal; + if( old_border_size != border_size ) + changed |= SettingBorder; + + config->setGroup( "Windows" ); + bool old_move_resize_maximized_windows = move_resize_maximized_windows; + move_resize_maximized_windows = config->readBoolEntry( "MoveResizeMaximizedWindows", true ); + if( old_move_resize_maximized_windows != move_resize_maximized_windows ) + changed |= SettingBorder; + +// destroy cached values + int i; + for(i=0; i < NUM_COLORS*2; ++i){ + if(cg[i]){ + delete cg[i]; + cg[i] = NULL; + } + } + + config->setGroup( old_group ); + + return changed; +} diff --git a/lib/kdecoration_p.h b/lib/kdecoration_p.h new file mode 100644 index 0000000000..80bbd2e251 --- /dev/null +++ b/lib/kdecoration_p.h @@ -0,0 +1,101 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#ifndef KDECORATION_P_H +#define KDECORATION_P_H + +// +// This header file is internal. I mean it. +// + +#include "kdecoration.h" +#include + +class KConfig; + +class KDecorationOptionsPrivate : public KDecorationDefines + { + public: + KDecorationOptionsPrivate(); + virtual ~KDecorationOptionsPrivate(); + void defaultKWinSettings(); // shared implementation + unsigned long updateKWinSettings( KConfig* ); // shared implementation + + QColor colors[NUM_COLORS*2]; + QColorGroup *cg[NUM_COLORS*2]; + QFont activeFont, inactiveFont, activeFontSmall, inactiveFontSmall; + QString title_buttons_left; + QString title_buttons_right; + bool custom_button_positions; + bool show_tooltips; + BorderSize border_size; + bool move_resize_maximized_windows; + }; + +// FRAME internal +class KDecorationBridge : public KDecorationDefines + { + public: + virtual bool isActive() const = 0; + virtual bool isCloseable() const = 0; + virtual bool isMaximizable() const = 0; + virtual MaximizeMode maximizeMode() const = 0; + virtual bool isMinimizable() const = 0; + virtual bool providesContextHelp() const = 0; + virtual int desktop() const = 0; + virtual bool isModal() const = 0; + virtual bool isShadeable() const = 0; + virtual bool isShade() const = 0; + virtual bool keepAbove() const = 0; + virtual bool keepBelow() const = 0; + virtual bool isMovable() const = 0; + virtual bool isResizable() const = 0; + virtual NET::WindowType windowType( unsigned long supported_types ) const = 0; + virtual QIconSet icon() const = 0; + virtual QString caption() const = 0; + virtual void processMousePressEvent( QMouseEvent* ) = 0; + virtual void showWindowMenu( QPoint ) = 0; + virtual void performWindowOperation( WindowOperation ) = 0; + virtual void setMask( const QRegion&, int ) = 0; + virtual bool isPreview() const = 0; + virtual QRect geometry() const = 0; + virtual QRect iconGeometry() const = 0; + virtual QWidget* workspaceWidget() const = 0; + virtual void closeWindow() = 0; + virtual void maximize( MaximizeMode mode ) = 0; + virtual void minimize() = 0; + virtual void showContextHelp() = 0; + virtual void setDesktop( int desktop ) = 0; + virtual void titlebarDblClickOperation() = 0; + virtual void setShade( bool set ) = 0; + virtual void setKeepAbove( bool ) = 0; + virtual void setKeepBelow( bool ) = 0; + // not part of public API + virtual int currentDesktop() const = 0; + virtual QWidget* initialParentWidget() const = 0; + virtual Qt::WFlags initialWFlags() const = 0; + virtual void helperShowHide( bool ) = 0; + }; + +#endif diff --git a/lib/kdecoration_plugins_p.cpp b/lib/kdecoration_plugins_p.cpp new file mode 100644 index 0000000000..3f9341269e --- /dev/null +++ b/lib/kdecoration_plugins_p.cpp @@ -0,0 +1,187 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 1999, 2000 Daniel M. Duley +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#include "kdecoration_plugins_p.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include "kdecorationfactory.h" + +KDecorationPlugins::KDecorationPlugins( KConfig* cfg ) + : create_ptr( NULL ), + library( NULL ), + fact( NULL ), + old_library( NULL ), + old_fact( NULL ), + pluginStr( "kwin3_undefined " ), + config( cfg ) + { + } + +KDecorationPlugins::~KDecorationPlugins() + { + if(library) + { + assert( fact != NULL ); + delete fact; + library->unload(); + } + if(old_library) + { + assert( old_fact != NULL ); + delete old_fact; + old_library->unload(); + } + } + +bool KDecorationPlugins::reset( unsigned long changed ) + { + QString oldPlugin = pluginStr; + config->reparseConfiguration(); + bool ret = false; + if(( !loadPlugin( "" ) && library ) // "" = read the one in cfg file + || oldPlugin == pluginStr ) + { // no new plugin loaded, reset the old one + assert( fact != NULL ); + ret = fact->reset( changed ); + } + return ret || oldPlugin != pluginStr; + } + +KDecorationFactory* KDecorationPlugins::factory() + { + return fact; + } + +// convenience +KDecoration* KDecorationPlugins::createDecoration( KDecorationBridge* bridge ) + { + if( fact != NULL ) + return fact->createDecoration( bridge ); + return NULL; + } + +// returns true if plugin was loaded successfully +bool KDecorationPlugins::loadPlugin( QString nameStr ) + { + if( nameStr.isEmpty()) + { + KConfigGroupSaver saver( config, "Style" ); + nameStr = config->readEntry("PluginLib", defaultPlugin ); + } + // make sure people can switch between HEAD and kwin_iii branch + if( nameStr.startsWith( "kwin_" )) + nameStr = "kwin3_" + nameStr.mid( 5 ); + + KLibrary *oldLibrary = library; + KDecorationFactory* oldFactory = fact; + + QString path = KLibLoader::findLibrary(QFile::encodeName(nameStr)); + + // If the plugin was not found, try to find the default + if (path.isEmpty()) + { + nameStr = defaultPlugin; + path = KLibLoader::findLibrary(QFile::encodeName(nameStr)); + } + + // If no library was found, exit kwin with an error message + if (path.isEmpty()) + { + error( i18n("No window decoration plugin library was found!" )); + return false; + } + + // Check if this library is not already loaded. + if(pluginStr == nameStr) + return true; + + // Try loading the requested plugin + library = KLibLoader::self()->library(QFile::encodeName(path)); + + // If that fails, fall back to the default plugin + if (!library) + { + kdDebug() << " could not load library, try default plugin again" << endl; + nameStr = defaultPlugin; + if ( pluginStr == nameStr ) + return true; + path = KLibLoader::findLibrary(QFile::encodeName(nameStr)); + if (!path.isEmpty()) + library = KLibLoader::self()->library(QFile::encodeName(path)); + } + + if (!library) + { + error( i18n("The default decoration plugin is corrupt " + "and could not be loaded!" )); + return false; + } + + create_ptr = NULL; + if( library->hasSymbol("create_factory")) + { + void* create_func = library->symbol("create_factory"); + if(create_func) + create_ptr = (KDecorationFactory* (*)())create_func; + } + if(!create_ptr) + { + error( i18n( "The library %1 is not a KWin plugin." ).arg( path )); + library->unload(); + return false; + } + fact = create_ptr(); + + pluginStr = nameStr; + + old_library = oldLibrary; // save for delayed destroying + old_fact = oldFactory; + + return true; +} + +void KDecorationPlugins::destroyPreviousPlugin() +{ + // Destroy the old plugin + if(old_library) + { + delete old_fact; + old_fact = NULL; + old_library->unload(); + old_library = NULL; + } +} + +void KDecorationPlugins::error( const QString& ) + { + } diff --git a/lib/kdecoration_plugins_p.h b/lib/kdecoration_plugins_p.h new file mode 100644 index 0000000000..e283071aa0 --- /dev/null +++ b/lib/kdecoration_plugins_p.h @@ -0,0 +1,74 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 1999, 2000 Daniel M. Duley +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#ifndef KDECORATION_PLUGINS_H +#define KDECORATION_PLUGINS_H + +// +// This header file is internal. I mean it. +// + +#include +#include +#include + +class KLibrary; +class KDecoration; +class KDecorationBridge; +class KDecorationFactory; +class KConfig; + +class KDecorationPlugins + { + public: + KDecorationPlugins( KConfig* cfg ); + virtual ~KDecorationPlugins(); + bool loadPlugin( QString name ); + void destroyPreviousPlugin(); + KDecorationFactory* factory(); + KDecoration* createDecoration( KDecorationBridge* ); + QString currentPlugin() { return pluginStr; } + bool reset( unsigned long changed ); // returns true if decorations need to be recreated + protected: + virtual void error( const QString& error_msg ); + QCString defaultPlugin; // FRAME normalne protected? + private: + KDecorationFactory* (*create_ptr)(); + KLibrary *library; + KDecorationFactory* fact; + KLibrary *old_library; + KDecorationFactory* old_fact; + QString pluginStr; + KConfig* config; + }; + +/* + + Plugins API: + KDecorationFactory* create_factory(); - called once after loading + +*/ + +#endif diff --git a/lib/kdecorationfactory.cpp b/lib/kdecorationfactory.cpp new file mode 100644 index 0000000000..1f9eaae59d --- /dev/null +++ b/lib/kdecorationfactory.cpp @@ -0,0 +1,64 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#include "kdecorationfactory.h" + +#include + +KDecorationFactory::KDecorationFactory() + { + } + +KDecorationFactory::~KDecorationFactory() + { + assert( _decorations.count() == 0 ); + } + +bool KDecorationFactory::reset( unsigned long ) + { + return false; + } + +bool KDecorationFactory::supports( Ability ) + { + return false; + } + +void KDecorationFactory::addDecoration( KDecoration* deco ) + { + _decorations.append( deco ); + } + +void KDecorationFactory::removeDecoration( KDecoration* deco ) + { + _decorations.remove( deco ); + } + +void KDecorationFactory::resetDecorations( unsigned long changed ) + { + for( QValueList< KDecoration* >::ConstIterator it = _decorations.begin(); + it != _decorations.end(); + ++it ) + (*it)->reset( changed ); + } diff --git a/lib/kdecorationfactory.h b/lib/kdecorationfactory.h new file mode 100644 index 0000000000..15af01784d --- /dev/null +++ b/lib/kdecorationfactory.h @@ -0,0 +1,95 @@ +/***************************************************************** +This file is part of the KDE project. + +Copyright (C) 2003 Lubos Lunak + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +******************************************************************/ + +#ifndef KDECORATIONFACTORY_H +#define KDECORATIONFACTORY_H + +#include + +class KDecoration; +class KDecorationBridge; +class KDecorationFactoryPrivate; + +class KDecorationFactory + : public KDecorationDefines + { + public: + enum Ability { NOTHING_YET }; // FRAME pridat, + pamatovat na 32bitu? + /** + * Constructor. Called after loading the decoration plugin. All global + * initialization of the plugin should be done in the factory constructor. + */ + KDecorationFactory(); + /** + * Destructor. Called before unloading the decoration plugin. All global + * cleanup of the plugin should be done in the factory destructor. + */ + virtual ~KDecorationFactory(); + /** + * This function must be reimplemented to create decoration objects. + * The argument should be passed to the KDecoration constructor, the second + * KDecoration argument should be this factory object. + */ + virtual KDecoration* createDecoration( KDecorationBridge* bridge ) = 0; + /** + * This function is called when the configuration settings changed. + * The argument specifies what has changed, using the SettingXXX masks. + * It should be determined whether the decorations need to be completely + * remade, in which case true should be returned, or whether only e.g. + * a repaint will be sufficient, in which case false should be returned, + * and resetDecorations() can be called to reset all decoration objects. + * Note that true should be returned only when really necessary. + */ + virtual bool reset( unsigned long changed ); // returns true if the decoration needs to be recreated + virtual bool supports( Ability ability ); + /** + * Returns the KDecorationOptions object, which is used to access + * configuration settings for the decoration. + */ + const KDecorationOptions* options(); // convenience + /** + * @internal + */ + void addDecoration( KDecoration* ); + /** + * @internal + */ + void removeDecoration( KDecoration* ); + protected: + /** + * Convenience function that calls KDecoration::reset() for all decoration + * objects. + */ + void resetDecorations( unsigned long changed ); // convenience + private: + QValueList< KDecoration* > _decorations; + KDecorationFactoryPrivate* d; + }; + +inline const KDecorationOptions* KDecorationFactory::options() + { + return KDecoration::options(); + } + +#endif