2013-07-29 06:08:34 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Our WinMain() functions, and Win32-specific stuff to set up our windows
|
|
|
|
// and otherwise handle our interface to the operating system. Everything
|
|
|
|
// outside win32/... should be standard C++ and gl.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
#include <time.h>
|
2015-03-24 01:49:04 +08:00
|
|
|
#include <windows.h>
|
2008-02-09 21:52:01 +08:00
|
|
|
#include <shellapi.h>
|
2008-03-25 18:02:13 +08:00
|
|
|
#include <commctrl.h>
|
2008-04-18 19:11:48 +08:00
|
|
|
#include <commdlg.h>
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "solvespace.h"
|
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2013-11-13 13:33:23 +08:00
|
|
|
# include <si.h>
|
|
|
|
# include <siapp.h>
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
# undef uint32_t // thanks but no thanks
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
HINSTANCE Instance;
|
|
|
|
|
2008-04-01 18:48:44 +08:00
|
|
|
HWND TextWnd;
|
2008-03-25 18:02:13 +08:00
|
|
|
HWND TextWndScrollBar;
|
2008-05-27 14:36:59 +08:00
|
|
|
HWND TextEditControl;
|
2010-04-26 15:52:49 +08:00
|
|
|
HGLRC TextGl;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2008-04-01 18:48:44 +08:00
|
|
|
HWND GraphicsWnd;
|
2010-04-26 15:52:49 +08:00
|
|
|
HGLRC GraphicsGl;
|
2008-04-21 18:12:04 +08:00
|
|
|
HWND GraphicsEditControl;
|
2013-10-19 13:36:45 +08:00
|
|
|
static struct {
|
2008-04-01 18:48:44 +08:00
|
|
|
int x, y;
|
|
|
|
} LastMousePos;
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2008-05-28 18:10:31 +08:00
|
|
|
HMENU SubMenus[100];
|
|
|
|
HMENU RecentOpenMenu, RecentImportMenu;
|
|
|
|
|
2009-09-23 18:59:59 +08:00
|
|
|
HMENU ContextMenu, ContextSubmenu;
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
int ClientIsSmallerBy;
|
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
HFONT FixedFont;
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
// The 6-DOF input device.
|
|
|
|
SiHdl SpaceNavigator = SI_NO_HANDLE;
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Routines to display message boxes on screen. Do our own, instead of using
|
2015-03-29 08:30:52 +08:00
|
|
|
// MessageBox, because that is not consistent from version to version and
|
2010-01-16 17:22:44 +08:00
|
|
|
// there's word wrap problems.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
HWND MessageWnd, OkButton;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
bool MessageDone;
|
2013-08-27 02:58:35 +08:00
|
|
|
const char *MessageString;
|
2010-01-16 17:22:44 +08:00
|
|
|
|
|
|
|
static LRESULT CALLBACK MessageProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
2008-04-12 23:17:58 +08:00
|
|
|
{
|
2010-01-16 17:22:44 +08:00
|
|
|
switch (msg) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
if((HWND)lParam == OkButton && wParam == BN_CLICKED) {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = true;
|
2010-01-16 17:22:44 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = true;
|
2010-01-16 17:22:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
int row = 0, col = 0, i;
|
|
|
|
SelectObject(hdc, FixedFont);
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-17 04:00:58 +08:00
|
|
|
SetTextColor(hdc, 0x000000);
|
2010-01-16 17:22:44 +08:00
|
|
|
SetBkMode(hdc, TRANSPARENT);
|
|
|
|
for(i = 0; MessageString[i]; i++) {
|
|
|
|
if(MessageString[i] == '\n') {
|
|
|
|
col = 0;
|
|
|
|
row++;
|
|
|
|
} else {
|
2015-12-27 15:51:28 +08:00
|
|
|
TextOutW(hdc, col*SS.TW.CHAR_WIDTH + 10,
|
|
|
|
row*SS.TW.LINE_HEIGHT + 10,
|
|
|
|
Widen(&(MessageString[i])).c_str(), 1);
|
2010-01-16 17:22:44 +08:00
|
|
|
col++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
return 1;
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
HWND CreateWindowClient(DWORD exStyle, const wchar_t *className, const wchar_t *windowName,
|
2010-01-16 17:22:44 +08:00
|
|
|
DWORD style, int x, int y, int width, int height, HWND parent,
|
|
|
|
HMENU menu, HINSTANCE instance, void *param)
|
2008-02-09 21:52:01 +08:00
|
|
|
{
|
2015-12-27 15:51:28 +08:00
|
|
|
HWND h = CreateWindowExW(exStyle, className, windowName, style, x, y,
|
2010-01-16 17:22:44 +08:00
|
|
|
width, height, parent, menu, instance, param);
|
|
|
|
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(h, &r);
|
|
|
|
width = width - (r.right - width);
|
|
|
|
height = height - (r.bottom - height);
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
SetWindowPos(h, HWND_TOP, x, y, width, height, 0);
|
|
|
|
|
|
|
|
return h;
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::DoMessageBox(const char *str, int rows, int cols, bool error)
|
2008-02-09 21:52:01 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
2010-01-16 17:22:44 +08:00
|
|
|
|
|
|
|
// Register the window class for our dialog.
|
2015-03-27 23:31:23 +08:00
|
|
|
WNDCLASSEX wc = {};
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.cbSize = sizeof(wc);
|
2010-01-16 17:22:44 +08:00
|
|
|
wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC;
|
|
|
|
wc.lpfnWndProc = (WNDPROC)MessageProc;
|
|
|
|
wc.hInstance = Instance;
|
|
|
|
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.lpszClassName = L"MessageWnd";
|
2010-01-16 17:22:44 +08:00
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 32, 32, 0);
|
|
|
|
wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 16, 16, 0);
|
|
|
|
RegisterClassEx(&wc);
|
|
|
|
|
|
|
|
// Create the window.
|
|
|
|
MessageString = str;
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(GraphicsWnd, &r);
|
2013-10-19 13:36:45 +08:00
|
|
|
const char *title = error ? "SolveSpace - Error" : "SolveSpace - Message";
|
2010-04-26 15:52:49 +08:00
|
|
|
int width = cols*SS.TW.CHAR_WIDTH + 20,
|
|
|
|
height = rows*SS.TW.LINE_HEIGHT + 60;
|
2015-12-27 15:51:28 +08:00
|
|
|
MessageWnd = CreateWindowClient(0, L"MessageWnd", Widen(title).c_str(),
|
2010-01-16 17:22:44 +08:00
|
|
|
WS_OVERLAPPED | WS_SYSMENU,
|
|
|
|
r.left + 100, r.top + 100, width, height, NULL, NULL, Instance, NULL);
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
OkButton = CreateWindowExW(0, WC_BUTTON, L"OK",
|
2010-01-16 17:22:44 +08:00
|
|
|
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON,
|
2010-04-26 15:52:49 +08:00
|
|
|
(width - 70)/2, rows*SS.TW.LINE_HEIGHT + 20,
|
2015-03-29 08:30:52 +08:00
|
|
|
70, 25, MessageWnd, NULL, Instance, NULL);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
SendMessage(OkButton, WM_SETFONT, (WPARAM)FixedFont, true);
|
2010-01-16 17:22:44 +08:00
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
ShowWindow(MessageWnd, true);
|
2010-01-16 17:22:44 +08:00
|
|
|
SetFocus(OkButton);
|
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
DWORD ret;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = false;
|
2013-08-27 04:54:04 +08:00
|
|
|
while((ret = GetMessage(&msg, NULL, 0, 0)) != 0 && !MessageDone) {
|
2010-01-16 17:22:44 +08:00
|
|
|
if((msg.message == WM_KEYDOWN &&
|
|
|
|
(msg.wParam == VK_RETURN ||
|
|
|
|
msg.wParam == VK_ESCAPE)) ||
|
|
|
|
(msg.message == WM_KEYUP &&
|
|
|
|
(msg.wParam == VK_SPACE)))
|
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MessageDone = true;
|
2010-01-16 17:22:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2010-01-16 17:22:44 +08:00
|
|
|
MessageString = NULL;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
2010-01-16 17:22:44 +08:00
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
DestroyWindow(MessageWnd);
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::AddContextMenuItem(const char *label, int id)
|
2009-09-23 18:59:59 +08:00
|
|
|
{
|
|
|
|
if(!ContextMenu) ContextMenu = CreatePopupMenu();
|
|
|
|
|
|
|
|
if(id == CONTEXT_SUBMENU) {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(ContextMenu, MF_STRING | MF_POPUP,
|
|
|
|
(UINT_PTR)ContextSubmenu, Widen(label).c_str());
|
2009-09-23 18:59:59 +08:00
|
|
|
ContextSubmenu = NULL;
|
|
|
|
} else {
|
|
|
|
HMENU m = ContextSubmenu ? ContextSubmenu : ContextMenu;
|
|
|
|
if(id == CONTEXT_SEPARATOR) {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_SEPARATOR, 0, L"");
|
2009-09-23 18:59:59 +08:00
|
|
|
} else {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_STRING, id, Widen(label).c_str());
|
2009-09-23 18:59:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::CreateContextSubmenu(void)
|
2009-09-23 18:59:59 +08:00
|
|
|
{
|
|
|
|
ContextSubmenu = CreatePopupMenu();
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
int SolveSpace::ShowContextMenu(void)
|
2009-09-23 18:59:59 +08:00
|
|
|
{
|
|
|
|
POINT p;
|
|
|
|
GetCursorPos(&p);
|
2015-03-29 08:30:52 +08:00
|
|
|
int r = TrackPopupMenu(ContextMenu,
|
2009-09-23 18:59:59 +08:00
|
|
|
TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_TOPALIGN,
|
|
|
|
p.x, p.y, 0, GraphicsWnd, NULL);
|
|
|
|
|
|
|
|
DestroyMenu(ContextMenu);
|
|
|
|
ContextMenu = NULL;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-01-02 18:38:36 +08:00
|
|
|
void CALLBACK TimerCallback(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
|
|
|
|
{
|
2009-01-04 20:52:11 +08:00
|
|
|
// The timer is periodic, so needs to be killed explicitly.
|
|
|
|
KillTimer(GraphicsWnd, 1);
|
2009-01-02 18:38:36 +08:00
|
|
|
SS.GW.TimerCallback();
|
2010-05-03 13:04:42 +08:00
|
|
|
SS.TW.TimerCallback();
|
2009-01-02 18:38:36 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::SetTimerFor(int milliseconds)
|
2009-01-02 18:38:36 +08:00
|
|
|
{
|
|
|
|
SetTimer(GraphicsWnd, 1, milliseconds, TimerCallback);
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::ScheduleLater()
|
2015-03-19 01:02:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-29 12:46:57 +08:00
|
|
|
static void CALLBACK AutosaveCallback(HWND hwnd, UINT msg, UINT_PTR id, DWORD time)
|
|
|
|
{
|
|
|
|
KillTimer(GraphicsWnd, 1);
|
|
|
|
SS.Autosave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SolveSpace::SetAutosaveTimerFor(int minutes)
|
|
|
|
{
|
|
|
|
SetTimer(GraphicsWnd, 2, minutes * 60 * 1000, AutosaveCallback);
|
|
|
|
}
|
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
static void GetWindowSize(HWND hwnd, int *w, int *h)
|
2009-01-02 18:38:36 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
RECT r;
|
|
|
|
GetClientRect(hwnd, &r);
|
|
|
|
*w = r.right - r.left;
|
|
|
|
*h = r.bottom - r.top;
|
2009-01-02 18:38:36 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::GetGraphicsWindowSize(int *w, int *h)
|
2009-01-02 18:38:36 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
GetWindowSize(GraphicsWnd, w, h);
|
2009-01-02 18:38:36 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::GetTextWindowSize(int *w, int *h)
|
2010-05-03 13:04:42 +08:00
|
|
|
{
|
|
|
|
GetWindowSize(TextWnd, w, h);
|
|
|
|
}
|
2008-02-09 21:52:01 +08:00
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::OpenWebsite(const char *url) {
|
2015-12-27 15:51:28 +08:00
|
|
|
ShellExecuteW(GraphicsWnd, L"open", Widen(url).c_str(), NULL, NULL, SW_SHOWNORMAL);
|
2008-02-09 21:52:01 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::ExitNow(void) {
|
2008-06-04 02:48:47 +08:00
|
|
|
PostQuitMessage(0);
|
|
|
|
}
|
|
|
|
|
2008-06-11 12:22:52 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helpers so that we can read/write registry keys from the platform-
|
|
|
|
// independent code.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-26 23:54:26 +08:00
|
|
|
inline int CLAMP(int v, int a, int b) {
|
|
|
|
// Clamp it to the range [a, b]
|
|
|
|
if(v <= a) return a;
|
|
|
|
if(v >= b) return b;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HKEY GetRegistryKey()
|
|
|
|
{
|
|
|
|
HKEY Software;
|
2015-12-27 15:51:28 +08:00
|
|
|
if(RegOpenKeyExW(HKEY_CURRENT_USER, L"Software", 0,
|
|
|
|
KEY_ALL_ACCESS, &Software) != ERROR_SUCCESS)
|
2015-12-26 23:54:26 +08:00
|
|
|
return NULL;
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
HKEY SolveSpace;
|
2015-12-27 15:51:28 +08:00
|
|
|
if(RegCreateKeyExW(Software, L"SolveSpace", 0, NULL, 0,
|
|
|
|
KEY_ALL_ACCESS, NULL, &SolveSpace, NULL) != ERROR_SUCCESS)
|
2015-12-26 23:54:26 +08:00
|
|
|
return NULL;
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(Software);
|
2013-10-19 13:36:45 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
return SolveSpace;
|
2013-10-19 13:36:45 +08:00
|
|
|
}
|
2008-07-08 15:41:29 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
void SolveSpace::CnfFreezeInt(uint32_t val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
2015-12-27 15:51:28 +08:00
|
|
|
RegSetValueExW(SolveSpace, &Widen(name)[0], 0,
|
|
|
|
REG_DWORD, (const BYTE*) &val, sizeof(DWORD));
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
}
|
|
|
|
void SolveSpace::CnfFreezeFloat(float val, const std::string &name)
|
|
|
|
{
|
|
|
|
static_assert(sizeof(float) == sizeof(DWORD),
|
|
|
|
"sizes of float and DWORD must match");
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
2015-12-27 15:51:28 +08:00
|
|
|
RegSetValueExW(SolveSpace, &Widen(name)[0], 0,
|
|
|
|
REG_DWORD, (const BYTE*) &val, sizeof(DWORD));
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
}
|
|
|
|
void SolveSpace::CnfFreezeString(const std::string &str, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring strW = Widen(str);
|
|
|
|
RegSetValueExW(SolveSpace, &Widen(name)[0], 0,
|
|
|
|
REG_SZ, (const BYTE*) &strW[0], (strW.length() + 1) * 2);
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
}
|
|
|
|
static void FreezeWindowPos(HWND hwnd, const std::string &name)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(hwnd, &r);
|
|
|
|
CnfFreezeInt(r.left, name + "_left");
|
|
|
|
CnfFreezeInt(r.right, name + "_right");
|
|
|
|
CnfFreezeInt(r.top, name + "_top");
|
|
|
|
CnfFreezeInt(r.bottom, name + "_bottom");
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
CnfFreezeInt(IsZoomed(hwnd), name + "_maximized");
|
|
|
|
}
|
2008-06-11 12:22:52 +08:00
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
uint32_t SolveSpace::CnfThawInt(uint32_t val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
|
|
|
DWORD type, newval, len = sizeof(DWORD);
|
2015-12-27 15:51:28 +08:00
|
|
|
LONG result = RegQueryValueEx(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
&type, (BYTE*) &newval, &len);
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
|
|
|
|
if(result == ERROR_SUCCESS && type == REG_DWORD)
|
|
|
|
return newval;
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
float SolveSpace::CnfThawFloat(float val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
|
|
|
DWORD type, len = sizeof(DWORD);
|
|
|
|
float newval;
|
2015-12-27 15:51:28 +08:00
|
|
|
LONG result = RegQueryValueExW(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
&type, (BYTE*) &newval, &len);
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
|
|
|
|
if(result == ERROR_SUCCESS && type == REG_DWORD)
|
|
|
|
return newval;
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
std::string SolveSpace::CnfThawString(const std::string &val, const std::string &name)
|
|
|
|
{
|
|
|
|
HKEY SolveSpace = GetRegistryKey();
|
|
|
|
DWORD type, len;
|
2015-12-27 15:51:28 +08:00
|
|
|
if(RegQueryValueExW(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
&type, NULL, &len) != ERROR_SUCCESS || type != REG_SZ) {
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring newval;
|
|
|
|
newval.resize(len / 2 - 1);
|
|
|
|
if(RegQueryValueExW(SolveSpace, &Widen(name)[0], NULL,
|
|
|
|
NULL, (BYTE*) &newval[0], &len) != ERROR_SUCCESS) {
|
2015-12-26 23:54:26 +08:00
|
|
|
RegCloseKey(SolveSpace);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(SolveSpace);
|
2015-12-27 15:51:28 +08:00
|
|
|
return Narrow(newval);
|
2015-12-26 23:54:26 +08:00
|
|
|
}
|
|
|
|
static void ThawWindowPos(HWND hwnd, const std::string &name)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(hwnd, &r);
|
|
|
|
r.left = CnfThawInt(r.left, name + "_left");
|
|
|
|
r.right = CnfThawInt(r.right, name + "_right");
|
|
|
|
r.top = CnfThawInt(r.top, name + "_top");
|
|
|
|
r.bottom = CnfThawInt(r.bottom, name + "_bottom");
|
|
|
|
|
|
|
|
HMONITOR hMonitor = MonitorFromRect(&r, MONITOR_DEFAULTTONEAREST);;
|
|
|
|
MONITORINFO mi;
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
GetMonitorInfo(hMonitor, &mi);
|
|
|
|
|
|
|
|
// If it somehow ended up off-screen, then put it back.
|
|
|
|
RECT dr = mi.rcMonitor;
|
|
|
|
r.left = CLAMP(r.left, dr.left, dr.right);
|
|
|
|
r.right = CLAMP(r.right, dr.left, dr.right);
|
|
|
|
r.top = CLAMP(r.top, dr.top, dr.bottom);
|
|
|
|
r.bottom = CLAMP(r.bottom, dr.top, dr.bottom);
|
|
|
|
MoveWindow(hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);
|
|
|
|
|
|
|
|
if(CnfThawInt(FALSE, name + "_maximized"))
|
|
|
|
ShowWindow(hwnd, SW_MAXIMIZE);
|
2008-07-08 15:41:29 +08:00
|
|
|
}
|
|
|
|
|
2015-12-27 09:03:24 +08:00
|
|
|
void SolveSpace::SetCurrentFilename(const std::string &filename) {
|
|
|
|
if(!filename.empty()) {
|
2015-12-27 15:51:28 +08:00
|
|
|
SetWindowTextW(GraphicsWnd, Widen("SolveSpace - " + filename).c_str());
|
2015-03-24 14:45:53 +08:00
|
|
|
} else {
|
2015-12-27 15:51:28 +08:00
|
|
|
SetWindowTextW(GraphicsWnd, L"SolveSpace - (not yet saved)");
|
2015-03-24 14:45:53 +08:00
|
|
|
}
|
2008-07-08 16:02:22 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::SetMousePointerToHand(bool yes) {
|
2010-04-26 15:52:49 +08:00
|
|
|
SetCursor(LoadCursor(NULL, yes ? IDC_HAND : IDC_ARROW));
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
static void PaintTextWnd(HDC hdc)
|
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
wglMakeCurrent(GetDC(TextWnd), TextGl);
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-05-03 13:04:42 +08:00
|
|
|
SS.TW.Paint();
|
2010-04-26 15:52:49 +08:00
|
|
|
SwapBuffers(GetDC(TextWnd));
|
2008-03-25 18:02:13 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
// Leave the graphics window context active, except when we're painting
|
|
|
|
// this text window.
|
|
|
|
wglMakeCurrent(GetDC(GraphicsWnd), GraphicsGl);
|
|
|
|
}
|
2008-04-09 17:35:09 +08:00
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::MoveTextScrollbarTo(int pos, int maxPos, int page)
|
2010-04-26 15:52:49 +08:00
|
|
|
{
|
2015-03-27 23:31:23 +08:00
|
|
|
SCROLLINFO si = {};
|
2008-03-25 18:02:13 +08:00
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_DISABLENOSCROLL | SIF_ALL;
|
|
|
|
si.nMin = 0;
|
2010-04-26 15:52:49 +08:00
|
|
|
si.nMax = maxPos;
|
|
|
|
si.nPos = pos;
|
|
|
|
si.nPage = page;
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
SetScrollInfo(TextWndScrollBar, SB_CTL, &si, true);
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleTextWindowScrollBar(WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
int maxPos, minPos, pos;
|
|
|
|
GetScrollRange(TextWndScrollBar, SB_CTL, &minPos, &maxPos);
|
|
|
|
pos = GetScrollPos(TextWndScrollBar, SB_CTL);
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
switch(LOWORD(wParam)) {
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_LINEUP: pos--; break;
|
|
|
|
case SB_PAGEUP: pos -= 4; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_LINEDOWN: pos++; break;
|
|
|
|
case SB_PAGEDOWN: pos += 4; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_TOP: pos = 0; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_BOTTOM: pos = maxPos; break;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
case SB_THUMBTRACK:
|
2010-04-26 15:52:49 +08:00
|
|
|
case SB_THUMBPOSITION: pos = HIWORD(wParam); break;
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
SS.TW.ScrollbarEvent(pos);
|
2008-03-25 18:02:13 +08:00
|
|
|
}
|
|
|
|
|
2009-07-21 03:05:33 +08:00
|
|
|
static void MouseWheel(int thisDelta) {
|
|
|
|
static int DeltaAccum;
|
|
|
|
int delta = 0;
|
|
|
|
// Handle mouse deltas of less than 120 (like from an un-detented mouse
|
|
|
|
// wheel) correctly, even though no one ever uses those.
|
|
|
|
DeltaAccum += thisDelta;
|
|
|
|
while(DeltaAccum >= 120) {
|
|
|
|
DeltaAccum -= 120;
|
|
|
|
delta += 120;
|
|
|
|
}
|
|
|
|
while(DeltaAccum <= -120) {
|
|
|
|
DeltaAccum += 120;
|
|
|
|
delta -= 120;
|
|
|
|
}
|
|
|
|
if(delta == 0) return;
|
|
|
|
|
2008-08-15 12:55:03 +08:00
|
|
|
POINT pt;
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
HWND hw = WindowFromPoint(pt);
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-08-15 12:55:03 +08:00
|
|
|
// Make the mousewheel work according to which window the mouse is
|
|
|
|
// over, not according to which window is active.
|
|
|
|
bool inTextWindow;
|
|
|
|
if(hw == TextWnd) {
|
|
|
|
inTextWindow = true;
|
|
|
|
} else if(hw == GraphicsWnd) {
|
|
|
|
inTextWindow = false;
|
|
|
|
} else if(GetForegroundWindow() == TextWnd) {
|
|
|
|
inTextWindow = true;
|
|
|
|
} else {
|
|
|
|
inTextWindow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(inTextWindow) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < abs(delta/40); i++) {
|
|
|
|
HandleTextWindowScrollBar(delta > 0 ? SB_LINEUP : SB_LINEDOWN, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SS.GW.MouseScroll(LastMousePos.x, LastMousePos.y, delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
2008-04-27 17:31:56 +08:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
break;
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
2015-03-24 01:49:04 +08:00
|
|
|
SolveSpaceUI::MenuFile(GraphicsWindow::MNU_EXIT);
|
2008-03-25 18:02:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
2010-04-26 15:52:49 +08:00
|
|
|
// Actually paint the text window, with gl.
|
|
|
|
PaintTextWnd(GetDC(TextWnd));
|
|
|
|
// And then just make Windows happy.
|
2008-03-25 18:02:13 +08:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_SIZING: {
|
|
|
|
RECT *r = (RECT *)lParam;
|
|
|
|
int hc = (r->bottom - r->top) - ClientIsSmallerBy;
|
2010-04-26 15:52:49 +08:00
|
|
|
int extra = hc % (SS.TW.LINE_HEIGHT/2);
|
2008-03-25 18:02:13 +08:00
|
|
|
switch(wParam) {
|
|
|
|
case WMSZ_BOTTOM:
|
|
|
|
case WMSZ_BOTTOMLEFT:
|
|
|
|
case WMSZ_BOTTOMRIGHT:
|
|
|
|
r->bottom -= extra;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WMSZ_TOP:
|
|
|
|
case WMSZ_TOPLEFT:
|
|
|
|
case WMSZ_TOPRIGHT:
|
|
|
|
r->top += extra;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-26 15:52:49 +08:00
|
|
|
int tooNarrow = (SS.TW.MIN_COLS*SS.TW.CHAR_WIDTH) -
|
|
|
|
(r->right - r->left);
|
2008-04-11 20:47:14 +08:00
|
|
|
if(tooNarrow >= 0) {
|
|
|
|
switch(wParam) {
|
|
|
|
case WMSZ_RIGHT:
|
|
|
|
case WMSZ_BOTTOMRIGHT:
|
|
|
|
case WMSZ_TOPRIGHT:
|
|
|
|
r->right += tooNarrow;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WMSZ_LEFT:
|
|
|
|
case WMSZ_BOTTOMLEFT:
|
|
|
|
case WMSZ_TOPLEFT:
|
|
|
|
r->left -= tooNarrow;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-25 18:02:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-03 13:04:42 +08:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
SS.TW.MouseLeave();
|
|
|
|
break;
|
|
|
|
|
2008-03-28 18:00:37 +08:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_MOUSEMOVE: {
|
2010-05-03 13:04:42 +08:00
|
|
|
// We need this in order to get the WM_MOUSELEAVE
|
2015-03-27 23:31:23 +08:00
|
|
|
TRACKMOUSEEVENT tme = {};
|
2010-05-03 13:04:42 +08:00
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = TextWnd;
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
|
|
|
// And process the actual message
|
2008-03-28 18:00:37 +08:00
|
|
|
int x = LOWORD(lParam);
|
|
|
|
int y = HIWORD(lParam);
|
2010-07-21 13:04:03 +08:00
|
|
|
SS.TW.MouseEvent(msg == WM_LBUTTONDOWN, wParam & MK_LBUTTON, x, y);
|
2008-03-28 18:00:37 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_SIZE: {
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(TextWndScrollBar, &r);
|
|
|
|
int sw = r.right - r.left;
|
|
|
|
GetClientRect(hwnd, &r);
|
|
|
|
MoveWindow(TextWndScrollBar, r.right - sw, r.top, sw,
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
(r.bottom - r.top), true);
|
2008-05-27 14:36:59 +08:00
|
|
|
// If the window is growing, then the scrollbar position may
|
|
|
|
// be moving, so it's as if we're dragging the scrollbar.
|
2013-08-27 04:09:15 +08:00
|
|
|
HandleTextWindowScrollBar((WPARAM)-1, -1);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(TextWnd, NULL, false);
|
2008-03-25 18:02:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2008-08-15 12:55:03 +08:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
MouseWheel(GET_WHEEL_DELTA_WPARAM(wParam));
|
2008-02-10 22:06:54 +08:00
|
|
|
break;
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
case WM_VSCROLL:
|
|
|
|
HandleTextWindowScrollBar(wParam, lParam);
|
|
|
|
break;
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
default:
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
static std::string EditControlText(HWND hwnd)
|
|
|
|
{
|
|
|
|
std::wstring result;
|
|
|
|
result.resize(GetWindowTextLength(hwnd));
|
|
|
|
GetWindowTextW(hwnd, &result[0], result.length() + 1);
|
|
|
|
return Narrow(result);
|
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
static bool ProcessKeyDown(WPARAM wParam)
|
2008-04-12 23:17:58 +08:00
|
|
|
{
|
2008-04-21 18:12:04 +08:00
|
|
|
if(GraphicsEditControlIsVisible() && wParam != VK_ESCAPE) {
|
|
|
|
if(wParam == VK_RETURN) {
|
2015-12-27 15:51:28 +08:00
|
|
|
SS.GW.EditControlDone(EditControlText(GraphicsEditControl).c_str());
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return true;
|
2008-04-21 18:12:04 +08:00
|
|
|
} else {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return false;
|
2008-04-21 18:12:04 +08:00
|
|
|
}
|
|
|
|
}
|
2008-05-27 14:36:59 +08:00
|
|
|
if(TextEditControlIsVisible() && wParam != VK_ESCAPE) {
|
|
|
|
if(wParam == VK_RETURN) {
|
2015-12-27 15:51:28 +08:00
|
|
|
SS.TW.EditControlDone(EditControlText(TextEditControl).c_str());
|
2008-05-27 14:36:59 +08:00
|
|
|
} else {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return false;
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
|
|
|
}
|
2008-04-21 18:12:04 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
int c;
|
|
|
|
switch(wParam) {
|
2009-09-28 18:01:34 +08:00
|
|
|
case VK_OEM_PLUS: c = '+'; break;
|
|
|
|
case VK_OEM_MINUS: c = '-'; break;
|
|
|
|
case VK_ESCAPE: c = 27; break;
|
|
|
|
case VK_OEM_1: c = ';'; break;
|
2009-09-29 19:35:19 +08:00
|
|
|
case VK_OEM_3: c = '`'; break;
|
2009-09-28 18:01:34 +08:00
|
|
|
case VK_OEM_4: c = '['; break;
|
|
|
|
case VK_OEM_6: c = ']'; break;
|
|
|
|
case VK_OEM_5: c = '\\'; break;
|
2009-09-29 19:35:19 +08:00
|
|
|
case VK_OEM_PERIOD: c = '.'; break;
|
2009-09-28 18:01:34 +08:00
|
|
|
case VK_SPACE: c = ' '; break;
|
|
|
|
case VK_DELETE: c = 127; break;
|
|
|
|
case VK_TAB: c = '\t'; break;
|
|
|
|
|
|
|
|
case VK_BROWSER_BACK:
|
2013-09-19 04:41:23 +08:00
|
|
|
case VK_BACK: c = '\b'; break;
|
2008-04-12 23:17:58 +08:00
|
|
|
|
2009-01-02 12:06:47 +08:00
|
|
|
case VK_F1:
|
|
|
|
case VK_F2:
|
|
|
|
case VK_F3:
|
|
|
|
case VK_F4:
|
|
|
|
case VK_F5:
|
|
|
|
case VK_F6:
|
|
|
|
case VK_F7:
|
|
|
|
case VK_F8:
|
|
|
|
case VK_F9:
|
|
|
|
case VK_F10:
|
|
|
|
case VK_F11:
|
2013-08-27 04:09:15 +08:00
|
|
|
case VK_F12: c = ((int)wParam - VK_F1) + 0xf1; break;
|
2009-01-02 12:06:47 +08:00
|
|
|
|
2008-07-10 15:26:41 +08:00
|
|
|
// These overlap with some character codes that I'm using, so
|
|
|
|
// don't let them trigger by accident.
|
|
|
|
case VK_F16:
|
|
|
|
case VK_INSERT:
|
|
|
|
case VK_EXECUTE:
|
|
|
|
case VK_APPS:
|
|
|
|
case VK_LWIN:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
case VK_RWIN: return false;
|
2008-07-10 15:26:41 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
default:
|
2013-08-27 04:09:15 +08:00
|
|
|
c = (int)wParam;
|
2008-04-12 23:17:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-09-21 01:54:57 +08:00
|
|
|
if(GetAsyncKeyState(VK_SHIFT) & 0x8000) c |= GraphicsWindow::SHIFT_MASK;
|
|
|
|
if(GetAsyncKeyState(VK_CONTROL) & 0x8000) c |= GraphicsWindow::CTRL_MASK;
|
2008-04-12 23:17:58 +08:00
|
|
|
|
2013-09-21 02:01:31 +08:00
|
|
|
switch(c) {
|
|
|
|
case GraphicsWindow::SHIFT_MASK | '.': c = '>'; break;
|
|
|
|
}
|
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
for(int i = 0; SS.GW.menu[i].level >= 0; i++) {
|
|
|
|
if(c == SS.GW.menu[i].accel) {
|
|
|
|
(SS.GW.menu[i].fn)((GraphicsWindow::MenuId)SS.GW.menu[i].id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
if(SS.GW.KeyDown(c)) return true;
|
2009-09-28 18:01:34 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
// No accelerator; process the key as normal.
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return false;
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::ToggleMenuBar(void)
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
bool SolveSpace::MenuBarIsVisible(void)
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::ShowTextWindow(bool visible)
|
2008-04-27 13:00:12 +08:00
|
|
|
{
|
|
|
|
ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE);
|
|
|
|
}
|
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
static void CreateGlContext(HWND hwnd, HGLRC *glrc)
|
|
|
|
{
|
|
|
|
HDC hdc = GetDC(hwnd);
|
2008-05-16 12:54:47 +08:00
|
|
|
|
2015-03-27 23:31:23 +08:00
|
|
|
PIXELFORMATDESCRIPTOR pfd = {};
|
2009-03-15 04:01:20 +08:00
|
|
|
int pixelFormat;
|
2008-03-27 17:53:51 +08:00
|
|
|
|
2015-03-29 08:30:52 +08:00
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
|
|
|
|
PFD_DOUBLEBUFFER;
|
|
|
|
pfd.dwLayerMask = PFD_MAIN_PLANE;
|
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 32;
|
|
|
|
pfd.cDepthBits = 24;
|
|
|
|
pfd.cAccumBits = 0;
|
|
|
|
pfd.cStencilBits = 0;
|
|
|
|
|
|
|
|
pixelFormat = ChoosePixelFormat(hdc, &pfd);
|
2008-03-27 17:53:51 +08:00
|
|
|
if(!pixelFormat) oops();
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-27 17:53:51 +08:00
|
|
|
if(!SetPixelFormat(hdc, pixelFormat, &pfd)) oops();
|
|
|
|
|
2015-03-29 08:30:52 +08:00
|
|
|
*glrc = wglCreateContext(hdc);
|
2010-04-26 15:52:49 +08:00
|
|
|
wglMakeCurrent(hdc, *glrc);
|
2008-03-27 17:53:51 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::PaintGraphics(void)
|
2008-06-12 15:31:41 +08:00
|
|
|
{
|
2010-05-03 13:04:42 +08:00
|
|
|
SS.GW.Paint();
|
2008-05-16 12:54:47 +08:00
|
|
|
SwapBuffers(GetDC(GraphicsWnd));
|
2008-04-18 19:11:48 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::InvalidateGraphics(void)
|
2010-04-26 15:52:49 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(GraphicsWnd, NULL, false);
|
2010-04-26 15:52:49 +08:00
|
|
|
}
|
2008-05-16 12:54:47 +08:00
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::ToggleFullScreen(void)
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
bool SolveSpace::FullScreenIsActive(void)
|
2013-10-25 13:04:16 +08:00
|
|
|
{
|
|
|
|
// Implement me
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
int64_t SolveSpace::GetMilliseconds(void)
|
2008-04-18 19:11:48 +08:00
|
|
|
{
|
2008-06-01 17:46:02 +08:00
|
|
|
LARGE_INTEGER t, f;
|
|
|
|
QueryPerformanceCounter(&t);
|
|
|
|
QueryPerformanceFrequency(&f);
|
|
|
|
LONGLONG d = t.QuadPart/(f.QuadPart/1000);
|
2013-10-28 12:28:39 +08:00
|
|
|
return (int64_t)d;
|
2008-04-18 19:11:48 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
int64_t SolveSpace::GetUnixTime(void)
|
2009-06-10 14:57:27 +08:00
|
|
|
{
|
2015-10-27 15:34:13 +08:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
time_t ret;
|
|
|
|
time(&ret);
|
|
|
|
#else
|
2009-06-10 14:57:27 +08:00
|
|
|
__time64_t ret;
|
|
|
|
_time64(&ret);
|
2015-10-27 15:34:13 +08:00
|
|
|
#endif
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return (int64_t)ret;
|
2009-06-10 14:57:27 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::InvalidateText(void)
|
2008-04-11 20:47:14 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(TextWnd, NULL, false);
|
2008-04-11 20:47:14 +08:00
|
|
|
}
|
2008-03-27 17:53:51 +08:00
|
|
|
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
static void ShowEditControl(HWND h, int x, int y, int fontHeight,
|
|
|
|
bool isMonospace, const std::wstring &s) {
|
|
|
|
static HFONT hf;
|
|
|
|
if(hf) DeleteObject(hf);
|
|
|
|
hf = CreateFontW(-fontHeight, 0, 0, 0,
|
|
|
|
FW_REGULAR, false, false, false, ANSI_CHARSET,
|
|
|
|
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
|
|
|
DEFAULT_QUALITY, FF_DONTCARE, isMonospace ? L"Lucida Console" : L"Arial");
|
|
|
|
if(hf) SendMessage(h, WM_SETFONT, (WPARAM)hf, false);
|
|
|
|
else SendMessage(h, WM_SETFONT, (WPARAM)(HFONT)GetStockObject(SYSTEM_FONT), false);
|
|
|
|
SendMessage(h, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, 0);
|
|
|
|
|
|
|
|
TEXTMETRICW tm;
|
|
|
|
HDC hdc = GetDC(h);
|
|
|
|
SelectObject(hdc, hf);
|
|
|
|
GetTextMetrics(hdc, &tm);
|
|
|
|
ReleaseDC(h, hdc);
|
|
|
|
y -= tm.tmAscent; /* y coordinate denotes baseline */
|
|
|
|
|
|
|
|
RECT rc = { x, y, x + tm.tmAveCharWidth * 30, y + tm.tmHeight };
|
|
|
|
AdjustWindowRectEx(&rc, 0, false, WS_EX_CLIENTEDGE);
|
|
|
|
|
|
|
|
MoveWindow(h, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, true);
|
2008-05-27 14:36:59 +08:00
|
|
|
ShowWindow(h, SW_SHOW);
|
2015-12-27 15:51:28 +08:00
|
|
|
if(!s.empty()) {
|
|
|
|
SendMessage(h, WM_SETTEXT, 0, (LPARAM)s.c_str());
|
|
|
|
SendMessage(h, EM_SETSEL, 0, s.length());
|
2010-04-26 15:52:49 +08:00
|
|
|
SetFocus(h);
|
|
|
|
}
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
2015-11-06 16:40:12 +08:00
|
|
|
void SolveSpace::ShowTextEditControl(int x, int y, const std::string &str)
|
2008-05-27 14:36:59 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
2008-05-27 14:36:59 +08:00
|
|
|
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
ShowEditControl(TextEditControl, x, y, TextWindow::CHAR_HEIGHT,
|
|
|
|
/*isMonospace=*/true, Widen(str));
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::HideTextEditControl(void)
|
2008-05-27 14:36:59 +08:00
|
|
|
{
|
|
|
|
ShowWindow(TextEditControl, SW_HIDE);
|
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
bool SolveSpace::TextEditControlIsVisible(void)
|
2008-05-27 14:36:59 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return IsWindowVisible(TextEditControl) ? true : false;
|
2008-05-27 14:36:59 +08:00
|
|
|
}
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
void SolveSpace::ShowGraphicsEditControl(int x, int y, int fontHeight,
|
|
|
|
const std::string &str)
|
2008-04-21 18:12:04 +08:00
|
|
|
{
|
2010-04-26 15:52:49 +08:00
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
2008-05-27 14:36:59 +08:00
|
|
|
|
2008-04-21 18:12:04 +08:00
|
|
|
RECT r;
|
|
|
|
GetClientRect(GraphicsWnd, &r);
|
|
|
|
x = x + (r.right - r.left)/2;
|
|
|
|
y = (r.bottom - r.top)/2 - y;
|
|
|
|
|
Ensure edit control font size matches font size of text being edited.
Before this commit, the position of the edit box was adjusted
by trial and error, as far as I can tell. This commit changes
the positioning machinery for edit controls as follows:
The coordinates passed to ShowTextEditControl/ShowGraphicsEditControl
now denote: X the left bound, and Y the baseline.
The font height passed to ShowGraphicsEditControl denotes
the absolute font height in pixels, i.e. ascent plus descent.
Platform-dependent code uses these coordinates, the font metrics
for the font appropriate for the platform, and the knowledge of
the decorations drawn around the text by the native edit control
to position the edit control in a way that overlays the text inside
the edit control with the rendered text.
On OS X, GNU Unifont (of height 16) has metrics identical to
Monaco (of height 15) and so as an exception, the edit control
is nudged slightly for a pixel-perfect fit.
Also, since the built-in vector font is proportional, this commit
also switches the edit control font to proportional when editing
constraints.
2016-04-12 22:24:09 +08:00
|
|
|
ShowEditControl(GraphicsEditControl, x, y, fontHeight,
|
|
|
|
/*isMonospace=*/false, Widen(str));
|
2008-04-21 18:12:04 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::HideGraphicsEditControl(void)
|
2008-04-21 18:12:04 +08:00
|
|
|
{
|
|
|
|
ShowWindow(GraphicsEditControl, SW_HIDE);
|
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
bool SolveSpace::GraphicsEditControlIsVisible(void)
|
2008-04-21 18:12:04 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return IsWindowVisible(GraphicsEditControl) ? true : false;
|
2008-04-21 18:12:04 +08:00
|
|
|
}
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
2008-03-27 17:53:51 +08:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SIZE:
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
InvalidateRect(GraphicsWnd, NULL, false);
|
2008-03-27 17:53:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
2010-04-26 15:52:49 +08:00
|
|
|
// Actually paint the window, with gl.
|
2008-05-16 12:54:47 +08:00
|
|
|
PaintGraphics();
|
2010-04-26 15:52:49 +08:00
|
|
|
// And make Windows happy.
|
2008-03-27 17:53:51 +08:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-02 18:38:36 +08:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
SS.GW.MouseLeave();
|
|
|
|
break;
|
|
|
|
|
2008-03-27 17:53:51 +08:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
case WM_LBUTTONDOWN:
|
2008-04-22 18:53:42 +08:00
|
|
|
case WM_LBUTTONUP:
|
2008-04-21 18:12:04 +08:00
|
|
|
case WM_LBUTTONDBLCLK:
|
2008-07-06 15:56:24 +08:00
|
|
|
case WM_RBUTTONDOWN:
|
2009-09-23 18:59:59 +08:00
|
|
|
case WM_RBUTTONUP:
|
2008-03-27 17:53:51 +08:00
|
|
|
case WM_MBUTTONDOWN: {
|
|
|
|
int x = LOWORD(lParam);
|
|
|
|
int y = HIWORD(lParam);
|
|
|
|
|
2009-01-02 18:38:36 +08:00
|
|
|
// We need this in order to get the WM_MOUSELEAVE
|
2015-03-27 23:31:23 +08:00
|
|
|
TRACKMOUSEEVENT tme = {};
|
2009-01-02 18:38:36 +08:00
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = GraphicsWnd;
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
|
|
|
// Convert to xy (vs. ij) style coordinates, with (0, 0) at center
|
2008-03-27 17:53:51 +08:00
|
|
|
RECT r;
|
|
|
|
GetClientRect(GraphicsWnd, &r);
|
|
|
|
x = x - (r.right - r.left)/2;
|
|
|
|
y = (r.bottom - r.top)/2 - y;
|
|
|
|
|
2008-04-01 18:48:44 +08:00
|
|
|
LastMousePos.x = x;
|
|
|
|
LastMousePos.y = y;
|
|
|
|
|
2008-03-27 17:53:51 +08:00
|
|
|
if(msg == WM_LBUTTONDOWN) {
|
|
|
|
SS.GW.MouseLeftDown(x, y);
|
2008-04-22 18:53:42 +08:00
|
|
|
} else if(msg == WM_LBUTTONUP) {
|
|
|
|
SS.GW.MouseLeftUp(x, y);
|
2008-04-21 18:12:04 +08:00
|
|
|
} else if(msg == WM_LBUTTONDBLCLK) {
|
|
|
|
SS.GW.MouseLeftDoubleClick(x, y);
|
2008-07-06 15:56:24 +08:00
|
|
|
} else if(msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
|
|
|
|
SS.GW.MouseMiddleOrRightDown(x, y);
|
2009-09-23 18:59:59 +08:00
|
|
|
} else if(msg == WM_RBUTTONUP) {
|
|
|
|
SS.GW.MouseRightUp(x, y);
|
2008-03-27 17:53:51 +08:00
|
|
|
} else if(msg == WM_MOUSEMOVE) {
|
|
|
|
SS.GW.MouseMoved(x, y,
|
|
|
|
!!(wParam & MK_LBUTTON),
|
|
|
|
!!(wParam & MK_MBUTTON),
|
|
|
|
!!(wParam & MK_RBUTTON),
|
|
|
|
!!(wParam & MK_SHIFT),
|
|
|
|
!!(wParam & MK_CONTROL));
|
|
|
|
} else {
|
|
|
|
oops();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-08-15 12:55:03 +08:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
MouseWheel(GET_WHEEL_DELTA_WPARAM(wParam));
|
2008-04-01 18:48:44 +08:00
|
|
|
break;
|
2008-08-15 12:55:03 +08:00
|
|
|
|
2008-04-12 23:17:58 +08:00
|
|
|
case WM_COMMAND: {
|
2008-04-21 18:12:04 +08:00
|
|
|
if(HIWORD(wParam) == 0) {
|
|
|
|
int id = LOWORD(wParam);
|
2008-05-28 18:10:31 +08:00
|
|
|
if((id >= RECENT_OPEN && id < (RECENT_OPEN + MAX_RECENT))) {
|
2015-03-24 01:49:04 +08:00
|
|
|
SolveSpaceUI::MenuFile(id);
|
2008-05-28 18:10:31 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if((id >= RECENT_IMPORT && id < (RECENT_IMPORT + MAX_RECENT))) {
|
|
|
|
Group::MenuGroup(id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int i;
|
|
|
|
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
2008-04-21 18:12:04 +08:00
|
|
|
if(id == SS.GW.menu[i].id) {
|
|
|
|
(SS.GW.menu[i].fn)((GraphicsWindow::MenuId)id);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
2008-05-28 18:10:31 +08:00
|
|
|
if(SS.GW.menu[i].level < 0) oops();
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-03-27 17:53:51 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_DESTROY:
|
2015-03-24 01:49:04 +08:00
|
|
|
SolveSpaceUI::MenuFile(GraphicsWindow::MNU_EXIT);
|
2008-03-25 18:02:13 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-18 19:11:48 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Common dialog routines, to open or save a file.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-27 15:51:28 +08:00
|
|
|
static size_t strlen2(const char *p) {
|
|
|
|
const char *s = p;
|
|
|
|
while(*p || (!*p && *(p+1))) p++;
|
|
|
|
return p - s + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool OpenSaveFile(bool isOpen, std::string &filename,
|
2016-01-11 16:23:51 +08:00
|
|
|
const std::string &defExtension, const char *selPattern) {
|
2015-12-27 15:51:28 +08:00
|
|
|
// UNC paths may be as long as 32767 characters.
|
2015-12-27 09:03:24 +08:00
|
|
|
// Unfortunately, the Get*FileName API does not provide any way to use it
|
|
|
|
// except with a preallocated buffer of fixed size, so we use something
|
|
|
|
// reasonably large.
|
2015-12-27 15:51:28 +08:00
|
|
|
const int len = 32768;
|
|
|
|
wchar_t filenameC[len] = {};
|
|
|
|
wcsncpy(filenameC, Widen(filename).c_str(), len - 1);
|
|
|
|
|
|
|
|
std::wstring selPatternW = Widen(std::string(selPattern, strlen2(selPattern)));
|
|
|
|
std::wstring defExtensionW = Widen(defExtension);
|
2008-04-18 19:11:48 +08:00
|
|
|
|
2015-12-27 09:03:24 +08:00
|
|
|
OPENFILENAME ofn = {};
|
2008-04-18 19:11:48 +08:00
|
|
|
ofn.lStructSize = sizeof(ofn);
|
|
|
|
ofn.hInstance = Instance;
|
|
|
|
ofn.hwndOwner = GraphicsWnd;
|
2015-12-27 15:51:28 +08:00
|
|
|
ofn.lpstrFilter = selPatternW.c_str();
|
|
|
|
ofn.lpstrDefExt = defExtensionW.c_str();
|
2015-12-27 09:03:24 +08:00
|
|
|
ofn.lpstrFile = filenameC;
|
2015-12-27 15:51:28 +08:00
|
|
|
ofn.nMaxFile = len;
|
2008-04-18 19:11:48 +08:00
|
|
|
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
BOOL r;
|
|
|
|
if(isOpen) {
|
|
|
|
r = GetOpenFileNameW(&ofn);
|
|
|
|
} else {
|
|
|
|
r = GetSaveFileNameW(&ofn);
|
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
2008-04-18 19:11:48 +08:00
|
|
|
SetForegroundWindow(GraphicsWnd);
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
if(r) filename = Narrow(filenameC);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return r ? true : false;
|
2008-04-18 19:11:48 +08:00
|
|
|
}
|
2015-03-29 12:46:57 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
bool SolveSpace::GetOpenFile(std::string &filename,
|
2016-01-11 16:23:51 +08:00
|
|
|
const std::string &defExtension, const char *selPattern)
|
2008-04-18 19:11:48 +08:00
|
|
|
{
|
2015-12-27 15:51:28 +08:00
|
|
|
return OpenSaveFile(true, filename, defExtension, selPattern);
|
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
bool SolveSpace::GetSaveFile(std::string &filename,
|
2016-01-11 16:23:51 +08:00
|
|
|
const std::string &defExtension, const char *selPattern)
|
2015-12-27 15:51:28 +08:00
|
|
|
{
|
|
|
|
return OpenSaveFile(false, filename, defExtension, selPattern);
|
2008-04-18 19:11:48 +08:00
|
|
|
}
|
2015-03-29 12:46:57 +08:00
|
|
|
|
2016-01-11 20:18:18 +08:00
|
|
|
DialogChoice SolveSpace::SaveFileYesNoCancel(void)
|
2008-04-18 19:11:48 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
2008-06-25 13:14:49 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
int r = MessageBoxW(GraphicsWnd,
|
2016-01-11 20:18:18 +08:00
|
|
|
L"The file has changed since it was last saved.\n\n"
|
2015-12-27 15:51:28 +08:00
|
|
|
L"Do you want to save the changes?", L"SolveSpace",
|
2008-04-18 19:11:48 +08:00
|
|
|
MB_YESNOCANCEL | MB_ICONWARNING);
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
2008-06-25 13:14:49 +08:00
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
|
2013-09-19 04:49:32 +08:00
|
|
|
switch(r) {
|
2016-01-11 20:18:18 +08:00
|
|
|
case IDYES:
|
|
|
|
return DIALOG_YES;
|
|
|
|
case IDNO:
|
|
|
|
return DIALOG_NO;
|
|
|
|
case IDCANCEL:
|
|
|
|
default:
|
|
|
|
return DIALOG_CANCEL;
|
2013-09-19 04:49:32 +08:00
|
|
|
}
|
2008-06-25 13:14:49 +08:00
|
|
|
}
|
2008-06-30 17:09:17 +08:00
|
|
|
|
2016-01-11 20:18:18 +08:00
|
|
|
DialogChoice SolveSpace::LoadAutosaveYesNo(void)
|
2015-03-29 12:46:57 +08:00
|
|
|
{
|
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
int r = MessageBoxW(GraphicsWnd,
|
2016-01-11 20:18:18 +08:00
|
|
|
L"An autosave file is availible for this project.\n\n"
|
2015-12-27 15:51:28 +08:00
|
|
|
L"Do you want to load the autosave file instead?", L"SolveSpace",
|
2015-03-29 12:46:57 +08:00
|
|
|
MB_YESNO | MB_ICONWARNING);
|
|
|
|
|
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
|
|
|
|
switch (r) {
|
2016-01-11 20:18:18 +08:00
|
|
|
case IDYES:
|
|
|
|
return DIALOG_YES;
|
|
|
|
case IDNO:
|
|
|
|
default:
|
|
|
|
return DIALOG_NO;
|
2015-03-29 12:46:57 +08:00
|
|
|
}
|
2016-01-11 20:18:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogChoice SolveSpace::LocateImportedFileYesNoCancel(const std::string &filename,
|
|
|
|
bool canCancel) {
|
|
|
|
EnableWindow(GraphicsWnd, false);
|
|
|
|
EnableWindow(TextWnd, false);
|
|
|
|
|
|
|
|
std::string message =
|
|
|
|
"The imported file " + filename + " is not present.\n\n"
|
|
|
|
"Do you want to locate it manually?\n\n"
|
|
|
|
"If you select \"No\", any geometry that depends on "
|
|
|
|
"the missing file will be removed.";
|
2015-03-29 12:46:57 +08:00
|
|
|
|
2016-01-11 20:18:18 +08:00
|
|
|
int r = MessageBoxW(GraphicsWnd, Widen(message).c_str(), L"SolveSpace",
|
|
|
|
(canCancel ? MB_YESNOCANCEL : MB_YESNO) | MB_ICONWARNING);
|
|
|
|
|
|
|
|
EnableWindow(TextWnd, true);
|
|
|
|
EnableWindow(GraphicsWnd, true);
|
|
|
|
SetForegroundWindow(GraphicsWnd);
|
|
|
|
|
|
|
|
switch(r) {
|
|
|
|
case IDYES:
|
|
|
|
return DIALOG_YES;
|
|
|
|
case IDNO:
|
|
|
|
return DIALOG_NO;
|
|
|
|
case IDCANCEL:
|
|
|
|
default:
|
|
|
|
return DIALOG_CANCEL;
|
|
|
|
}
|
2015-03-29 12:46:57 +08:00
|
|
|
}
|
|
|
|
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
std::vector<std::string> SolveSpace::GetFontFiles() {
|
|
|
|
std::vector<std::string> fonts;
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring fontsDir(MAX_PATH, '\0');
|
|
|
|
fontsDir.resize(GetWindowsDirectoryW(&fontsDir[0], fontsDir.length()));
|
|
|
|
fontsDir += L"\\fonts\\";
|
2008-06-30 17:09:17 +08:00
|
|
|
|
2015-12-27 09:03:24 +08:00
|
|
|
WIN32_FIND_DATA wfd;
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
HANDLE h = FindFirstFileW((fontsDir + L"*").c_str(), &wfd);
|
2008-06-30 17:09:17 +08:00
|
|
|
while(h != INVALID_HANDLE_VALUE) {
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
fonts.push_back(Narrow(fontsDir) + Narrow(wfd.cFileName));
|
2015-12-27 15:51:28 +08:00
|
|
|
if(!FindNextFileW(h, &wfd)) break;
|
2008-06-30 17:09:17 +08:00
|
|
|
}
|
Rewrite TTF to Bezier conversion using Freetype.
Benefits:
* Much simpler code.
* Handles the entire TTF spec, not just a small subset that
only really worked well on Windows fonts.
* Handles all character sets as well as accented characters.
* Much faster parsing, since Freetype lazily loads and
caches glyphs.
* Support for basically every kind of font that was invented,
not just TTF.
Note that OpenType features, e.g. ligatures, are not yet supported.
This means that Arabic and Devanagari scripts, among others, will
not be rendered in their proper form.
RTL scripts are not supported either, neither in TTF nor in
the text window. Adding RTL support is comparatively easy, but
given that Arabic would not be legibly rendered anyway, this is not
done so far.
2016-01-30 09:42:44 +08:00
|
|
|
|
|
|
|
return fonts;
|
2008-06-30 17:09:17 +08:00
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
static void MenuById(int id, bool yes, bool check)
|
2008-04-14 18:28:32 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int subMenu = -1;
|
|
|
|
|
|
|
|
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
|
|
|
if(SS.GW.menu[i].level == 0) subMenu++;
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-04-14 18:28:32 +08:00
|
|
|
if(SS.GW.menu[i].id == id) {
|
|
|
|
if(subMenu < 0) oops();
|
2013-10-19 13:36:45 +08:00
|
|
|
if(subMenu >= (int)arraylen(SubMenus)) oops();
|
2008-04-14 18:28:32 +08:00
|
|
|
|
2008-04-18 15:06:37 +08:00
|
|
|
if(check) {
|
|
|
|
CheckMenuItem(SubMenus[subMenu], id,
|
|
|
|
yes ? MF_CHECKED : MF_UNCHECKED);
|
|
|
|
} else {
|
|
|
|
EnableMenuItem(SubMenus[subMenu], id,
|
|
|
|
yes ? MF_ENABLED : MF_GRAYED);
|
|
|
|
}
|
2008-04-14 18:28:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
oops();
|
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::CheckMenuById(int id, bool checked)
|
2008-04-18 15:06:37 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MenuById(id, checked, true);
|
2008-04-18 15:06:37 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::RadioMenuById(int id, bool selected)
|
2013-09-19 12:59:18 +08:00
|
|
|
{
|
|
|
|
// Windows does not natively support radio-button menu items
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MenuById(id, selected, true);
|
2013-09-19 12:59:18 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::EnableMenuById(int id, bool enabled)
|
2008-04-18 15:06:37 +08:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
MenuById(id, enabled, false);
|
2008-04-18 15:06:37 +08:00
|
|
|
}
|
2008-05-28 18:10:31 +08:00
|
|
|
static void DoRecent(HMENU m, int base)
|
|
|
|
{
|
|
|
|
while(DeleteMenu(m, 0, MF_BYPOSITION))
|
|
|
|
;
|
|
|
|
int i, c = 0;
|
|
|
|
for(i = 0; i < MAX_RECENT; i++) {
|
2015-12-27 09:03:24 +08:00
|
|
|
if(!RecentFile[i].empty()) {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_STRING, base + i, Widen(RecentFile[i]).c_str());
|
2008-05-28 18:10:31 +08:00
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
2015-12-27 15:51:28 +08:00
|
|
|
if(c == 0) AppendMenuW(m, MF_STRING | MF_GRAYED, 0, L"(no recent files)");
|
2008-05-28 18:10:31 +08:00
|
|
|
}
|
2015-03-24 01:49:04 +08:00
|
|
|
void SolveSpace::RefreshRecentMenus(void)
|
2008-05-28 18:10:31 +08:00
|
|
|
{
|
|
|
|
DoRecent(RecentOpenMenu, RECENT_OPEN);
|
|
|
|
DoRecent(RecentImportMenu, RECENT_IMPORT);
|
|
|
|
}
|
2008-04-14 18:28:32 +08:00
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
HMENU CreateGraphicsWindowMenus(void)
|
|
|
|
{
|
|
|
|
HMENU top = CreateMenu();
|
2013-08-27 03:36:00 +08:00
|
|
|
HMENU m = 0;
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
int i;
|
|
|
|
int subMenu = 0;
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
2016-01-27 13:13:04 +08:00
|
|
|
std::string label;
|
2013-09-21 03:01:00 +08:00
|
|
|
if(SS.GW.menu[i].label) {
|
|
|
|
char accelbuf[40];
|
|
|
|
const char *sep =
|
|
|
|
MakeAcceleratorLabel(SS.GW.menu[i].accel, accelbuf) ?
|
|
|
|
"\t" : "";
|
2016-01-27 13:13:04 +08:00
|
|
|
label = ssprintf("%s%s%s", SS.GW.menu[i].label, sep, accelbuf);
|
2013-09-21 03:01:00 +08:00
|
|
|
}
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
if(SS.GW.menu[i].level == 0) {
|
|
|
|
m = CreateMenu();
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(top, MF_STRING | MF_POPUP, (UINT_PTR)m, Widen(label).c_str());
|
2013-10-19 13:36:45 +08:00
|
|
|
if(subMenu >= (int)arraylen(SubMenus)) oops();
|
2008-03-26 17:18:12 +08:00
|
|
|
SubMenus[subMenu] = m;
|
|
|
|
subMenu++;
|
2008-05-28 18:10:31 +08:00
|
|
|
} else if(SS.GW.menu[i].level == 1) {
|
2013-09-21 01:40:17 +08:00
|
|
|
if(SS.GW.menu[i].id == GraphicsWindow::MNU_OPEN_RECENT) {
|
|
|
|
RecentOpenMenu = CreateMenu();
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_STRING | MF_POPUP,
|
|
|
|
(UINT_PTR)RecentOpenMenu, Widen(label).c_str());
|
2013-09-21 01:40:17 +08:00
|
|
|
} else if(SS.GW.menu[i].id == GraphicsWindow::MNU_GROUP_RECENT) {
|
|
|
|
RecentImportMenu = CreateMenu();
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_STRING | MF_POPUP,
|
|
|
|
(UINT_PTR)RecentImportMenu, Widen(label).c_str());
|
2013-09-21 01:40:17 +08:00
|
|
|
} else if(SS.GW.menu[i].label) {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_STRING, SS.GW.menu[i].id, Widen(label).c_str());
|
2008-03-26 17:18:12 +08:00
|
|
|
} else {
|
2015-12-27 15:51:28 +08:00
|
|
|
AppendMenuW(m, MF_SEPARATOR, SS.GW.menu[i].id, L"");
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
2008-05-28 18:10:31 +08:00
|
|
|
} else oops();
|
2008-03-26 17:18:12 +08:00
|
|
|
}
|
2008-05-28 18:10:31 +08:00
|
|
|
RefreshRecentMenus();
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
static void CreateMainWindows(void)
|
|
|
|
{
|
2015-03-27 23:31:23 +08:00
|
|
|
WNDCLASSEX wc = {};
|
2008-03-25 18:02:13 +08:00
|
|
|
|
|
|
|
wc.cbSize = sizeof(wc);
|
2008-03-26 17:18:12 +08:00
|
|
|
|
|
|
|
// The graphics window, where the sketch is drawn and shown.
|
2008-03-25 18:02:13 +08:00
|
|
|
wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC |
|
|
|
|
CS_DBLCLKS;
|
2008-03-26 17:18:12 +08:00
|
|
|
wc.lpfnWndProc = (WNDPROC)GraphicsWndProc;
|
2015-03-29 08:30:52 +08:00
|
|
|
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.lpszClassName = L"GraphicsWnd";
|
2008-03-25 18:02:13 +08:00
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2008-07-18 17:50:52 +08:00
|
|
|
wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 32, 32, 0);
|
|
|
|
wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
|
|
|
|
IMAGE_ICON, 16, 16, 0);
|
2008-03-25 18:02:13 +08:00
|
|
|
if(!RegisterClassEx(&wc)) oops();
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
HMENU top = CreateGraphicsWindowMenus();
|
2015-12-27 15:51:28 +08:00
|
|
|
GraphicsWnd = CreateWindowExW(0, L"GraphicsWnd",
|
|
|
|
L"SolveSpace (not yet saved)",
|
2008-03-25 18:02:13 +08:00
|
|
|
WS_OVERLAPPED | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX |
|
2008-03-27 17:53:51 +08:00
|
|
|
WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX | WS_CLIPSIBLINGS,
|
2008-05-27 17:59:19 +08:00
|
|
|
50, 50, 900, 600, NULL, top, Instance, NULL);
|
2008-03-26 17:18:12 +08:00
|
|
|
if(!GraphicsWnd) oops();
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
GraphicsEditControl = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDIT, L"",
|
2008-04-21 18:12:04 +08:00
|
|
|
WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
|
|
|
|
50, 50, 100, 21, GraphicsWnd, NULL, Instance, NULL);
|
|
|
|
|
2008-03-26 17:18:12 +08:00
|
|
|
// The text window, with a comand line and some textual information
|
|
|
|
// about the sketch.
|
2008-04-11 20:47:14 +08:00
|
|
|
wc.style &= ~CS_DBLCLKS;
|
2008-03-26 17:18:12 +08:00
|
|
|
wc.lpfnWndProc = (WNDPROC)TextWndProc;
|
|
|
|
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
2015-12-27 15:51:28 +08:00
|
|
|
wc.lpszClassName = L"TextWnd";
|
2008-03-28 18:00:37 +08:00
|
|
|
wc.hCursor = NULL;
|
2008-03-26 17:18:12 +08:00
|
|
|
if(!RegisterClassEx(&wc)) oops();
|
|
|
|
|
|
|
|
// We get the desired Alt+Tab behaviour by specifying that the text
|
|
|
|
// window is a child of the graphics window.
|
2015-12-27 15:51:28 +08:00
|
|
|
TextWnd = CreateWindowExW(0,
|
|
|
|
L"TextWnd", L"SolveSpace - Browser", WS_THICKFRAME | WS_CLIPCHILDREN,
|
2008-05-27 17:59:19 +08:00
|
|
|
650, 500, 420, 300, GraphicsWnd, (HMENU)NULL, Instance, NULL);
|
2008-03-25 18:02:13 +08:00
|
|
|
if(!TextWnd) oops();
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
TextWndScrollBar = CreateWindowExW(0, WC_SCROLLBAR, L"", WS_CHILD |
|
2015-03-29 08:30:52 +08:00
|
|
|
SBS_VERT | SBS_LEFTALIGN | WS_VISIBLE | WS_CLIPSIBLINGS,
|
2008-03-25 18:02:13 +08:00
|
|
|
200, 100, 100, 100, TextWnd, NULL, Instance, NULL);
|
|
|
|
// Force the scrollbar to get resized to the window,
|
|
|
|
TextWndProc(TextWnd, WM_SIZE, 0, 0);
|
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
TextEditControl = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDIT, L"",
|
2008-05-27 14:36:59 +08:00
|
|
|
WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
|
|
|
|
50, 50, 100, 21, TextWnd, NULL, Instance, NULL);
|
|
|
|
|
2010-04-26 15:52:49 +08:00
|
|
|
// Now that all our windows exist, set up gl contexts.
|
|
|
|
CreateGlContext(TextWnd, &TextGl);
|
|
|
|
CreateGlContext(GraphicsWnd, &GraphicsGl);
|
2008-03-25 18:02:13 +08:00
|
|
|
|
|
|
|
RECT r, rc;
|
|
|
|
GetWindowRect(TextWnd, &r);
|
|
|
|
GetClientRect(TextWnd, &rc);
|
|
|
|
ClientIsSmallerBy = (r.bottom - r.top) - (rc.bottom - rc.top);
|
|
|
|
}
|
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Test if a message comes from the SpaceNavigator device. If yes, dispatch
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
// it appropriately and return true. Otherwise, do nothing and return false.
|
2009-07-21 03:05:33 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
static bool ProcessSpaceNavigatorMsg(MSG *msg) {
|
|
|
|
if(SpaceNavigator == SI_NO_HANDLE) return false;
|
2009-07-21 03:05:33 +08:00
|
|
|
|
|
|
|
SiGetEventData sged;
|
|
|
|
SiSpwEvent sse;
|
|
|
|
|
|
|
|
SiGetEventWinInit(&sged, msg->message, msg->wParam, msg->lParam);
|
|
|
|
int ret = SiGetEvent(SpaceNavigator, 0, &sged, &sse);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
if(ret == SI_NOT_EVENT) return false;
|
2009-07-21 03:05:33 +08:00
|
|
|
// So the device is a SpaceNavigator event, or a SpaceNavigator error.
|
|
|
|
|
|
|
|
if(ret == SI_IS_EVENT) {
|
|
|
|
if(sse.type == SI_MOTION_EVENT) {
|
|
|
|
// The Z axis translation and rotation are both
|
|
|
|
// backwards in the default mapping.
|
2009-07-26 09:29:56 +08:00
|
|
|
double tx = sse.u.spwData.mData[SI_TX]*1.0,
|
|
|
|
ty = sse.u.spwData.mData[SI_TY]*1.0,
|
|
|
|
tz = -sse.u.spwData.mData[SI_TZ]*1.0,
|
2009-07-21 03:05:33 +08:00
|
|
|
rx = sse.u.spwData.mData[SI_RX]*0.001,
|
|
|
|
ry = sse.u.spwData.mData[SI_RY]*0.001,
|
|
|
|
rz = -sse.u.spwData.mData[SI_RZ]*0.001;
|
|
|
|
SS.GW.SpaceNavigatorMoved(tx, ty, tz, rx, ry, rz,
|
|
|
|
!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
|
|
|
|
} else if(sse.type == SI_BUTTON_EVENT) {
|
|
|
|
int button;
|
|
|
|
button = SiButtonReleased(&sse);
|
|
|
|
if(button == SI_APP_FIT_BUTTON) SS.GW.SpaceNavigatorButtonUp();
|
|
|
|
}
|
|
|
|
}
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
return true;
|
2009-07-21 03:05:33 +08:00
|
|
|
}
|
2015-03-29 08:33:46 +08:00
|
|
|
#endif // HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Entry point into the program.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
|
|
LPSTR lpCmdLine, INT nCmdShow)
|
|
|
|
{
|
|
|
|
Instance = hInstance;
|
|
|
|
|
2008-04-21 18:12:04 +08:00
|
|
|
InitCommonControls();
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
// A monospaced font
|
2015-12-27 15:51:28 +08:00
|
|
|
FixedFont = CreateFontW(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0,
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 13:45:13 +08:00
|
|
|
FW_REGULAR, false,
|
|
|
|
false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
2015-12-27 15:51:28 +08:00
|
|
|
DEFAULT_QUALITY, FF_DONTCARE, L"Lucida Console");
|
2008-03-25 18:02:13 +08:00
|
|
|
if(!FixedFont)
|
|
|
|
FixedFont = (HFONT)GetStockObject(SYSTEM_FONT);
|
|
|
|
|
2008-04-21 18:12:04 +08:00
|
|
|
// Create the root windows: one for control, with text, and one for
|
|
|
|
// the graphics
|
|
|
|
CreateMainWindows();
|
|
|
|
|
2015-12-26 23:54:26 +08:00
|
|
|
ThawWindowPos(TextWnd, "TextWnd");
|
|
|
|
ThawWindowPos(GraphicsWnd, "GraphicsWnd");
|
2008-04-21 18:12:04 +08:00
|
|
|
|
2009-06-14 12:36:38 +08:00
|
|
|
ShowWindow(TextWnd, SW_SHOWNOACTIVATE);
|
|
|
|
ShowWindow(GraphicsWnd, SW_SHOW);
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2009-06-14 12:36:38 +08:00
|
|
|
glClearColor(0, 0, 0, 1);
|
2015-03-29 08:30:52 +08:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2009-06-14 12:36:38 +08:00
|
|
|
SwapBuffers(GetDC(GraphicsWnd));
|
|
|
|
glClearColor(0, 0, 0, 1);
|
2015-03-29 08:30:52 +08:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2009-06-14 12:36:38 +08:00
|
|
|
SwapBuffers(GetDC(GraphicsWnd));
|
|
|
|
|
2009-04-20 15:30:09 +08:00
|
|
|
// Create the heaps for all dynamic memory (AllocTemporary, MemAlloc)
|
|
|
|
InitHeaps();
|
2008-04-13 22:28:35 +08:00
|
|
|
|
2015-12-27 15:51:28 +08:00
|
|
|
// Pull out the Unicode command line.
|
|
|
|
int argc;
|
|
|
|
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
|
|
|
|
2008-06-16 16:35:05 +08:00
|
|
|
// A filename may have been specified on the command line; if so, then
|
|
|
|
// strip any quotation marks, and make it absolute.
|
2015-12-27 15:51:28 +08:00
|
|
|
std::wstring filenameRel, filename;
|
|
|
|
if(argc >= 2) {
|
|
|
|
filenameRel = argv[1];
|
|
|
|
if(filenameRel[0] == L'\"' && filenameRel[filenameRel.length() - 1] == L'\"') {
|
|
|
|
filenameRel.erase(0, 1);
|
|
|
|
filenameRel.erase(filenameRel.length() - 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD len = GetFullPathNameW(&filenameRel[0], 0, NULL, NULL);
|
|
|
|
filename.resize(len - 1);
|
|
|
|
GetFullPathNameW(&filenameRel[0], len, &filename[0], NULL);
|
|
|
|
}
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
// Initialize the SpaceBall, if present. Test if the driver is running
|
|
|
|
// first, to avoid a long timeout if it's not.
|
2015-12-27 15:51:28 +08:00
|
|
|
HWND swdc = FindWindowW(L"SpaceWare Driver Class", NULL);
|
2009-07-21 03:05:33 +08:00
|
|
|
if(swdc != NULL) {
|
|
|
|
SiOpenData sod;
|
|
|
|
SiInitialize();
|
|
|
|
SiOpenWinInit(&sod, GraphicsWnd);
|
|
|
|
SpaceNavigator =
|
|
|
|
SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod);
|
|
|
|
SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS);
|
|
|
|
}
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2015-03-29 08:30:52 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
// Call in to the platform-independent code, and let them do their init
|
2015-03-24 14:45:53 +08:00
|
|
|
SS.Init();
|
2015-12-27 09:03:24 +08:00
|
|
|
if(!filename.empty())
|
2015-12-27 15:51:28 +08:00
|
|
|
SS.OpenFile(Narrow(filename));
|
2008-03-26 17:18:12 +08:00
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
// And now it's the message loop. All calls in to the rest of the code
|
|
|
|
// will be from the wndprocs.
|
|
|
|
MSG msg;
|
|
|
|
DWORD ret;
|
2013-08-27 04:54:04 +08:00
|
|
|
while((ret = GetMessage(&msg, NULL, 0, 0)) != 0) {
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
// Is it a message from the six degree of freedom input device?
|
|
|
|
if(ProcessSpaceNavigatorMsg(&msg)) goto done;
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
|
|
|
// A message from the keyboard, which should be processed as a keyboard
|
|
|
|
// accelerator?
|
2008-04-12 23:17:58 +08:00
|
|
|
if(msg.message == WM_KEYDOWN) {
|
2008-06-04 02:28:41 +08:00
|
|
|
if(ProcessKeyDown(msg.wParam)) goto done;
|
|
|
|
}
|
|
|
|
if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) {
|
|
|
|
// If the user presses the Alt key when the text window has focus,
|
|
|
|
// then that should probably go to the graphics window instead.
|
|
|
|
SetForegroundWindow(GraphicsWnd);
|
2008-04-12 23:17:58 +08:00
|
|
|
}
|
2009-07-21 03:05:33 +08:00
|
|
|
|
|
|
|
// None of the above; so just a normal message to process.
|
2008-03-25 18:02:13 +08:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
2008-06-04 02:28:41 +08:00
|
|
|
done:
|
|
|
|
SS.DoLater();
|
2008-03-25 18:02:13 +08:00
|
|
|
}
|
2008-05-28 18:10:31 +08:00
|
|
|
|
2015-03-29 08:33:46 +08:00
|
|
|
#ifdef HAVE_SPACEWARE
|
2009-07-21 03:05:33 +08:00
|
|
|
if(swdc != NULL) {
|
|
|
|
if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator);
|
|
|
|
SiTerminate();
|
|
|
|
}
|
2013-09-21 03:25:14 +08:00
|
|
|
#endif
|
2009-07-21 03:05:33 +08:00
|
|
|
|
2008-05-28 18:10:31 +08:00
|
|
|
// Write everything back to the registry
|
2015-12-26 23:54:26 +08:00
|
|
|
FreezeWindowPos(TextWnd, "TextWnd");
|
|
|
|
FreezeWindowPos(GraphicsWnd, "GraphicsWnd");
|
2013-09-19 12:33:12 +08:00
|
|
|
|
|
|
|
// Free the memory we've used; anything that remains is a leak.
|
|
|
|
SK.Clear();
|
|
|
|
SS.Clear();
|
|
|
|
|
2008-03-25 18:02:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|