• 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 TQ_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(TQt::black, d->colors[idx], d->colors[idx].light(150),
397  d->colors[idx].dark(), d->colors[idx].dark(120),
398  TQt::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 == TQt::RightButton? d->OpMaxButtonRightClick :
440  button == TQt::MidButton? d->OpMaxButtonMiddleClick :
441  d->OpMaxButtonLeftClick;
442  }
443 
444 #include "kdecoration.moc"
KDecoration::initialParentWidget
TQWidget * initialParentWidget() const
The parent widget that should be used for the main widget.
Definition: kdecoration.cpp:74
KDecoration::desktop
int desktop() const
Returns the number of the virtual desktop the decorated window is currently on (including NET::OnAllD...
Definition: kdecoration.cpp:114
KDecoration::isModal
bool isModal() const
Returns true if the decoration window is modal (usually a modal dialog).
Definition: kdecoration.cpp:119
KDecoration::minimize
void minimize()
Minimize the decorated window.
Definition: kdecoration.cpp:249
KDecoration::showContextHelp
void showContextHelp()
Start showing context help in the window (i.e.
Definition: kdecoration.cpp:254
KDecoration::ungrabXServer
void ungrabXServer()
Ungrabs X server (if the number of ungrab attempts matches the number of grab attempts).
Definition: kdecoration.cpp:326
KDecoration::providesContextHelp
bool providesContextHelp() const
Return true if the decorated window can show context help (i.e.
Definition: kdecoration.cpp:109
KDecoration::options
static const KDecorationOptions * options()
Returns the KDecorationOptions object, which is used to access configuration settings for the decorat...
Definition: kdecoration.cpp:55
KDecoration::isMaximizable
bool isMaximizable() const
Returns true if the decorated window can be maximized.
Definition: kdecoration.cpp:94
KDecoration::showWindowMenu
void showWindowMenu(const TQRect &pos)
This function invokes the window operations menu.
Definition: kdecoration.cpp:179
KDecoration::keepBelow
bool keepBelow() const
Returns true if the decorated window should be kept below other windows.
Definition: kdecoration.cpp:144
KDecoration::windowType
NET::WindowType windowType(unsigned long supported_types) const
This function returns the window type of the decorated window.
Definition: kdecoration.cpp:159
KDecorationOptions::font
const TQFont & font(bool active=true, bool small=false) const
Returns the active or inactive decoration font.
Definition: kdecoration.cpp:383
KDecoration::animateMinimize
virtual bool animateMinimize(bool minimize)
This function may be reimplemented to provide custom minimize/restore animations The reimplementation...
Definition: kdecoration.cpp:302
KDecoration::KDecoration
KDecoration(KDecorationBridge *bridge, KDecorationFactory *factory)
Constructs a KDecoration object.
Definition: kdecoration.cpp:41
KDecoration::setShade
void setShade(bool set)
Shades or unshades the decorated window.
Definition: kdecoration.cpp:282
KDecoration::isCloseable
bool isCloseable() const
Returns true if the decoration window can be closed by the user.
Definition: kdecoration.cpp:89
KDecoration::createMainWidget
void createMainWidget(TQt::WFlags flags=0)
Convenience functions that creates and sets a main widget as necessary.
Definition: kdecoration.cpp:60
KDecoration::closeWindow
void closeWindow()
This function can be called by the decoration to request closing of the decorated window...
Definition: kdecoration.cpp:234
KDecoration::caption
TQString caption() const
Returns the decorated window&#39;s caption that should be shown in the titlebar.
Definition: kdecoration.cpp:169
KDecoration::grabXServer
void grabXServer()
Performs X server grab.
Definition: kdecoration.cpp:321
KDecoration::isOnAllDesktops
bool isOnAllDesktops() const
Convenience function that returns true if the window is on all virtual desktops.
Definition: kdecoration.h:875
KDecoration::windowId
WId windowId() const
Returns the handle of the window that is being decorated.
Definition: kdecoration.cpp:229
KDecoration::keepAbove
bool keepAbove() const
Returns true if the decorated window should be kept above other windows.
Definition: kdecoration.cpp:139
KDecoration::toggleOnAllDesktops
void toggleOnAllDesktops()
This function toggles the on-all-desktops state of the decorated window.
Definition: kdecoration.cpp:264
KDecoration::~KDecoration
virtual ~KDecoration()
Destroys the KDecoration.
Definition: kdecoration.cpp:49
KDecoration::reset
virtual void reset(unsigned long changed)
This function is called to reset the decoration on settings changes.
Definition: kdecoration.cpp:317
KDecoration::setKeepBelow
void setKeepBelow(bool set)
Sets or reset keeping this window below others.
Definition: kdecoration.cpp:292
KDecoration::setMask
void setMask(const TQRegion &reg, int mode=0)
If the decoration is non-rectangular, this function needs to be called to set the shape of the decora...
Definition: kdecoration.cpp:194
KDecoration::isShadeable
bool isShadeable() const
Returns true if the decorated window can be shaded.
Definition: kdecoration.cpp:124
KDecoration::icon
TQIconSet icon() const
Returns an icon set with the decorated window&#39;s icon.
Definition: kdecoration.cpp:164
KDecoration::widget
TQWidget * widget()
Returns the main widget for the decoration.
Definition: kdecoration.h:860
KDecorationDefines::WindowOperation
WindowOperation
Definition: kdecoration.h:78
KDecorationOptions::preferredBorderSize
BorderSize preferredBorderSize(KDecorationFactory *factory) const
The preferred border size selected by the user, e.g.
Definition: kdecoration.cpp:423
KDecoration::helperShowHide
void helperShowHide(bool show)
This function is only allowed to be called once from animateMinimize().
Definition: kdecoration.cpp:312
KDecoration::isShade
bool isShade() const
Returns true if the decorated window is currently shaded.
Definition: kdecoration.cpp:129
KDecoration::unobscuredRegion
TQRegion unobscuredRegion(const TQRegion &r) const
Returns the intersection of the given region with the region left unobscured by the windows stacked a...
Definition: kdecoration.cpp:219
KDecoration::setKeepAbove
void setKeepAbove(bool set)
Sets or reset keeping this window above others.
Definition: kdecoration.cpp:287
KDecorationOptions::showTooltips
bool showTooltips() const
Definition: kdecoration.cpp:418
KDecorationOptions::titleButtonsLeft
TQString titleButtonsLeft() const
If customButtonPositions() returns true, titleButtonsLeft returns which buttons should be on the left...
Definition: kdecoration.cpp:408
KDecoration::geometry
TQRect geometry() const
Returns the geometry of the decoration.
Definition: kdecoration.cpp:209
KDecoration::titlebarDblClickOperation
void titlebarDblClickOperation()
This function performs the operation configured as titlebar double click operation.
Definition: kdecoration.cpp:272
KDecoration::borders
virtual void borders(int &left, int &right, int &top, int &bottom) const =0
This function should return the distance from each window side to the inner window.
KDecoration::isMinimizable
bool isMinimizable() const
Returns true if the decorated window can be minimized by the user.
Definition: kdecoration.cpp:104
KDecoration::processMousePressEvent
void processMousePressEvent(TQMouseEvent *e)
This function is the default handler for mouse events.
Definition: kdecoration.cpp:174
KDecoration::isSetShade
bool isSetShade() const
Returns true if the decorated window was set to be shaded.
Definition: kdecoration.cpp:134
KDecorationDefines::Position
Position
These values represent positions inside an area.
Definition: kdecoration.h:53
KDecoration::maximizeMode
MaximizeMode maximizeMode() const
Returns the current maximization mode of the decorated window.
Definition: kdecoration.cpp:99
KDecorationDefines::BorderSize
BorderSize
Border size.
Definition: kdecoration.h:141
KDecoration::setMainWidget
void setMainWidget(TQWidget *)
This should be the first function called in init() to specify the main widget of the decoration...
Definition: kdecoration.cpp:66
KDecoration::iconGeometry
TQRect iconGeometry() const
Returns the icon geometry for the window, i.e.
Definition: kdecoration.cpp:214
KDecorationOptions::titleButtonsRight
TQString titleButtonsRight() const
If customButtonPositions() returns true, titleButtonsRight returns which buttons should be on the rig...
Definition: kdecoration.cpp:413
KDecoration::performWindowOperation
void performWindowOperation(WindowOperation op)
This function performs the given window operation.
Definition: kdecoration.cpp:189
KDecoration::factory
KDecorationFactory * factory() const
Returns the factory that created this decoration.
Definition: kdecoration.h:870
KDecoration::isActive
bool isActive() const
Returns true if the decorated window is currently active.
Definition: kdecoration.cpp:84
KDecorationOptions::customButtonPositions
bool customButtonPositions() const
Returns true if the style should use custom button positions The changed flags for this setting is Se...
Definition: kdecoration.cpp:403
KDecoration::initialWFlags
TQt::WFlags initialWFlags() const
The flags that should be used when creating the main widget.
Definition: kdecoration.cpp:79
KDecoration::isMovable
bool isMovable() const
Returns true if the decorated window can be moved by the user.
Definition: kdecoration.cpp:149
KDecorationDefines::ColorType
ColorType
Basic color types that should be recognized by all decoration styles.
Definition: kdecoration.h:112
KDecoration::clearMask
void clearMask()
This convenience function resets the shape mask.
Definition: kdecoration.cpp:199
KDecoration::workspaceWidget
TQWidget * workspaceWidget() const
Returns the main workspace widget.
Definition: kdecoration.cpp:224
KDecoration::drawbound
virtual bool drawbound(const TQRect &geom, bool clear)
This function may be reimplemented to provide custom bound drawing for transparent moving or resizing...
Definition: kdecoration.cpp:297
KDecorationOptions::color
const TQColor & color(ColorType type, bool active=true) const
Returns the color that should be used for the given part of the decoration.
Definition: kdecoration.cpp:378
KDecoration::isResizable
bool isResizable() const
Returns true if the decorated window can be resized by the user.
Definition: kdecoration.cpp:154
KDecoration::isPreview
bool isPreview() const
If this function returns true, the decorated window is used as a preview e.g.
Definition: kdecoration.cpp:204
KDecoration::setDesktop
void setDesktop(int desktop)
Moves the window to the given desktop.
Definition: kdecoration.cpp:259
KDecorationOptions
This class holds various configuration settings for the decoration.
Definition: kdecoration.h:190
KDecoration::mousePosition
virtual Position mousePosition(const TQPoint &p) const =0
This function should return mouse cursor position in the decoration.
Definition: kdecoration.cpp:331
KDecoration::titlebarMouseWheelOperation
void titlebarMouseWheelOperation(int delta)
This function performs the operation configured as titlebar wheel mouse operation.
Definition: kdecoration.cpp:277
KDecorationOptions::colorGroup
const TQColorGroup & colorGroup(ColorType type, bool active=true) const
Returns a colorgroup using the given decoration color as the background.
Definition: kdecoration.cpp:391
KDecorationDefines::MaximizeMode
MaximizeMode
Maximize mode.
Definition: kdecoration.h:69

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.13
This website is maintained by Timothy Pearson.