KDEUI
kwindowinfo_win.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the KDE libraries 00003 Copyright (C) 2008 Carlo Segato (brandon.ml@gmail.com) 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "kwindowinfo.h" 00022 #include "kwindowsystem.h" 00023 #include <windows.h> 00024 00025 class KWindowInfo::Private 00026 { 00027 public: 00028 Private() 00029 : properties(0),properties2(0) 00030 {} 00031 00032 ~Private() { } 00033 00034 WId win_; 00035 int ref; 00036 unsigned long properties; 00037 unsigned long properties2; 00038 private: 00039 Private( const Private& ); 00040 void operator=( const Private& ); 00041 }; 00042 00043 #include <QRect> 00044 00045 KWindowInfo::KWindowInfo( WId win, unsigned long properties, unsigned long properties2) : d ( new Private ) 00046 { 00047 d->ref = 1; 00048 d->win_ = win; 00049 d->properties = properties; 00050 d->properties2 = properties2; 00051 } 00052 00053 KWindowInfo::KWindowInfo() 00054 : d( NULL ) 00055 { 00056 00057 } 00058 00059 KWindowInfo::~KWindowInfo() 00060 { 00061 if( d != NULL ) { 00062 if( --d->ref == 0 ) { 00063 delete d; 00064 } 00065 } 00066 } 00067 00068 KWindowInfo::KWindowInfo( const KWindowInfo& wininfo ) 00069 : d( wininfo.d ) 00070 { 00071 if( d != NULL ) 00072 ++d->ref; 00073 } 00074 00075 KWindowInfo& KWindowInfo::operator=( const KWindowInfo& wininfo ) 00076 { 00077 if( d != wininfo.d ) { 00078 if( d != NULL ) 00079 if( --d->ref == 0 ) 00080 delete d; 00081 d = wininfo.d; 00082 if( d != NULL ) 00083 ++d->ref; 00084 } 00085 return *this; 00086 } 00087 00088 00089 bool KWindowInfo::valid( bool withdrawn_is_valid ) const 00090 { 00091 return true; 00092 } 00093 00094 WId KWindowInfo::win() const 00095 { 00096 return d->win_; 00097 } 00098 00099 unsigned long KWindowInfo::state() const 00100 { 00101 unsigned long state = 0; 00102 #ifndef _WIN32_WCE 00103 if(IsZoomed(d->win_)) 00104 state |= NET::Max; 00105 #endif 00106 if(!IsWindowVisible(d->win_)) 00107 state |= NET::Hidden; 00108 00109 #ifndef _WIN32_WCE 00110 LONG_PTR lp = GetWindowLongPtr(d->win_, GWL_EXSTYLE); 00111 if(lp & WS_EX_TOOLWINDOW) 00112 state |= NET::SkipTaskbar; 00113 #endif 00114 00115 return state; 00116 } 00117 00118 bool KWindowInfo::hasState( unsigned long s ) const 00119 { 00120 return (state() & s); 00121 } 00122 00123 bool KWindowInfo::isMinimized() const 00124 { 00125 #ifndef _WIN32_WCE 00126 return IsIconic(d->win_); 00127 #else 00128 return false; 00129 #endif 00130 } 00131 00132 NET::MappingState KWindowInfo::mappingState() const 00133 { 00134 #ifndef _WIN32_WCE 00135 if(IsIconic(d->win_)) 00136 return NET::Iconic; 00137 #endif 00138 if(!IsWindowVisible(d->win_)) 00139 return NET::Withdrawn; 00140 return NET::Visible; 00141 } 00142 00143 NETExtendedStrut KWindowInfo::extendedStrut() const 00144 { 00145 return NETExtendedStrut(); 00146 } 00147 00148 NET::WindowType KWindowInfo::windowType( int supported_types ) const 00149 { 00150 NET::WindowType wt(NET::Normal); 00151 00152 00153 long windowStyle = GetWindowLong(d->win_,GWL_STYLE); 00154 long windowStyleEx = GetWindowLong(d->win_,GWL_EXSTYLE); 00155 00156 if(windowStyle & WS_POPUP && supported_types & NET::PopupMenuMask) 00157 return NET::PopupMenu; 00158 else if(windowStyleEx & WS_EX_TOOLWINDOW && supported_types & NET::TooltipMask) 00159 return NET::Tooltip; 00160 else if(!(windowStyle & WS_CHILD) && supported_types & NET::NormalMask) 00161 return NET::Normal; 00162 00163 return wt; 00164 } 00165 00166 QString KWindowInfo::visibleNameWithState() const 00167 { 00168 return name(); 00169 } 00170 00171 QString KWindowInfo::visibleName() const 00172 { 00173 return name(); 00174 } 00175 00176 QString KWindowInfo::name() const 00177 { 00178 QByteArray windowText = QByteArray ( (GetWindowTextLength(d->win_)+1) * sizeof(wchar_t), 0 ) ; 00179 GetWindowTextW(d->win_, (LPWSTR)windowText.data(), windowText.size()); 00180 return QString::fromWCharArray((wchar_t*)windowText.data()); 00181 } 00182 00183 QString KWindowInfo::visibleIconNameWithState() const 00184 { 00185 return QString(); 00186 } 00187 00188 QString KWindowInfo::visibleIconName() const 00189 { 00190 return QString(); 00191 } 00192 00193 QString KWindowInfo::iconName() const 00194 { 00195 return QString(); 00196 } 00197 00198 bool KWindowInfo::isOnCurrentDesktop() const 00199 { 00200 return true; 00201 } 00202 00203 bool KWindowInfo::isOnDesktop( int desk ) const 00204 { 00205 return desk == desktop(); 00206 } 00207 00208 bool KWindowInfo::onAllDesktops() const 00209 { 00210 return false; 00211 } 00212 00213 int KWindowInfo::desktop() const 00214 { 00215 return 1; 00216 } 00217 00218 QRect KWindowInfo::geometry() const 00219 { 00220 RECT wndRect; 00221 memset(&wndRect,0,sizeof(wndRect)); 00222 00223 //fetch the geometry INCLUDING the frames 00224 if (GetWindowRect(d->win_,&wndRect)) { 00225 QRect result; 00226 result.setCoords ( wndRect.left, wndRect.top, wndRect.right, wndRect.bottom ); 00227 return result; 00228 } 00229 00230 return QRect(); 00231 } 00232 00233 QRect KWindowInfo::frameGeometry() const 00234 { 00235 RECT wndRect; 00236 memset(&wndRect,0,sizeof(wndRect)); 00237 00238 //fetch only client area geometries ... i hope thats right 00239 if(GetClientRect(d->win_,&wndRect)){ 00240 QRect result; 00241 result.setCoords ( wndRect.left, wndRect.top, wndRect.right, wndRect.bottom ); 00242 return result; 00243 } 00244 00245 return QRect(); 00246 } 00247 00248 bool KWindowInfo::actionSupported( NET::Action action ) const 00249 { 00250 return true; // no idea if it's supported or not -> pretend it is 00251 } 00252 00253 #if 0 00254 WId KWindowInfo::transientFor() const 00255 { 00256 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2TransientFor ) == 0, 176 ) 00257 << "Pass NET::WM2TransientFor to KWindowInfo"; 00258 return d->info->transientFor(); 00259 } 00260 00261 WId KWindowInfo::groupLeader() const 00262 { 00263 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2GroupLeader ) == 0, 176 ) 00264 << "Pass NET::WM2GroupLeader to KWindowInfo"; 00265 return d->info->groupLeader(); 00266 } 00267 00268 QByteArray KWindowInfo::windowClassClass() const 00269 { 00270 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 ) 00271 << "Pass NET::WM2WindowClass to KWindowInfo"; 00272 return d->info->windowClassClass(); 00273 } 00274 00275 QByteArray KWindowInfo::windowClassName() const 00276 { 00277 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 ) 00278 << "Pass NET::WM2WindowClass to KWindowInfo"; 00279 return d->info->windowClassName(); 00280 } 00281 00282 QByteArray KWindowInfo::windowRole() const 00283 { 00284 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowRole ) == 0, 176 ) 00285 << "Pass NET::WM2WindowRole to KWindowInfo"; 00286 return d->info->windowRole(); 00287 } 00288 00289 QByteArray KWindowInfo::clientMachine() const 00290 { 00291 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2ClientMachine ) == 0, 176 ) 00292 << "Pass NET::WM2ClientMachine to KWindowInfo"; 00293 return d->info->clientMachine(); 00294 } 00295 00296 bool KWindowInfo::actionSupported( NET::Action action ) const 00297 { 00298 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2AllowedActions ) == 0, 176 ) 00299 << "Pass NET::WM2AllowedActions to KWindowInfo"; 00300 if( KWindowSystem::allowedActionsSupported()) 00301 return d->info->allowedActions() & action; 00302 else 00303 return true; // no idea if it's supported or not -> pretend it is 00304 } 00305 00306 // see NETWM spec section 7.6 00307 bool KWindowInfo::isMinimized() const 00308 { 00309 if( mappingState() != NET::Iconic ) 00310 return false; 00311 // NETWM 1.2 compliant WM - uses NET::Hidden for minimized windows 00312 if(( state() & NET::Hidden ) != 0 00313 && ( state() & NET::Shaded ) == 0 ) // shaded may have NET::Hidden too 00314 return true; 00315 // older WMs use WithdrawnState for other virtual desktops 00316 // and IconicState only for minimized 00317 return KWindowSystem::icccmCompliantMappingState() ? false : true; 00318 } 00319 #endif
KDE 4.6 API Reference