~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/desktop/shell/panelview_win.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
*
 
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
 
10
*
 
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.
 
15
*/
 
16
 
 
17
#include "panelview.h"
 
18
 
 
19
#include <KDebug>
 
20
 
 
21
#include "panelcontroller.h"
 
22
 
 
23
#include <windows.h>
 
24
 
 
25
#define WM_APPBAR_CALLBACK ( WM_USER + 1010 )
 
26
 
 
27
 
 
28
bool PanelView::registerAccessBar(bool fRegister)
 
29
{
 
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;
 
35
 
 
36
        if(!SHAppBarMessage(ABM_NEW, &abd)) {
 
37
            kWarning() << "SHAppBarMessage( ABM_NEW ) failed";
 
38
            return false;
 
39
        }
 
40
 
 
41
        switch (location()) {
 
42
            case Plasma::TopEdge:
 
43
                abd.uEdge = ABE_TOP;
 
44
                break;
 
45
 
 
46
            case Plasma::BottomEdge:
 
47
                abd.uEdge = ABE_BOTTOM;
 
48
                break;
 
49
 
 
50
            case Plasma::LeftEdge:
 
51
                abd.uEdge = ABE_LEFT;
 
52
                break;
 
53
 
 
54
            case Plasma::RightEdge:
 
55
                abd.uEdge = ABE_RIGHT;
 
56
                break;
 
57
        }
 
58
        
 
59
        //appBarPosChanged();
 
60
 
 
61
    } else {
 
62
        SHAppBarMessage(ABM_REMOVE, &abd);
 
63
    }
 
64
    return true;
 
65
}
 
66
 
 
67
bool PanelView::winEvent( MSG* msg, long* result )
 
68
{
 
69
        *result = 0;
 
70
 
 
71
        switch( msg->message )
 
72
        {
 
73
        case WM_APPBAR_CALLBACK:
 
74
                appBarCallback( msg->wParam, msg->lParam );
 
75
            return true;
 
76
 
 
77
        case WM_ACTIVATE:
 
78
                SHAppBarMessage( ABM_ACTIVATE, &abd );
 
79
                break;
 
80
 
 
81
        case WM_WINDOWPOSCHANGED:
 
82
            SHAppBarMessage( ABM_WINDOWPOSCHANGED, &abd );
 
83
                break;
 
84
 
 
85
        default:
 
86
                return false;
 
87
        }
 
88
        
 
89
        return false;
 
90
}
 
91
 
 
92
void PanelView::appBarCallback( WPARAM msg, LPARAM lParam )
 
93
{
 
94
    uint uState;
 
95
    switch (msg) {
 
96
        case ABN_STATECHANGE:
 
97
            break;
 
98
 
 
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);
 
105
            }
 
106
            break;
 
107
 
 
108
        case ABN_POSCHANGED:
 
109
            appBarPosChanged();
 
110
            break;
 
111
    }
 
112
}
 
113
 
 
114
void PanelView::appBarPosChanged()
 
115
{
 
116
    RECT rc; 
 
117
 
 
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 );
 
122
 
 
123
    switch (location()) {
 
124
        case Plasma::TopEdge:
 
125
            abd.uEdge = ABE_TOP;
 
126
            rc.bottom = rc.top + height();
 
127
            break;
 
128
 
 
129
        case Plasma::BottomEdge:
 
130
            abd.uEdge = ABE_BOTTOM;
 
131
            rc.top = rc.bottom - height();
 
132
            break;
 
133
 
 
134
        case Plasma::LeftEdge:
 
135
            abd.uEdge = ABE_LEFT;
 
136
            rc.right = rc.left + width();
 
137
            break;
 
138
 
 
139
        case Plasma::RightEdge:
 
140
            abd.uEdge = ABE_RIGHT;
 
141
            rc.left = rc.right - width();
 
142
            break;
 
143
    }
 
144
    
 
145
    appBarQuerySetPos(&rc);
 
146
}
 
147
 
 
148
void PanelView::appBarQuerySetPos(LPRECT lprc)
 
149
{
 
150
    int iHeight = 0; 
 
151
    int iWidth = 0; 
 
152
 
 
153
    abd.rc = *lprc;
 
154
 
 
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(); 
 
163
    }
 
164
 
 
165
    // Query the system for an approved size and position.
 
166
    SHAppBarMessage(ABM_QUERYPOS, &abd);
 
167
 
 
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;
 
174
 
 
175
        case ABE_RIGHT:
 
176
            abd.rc.left = abd.rc.right - iWidth;
 
177
            break;
 
178
 
 
179
        case ABE_TOP:
 
180
            abd.rc.bottom = abd.rc.top + iHeight;
 
181
            break;
 
182
 
 
183
        case ABE_BOTTOM:
 
184
            abd.rc.top = abd.rc.bottom - iHeight;
 
185
            break;
 
186
    }
 
187
 
 
188
    // Pass the final bounding rectangle to the system. 
 
189
    SHAppBarMessage(ABM_SETPOS, &abd);
 
190
    
 
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); 
 
194
}