1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
/********************************************************************************
* *
* R o o t W i n d o w O b j e c t *
* *
*********************************************************************************
* Copyright (C) 1997,2022 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"
#include "fxmath.h"
#include "FXArray.h"
#include "FXHash.h"
#include "FXMutex.h"
#include "FXStream.h"
#include "FXString.h"
#include "FXSize.h"
#include "FXPoint.h"
#include "FXRectangle.h"
#include "FXStringDictionary.h"
#include "FXSettings.h"
#include "FXRegistry.h"
#include "FXVisual.h"
#include "FXEvent.h"
#include "FXWindow.h"
#include "FXApp.h"
#include "FXRootWindow.h"
/*
Notes:
- Size of FXRootWindow is now size of the entire virtual display, which
is a tiled virtual area of primary and secondary display adapters.
- Maybe getDefaultWidth() and getDefaultHeight() now returns virtual
screen size.
*/
#define DISPLAY(app) ((Display*)((app)->display))
using namespace FX;
/*******************************************************************************/
namespace FX {
// Object implementation
FXIMPLEMENT(FXRootWindow,FXComposite,nullptr,0)
// Construct root window
FXRootWindow::FXRootWindow(FXApp* a,FXVisual *vis):FXComposite(a,vis){
}
#ifdef WIN32
// Returns device context
FXID FXRootWindow::GetDC() const {
LockWindowUpdate(GetDesktopWindow());
return GetDCEx(GetDesktopWindow(),nullptr,DCX_CACHE|DCX_LOCKWINDOWUPDATE);
}
// Release DC
int FXRootWindow::ReleaseDC(FXID hdc) const {
int status=::ReleaseDC(GetDesktopWindow(),(HDC)hdc);
LockWindowUpdate(nullptr);
return status;
}
/*
// EnumDisplayMonitors callback routine to determine biggest screen size
static BOOL maxScreenSizeCallback(HMONITOR hmon,HDC hdc,LPRECT rect,LPARAM args){
MONITORINFO moninfo; FXint w,h;
moninfo.cbSize=sizeof(moninfo);
GetMonitorInfo(hmon,&moninfo);
w=moninfo.rcWork.right-moninfo.rcWork.left;
h=moninfo.rcWork.bottom-moninfo.rcWork.top;
if(((FXint*)args)[0]<w) ((FXint*)args)[0]=w;
if(((FXint*)args)[1]<h) ((FXint*)args)[1]=h;
return true;
}
// Obtain largest dimensions of all screens (bounding box)
static FXbool getMaxScreenSize(FXint& width,FXint& height){
FXint args[2]={0,0};
if(EnumDisplayMonitors(nullptr,nullptr,(MONITORENUMPROC)maxScreenSizeCallback,(LPARAM)args)){
width=args[0];
height=args[1];
return true;
}
return false;
}
*/
#endif
// When created, create subwindows ONLY
void FXRootWindow::create(){
if(!xid){
if(getApp()->isInitialized()){
FXTRACE((100,"%s::create %p\n",getClassName(),this));
// Got to have a visual
if(!visual){ fxerror("%s::create: trying to create window without a visual.\n",getClassName()); }
// Initialize visual
visual->create();
#ifdef WIN32
// Get handle of desktop window
xid=GetDesktopWindow();
// Obtain desktop window size
width=GetSystemMetrics(SM_CXVIRTUALSCREEN);
height=GetSystemMetrics(SM_CYVIRTUALSCREEN);
//HDC hdc=::GetDC((HWND)xid);
//width=GetDeviceCaps(hdc,HORZRES);
//height=GetDeviceCaps(hdc,VERTRES);
//::ReleaseDC((HWND)xid,hdc);
// Size of primary display screen
//width=GetSystemMetrics(SM_CXSCREEN);
//height=GetSystemMetrics(SM_CYSCREEN);
// Size bigger than all display screens
//getMaxScreenSize(width,height);
// Store for xid to C++ object mapping
getApp()->hash.insert((void*)xid,this);
#else
// Get handle of desktop window
xid=RootWindow(DISPLAY(getApp()),DefaultScreen(DISPLAY(getApp())));
// Obtain desktop window size
width=DisplayWidth(DISPLAY(getApp()),DefaultScreen(DISPLAY(getApp())));
height=DisplayHeight(DISPLAY(getApp()),DefaultScreen(DISPLAY(getApp())));
// Store for xid to C++ object mapping
getApp()->hash.insert((void*)xid,this);
#endif
// Normally create children
for(FXWindow *c=getFirst(); c; c=c->getNext()) c->create();
}
}
}
// Can not attach the root window
void FXRootWindow::attach(FXID){
}
// Can not detach the root window
void FXRootWindow::detach(){
}
// When destroyed, destroy subwindows ONLY
void FXRootWindow::destroy(){
if(xid){
if(getApp()->isInitialized()){
FXTRACE((100,"%s::destroy %p\n",getClassName(),this));
// Normally destroy children
for(FXWindow *c=getFirst(); c; c=c->getNext()) c->destroy();
// Remove from xid to C++ object mapping
getApp()->hash.remove((void*)xid);
}
xid=0;
}
}
// Get default width
FXint FXRootWindow::getDefaultWidth(){
#ifdef WIN32
// HDC hdc=::GetDC(GetDesktopWindow());
// FXint w=GetDeviceCaps(hdc,HORZRES);
// ::ReleaseDC(GetDesktopWindow(),hdc);
// return w;
return GetSystemMetrics(SM_CXVIRTUALSCREEN);
#else
return DisplayWidth(DISPLAY(getApp()),DefaultScreen(DISPLAY(getApp())));
#endif
}
// Get default height
FXint FXRootWindow::getDefaultHeight(){
#ifdef WIN32
// HDC hdc=::GetDC(GetDesktopWindow());
// FXint h=GetDeviceCaps(hdc,VERTRES);
// ::ReleaseDC(GetDesktopWindow(),hdc);
// return h;
return GetSystemMetrics(SM_CYVIRTUALSCREEN);
#else
return DisplayHeight(DISPLAY(getApp()),DefaultScreen(DISPLAY(getApp())));
#endif
}
// Moving root has no effect
void FXRootWindow::move(FXint,FXint){ }
// Move and resize root has no effect
void FXRootWindow::position(FXint,FXint,FXint,FXint){ }
// Resize root window has no effect
void FXRootWindow::resize(FXint,FXint){ }
// Layout of root window
void FXRootWindow::layout(){ }
// Mark as dirty
void FXRootWindow::recalc(){ }
// Root can not be focused on
void FXRootWindow::setFocus(){ }
// Root can not be unfocused
void FXRootWindow::killFocus(){ }
// Does not destroy root window
FXRootWindow::~FXRootWindow(){
xid=0;
}
}
|