kwin/lib Library API Documentation

kdecoration.cpp

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 #include "kdecoration.h"
00026 
00027 #include <kdebug.h>
00028 #include <qapplication.h>
00029 #include <kglobal.h>
00030 #include <assert.h>
00031 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00032 #include <X11/Xlib.h>
00033 #include <fixx11h.h>
00034 #endif
00035 
00036 #include "kdecoration_p.h"
00037 #include "kdecorationfactory.h"
00038 
00039 KDecorationOptions* KDecoration::options_;
00040 
00041 KDecoration::KDecoration( KDecorationBridge* bridge, KDecorationFactory* factory )
00042     :   bridge_( bridge ),
00043     w_( NULL ),
00044         factory_( factory )
00045     {
00046     factory->addDecoration( this );
00047     }
00048 
00049 KDecoration::~KDecoration()
00050     {
00051     factory()->removeDecoration( this );
00052     delete w_;
00053     }
00054 
00055 const KDecorationOptions* KDecoration::options()
00056     {
00057     return options_;
00058     }
00059 
00060 void KDecoration::createMainWidget( WFlags flags )
00061     {
00062     // FRAME check flags?
00063     setMainWidget( new QWidget( initialParentWidget(), "decoration widget", initialWFlags() | flags ));
00064     }
00065 
00066 void KDecoration::setMainWidget( QWidget* w )
00067     {
00068     assert( w_ == NULL );
00069     w_ = w;
00070     w->setMouseTracking( true );
00071     widget()->resize( geometry().size());
00072     }
00073 
00074 QWidget* KDecoration::initialParentWidget() const
00075     {
00076     return bridge_->initialParentWidget();
00077     }
00078     
00079 Qt::WFlags KDecoration::initialWFlags() const
00080     {
00081     return bridge_->initialWFlags();
00082     }
00083 
00084 bool KDecoration::isActive() const
00085     {
00086     return bridge_->isActive();
00087     }
00088     
00089 bool KDecoration::isCloseable() const
00090     {
00091     return bridge_->isCloseable();
00092     }
00093 
00094 bool KDecoration::isMaximizable() const
00095     {
00096     return bridge_->isMaximizable();
00097     }
00098     
00099 KDecoration::MaximizeMode KDecoration::maximizeMode() const
00100     {
00101     return bridge_->maximizeMode();
00102     }
00103     
00104 bool KDecoration::isMinimizable() const
00105     {
00106     return bridge_->isMinimizable();
00107     }
00108 
00109 bool KDecoration::providesContextHelp() const
00110     {
00111     return bridge_->providesContextHelp();
00112     }
00113     
00114 int KDecoration::desktop() const
00115     {
00116     return bridge_->desktop();
00117     }
00118     
00119 bool KDecoration::isModal() const
00120     {
00121     return bridge_->isModal();
00122     }
00123     
00124 bool KDecoration::isShadeable() const
00125     {
00126     return bridge_->isShadeable();
00127     }
00128     
00129 bool KDecoration::isShade() const
00130     {
00131     return bridge_->isShade();
00132     }
00133     
00134 bool KDecoration::isSetShade() const
00135     {
00136     return bridge_->isSetShade();
00137     }
00138     
00139 bool KDecoration::keepAbove() const
00140     {
00141     return bridge_->keepAbove();
00142     }
00143 
00144 bool KDecoration::keepBelow() const
00145     {
00146     return bridge_->keepBelow();
00147     }
00148 
00149 bool KDecoration::isMovable() const
00150     {
00151     return bridge_->isMovable();
00152     }
00153 
00154 bool KDecoration::isResizable() const
00155     {
00156     return bridge_->isResizable();
00157     }
00158 
00159 NET::WindowType KDecoration::windowType( unsigned long supported_types ) const
00160     { // this one is also duplicated in KDecorationFactory
00161     return bridge_->windowType( supported_types );
00162     }
00163 
00164 QIconSet KDecoration::icon() const
00165     {
00166     return bridge_->icon();
00167     }
00168     
00169 QString KDecoration::caption() const
00170     {
00171     return bridge_->caption();
00172     }
00173 
00174 void KDecoration::processMousePressEvent( QMouseEvent* e )
00175     {
00176     return bridge_->processMousePressEvent( e );
00177     }
00178 
00179 void KDecoration::showWindowMenu( const QRect &pos )
00180     {
00181     bridge_->showWindowMenu( pos );
00182     }
00183     
00184 void KDecoration::showWindowMenu( QPoint pos )
00185     {
00186     bridge_->showWindowMenu( pos );
00187     }
00188 
00189 void KDecoration::performWindowOperation( WindowOperation op )
00190     {
00191     bridge_->performWindowOperation( op );
00192     }
00193 
00194 void KDecoration::setMask( const QRegion& reg, int mode )
00195     {
00196     bridge_->setMask( reg, mode );
00197     }
00198     
00199 void KDecoration::clearMask()
00200     {
00201     bridge_->setMask( QRegion(), 0 );
00202     }
00203     
00204 bool KDecoration::isPreview() const
00205     {
00206     return bridge_->isPreview();
00207     }
00208     
00209 QRect KDecoration::geometry() const
00210     {
00211     return bridge_->geometry();
00212     }
00213     
00214 QRect KDecoration::iconGeometry() const
00215     {
00216     return bridge_->iconGeometry();
00217     }
00218 
00219 QRegion KDecoration::unobscuredRegion( const QRegion& r ) const
00220     {
00221     return bridge_->unobscuredRegion( r );
00222     }
00223 
00224 QWidget* KDecoration::workspaceWidget() const
00225     {
00226     return bridge_->workspaceWidget();
00227     }
00228         
00229 void KDecoration::closeWindow()
00230     {
00231     bridge_->closeWindow();
00232     }
00233 
00234 void KDecoration::maximize( ButtonState button )
00235     {
00236     // This can be made configurable if needed.
00237     if( button == MidButton )
00238         maximize( maximizeMode() ^ MaximizeVertical );
00239     else if ( button == RightButton )
00240         maximize( maximizeMode() ^ MaximizeHorizontal );
00241     else
00242         maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull );
00243     }
00244 
00245 void KDecoration::maximize( MaximizeMode mode )
00246     {
00247     bridge_->maximize( mode );
00248     }
00249     
00250 void KDecoration::minimize()
00251     {
00252     bridge_->minimize();
00253     }
00254 
00255 void KDecoration::showContextHelp()
00256     {
00257     bridge_->showContextHelp();
00258     }
00259     
00260 void KDecoration::setDesktop( int desktop )
00261     {
00262     bridge_->setDesktop( desktop );
00263     }
00264 
00265 void KDecoration::toggleOnAllDesktops()
00266     {
00267     if( isOnAllDesktops())
00268         setDesktop( bridge_->currentDesktop());
00269     else
00270         setDesktop( NET::OnAllDesktops );
00271     }
00272 
00273 void KDecoration::titlebarDblClickOperation()
00274     {
00275     bridge_->titlebarDblClickOperation();
00276     }
00277 
00278 void KDecoration::setShade( bool set )
00279     {
00280     bridge_->setShade( set );
00281     }
00282         
00283 void KDecoration::setKeepAbove( bool set )
00284     {
00285     bridge_->setKeepAbove( set );
00286     }
00287     
00288 void KDecoration::setKeepBelow( bool set )
00289     {
00290     bridge_->setKeepBelow( set );
00291     }
00292 
00293 bool KDecoration::drawbound( const QRect&, bool )
00294     {
00295     return false;
00296     }
00297 
00298 bool KDecoration::animateMinimize( bool )
00299     {
00300     return false;
00301     }
00302 
00303 bool KDecoration::windowDocked( Position )
00304     {
00305     return false;
00306     }
00307 
00308 void KDecoration::helperShowHide( bool show )
00309     {
00310     bridge_->helperShowHide( show );
00311     }
00312 
00313 void KDecoration::reset( unsigned long )
00314     {
00315     }
00316 
00317 void KDecoration::grabXServer()
00318     {
00319     bridge_->grabXServer( true );
00320     }
00321     
00322 void KDecoration::ungrabXServer()
00323     {
00324     bridge_->grabXServer( false );
00325     }
00326     
00327 KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
00328 {
00329     const int range = 16;
00330     int bleft, bright, btop, bbottom;
00331     borders( bleft, bright, btop, bbottom );
00332     btop = KMIN( btop, 4 ); // otherwise whole titlebar would have resize cursor
00333 
00334     Position m = PositionCenter;
00335 
00336     if ( ( p.x() > bleft && p.x() < widget()->width() - bright )
00337          && ( p.y() > btop && p.y() < widget()->height() - bbottom ) )
00338         return PositionCenter;
00339 
00340     if ( p.y() <= KMAX( range, btop ) && p.x() <= KMAX( range, bleft ))
00341         m = PositionTopLeft;
00342     else if ( p.y() >= widget()->height()- KMAX( range, bbottom )
00343         && p.x() >= widget()->width()- KMAX( range, bright ))
00344         m = PositionBottomRight;
00345     else if ( p.y() >= widget()->height()- KMAX( range, bbottom ) && p.x() <= KMAX( range, bleft ))
00346         m = PositionBottomLeft;
00347     else if ( p.y() <= KMAX( range, btop ) && p.x() >= widget()->width()- KMAX( range, bright ))
00348         m = PositionTopRight;
00349     else if ( p.y() <= btop )
00350         m = PositionTop;
00351     else if ( p.y() >= widget()->height()-bbottom )
00352         m = PositionBottom;
00353     else if ( p.x() <= bleft )
00354         m = PositionLeft;
00355     else if ( p.x() >= widget()->width()-bright )
00356         m = PositionRight;
00357     else
00358         m = PositionCenter;
00359     return m;
00360 }
00361 
00362 KDecorationOptions::KDecorationOptions()
00363     {
00364     assert( KDecoration::options_ == NULL );
00365     KDecoration::options_ = this;
00366     }
00367 
00368 KDecorationOptions::~KDecorationOptions()
00369     {
00370     assert( KDecoration::options_ == this );
00371     KDecoration::options_ = NULL;
00372     }
00373 
00374 const QColor& KDecorationOptions::color(ColorType type, bool active) const
00375 {
00376     return(d->colors[type + (active ? 0 : NUM_COLORS)]);
00377 }
00378 
00379 const QFont& KDecorationOptions::font(bool active, bool small) const
00380 {
00381     if ( small )
00382         return(active ? d->activeFontSmall : d->inactiveFontSmall);
00383     else
00384         return(active ? d->activeFont : d->inactiveFont);
00385 }
00386 
00387 const QColorGroup& KDecorationOptions::colorGroup(ColorType type, bool active) const
00388 {
00389     int idx = type + (active ? 0 : NUM_COLORS);
00390     if(d->cg[idx])
00391         return(*d->cg[idx]);
00392     d->cg[idx] = new QColorGroup(Qt::black, d->colors[idx], d->colors[idx].light(150),
00393                               d->colors[idx].dark(), d->colors[idx].dark(120),
00394                               Qt::black, QApplication::palette().active().
00395                               base());
00396     return(*d->cg[idx]);
00397 }
00398 
00399 bool KDecorationOptions::customButtonPositions() const
00400 {
00401     return d->custom_button_positions;
00402 }
00403 
00404 QString KDecorationOptions::titleButtonsLeft() const
00405 {
00406     return d->title_buttons_left;
00407 }
00408 
00409 QString KDecorationOptions::titleButtonsRight() const
00410 {
00411     return d->title_buttons_right;
00412 }
00413 
00414 bool KDecorationOptions::showTooltips() const
00415 {
00416     return d->show_tooltips;
00417 }
00418 
00419 KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
00420 {
00421     assert( factory != NULL );
00422     if( d->cached_border_size == BordersCount ) // invalid
00423         d->cached_border_size = d->findPreferredBorderSize( d->border_size,
00424             factory->borderSizes());
00425     return d->cached_border_size;
00426 }
00427 
00428 bool KDecorationOptions::moveResizeMaximizedWindows() const
00429 {
00430     return d->move_resize_maximized_windows;
00431 }
00432 
00433 #include "kdecoration.moc"
KDE Logo
This file is part of the documentation for kwin/lib Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Aug 20 13:39:16 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003