~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/libkdecorations/kcommondecoration.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "kcommondecoration.h"
 
26
#include "kcommondecoration_p.h"
 
27
 
 
28
#include <QApplication>
 
29
#include <QCursor>
 
30
#include <QDateTime>
 
31
#include <QLabel>
 
32
 
 
33
#include <QWidget>
 
34
 
 
35
#include <kdebug.h>
 
36
 
 
37
#include <kapplication.h>
 
38
#include "kdecorationfactory.h"
 
39
#include <klocale.h>
 
40
 
 
41
#include <kephal/screens.h>
 
42
 
 
43
#include "kcommondecoration.moc"
 
44
 
 
45
/** @addtogroup kdecoration */
 
46
/** @{ */
 
47
 
 
48
KCommonDecoration::KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory)
 
49
    :   m_previewWidget(0),
 
50
        btnHideMinWidth(200),
 
51
        btnHideLastWidth(0),
 
52
        closing(false),
 
53
        wrapper(new KCommonDecorationWrapper(this, bridge, factory))
 
54
 
 
55
{
 
56
    // sizeof(...) is calculated at compile time
 
57
    memset(m_button, 0, sizeof(KCommonDecorationButton *) * NumButtons);
 
58
    connect(wrapper, SIGNAL(keepAboveChanged(bool)), this, SIGNAL(keepAboveChanged(bool)));
 
59
    connect(wrapper, SIGNAL(keepBelowChanged(bool)), this, SIGNAL(keepBelowChanged(bool)));
 
60
}
 
61
 
 
62
KCommonDecoration::~KCommonDecoration()
 
63
{
 
64
    for (int n = 0; n < NumButtons; n++) {
 
65
        if (m_button[n]) delete m_button[n];
 
66
    }
 
67
    delete m_previewWidget;
 
68
//    delete wrapper; - do not do this, this object is actually owned and deleted by the wrapper
 
69
}
 
70
 
 
71
QString KCommonDecoration::defaultButtonsLeft() const
 
72
{
 
73
    return KDecorationOptions::defaultTitleButtonsLeft();
 
74
}
 
75
 
 
76
QString KCommonDecoration::defaultButtonsRight() const
 
77
{
 
78
    return KDecorationOptions::defaultTitleButtonsRight();
 
79
}
 
80
 
 
81
bool KCommonDecoration::decorationBehaviour(DecorationBehaviour behaviour) const
 
82
{
 
83
    switch(behaviour) {
 
84
    case DB_MenuClose:
 
85
        return false;
 
86
 
 
87
    case DB_WindowMask:
 
88
        return false;
 
89
 
 
90
    case DB_ButtonHide:
 
91
        return true;
 
92
    }
 
93
 
 
94
    return false;
 
95
}
 
96
 
 
97
int KCommonDecoration::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *button) const
 
98
{
 
99
    switch(lm) {
 
100
    case LM_BorderLeft:
 
101
    case LM_BorderRight:
 
102
    case LM_BorderBottom:
 
103
    case LM_TitleEdgeTop:
 
104
    case LM_TitleEdgeBottom:
 
105
    case LM_TitleEdgeLeft:
 
106
    case LM_TitleEdgeRight:
 
107
    case LM_TitleBorderLeft:
 
108
    case LM_TitleBorderRight:
 
109
        return 5;
 
110
 
 
111
 
 
112
    case LM_ButtonWidth:
 
113
    case LM_ButtonHeight:
 
114
    case LM_TitleHeight:
 
115
        return 20;
 
116
 
 
117
    case LM_ButtonSpacing:
 
118
        return 5;
 
119
 
 
120
    case LM_ButtonMarginTop:
 
121
        return 0;
 
122
 
 
123
    case LM_ExplicitButtonSpacer:
 
124
        return layoutMetric(LM_ButtonWidth, respectWindowState, button) / 2; // half button width by default
 
125
 
 
126
    default:
 
127
        return 0;
 
128
    }
 
129
}
 
130
 
 
131
void KCommonDecoration::init()
 
132
{
 
133
    createMainWidget();
 
134
 
 
135
    // for flicker-free redraws
 
136
    widget()->setAttribute(Qt::WA_NoSystemBackground);
 
137
 
 
138
    widget()->installEventFilter(this);
 
139
 
 
140
    resetLayout();
 
141
 
 
142
    connect(this, SIGNAL(keepAboveChanged(bool)), SLOT(keepAboveChange(bool)));
 
143
    connect(this, SIGNAL(keepBelowChanged(bool)), SLOT(keepBelowChange(bool)));
 
144
 
 
145
    updateCaption();
 
146
}
 
147
 
 
148
void KCommonDecoration::reset(unsigned long changed)
 
149
{
 
150
    if (changed & SettingButtons) {
 
151
        resetLayout();
 
152
        widget()->update();
 
153
    }
 
154
}
 
155
 
 
156
QRegion KCommonDecoration::cornerShape(WindowCorner)
 
157
{
 
158
    return QRegion();
 
159
}
 
160
 
 
161
void KCommonDecoration::updateCaption()
 
162
{
 
163
    // This should be reimplemented in decorations for better efficiency
 
164
    widget()->update();
 
165
}
 
166
 
 
167
void KCommonDecoration::borders(int& left, int& right, int& top, int& bottom) const
 
168
{
 
169
    left = layoutMetric(LM_BorderLeft);
 
170
    right = layoutMetric(LM_BorderRight);
 
171
    bottom = layoutMetric(LM_BorderBottom);
 
172
    top = layoutMetric(LM_TitleHeight) +
 
173
          layoutMetric(LM_TitleEdgeTop) +
 
174
          layoutMetric(LM_TitleEdgeBottom);
 
175
 
 
176
    updateLayout(); // TODO!! don't call every time we are in ::borders
 
177
}
 
178
 
 
179
void KCommonDecoration::updateLayout() const
 
