19 #define NTDDI_VERSION NTDDI_WINBLUE 27 #if defined(CAIRO_HAS_WIN32_SURFACE) && !defined(__CYGWIN__) 28 #define USE_WIN32_SURFACE 29 #elif defined(CAIRO_HAS_XLIB_SURFACE) && !defined(MAC_OSX_TK) 31 #include <cairo/cairo-xlib.h> 42 #include <shellscalingapi.h> 43 #ifdef USE_WIN32_SURFACE 44 #include <cairo/cairo-win32.h> 48 #if defined(MAC_OSX_TK) 49 #include <Carbon/Carbon.h> 50 #include <cairo/cairo-quartz.h> 61 #ifdef USE_WIN32_SURFACE 62 #elif defined(MAC_OSX_TK) 69 char errorMessage[256];
70 XGetErrorText(ev->display, ev->error_code, errorMessage,
sizeof(errorMessage));
71 fputs(errorMessage,stderr);
78 void blit(
const Winfo& winfo,
int x,
int y,
int width,
int height)
80 #ifdef USE_WIN32_SURFACE 82 HDC dc=BeginPaint(winfo.childWindowId, &ps);
83 BitBlt(dc, x, y, width,height,winfo.hdcMem,x,y,SRCCOPY);
84 EndPaint(winfo.childWindowId, &ps);
86 #elif defined(USE_X11) 87 static mutex blitting;
88 const lock_guard<mutex> lock(blitting);
89 XCopyArea(winfo.display, winfo.bufferWindowId, winfo.childWindowId, winfo.graphicsContext, x, y, width, height, x, y);
90 XFlush(winfo.display);
91 XRaiseWindow(winfo.display, winfo.childWindowId);
96 WindowInformation::~WindowInformation()
98 bufferSurface.reset();
99 #ifdef USE_WIN32_SURFACE 100 SelectObject(hdcMem, hOld);
101 DeleteObject(hbmMem);
103 SetWindowLongPtrA(childWindowId, GWLP_USERDATA, 0);
104 PostMessageA(childWindowId,WM_CLOSE,0,0);
105 #elif defined(MAC_OSX_TK) 106 #elif defined(USE_X11) 107 XFreeGC(display, graphicsContext);
108 XDestroyWindow(display, childWindowId);
109 XDestroyWindow(display, bufferWindowId);
113 const ecolab::cairo::SurfacePtr& WindowInformation::getBufferSurface()
const 115 return bufferSurface;
118 void WindowInformation::copyBufferToMain()
120 cairo_surface_flush(bufferSurface->surface());
121 #ifdef USE_WIN32_SURFACE 122 InvalidateRect(childWindowId,
nullptr,
true);
123 PostMessageA(childWindowId,WM_PAINT,0,0);
124 #elif defined(USE_X11) 126 blit(*
this,0,0,childWidth,childHeight);
132 XExposeEvent& expose=
event.xexpose;
135 expose.width=childWidth;
136 expose.height=childHeight;
137 expose.window=childWindowId;
138 expose.display=display;
143 XSendEvent(display,childWindowId,
false,ExposureMask,&event);
149 #ifdef USE_WIN32_SURFACE 150 LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
155 if (
WindowInformation* winfo=reinterpret_cast<WindowInformation*>(GetWindowLongPtr(hwnd, GWLP_USERDATA)))
158 if (GetUpdateRect(hwnd,&r,
false))
159 blit(*winfo, r.left, r.top, r.right-r.left, r.bottom-r.top);
163 return HTTRANSPARENT;
167 return DefWindowProc(hwnd, msg, wparam, lparam);
173 void WindowInformation::EventThread::run()
175 #if defined(_PTHREAD_H) && defined(__USE_GNU) && !defined(NDEBUG) 176 pthread_setname_np(pthread_self(),
"event handler");
178 this_thread::sleep_for(1000ms);
189 eventReceived=XCheckWindowEvent(display, childWindowId, ExposureMask|StructureNotifyMask, &event);
192 this_thread::sleep_for(50ms);
198 blit(*
this,event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height);
204 catch (
const std::exception& ex)
207 cerr << ex.what() << endl;
210 catch (...) {
return;}
214 WindowInformation::WindowInformation(uint64_t parentWin,
int left,
int top,
int cWidth,
int cHeight,
215 double sf,
bool hasScrollBars,
const std::function<
void(
void)>& draw):
217 Winfo(NSContext(reinterpret_cast<void*>(parentWin),left,top,cWidth,cHeight,*this)), draw(draw),
219 hasScrollBars(hasScrollBars)
234 #ifdef USE_WIN32_SURFACE 235 parentWindowId =
reinterpret_cast<HWND
>(parentWin);
240 DEVICE_SCALE_FACTOR scaleFactor;
241 GetScaleFactorForMonitor(MonitorFromWindow(parentWindowId, MONITOR_DEFAULTTONEAREST), &scaleFactor);
242 sf=int(scaleFactor)/100.0;
254 GetWindowRect(parentWindowId,&window);
255 GetClientRect(parentWindowId,&client);
256 POINT clientTopLeft{client.left,client.top};
257 ClientToScreen(parentWindowId,&clientTopLeft);
259 auto offs=clientTopLeft.y-window.top;
261 auto style=GetWindowLong(parentWindowId,GWL_STYLE);
262 if (style & WS_BORDER) offs-=GetSystemMetrics(SM_CYBORDER);
263 if (style & WS_THICKFRAME) offs-=GetSystemMetrics(SM_CYSIZEFRAME);
266 SetWindowLongPtrA(parentWindowId, GWL_STYLE, style|WS_CLIPCHILDREN);
267 childWindowId=CreateWindowA(
"Button",
"", WS_CHILD | WS_VISIBLE|WS_CLIPSIBLINGS,
offsetLeft,
offsetTop,
childWidth,
childHeight, parentWindowId,
nullptr,
nullptr,
nullptr);
269 HDC hdc=GetDC(childWindowId);
270 hdcMem=CreateCompatibleDC(hdc);
272 ReleaseDC(parentWindowId, hdc);
273 hOld=SelectObject(hdcMem, hbmMem);
276 cairo_surface_set_device_scale(
bufferSurface->surface(), sf, sf);
277 SetWindowLongPtrA(childWindowId, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(
this));
278 SetWindowLongPtrA(childWindowId, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(windowProc));
279 #elif defined(USE_X11) 280 parentWindowId = parentWin;
281 static const bool errorHandlingSet = (XSetErrorHandler(
throwOnXError),
true);
282 display = XOpenDisplay(
nullptr);
283 const int err = XGetWindowAttributes(display, parentWin, &wAttr);
285 throw runtime_error(
"Invalid window: " +
to_string(parentWin));
289 childWindowId = XCreateWindow(display, parentWin,
offsetLeft,
offsetTop,
childWidth,
childHeight, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0,
nullptr);
291 graphicsContext=XCreateGC(display, childWindowId, 0,
nullptr);
293 XMapWindow(display, childWindowId);
297 XSelectInput(display, childWindowId, ExposureMask|StructureNotifyMask);
298 eventThread.reset(
new EventThread(*
this));
306 nsContext.requestRedraw();
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state cha...
string to_string(CONST84 char *x)