1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
|
/*
RISC OS KWin client
Copyright 2000
Rik Hemsley <rik@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <unistd.h> // for usleep
#include <config.h> // for usleep on non-linux platforms
#include <math.h> // for sin and cos
#include <tqapplication.h>
#include <tqimage.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpainter.h>
#include <netwm.h>
#include "Manager.h"
#include "Static.h"
#include "AboveButton.h"
#include "CloseButton.h"
#include "HelpButton.h"
#include "IconifyButton.h"
#include "LowerButton.h"
#include "MaximiseButton.h"
#include "StickyButton.h"
extern "C"
{
KDE_EXPORT KDecorationFactory* create_factory()
{
return new RiscOS::Factory();
}
}
namespace RiscOS
{
Manager::Manager(KDecorationBridge *bridge,
KDecorationFactory *factory)
: KDecoration(bridge, factory),
topLayout_ (NULL),
titleLayout_ (NULL),
titleSpacer_ (NULL)
{
}
Manager::~Manager()
{
}
void Manager::init()
{
createMainWidget(WNoAutoErase);
widget()->installEventFilter(this);
widget()->setBackgroundMode(NoBackground);
leftButtonList_.setAutoDelete(true);
rightButtonList_.setAutoDelete(true);
resetLayout();
}
bool Manager::eventFilter(TQObject *o, TQEvent *e)
{
if (TQT_BASE_OBJECT(o) != TQT_BASE_OBJECT(widget())) return false;
switch (e->type())
{
case TQEvent::Resize:
resizeEvent(TQT_TQRESIZEEVENT(e));
return true;
case TQEvent::Paint:
paintEvent(TQT_TQPAINTEVENT(e));
return true;
case TQEvent::MouseButtonDblClick:
mouseDoubleClickEvent(TQT_TQMOUSEEVENT(e));
return true;
case TQEvent::MouseButtonPress:
processMousePressEvent(TQT_TQMOUSEEVENT(e));
return true;
case TQEvent::Wheel:
wheelEvent( TQT_TQWHEELEVENT( e ));
return true;
case TQEvent::MouseButtonRelease:
return false;
case TQEvent::Show:
return false;
case TQEvent::MouseMove:
return false;
case TQEvent::Enter:
return false;
case TQEvent::Leave:
return false;
case TQEvent::Move:
return false;
default:
return false;
}
}
void Manager::reset(unsigned long /*changed*/)
{
resetLayout();
}
void Manager::borders(int &left, int &right, int &top, int &bottom) const
{
left = right = 1;
top = Static::instance()->titleHeight();
bottom = isResizable() ? Static::instance()->resizeHeight() : 1;
}
void Manager::resize(const TQSize &s)
{
widget()->resize(s);
}
TQSize Manager::minimumSize() const
{
return widget()->minimumSize();
}
void Manager::activeChange()
{
updateTitleBuffer();
widget()->tqrepaint();
emit(activeChanged(isActive()));
}
void Manager::captionChange()
{
updateTitleBuffer();
widget()->tqrepaint();
}
void Manager::iconChange()
{
}
void Manager::maximizeChange()
{
emit(maximizeChanged(maximizeMode() == MaximizeFull));
}
void Manager::desktopChange()
{
}
void Manager::shadeChange()
{
}
void Manager::paintEvent(TQPaintEvent *e)
{
TQPainter p(widget());
TQRect r(e->rect());
bool intersectsLeft = r.intersects(TQRect(0, 0, 1, height()));
bool intersectsRight =
r.intersects(TQRect(width() - 1, 0, width(), height()));
if (intersectsLeft || intersectsRight)
{
p.setPen(TQt::black);
if (intersectsLeft)
p.drawLine(0, r.top(), 0, r.bottom());
if (intersectsRight)
p.drawLine(width() - 1, r.top(), width() - 1, r.bottom());
}
Static * s = Static::instance();
bool active = isActive();
// Title bar.
TQRect tr = titleSpacer_->tqgeometry();
bitBlt(widget(), tr.topLeft(), &titleBuf_);
// Resize bar.
if (isResizable())
{
int rbt = height() - Static::instance()->resizeHeight(); // Resize bar top
bitBlt(widget(), 0, rbt, &(s->resize(active)));
bitBlt(widget(), 30, rbt, &(s->resizeMidLeft(active)));
p.drawTiledPixmap(32, rbt, width() - 34,
Static::instance()->resizeHeight(),
s->resizeMidMid(active));
bitBlt(widget(), width() - 32, rbt, &(s->resizeMidRight(active)));
bitBlt(widget(), width() - 30, rbt, &(s->resize(active)));
}
else
p.drawLine(1, height() - 1, width() - 2, height() - 1);
}
void Manager::resizeEvent(TQResizeEvent*)
{
updateButtonVisibility();
updateTitleBuffer();
widget()->tqrepaint();
}
void Manager::updateButtonVisibility()
{
#if 0
enum SizeProblem = { None, Small, Medium, Big };
SizeProblem sizeProblem = None;
if (width() < 80) sizeProblem = Big;
else if (width() < 100) sizeProblem = Medium;
else if (width() < 180) sizeProblem = Small;
switch (sizeProblem) {
case Small:
above_ ->hide();
lower_ ->hide();
sticky_ ->hide();
help_ ->hide();
iconify_ ->show();
maximise_ ->hide();
close_ ->show();
break;
case Medium:
above_ ->hide();
lower_ ->hide();
sticky_ ->hide();
help_ ->hide();
iconify_ ->hide();
maximise_ ->hide();
close_ ->show();
break;
case Big:
above_ ->hide();
lower_ ->hide();
sticky_ ->hide();
help_ ->hide();
iconify_ ->hide();
maximise_ ->hide();
close_ ->hide();
break;
case None:
default:
above_ ->show();
lower_ ->show();
sticky_ ->show();
if (providesContextHelp())
help_->show();
iconify_ ->show();
maximise_ ->show();
close_ ->show();
break;
}
tqlayout()->activate();
#endif
}
void Manager::updateTitleBuffer()
{
bool active = isActive();
Static * s = Static::instance();
TQRect tr = titleSpacer_->tqgeometry();
if (tr.width() == 0 || tr.height() == 0)
titleBuf_.resize(8, 8);
else
titleBuf_.resize(tr.size());
TQPainter p(&titleBuf_);
p.drawPixmap(0, 0, s->titleTextLeft(active));
p.drawTiledPixmap(3, 0, tr.width() - 6, Static::instance()->titleHeight(),
s->titleTextMid(active));
p.setPen(options()->color(KDecorationOptions::ColorFont, active));
p.setFont(options()->font(active));
p.drawText(4, 2, tr.width() - 8, Static::instance()->titleHeight() - 4,
AlignCenter, caption());
p.drawPixmap(tr.width() - 3, 0, s->titleTextRight(active));
}
KDecoration::Position Manager::mousePosition(const TQPoint& p) const
{
Position m = PositionCenter;
// Look out for off-by-one errors here.
if (isResizable())
{
if (p.y() > (height() - (Static::instance()->resizeHeight() + 1)))
{
// Keep order !
if (p.x() >= (width() - 30))
m = PositionBottomRight;
else if (p.x() <= 30)
m = PositionBottomLeft;
else
m = PositionBottom;
}
else
{
m = PositionCenter;
// Client::mousePosition(p);
}
}
else
{
m = PositionCenter;
// Client::mousePosition(p);
}
return m;
}
void Manager::mouseDoubleClickEvent(TQMouseEvent *e)
{
if (e->button() == Qt::LeftButton && titleSpacer_->tqgeometry().contains(e->pos()))
titlebarDblClickOperation();
}
void Manager::wheelEvent(TQWheelEvent *e)
{
if (isSetShade() || titleLayout_->tqgeometry().contains(e->pos()) )
titlebarMouseWheelOperation( e->delta());
}
void Manager::paletteChange(const TQPalette &)
{
resetLayout();
}
void Manager::stickyChange(bool b)
{
emit(stickyChanged(b));
}
void Manager::slotToggleSticky()
{
toggleOnAllDesktops();
emit(stickyChanged(isOnAllDesktops()));
}
void Manager::slotAbove()
{
setKeepAbove(!keepAbove());
}
void Manager::slotLower()
{
setKeepBelow(!keepBelow());
}
void Manager::slotMaximizeClicked(ButtonState state)
{
#if KDE_IS_VERSION(3, 3, 0)
maximize(state);
#else
switch (state)
{
case RightButton:
maximize(maximizeMode() ^ MaximizeHorizontal);
break;
case MidButton:
maximize(maximizeMode() ^ MaximizeVertical);
break;
case LeftButton:
default:
maximize(maximizeMode() == MaximizeFull ? MaximizeRestore
: MaximizeFull);
break;
}
#endif
emit(maximizeChanged(maximizeMode() == MaximizeFull));
}
bool Manager::animateMinimize(bool iconify)
{
int style = Static::instance()->animationStyle();
switch (style)
{
case 1:
{
// Double twisting double back, with pike ;)
if (!iconify) // No animation for restore.
return true;
// Go away quick.
helperShowHide(false);
tqApp->syncX();
TQRect r = iconGeometry();
if (!r.isValid())
return true;
// Algorithm taken from Window Maker (http://www.windowmaker.org)
int sx = geometry().x();
int sy = geometry().y();
int sw = width();
int sh = height();
int dx = r.x();
int dy = r.y();
int dw = r.width();
int dh = r.height();
double steps = 12;
double xstep = double((dx-sx)/steps);
double ystep = double((dy-sy)/steps);
double wstep = double((dw-sw)/steps);
double hstep = double((dh-sh)/steps);
double cx = sx;
double cy = sy;
double cw = sw;
double ch = sh;
double finalAngle = 3.14159265358979323846;
double delta = finalAngle / steps;
TQPainter p(workspaceWidget());
p.setRasterOp(TQt::NotROP);
for (double angle = 0; ; angle += delta)
{
if (angle > finalAngle)
angle = finalAngle;
double dx = (cw / 10) - ((cw / 5) * sin(angle));
double dch = (ch / 2) * cos(angle);
double midy = cy + (ch / 2);
TQPoint p1(int(cx + dx), int(midy - dch));
TQPoint p2(int(cx + cw - dx), p1.y());
TQPoint p3(int(cx + dw + dx), int(midy + dch));
TQPoint p4(int(cx - dx), p3.y());
grabXServer();
p.drawLine(p1, p2);
p.drawLine(p2, p3);
p.drawLine(p3, p4);
p.drawLine(p4, p1);
p.flush();
usleep(500);
p.drawLine(p1, p2);
p.drawLine(p2, p3);
p.drawLine(p3, p4);
p.drawLine(p4, p1);
ungrabXServer();
cx += xstep;
cy += ystep;
cw += wstep;
ch += hstep;
if (angle >= finalAngle)
break;
}
}
break;
case 2:
{
// KVirc style ? Maybe. For qwertz.
if (!iconify) // No animation for restore.
return true;
// Go away quick.
helperShowHide(false);
tqApp->syncX();
int stepCount = 12;
TQRect r(geometry());
int dx = r.width() / (stepCount * 2);
int dy = r.height() / (stepCount * 2);
TQPainter p(workspaceWidget());
p.setRasterOp(TQt::NotROP);
for (int step = 0; step < stepCount; step++)
{
r.moveBy(dx, dy);
r.setWidth(r.width() - 2 * dx);
r.setHeight(r.height() - 2 * dy);
grabXServer();
p.drawRect(r);
p.flush();
usleep(200);
p.drawRect(r);
ungrabXServer();
}
}
break;
default:
{
TQRect icongeom = iconGeometry();
if (!icongeom.isValid())
return true;
TQRect wingeom = geometry();
TQPainter p(workspaceWidget());
p.setRasterOp(TQt::NotROP);
#if 0
if (iconify)
p.setClipRegion(TQRegion(workspaceWidget()->rect()) - wingeom);
#endif
grabXServer();
p.drawLine(wingeom.bottomRight(), icongeom.bottomRight());
p.drawLine(wingeom.bottomLeft(), icongeom.bottomLeft());
p.drawLine(wingeom.topLeft(), icongeom.topLeft());
p.drawLine(wingeom.topRight(), icongeom.topRight());
p.flush();
tqApp->syncX();
usleep(30000);
p.drawLine(wingeom.bottomRight(), icongeom.bottomRight());
p.drawLine(wingeom.bottomLeft(), icongeom.bottomLeft());
p.drawLine(wingeom.topLeft(), icongeom.topLeft());
p.drawLine(wingeom.topRight(), icongeom.topRight());
ungrabXServer();
}
break;
}
return true;
}
void Manager::createTitle()
{
leftButtonList_.clear();
rightButtonList_.clear();
TQString buttons;
if (options()->customButtonPositions())
buttons = options()->titleButtonsLeft() + "|" +
options()->titleButtonsRight();
else
buttons = "XSH|IA";
TQPtrList<Button> *buttonList = &leftButtonList_;
for (unsigned int i = 0; i < buttons.length(); ++i)
{
Button * tb = NULL;
switch (buttons[i].latin1())
{
case 'S': // Sticky
tb = new StickyButton(widget());
connect(this, TQT_SIGNAL(stickyChanged(bool)),
tb, TQT_SLOT(setOn(bool)));
connect(tb, TQT_SIGNAL(toggleSticky()), this, TQT_SLOT(slotToggleSticky()));
emit(stickyChanged(isOnAllDesktops()));
break;
case 'H': // Help
if (providesContextHelp())
{
tb = new HelpButton(widget());
connect(tb, TQT_SIGNAL(help()), this, TQT_SLOT(showContextHelp()));
}
break;
case 'I': // Minimize
if (isMinimizable())
{
tb = new IconifyButton(widget());
connect(tb, TQT_SIGNAL(iconify()), this, TQT_SLOT(minimize()));
}
break;
case 'A': // Maximize
if (isMaximizable())
{
tb = new MaximiseButton(widget());
connect(tb, TQT_SIGNAL(maximizeClicked(ButtonState)),
this, TQT_SLOT(slotMaximizeClicked(ButtonState)));
connect(this, TQT_SIGNAL(maximizeChanged(bool)),
tb, TQT_SLOT(setOn(bool)));
emit(maximizeChanged(maximizeMode() == MaximizeFull));
}
break;
case 'F': // Above
tb = new AboveButton(widget());
connect(tb, TQT_SIGNAL(above()), this, TQT_SLOT(slotAbove()));
break;
case 'B': // Lower
tb = new LowerButton(widget());
connect(tb, TQT_SIGNAL(lower()), this, TQT_SLOT(slotLower()));
break;
case 'X': // Close
if (isCloseable())
{
tb = new CloseButton(widget());
connect(tb, TQT_SIGNAL(closeWindow()), this, TQT_SLOT(closeWindow()));
}
break;
case '|':
buttonList = &rightButtonList_;
break;
}
if (tb != NULL)
{
connect(this, TQT_SIGNAL(activeChanged(bool)), tb, TQT_SLOT(setActive(bool)));
buttonList->append(tb);
}
}
for (TQPtrListIterator<Button> it(leftButtonList_); it.current(); ++it)
{
it.current()->setAlignment(Button::Left);
titleLayout_->addWidget(it.current());
}
titleSpacer_ = new TQSpacerItem(0, Static::instance()->titleHeight(),
TQSizePolicy::Expanding, TQSizePolicy::Fixed);
titleLayout_->addItem(titleSpacer_);
for (TQPtrListIterator<Button> it(rightButtonList_); it.current(); ++it)
{
it.current()->setAlignment(Button::Right);
titleLayout_->addWidget(it.current());
}
}
void Manager::resetLayout()
{
delete topLayout_;
topLayout_ = new TQVBoxLayout(widget(), 0, 0);
topLayout_->setResizeMode(TQLayout::FreeResize);
titleLayout_ = new TQBoxLayout(topLayout_, TQBoxLayout::LeftToRight, 0, 0);
titleLayout_->setResizeMode(TQLayout::FreeResize);
createTitle();
TQBoxLayout *midLayout = new TQBoxLayout(topLayout_, TQBoxLayout::LeftToRight,
0, 0);
midLayout->setResizeMode(TQLayout::FreeResize);
midLayout->addSpacing(1);
if (isPreview())
midLayout->addWidget(
new TQLabel(i18n("<center><b>RiscOS preview</b></center>"), widget()));
midLayout->addSpacing(1);
if (isResizable())
topLayout_->addSpacing(Static::instance()->resizeHeight());
else
topLayout_->addSpacing(1);
}
// --------------------
Factory::Factory()
{
(void) RiscOS::Static::instance();
}
Factory::~Factory()
{
delete RiscOS::Static::instance();
}
bool Factory::reset(unsigned long /*changed*/)
{
RiscOS::Static::instance()->reset();
return true;
}
bool Factory::supports( Ability ability )
{
switch( ability )
{
case AbilityAnnounceButtons:
case AbilityButtonOnAllDesktops:
case AbilityButtonHelp:
case AbilityButtonMinimize:
case AbilityButtonMaximize:
case AbilityButtonClose:
case AbilityButtonAboveOthers:
case AbilityButtonBelowOthers:
return true;
default:
return false;
};
}
KDecoration* Factory::createDecoration(KDecorationBridge *bridge)
{
return new Manager(bridge, this);
}
} // End namespace
// vim:ts=2:sw=2:tw=78
#include "Manager.moc"
|