180
{
 
181
    const int paddingLeft   = layoutMetric(LM_OuterPaddingLeft);
 
182
    const int paddingTop    = layoutMetric(LM_OuterPaddingTop);
 
183
    const int paddingRight  = layoutMetric(LM_OuterPaddingRight);
 
184
    const int paddingBottom = layoutMetric(LM_OuterPaddingBottom);
 
185
 
 
186
    QRect r = widget()->rect().adjusted(paddingLeft, paddingTop, -paddingRight, -paddingBottom);
 
187
    int r_x, r_y, r_x2, r_y2;
 
188
    r.getCoords(&r_x, &r_y, &r_x2, &r_y2);
 
189
 
 
190
    // layout preview widget
 
191
    if (m_previewWidget) {
 
192
        const int borderLeft = layoutMetric(LM_BorderLeft);
 
193
        const int borderRight = layoutMetric(LM_BorderRight);
 
194
        const int borderBottom = layoutMetric(LM_BorderBottom);
 
195
        const int titleHeight = layoutMetric(LM_TitleHeight);
 
196
        const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
 
197
        const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
 
198
 
 
199
        int left = r_x + borderLeft;
 
200
        int top = r_y + titleEdgeTop + titleHeight + titleEdgeBottom;
 
201
        int width = r_x2 - borderRight - left + 1;
 
202
        int height = r_y2 - borderBottom - top + 1;
 
203
        m_previewWidget->setGeometry(left, top, width, height);
 
204
        moveWidget(left, top, m_previewWidget);
 
205
        resizeWidget(width, height, m_previewWidget);
 
206
    }
 
207
 
 
208
    // resize buttons...
 
209
    for (int n = 0; n < NumButtons; n++) {
 
210
        if (m_button[n]) {
 
211
            QSize newSize = QSize(layoutMetric(LM_ButtonWidth, true, m_button[n]),
 
212
                                  layoutMetric(LM_ButtonHeight, true, m_button[n]));
 
213
            if (newSize != m_button[n]->size())
 
214
                m_button[n]->setSize(newSize);
 
215
        }
 
216
    }
 
217
 
 
218
    // layout buttons
 
219
    int y = r_y + layoutMetric(LM_TitleEdgeTop) + layoutMetric(LM_ButtonMarginTop);
 
220
    if (m_buttonsLeft.count() > 0) {
 
221
        const int buttonSpacing = layoutMetric(LM_ButtonSpacing);
 
222
        int x = r_x + layoutMetric(LM_TitleEdgeLeft);
 
223
        for (ButtonContainer::const_iterator it = m_buttonsLeft.begin(); it != m_buttonsLeft.end(); ++it) {
 
224
            bool elementLayouted = false;
 
225
            if (*it) {
 
226
                if (!(*it)->isHidden()) {
 
227
                    moveWidget(x, y, *it);
 
228
                    x += layoutMetric(LM_ButtonWidth, true, qobject_cast<KCommonDecorationButton*>(*it));
 
229
                    elementLayouted = true;
 
230
                }
 
231
            } else {
 
232
                x += layoutMetric(LM_ExplicitButtonSpacer);
 
233
                elementLayouted = true;
 
234
            }
 
235
            if (elementLayouted && it != m_buttonsLeft.end())
 
236
                x += buttonSpacing;
 
237
        }
 
238
    }
 
239
 
 
240
    if (m_buttonsRight.count() > 0) {
 
241
        const int titleEdgeRightLeft = r_x2 - layoutMetric(LM_TitleEdgeRight) + 1;
 
242
 
 
243
        const int buttonSpacing = layoutMetric(LM_ButtonSpacing);
 
244
        int x = titleEdgeRightLeft - buttonContainerWidth(m_buttonsRight);
 
245
        for (ButtonContainer::const_iterator it = m_buttonsRight.begin(); it != m_buttonsRight.end(); ++it) {
 
246
            bool elementLayouted = false;
 
247
            if (*it) {
 
248
                if (!(*it)->isHidden()) {
 
249
                    moveWidget(x, y, *it);
 
250
                    x += layoutMetric(LM_ButtonWidth, true, qobject_cast<KCommonDecorationButton*>(*it));;
 
251
                    elementLayouted = true;
 
252
                }
 
253
            } else {
 
254
                x += layoutMetric(LM_ExplicitButtonSpacer);
 
255
                elementLayouted = true;
 
256
            }
 
257
            if (elementLayouted && it != m_buttonsRight.end())
 
258
                x += buttonSpacing;
 
259
        }
 
260
    }
 
261
}
 
262
 
 
263
void KCommonDecoration::updateButtons() const
 
264
{
 
265
    for (int n = 0; n < NumButtons; n++)
 
266
        if (m_button[n]) m_button[n]->update();
 
267
}
 
268
 
 
269
void KCommonDecoration::resetButtons() const
 
270
{
 
271
    for (int n = 0; n < NumButtons; n++)
 
272
        if (m_button[n]) m_button[n]->reset(KCommonDecorationButton::ManualReset);
 
273
}
 
274
 
 
275
void KCommonDecoration::resetLayout()
 
276
{
 
277
    for (int n = 0; n < NumButtons; n++) {
 
278
        if (m_button[n]) {
 
279
            delete m_button[n];
 
280
            m_button[n] = 0;
 
281
        }
 
282
    }
 
283
    m_buttonsLeft.clear();
 
284
    m_buttonsRight.clear();
 
285
 
 
286
    delete m_previewWidget;
 
287
    m_previewWidget = 0;
 
288
 
 
289
    // shown instead of the window contents in decoration previews
 
290
    if (isPreview()) {
 
291
        m_previewWidget = new QLabel(i18n("<center><b>%1</b></center>", visibleName()), widget());
 
292
        m_previewWidget->setAutoFillBackground(true);
 
293
        m_previewWidget->show();
 
294
 
 
295
        // fix double deletion, see buttonDestroyed()
 
296
        connect(m_previewWidget, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
297
    }
 
298
 
 
299
    addButtons(m_buttonsLeft,
 
300
               options()->customButtonPositions() ? options()->titleButtonsLeft() : defaultButtonsLeft(),
 
301
               true);
 
302
    addButtons(m_buttonsRight,
 
303
               options()->customButtonPositions() ? options()->titleButtonsRight() : defaultButtonsRight(),
 
304
               false);
 
305
 
 
306
    updateLayout();
 
307
 
 
308
    const int minTitleBarWidth = 35;
 
309
    btnHideMinWidth = buttonContainerWidth(m_buttonsLeft, true) + buttonContainerWidth(m_buttonsRight, true) +
 
310
                      layoutMetric(LM_TitleEdgeLeft, false) + layoutMetric(LM_TitleEdgeRight, false) +
 
311
                      layoutMetric(LM_TitleBorderLeft, false) + layoutMetric(LM_TitleBorderRight, false) +
 
312
                      minTitleBarWidth;
 
313
    btnHideLastWidth = 0;
 
314
}
 
315
 
 
316
void KCommonDecoration::objDestroyed(QObject *obj)
 
317
{
 
318
    // make sure button deletion is reflected in the m_button[] array.
 
319
    // this makes sure that m_button[]-entries are not destroyed
 
320
    // twice, first in their KCommonDecorationButton/QObject
 
321
    // destructor (button objects are parented with the decroation
 
322
    // widget in KCommonDecoration constructor), and then in
 
323
    // ~KCommonDecoration.  a QPointer<KCommonDecorationButton> would
 
324
    // have been the better approach, but changing the button array
 
325
    // would have been ABI incompatible & would have required creation
 
326
    // of kcommondecorationprivate instance.
 
327
    // the same applies to m_previewWidget.
 
328
    for (int n = 0; n < NumButtons; n++) {
 
329
        if (m_button[n] == obj) {
 
330
            m_button[n] = 0;
 
331
            break;
 
332
        }
 
333
    }
 
334
    if (obj == m_previewWidget)
 
335
        m_previewWidget = 0;
 
336
}
 
337
 
 
338
int KCommonDecoration::buttonsLeftWidth() const
 
339
{
 
340
    return buttonContainerWidth(m_buttonsLeft);
 
341
}
 
342
 
 
343
int KCommonDecoration::buttonsRightWidth() const
 
344
{
 
345
    return buttonContainerWidth(m_buttonsRight);
 
346
}
 
347
 
 
348
int KCommonDecoration::buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden) const
 
