KDEUI
kwindowinfo_win.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 if(IsZoomed(d->win_))
00103 state |= NET::Max;
00104 if(!IsWindowVisible(d->win_))
00105 state |= NET::Hidden;
00106
00107 LONG_PTR lp = GetWindowLongPtr(d->win_, GWL_EXSTYLE);
00108 if(lp & WS_EX_TOOLWINDOW)
00109 state |= NET::SkipTaskbar;
00110
00111 return state;
00112 }
00113
00114 bool KWindowInfo::hasState( unsigned long s ) const
00115 {
00116 return (state() & s);
00117 }
00118
00119 bool KWindowInfo::isMinimized() const
00120 {
00121 return IsIconic(d->win_);
00122 }
00123
00124 NET::MappingState KWindowInfo::mappingState() const
00125 {
00126 if(IsIconic(d->win_))
00127 return NET::Iconic;
00128 if(!IsWindowVisible(d->win_))
00129 return NET::Withdrawn;
00130 return NET::Visible;
00131 }
00132
00133 NETExtendedStrut KWindowInfo::extendedStrut() const
00134 {
00135 return NETExtendedStrut();
00136 }
00137
00138 NET::WindowType KWindowInfo::windowType( int supported_types ) const
00139 {
00140 NET::WindowType wt(NET::Normal);
00141
00142
00143 long windowStyle = GetWindowLong(d->win_,GWL_STYLE);
00144 long windowStyleEx = GetWindowLong(d->win_,GWL_EXSTYLE);
00145
00146 if(windowStyle & WS_POPUP && supported_types & NET::PopupMenuMask)
00147 return NET::PopupMenu;
00148 else if(windowStyleEx & WS_EX_TOOLWINDOW && supported_types & NET::TooltipMask)
00149 return NET::Tooltip;
00150 else if(!windowStyle & WS_CHILD && supported_types & NET::NormalMask)
00151 return NET::Normal;
00152
00153 return wt;
00154 }
00155
00156 QString KWindowInfo::visibleNameWithState() const
00157 {
00158 return name();
00159 }
00160
00161 QString KWindowInfo::visibleName() const
00162 {
00163 return name();
00164 }
00165
00166 QString KWindowInfo::name() const
00167 {
00168 QByteArray windowText = QByteArray ( GetWindowTextLength(d->win_)+1, 0 ) ;
00169 GetWindowTextA(d->win_, windowText.data(), windowText.size());
00170 return QString(windowText);
00171 }
00172
00173 QString KWindowInfo::visibleIconNameWithState() const
00174 {
00175 return QString();
00176 }
00177
00178 QString KWindowInfo::visibleIconName() const
00179 {
00180 return QString();
00181 }
00182
00183 QString KWindowInfo::iconName() const
00184 {
00185 return QString();
00186 }
00187
00188 bool KWindowInfo::isOnCurrentDesktop() const
00189 {
00190 return true;
00191 }
00192
00193 bool KWindowInfo::isOnDesktop( int desk ) const
00194 {
00195 if(desk == desktop())
00196 return true;
00197 return false;
00198 }
00199
00200 bool KWindowInfo::onAllDesktops() const
00201 {
00202 return false;
00203 }
00204
00205 int KWindowInfo::desktop() const
00206 {
00207 return 0;
00208 }
00209
00210 QRect KWindowInfo::geometry() const
00211 {
00212 RECT wndRect;
00213 memset(&wndRect,0,sizeof(wndRect));
00214
00215
00216 if(GetWindowRect(d->win_,&wndRect)){
00217 QRect result;
00218 result.setCoords ( wndRect.left, wndRect.top, wndRect.right, wndRect.bottom );
00219 return result;
00220 }
00221
00222 return QRect();
00223 }
00224
00225 QRect KWindowInfo::frameGeometry() const
00226 {
00227 RECT wndRect;
00228 memset(&wndRect,0,sizeof(wndRect));
00229
00230
00231 if(GetClientRect(d->win_,&wndRect)){
00232 QRect result;
00233 result.setCoords ( wndRect.left, wndRect.top, wndRect.right, wndRect.bottom );
00234 return result;
00235 }
00236
00237 return QRect();
00238 }
00239
00240 bool KWindowInfo::actionSupported( NET::Action action ) const
00241 {
00242 return true;
00243 }
00244
00245 #if 0
00246 WId KWindowInfo::transientFor() const
00247 {
00248 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2TransientFor ) == 0, 176 )
00249 << "Pass NET::WM2TransientFor to KWindowInfo" << endl;
00250 return d->info->transientFor();
00251 }
00252
00253 WId KWindowInfo::groupLeader() const
00254 {
00255 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2GroupLeader ) == 0, 176 )
00256 << "Pass NET::WM2GroupLeader to KWindowInfo" << endl;
00257 return d->info->groupLeader();
00258 }
00259
00260 QByteArray KWindowInfo::windowClassClass() const
00261 {
00262 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
00263 << "Pass NET::WM2WindowClass to KWindowInfo" << endl;
00264 return d->info->windowClassClass();
00265 }
00266
00267 QByteArray KWindowInfo::windowClassName() const
00268 {
00269 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
00270 << "Pass NET::WM2WindowClass to KWindowInfo" << endl;
00271 return d->info->windowClassName();
00272 }
00273
00274 QByteArray KWindowInfo::windowRole() const
00275 {
00276 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowRole ) == 0, 176 )
00277 << "Pass NET::WM2WindowRole to KWindowInfo" << endl;
00278 return d->info->windowRole();
00279 }
00280
00281 QByteArray KWindowInfo::clientMachine() const
00282 {
00283 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2ClientMachine ) == 0, 176 )
00284 << "Pass NET::WM2ClientMachine to KWindowInfo" << endl;
00285 return d->info->clientMachine();
00286 }
00287
00288 bool KWindowInfo::actionSupported( NET::Action action ) const
00289 {
00290 kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2AllowedActions ) == 0, 176 )
00291 << "Pass NET::WM2AllowedActions to KWindowInfo" << endl;
00292 if( KWindowSystem::allowedActionsSupported())
00293 return d->info->allowedActions() & action;
00294 else
00295 return true;
00296 }
00297
00298
00299 bool KWindowInfo::isMinimized() const
00300 {
00301 if( mappingState() != NET::Iconic )
00302 return false;
00303
00304 if(( state() & NET::Hidden ) != 0
00305 && ( state() & NET::Shaded ) == 0 )
00306 return true;
00307
00308
00309 return KWindowSystem::icccmCompliantMappingState() ? false : true;
00310 }
00311 #endif