• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • twin/lib
 

twin/lib

  • twin
  • lib
kdecoration.cpp
1 /*****************************************************************
2 This file is part of the KDE project.
3 
4 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
5 
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 ******************************************************************/
24 
25 #include "kdecoration.h"
26 
27 #include <kdebug.h>
28 #include <tqapplication.h>
29 #include <tdeglobal.h>
30 #include <assert.h>
31 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
32 #include <X11/Xlib.h>
33 #include <fixx11h.h>
34 #endif
35 
36 #include "kdecoration_p.h"
37 #include "kdecorationfactory.h"
38 
39 KDecorationOptions* KDecoration::options_;
40 
41 KDecoration::KDecoration( KDecorationBridge* bridge, KDecorationFactory* factory )
42  : bridge_( bridge ),
43  w_( NULL ),
44  factory_( factory )
45  {
46  factory->addDecoration( this );
47  }
48 
49 KDecoration::~KDecoration()
50  {
51  factory()->removeDecoration( this );
52  delete w_;
53  }
54 
55 const KDecorationOptions* KDecoration::options()
56  {
57  return options_;
58  }
59 
60 void KDecoration::createMainWidget( TQt::WFlags flags )
61  {
62  // FRAME check flags?
63  setMainWidget( new TQWidget( initialParentWidget(), "decoration widget", initialWFlags() | flags ));
64  }
65 
66 void KDecoration::setMainWidget( TQWidget* w )
67  {
68  assert( w_ == NULL );
69  w_ = w;
70  w->setMouseTracking( true );
71  widget()->resize( geometry().size());
72  }
73 
74 TQWidget* KDecoration::initialParentWidget() const
75  {
76  return bridge_->initialParentWidget();
77  }
78 
79 TQt::WFlags KDecoration::initialWFlags() const
80  {
81  return bridge_->initialWFlags();
82  }
83 
84 bool KDecoration::isActive() const
85  {
86  return bridge_->isActive();
87  }
88 
89 bool KDecoration::isCloseable() const
90  {
91  return bridge_->isCloseable();
92  }
93 
94 bool KDecoration::isMaximizable() const
95  {
96  return bridge_->isMaximizable();
97  }
98 
99 KDecoration::MaximizeMode KDecoration::maximizeMode() const
100  {
101  return bridge_->maximizeMode();
102  }
103 
104 bool KDecoration::isMinimizable() const
105  {
106  return bridge_->isMinimizable();
107  }
108 
109 bool KDecoration::providesContextHelp() const
110  {
111  return bridge_->providesContextHelp();
112  }
113 
114 int KDecoration::desktop() const
115  {
116  return bridge_->desktop();
117  }
118 
119 bool KDecoration::isModal() const
120  {
121  return bridge_->isModal();
122  }
123 
124 bool KDecoration::isShadeable() const
125  {
126  return bridge_->isShadeable();
127  }
128 
129 bool KDecoration::isShade() const
130  {
131  return bridge_->isShade();
132  }
133 
134 bool KDecoration::isSetShade() const
135  {
136  return bridge_->isSetShade();
137  }
138 
139 bool KDecoration::keepAbove() const
140  {
141  return bridge_->keepAbove();
142  }
143 
144 bool KDecoration::keepBelow() const
145  {
146  return bridge_->keepBelow();
147  }
148 
149 bool KDecoration::isMovable() const
150  {
151  return bridge_->isMovable();
152  }
153 
154 bool KDecoration::isResizable() const
155  {
156  return bridge_->isResizable();
157  }
158 
159 NET::WindowType KDecoration::windowType( unsigned long supported_types ) const
160  { // this one is also duplicated in KDecorationFactory
161  return bridge_->windowType( supported_types );
162  }
163 
164 TQIconSet KDecoration::icon() const
165  {
166  return bridge_->icon();
167  }
168 
169 TQString KDecoration::caption() const
170  {
171  return bridge_->caption();
172  }
173 
174 void KDecoration::processMousePressEvent( TQMouseEvent* e )
175  {
176  return bridge_->processMousePressEvent( e );
177  }
178 
179 void KDecoration::showWindowMenu( const TQRect &pos )
180  {
181  bridge_->showWindowMenu( pos );
182  }
183 
184 void KDecoration::showWindowMenu( TQPoint pos )
185  {
186  bridge_->showWindowMenu( pos );
187  }
188 
189 void KDecoration::performWindowOperation( WindowOperation op )
190  {
191  bridge_->performWindowOperation( op );
192  }
193 
194 void KDecoration::setMask( const TQRegion& reg, int mode )
195  {
196  bridge_->setMask( reg, mode );
197  }
198 
199 void KDecoration::clearMask()
200  {
201  bridge_->setMask( TQRegion(), 0 );
202  }
203 
204 bool KDecoration::isPreview() const
205  {
206  return bridge_->isPreview();
207  }
208 
209 TQRect KDecoration::geometry() const
210  {
211  return bridge_->geometry();
212  }
213 
214 TQRect KDecoration::iconGeometry() const
215  {
216  return bridge_->iconGeometry();
217  }
218 
219 TQRegion KDecoration::unobscuredRegion( const TQRegion& r ) const
220  {
221  return bridge_->unobscuredRegion( r );
222  }
223 
224 TQWidget* KDecoration::workspaceWidget() const
225  {
226  return bridge_->workspaceWidget();
227  }
228 
229 WId KDecoration::windowId() const
230  {
231  return bridge_->windowId();
232  }
233 
234 void KDecoration::closeWindow()
235  {
236  bridge_->closeWindow();
237  }
238 
239 void KDecoration::maximize( ButtonState button )
240  {
241  performWindowOperation( options()->operationMaxButtonClick( button ));
242  }
243 
244 void KDecoration::maximize( MaximizeMode mode )
245  {
246  bridge_->maximize( mode );
247  }
248 
249 void KDecoration::minimize()
250  {
251  bridge_->minimize();
252  }
253 
254 void KDecoration::showContextHelp()
255  {
256  bridge_->showContextHelp();
257  }
258 
259 void KDecoration::setDesktop( int desktop )
260  {
261  bridge_->setDesktop( desktop );
262  }
263 
264 void KDecoration::toggleOnAllDesktops()
265  {
266  if( isOnAllDesktops())
267  setDesktop( bridge_->currentDesktop());
268  else
269  setDesktop( NET::OnAllDesktops );
270  }
271 
272 void KDecoration::titlebarDblClickOperation()
273  {
274  bridge_->titlebarDblClickOperation();
275  }
276 
277 void KDecoration::titlebarMouseWheelOperation( int delta )
278  {
279  bridge_->titlebarMouseWheelOperation( delta );
280  }
281 
282 void KDecoration::setShade( bool set )
283  {
284  bridge_->setShade( set );
285  }
286 
287 void KDecoration::setKeepAbove( bool set )
288  {
289  bridge_->setKeepAbove( set );
290  }
291 
292 void KDecoration::setKeepBelow( bool set )
293  {
294  bridge_->setKeepBelow( set );
295  }
296 
297 bool KDecoration::drawbound( const TQRect&, bool )
298  {
299  return false;
300  }
301 
302 bool KDecoration::animateMinimize( bool )
303  {
304  return false;
305  }
306 
307 bool KDecoration::windowDocked( Position )
308  {
309  return false;
310  }
311 
312 void KDecoration::helperShowHide( bool show )
313  {
314  bridge_->helperShowHide( show );
315  }
316 
317 void KDecoration::reset( unsigned long )
318  {
319  }
320 
321 void KDecoration::grabXServer()
322  {
323  bridge_->grabXServer( true );
324  }
325 
326 void KDecoration::ungrabXServer()
327  {
328  bridge_->grabXServer( false );
329  }
330 
331 KDecoration::Position KDecoration::mousePosition( const TQPoint& p ) const
332 {
333  const int range = 16;
334  int bleft, bright, btop, bbottom;
335  borders( bleft, bright, btop, bbottom );
336  btop = KMIN( btop, 4 ); // otherwise whole titlebar would have resize cursor
337 
338  Position m = PositionCenter;
339 
340  if ( ( p.x() > bleft && p.x() < widget()->width() - bright )
341  && ( p.y() > btop && p.y() < widget()->height() - bbottom ) )
342  return PositionCenter;
343 
344  if ( p.y() <= KMAX( range, btop ) && p.x() <= KMAX( range, bleft ))
345  m = PositionTopLeft;
346  else if ( p.y() >= widget()->height()- KMAX( range, bbottom )
347  && p.x() >= widget()->width()- KMAX( range, bright ))
348  m = PositionBottomRight;
349  else if ( p.y() >= widget()->height()- KMAX( range, bbottom ) && p.x() <= KMAX( range, bleft ))
350  m = PositionBottomLeft;
351  else if ( p.y() <= KMAX( range, btop ) && p.x() >= widget()->width()- KMAX( range, bright ))
352  m = PositionTopRight;
353  else if ( p.y() <= btop )
354  m = PositionTop;
355  else if ( p.y() >= widget()->height()-bbottom )
356  m = PositionBottom;
357  else if ( p.x() <= bleft )
358  m = PositionLeft;
359  else if ( p.x() >= widget()->width()-bright )
360  m = PositionRight;
361  else
362  m = PositionCenter;
363  return m;
364 }
365 
366 KDecorationOptions::KDecorationOptions()
367  {
368  assert( KDecoration::options_ == NULL );
369  KDecoration::options_ = this;
370  }
371 
372 KDecorationOptions::~KDecorationOptions()
373  {
374  assert( KDecoration::options_ == this );
375  KDecoration::options_ = NULL;
376  }
377 
378 const TQColor& KDecorationOptions::color(ColorType type, bool active) const
379 {
380  return(d->colors[type + (active ? 0 : NUM_COLORS)]);
381 }
382 
383 const TQFont& KDecorationOptions::font(bool active, bool small) const
384 {
385  if ( small )
386  return(active ? d->activeFontSmall : d->inactiveFontSmall);
387  else
388  return(active ? d->activeFont : d->inactiveFont);
389 }
390 
391 const TQColorGroup& KDecorationOptions::colorGroup(ColorType type, bool active) const
392 {
393  int idx = type + (active ? 0 : NUM_COLORS);
394  if(d->cg[idx])
395  return(*d->cg[idx]);
396  d->cg[idx] = new TQColorGroup(Qt::black, d->colors[idx], d->colors[idx].light(150),
397  d->colors[idx].dark(), d->colors[idx].dark(120),
398  Qt::black, TQApplication::palette().active().
399  base());
400  return(*d->cg[idx]);
401 }
402 
403 bool KDecorationOptions::customButtonPositions() const
404 {
405  return d->custom_button_positions;
406 }
407 
408 TQString KDecorationOptions::titleButtonsLeft() const
409 {
410  return d->title_buttons_left;
411 }
412 
413 TQString KDecorationOptions::titleButtonsRight() const
414 {
415  return d->title_buttons_right;
416 }
417 
418 bool KDecorationOptions::showTooltips() const
419 {
420  return d->show_tooltips;
421 }
422 
423 KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize( KDecorationFactory* factory ) const
424 {
425  assert( factory != NULL );
426  if( d->cached_border_size == BordersCount ) // invalid
427  d->cached_border_size = d->findPreferredBorderSize( d->border_size,
428  factory->borderSizes());
429  return d->cached_border_size;
430 }
431 
432 bool KDecorationOptions::moveResizeMaximizedWindows() const
433 {
434  return d->move_resize_maximized_windows;
435 }
436 
437 KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick( TQt::ButtonState button ) const
438  {
439  return button == Qt::RightButton? d->OpMaxButtonRightClick :
440  button == Qt::MidButton? d->OpMaxButtonMiddleClick :
441  d->OpMaxButtonLeftClick;
442  }
443 
444 #include "kdecoration.moc"

twin/lib

Skip menu "twin/lib"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

twin/lib

Skip menu "twin/lib"
  • kate
  • libkonq
  • twin
  •   lib
Generated for twin/lib by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.