349
{
 
350
    int explicitSpacer = layoutMetric(LM_ExplicitButtonSpacer);
 
351
 
 
352
    int shownElementsCount = 0;
 
353
 
 
354
    int w = 0;
 
355
    for (ButtonContainer::const_iterator it = btnContainer.begin(); it != btnContainer.end(); ++it) {
 
356
        if (*it) {
 
357
            if (countHidden || !(*it)->isHidden()) {
 
358
                w += (*it)->width();
 
359
                ++shownElementsCount;
 
360
            }
 
361
        } else {
 
362
            w += explicitSpacer;
 
363
            ++shownElementsCount;
 
364
        }
 
365
    }
 
366
    w += layoutMetric(LM_ButtonSpacing) * (shownElementsCount - 1);
 
367
 
 
368
    return w;
 
369
}
 
370
 
 
371
void KCommonDecoration::addButtons(ButtonContainer &btnContainer, const QString& s, bool isLeft)
 
372
{
 
373
    if (s.length() > 0) {
 
374
        for (int n = 0; n < s.length(); n++) {
 
375
            KCommonDecorationButton *btn = 0;
 
376
            switch(s[n].toAscii()) {
 
377
            case 'M': // Menu button
 
378
                if (!m_button[MenuButton]) {
 
379
                    btn = createButton(MenuButton);
 
380
                    if (!btn) break;
 
381
                    btn->setTipText(i18n("Menu"));
 
382
                    btn->setRealizeButtons(Qt::LeftButton | Qt::RightButton);
 
383
                    connect(btn, SIGNAL(pressed()), SLOT(menuButtonPressed()));
 
384
                    connect(btn, SIGNAL(released()), this, SLOT(menuButtonReleased()));
 
385
 
 
386
                    // fix double deletion, see objDestroyed()
 
387
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
388
 
 
389
                    m_button[MenuButton] = btn;
 
390
                }
 
391
                break;
 
392
            case 'S': // OnAllDesktops button
 
393
                if (!m_button[OnAllDesktopsButton]) {
 
394
                    btn = createButton(OnAllDesktopsButton);
 
395
                    if (!btn) break;
 
396
                    const bool oad = isOnAllDesktops();
 
397
                    btn->setTipText(oad ? i18n("Not on all desktops") : i18n("On all desktops"));
 
398
                    btn->setToggleButton(true);
 
399
                    btn->setOn(oad);
 
400
                    connect(btn, SIGNAL(clicked()), SLOT(toggleOnAllDesktops()));
 
401
 
 
402
                    // fix double deletion, see objDestroyed()
 
403
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
404
 
 
405
                    m_button[OnAllDesktopsButton] = btn;
 
406
                }
 
407
                break;
 
408
            case 'H': // Help button
 
409
                if ((!m_button[HelpButton]) && providesContextHelp()) {
 
410
                    btn = createButton(HelpButton);
 
411
                    if (!btn) break;
 
412
                    btn->setTipText(i18n("Help"));
 
413
                    connect(btn, SIGNAL(clicked()), SLOT(showContextHelp()));
 
414
 
 
415
                    // fix double deletion, see objDestroyed()
 
416
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
417
 
 
418
                    m_button[HelpButton] = btn;
 
419
                }
 
420
                break;
 
421
            case 'I': // Minimize button
 
422
                if ((!m_button[MinButton]) && isMinimizable()) {
 
423
                    btn = createButton(MinButton);
 
424
                    if (!btn) break;
 
425
                    btn->setTipText(i18n("Minimize"));
 
426
                    connect(btn, SIGNAL(clicked()), SLOT(minimize()));
 
427
 
 
428
                    // fix double deletion, see objDestroyed()
 
429
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
430
 
 
431
                    m_button[MinButton] = btn;
 
432
                }
 
433
                break;
 
434
            case 'A': // Maximize button
 
435
                if ((!m_button[MaxButton]) && isMaximizable()) {
 
436
                    btn = createButton(MaxButton);
 
437
                    if (!btn) break;
 
438
                    btn->setRealizeButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton);
 
439
                    const bool max = maximizeMode() == MaximizeFull;
 
440
                    btn->setTipText(max ? i18n("Restore") : i18n("Maximize"));
 
441
                    btn->setToggleButton(true);
 
442
                    btn->setOn(max);
 
443
                    connect(btn, SIGNAL(clicked()), SLOT(slotMaximize()));
 
444
 
 
445
                    // fix double deletion, see objDestroyed()
 
446
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
447
 
 
448
                    m_button[MaxButton] = btn;
 
449
                }
 
450
                break;
 
451
            case 'X': // Close button
 
452
                if ((!m_button[CloseButton]) && isCloseable()) {
 
453
                    btn = createButton(CloseButton);
 
454
                    if (!btn) break;
 
455
                    btn->setTipText(i18n("Close"));
 
456
                    connect(btn, SIGNAL(clicked()), SLOT(closeWindow()));
 
457
 
 
458
                    // fix double deletion, see objDestroyed()
 
459
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
460
 
 
461
                    m_button[CloseButton] = btn;
 
462
                }
 
463
                break;
 
464
            case 'F': // AboveButton button
 
465
                if (!m_button[AboveButton]) {
 
466
                    btn = createButton(AboveButton);
 
467
                    if (!btn) break;
 
468
                    bool above = keepAbove();
 
469
                    btn->setTipText(above ? i18n("Do not keep above others") : i18n("Keep above others"));
 
470
                    btn->setToggleButton(true);
 
471
                    btn->setOn(above);
 
472
                    connect(btn, SIGNAL(clicked()), SLOT(slotKeepAbove()));
 
473
 
 
474
                    // fix double deletion, see objDestroyed()
 
475
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
476
 
 
477
                    m_button[AboveButton] = btn;
 
478
                }
 
479
                break;
 
480
            case 'B': // BelowButton button
 
481
                if (!m_button[BelowButton]) {
 
482
                    btn = createButton(BelowButton);
 
483
                    if (!btn) break;
 
484
                    bool below = keepBelow();
 
485
                    btn->setTipText(below ? i18n("Do not keep below others") : i18n("Keep below others"));
 
486
                    btn->setToggleButton(true);
 
487
                    btn->setOn(below);
 
488
                    connect(btn, SIGNAL(clicked()), SLOT(slotKeepBelow()));
 
489
 
 
490
                    // fix double deletion, see objDestroyed()
 
491
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
492
 
 
493
                    m_button[BelowButton] = btn;
 
494
                }
 
495
                break;
 
496
            case 'L': // Shade button
 
497
                if ((!m_button[ShadeButton]) && isShadeable()) {
 
498
                    btn = createButton(ShadeButton);
 
499
                    if (!btn) break;
 
500
                    bool shaded = isSetShade();
 
501
                    btn->setTipText(shaded ? i18n("Unshade") : i18n("Shade"));
 
502
                    btn->setToggleButton(true);
 
503
                    btn->setOn(shaded);
 
504
                    connect(btn, SIGNAL(clicked()), SLOT(slotShade()));
 
505
 
 
506
                    // fix double deletion, see objDestroyed()
 
507
                    connect(btn, SIGNAL(destroyed(QObject*)), this, SLOT(objDestroyed(QObject*)));
 
508
 
 
509
                    m_button[ShadeButton] = btn;
 
510
                }
 
511
                break;
 
512
            case '_': // Spacer item
 
513
                btnContainer.append(0);
 
514
            }
 
515
 
 
516
 
 
517
            if (btn) {
 
518
                btn->setLeft(isLeft);
 
519
                btn->setSize(QSize(layoutMetric(LM_ButtonWidth, true, btn), layoutMetric(LM_ButtonHeight, true, btn)));
 
520
                btn->show();
 
521
                btnContainer.append(btn);
 
522
            }
 
523
 
 
524
        }
 
525
    }
 
