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( QPoint pos )
00180     {
00181     bridge_->showWindowMenu( pos );
00182     }
00183     
00184 void KDecoration::performWindowOperation( WindowOperation op )
00185     {
00186     bridge_->performWindowOperation( op );
00187     }
00188 
00189 void KDecoration::setMask( const QRegion& reg, int mode )
00190     {
00191     bridge_->setMask( reg, mode );
00192     }
00193     
00194 void KDecoration::clearMask()
00195     {
00196     bridge_->setMask( QRegion(), 0 );
00197     }
00198     
00199 bool KDecoration::isPreview() const
00200     {
00201     return bridge_->isPreview();
00202     }
00203     
00204 QRect KDecoration::geometry() const
00205     {
00206     return bridge_->geometry();
00207     }
00208     
00209 QRect KDecoration::iconGeometry() const
00210     {
00211     return bridge_->iconGeometry();
00212     }
00213 
00214 QRegion KDecoration::unobscuredRegion( const QRegion& r ) const
00215     {
00216     return bridge_->unobscuredRegion( r );
00217     }
00218 
00219 QWidget* KDecoration::workspaceWidget() const
00220     {
00221     return bridge_->workspaceWidget();
00222     }
00223         
00224 void KDecoration::closeWindow()
00225     {
00226     bridge_->closeWindow();
00227     }
00228 
00229 void KDecoration::maximize( MaximizeMode mode )
00230     {
00231     bridge_->maximize( mode );
00232     }
00233     
00234 void KDecoration::minimize()
00235     {
00236     bridge_->minimize();
00237     }
00238 
00239 void KDecoration::showContextHelp()
00240     {
00241     bridge_->showContextHelp();
00242     }
00243     
00244 void KDecoration::setDesktop( int desktop )
00245     {
00246     bridge_->setDesktop( desktop );
00247     }
00248 
00249 void KDecoration::toggleOnAllDesktops()
00250     {
00251     if( isOnAllDesktops())
00252         setDesktop( bridge_->currentDesktop());
00253     else
00254         setDesktop( NET::OnAllDesktops );
00255     }
00256 
00257 void KDecoration::titlebarDblClickOperation()
00258     {
00259     bridge_->titlebarDblClickOperation();
00260     }
00261 
00262 void KDecoration::setShade( bool set )
00263     {
00264     bridge_->setShade( set );
00265     }
00266         
00267 void KDecoration::setKeepAbove( bool set )
00268     {
00269     bridge_->setKeepAbove( set );
00270     }
00271     
00272 void KDecoration::setKeepBelow( bool set )
00273     {
00274     bridge_->setKeepBelow( set );
00275     }
00276 
00277 bool KDecoration::drawbound( const QRect&, bool )
00278     {
00279     return false;
00280     }
00281 
00282 bool KDecoration::animateMinimize( bool )
00283     {
00284     return false;
00285     }
00286 
00287 bool KDecoration::windowDocked( Position )
00288     {
00289     return false;
00290     }
00291 
00292 void KDecoration::helperShowHide( bool show )
00293     {
00294     bridge_->helperShowHide( show );
00295     }
00296 
00297 void KDecoration::reset( unsigned long )
00298     {
00299     }
00300 
00301 void KDecoration::grabXServer()
00302     {
00303     bridge_->grabXServer( true );
00304     }
00305     
00306 void KDecoration::ungrabXServer()
00307     {
00308     bridge_->grabXServer( false );
00309     }
00310     
00311 KDecoration::Position KDecoration::mousePosition( const QPoint& p ) const
00312 {
00313     const int range = 16;
00314     int bleft, bright, btop, bbottom;
00315     borders( bleft, bright, btop, bbottom );
00316     btop = KMIN( btop, 4 ); // otherwise whole titlebar would have resize cursor
00317 
00318     Position m = PositionCenter;
00319 
00320     if ( ( p.x() > bleft && p.x() < widget()->width() - bright )
00321          && ( p.y() > btop && p.y() < widget()->height() - bbottom ) )
00322         return PositionCenter;
00323 
00324     if ( p.y() <= KMAX( range, btop ) && p.x() <= KMAX( range, bleft ))
00325         m = PositionTopLeft;
00326     else if ( p.y() >= widget()->height()- KMAX( range, bbottom )
00327         && p.x() >= widget()->width()- KMAX( range, bright ))
00328         m = PositionBottomRight;
00329     else if ( p.y() >= widget()->height()- KMAX( range, bbottom ) && p.x() <= KMAX( range, bleft ))
00330         m = PositionBottomLeft;
00331     else if ( p.y() <= KMAX( range, btop ) && p.x() >= widget()->width()- KMAX( range, bright ))
00332         m = PositionTopRight;
00333     else if ( p.y() <= btop )
00334         m = PositionTop;
00335     else if ( p.y() >= widget()->height()-bbottom )
00336         m = PositionBottom;
00337     else if ( p.x() <= bleft )
00338         m = PositionLeft;
00339     else if ( p.x() >= widget()->width()-bright )
00340         m = PositionRight;
00341     else
00342         m = PositionCenter;
00343     return m;
00344 }
00345 
00346 KDecorationOptions::KDecorationOptions()
00347     {
00348     assert( KDecoration::options_ == NULL );
00349     KDecoration::options_ = this;
00350     }
00351 
00352 KDecorationOptions::~KDecorationOptions()
00353     {
00354     assert( KDecoration::options_ == this );
00355     KDecoration::options_ = NULL;
00356     }
00357 
00358 const QColor& KDecorationOptions::color(ColorType type, bool active) const
00359 {
00360     return(d->colors[type + (active ? 0 : NUM_COLORS)]);
00361 }
00362 
00363 const QFont& KDecorationOptions::font(bool active, bool small) const
00364 {
00365     if ( small )
00366         return(active ? d->activeFontSmall : d->inactiveFontSmall);
00367     else
00368         return(active ? d->activeFont : d->inactiveFont);
00369 }
00370 
00371 const QColorGroup& KDecorationOptions::colorGroup(ColorType type, bool active) const
00372 {
00373     int idx = type + (active ? 0 : NUM_COLORS);
00374     if(d->cg[idx])
00375         return(*d->cg[idx]);
00376     d->cg[idx] = new QColorGroup(Qt::black, d->colors[idx], d->colors[idx].light(150),
00377                               d->colors[idx].dark(), d->colors[idx].dark(120),
00378                               Qt::black, QApplication::palette().active().
00379                               base());
00380     return(*d->cg[idx]);
00381 }
00382 
00383 bool KDecorationOptions::customButtonPositions() const
00384 {
00385     return d->custom_button_positions;
00386 }
00387 
00388 QString KDecorationOptions::titleButtonsLeft() const
00389 {
00390     return d->title_buttons_left;
00391 }
00392 
00393 QString KDecorationOptions::titleButtonsRight() const
00394 {
00395     return d->title_buttons_right;
00396 }
00397 
00398 bool KDecorationOptions::showTooltips() const
00399 {
00400     return d->show_tooltips;
00401 }
00402 
00403 KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
00404 {
00405     assert( factory != NULL );
00406     if( d->cached_border_size == BordersCount ) // invalid
00407         d->cached_border_size = d->findPreferredBorderSize( d->border_size,
00408             factory->borderSizes());
00409     return d->cached_border_size;
00410 }
00411 
00412 bool KDecorationOptions::moveResizeMaximizedWindows() const
00413 {
00414     return d->move_resize_maximized_windows;
00415 }
00416 
00417 #include "kdecoration.moc"
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 29 21:20:50 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003