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