526
}
 
527
 
 
528
void KCommonDecoration::calcHiddenButtons()
 
529
{
 
530
    if (width() == btnHideLastWidth)
 
531
        return;
 
532
 
 
533
    btnHideLastWidth = width();
 
534
 
 
535
    //Hide buttons in the following order:
 
536
    KCommonDecorationButton* btnArray[] = { m_button[HelpButton], m_button[ShadeButton], m_button[BelowButton],
 
537
                                            m_button[AboveButton], m_button[OnAllDesktopsButton], m_button[MaxButton],
 
538
                                            m_button[MinButton], m_button[MenuButton], m_button[CloseButton]
 
539
                                          };
 
540
    const int buttonsCount = sizeof(btnArray) / sizeof(btnArray[ 0 ]);
 
541
 
 
542
    int current_width = width();
 
543
    int count = 0;
 
544
 
 
545
    // Hide buttons
 
546
    while (current_width < btnHideMinWidth && count < buttonsCount) {
 
547
        if (btnArray[count]) {
 
548
            current_width += btnArray[count]->width();
 
549
            if (btnArray[count]->isVisible())
 
550
                btnArray[count]->hide();
 
551
        }
 
552
        count++;
 
553
    }
 
554
    // Show the rest of the buttons...
 
555
    for (int i = count; i < buttonsCount; i++) {
 
556
        if (btnArray[i]) {
 
557
 
 
558
            if (! btnArray[i]->isHidden())
 
559
                break; // all buttons shown...
 
560
 
 
561
            btnArray[i]->show();
 
562
        }
 
563
    }
 
564
}
 
565
 
 
566
void KCommonDecoration::show()
 
567
{
 
568
    if (decorationBehaviour(DB_ButtonHide))
 
569
        calcHiddenButtons();
 
570
    widget()->show();
 
571
}
 
572
 
 
573
void KCommonDecoration::resize(const QSize& s)
 
574
{
 
575
    widget()->resize(s);
 
576
}
 
577
 
 
578
QSize KCommonDecoration::minimumSize() const
 
579
{
 
580
    const int minWidth = qMax(layoutMetric(LM_TitleEdgeLeft), layoutMetric(LM_BorderLeft))
 
581
                         + qMax(layoutMetric(LM_TitleEdgeRight), layoutMetric(LM_BorderRight))
 
582
                         + layoutMetric(LM_TitleBorderLeft) + layoutMetric(LM_TitleBorderRight);
 
583
    return QSize(minWidth,
 
584
                 layoutMetric(LM_TitleEdgeTop) + layoutMetric(LM_TitleHeight)
 
585
                 + layoutMetric(LM_TitleEdgeBottom)
 
586
                 + layoutMetric(LM_BorderBottom));
 
587
}
 
588
 
 
589
void KCommonDecoration::maximizeChange()
 
590
{
 
591
    if (m_button[MaxButton]) {
 
592
        m_button[MaxButton]->setOn(maximizeMode() == MaximizeFull);
 
593
        m_button[MaxButton]->setTipText((maximizeMode() != MaximizeFull) ?
 
594
                                        i18n("Maximize")
 
595
                                        : i18n("Restore"));
 
596
        m_button[MaxButton]->reset(KCommonDecorationButton::StateChange);
 
597
    }
 
598
    updateWindowShape();
 
599
    widget()->update();
 
600
}
 
601
 
 
602
void KCommonDecoration::desktopChange()
 
603
{
 
604
    if (m_button[OnAllDesktopsButton]) {
 
605
        m_button[OnAllDesktopsButton]->setOn(isOnAllDesktops());
 
606
        m_button[OnAllDesktopsButton]->setTipText(isOnAllDesktops() ?
 
607
                i18n("Not on all desktops")
 
608
                : i18n("On all desktops"));
 
609
        m_button[OnAllDesktopsButton]->reset(KCommonDecorationButton::StateChange);
 
610
    }
 
611
}
 
612
 
 
613
void KCommonDecoration::shadeChange()
 
614
{
 
615
    if (m_button[ShadeButton]) {
 
616
        bool shaded = isSetShade();
 
617
        m_button[ShadeButton]->setOn(shaded);
 
618
        m_button[ShadeButton]->setTipText(shaded ?
 
619
                                          i18n("Unshade")
 
620
                                          : i18n("Shade"));
 
621
        m_button[ShadeButton]->reset(KCommonDecorationButton::StateChange);
 
622
    }
 
623
}
 
624
 
 
625
void KCommonDecoration::iconChange()
 
626
{
 
627
    if (m_button[MenuButton]) {
 
628
        m_button[MenuButton]->update();
 
629
        m_button[MenuButton]->reset(KCommonDecorationButton::IconChange);
 
630
    }
 
631
}
 
632
 
 
633
void KCommonDecoration::activeChange()
 
634
{
 
635
    updateButtons();
 
636
    widget()->update(); // do something similar to updateCaption here
 
637
}
 
638
 
 
639
void KCommonDecoration::captionChange()
 
640
{
 
641
    updateCaption();
 
642
}
 
643
 
 
644
void KCommonDecoration::keepAboveChange(bool above)
 
645
{
 
646
    if (m_button[AboveButton]) {
 
647
        m_button[AboveButton]->setOn(above);
 
648
        m_button[AboveButton]->setTipText(above ? i18n("Do not keep above others") : i18n("Keep above others"));
 
649
        m_button[AboveButton]->reset(KCommonDecorationButton::StateChange);
 
650
    }
 
651
 
 
652
    if (m_button[BelowButton] && m_button[BelowButton]->isChecked()) {
 
653
        m_button[BelowButton]->setOn(false);
 
654
        m_button[BelowButton]->setTipText(i18n("Keep below others"));
 
655
        m_button[BelowButton]->reset(KCommonDecorationButton::StateChange);
 
656
    }
 
657
}
 
658
 
 
659
void KCommonDecoration::keepBelowChange(bool below)
 
660
{
 
661
    if (m_button[BelowButton]) {
 
662
        m_button[BelowButton]->setOn(below);
 
663
        m_button[BelowButton]->setTipText(below ? i18n("Do not keep below others") : i18n("Keep below others"));
 
664
        m_button[BelowButton]->reset(KCommonDecorationButton::StateChange);
 
665
    }
 
666
 
 
667
    if (m_button[AboveButton] && m_button[AboveButton]->isChecked()) {
 
668
        m_button[AboveButton]->setOn(false);
 
669
        m_button[AboveButton]->setTipText(i18n("Keep above others"));
 
670
        m_button[AboveButton]->reset(KCommonDecorationButton::StateChange);
 
671
    }
 
672
}
 
