-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
Window.cpp
4090 lines (3284 loc) · 89.5 KB
/
Window.cpp
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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2001-2011, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Adrian Oanca <adioanca@cotty.iren.ro>
* Axel Dörfler, axeld@pinc-software.de
* Stephan Aßmus, <superstippi@gmx.de>
*/
#include <Window.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <Application.h>
#include <Autolock.h>
#include <Bitmap.h>
#include <Button.h>
#include <FindDirectory.h>
#include <Layout.h>
#include <LayoutUtils.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <MessageQueue.h>
#include <MessageRunner.h>
#include <Path.h>
#include <PropertyInfo.h>
#include <Roster.h>
#include <Screen.h>
#include <String.h>
#include <AppMisc.h>
#include <AppServerLink.h>
#include <ApplicationPrivate.h>
#include <binary_compatibility/Interface.h>
#include <DirectMessageTarget.h>
#include <input_globals.h>
#include <InputServerTypes.h>
#include <MenuPrivate.h>
#include <MessagePrivate.h>
#include <PortLink.h>
#include <RosterPrivate.h>
#include <ServerProtocol.h>
#include <TokenSpace.h>
#include <ToolTipManager.h>
#include <ToolTipWindow.h>
#include <tracker_private.h>
#include <WindowPrivate.h>
//#define DEBUG_WIN
#ifdef DEBUG_WIN
# define STRACE(x) printf x
#else
# define STRACE(x) ;
#endif
#define B_HIDE_APPLICATION '_AHD'
// if we ever move this to a public namespace, we should also move the
// handling of this message into BApplication
#define _MINIMIZE_ '_WMZ'
#define _ZOOM_ '_WZO'
#define _SEND_BEHIND_ '_WSB'
#define _SEND_TO_FRONT_ '_WSF'
#define _SWITCH_WORKSPACE_ '_SWS'
void do_minimize_team(BRect zoomRect, team_id team, bool zoom);
struct BWindow::unpack_cookie {
unpack_cookie();
BMessage* message;
int32 index;
BHandler* focus;
int32 focus_token;
int32 last_view_token;
bool found_focus;
bool tokens_scanned;
};
class BWindow::Shortcut {
public:
Shortcut(uint32 key, uint32 modifiers,
BMenuItem* item);
Shortcut(uint32 key, uint32 modifiers,
BMessage* message, BHandler* target);
~Shortcut();
bool Matches(uint32 key, uint32 modifiers) const;
BMenuItem* MenuItem() const { return fMenuItem; }
BMessage* Message() const { return fMessage; }
BHandler* Target() const { return fTarget; }
static uint32 AllowedModifiers();
static uint32 PrepareKey(uint32 key);
static uint32 PrepareModifiers(uint32 modifiers);
private:
uint32 fKey;
uint32 fModifiers;
BMenuItem* fMenuItem;
BMessage* fMessage;
BHandler* fTarget;
};
using BPrivate::gDefaultTokens;
using BPrivate::MenuPrivate;
static property_info sWindowPropInfo[] = {
{
"Active", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_BOOL_TYPE }
},
{
"Feel", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_INT32_TYPE }
},
{
"Flags", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_INT32_TYPE }
},
{
"Frame", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_RECT_TYPE }
},
{
"Hidden", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_BOOL_TYPE }
},
{
"Look", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_INT32_TYPE }
},
{
"Title", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_STRING_TYPE }
},
{
"Workspaces", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_INT32_TYPE }
},
{
"MenuBar", {},
{ B_DIRECT_SPECIFIER }, NULL, 0, {}
},
{
"View", { B_COUNT_PROPERTIES },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_INT32_TYPE }
},
{
"View", {}, {}, NULL, 0, {}
},
{
"Minimize", { B_GET_PROPERTY, B_SET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_BOOL_TYPE }
},
{
"TabFrame", { B_GET_PROPERTY },
{ B_DIRECT_SPECIFIER }, NULL, 0, { B_RECT_TYPE }
},
{}
};
static value_info sWindowValueInfo[] = {
{
"MoveTo", 'WDMT', B_COMMAND_KIND,
"Moves to the position in the BPoint data"
},
{
"MoveBy", 'WDMB', B_COMMAND_KIND,
"Moves by the offsets in the BPoint data"
},
{
"ResizeTo", 'WDRT', B_COMMAND_KIND,
"Resize to the size in the BPoint data"
},
{
"ResizeBy", 'WDRB', B_COMMAND_KIND,
"Resize by the offsets in the BPoint data"
},
{}
};
void
_set_menu_sem_(BWindow* window, sem_id sem)
{
if (window != NULL)
window->fMenuSem = sem;
}
// #pragma mark -
BWindow::unpack_cookie::unpack_cookie()
:
message((BMessage*)~0UL),
// message == NULL is our exit condition
index(0),
focus_token(B_NULL_TOKEN),
last_view_token(B_NULL_TOKEN),
found_focus(false),
tokens_scanned(false)
{
}
// #pragma mark -
BWindow::Shortcut::Shortcut(uint32 key, uint32 modifiers, BMenuItem* item)
:
fKey(PrepareKey(key)),
fModifiers(PrepareModifiers(modifiers)),
fMenuItem(item),
fMessage(NULL),
fTarget(NULL)
{
}
BWindow::Shortcut::Shortcut(uint32 key, uint32 modifiers, BMessage* message,
BHandler* target)
:
fKey(PrepareKey(key)),
fModifiers(PrepareModifiers(modifiers)),
fMenuItem(NULL),
fMessage(message),
fTarget(target)
{
}
BWindow::Shortcut::~Shortcut()
{
// we own the message, if any
delete fMessage;
}
bool
BWindow::Shortcut::Matches(uint32 key, uint32 modifiers) const
{
return fKey == key && fModifiers == modifiers;
}
/*static*/
uint32
BWindow::Shortcut::AllowedModifiers()
{
return B_COMMAND_KEY | B_OPTION_KEY | B_SHIFT_KEY | B_CONTROL_KEY
| B_MENU_KEY;
}
/*static*/
uint32
BWindow::Shortcut::PrepareModifiers(uint32 modifiers)
{
return (modifiers & AllowedModifiers()) | B_COMMAND_KEY;
}
/*static*/
uint32
BWindow::Shortcut::PrepareKey(uint32 key)
{
return tolower(key);
// TODO: support unicode and/or more intelligent key mapping
}
// #pragma mark -
BWindow::BWindow(BRect frame, const char* title, window_type type,
uint32 flags, uint32 workspace)
:
BLooper(title, B_DISPLAY_PRIORITY)
{
window_look look;
window_feel feel;
_DecomposeType(type, &look, &feel);
_InitData(frame, title, look, feel, flags, workspace);
}
BWindow::BWindow(BRect frame, const char* title, window_look look,
window_feel feel, uint32 flags, uint32 workspace)
:
BLooper(title, B_DISPLAY_PRIORITY)
{
_InitData(frame, title, look, feel, flags, workspace);
}
BWindow::BWindow(BMessage* data)
:
BLooper(data)
{
data->FindRect("_frame", &fFrame);
const char* title;
data->FindString("_title", &title);
window_look look;
data->FindInt32("_wlook", (int32*)&look);
window_feel feel;
data->FindInt32("_wfeel", (int32*)&feel);
if (data->FindInt32("_flags", (int32*)&fFlags) != B_OK)
fFlags = 0;
uint32 workspaces;
data->FindInt32("_wspace", (int32*)&workspaces);
uint32 type;
if (data->FindInt32("_type", (int32*)&type) == B_OK)
_DecomposeType((window_type)type, &fLook, &fFeel);
// connect to app_server and initialize data
_InitData(fFrame, title, look, feel, fFlags, workspaces);
if (data->FindFloat("_zoom", 0, &fMaxZoomWidth) == B_OK
&& data->FindFloat("_zoom", 1, &fMaxZoomHeight) == B_OK)
SetZoomLimits(fMaxZoomWidth, fMaxZoomHeight);
if (data->FindFloat("_sizel", 0, &fMinWidth) == B_OK
&& data->FindFloat("_sizel", 1, &fMinHeight) == B_OK
&& data->FindFloat("_sizel", 2, &fMaxWidth) == B_OK
&& data->FindFloat("_sizel", 3, &fMaxHeight) == B_OK)
SetSizeLimits(fMinWidth, fMaxWidth,
fMinHeight, fMaxHeight);
if (data->FindInt64("_pulse", &fPulseRate) == B_OK)
SetPulseRate(fPulseRate);
BMessage msg;
int32 i = 0;
while (data->FindMessage("_views", i++, &msg) == B_OK) {
BArchivable* obj = instantiate_object(&msg);
if (BView* child = dynamic_cast<BView*>(obj))
AddChild(child);
}
}
BWindow::BWindow(BRect frame, int32 bitmapToken)
:
BLooper("offscreen bitmap")
{
_DecomposeType(B_UNTYPED_WINDOW, &fLook, &fFeel);
_InitData(frame, "offscreen", fLook, fFeel, 0, 0, bitmapToken);
}
BWindow::~BWindow()
{
if (BMenu* menu = dynamic_cast<BMenu*>(fFocus)) {
MenuPrivate(menu).QuitTracking();
}
// The BWindow is locked when the destructor is called,
// we need to unlock because the menubar thread tries
// to post a message, which will deadlock otherwise.
// TODO: I replaced Unlock() with UnlockFully() because the window
// was kept locked after that in case it was closed using ALT-W.
// There might be an extra Lock() somewhere in the quitting path...
UnlockFully();
// Wait if a menu is still tracking
if (fMenuSem > 0) {
while (acquire_sem(fMenuSem) == B_INTERRUPTED)
;
}
Lock();
fTopView->RemoveSelf();
delete fTopView;
// remove all remaining shortcuts
int32 shortCutCount = fShortcuts.CountItems();
for (int32 i = 0; i < shortCutCount; i++) {
delete (Shortcut*)fShortcuts.ItemAtFast(i);
}
// TODO: release other dynamically-allocated objects
free(fTitle);
// disable pulsing
SetPulseRate(0);
// tell app_server about our demise
fLink->StartMessage(AS_DELETE_WINDOW);
// sync with the server so that for example
// a BBitmap can be sure that there are no
// more pending messages that are executed
// after the bitmap is deleted (which uses
// a different link and server side thread)
int32 code;
fLink->FlushWithReply(code);
// the sender port belongs to the app_server
delete_port(fLink->ReceiverPort());
delete fLink;
}
BArchivable*
BWindow::Instantiate(BMessage* data)
{
if (!validate_instantiation(data , "BWindow"))
return NULL;
return new(std::nothrow) BWindow(data);
}
status_t
BWindow::Archive(BMessage* data, bool deep) const
{
status_t ret = BLooper::Archive(data, deep);
if (ret == B_OK)
ret = data->AddRect("_frame", fFrame);
if (ret == B_OK)
ret = data->AddString("_title", fTitle);
if (ret == B_OK)
ret = data->AddInt32("_wlook", fLook);
if (ret == B_OK)
ret = data->AddInt32("_wfeel", fFeel);
if (ret == B_OK && fFlags != 0)
ret = data->AddInt32("_flags", fFlags);
if (ret == B_OK)
ret = data->AddInt32("_wspace", (uint32)Workspaces());
if (ret == B_OK && !_ComposeType(fLook, fFeel))
ret = data->AddInt32("_type", (uint32)Type());
if (fMaxZoomWidth != 32768.0 || fMaxZoomHeight != 32768.0) {
if (ret == B_OK)
ret = data->AddFloat("_zoom", fMaxZoomWidth);
if (ret == B_OK)
ret = data->AddFloat("_zoom", fMaxZoomHeight);
}
if (fMinWidth != 0.0 || fMinHeight != 0.0
|| fMaxWidth != 32768.0 || fMaxHeight != 32768.0) {
if (ret == B_OK)
ret = data->AddFloat("_sizel", fMinWidth);
if (ret == B_OK)
ret = data->AddFloat("_sizel", fMinHeight);
if (ret == B_OK)
ret = data->AddFloat("_sizel", fMaxWidth);
if (ret == B_OK)
ret = data->AddFloat("_sizel", fMaxHeight);
}
if (ret == B_OK && fPulseRate != 500000)
data->AddInt64("_pulse", fPulseRate);
if (ret == B_OK && deep) {
int32 noOfViews = CountChildren();
for (int32 i = 0; i < noOfViews; i++){
BMessage childArchive;
ret = ChildAt(i)->Archive(&childArchive, true);
if (ret == B_OK)
ret = data->AddMessage("_views", &childArchive);
if (ret != B_OK)
break;
}
}
return ret;
}
void
BWindow::Quit()
{
if (!IsLocked()) {
const char* name = Name();
if (!name)
name = "no-name";
printf("ERROR - you must Lock a looper before calling Quit(), "
"team=%" B_PRId32 ", looper=%s\n", Team(), name);
}
// Try to lock
if (!Lock()){
// We're toast already
return;
}
while (!IsHidden()) {
Hide();
}
if (fFlags & B_QUIT_ON_WINDOW_CLOSE)
be_app->PostMessage(B_QUIT_REQUESTED);
BLooper::Quit();
}
void
BWindow::AddChild(BView* child, BView* before)
{
BAutolock locker(this);
if (locker.IsLocked())
fTopView->AddChild(child, before);
}
void
BWindow::AddChild(BLayoutItem* child)
{
BAutolock locker(this);
if (locker.IsLocked())
fTopView->AddChild(child);
}
bool
BWindow::RemoveChild(BView* child)
{
BAutolock locker(this);
if (!locker.IsLocked())
return false;
return fTopView->RemoveChild(child);
}
int32
BWindow::CountChildren() const
{
BAutolock locker(const_cast<BWindow*>(this));
if (!locker.IsLocked())
return 0;
return fTopView->CountChildren();
}
BView*
BWindow::ChildAt(int32 index) const
{
BAutolock locker(const_cast<BWindow*>(this));
if (!locker.IsLocked())
return NULL;
return fTopView->ChildAt(index);
}
void
BWindow::Minimize(bool minimize)
{
if (IsModal() || IsFloating() || IsHidden() || fMinimized == minimize
|| !Lock())
return;
fMinimized = minimize;
fLink->StartMessage(AS_MINIMIZE_WINDOW);
fLink->Attach<bool>(minimize);
fLink->Flush();
Unlock();
}
status_t
BWindow::SendBehind(const BWindow* window)
{
if (!Lock())
return B_ERROR;
fLink->StartMessage(AS_SEND_BEHIND);
fLink->Attach<int32>(window != NULL ? _get_object_token_(window) : -1);
fLink->Attach<team_id>(Team());
status_t status = B_ERROR;
fLink->FlushWithReply(status);
Unlock();
return status;
}
void
BWindow::Flush() const
{
if (const_cast<BWindow*>(this)->Lock()) {
fLink->Flush();
const_cast<BWindow*>(this)->Unlock();
}
}
void
BWindow::Sync() const
{
if (!const_cast<BWindow*>(this)->Lock())
return;
fLink->StartMessage(AS_SYNC);
// waiting for the reply is the actual syncing
int32 code;
fLink->FlushWithReply(code);
const_cast<BWindow*>(this)->Unlock();
}
void
BWindow::DisableUpdates()
{
if (Lock()) {
fLink->StartMessage(AS_DISABLE_UPDATES);
fLink->Flush();
Unlock();
}
}
void
BWindow::EnableUpdates()
{
if (Lock()) {
fLink->StartMessage(AS_ENABLE_UPDATES);
fLink->Flush();
Unlock();
}
}
void
BWindow::BeginViewTransaction()
{
if (Lock()) {
fInTransaction = true;
Unlock();
}
}
void
BWindow::EndViewTransaction()
{
if (Lock()) {
if (fInTransaction)
fLink->Flush();
fInTransaction = false;
Unlock();
}
}
bool
BWindow::InViewTransaction() const
{
BAutolock locker(const_cast<BWindow*>(this));
return fInTransaction;
}
bool
BWindow::IsFront() const
{
BAutolock locker(const_cast<BWindow*>(this));
if (!locker.IsLocked())
return false;
fLink->StartMessage(AS_IS_FRONT_WINDOW);
status_t status;
if (fLink->FlushWithReply(status) == B_OK)
return status >= B_OK;
return false;
}
void
BWindow::MessageReceived(BMessage* msg)
{
if (!msg->HasSpecifiers()) {
if (msg->what == B_KEY_DOWN)
_KeyboardNavigation();
if (msg->what == (int32)kMsgAppServerRestarted) {
fLink->SetSenderPort(BApplication::Private::ServerLink()->SenderPort());
BPrivate::AppServerLink lockLink;
// we're talking to the server application using our own
// communication channel (fLink) - we better make sure no one
// interferes by locking that channel (which AppServerLink does
// implicetly)
fLink->StartMessage(AS_CREATE_WINDOW);
fLink->Attach<BRect>(fFrame);
fLink->Attach<uint32>((uint32)fLook);
fLink->Attach<uint32>((uint32)fFeel);
fLink->Attach<uint32>(fFlags);
fLink->Attach<uint32>(0);
fLink->Attach<int32>(_get_object_token_(this));
fLink->Attach<port_id>(fLink->ReceiverPort());
fLink->Attach<port_id>(fMsgPort);
fLink->AttachString(fTitle);
port_id sendPort;
int32 code;
if (fLink->FlushWithReply(code) == B_OK
&& code == B_OK
&& fLink->Read<port_id>(&sendPort) == B_OK) {
// read the frame size and its limits that were really
// enforced on the server side
fLink->Read<BRect>(&fFrame);
fLink->Read<float>(&fMinWidth);
fLink->Read<float>(&fMaxWidth);
fLink->Read<float>(&fMinHeight);
fLink->Read<float>(&fMaxHeight);
fMaxZoomWidth = fMaxWidth;
fMaxZoomHeight = fMaxHeight;
} else
sendPort = -1;
// Redirect our link to the new window connection
fLink->SetSenderPort(sendPort);
// connect all views to the server again
fTopView->_CreateSelf();
_SendShowOrHideMessage();
}
return BLooper::MessageReceived(msg);
}
BMessage replyMsg(B_REPLY);
bool handled = false;
BMessage specifier;
int32 what;
const char* prop;
int32 index;
if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK)
return BLooper::MessageReceived(msg);
BPropertyInfo propertyInfo(sWindowPropInfo);
switch (propertyInfo.FindMatch(msg, index, &specifier, what, prop)) {
case 0:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddBool("result", IsActive());
handled = true;
} else if (msg->what == B_SET_PROPERTY) {
bool newActive;
if (msg->FindBool("data", &newActive) == B_OK) {
Activate(newActive);
handled = true;
}
}
break;
case 1:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32("result", (uint32)Feel());
handled = true;
} else {
uint32 newFeel;
if (msg->FindInt32("data", (int32*)&newFeel) == B_OK) {
SetFeel((window_feel)newFeel);
handled = true;
}
}
break;
case 2:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32("result", Flags());
handled = true;
} else {
uint32 newFlags;
if (msg->FindInt32("data", (int32*)&newFlags) == B_OK) {
SetFlags(newFlags);
handled = true;
}
}
break;
case 3:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddRect("result", Frame());
handled = true;
} else {
BRect newFrame;
if (msg->FindRect("data", &newFrame) == B_OK) {
MoveTo(newFrame.LeftTop());
ResizeTo(newFrame.Width(), newFrame.Height());
handled = true;
}
}
break;
case 4:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddBool("result", IsHidden());
handled = true;
} else {
bool hide;
if (msg->FindBool("data", &hide) == B_OK) {
if (hide) {
if (!IsHidden())
Hide();
} else if (IsHidden())
Show();
handled = true;
}
}
break;
case 5:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32("result", (uint32)Look());
handled = true;
} else {
uint32 newLook;
if (msg->FindInt32("data", (int32*)&newLook) == B_OK) {
SetLook((window_look)newLook);
handled = true;
}
}
break;
case 6:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddString("result", Title());
handled = true;
} else {
const char* newTitle = NULL;
if (msg->FindString("data", &newTitle) == B_OK) {
SetTitle(newTitle);
handled = true;
}
}
break;
case 7:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddInt32( "result", Workspaces());
handled = true;
} else {
uint32 newWorkspaces;
if (msg->FindInt32("data", (int32*)&newWorkspaces) == B_OK) {
SetWorkspaces(newWorkspaces);
handled = true;
}
}
break;
case 11:
if (msg->what == B_GET_PROPERTY) {
replyMsg.AddBool("result", IsMinimized());
handled = true;
} else {
bool minimize;
if (msg->FindBool("data", &minimize) == B_OK) {
Minimize(minimize);
handled = true;
}
}
break;
case 12:
if (msg->what == B_GET_PROPERTY) {
BMessage settings;
if (GetDecoratorSettings(&settings) == B_OK) {
BRect frame;
if (settings.FindRect("tab frame", &frame) == B_OK) {
replyMsg.AddRect("result", frame);
handled = true;
}
}
}
break;
default:
return BLooper::MessageReceived(msg);
}
if (handled) {
if (msg->what == B_SET_PROPERTY)
replyMsg.AddInt32("error", B_OK);
} else {
replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD;
replyMsg.AddInt32("error", B_BAD_SCRIPT_SYNTAX);
replyMsg.AddString("message", "Didn't understand the specifier(s)");
}
msg->SendReply(&replyMsg);
}
void
BWindow::DispatchMessage(BMessage* msg, BHandler* target)
{
if (!msg)
return;
switch (msg->what) {
case B_ZOOM:
Zoom();
break;
case _MINIMIZE_:
// Used by the minimize shortcut
if ((Flags() & B_NOT_MINIMIZABLE) == 0)
Minimize(true);
break;
case _ZOOM_:
// Used by the zoom shortcut
if ((Flags() & B_NOT_ZOOMABLE) == 0)
Zoom();
break;
case _SEND_BEHIND_:
SendBehind(NULL);
break;
case _SEND_TO_FRONT_:
Activate();
break;
case _SWITCH_WORKSPACE_:
{
int32 deltaX = 0;
msg->FindInt32("delta_x", &deltaX);
int32 deltaY = 0;
msg->FindInt32("delta_y", &deltaY);
bool takeMeThere = false;
msg->FindBool("take_me_there", &takeMeThere);
if (deltaX == 0 && deltaY == 0)
break;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_WORKSPACE_LAYOUT);
status_t status;
int32 columns;
int32 rows;
if (link.FlushWithReply(status) != B_OK || status != B_OK)
break;
link.Read<int32>(&columns);
link.Read<int32>(&rows);
int32 current = current_workspace();
int32 nextColumn = current % columns + deltaX;
int32 nextRow = current / columns + deltaY;
if (nextColumn >= columns)
nextColumn = columns - 1;
else if (nextColumn < 0)
nextColumn = 0;
if (nextRow >= rows)
nextRow = rows - 1;
else if (nextRow < 0)
nextRow = 0;