dtor first
[personal-kdebase.git] / workspace / plasma / shells / desktop / panelview_win.cpp
bloba64f15c3b40c284970f883d411843c6a1e9e8b25
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU Library General Public License version 2,
4 * or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details
11 * You should have received a copy of the GNU Library General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #include "panelview.h"
19 #include <KDebug>
21 #include "panelcontroller.h"
23 #include <windows.h>
25 #define WM_APPBAR_CALLBACK ( WM_USER + 1010 )
28 bool PanelView::registerAccessBar(bool fRegister)
30 if(fRegister) {
31 setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
32 abd.cbSize = sizeof(APPBARDATA);
33 abd.hWnd = (HWND)winId();
34 abd.uCallbackMessage = WM_APPBAR_CALLBACK;
36 if(!SHAppBarMessage(ABM_NEW, &abd)) {
37 kWarning() << "SHAppBarMessage( ABM_NEW ) failed";
38 return false;
41 switch (location()) {
42 case Plasma::TopEdge:
43 abd.uEdge = ABE_TOP;
44 break;
46 case Plasma::BottomEdge:
47 abd.uEdge = ABE_BOTTOM;
48 break;
50 case Plasma::LeftEdge:
51 abd.uEdge = ABE_LEFT;
52 break;
54 case Plasma::RightEdge:
55 abd.uEdge = ABE_RIGHT;
56 break;
59 //appBarPosChanged();
61 } else {
62 SHAppBarMessage(ABM_REMOVE, &abd);
64 return true;
67 bool PanelView::winEvent( MSG* msg, long* result )
69 *result = 0;
71 switch( msg->message )
73 case WM_APPBAR_CALLBACK:
74 appBarCallback( msg->wParam, msg->lParam );
75 return true;
77 case WM_ACTIVATE:
78 SHAppBarMessage( ABM_ACTIVATE, &abd );
79 break;
81 case WM_WINDOWPOSCHANGED:
82 SHAppBarMessage( ABM_WINDOWPOSCHANGED, &abd );
83 break;
85 default:
86 return false;
89 return false;
92 void PanelView::appBarCallback( WPARAM msg, LPARAM lParam )
94 uint uState;
95 switch (msg) {
96 case ABN_STATECHANGE:
97 break;
99 case ABN_FULLSCREENAPP:
100 uState = SHAppBarMessage(ABM_GETSTATE, &abd);
101 if (lParam) {
102 SetWindowPos(winId(), (ABS_ALWAYSONTOP & uState) ? HWND_TOPMOST : HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
103 } else if (uState & ABS_ALWAYSONTOP) {
104 SetWindowPos(winId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
106 break;
108 case ABN_POSCHANGED:
109 appBarPosChanged();
110 break;
114 void PanelView::appBarPosChanged()
116 RECT rc;
118 // Get the area of the entire desktop
119 rc.left = rc.top = 0;
120 rc.right = GetSystemMetrics( SM_CXSCREEN );
121 rc.bottom = GetSystemMetrics( SM_CYSCREEN );
123 switch (location()) {
124 case Plasma::TopEdge:
125 abd.uEdge = ABE_TOP;
126 rc.bottom = rc.top + height();
127 break;
129 case Plasma::BottomEdge:
130 abd.uEdge = ABE_BOTTOM;
131 rc.top = rc.bottom - height();
132 break;
134 case Plasma::LeftEdge:
135 abd.uEdge = ABE_LEFT;
136 rc.right = rc.left + width();
137 break;
139 case Plasma::RightEdge:
140 abd.uEdge = ABE_RIGHT;
141 rc.left = rc.right - width();
142 break;
145 appBarQuerySetPos(&rc);
148 void PanelView::appBarQuerySetPos(LPRECT lprc)
150 int iHeight = 0;
151 int iWidth = 0;
153 abd.rc = *lprc;
155 if ((abd.uEdge == ABE_LEFT) || (abd.uEdge == ABE_RIGHT)) {
156 iWidth = abd.rc.right - abd.rc.left;
157 abd.rc.top = y();
158 abd.rc.bottom = y()+height();
159 } else {
160 iHeight = abd.rc.bottom - abd.rc.top;
161 abd.rc.left = x();
162 abd.rc.right = x()+width();
165 // Query the system for an approved size and position.
166 SHAppBarMessage(ABM_QUERYPOS, &abd);
168 // Adjust the rectangle, depending on the edge to which the
169 // appbar is anchored.
170 switch (abd.uEdge) {
171 case ABE_LEFT:
172 abd.rc.right = abd.rc.left + iWidth;
173 break;
175 case ABE_RIGHT:
176 abd.rc.left = abd.rc.right - iWidth;
177 break;
179 case ABE_TOP:
180 abd.rc.bottom = abd.rc.top + iHeight;
181 break;
183 case ABE_BOTTOM:
184 abd.rc.top = abd.rc.bottom - iHeight;
185 break;
188 // Pass the final bounding rectangle to the system.
189 SHAppBarMessage(ABM_SETPOS, &abd);
191 // Move and size the appbar so that it conforms to the
192 // bounding rectangle passed to the system.
193 //MoveWindow(winId(), abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true);