673
 
 
674
void KCommonDecoration::slotMaximize()
 
675
{
 
676
    if (m_button[MaxButton]) {
 
677
        maximize(m_button[MaxButton]->lastMousePress());
 
678
    }
 
679
}
 
680
 
 
681
void KCommonDecoration::slotShade()
 
682
{
 
683
    setShade(!isSetShade());
 
684
}
 
685
 
 
686
void KCommonDecoration::slotKeepAbove()
 
687
{
 
688
    setKeepAbove(!keepAbove());
 
689
}
 
690
 
 
691
void KCommonDecoration::slotKeepBelow()
 
692
{
 
693
    setKeepBelow(!keepBelow());
 
694
}
 
695
 
 
696
void KCommonDecoration::menuButtonPressed()
 
697
{
 
698
    static QTime* t = NULL;
 
699
    static KCommonDecoration* lastClient = NULL;
 
700
    if (t == NULL)
 
701
        t = new QTime;
 
702
    bool dbl = (lastClient == this && t->elapsed() <= QApplication::doubleClickInterval());
 
703
    lastClient = this;
 
704
    t->start();
 
705
    if (!dbl || !decorationBehaviour(DB_MenuClose)) {
 
706
        QRect menuRect = m_button[MenuButton]->rect();
 
707
        QPoint menutop = m_button[MenuButton]->mapToGlobal(menuRect.topLeft());
 
708
        QPoint menubottom = m_button[MenuButton]->mapToGlobal(menuRect.bottomRight()) + QPoint(0, 2);
 
709
        KDecorationFactory* f = factory();
 
710
        showWindowMenu(QRect(menutop, menubottom));
 
711
        if (!f->exists(decoration()))   // 'this' was deleted
 
712
            return;
 
713
        m_button[MenuButton]->setDown(false);
 
714
    } else
 
715
        closing = true;
 
716
}
 
717
 
 
718
void KCommonDecoration::menuButtonReleased()
 
719
{
 
720
    if (closing)
 
721
        closeWindow();
 
722
}
 
723
 
 
724
void KCommonDecoration::resizeEvent(QResizeEvent */*e*/)
 
725
{
 
726
    if (decorationBehaviour(DB_ButtonHide))
 
727
        calcHiddenButtons();
 
728
 
 
729
    updateLayout();
 
730
 
 
731
    updateWindowShape();
 
732
    // FIXME: don't update() here! this would result in two paintEvent()s
 
733
    // because there is already "something" else triggering the repaint...
 
734
//     widget()->update();
 
735
}
 
736
 
 
737
void KCommonDecoration::moveWidget(int x, int y, QWidget *widget) const
 
738
{
 
739
    QPoint p = widget->pos();
 
740
    int oldX = p.y();
 
741
    int oldY = p.x();
 
742
 
 
743
    if (x != oldX || y != oldY)
 
744
        widget->move(x, y);
 
745
}
 
746
 
 
747
void KCommonDecoration::resizeWidget(int w, int h, QWidget *widget) const
 
748
{
 
749
    QSize s = widget->size();
 
750
    int oldW = s.width();
 
751
    int oldH = s.height();
 
752
 
 
753
    if (w != oldW || h != oldH)
 
754
        widget->resize(w, h);
 
755
}
 
756
 
 
757
void KCommonDecoration::mouseDoubleClickEvent(QMouseEvent *e)
 
758
{
 
759
    if (e->button() != Qt::LeftButton)
 
760
        return;
 
761
 
 
762
    int tb = layoutMetric(LM_TitleEdgeTop) + layoutMetric(LM_TitleHeight) +
 
763
             layoutMetric(LM_TitleEdgeBottom) + layoutMetric(LM_OuterPaddingTop);
 
764
    // when shaded, react on double clicks everywhere to make it easier to unshade. otherwise
 
765
    // react only on double clicks in the title bar region...
 
766
    if (isSetShade() || e->pos().y() <= tb)
 
767
        titlebarDblClickOperation();
 
768
}
 
769
 
 
770
void KCommonDecoration::wheelEvent(QWheelEvent *e)
 
771
{
 
772
    int tb = layoutMetric(LM_TitleEdgeTop) + layoutMetric(LM_TitleHeight) +
 
773
             layoutMetric(LM_TitleEdgeBottom) + layoutMetric(LM_OuterPaddingTop);
 
774
    if (isSetShade() || e->pos().y() <= tb)
 
775
        titlebarMouseWheelOperation(e->delta());
 
776
}
 
777
 
 
778
KCommonDecoration::Position KCommonDecoration::mousePosition(const QPoint &point) const
 
779
{
 
780
    const int corner = 18 + 3 * layoutMetric(LM_BorderBottom, false) / 2;
 
781
    Position pos = PositionCenter;
 
782
 
 
783
    const int paddingLeft   = layoutMetric(LM_OuterPaddingLeft);
 
784
    const int paddingTop    = layoutMetric(LM_OuterPaddingTop);
 
785
    const int paddingRight  = layoutMetric(LM_OuterPaddingRight);
 
786
    const int paddingBottom = layoutMetric(LM_OuterPaddingBottom);
 
787
 
 
788
    QRect r = widget()->rect().adjusted(paddingLeft, paddingTop, -paddingRight, -paddingBottom);
 
789
    int r_x, r_y, r_x2, r_y2;
 
790
    r.getCoords(&r_x, &r_y, &r_x2, &r_y2);
 
791
    int p_x = point.x();
 
792
    int p_y = point.y();
 
793
    const int borderLeft = layoutMetric(LM_BorderLeft);
 
794
//     const int borderRight = layoutMetric(LM_BorderRight);
 
795
    const int borderBottom = layoutMetric(LM_BorderBottom);
 
796
    const int titleHeight = layoutMetric(LM_TitleHeight);
 
797
    const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
 
798
    const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
 
799
    const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
 
800
    const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
 
801
 
 
802
    const int borderBottomTop = r_y2 - borderBottom + 1;
 
803
    const int borderLeftRight = r_x + borderLeft - 1;
 
804
//     const int borderRightLeft = r_x2-borderRight+1;
 
805
    const int titleEdgeLeftRight = r_x + titleEdgeLeft - 1;
 
806
    const int titleEdgeRightLeft = r_x2 - titleEdgeRight + 1;
 
807
    const int titleEdgeBottomBottom = r_y + titleEdgeTop + titleHeight + titleEdgeBottom - 1;
 
808
    const int titleEdgeTopBottom = r_y + titleEdgeTop - 1;
 
809
 
 
810
    if (p_y <= titleEdgeTopBottom) {
 
811
        if (p_x <= r_x + corner)
 
812
            pos = PositionTopLeft;
 
813
        else if (p_x >= r_x2 - corner)
 
814
            pos = PositionTopRight;
 
815
        else
 
816
            pos = PositionTop;
 
817
    } else if (p_y <= titleEdgeBottomBottom) {
 
818
        if (p_x <= titleEdgeLeftRight)
 
819
            pos = PositionTopLeft;
 
820
        else if (p_x >= titleEdgeRightLeft)
 
821
            pos = PositionTopRight;
 
822
        else
 
823
            pos = PositionCenter; // title bar
 
824
    } else if (p_y < borderBottomTop) {
 
825
        if (p_y < r_y2 - corner) {
 
826
            if (p_x <= borderLeftRight)
 
827
                pos = PositionLeft;
 
828
            else
 
829
                pos = PositionRight;
 
830
        } else {
 
831
            if (p_x <= borderLeftRight)
 
832
                pos = PositionBottomLeft;
 
833
            else
 
834
                pos = PositionBottomRight;
 
835
        }
 
836
    } else if (p_y >= borderBottomTop) {
 
837
        if (p_x <= r_x + corner)
 
838
            pos = PositionBottomLeft;
 
839
        else if (p_x >= r_x2 - corner)
 
840
            pos = PositionBottomRight;
 
841
        else
 
842
            pos = PositionBottom;
 
843
    }
 
844
 
 
845
    return pos;
 
846
}
 
