2016-02-10 19:49:35 +00:00
|
|
|
//
|
|
|
|
|
// "$Id$"
|
|
|
|
|
//
|
2018-02-09 14:39:42 +00:00
|
|
|
// Windows screen interface for the Fast Light Tool Kit (FLTK).
|
2016-02-10 19:49:35 +00:00
|
|
|
//
|
2018-01-31 21:17:17 +00:00
|
|
|
// Copyright 1998-2018 by Bill Spitzak and others.
|
2016-02-10 19:49:35 +00:00
|
|
|
//
|
|
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
|
//
|
|
|
|
|
// http://www.fltk.org/COPYING.php
|
|
|
|
|
//
|
|
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
|
//
|
|
|
|
|
// http://www.fltk.org/str.php
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "../../config_lib.h"
|
2016-02-26 16:12:43 +00:00
|
|
|
#include "Fl_WinAPI_Screen_Driver.H"
|
2016-04-02 15:37:03 +00:00
|
|
|
#include "../GDI/Fl_Font.H"
|
2016-02-13 16:12:57 +00:00
|
|
|
#include <FL/Fl.H>
|
2018-01-31 21:17:17 +00:00
|
|
|
#include <FL/platform.H>
|
2016-02-18 16:21:51 +00:00
|
|
|
#include <FL/Fl_Graphics_Driver.H>
|
2016-08-23 09:38:46 +00:00
|
|
|
#include <FL/Fl_RGB_Image.H>
|
2016-02-17 11:23:26 +00:00
|
|
|
#include <FL/fl_ask.H>
|
2016-02-13 12:57:00 +00:00
|
|
|
#include <stdio.h>
|
2016-02-10 19:49:35 +00:00
|
|
|
|
2016-02-15 13:52:58 +00:00
|
|
|
|
|
|
|
|
// these are set by Fl::args() and override any system colors: from Fl_get_system_colors.cxx
|
|
|
|
|
extern const char *fl_fg;
|
|
|
|
|
extern const char *fl_bg;
|
|
|
|
|
extern const char *fl_bg2;
|
|
|
|
|
// end of extern additions workaround
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 12:57:00 +00:00
|
|
|
#if !defined(HMONITOR_DECLARED) && (_WIN32_WINNT < 0x0500)
|
|
|
|
|
# define COMPILE_MULTIMON_STUBS
|
|
|
|
|
# include <multimon.h>
|
|
|
|
|
#endif // !HMONITOR_DECLARED && _WIN32_WINNT < 0x0500
|
2016-02-10 21:02:38 +00:00
|
|
|
|
2016-02-10 19:49:35 +00:00
|
|
|
|
2016-04-12 07:07:21 +00:00
|
|
|
/*
|
2016-02-10 19:49:35 +00:00
|
|
|
Creates a driver that manages all screen and display related calls.
|
2016-02-15 13:52:58 +00:00
|
|
|
|
2016-04-12 07:07:21 +00:00
|
|
|
This function must be implemented once for every platform.
|
2016-02-10 19:49:35 +00:00
|
|
|
*/
|
|
|
|
|
Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver()
|
|
|
|
|
{
|
|
|
|
|
return new Fl_WinAPI_Screen_Driver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-15 13:52:58 +00:00
|
|
|
int Fl_WinAPI_Screen_Driver::visual(int flags)
|
2016-02-13 16:12:57 +00:00
|
|
|
{
|
|
|
|
|
fl_GetDC(0);
|
|
|
|
|
if (flags & FL_DOUBLE) return 0;
|
2016-11-09 09:49:48 +00:00
|
|
|
HDC gc = (HDC)Fl_Graphics_Driver::default_driver().gc();
|
2016-02-13 16:12:57 +00:00
|
|
|
if (!(flags & FL_INDEX) &&
|
2016-02-18 16:21:51 +00:00
|
|
|
GetDeviceCaps(gc,BITSPIXEL) <= 8) return 0;
|
|
|
|
|
if ((flags & FL_RGB8) && GetDeviceCaps(gc,BITSPIXEL)<24) return 0;
|
2016-02-13 16:12:57 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-10 21:02:38 +00:00
|
|
|
// We go the much more difficult route of individually picking some multi-screen
|
|
|
|
|
// functions from the USER32.DLL . If these functions are not available, we
|
|
|
|
|
// will gracefully fall back to single monitor support.
|
|
|
|
|
//
|
|
|
|
|
// If we were to insist on the existence of "EnumDisplayMonitors" and
|
|
|
|
|
// "GetMonitorInfoA", it would be impossible to use FLTK on Windows 2000
|
|
|
|
|
// before SP2 or earlier.
|
|
|
|
|
|
|
|
|
|
// BOOL EnumDisplayMonitors(HDC, LPCRECT, MONITORENUMPROC, LPARAM)
|
|
|
|
|
typedef BOOL(WINAPI* fl_edm_func)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
|
|
|
|
|
// BOOL GetMonitorInfo(HMONITOR, LPMONITORINFO)
|
|
|
|
|
typedef BOOL(WINAPI* fl_gmi_func)(HMONITOR, LPMONITORINFO);
|
|
|
|
|
|
|
|
|
|
static fl_gmi_func fl_gmi = NULL; // used to get a proc pointer for GetMonitorInfoA
|
|
|
|
|
|
|
|
|
|
|
2016-02-15 13:52:58 +00:00
|
|
|
BOOL Fl_WinAPI_Screen_Driver::screen_cb(HMONITOR mon, HDC hdc, LPRECT r, LPARAM d)
|
2016-02-10 21:02:38 +00:00
|
|
|
{
|
|
|
|
|
Fl_WinAPI_Screen_Driver *drv = (Fl_WinAPI_Screen_Driver*)d;
|
|
|
|
|
return drv->screen_cb(mon, hdc, r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-15 13:52:58 +00:00
|
|
|
BOOL Fl_WinAPI_Screen_Driver::screen_cb(HMONITOR mon, HDC, LPRECT r)
|
2016-02-10 21:02:38 +00:00
|
|
|
{
|
|
|
|
|
if (num_screens >= MAX_SCREENS) return TRUE;
|
|
|
|
|
|
|
|
|
|
MONITORINFOEX mi;
|
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
|
|
|
|
|
|
// GetMonitorInfo(mon, &mi);
|
|
|
|
|
// (but we use our self-acquired function pointer instead)
|
|
|
|
|
if (fl_gmi(mon, &mi)) {
|
|
|
|
|
screens[num_screens] = mi.rcMonitor;
|
|
|
|
|
// If we also want to record the work area, we would also store mi.rcWork at this point
|
|
|
|
|
work_area[num_screens] = mi.rcWork;
|
|
|
|
|
num_screens++;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-10 19:49:35 +00:00
|
|
|
void Fl_WinAPI_Screen_Driver::init()
|
|
|
|
|
{
|
2017-08-19 07:29:26 +00:00
|
|
|
open_display();
|
2016-02-10 21:02:38 +00:00
|
|
|
// Since not all versions of Windows include multiple monitor support,
|
|
|
|
|
// we do a run-time check for the required functions...
|
|
|
|
|
HMODULE hMod = GetModuleHandle("USER32.DLL");
|
|
|
|
|
|
|
|
|
|
if (hMod) {
|
|
|
|
|
// check that EnumDisplayMonitors is available
|
|
|
|
|
fl_edm_func fl_edm = (fl_edm_func)GetProcAddress(hMod, "EnumDisplayMonitors");
|
|
|
|
|
|
|
|
|
|
if (fl_edm) {
|
|
|
|
|
// we have EnumDisplayMonitors - do we also have GetMonitorInfoA ?
|
|
|
|
|
fl_gmi = (fl_gmi_func)GetProcAddress(hMod, "GetMonitorInfoA");
|
|
|
|
|
if (fl_gmi) {
|
|
|
|
|
// We have GetMonitorInfoA, enumerate all the screens...
|
|
|
|
|
// EnumDisplayMonitors(0,0,screen_cb,0);
|
|
|
|
|
// (but we use our self-acquired function pointer instead)
|
|
|
|
|
// NOTE: num_screens is incremented in screen_cb so we must first reset it here...
|
|
|
|
|
num_screens = 0;
|
|
|
|
|
fl_edm(0, 0, screen_cb, (LPARAM)this);
|
2019-06-16 10:00:38 +00:00
|
|
|
goto way_out;
|
2016-02-10 21:02:38 +00:00
|
|
|
}
|
2016-02-10 19:49:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-02-10 21:02:38 +00:00
|
|
|
|
|
|
|
|
// If we get here, assume we have 1 monitor...
|
|
|
|
|
num_screens = 1;
|
|
|
|
|
screens[0].top = 0;
|
|
|
|
|
screens[0].left = 0;
|
|
|
|
|
screens[0].right = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
|
screens[0].bottom = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
|
work_area[0] = screens[0];
|
2019-06-16 10:00:38 +00:00
|
|
|
way_out:
|
2019-06-18 11:35:39 +00:00
|
|
|
desktop_scale_factor();
|
2016-02-10 19:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::screen_work_area(int &X, int &Y, int &W, int &H, int n)
|
|
|
|
|
{
|
|
|
|
|
if (num_screens < 0) init();
|
|
|
|
|
if (n < 0 || n >= num_screens) n = 0;
|
2017-06-29 09:44:35 +00:00
|
|
|
X = work_area[n].left/scale_of_screen[n];
|
|
|
|
|
Y = work_area[n].top/scale_of_screen[n];
|
2019-02-28 17:06:32 +00:00
|
|
|
W = (work_area[n].right - work_area[n].left)/scale_of_screen[n];
|
|
|
|
|
H = (work_area[n].bottom - work_area[n].top)/scale_of_screen[n];
|
2016-02-10 19:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::screen_xywh(int &X, int &Y, int &W, int &H, int n)
|
|
|
|
|
{
|
|
|
|
|
if (num_screens < 0) init();
|
|
|
|
|
|
|
|
|
|
if ((n < 0) || (n >= num_screens))
|
|
|
|
|
n = 0;
|
|
|
|
|
|
2016-02-10 21:02:38 +00:00
|
|
|
if (num_screens > 0) {
|
2017-06-29 09:44:35 +00:00
|
|
|
X = screens[n].left/scale_of_screen[n];
|
|
|
|
|
Y = screens[n].top/scale_of_screen[n];
|
|
|
|
|
W = (screens[n].right - screens[n].left)/scale_of_screen[n];
|
|
|
|
|
H = (screens[n].bottom - screens[n].top)/scale_of_screen[n];
|
2016-02-10 21:02:38 +00:00
|
|
|
} else {
|
|
|
|
|
/* Fallback if something is broken... */
|
|
|
|
|
X = 0;
|
|
|
|
|
Y = 0;
|
|
|
|
|
W = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
|
H = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
|
}
|
2016-02-10 19:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::screen_dpi(float &h, float &v, int n)
|
|
|
|
|
{
|
|
|
|
|
if (num_screens < 0) init();
|
|
|
|
|
h = v = 0.0f;
|
|
|
|
|
if (n >= 0 && n < num_screens) {
|
2016-02-10 21:02:38 +00:00
|
|
|
h = float(dpi[n][0]);
|
|
|
|
|
v = float(dpi[n][1]);
|
2016-02-10 19:49:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-10 22:43:45 +00:00
|
|
|
|
2016-02-10 21:02:38 +00:00
|
|
|
int Fl_WinAPI_Screen_Driver::x()
|
|
|
|
|
{
|
2018-11-26 20:55:23 +00:00
|
|
|
/*RECT r;
|
2016-02-10 21:02:38 +00:00
|
|
|
|
|
|
|
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
|
2018-11-26 20:55:23 +00:00
|
|
|
return r.left;*/
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
screen_work_area(X, Y, W, H, 0);
|
|
|
|
|
return X;
|
2016-02-10 21:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-10 22:43:45 +00:00
|
|
|
|
2016-02-10 21:02:38 +00:00
|
|
|
int Fl_WinAPI_Screen_Driver::y()
|
|
|
|
|
{
|
2018-11-26 20:55:23 +00:00
|
|
|
/*RECT r;
|
2016-02-10 21:02:38 +00:00
|
|
|
|
|
|
|
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
|
2018-11-26 20:55:23 +00:00
|
|
|
return r.top;*/
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
screen_work_area(X, Y, W, H, 0);
|
|
|
|
|
return Y;
|
2016-02-10 21:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-10 22:43:45 +00:00
|
|
|
|
2016-02-10 21:02:38 +00:00
|
|
|
int Fl_WinAPI_Screen_Driver::h()
|
|
|
|
|
{
|
2018-11-26 20:55:23 +00:00
|
|
|
/*RECT r;
|
2016-02-10 21:02:38 +00:00
|
|
|
|
|
|
|
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
|
2018-11-26 20:55:23 +00:00
|
|
|
return r.bottom - r.top;*/
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
screen_work_area(X, Y, W, H, 0);
|
|
|
|
|
return H;
|
2016-02-10 21:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-10 22:43:45 +00:00
|
|
|
|
2016-02-10 21:02:38 +00:00
|
|
|
int Fl_WinAPI_Screen_Driver::w()
|
|
|
|
|
{
|
2018-11-26 20:55:23 +00:00
|
|
|
/*RECT r;
|
2016-02-10 21:02:38 +00:00
|
|
|
|
|
|
|
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
|
2018-11-26 20:55:23 +00:00
|
|
|
return r.right - r.left;*/
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
screen_work_area(X, Y, W, H, 0);
|
|
|
|
|
return W;
|
2016-02-10 21:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-10 19:49:35 +00:00
|
|
|
|
2016-02-10 22:43:45 +00:00
|
|
|
void Fl_WinAPI_Screen_Driver::beep(int type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case FL_BEEP_QUESTION :
|
|
|
|
|
case FL_BEEP_PASSWORD :
|
|
|
|
|
MessageBeep(MB_ICONQUESTION);
|
|
|
|
|
break;
|
|
|
|
|
case FL_BEEP_MESSAGE :
|
|
|
|
|
MessageBeep(MB_ICONASTERISK);
|
|
|
|
|
break;
|
|
|
|
|
case FL_BEEP_NOTIFICATION :
|
|
|
|
|
MessageBeep(MB_ICONASTERISK);
|
|
|
|
|
break;
|
|
|
|
|
case FL_BEEP_ERROR :
|
|
|
|
|
MessageBeep(MB_ICONERROR);
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
MessageBeep(0xFFFFFFFF);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-11 00:10:49 +00:00
|
|
|
void Fl_WinAPI_Screen_Driver::flush()
|
|
|
|
|
{
|
|
|
|
|
GdiFlush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 16:12:57 +00:00
|
|
|
extern void fl_fix_focus(); // in Fl.cxx
|
|
|
|
|
|
|
|
|
|
// We have to keep track of whether we have captured the mouse, since
|
2018-02-09 14:39:42 +00:00
|
|
|
// Windows shows little respect for this... Grep for fl_capture to
|
2016-02-13 16:12:57 +00:00
|
|
|
// see where and how this is used.
|
|
|
|
|
extern HWND fl_capture;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::grab(Fl_Window* win)
|
|
|
|
|
{
|
|
|
|
|
if (win) {
|
|
|
|
|
if (!Fl::grab_) {
|
|
|
|
|
SetActiveWindow(fl_capture = fl_xid(Fl::first_window()));
|
|
|
|
|
SetCapture(fl_capture);
|
|
|
|
|
}
|
|
|
|
|
Fl::grab_ = win;
|
|
|
|
|
} else {
|
|
|
|
|
if (Fl::grab_) {
|
|
|
|
|
fl_capture = 0;
|
|
|
|
|
ReleaseCapture();
|
|
|
|
|
Fl::grab_ = 0;
|
|
|
|
|
fl_fix_focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 13:17:29 +00:00
|
|
|
static void set_selection_color(uchar r, uchar g, uchar b)
|
|
|
|
|
{
|
|
|
|
|
Fl::set_color(FL_SELECTION_COLOR,r,g,b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void getsyscolor(int what, const char* arg, void (*func)(uchar,uchar,uchar))
|
|
|
|
|
{
|
|
|
|
|
if (arg) {
|
|
|
|
|
uchar r,g,b;
|
|
|
|
|
if (!fl_parse_color(arg, r,g,b))
|
|
|
|
|
Fl::error("Unknown color: %s", arg);
|
|
|
|
|
else
|
|
|
|
|
func(r,g,b);
|
|
|
|
|
} else {
|
|
|
|
|
DWORD x = GetSysColor(what);
|
|
|
|
|
func(uchar(x&255), uchar(x>>8), uchar(x>>16));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::get_system_colors()
|
|
|
|
|
{
|
|
|
|
|
if (!bg2_set) getsyscolor(COLOR_WINDOW, fl_bg2,Fl::background2);
|
|
|
|
|
if (!fg_set) getsyscolor(COLOR_WINDOWTEXT, fl_fg, Fl::foreground);
|
|
|
|
|
if (!bg_set) getsyscolor(COLOR_BTNFACE, fl_bg, Fl::background);
|
|
|
|
|
getsyscolor(COLOR_HIGHLIGHT, 0, set_selection_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-01 00:54:21 +00:00
|
|
|
// ---- timers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Win32Timer
|
|
|
|
|
{
|
|
|
|
|
UINT_PTR handle;
|
|
|
|
|
Fl_Timeout_Handler callback;
|
|
|
|
|
void *data;
|
|
|
|
|
};
|
|
|
|
|
static Win32Timer* win32_timers;
|
|
|
|
|
static int win32_timer_alloc;
|
|
|
|
|
static int win32_timer_used;
|
|
|
|
|
static HWND s_TimerWnd;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void realloc_timers()
|
|
|
|
|
{
|
|
|
|
|
if (win32_timer_alloc == 0) {
|
|
|
|
|
win32_timer_alloc = 8;
|
|
|
|
|
}
|
|
|
|
|
win32_timer_alloc *= 2;
|
|
|
|
|
Win32Timer* new_timers = new Win32Timer[win32_timer_alloc];
|
|
|
|
|
memset(new_timers, 0, sizeof(Win32Timer) * win32_timer_used);
|
|
|
|
|
memcpy(new_timers, win32_timers, sizeof(Win32Timer) * win32_timer_used);
|
|
|
|
|
Win32Timer* delete_me = win32_timers;
|
|
|
|
|
win32_timers = new_timers;
|
|
|
|
|
delete [] delete_me;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void delete_timer(Win32Timer& t)
|
|
|
|
|
{
|
|
|
|
|
KillTimer(s_TimerWnd, t.handle);
|
|
|
|
|
memset(&t, 0, sizeof(Win32Timer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static LRESULT CALLBACK s_TimerProc(HWND hwnd, UINT msg,
|
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
switch (msg) {
|
|
|
|
|
case WM_TIMER:
|
|
|
|
|
{
|
|
|
|
|
unsigned int id = (unsigned) (wParam - 1);
|
|
|
|
|
if (id < (unsigned int)win32_timer_used && win32_timers[id].handle) {
|
|
|
|
|
Fl_Timeout_Handler cb = win32_timers[id].callback;
|
|
|
|
|
void* data = win32_timers[id].data;
|
|
|
|
|
delete_timer(win32_timers[id]);
|
|
|
|
|
if (cb) {
|
|
|
|
|
(*cb)(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::add_timeout(double time, Fl_Timeout_Handler cb, void* data)
|
|
|
|
|
{
|
|
|
|
|
repeat_timeout(time, cb, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::repeat_timeout(double time, Fl_Timeout_Handler cb, void* data)
|
|
|
|
|
{
|
|
|
|
|
int timer_id = -1;
|
|
|
|
|
for (int i = 0; i < win32_timer_used; ++i) {
|
|
|
|
|
if ( !win32_timers[i].handle ) {
|
|
|
|
|
timer_id = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (timer_id == -1) {
|
|
|
|
|
if (win32_timer_used == win32_timer_alloc) {
|
|
|
|
|
realloc_timers();
|
|
|
|
|
}
|
|
|
|
|
timer_id = win32_timer_used++;
|
|
|
|
|
}
|
|
|
|
|
unsigned int elapsed = (unsigned int)(time * 1000);
|
|
|
|
|
|
|
|
|
|
if ( !s_TimerWnd ) {
|
|
|
|
|
const char* timer_class = "FLTimer";
|
|
|
|
|
WNDCLASSEX wc;
|
|
|
|
|
memset(&wc, 0, sizeof(wc));
|
|
|
|
|
wc.cbSize = sizeof (wc);
|
|
|
|
|
wc.style = CS_CLASSDC;
|
|
|
|
|
wc.lpfnWndProc = (WNDPROC)s_TimerProc;
|
|
|
|
|
wc.hInstance = fl_display;
|
|
|
|
|
wc.lpszClassName = timer_class;
|
|
|
|
|
/*ATOM atom =*/ RegisterClassEx(&wc);
|
|
|
|
|
// create a zero size window to handle timer events
|
|
|
|
|
s_TimerWnd = CreateWindowEx(WS_EX_LEFT | WS_EX_TOOLWINDOW,
|
|
|
|
|
timer_class, "",
|
|
|
|
|
WS_POPUP,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
NULL, NULL, fl_display, NULL);
|
|
|
|
|
// just in case this OS won't let us create a 0x0 size window:
|
|
|
|
|
if (!s_TimerWnd)
|
|
|
|
|
s_TimerWnd = CreateWindowEx(WS_EX_LEFT | WS_EX_TOOLWINDOW,
|
|
|
|
|
timer_class, "",
|
|
|
|
|
WS_POPUP,
|
|
|
|
|
0, 0, 1, 1,
|
|
|
|
|
NULL, NULL, fl_display, NULL);
|
|
|
|
|
ShowWindow(s_TimerWnd, SW_SHOWNOACTIVATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
win32_timers[timer_id].callback = cb;
|
|
|
|
|
win32_timers[timer_id].data = data;
|
|
|
|
|
|
|
|
|
|
win32_timers[timer_id].handle =
|
|
|
|
|
SetTimer(s_TimerWnd, timer_id + 1, elapsed, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Fl_WinAPI_Screen_Driver::has_timeout(Fl_Timeout_Handler cb, void* data)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < win32_timer_used; ++i) {
|
|
|
|
|
Win32Timer& t = win32_timers[i];
|
|
|
|
|
if (t.handle && t.callback == cb && t.data == data) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Fl_WinAPI_Screen_Driver::remove_timeout(Fl_Timeout_Handler cb, void* data)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < win32_timer_used; ++i) {
|
|
|
|
|
Win32Timer& t = win32_timers[i];
|
|
|
|
|
if (t.handle && t.callback == cb &&
|
|
|
|
|
(t.data == data || data == NULL)) {
|
|
|
|
|
delete_timer(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-31 19:55:03 +00:00
|
|
|
int Fl_WinAPI_Screen_Driver::compose(int &del) {
|
|
|
|
|
unsigned char ascii = (unsigned char)Fl::e_text[0];
|
|
|
|
|
int condition = (Fl::e_state & (FL_ALT | FL_META)) && !(ascii & 128) ;
|
|
|
|
|
if (condition) { // this stuff is to be treated as a function key
|
|
|
|
|
del = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
del = Fl::compose_state;
|
|
|
|
|
Fl::compose_state = 0;
|
|
|
|
|
// Only insert non-control characters:
|
|
|
|
|
if ( (!Fl::compose_state) && ! (ascii & ~31 && ascii!=127)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2016-02-13 13:17:29 +00:00
|
|
|
|
2016-04-03 06:51:09 +00:00
|
|
|
|
2017-06-18 16:01:53 +00:00
|
|
|
Fl_RGB_Image * // O - image or NULL if failed
|
2018-02-09 13:48:22 +00:00
|
|
|
Fl_WinAPI_Screen_Driver::read_win_rectangle(
|
2016-04-03 06:51:09 +00:00
|
|
|
int X, // I - Left position
|
|
|
|
|
int Y, // I - Top position
|
|
|
|
|
int w, // I - Width of area to read
|
2019-06-06 16:28:49 +00:00
|
|
|
int h, // I - Height of area to read
|
2019-08-21 10:01:01 +00:00
|
|
|
Fl_Window *win, // I - window to capture from or NULL to capture from current offscreen
|
|
|
|
|
bool may_capture_subwins, bool *did_capture_subwins)
|
2017-06-18 16:01:53 +00:00
|
|
|
{
|
|
|
|
|
float s = Fl_Surface_Device::surface()->driver()->scale();
|
2018-05-03 08:37:58 +00:00
|
|
|
int ws, hs;
|
|
|
|
|
if (int(s) == s) { ws = w * s; hs = h * s;}
|
|
|
|
|
else {
|
2019-11-02 10:41:42 +00:00
|
|
|
ws = (w+1)*s; // matches what Fl_Graphics_Driver::cache_size() does
|
|
|
|
|
hs = (h+1)*s;
|
2018-05-03 08:37:58 +00:00
|
|
|
if (ws < 1) ws = 1;
|
|
|
|
|
if (hs < 1) hs = 1;
|
|
|
|
|
}
|
2019-06-06 16:28:49 +00:00
|
|
|
return read_win_rectangle_unscaled(X*s, Y*s, ws, hs, win);
|
2017-06-18 16:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-06 16:28:49 +00:00
|
|
|
Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(int X, int Y, int w, int h, Fl_Window *win)
|
2016-04-03 06:51:09 +00:00
|
|
|
{
|
2018-02-09 13:48:22 +00:00
|
|
|
int d = 3; // Depth of image
|
|
|
|
|
int alpha = 0; uchar *p = NULL;
|
|
|
|
|
// Allocate the image data array as needed...
|
2016-08-23 09:38:46 +00:00
|
|
|
const uchar *oldp = p;
|
2016-04-03 06:51:09 +00:00
|
|
|
if (!p) p = new uchar[w * h * d];
|
|
|
|
|
|
|
|
|
|
// Initialize the default colors/alpha in the whole image...
|
|
|
|
|
memset(p, alpha, w * h * d);
|
|
|
|
|
|
|
|
|
|
// Grab all of the pixels in the image...
|
|
|
|
|
|
|
|
|
|
// Assure that we are not trying to read non-existing data. If it is so, the
|
|
|
|
|
// function should still work, but the out-of-bounds part of the image is
|
|
|
|
|
// untouched (initialized with the alpha value or 0 (black), resp.).
|
|
|
|
|
|
|
|
|
|
int ww = w; // We need the original width for output data line size
|
|
|
|
|
|
|
|
|
|
int shift_x = 0; // X target shift if X modified
|
|
|
|
|
int shift_y = 0; // Y target shift if X modified
|
|
|
|
|
|
|
|
|
|
if (X < 0) {
|
|
|
|
|
shift_x = -X;
|
|
|
|
|
w += X;
|
|
|
|
|
X = 0;
|
|
|
|
|
}
|
|
|
|
|
if (Y < 0) {
|
|
|
|
|
shift_y = -Y;
|
|
|
|
|
h += Y;
|
|
|
|
|
Y = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 09:38:46 +00:00
|
|
|
if (h < 1 || w < 1) return 0/*p*/; // nothing to copy
|
2016-04-03 06:51:09 +00:00
|
|
|
|
|
|
|
|
int line_size = ((3*w+3)/4) * 4; // each line is aligned on a DWORD (4 bytes)
|
|
|
|
|
uchar *dib = new uchar[line_size*h]; // create temporary buffer to read DIB
|
|
|
|
|
|
|
|
|
|
// fill in bitmap info for GetDIBits
|
|
|
|
|
|
|
|
|
|
BITMAPINFO bi;
|
|
|
|
|
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
|
bi.bmiHeader.biWidth = w;
|
|
|
|
|
bi.bmiHeader.biHeight = -h; // negative => top-down DIB
|
|
|
|
|
bi.bmiHeader.biPlanes = 1;
|
|
|
|
|
bi.bmiHeader.biBitCount = 24; // 24 bits RGB
|
|
|
|
|
bi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
|
bi.bmiHeader.biSizeImage = 0;
|
|
|
|
|
bi.bmiHeader.biXPelsPerMeter = 0;
|
|
|
|
|
bi.bmiHeader.biYPelsPerMeter = 0;
|
|
|
|
|
bi.bmiHeader.biClrUsed = 0;
|
|
|
|
|
bi.bmiHeader.biClrImportant = 0;
|
|
|
|
|
|
|
|
|
|
// copy bitmap from original DC (Window, Fl_Offscreen, ...)
|
2019-06-06 16:28:49 +00:00
|
|
|
if (win && Fl_Window::current() != win) win->make_current();
|
2016-04-03 06:51:09 +00:00
|
|
|
HDC gc = (HDC)fl_graphics_driver->gc();
|
|
|
|
|
HDC hdc = CreateCompatibleDC(gc);
|
|
|
|
|
HBITMAP hbm = CreateCompatibleBitmap(gc,w,h);
|
|
|
|
|
|
|
|
|
|
int save_dc = SaveDC(hdc); // save context for cleanup
|
|
|
|
|
SelectObject(hdc,hbm); // select bitmap
|
|
|
|
|
BitBlt(hdc,0,0,w,h,gc,X,Y,SRCCOPY); // copy image section to DDB
|
|
|
|
|
|
|
|
|
|
// copy RGB image data to the allocated DIB
|
|
|
|
|
|
|
|
|
|
GetDIBits(hdc, hbm, 0, h, dib, (BITMAPINFO *)&bi, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
|
|
// finally copy the image data to the user buffer
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j<h; j++) {
|
|
|
|
|
const uchar *src = dib + j * line_size; // source line
|
|
|
|
|
uchar *tg = p + (j + shift_y) * d * ww + shift_x * d; // target line
|
|
|
|
|
for (int i = 0; i<w; i++) {
|
|
|
|
|
uchar b = *src++;
|
|
|
|
|
uchar g = *src++;
|
|
|
|
|
*tg++ = *src++; // R
|
|
|
|
|
*tg++ = g; // G
|
|
|
|
|
*tg++ = b; // B
|
|
|
|
|
if (alpha)
|
|
|
|
|
*tg++ = alpha; // alpha
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// free used GDI and other structures
|
|
|
|
|
|
|
|
|
|
RestoreDC(hdc,save_dc); // reset DC
|
|
|
|
|
DeleteDC(hdc);
|
|
|
|
|
DeleteObject(hbm);
|
|
|
|
|
delete[] dib; // delete DIB temporary buffer
|
|
|
|
|
|
2016-08-23 09:38:46 +00:00
|
|
|
Fl_RGB_Image *rgb = new Fl_RGB_Image(p, w, h, d);
|
|
|
|
|
if (!oldp) rgb->alloc_array = 1;
|
|
|
|
|
return rgb;
|
2016-04-03 06:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-07 15:06:51 +00:00
|
|
|
|
2016-12-14 18:54:12 +00:00
|
|
|
void Fl_WinAPI_Screen_Driver::offscreen_size(Fl_Offscreen off, int &width, int &height)
|
|
|
|
|
{
|
|
|
|
|
BITMAP bitmap;
|
|
|
|
|
if ( GetObject(off, sizeof(BITMAP), &bitmap) ) {
|
|
|
|
|
width = bitmap.bmWidth;
|
|
|
|
|
height = bitmap.bmHeight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 16:21:57 +00:00
|
|
|
//NOTICE: returns -1 if x,y is not in any screen
|
2017-06-18 16:01:53 +00:00
|
|
|
int Fl_WinAPI_Screen_Driver::screen_num_unscaled(int x, int y)
|
|
|
|
|
{
|
2017-07-30 16:21:57 +00:00
|
|
|
int screen = -1;
|
2017-06-18 16:01:53 +00:00
|
|
|
if (num_screens < 0) init();
|
|
|
|
|
for (int i = 0; i < num_screens; i ++) {
|
|
|
|
|
if (x >= screens[i].left && x < screens[i].right &&
|
|
|
|
|
y >= screens[i].top && y < screens[i].bottom) {
|
|
|
|
|
screen = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return screen;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-10 19:49:35 +00:00
|
|
|
//
|
|
|
|
|
// End of "$Id$".
|
2016-09-19 16:59:59 +00:00
|
|
|
//
|