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 <tqapplication.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( TQt::WFlags flags ) 00061 { 00062 // FRAME check flags? 00063 setMainWidget( new TQWidget( initialParentWidget(), "decoration widget", initialWFlags() | flags )); 00064 } 00065 00066 void KDecoration::setMainWidget( TQWidget* w ) 00067 { 00068 assert( w_ == NULL ); 00069 w_ = w; 00070 w->setMouseTracking( true ); 00071 widget()->resize( geometry().size()); 00072 } 00073 00074 TQWidget* KDecoration::initialParentWidget() const 00075 { 00076 return bridge_->initialParentWidget(); 00077 } 00078 00079 TQt::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 TQIconSet KDecoration::icon() const 00165 { 00166 return bridge_->icon(); 00167 } 00168 00169 TQString KDecoration::caption() const 00170 { 00171 return bridge_->caption(); 00172 } 00173 00174 void KDecoration::processMousePressEvent( TQMouseEvent* e ) 00175 { 00176 return bridge_->processMousePressEvent( e ); 00177 } 00178 00179 void KDecoration::showWindowMenu( const TQRect &pos ) 00180 { 00181 bridge_->showWindowMenu( pos ); 00182 } 00183 00184 void KDecoration::showWindowMenu( TQPoint 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 TQRegion& reg, int mode ) 00195 { 00196 bridge_->setMask( reg, mode ); 00197 } 00198 00199 void KDecoration::clearMask() 00200 { 00201 bridge_->setMask( TQRegion(), 0 ); 00202 } 00203 00204 bool KDecoration::isPreview() const 00205 { 00206 return bridge_->isPreview(); 00207 } 00208 00209 TQRect KDecoration::geometry() const 00210 { 00211 return bridge_->geometry(); 00212 } 00213 00214 TQRect KDecoration::iconGeometry() const 00215 { 00216 return bridge_->iconGeometry(); 00217 } 00218 00219 TQRegion KDecoration::unobscuredRegion( const TQRegion& r ) const 00220 { 00221 return bridge_->unobscuredRegion( r ); 00222 } 00223 00224 TQWidget* 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::titlebarMouseWheelOperation( int delta ) 00278 { 00279 bridge_->titlebarMouseWheelOperation( delta ); 00280 } 00281 00282 void KDecoration::setShade( bool set ) 00283 { 00284 bridge_->setShade( set ); 00285 } 00286 00287 void KDecoration::setKeepAbove( bool set ) 00288 { 00289 bridge_->setKeepAbove( set ); 00290 } 00291 00292 void KDecoration::setKeepBelow( bool set ) 00293 { 00294 bridge_->setKeepBelow( set ); 00295 } 00296 00297 bool KDecoration::drawbound( const TQRect&, bool ) 00298 { 00299 return false; 00300 } 00301 00302 bool KDecoration::animateMinimize( bool ) 00303 { 00304 return false; 00305 } 00306 00307 bool KDecoration::windowDocked( Position ) 00308 { 00309 return false; 00310 } 00311 00312 void KDecoration::helperShowHide( bool show ) 00313 { 00314 bridge_->helperShowHide( show ); 00315 } 00316 00317 void KDecoration::reset( unsigned long ) 00318 { 00319 } 00320 00321 void KDecoration::grabXServer() 00322 { 00323 bridge_->grabXServer( true ); 00324 } 00325 00326 void KDecoration::ungrabXServer() 00327 { 00328 bridge_->grabXServer( false ); 00329 } 00330 00331 KDecoration::Position KDecoration::mousePosition( const TQPoint& p ) const 00332 { 00333 const int range = 16; 00334 int bleft, bright, btop, bbottom; 00335 borders( bleft, bright, btop, bbottom ); 00336 btop = KMIN( btop, 4 ); // otherwise whole titlebar would have resize cursor 00337 00338 Position m = PositionCenter; 00339 00340 if ( ( p.x() > bleft && p.x() < widget()->width() - bright ) 00341 && ( p.y() > btop && p.y() < widget()->height() - bbottom ) ) 00342 return PositionCenter; 00343 00344 if ( p.y() <= KMAX( range, btop ) && p.x() <= KMAX( range, bleft )) 00345 m = PositionTopLeft; 00346 else if ( p.y() >= widget()->height()- KMAX( range, bbottom ) 00347 && p.x() >= widget()->width()- KMAX( range, bright )) 00348 m = PositionBottomRight; 00349 else if ( p.y() >= widget()->height()- KMAX( range, bbottom ) && p.x() <= KMAX( range, bleft )) 00350 m = PositionBottomLeft; 00351 else if ( p.y() <= KMAX( range, btop ) && p.x() >= widget()->width()- KMAX( range, bright )) 00352 m = PositionTopRight; 00353 else if ( p.y() <= btop ) 00354 m = PositionTop; 00355 else if ( p.y() >= widget()->height()-bbottom ) 00356 m = PositionBottom; 00357 else if ( p.x() <= bleft ) 00358 m = PositionLeft; 00359 else if ( p.x() >= widget()->width()-bright ) 00360 m = PositionRight; 00361 else 00362 m = PositionCenter; 00363 return m; 00364 } 00365 00366 KDecorationOptions::KDecorationOptions() 00367 { 00368 assert( KDecoration::options_ == NULL ); 00369 KDecoration::options_ = this; 00370 } 00371 00372 KDecorationOptions::~KDecorationOptions() 00373 { 00374 assert( KDecoration::options_ == this ); 00375 KDecoration::options_ = NULL; 00376 } 00377 00378 const TQColor& KDecorationOptions::color(ColorType type, bool active) const 00379 { 00380 return(d->colors[type + (active ? 0 : NUM_COLORS)]); 00381 } 00382 00383 const TQFont& KDecorationOptions::font(bool active, bool small) const 00384 { 00385 if ( small ) 00386 return(active ? d->activeFontSmall : d->inactiveFontSmall); 00387 else 00388 return(active ? d->activeFont : d->inactiveFont); 00389 } 00390 00391 const TQColorGroup& KDecorationOptions::colorGroup(ColorType type, bool active) const 00392 { 00393 int idx = type + (active ? 0 : NUM_COLORS); 00394 if(d->cg[idx]) 00395 return(*d->cg[idx]); 00396 d->cg[idx] = new TQColorGroup(Qt::black, d->colors[idx], d->colors[idx].light(150), 00397 d->colors[idx].dark(), d->colors[idx].dark(120), 00398 Qt::black, TQApplication::palette().active(). 00399 base()); 00400 return(*d->cg[idx]); 00401 } 00402 00403 bool KDecorationOptions::customButtonPositions() const 00404 { 00405 return d->custom_button_positions; 00406 } 00407 00408 TQString KDecorationOptions::titleButtonsLeft() const 00409 { 00410 return d->title_buttons_left; 00411 } 00412 00413 TQString KDecorationOptions::titleButtonsRight() const 00414 { 00415 return d->title_buttons_right; 00416 } 00417 00418 bool KDecorationOptions::showTooltips() const 00419 { 00420 return d->show_tooltips; 00421 } 00422 00423 KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const 00424 { 00425 assert( factory != NULL ); 00426 if( d->cached_border_size == BordersCount ) // invalid 00427 d->cached_border_size = d->findPreferredBorderSize( d->border_size, 00428 factory->borderSizes()); 00429 return d->cached_border_size; 00430 } 00431 00432 bool KDecorationOptions::moveResizeMaximizedWindows() const 00433 { 00434 return d->move_resize_maximized_windows; 00435 } 00436 00437 KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( TQt::ButtonState button ) const 00438 { 00439 return button == Qt::RightButton? d->OpMaxButtonRightClick : 00440 button == Qt::MidButton? d->OpMaxButtonMiddleClick : 00441 d->OpMaxButtonLeftClick; 00442 } 00443 00444 #include "kdecoration.moc"