847
 
 
848
void KCommonDecoration::updateWindowShape()
 
849
{
 
850
    // don't mask the widget...
 
851
    if (!decorationBehaviour(DB_WindowMask))
 
852
        return;
 
853
 
 
854
    int w = widget()->width();
 
855
    int h = widget()->height();
 
856
 
 
857
    QRegion mask(0, 0, w, h);
 
858
 
 
859
    // Remove corners (if subclass wants to.)
 
860
    mask -= cornerShape(WC_TopLeft);
 
861
    mask -= cornerShape(WC_TopRight);
 
862
    mask -= cornerShape(WC_BottomLeft);
 
863
    mask -= cornerShape(WC_BottomRight);
 
864
 
 
865
    setMask(mask);
 
866
}
 
867
 
 
868
bool KCommonDecoration::eventFilter(QObject* o, QEvent* e)
 
869
{
 
870
    if (o != widget())
 
871
        return false;
 
872
    switch(e->type()) {
 
873
    case QEvent::Resize:
 
874
        resizeEvent(static_cast<QResizeEvent*>(e));
 
875
        return true;
 
876
    case QEvent::Paint:
 
877
        paintEvent(static_cast< QPaintEvent* >(e));
 
878
        return true;
 
879
    case QEvent::MouseButtonDblClick:
 
880
        mouseDoubleClickEvent(static_cast< QMouseEvent* >(e));
 
881
        return true;
 
882
    case QEvent::MouseButtonPress:
 
883
        processMousePressEvent(static_cast< QMouseEvent* >(e));
 
884
        return true;
 
885
    case QEvent::Wheel:
 
886
        wheelEvent(static_cast< QWheelEvent* >(e));
 
887
        return true;
 
888
    default:
 
889
        return false;
 
890
    }
 
891
}
 
892
 
 
893
const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
 
894
                                        | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
 
895
                                        | NET::UtilityMask | NET::SplashMask;
 
896
 
 
897
bool KCommonDecoration::isToolWindow() const
 
898
{
 
899
    NET::WindowType type = windowType(SUPPORTED_WINDOW_TYPES_MASK);
 
900
    return ((type == NET::Toolbar) || (type == NET::Utility) || (type == NET::Menu));
 
901
}
 
902
 
 
903
QRect KCommonDecoration::titleRect() const
 
904
{
 
905
    const int pl = layoutMetric(LM_OuterPaddingLeft);
 
906
    const int pt = layoutMetric(LM_OuterPaddingTop);
 
907
    const int pr = layoutMetric(LM_OuterPaddingRight);
 
908
    const int pb = layoutMetric(LM_OuterPaddingBottom);
 
909
 
 
910
    int r_x, r_y, r_x2, r_y2;
 
911
    widget()->rect().adjusted(pl, pt, -pr, -pb).getCoords(&r_x, &r_y, &r_x2, &r_y2);
 
912
 
 
913
    const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
 
914
    const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
 
915
    const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);
 
916
    const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
 
917
    const int titleBorderLeft = layoutMetric(LM_TitleBorderLeft);
 
918
    const int titleBorderRight = layoutMetric(LM_TitleBorderRight);
 
919
    const int ttlHeight = layoutMetric(LM_TitleHeight);
 
920
    const int titleEdgeBottomBottom = r_y + titleEdgeTop + ttlHeight + titleEdgeBottom - 1;
 
921
    return QRect(r_x + titleEdgeLeft + buttonsLeftWidth() + titleBorderLeft, r_y + titleEdgeTop,
 
922
                 r_x2 - titleEdgeRight - buttonsRightWidth() - titleBorderRight - (r_x + titleEdgeLeft + buttonsLeftWidth() + titleBorderLeft),
 
923
                 titleEdgeBottomBottom - (r_y + titleEdgeTop));
 
924
}
 
925
 
 
926
QRect KCommonDecoration::transparentRect() const
 
927
{
 
928
    return wrapper->transparentRect();
 
929
}
 
930
 
 
931
KCommonDecorationButton::KCommonDecorationButton(ButtonType type, KCommonDecoration *parent)
 
932
    : QAbstractButton(parent ? parent->widget() : 0),
 
933
      m_decoration(parent),
 
934
      m_type(type),
 
935
      m_realizeButtons(Qt::LeftButton),
 
936
      m_lastMouse(Qt::NoButton),
 
937
      m_isLeft(true)
 
938
{
 
939
    setCursor(Qt::ArrowCursor);
 
940
}
 
941
 
 
942
KCommonDecorationButton::~KCommonDecorationButton()
 
943
{
 
944
}
 
945
 
 
946
KCommonDecoration *KCommonDecorationButton::decoration() const
 
947
{
 
948
    return m_decoration;
 
949
}
 
950
 
 
951
ButtonType KCommonDecorationButton::type() const
 
952
{
 
953
    return m_type;
 
954
}
 
955
 
 
956
bool KCommonDecorationButton::isLeft() const
 
957
{
 
958
    return m_isLeft;
 
959
}
 
960
 
 
961
void KCommonDecorationButton::setLeft(bool left)
 
962
{
 
963
    m_isLeft = left;
 
964
}
 
965
 
 
966
void KCommonDecorationButton::setRealizeButtons(int btns)
 
967
{
 
968
    m_realizeButtons = btns;
 
969
}
 
970
 
 
971
void KCommonDecorationButton::setSize(const QSize &s)
 
972
{
 
973
    if (!m_size.isValid() || s != size()) {
 
974
        m_size = s;
 
975
 
 
976
        setFixedSize(m_size);
 
977
        reset(SizeChange);
 
978
    }
 
979
}
 
980
 
 
981
QSize KCommonDecorationButton::sizeHint() const
 
982
{
 
983
    return m_size;
 
984
}
 
985
 
 
986
void KCommonDecorationButton::setTipText(const QString &tip)
 
987
{
 
988
    this->setToolTip(tip);
 
989
}
 
990
 
 
991
void KCommonDecorationButton::setToggleButton(bool toggle)
 
992
{
 
993
    QAbstractButton::setCheckable(toggle);
 
994
    reset(ToggleChange);
 
995
}
 
