2 * Copyright 2011, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
7 #include "PanelWindow.h"
11 #include <GroupLayout.h>
12 #include <MessageRunner.h>
15 #include "ApplicationsView.h"
16 #include "GroupListView.h"
18 #include "WindowsView.h"
21 static const uint32 kMsgShow
= 'SHOW';
22 static const uint32 kMsgHide
= 'HIDE';
24 static const int32 kMinShowState
= 0;
25 static const int32 kMaxShowState
= 4;
26 static const bigtime_t kMoveDelay
= 15000;
30 PanelWindow::PanelWindow(uint32 location
, uint32 which
, team_id team
)
32 BWindow(BRect(-16000, -16000, -15900, -15900), "panel",
33 B_BORDERED_WINDOW_LOOK
, B_FLOATING_ALL_WINDOW_FEEL
,
34 B_ASYNCHRONOUS_CONTROLS
| B_AUTO_UPDATE_SIZE_LIMITS
| B_AVOID_FOCUS
,
37 fShowState(kMinShowState
)
39 SetLayout(new BGroupLayout(B_HORIZONTAL
));
41 BView
* child
= _ViewFor(location
, which
, team
);
46 PostMessage(kMsgShow
);
50 PanelWindow::~PanelWindow()
52 BMessage
message(kMsgLocationFree
);
53 message
.AddInt32("location", fLocation
);
54 be_app
->PostMessage(&message
);
59 PanelWindow::MessageReceived(BMessage
* message
)
61 switch (message
->what
) {
64 _UpdateShowState(message
->what
);
68 BWindow::MessageReceived(message
);
75 PanelWindow::_ViewFor(uint32 location
, uint32 which
, team_id team
) const
78 case kShowApplications
:
79 return new ApplicationsView(location
);
80 case kShowApplicationWindows
:
81 return new WindowsView(team
, location
);
90 PanelWindow::_UpdateShowState(uint32 how
)
92 if ((how
== kMsgShow
&& fShowState
>= kMaxShowState
)
93 || (how
== kMsgHide
&& fShowState
<= kMinShowState
))
96 fShowState
+= how
== kMsgShow
? 1 : -1;
98 // Compute start and end position depending on the location
99 // TODO: multi-screen support
101 BRect screenFrame
= screen
.Frame();
108 from
.y
= screenFrame
.top
109 + (screenFrame
.Height() - Bounds().Height()) / 2.f
;
114 from
.x
= screenFrame
.left
115 + (screenFrame
.Width() - Bounds().Width()) / 2.f
;
122 from
.x
= screenFrame
.left
- Bounds().Width();
123 to
.x
= screenFrame
.left
;
126 from
.x
= screenFrame
.right
;
127 to
.x
= screenFrame
.right
- Bounds().Width();
130 from
.y
= screenFrame
.top
- Bounds().Height();
131 to
.y
= screenFrame
.top
;
134 from
.y
= screenFrame
.bottom
;
135 to
.y
= screenFrame
.bottom
- Bounds().Height();
139 MoveTo(from
.x
+ _Factor() * (to
.x
- from
.x
),
140 from
.y
+ _Factor() * (to
.y
- from
.y
));
142 if (kMsgShow
&& IsHidden())
144 else if (fShowState
== 0 && kMsgHide
&& !IsHidden())
147 if ((how
== kMsgShow
&& fShowState
< kMaxShowState
)
148 || (how
== kMsgHide
&& fShowState
> kMinShowState
)) {
150 BMessageRunner::StartSending(this, &move
, kMoveDelay
, 1);
151 } else if (how
== kMsgShow
) {
152 // Hide the window once the mouse left its frame
153 BMessage
hide(kMsgHideWhenMouseMovedOut
);
154 hide
.AddMessenger("target", this);
155 hide
.AddInt32("what", kMsgHide
);
157 // The window might not span over the whole screen, but one dimension
158 // should be ignored for the cursor movements
159 BRect frame
= Frame();
163 frame
.top
= screenFrame
.top
;
164 frame
.bottom
= screenFrame
.bottom
;
168 frame
.left
= screenFrame
.left
;
169 frame
.right
= screenFrame
.right
;
172 hide
.AddRect("frame", frame
);
173 be_app
->PostMessage(&hide
);
179 PanelWindow::_Factor()
181 float factor
= 1.f
* fShowState
/ kMaxShowState
;
182 return 1 - (factor
- 1) * (factor
- 1);