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"
21 #include "panelcontroller.h"
25 #define WM_APPBAR_CALLBACK ( WM_USER + 1010 )
28 bool PanelView::registerAccessBar(bool 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";
46 case Plasma::BottomEdge
:
47 abd
.uEdge
= ABE_BOTTOM
;
50 case Plasma::LeftEdge
:
54 case Plasma::RightEdge
:
55 abd
.uEdge
= ABE_RIGHT
;
62 SHAppBarMessage(ABM_REMOVE
, &abd
);
67 bool PanelView::winEvent( MSG
* msg
, long* result
)
71 switch( msg
->message
)
73 case WM_APPBAR_CALLBACK
:
74 appBarCallback( msg
->wParam
, msg
->lParam
);
78 SHAppBarMessage( ABM_ACTIVATE
, &abd
);
81 case WM_WINDOWPOSCHANGED
:
82 SHAppBarMessage( ABM_WINDOWPOSCHANGED
, &abd
);
92 void PanelView::appBarCallback( WPARAM msg
, LPARAM lParam
)
99 case ABN_FULLSCREENAPP
:
100 uState
= SHAppBarMessage(ABM_GETSTATE
, &abd
);
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
);
114 void PanelView::appBarPosChanged()
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
:
126 rc
.bottom
= rc
.top
+ height();
129 case Plasma::BottomEdge
:
130 abd
.uEdge
= ABE_BOTTOM
;
131 rc
.top
= rc
.bottom
- height();
134 case Plasma::LeftEdge
:
135 abd
.uEdge
= ABE_LEFT
;
136 rc
.right
= rc
.left
+ width();
139 case Plasma::RightEdge
:
140 abd
.uEdge
= ABE_RIGHT
;
141 rc
.left
= rc
.right
- width();
145 appBarQuerySetPos(&rc
);
148 void PanelView::appBarQuerySetPos(LPRECT lprc
)
155 if ((abd
.uEdge
== ABE_LEFT
) || (abd
.uEdge
== ABE_RIGHT
)) {
156 iWidth
= abd
.rc
.right
- abd
.rc
.left
;
158 abd
.rc
.bottom
= y()+height();
160 iHeight
= abd
.rc
.bottom
- abd
.rc
.top
;
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.
172 abd
.rc
.right
= abd
.rc
.left
+ iWidth
;
176 abd
.rc
.left
= abd
.rc
.right
- iWidth
;
180 abd
.rc
.bottom
= abd
.rc
.top
+ iHeight
;
184 abd
.rc
.top
= abd
.rc
.bottom
- iHeight
;
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);