996
 
 
997
void KCommonDecorationButton::setOn(bool on)
 
998
{
 
999
    if (on != isChecked()) {
 
1000
        QAbstractButton::setChecked(on);
 
1001
        reset(StateChange);
 
1002
    }
 
1003
}
 
1004
 
 
1005
void KCommonDecorationButton::mousePressEvent(QMouseEvent* e)
 
1006
{
 
1007
    m_lastMouse = e->button();
 
1008
    // pass on event after changing button to LeftButton
 
1009
    QMouseEvent me(e->type(), e->pos(), (e->button()&m_realizeButtons) ? Qt::LeftButton : Qt::NoButton, e->buttons(), e->modifiers());
 
1010
 
 
1011
    QAbstractButton::mousePressEvent(&me);
 
1012
}
 
1013
 
 
1014
void KCommonDecorationButton::mouseReleaseEvent(QMouseEvent* e)
 
1015
{
 
1016
    m_lastMouse = e->button();
 
1017
    // pass on event after changing button to LeftButton
 
1018
    QMouseEvent me(e->type(), e->pos(), (e->button()&m_realizeButtons) ? Qt::LeftButton : Qt::NoButton, e->buttons(), e->modifiers());
 
1019
 
 
1020
    QAbstractButton::mouseReleaseEvent(&me);
 
1021
}
 
1022
 
 
1023
 
 
1024
 
 
1025
// *** wrap everything from KDecoration *** //
 
1026
bool KCommonDecoration::drawbound(const QRect&, bool)
 
1027
{
 
1028
    return false;
 
1029
}
 
1030
bool KCommonDecoration::windowDocked(Position)
 
1031
{
 
1032
    return false;
 
1033
}
 
1034
const KDecorationOptions* KCommonDecoration::options()
 
1035
{
 
1036
    return KDecoration::options();
 
1037
}
 
1038
bool KCommonDecoration::isActive() const
 
1039
{
 
1040
    return wrapper->isActive();
 
1041
}
 
1042
bool KCommonDecoration::isCloseable() const
 
1043
{
 
1044
    return wrapper->isCloseable();
 
1045
}
 
1046
bool KCommonDecoration::isMaximizable() const
 
1047
{
 
1048
    return wrapper->isMaximizable();
 
1049
}
 
1050
KCommonDecoration::MaximizeMode KCommonDecoration::maximizeMode() const
 
1051
{
 
1052
    return wrapper->maximizeMode();
 
1053
}
 
1054
bool KCommonDecoration::isMinimizable() const
 
1055
{
 
1056
    return wrapper->isMinimizable();
 
1057
}
 
1058
bool KCommonDecoration::providesContextHelp() const
 
1059
{
 
1060
    return wrapper->providesContextHelp();
 
1061
}
 
1062
int KCommonDecoration::desktop() const
 
1063
{
 
1064
    return wrapper->desktop();
 
1065
}
 
1066
bool KCommonDecoration::isOnAllDesktops() const
 
1067
{
 
1068
    return wrapper->isOnAllDesktops();
 
1069
}
 
1070
bool KCommonDecoration::isModal() const
 
1071
{
 
1072
    return wrapper->isModal();
 
1073
}
 
1074
bool KCommonDecoration::isShadeable() const
 
1075
{
 
1076
    return wrapper->isShadeable();
 
1077
}
 
1078
bool KCommonDecoration::isShade() const
 
1079
{
 
1080
    return wrapper->isShade();
 
1081
}
 
1082
bool KCommonDecoration::isSetShade() const
 
1083
{
 
1084
    return wrapper->isSetShade();
 
1085
}
 
1086
bool KCommonDecoration::keepAbove() const
 
1087
{
 
1088
    return wrapper->keepAbove();
 
1089
}
 
1090
bool KCommonDecoration::keepBelow() const
 
1091
{
 
1092
    return wrapper->keepBelow();
 
1093
}
 
1094
bool KCommonDecoration::isMovable() const
 
1095
{
 
1096
    return wrapper->isMovable();
 
1097
}
 
1098
bool KCommonDecoration::isResizable() const
 
1099
{
 
1100
    return wrapper->isResizable();
 
1101
}
 
1102
NET::WindowType KCommonDecoration::windowType(unsigned long supported_types) const
 
1103
{
 
1104
    return wrapper->windowType(supported_types);
 
1105
}
 
1106
QIcon KCommonDecoration::icon() const
 
1107
{
 
1108
    return wrapper->icon();
 
1109
}
 
1110
QString KCommonDecoration::caption() const
 
1111
{
 
1112
    return wrapper->caption();
 
1113
}
 
1114
void KCommonDecoration::showWindowMenu(const QRect &pos)
 
1115
{
 
1116
    return wrapper->showWindowMenu(pos);
 
1117
}
 
1118
void KCommonDecoration::showWindowMenu(QPoint pos)
 
1119
{
 
1120
    return wrapper->showWindowMenu(pos);
 
1121
}
 
1122
void KCommonDecoration::performWindowOperation(WindowOperation op)
 
1123
{
 
1124
    return wrapper->performWindowOperation(op);
 
1125
}
 
1126
void KCommonDecoration::setMask(const QRegion& reg, int mode)
 
1127
{
 
1128
    return wrapper->setMask(reg, mode);
 
1129
}
 
1130
void KCommonDecoration::clearMask()
 
1131
{
 
1132
    return wrapper->clearMask();
 
1133
}
 
1134
bool KCommonDecoration::isPreview() const
 
1135
{
 
1136
    return wrapper->isPreview();
 
1137
}
 
1138
QRect KCommonDecoration::geometry() const
 
1139
{
 
1140
    return wrapper->geometry();
 
1141
}
 
1142
QRect KCommonDecoration::iconGeometry() const
 
1143
{
 
1144
    return wrapper->iconGeometry();
 
1145
}
 
1146
QRegion KCommonDecoration::unobscuredRegion(const QRegion& r) const
 
1147
{
 
1148
    return wrapper->unobscuredRegion(r);
 
1149
}
 
1150
WId KCommonDecoration::windowId() const
 
1151
{
 
1152
    return wrapper->windowId();
 
1153
}
 
1154
int KCommonDecoration::width() const
 
1155
{
 
1156
    return wrapper->width();
 
1157
}
 
1158
int KCommonDecoration::height() const
 
1159
{
 
1160
    return wrapper->height();
 
1161
}
 
1162
void KCommonDecoration::processMousePressEvent(QMouseEvent* e)
 
1163
{
 
1164
    return wrapper->processMousePressEvent(e);
 
1165
}
 
1166
void KCommonDecoration::setMainWidget(QWidget* w)
 
1167
{
 
1168
    return wrapper->setMainWidget(w);
 
1169
}
 
1170
void KCommonDecoration::createMainWidget(Qt::WFlags flags)
 
1171
{
 
1172
    return wrapper->createMainWidget(flags);
 
1173
}
 
1174
QWidget* KCommonDecoration::initialParentWidget() const
 
1175
{
 
1176
    return wrapper->initialParentWidget();
 
1177
}
 
1178
Qt::WFlags KCommonDecoration::initialWFlags() const
 
