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

twin/lib

  • twin
  • lib
kcommondecoration.cpp
1/*
2 This file is part of the KDE project.
3
4 Copyright (C) 2005 Sandro Giessl <sandro@giessl.com>
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 <tqapplication.h>
26#include <tqcursor.h>
27#include <tqdatetime.h>
28#include <tqlabel.h>
29#include <tqtooltip.h>
30#include <tqwidget.h>
31
32#include <kdebug.h>
33
34#include <tdeapplication.h>
35#include <kdecorationfactory.h>
36#include <tdelocale.h>
37
38#include <X11/Xlib.h>
39#include <X11/Xatom.h>
40
41#include "kcommondecoration.h"
42#include "kcommondecoration.moc"
43
44KCommonDecoration::KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory)
45 : KDecoration (bridge, factory),
46 m_previewWidget(0),
47 btnHideMinWidth(200),
48 btnHideLastWidth(0),
49 closing(false)
50{
51 // sizeof(...) is calculated at compile time
52 memset(m_button, 0, sizeof(KCommonDecorationButton *) * NumButtons);
53}
54
55KCommonDecoration::~KCommonDecoration()
56{
57 for (int n=0; n<NumButtons; n++) {
58 if (m_button[n]) delete m_button[n];
59 }
60 delete m_previewWidget;
61}
62
63bool KCommonDecoration::decorationBehaviour(DecorationBehaviour behaviour) const
64{
65 switch (behaviour) {
66 case DB_MenuClose:
67 return false;
68
69 case DB_WindowMask:
70 return false;
71
72 case DB_ButtonHide:
73 return true;
74 }
75
76 return false;
77}
78
79int KCommonDecoration::layoutMetric(LayoutMetric lm, bool, const KCommonDecorationButton *) const
80{
81 switch (lm) {
82 case LM_BorderLeft:
83 case LM_BorderRight:
84 case LM_BorderBottom:
85 case LM_TitleEdgeTop:
86 case LM_TitleEdgeBottom:
87 case LM_TitleEdgeLeft:
88 case LM_TitleEdgeRight:
89 case LM_TitleBorderLeft:
90 case LM_TitleBorderRight:
91 return 5;
92
93
94 case LM_ButtonWidth:
95 case LM_ButtonHeight:
96 case LM_TitleHeight:
97 return 20;
98
99 case LM_ButtonSpacing:
100 return 5;
101
102 case LM_ButtonMarginTop:
103 case LM_RightButtonsMarginTop:
104 return 0;
105
106 case LM_ExplicitButtonSpacer:
107 return 5;
108
109 default:
110 return 0;
111 }
112}
113
114void KCommonDecoration::init()
115{
116 createMainWidget(TQt::WNoAutoErase);
117
118 // for flicker-free redraws
119 widget()->setBackgroundMode(NoBackground);
120
121 widget()->installEventFilter( this );
122
123 resetLayout();
124
125 connect(this, TQ_SIGNAL(keepAboveChanged(bool) ), TQ_SLOT(keepAboveChange(bool) ) );
126 connect(this, TQ_SIGNAL(keepBelowChanged(bool) ), TQ_SLOT(keepBelowChange(bool) ) );
127
128 updateCaption();
129}
130
131void KCommonDecoration::reset( unsigned long changed )
132{
133 if (changed & SettingButtons) {
134 resetLayout();
135 widget()->update();
136 }
137}
138
139TQRegion KCommonDecoration::cornerShape(WindowCorner)
140{
141 return TQRegion();
142}
143
144void KCommonDecoration::updateCaption()
145{
146 // This should be reimplemented in decorations for better efficiency
147 widget()->update();
148}
149
150void KCommonDecoration::borders( int& left, int& right, int& top, int& bottom ) const
151{
152 left = layoutMetric(LM_BorderLeft);
153 right = layoutMetric(LM_BorderRight);
154 bottom = layoutMetric(LM_BorderBottom);
155 top = layoutMetric(LM_TitleHeight) +
156 layoutMetric(LM_TitleEdgeTop) +
157 layoutMetric(LM_TitleEdgeBottom);
158
159 updateLayout(); // TODO!! don't call everytime we are in ::borders
160}
161
162void KCommonDecoration::updateLayout() const
163{
164 TQRect r = widget()->rect();
165 int r_x, r_y, r_x2, r_y2;
166 r.coords(&r_x, &r_y, &r_x2, &r_y2);
167
168 // layout preview widget
169 if (m_previewWidget) {
170 const int borderLeft = layoutMetric(LM_BorderLeft);
171 const int borderRight = layoutMetric(LM_BorderRight);
172 const int borderBottom = layoutMetric(LM_BorderBottom);
173 const int titleHeight = layoutMetric(LM_TitleHeight);
174 const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
175 const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
176
177 int left = r_x+borderLeft;
178 int top = r_y+titleEdgeTop+titleHeight+titleEdgeBottom;
179 int width = r_x2-borderRight-left+1;
180 int height = r_y2-borderBottom-top+1;
181 m_previewWidget->setGeometry(left, top, width, height);
182 moveWidget(left,top, m_previewWidget);
183 resizeWidget(width, height, m_previewWidget);
184 }
185
186 // resize buttons...
187 for (int n=0; n<NumButtons; n++) {
188 if (m_button[n]) {
189 TQSize newSize = TQSize(layoutMetric(LM_ButtonWidth, true, m_button[n]),
190 layoutMetric(LM_ButtonHeight, true, m_button[n]) );
191 if (newSize != m_button[n]->size() )
192 m_button[n]->setSize(newSize);
193 }
194 }
195
196 // layout buttons
197 int y = r_y + layoutMetric(LM_TitleEdgeTop) + layoutMetric(LM_ButtonMarginTop);
198 if (m_buttonsLeft.count() > 0) {
199 const int buttonSpacing = layoutMetric(LM_ButtonSpacing);
200 int x = r_x + layoutMetric(LM_TitleEdgeLeft);
201 for (ButtonContainer::const_iterator it = m_buttonsLeft.begin(); it != m_buttonsLeft.end(); ++it) {
202 bool elementLayouted = false;
203 if (*it) {
204 if (!(*it)->isHidden() ) {
205 moveWidget(x,y, *it);
206 x += layoutMetric(LM_ButtonWidth, true, ::tqt_cast<KCommonDecorationButton*>(*it) );
207 elementLayouted = true;
208 }
209 } else {
210 x+= layoutMetric(LM_ExplicitButtonSpacer);
211 elementLayouted = true;
212 }
213 if (elementLayouted && it != m_buttonsLeft.end() )
214 x += buttonSpacing;
215 }
216 }
217
218 if (m_buttonsRight.count() > 0) {
219 int y = r_y + layoutMetric(LM_TitleEdgeTop) + layoutMetric(LM_ButtonMarginTop) + layoutMetric(LM_RightButtonsMarginTop);
220 const int titleEdgeRightLeft = r_x2-layoutMetric(LM_TitleEdgeRight)+1;
221
222 const int buttonSpacing = layoutMetric(LM_ButtonSpacing);
223 int x = titleEdgeRightLeft - buttonContainerWidth(m_buttonsRight);
224 for (ButtonContainer::const_iterator it = m_buttonsRight.begin(); it != m_buttonsRight.end(); ++it) {
225 bool elementLayouted = false;
226 if (*it) {
227 if (!(*it)->isHidden() ) {
228 moveWidget(x,y, *it);
229 x += layoutMetric(LM_ButtonWidth, true, ::tqt_cast<KCommonDecorationButton*>(*it) );;
230 elementLayouted = true;
231 }
232 } else {
233 x += layoutMetric(LM_ExplicitButtonSpacer);
234 elementLayouted = true;
235 }
236 if (elementLayouted && it != m_buttonsRight.end() )
237 x += buttonSpacing;
238 }
239 }
240}
241
242void KCommonDecoration::updateButtons() const
243{
244 for (int n=0; n<NumButtons; n++)
245 if (m_button[n]) m_button[n]->update();
246}
247
248void KCommonDecoration::resetButtons() const
249{
250 for (int n=0; n<NumButtons; n++)
251 if (m_button[n]) m_button[n]->reset(KCommonDecorationButton::ManualReset);
252}
253
254void KCommonDecoration::resetLayout()
255{
256 for (int n=0; n<NumButtons; n++) {
257 if (m_button[n]) {
258 delete m_button[n];
259 m_button[n] = 0;
260 }
261 }
262 m_buttonsLeft.clear();
263 m_buttonsRight.clear();
264
265 delete m_previewWidget;
266 m_previewWidget = 0;
267
268 // shown instead of the window contents in decoration previews
269 if(isPreview() ) {
270 m_previewWidget = new TQLabel(i18n("%1 is the name of window decoration style", "<center><b>%1 preview</b></center>").arg(visibleName() ), widget());
271 m_previewWidget->show();
272 }
273
274 addButtons(m_buttonsLeft,
275 options()->customButtonPositions() ? options()->titleButtonsLeft() : defaultButtonsLeft(),
276 true);
277 addButtons(m_buttonsRight,
278 options()->customButtonPositions() ? options()->titleButtonsRight() : defaultButtonsRight(),
279 false);
280
281 updateLayout();
282
283 const int minTitleBarWidth = 35;
284 btnHideMinWidth = buttonContainerWidth(m_buttonsLeft,true) + buttonContainerWidth(m_buttonsRight,true) +
285 layoutMetric(LM_TitleEdgeLeft,false) + layoutMetric(LM_TitleEdgeRight,false) +
286 layoutMetric(LM_TitleBorderLeft,false) + layoutMetric(LM_TitleBorderRight,false) +
287 minTitleBarWidth;
288 btnHideLastWidth = 0;
289}
290
291int KCommonDecoration::buttonsLeftWidth() const
292{
293 return buttonContainerWidth(m_buttonsLeft);
294}
295
296int KCommonDecoration::buttonsRightWidth() const
297{
298 return buttonContainerWidth(m_buttonsRight);
299}
300
301int KCommonDecoration::buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden) const
302{
303 int explicitSpacer = layoutMetric(LM_ExplicitButtonSpacer);
304
305 int shownElementsCount = 0;
306
307 int w = 0;
308 for (ButtonContainer::const_iterator it = btnContainer.begin(); it != btnContainer.end(); ++it) {
309 if (*it) {
310 if (countHidden || !(*it)->isHidden() ) {
311 w += (*it)->width();
312 ++shownElementsCount;
313 }
314 } else {
315 w += explicitSpacer;
316 ++shownElementsCount;
317 }
318 }
319 w += layoutMetric(LM_ButtonSpacing)*(shownElementsCount-1);
320
321 return w;
322}
323
324bool KCommonDecoration::isModalSystemNotification()
325{
326 unsigned char *data = 0;
327 Atom actual;
328 int format, result;
329 unsigned long n, left;
330 Atom kde_wm_system_modal_notification;
331 kde_wm_system_modal_notification = XInternAtom(tqt_xdisplay(), "_TDE_WM_MODAL_SYS_NOTIFICATION", False);
332 result = XGetWindowProperty(tqt_xdisplay(), windowId(), kde_wm_system_modal_notification, 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left, /*(unsigned char **)*/ &data);
333 if (result == Success && data != None && format == 32 )
334 {
335 return TRUE;
336 }
337 return FALSE;
338}
339
340void KCommonDecoration::addButtons(ButtonContainer &btnContainer, const TQString& s, bool isLeft)
341{
342 if (s.length() > 0) {
343 for (unsigned n=0; n < s.length(); n++) {
344 KCommonDecorationButton *btn = 0;
345 switch (s[n]) {
346 case 'M': // Menu button
347 if (!isModalSystemNotification()) {
348 if (!m_button[MenuButton]){
349 btn = createButton(MenuButton);
350 if (!btn) break;
351 btn->setTipText(i18n("Menu") );
352 btn->setRealizeButtons(TQt::LeftButton|TQt::RightButton);
353 connect(btn, TQ_SIGNAL(pressed()), TQ_SLOT(menuButtonPressed()));
354 connect(btn, TQ_SIGNAL(released()), this, TQ_SLOT(menuButtonReleased()));
355
356 m_button[MenuButton] = btn;
357 }
358 }
359 break;
360 case 'S': // OnAllDesktops button
361 if (!isModalSystemNotification()) {
362 if (!m_button[OnAllDesktopsButton]){
363 btn = createButton(OnAllDesktopsButton);
364 if (!btn) break;
365 const bool oad = isOnAllDesktops();
366 btn->setTipText(oad?i18n("Not on all desktops"):i18n("On all desktops") );
367 btn->setToggleButton(true);
368 btn->setOn( oad );
369 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(toggleOnAllDesktops()));
370
371 m_button[OnAllDesktopsButton] = btn;
372 }
373 }
374 break;
375 case 'H': // Help button
376 if ((!m_button[HelpButton]) && providesContextHelp()){
377 btn = createButton(HelpButton);
378 if (!btn) break;
379 btn->setTipText(i18n("Help") );
380 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(showContextHelp()));
381
382 m_button[HelpButton] = btn;
383 }
384 break;
385 case 'I': // Minimize button
386 if ((!m_button[MinButton]) && isMinimizable()){
387 btn = createButton(MinButton);
388 if (!btn) break;
389 btn->setTipText(i18n("Minimize") );
390 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(minimize()));
391
392 m_button[MinButton] = btn;
393 }
394 break;
395 case 'A': // Maximize button
396 if ((!m_button[MaxButton]) && isMaximizable()){
397 btn = createButton(MaxButton);
398 if (!btn) break;
399 btn->setRealizeButtons(TQt::LeftButton|TQt::MidButton|TQt::RightButton);
400 const bool max = maximizeMode()==MaximizeFull;
401 btn->setTipText(max?i18n("Restore"):i18n("Maximize") );
402 btn->setToggleButton(true);
403 btn->setOn( max );
404 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotMaximize()));
405
406 m_button[MaxButton] = btn;
407 }
408 break;
409 case 'X': // Close button
410 if ((!m_button[CloseButton]) && isCloseable()){
411 btn = createButton(CloseButton);
412 if (!btn) break;
413 btn->setTipText(i18n("Close") );
414 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(closeWindow()));
415
416 m_button[CloseButton] = btn;
417 }
418 break;
419 case 'F': // AboveButton button
420 if (!m_button[AboveButton]){
421 btn = createButton(AboveButton);
422 if (!btn) break;
423 bool above = keepAbove();
424 btn->setTipText(above?i18n("Do not keep above others"):i18n("Keep above others") );
425 btn->setToggleButton(true);
426 btn->setOn( above );
427 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotKeepAbove()));
428
429 m_button[AboveButton] = btn;
430 }
431 break;
432 case 'B': // BelowButton button
433 if (!m_button[BelowButton]){
434 btn = createButton(BelowButton);
435 if (!btn) break;
436 bool below = keepBelow();
437 btn->setTipText(below?i18n("Do not keep below others"):i18n("Keep below others") );
438 btn->setToggleButton(true);
439 btn->setOn( below );
440 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotKeepBelow()));
441
442 m_button[BelowButton] = btn;
443 }
444 break;
445 case 'L': // Shade button
446 if ((!m_button[ShadeButton]) && isShadeable()){
447 btn = createButton(ShadeButton);
448 if (!btn) break;
449 bool shaded = isSetShade();
450 btn->setTipText(shaded?i18n("Unshade"):i18n("Shade") );
451 btn->setToggleButton(true);
452 btn->setOn( shaded );
453 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotShade()));
454
455 m_button[ShadeButton] = btn;
456 }
457 break;
458 case '_': // Spacer item
459 btnContainer.append(0);
460 }
461
462
463 if (btn) {
464 btn->setLeft(isLeft);
465 btn->setSize(TQSize(layoutMetric(LM_ButtonWidth, true, btn),layoutMetric(LM_ButtonHeight, true, btn)) );
466 btn->show();
467 btnContainer.append(btn);
468 }
469
470 }
471 }
472}
473
474void KCommonDecoration::calcHiddenButtons()
475{
476 if (width() == btnHideLastWidth)
477 return;
478
479 btnHideLastWidth = width();
480
481 //Hide buttons in the following order:
482 KCommonDecorationButton* btnArray[] = { m_button[HelpButton], m_button[ShadeButton], m_button[BelowButton],
483 m_button[AboveButton], m_button[OnAllDesktopsButton], m_button[MaxButton],
484 m_button[MinButton], m_button[MenuButton], m_button[CloseButton] };
485 const int buttonsCount = sizeof( btnArray ) / sizeof( btnArray[ 0 ] );
486
487 int current_width = width();
488 int count = 0;
489
490 // Hide buttons
491 while (current_width < btnHideMinWidth && count < buttonsCount)
492 {
493 if (btnArray[count] ) {
494 current_width += btnArray[count]->width();
495 if (btnArray[count]->isVisible() )
496 btnArray[count]->hide();
497 }
498 count++;
499 }
500 // Show the rest of the buttons...
501 for(int i = count; i < buttonsCount; i++)
502 {
503 if (btnArray[i] ) {
504
505 if (! btnArray[i]->isHidden() )
506 break; // all buttons shown...
507
508 btnArray[i]->show();
509 }
510 }
511}
512
513void KCommonDecoration::show()
514{
515 if (decorationBehaviour(DB_ButtonHide) )
516 calcHiddenButtons();
517 widget()->show();
518}
519
520void KCommonDecoration::resize( const TQSize& s )
521{
522 widget()->resize( s );
523}
524
525TQSize KCommonDecoration::minimumSize() const
526{
527 const int minWidth = TQMAX(layoutMetric(LM_TitleEdgeLeft), layoutMetric(LM_BorderLeft))
528 +TQMAX(layoutMetric(LM_TitleEdgeRight), layoutMetric(LM_BorderRight))
529 +layoutMetric(LM_TitleBorderLeft)+layoutMetric(LM_TitleBorderRight);
530 return TQSize(minWidth,
531 layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)
532 +layoutMetric(LM_TitleEdgeBottom)
533 +layoutMetric(LM_BorderBottom) );
534}
535
536void KCommonDecoration::maximizeChange()
537{
538 if( m_button[MaxButton] ) {
539 m_button[MaxButton]->setOn( maximizeMode()==MaximizeFull);
540 m_button[MaxButton]->setTipText( (maximizeMode()!=MaximizeFull) ?
541 i18n("Maximize")
542 : i18n("Restore"));
543 m_button[MaxButton]->reset(KCommonDecorationButton::StateChange);
544 }
545 updateWindowShape();
546 widget()->update();
547}
548
549void KCommonDecoration::desktopChange()
550{
551 if ( m_button[OnAllDesktopsButton] ) {
552 m_button[OnAllDesktopsButton]->setOn( isOnAllDesktops() );
553 m_button[OnAllDesktopsButton]->setTipText( isOnAllDesktops() ?
554 i18n("Not on all desktops")
555 : i18n("On all desktops"));
556 m_button[OnAllDesktopsButton]->reset(KCommonDecorationButton::StateChange);
557 }
558}
559
560void KCommonDecoration::shadeChange()
561{
562 if ( m_button[ShadeButton] ) {
563 bool shaded = isSetShade();
564 m_button[ShadeButton]->setOn( shaded );
565 m_button[ShadeButton]->setTipText( shaded ?
566 i18n("Unshade")
567 : i18n("Shade"));
568 m_button[ShadeButton]->reset(KCommonDecorationButton::StateChange);
569 }
570}
571
572void KCommonDecoration::iconChange()
573{
574 if (m_button[MenuButton])
575 {
576 m_button[MenuButton]->update();
577 m_button[MenuButton]->reset(KCommonDecorationButton::IconChange);
578 }
579}
580
581void KCommonDecoration::activeChange()
582{
583 updateButtons();
584 widget()->update(); // do something similar to updateCaption here
585}
586
587void KCommonDecoration::captionChange()
588{
589 updateCaption();
590}
591
592void KCommonDecoration::keepAboveChange(bool above)
593{
594 if (m_button[AboveButton])
595 {
596 m_button[AboveButton]->setOn(above);
597 m_button[AboveButton]->setTipText( above?i18n("Do not keep above others"):i18n("Keep above others") );
598 m_button[AboveButton]->reset(KCommonDecorationButton::StateChange);
599 }
600
601 if (m_button[BelowButton] && m_button[BelowButton]->isOn())
602 {
603 m_button[BelowButton]->setOn(false);
604 m_button[BelowButton]->setTipText( i18n("Keep below others") );
605 m_button[BelowButton]->reset(KCommonDecorationButton::StateChange);
606 }
607}
608
609void KCommonDecoration::keepBelowChange(bool below)
610{
611 if (m_button[BelowButton])
612 {
613 m_button[BelowButton]->setOn(below);
614 m_button[BelowButton]->setTipText( below?i18n("Do not keep below others"):i18n("Keep below others") );
615 m_button[BelowButton]->reset(KCommonDecorationButton::StateChange);
616 }
617
618 if (m_button[AboveButton] && m_button[AboveButton]->isOn())
619 {
620 m_button[AboveButton]->setOn(false);
621 m_button[AboveButton]->setTipText( i18n("Keep above others") );
622 m_button[AboveButton]->reset(KCommonDecorationButton::StateChange);
623 }
624}
625
626void KCommonDecoration::slotMaximize()
627{
628 if (m_button[MaxButton])
629 {
630 maximize(m_button[MaxButton]->lastMousePress() );
631 }
632}
633
634void KCommonDecoration::slotShade()
635{
636 setShade( !isSetShade() );
637}
638
639void KCommonDecoration::slotKeepAbove()
640{
641 setKeepAbove(!keepAbove() );
642}
643
644void KCommonDecoration::slotKeepBelow()
645{
646 setKeepBelow(!keepBelow() );
647}
648
649void KCommonDecoration::menuButtonPressed()
650{
651 static TQTime* t = NULL;
652 static KCommonDecoration* lastClient = NULL;
653 if (t == NULL)
654 t = new TQTime;
655 bool dbl = (lastClient==this && t->elapsed() <= TQApplication::doubleClickInterval());
656 lastClient = this;
657 t->start();
658 if (!dbl || !decorationBehaviour(DB_MenuClose) ) {
659 TQRect menuRect = m_button[MenuButton]->rect();
660 TQPoint menutop = m_button[MenuButton]->mapToGlobal(menuRect.topLeft());
661 TQPoint menubottom = m_button[MenuButton]->mapToGlobal(menuRect.bottomRight())+TQPoint(0,2);
662 KDecorationFactory* f = factory();
663 showWindowMenu(TQRect(menutop, menubottom));
664 if( !f->exists( this )) // 'this' was deleted
665 return;
666 m_button[MenuButton]->setDown(false);
667 }
668 else
669 closing = true;
670}
671
672void KCommonDecoration::menuButtonReleased()
673{
674 if(closing)
675 closeWindow();
676}
677
678void KCommonDecoration::resizeEvent(TQResizeEvent */*e*/)
679{
680 if (decorationBehaviour(DB_ButtonHide) )
681 calcHiddenButtons();
682
683 updateLayout();
684
685 updateWindowShape();
686 // FIXME: don't update() here! this would result in two paintEvent()s
687 // because there is already "something" else triggering the repaint...
688// widget()->update();
689}
690
691void KCommonDecoration::moveWidget(int x, int y, TQWidget *widget) const
692{
693 TQPoint p = widget->pos();
694 int oldX = p.y();
695 int oldY = p.x();
696
697 if (x!=oldX || y!=oldY)
698 widget->move(x,y);
699}
700
701void KCommonDecoration::resizeWidget(int w, int h, TQWidget *widget) const
702{
703 TQSize s = widget->size();
704 int oldW = s.width();
705 int oldH = s.height();
706
707 if (w!=oldW || h!=oldH)
708 widget->resize(w,h);
709}
710
711void KCommonDecoration::mouseDoubleClickEvent(TQMouseEvent *e)
712{
713 if( e->button() != TQt::LeftButton )
714 return;
715
716 int tb = layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeBottom);
717 // when shaded, react on double clicks everywhere to make it easier to unshade. otherwise
718 // react only on double clicks in the title bar region...
719 if (isSetShade() || e->pos().y() <= tb )
720 titlebarDblClickOperation();
721}
722
723void KCommonDecoration::wheelEvent(TQWheelEvent *e)
724{
725 int tb = layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeBottom);
726 if (isSetShade() || e->pos().y() <= tb )
727 titlebarMouseWheelOperation( e->delta());
728}
729
730KCommonDecoration::Position KCommonDecoration::mousePosition(const TQPoint &point) const
731{
732 const int corner = 18+3*layoutMetric(LM_BorderBottom, false)/2;
733 Position pos = PositionCenter;
734
735 TQRect r = widget()->rect();
736 int r_x, r_y, r_x2, r_y2;
737 r.coords(&r_x, &r_y, &r_x2, &r_y2);
738 int p_x = point.x();
739 int p_y = point.y();
740 const int borderLeft = layoutMetric(LM_BorderLeft);
741// const int borderRight = layoutMetric(LM_BorderRight);
742 const int borderBottom = layoutMetric(LM_BorderBottom);
743 const int titleHeight = layoutMetric(LM_TitleHeight);
744 const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
745 const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
746 const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
747 const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
748
749 const int borderBottomTop = r_y2-borderBottom+1;
750 const int borderLeftRight = r_x+borderLeft-1;
751// const int borderRightLeft = r_x2-borderRight+1;
752 const int titleEdgeLeftRight = r_x+titleEdgeLeft-1;
753 const int titleEdgeRightLeft = r_x2-titleEdgeRight+1;
754 const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1;
755 const int titleEdgeTopBottom = r_y+titleEdgeTop-1;
756
757 if (p_y <= titleEdgeTopBottom) {
758 if (p_x <= r_x+corner)
759 pos = PositionTopLeft;
760 else if (p_x >= r_x2-corner)
761 pos = PositionTopRight;
762 else
763 pos = PositionTop;
764 } else if (p_y <= titleEdgeBottomBottom) {
765 if (p_x <= titleEdgeLeftRight)
766 pos = PositionTopLeft;
767 else if (p_x >= titleEdgeRightLeft)
768 pos = PositionTopRight;
769 else
770 pos = PositionCenter; // title bar
771 } else if (p_y < borderBottomTop) {
772 if (p_y < r_y2-corner) {
773 if (p_x <= borderLeftRight)
774 pos = PositionLeft;
775 else
776 pos = PositionRight;
777 } else {
778 if (p_x <= borderLeftRight)
779 pos = PositionBottomLeft;
780 else
781 pos = PositionBottomRight;
782 }
783 } else if(p_y >= borderBottomTop) {
784 if (p_x <= r_x+corner)
785 pos = PositionBottomLeft;
786 else if (p_x >= r_x2-corner)
787 pos = PositionBottomRight;
788 else
789 pos = PositionBottom;
790 }
791
792 return pos;
793}
794
795void KCommonDecoration::updateWindowShape()
796{
797 // don't mask the widget...
798 if (!decorationBehaviour(DB_WindowMask) )
799 return;
800
801 int w = widget()->width();
802 int h = widget()->height();
803
804 bool tl=true,tr=true,bl=true,br=true; // is there a transparent rounded corner in top-left? etc
805
806 TQDesktopWidget *desktop=TDEApplication::desktop();
807 // no transparent rounded corners if this window corner lines up with a screen corner
808 for(int screen=0; screen < desktop->numScreens(); ++screen)
809 {
810 TQRect fullscreen(desktop->screenGeometry(screen));
811 TQRect window = geometry();
812
813 if(window.topLeft() == fullscreen.topLeft() ) tl = false;
814 if(window.topRight() == fullscreen.topRight() ) tr = false;
815 if(window.bottomLeft() == fullscreen.bottomLeft() ) bl = false;
816 if(window.bottomRight()== fullscreen.bottomRight() ) br = false;
817 }
818
819 TQRegion mask(0, 0, w, h);
820
821 // Remove top-left corner.
822 if(tl)
823 {
824 mask -= cornerShape(WC_TopLeft);
825 }
826 // Remove top-right corner.
827 if(tr)
828 {
829 mask -= cornerShape(WC_TopRight);
830 }
831 // Remove top-left corner.
832 if(bl)
833 {
834 mask -= cornerShape(WC_BottomLeft);
835 }
836 // Remove top-right corner.
837 if(br)
838 {
839 mask -= cornerShape(WC_BottomRight);
840 }
841
842 setMask( mask );
843}
844
845bool KCommonDecoration::eventFilter( TQObject* o, TQEvent* e )
846{
847 if( o != widget())
848 return false;
849 switch( e->type())
850 {
851 case TQEvent::Resize:
852 resizeEvent(static_cast<TQResizeEvent*>(e) );
853 return true;
854 case TQEvent::Paint:
855 paintEvent(static_cast<TQPaintEvent*>( e ));
856 return true;
857 case TQEvent::MouseButtonDblClick:
858 mouseDoubleClickEvent(static_cast<TQMouseEvent*>( e ));
859 return true;
860 case TQEvent::MouseButtonPress:
861 processMousePressEvent(static_cast<TQMouseEvent*>( e ));
862 return true;
863 case TQEvent::Wheel:
864 wheelEvent(static_cast<TQWheelEvent*>( e ));
865 return true;
866 default:
867 return false;
868 }
869}
870
871const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
872 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
873 | NET::UtilityMask | NET::SplashMask;
874
875bool KCommonDecoration::isToolWindow() const
876{
877 NET::WindowType type = windowType( SUPPORTED_WINDOW_TYPES_MASK );
878 return ((type==NET::Toolbar)||(type==NET::Utility)||(type==NET::Menu));
879}
880
881TQRect KCommonDecoration::titleRect() const
882{
883 int r_x, r_y, r_x2, r_y2;
884 widget()->rect().coords(&r_x, &r_y, &r_x2, &r_y2);
885 const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
886 const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
887 const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
888 const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
889 const int titleBorderLeft = layoutMetric(LM_TitleBorderLeft);
890 const int titleBorderRight = layoutMetric(LM_TitleBorderRight);
891 const int ttlHeight = layoutMetric(LM_TitleHeight);
892 const int titleEdgeBottomBottom = r_y+titleEdgeTop+ttlHeight+titleEdgeBottom-1;
893 return TQRect(r_x+titleEdgeLeft+buttonsLeftWidth()+titleBorderLeft, r_y+titleEdgeTop,
894 r_x2-titleEdgeRight-buttonsRightWidth()-titleBorderRight-(r_x+titleEdgeLeft+buttonsLeftWidth()+titleBorderLeft),
895 titleEdgeBottomBottom-(r_y+titleEdgeTop) );
896}
897
898
899KCommonDecorationButton::KCommonDecorationButton(ButtonType type, KCommonDecoration *parent, const char *name)
900 : TQButton(parent->widget(), name),
901 m_decoration(parent),
902 m_type(type),
903 m_realizeButtons(TQt::LeftButton),
904 m_lastMouse(TQt::NoButton),
905 m_isLeft(true)
906{
907 setCursor(ArrowCursor);
908}
909
910KCommonDecorationButton::~KCommonDecorationButton()
911{
912}
913
914KCommonDecoration *KCommonDecorationButton::decoration() const
915{
916 return m_decoration;
917}
918
919ButtonType KCommonDecorationButton::type() const
920{
921 return m_type;
922}
923
924bool KCommonDecorationButton::isLeft() const
925{
926 return m_isLeft;
927}
928
929void KCommonDecorationButton::setLeft(bool left)
930{
931 m_isLeft = left;
932}
933
934void KCommonDecorationButton::setRealizeButtons(int btns)
935{
936 m_realizeButtons = btns;
937}
938
939void KCommonDecorationButton::setSize(const TQSize &s)
940{
941 if (!m_size.isValid() || s != size() ) {
942 m_size = s;
943
944 setFixedSize(m_size);
945 reset(SizeChange);
946 }
947}
948
949TQSize KCommonDecorationButton::sizeHint() const
950{
951 return m_size;
952}
953
954void KCommonDecorationButton::setTipText(const TQString &tip) {
955 TQToolTip::remove(this );
956 TQToolTip::add(this, tip );
957}
958
959void KCommonDecorationButton::setToggleButton(bool toggle)
960{
961 TQButton::setToggleButton(toggle);
962 reset(ToggleChange);
963}
964
965void KCommonDecorationButton::setOn(bool on)
966{
967 if (on != isOn() ) {
968 TQButton::setOn(on);
969 reset(StateChange);
970 }
971}
972
973void KCommonDecorationButton::mousePressEvent(TQMouseEvent* e)
974{
975 m_lastMouse = e->button();
976 // pass on event after changing button to LeftButton
977 TQMouseEvent me(e->type(), e->pos(), e->globalPos(),
978 (e->button()&m_realizeButtons)?TQt::LeftButton:TQt::NoButton, e->state());
979
980 TQButton::mousePressEvent(&me);
981}
982
983void KCommonDecorationButton::mouseReleaseEvent(TQMouseEvent* e)
984{
985 m_lastMouse = e->button();
986 // pass on event after changing button to LeftButton
987 TQMouseEvent me(e->type(), e->pos(), e->globalPos(),
988 (e->button()&m_realizeButtons)?TQt::LeftButton:TQt::NoButton, e->state());
989
990 TQButton::mouseReleaseEvent(&me);
991}
KCommonDecorationButton
Title bar buttons of KCommonDecoration need to inherit this class.
Definition: kcommondecoration.h:293
KCommonDecorationButton::reset
virtual void reset(unsigned long changed)=0
Initialize the button after size change etc.
KCommonDecorationButton::SizeChange
@ SizeChange
The button size changed.
Definition: kcommondecoration.h:309
KCommonDecorationButton::ManualReset
@ ManualReset
The button might want to do a full reset for some reason...
Definition: kcommondecoration.h:308
KCommonDecorationButton::ToggleChange
@ ToggleChange
The button toggle state has changed.
Definition: kcommondecoration.h:310
KCommonDecorationButton::IconChange
@ IconChange
The window icon has been changed.
Definition: kcommondecoration.h:312
KCommonDecorationButton::StateChange
@ StateChange
The button has been set pressed or not...
Definition: kcommondecoration.h:311
KCommonDecorationButton::setSize
void setSize(const TQSize &s)
Set the button size.
Definition: kcommondecoration.cpp:939
KCommonDecorationButton::setTipText
void setTipText(const TQString &tip)
Set/update the button's tool tip.
Definition: kcommondecoration.cpp:954
KCommonDecorationButton::type
ButtonType type() const
Definition: kcommondecoration.cpp:919
KCommonDecorationButton::decoration
KCommonDecoration * decoration() const
Definition: kcommondecoration.cpp:914
KCommonDecorationButton::setRealizeButtons
void setRealizeButtons(int btns)
Set which mouse buttons the button should honor.
Definition: kcommondecoration.cpp:934
KCommonDecorationButton::isLeft
bool isLeft() const
Whether the button is left of the titlebar or not.
Definition: kcommondecoration.cpp:924
KCommonDecoration
This class eases development of decorations by implementing parts of KDecoration which are error pron...
Definition: kcommondecoration.h:60
KCommonDecoration::borders
virtual void borders(int &left, int &right, int &top, int &bottom) const
This function should return the distance from each window side to the inner window.
Definition: kcommondecoration.cpp:150
KCommonDecoration::cornerShape
virtual TQRegion cornerShape(WindowCorner corner)
Definition: kcommondecoration.cpp:139
KCommonDecoration::maximizeChange
virtual void maximizeChange()
This function is called whenever the maximalization state of the window changes.
Definition: kcommondecoration.cpp:536
KCommonDecoration::defaultButtonsRight
virtual TQString defaultButtonsRight() const =0
The default title button order on the left.
KCommonDecoration::decorationBehaviour
virtual bool decorationBehaviour(DecorationBehaviour behaviour) const
This controls whether some specific behaviour should be enabled or not.
Definition: kcommondecoration.cpp:63
KCommonDecoration::createButton
virtual KCommonDecorationButton * createButton(ButtonType type)=0
Create a new title bar button.
KCommonDecoration::visibleName
virtual TQString visibleName() const =0
The name of the decoration used in the decoration preview.
KCommonDecoration::updateButtons
void updateButtons() const
Makes sure all buttons are repainted.
Definition: kcommondecoration.cpp:242
KCommonDecoration::minimumSize
virtual TQSize minimumSize() const
This function should return the minimum required size for the decoration.
Definition: kcommondecoration.cpp:525
KCommonDecoration::activeChange
virtual void activeChange()
This function is called whenever the window either becomes or stops being active.
Definition: kcommondecoration.cpp:581
KCommonDecoration::paintEvent
virtual void paintEvent(TQPaintEvent *e)=0
Draw the window decoration.
KCommonDecoration::DecorationBehaviour
DecorationBehaviour
Definition: kcommondecoration.h:121
KCommonDecoration::DB_ButtonHide
@ DB_ButtonHide
Hide buttons when there is not enough space in the titlebar.
Definition: kcommondecoration.h:124
KCommonDecoration::DB_WindowMask
@ DB_WindowMask
Set a mask on the window.
Definition: kcommondecoration.h:123
KCommonDecoration::DB_MenuClose
@ DB_MenuClose
Close window on double clicking the menu.
Definition: kcommondecoration.h:122
KCommonDecoration::init
virtual void init()
Handles widget and layout creation, call the base implementation when subclassing this member.
Definition: kcommondecoration.cpp:114
KCommonDecoration::defaultButtonsLeft
virtual TQString defaultButtonsLeft() const =0
The default title button order on the left.
KCommonDecoration::shadeChange
virtual void shadeChange()
This function is called whenever the window is shaded or unshaded.
Definition: kcommondecoration.cpp:560
KCommonDecoration::titleRect
TQRect titleRect() const
Convenience method.
Definition: kcommondecoration.cpp:881
KCommonDecoration::isToolWindow
bool isToolWindow() const
Convenience method.
Definition: kcommondecoration.cpp:875
KCommonDecoration::LayoutMetric
LayoutMetric
Used to calculate the decoration layout.
Definition: kcommondecoration.h:101
KCommonDecoration::iconChange
virtual void iconChange()
This function is called whenever the window icon changes.
Definition: kcommondecoration.cpp:572
KCommonDecoration::updateCaption
virtual void updateCaption()
This is used to update the painting of the title bar after the caption has been changed.
Definition: kcommondecoration.cpp:144
KCommonDecoration::updateWindowShape
virtual void updateWindowShape()
This updates the window mask using the information provided by cornerShape().
Definition: kcommondecoration.cpp:795
KCommonDecoration::captionChange
virtual void captionChange()
This function is called whenever the caption changes.
Definition: kcommondecoration.cpp:587
KCommonDecoration::reset
virtual void reset(unsigned long changed)
Handles SettingButtons, call the base implementation when subclassing this member.
Definition: kcommondecoration.cpp:131
KCommonDecoration::resize
virtual void resize(const TQSize &s)
This method is called by twin when the style should resize the decoration window.
Definition: kcommondecoration.cpp:520
KCommonDecoration::layoutMetric
virtual int layoutMetric(LayoutMetric lm, bool respectWindowState=true, const KCommonDecorationButton *button=0) const
This controls the layout of the decoration in various ways.
Definition: kcommondecoration.cpp:79
KCommonDecoration::updateLayout
void updateLayout() const
TODO: remove?
Definition: kcommondecoration.cpp:162
KCommonDecoration::desktopChange
virtual void desktopChange()
This function is called whenever the desktop for the window changes.
Definition: kcommondecoration.cpp:549
KCommonDecoration::resetButtons
void resetButtons() const
Manually call reset() on each button.
Definition: kcommondecoration.cpp:248
KCommonDecoration::mousePosition
virtual Position mousePosition(const TQPoint &point) const
This function should return mouse cursor position in the decoration.
Definition: kcommondecoration.cpp:730
KDecorationDefines::SettingButtons
@ SettingButtons
The button layout was changed.
Definition: kdecoration.h:132
KDecorationDefines::Position
Position
These values represent positions inside an area.
Definition: kdecoration.h:54
KDecorationDefines::MaximizeFull
@ MaximizeFull
Equal to MaximizeVertical | MaximizeHorizontal.
Definition: kdecoration.h:75
KDecoration
This is the base class for a decoration object.
Definition: kdecoration.h:315
KDecoration::processMousePressEvent
void processMousePressEvent(TQMouseEvent *e)
This function is the default handler for mouse events.
Definition: kdecoration.cpp:174
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::isMinimizable
bool isMinimizable() const
Returns true if the decorated window can be minimized by the user.
Definition: kdecoration.cpp:104
KDecoration::closeWindow
void closeWindow()
This function can be called by the decoration to request closing of the decorated window.
Definition: kdecoration.cpp:234
KDecoration::setShade
void setShade(bool set)
Shades or unshades the decorated window.
Definition: kdecoration.cpp:282
KDecoration::maximizeMode
MaximizeMode maximizeMode() const
Returns the current maximization mode of the decorated window.
Definition: kdecoration.cpp:99
KDecoration::keepAbove
bool keepAbove() const
Returns true if the decorated window should be kept above other windows.
Definition: kdecoration.cpp:139
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::isShadeable
bool isShadeable() const
Returns true if the decorated window can be shaded.
Definition: kdecoration.cpp:124
KDecoration::isSetShade
bool isSetShade() const
Returns true if the decorated window was set to be shaded.
Definition: kdecoration.cpp:134
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::geometry
TQRect geometry() const
Returns the geometry of the decoration.
Definition: kdecoration.cpp:209
KDecoration::windowId
WId windowId() const
Returns the handle of the window that is being decorated.
Definition: kdecoration.cpp:229
KDecoration::showContextHelp
void showContextHelp()
Start showing context help in the window (i.e.
Definition: kdecoration.cpp:254
KDecoration::isMaximizable
bool isMaximizable() const
Returns true if the decorated window can be maximized.
Definition: kdecoration.cpp:94
KDecoration::height
int height() const
Convenience function that returns the height of the decoration.
Definition: kdecoration.h:885
KDecoration::widget
TQWidget * widget()
Returns the main widget for the decoration.
Definition: kdecoration.h:860
KDecoration::setKeepAbove
void setKeepAbove(bool set)
Sets or reset keeping this window above others.
Definition: kdecoration.cpp:287
KDecoration::createMainWidget
void createMainWidget(TQt::WFlags flags=0)
Convenience functions that creates and sets a main widget as necessary.
Definition: kdecoration.cpp:60
KDecoration::factory
KDecorationFactory * factory() const
Returns the factory that created this decoration.
Definition: kdecoration.h:870
KDecoration::setKeepBelow
void setKeepBelow(bool set)
Sets or reset keeping this window below others.
Definition: kdecoration.cpp:292
KDecoration::minimize
void minimize()
Minimize the decorated window.
Definition: kdecoration.cpp:249
KDecoration::titlebarDblClickOperation
void titlebarDblClickOperation()
This function performs the operation configured as titlebar double click operation.
Definition: kdecoration.cpp:272
KDecoration::providesContextHelp
bool providesContextHelp() const
Return true if the decorated window can show context help (i.e.
Definition: kdecoration.cpp:109
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::isCloseable
bool isCloseable() const
Returns true if the decoration window can be closed by the user.
Definition: kdecoration.cpp:89
KDecoration::keepBelowChanged
void keepBelowChanged(bool)
This signal is emitted whenever the window's keep-below state changes.
KDecoration::keepAboveChanged
void keepAboveChanged(bool)
This signal is emitted whenever the window's keep-above state changes.
KDecoration::isOnAllDesktops
bool isOnAllDesktops() const
Convenience function that returns true if the window is on all virtual desktops.
Definition: kdecoration.h:875
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::titlebarMouseWheelOperation
void titlebarMouseWheelOperation(int delta)
This function performs the operation configured as titlebar wheel mouse operation.
Definition: kdecoration.cpp:277
KDecoration::toggleOnAllDesktops
void toggleOnAllDesktops()
This function toggles the on-all-desktops state of the decorated window.
Definition: kdecoration.cpp:264
KDecoration::windowType
NET::WindowType windowType(unsigned long supported_types) const
This function returns the window type of the decorated window.
Definition: kdecoration.cpp:159
KDecoration::width
int width() const
Convenience function that returns the width of the decoration.
Definition: kdecoration.h:880

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