kwin 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 WId KDecoration::windowId() const
00230     {
00231     return bridge_->windowId();
00232     }
00233         
00234 void KDecoration::closeWindow()
00235     {
00236     bridge_->closeWindow();
00237     }
00238 
00239 void KDecoration::maximize( ButtonState button )
00240     {
00241     performWindowOperation( options()->operationMaxButtonClick( button ));
00242     }
00243 
00244 void KDecoration::maximize( MaximizeMode mode )
00245     {
00246     bridge_->maximize( mode );
00247     }
00248     
00249 void KDecoration::minimize()
00250     {
00251     bridge_->minimize();
00252     }
00253 
00254 void KDecoration::showContextHelp()
00255     {
00256     bridge_->showContextHelp();
00257     }
00258     
00259 void KDecoration::setDesktop( int desktop )
00260     {
00261     bridge_->setDesktop( desktop );
00262     }
00263 
00264 void KDecoration::toggleOnAllDesktops()
00265     {
00266     if( isOnAllDesktops())
00267         setDesktop( bridge_->currentDesktop());
00268     else
00269         setDesktop( NET::OnAllDesktops );
00270     }
00271 
00272 void KDecoration::titlebarDblClickOperation()
00273     {
00274     bridge_->titlebarDblClickOperation();
00275     }
00276 
00277 void KDecoration::setShade( bool set )
00278     {
00279     bridge_->setShade( set );
00280     }
00281         
00282 void KDecoration::setKeepAbove( bool set )
00283     {
00284     bridge_->setKeepAbove( set );
00285     }
00286     
00287 void KDecoration::setKeepBelow( bool set )
00288     {
00289     bridge_->setKeepBelow( set );
00290     }
00291 
00292 bool KDecoration::drawbound( const QRect&, bool )
00293     {
00294     return false;
00295     }
00296 
00297 bool KDecoration::animateMinimize( bool )
00298     {
00299     return false;
00300     }
00301 
00302 bool KDecoration::windowDocked( Position )
00303     {
00304     return false;
00305     }
00306 
00307 void KDecoration::helperShowHide( bool show )
00308     {
00309     bridge_->helperShowHide( show );
00310     }
00311 
00312 void KDecoration::reset( unsigned long )
00313     {
00314     }
00315 
00316 void KDecoration::grabXServer()
00317     {
00318     bridge_->grabXServer( true );
00319     }
00320     
00321 void KDecoration::ungrabXServer()
00322     {
00323     bridge_->grabXServer( false );
00324     }
00325     
00326 KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
00327 {
00328     const int range = 16;
00329     int bleft, bright, btop, bbottom;
00330     borders( bleft, bright, btop, bbottom );
00331     btop = KMIN( btop, 4 ); // otherwise whole titlebar would have resize cursor
00332 
00333     Position m = PositionCenter;
00334 
00335     if ( ( p.x() > bleft && p.x() < widget()->width() - bright )
00336          && ( p.y() > btop && p.y() < widget()->height() - bbottom ) )
00337         return PositionCenter;
00338 
00339     if ( p.y() <= KMAX( range, btop ) && p.x() <= KMAX( range, bleft ))
00340         m = PositionTopLeft;
00341     else if ( p.y() >= widget()->height()- KMAX( range, bbottom )
00342         && p.x() >= widget()->width()- KMAX( range, bright ))
00343         m = PositionBottomRight;
00344     else if ( p.y() >= widget()->height()- KMAX( range, bbottom ) && p.x() <= KMAX( range, bleft ))
00345         m = PositionBottomLeft;
00346     else if ( p.y() <= KMAX( range, btop ) && p.x() >= widget()->width()- KMAX( range, bright ))
00347         m = PositionTopRight;
00348     else if ( p.y() <= btop )
00349         m = PositionTop;
00350     else if ( p.y() >= widget()->height()-bbottom )
00351         m = PositionBottom;
00352     else if ( p.x() <= bleft )
00353         m = PositionLeft;
00354     else if ( p.x() >= widget()->width()-bright )
00355         m = PositionRight;
00356     else
00357         m = PositionCenter;
00358     return m;
00359 }
00360 
00361 KDecorationOptions::KDecorationOptions()
00362     {
00363     assert( KDecoration::options_ == NULL );
00364     KDecoration::options_ = this;
00365     }
00366 
00367 KDecorationOptions::~KDecorationOptions()
00368     {
00369     assert( KDecoration::options_ == this );
00370     KDecoration::options_ = NULL;
00371     }
00372 
00373 const QColor& KDecorationOptions::color(ColorType type, bool active) const
00374 {
00375     return(d->colors[type + (active ? 0 : NUM_COLORS)]);
00376 }
00377 
00378 const QFont& KDecorationOptions::font(bool active, bool small) const
00379 {
00380     if ( small )
00381         return(active ? d->activeFontSmall : d->inactiveFontSmall);
00382     else
00383         return(active ? d->activeFont : d->inactiveFont);
00384 }
00385 
00386 const QColorGroup& KDecorationOptions::colorGroup(ColorType type, bool active) const
00387 {
00388     int idx = type + (active ? 0 : NUM_COLORS);
00389     if(d->cg[idx])
00390         return(*d->cg[idx]);
00391     d->cg[idx] = new QColorGroup(Qt::black, d->colors[idx], d->colors[idx].light(150),
00392                               d->colors[idx].dark(), d->colors[idx].dark(120),
00393                               Qt::black, QApplication::palette().active().
00394                               base());
00395     return(*d->cg[idx]);
00396 }
00397 
00398 bool KDecorationOptions::customButtonPositions() const
00399 {
00400     return d->custom_button_positions;
00401 }
00402 
00403 QString KDecorationOptions::titleButtonsLeft() const
00404 {
00405     return d->title_buttons_left;
00406 }
00407 
00408 QString KDecorationOptions::titleButtonsRight() const
00409 {
00410     return d->title_buttons_right;
00411 }
00412 
00413 bool KDecorationOptions::showTooltips() const
00414 {
00415     return d->show_tooltips;
00416 }
00417 
00418 KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
00419 {
00420     assert( factory != NULL );
00421     if( d->cached_border_size == BordersCount ) // invalid
00422         d->cached_border_size = d->findPreferredBorderSize( d->border_size,
00423             factory->borderSizes());
00424     return d->cached_border_size;
00425 }
00426 
00427 bool KDecorationOptions::moveResizeMaximizedWindows() const
00428 {
00429     return d->move_resize_maximized_windows;
00430 }
00431 
00432 KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( Qt::ButtonState button ) const
00433     {
00434     return button == Qt::RightButton? d->OpMaxButtonRightClick : 
00435            button == Qt::MidButton?   d->OpMaxButtonMiddleClick :
00436                                       d->OpMaxButtonLeftClick;
00437     }
00438 
00439 #include "kdecoration.moc"
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Nov 4 00:45:26 2005 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003