1179
{
 
1180
    return wrapper->initialWFlags();
 
1181
}
 
1182
QWidget* KCommonDecoration::widget()
 
1183
{
 
1184
    return wrapper->widget();
 
1185
}
 
1186
const QWidget* KCommonDecoration::widget() const
 
1187
{
 
1188
    return wrapper->widget();
 
1189
}
 
1190
KDecorationFactory* KCommonDecoration::factory() const
 
1191
{
 
1192
    return wrapper->factory();
 
1193
}
 
1194
void KCommonDecoration::grabXServer()
 
1195
{
 
1196
    return wrapper->grabXServer();
 
1197
}
 
1198
void KCommonDecoration::ungrabXServer()
 
1199
{
 
1200
    return wrapper->ungrabXServer();
 
1201
}
 
1202
void KCommonDecoration::closeWindow()
 
1203
{
 
1204
    return wrapper->closeWindow();
 
1205
}
 
1206
void KCommonDecoration::maximize(Qt::MouseButtons button)
 
1207
{
 
1208
    return wrapper->maximize(button);
 
1209
}
 
1210
void KCommonDecoration::maximize(MaximizeMode mode)
 
1211
{
 
1212
    return wrapper->maximize(mode);
 
1213
}
 
1214
void KCommonDecoration::minimize()
 
1215
{
 
1216
    return wrapper->minimize();
 
1217
}
 
1218
void KCommonDecoration::showContextHelp()
 
1219
{
 
1220
    return wrapper->showContextHelp();
 
1221
}
 
1222
void KCommonDecoration::setDesktop(int desktop)
 
1223
{
 
1224
    return wrapper->setDesktop(desktop);
 
1225
}
 
1226
void KCommonDecoration::toggleOnAllDesktops()
 
1227
{
 
1228
    return wrapper->toggleOnAllDesktops();
 
1229
}
 
1230
void KCommonDecoration::titlebarDblClickOperation()
 
1231
{
 
1232
    return wrapper->titlebarDblClickOperation();
 
1233
}
 
1234
void KCommonDecoration::titlebarMouseWheelOperation(int delta)
 
1235
{
 
1236
    return wrapper->titlebarMouseWheelOperation(delta);
 
1237
}
 
1238
void KCommonDecoration::setShade(bool set)
 
1239
{
 
1240
    return wrapper->setShade(set);
 
1241
}
 
1242
void KCommonDecoration::setKeepAbove(bool set)
 
1243
{
 
1244
    return wrapper->setKeepAbove(set);
 
1245
}
 
1246
void KCommonDecoration::setKeepBelow(bool set)
 
1247
{
 
1248
    return wrapper->setKeepBelow(set);
 
1249
}
 
1250
// *** end of wrapping of everything from KDecoration *** //
 
1251
 
 
1252
const KDecoration* KCommonDecoration::decoration() const
 
1253
{
 
1254
    return wrapper;
 
1255
}
 
1256
KDecoration* KCommonDecoration::decoration()
 
1257
{
 
1258
    return wrapper;
 
1259
}
 
1260
 
 
1261
 
 
1262
KCommonDecorationUnstable::KCommonDecorationUnstable(KDecorationBridge* bridge, KDecorationFactory* factory)
 
1263
    : KCommonDecoration(bridge, factory)
 
1264
{
 
1265
    Q_ASSERT(dynamic_cast<const KDecorationUnstable*>(decoration()));
 
1266
}
 
1267
 
 
1268
KCommonDecorationUnstable::~KCommonDecorationUnstable()
 
1269
{
 
1270
}
 
1271
 
 
1272
// All copied from kdecoration.cpp
 
1273
bool KCommonDecorationUnstable::compositingActive() const
 
1274
{
 
1275
    return static_cast<const KDecorationUnstable*>(decoration())->compositingActive();
 
1276
}
 
1277
 
 
1278
// Window tabbing
 
1279
 
 
1280
bool KCommonDecorationUnstable::isClientGroupActive()
 
1281
{
 
1282
    return static_cast<KDecorationUnstable*>(decoration())->isClientGroupActive();
 
1283
}
 
1284
 
 
1285
QList< ClientGroupItem > KCommonDecorationUnstable::clientGroupItems() const
 
1286
{
 
1287
    return static_cast<const KDecorationUnstable*>(decoration())->clientGroupItems();
 
1288
}
 
1289
 
 
1290
long KCommonDecorationUnstable::itemId(int index)
 
1291
{
 
1292
    return static_cast<KDecorationUnstable*>(decoration())->itemId(index);
 
1293
}
 
1294
 
 
1295
int KCommonDecorationUnstable::visibleClientGroupItem()
 
1296
{
 
1297
    return static_cast<KDecorationUnstable*>(decoration())->visibleClientGroupItem();
 
1298
}
 
1299
 
 
1300
void KCommonDecorationUnstable::setVisibleClientGroupItem(int index)
 
1301
{
 
1302
    static_cast<KDecorationUnstable*>(decoration())->setVisibleClientGroupItem(index);
 
1303
}
 
1304
 
 
1305
void KCommonDecorationUnstable::moveItemInClientGroup(int index, int before)
 
1306
{
 
1307
    static_cast<KDecorationUnstable*>(decoration())->moveItemInClientGroup(index, before);
 
1308
}
 
1309
 
 
1310
void KCommonDecorationUnstable::moveItemToClientGroup(long itemId, int before)
 
1311
{
 
1312
    static_cast<KDecorationUnstable*>(decoration())->moveItemToClientGroup(itemId, before);
 
1313
}
 
1314
 
 
1315
void KCommonDecorationUnstable::removeFromClientGroup(int index, const QRect& newGeom)
 
1316
{
 
1317
    static_cast<KDecorationUnstable*>(decoration())->removeFromClientGroup(index, newGeom);
 
1318
}
 
1319
 
 
1320
void KCommonDecorationUnstable::closeClientGroupItem(int index)
 
1321
{
 
1322
    static_cast<KDecorationUnstable*>(decoration())->closeClientGroupItem(index);
 
1323
}
 
1324
 
 
1325
void KCommonDecorationUnstable::closeAllInClientGroup()
 
1326
{
 
1327
    static_cast<KDecorationUnstable*>(decoration())->closeAllInClientGroup();
 
1328
}
 
1329
 
 
1330
void KCommonDecorationUnstable::displayClientMenu(int index, const QPoint& pos)
 
1331
{
 
1332
    static_cast<KDecorationUnstable*>(decoration())->displayClientMenu(index, pos);
 
1333
}
 
1334
 
 
1335
KDecoration::WindowOperation KCommonDecorationUnstable::buttonToWindowOperation(Qt::MouseButtons button)
 
1336
{
 
1337
    return static_cast<KDecorationUnstable*>(decoration())->buttonToWindowOperation(button);
 
1338
}
 
1339
 
 
1340
bool KCommonDecorationUnstable::eventFilter(QObject* o, QEvent* e)
 
1341
{
 
1342
    return KCommonDecoration::eventFilter(o, e);
 
1343
}
 
1344
 
 
1345
// kate: space-indent on; indent-width 4; mixedindent off; indent-mode cstyle;
 
1346