experimental changes to get it compiling on win16

This commit is contained in:
IoIxD 2026-08-09 14:06:19 -07:00
commit 336019b94d
30 changed files with 8582 additions and 8442 deletions

3
.gitignore vendored
View file

@ -22,10 +22,11 @@ compile_flags.txt
/vms
/BorMakefile
*.err
*.pef
*.dsk
*.bin
*.rsrc
*.finf
*.gdb

27
WatMakefile generated
View file

@ -1,10 +1,22 @@
!ifndef %mw16
CC = wcc386 -bt=nt -q
!else
CC = wcc -bt=windows -q
!endif
LD = wlink option quiet
MW_CFLAGS = -bd -i=include -i=external/libz/include -d_MILSKO -d_MILSKO_BUILD -dUSE_GDI -dUSE_STB_TRUETYPE -dUSE_STB_IMAGE -dSTBI_NO_SIMD
MW_LDFLAGS = system nt_dll
EXE_CFLAGS = -i=include
!ifndef %mw16
MW_CFLAGS = -bd -i=include -i=external/libz/include -d_MILSKO -d_MILSKO_BUILD -dUSE_GDI -dUSE_STB_TRUETYPE -dUSE_STB_IMAGE -dSTBI_NO_SIMD -dMW_OPENGL
MW_LDFLAGS = system nt_dll
EXE_LDFLAGS = system nt
!else
MW_CFLAGS = -bd -i=include -i=external/libz/include -d_MILSKO -d_MILSKO_BUILD -dUSE_GDI -dSTBI_NO_SIMD -dNO_IMAGE -os -oh
MW_LDFLAGS = system windows_dll
EXE_LDFLAGS = system windows
!endif
all: src/Mw.dll examples/basic/box.exe examples/basic/calculator.exe examples/basic/checkbox.exe examples/basic/clipboard.exe examples/basic/colorpicker.exe examples/basic/combobox.exe examples/basic/example.exe examples/basic/filechooser.exe examples/basic/image.exe examples/basic/listbox.exe examples/basic/messagebox.exe examples/basic/periodic.exe examples/basic/progressbar.exe examples/basic/radiobox.exe examples/basic/rotate.exe examples/basic/scrollbar.exe examples/basic/sevensegment.exe examples/basic/subwindow.exe examples/basic/tab.exe examples/basic/treeview.exe examples/basic/viewport.exe examples/gldemos/boing.exe examples/gldemos/clock.exe examples/gldemos/cube.exe examples/gldemos/gears.exe examples/gldemos/triangle.exe examples/gldemos/tripaint.exe
lib: src/Mw.dll
examples: examples/basic/box.exe examples/basic/calculator.exe examples/basic/checkbox.exe examples/basic/clipboard.exe examples/basic/colorpicker.exe examples/basic/combobox.exe examples/basic/example.exe examples/basic/filechooser.exe examples/basic/image.exe examples/basic/listbox.exe examples/basic/messagebox.exe examples/basic/periodic.exe examples/basic/progressbar.exe examples/basic/radiobox.exe examples/basic/rotate.exe examples/basic/scrollbar.exe examples/basic/sevensegment.exe examples/basic/subwindow.exe examples/basic/tab.exe examples/basic/treeview.exe examples/basic/viewport.exe examples/gldemos/boing.exe examples/gldemos/clock.exe examples/gldemos/cube.exe examples/gldemos/gears.exe examples/gldemos/triangle.exe examples/gldemos/tripaint.exe
@ -280,6 +292,7 @@ examples/basic/viewport.exe: examples/basic/viewport.obj src/Mw.dll
examples/basic/viewport.obj: examples/basic/viewport.c
$(CC) $(EXE_CFLAGS) -fo=$@ examples/basic/viewport.c
!ifndef %mw16
examples/gldemos/boing.exe: examples/gldemos/boing.obj src/Mw.dll
$(LD) $(EXE_LDFLAGS) name $@ file examples/gldemos/boing.obj library clib3r.lib library src/Mw.lib library opengl32.lib library glu32.lib
@ -315,11 +328,15 @@ examples/gldemos/tripaint.exe: examples/gldemos/tripaint.obj src/Mw.dll
examples/gldemos/tripaint.obj: examples/gldemos/tripaint.c
$(CC) $(EXE_CFLAGS) -fo=$@ examples/gldemos/tripaint.c
!endif
!ifndef %mw16
src/Mw.dll: external/libz/src/adler32.obj external/libz/src/compress.obj external/libz/src/crc32.obj external/libz/src/deflate.obj external/libz/src/gzclose.obj external/libz/src/gzlib.obj external/libz/src/gzread.obj external/libz/src/gzwrite.obj external/libz/src/infback.obj external/libz/src/inffast.obj external/libz/src/inflate.obj external/libz/src/inftrees.obj external/libz/src/trees.obj external/libz/src/uncompr.obj external/libz/src/zutil.obj external/stb_ds.obj external/stb_image.obj external/stb_truetype.obj src/abstract/charset.obj src/abstract/directory.obj src/abstract/dynamic.obj src/abstract/time.obj src/backend/gdi.obj src/color.obj src/core.obj src/cursor/arrow.obj src/cursor/cross.obj src/cursor/default.obj src/cursor/hidden.obj src/cursor/text.obj src/default.obj src/dialog/colorpicker.obj src/dialog/directorychooser.obj src/dialog/filechooser.obj src/dialog/messagebox.obj src/draw.obj src/icon/back.obj src/icon/clock.obj src/icon/computer.obj src/icon/directory.obj src/icon/down.obj src/icon/error.obj src/icon/file.obj src/icon/forward.obj src/icon/info.obj src/icon/left.obj src/icon/news.obj src/icon/note.obj src/icon/right.obj src/icon/search.obj src/icon/up.obj src/icon/warning.obj src/lowlevel.obj src/string.obj src/text/font/boldfont.obj src/text/font/boldmonottf.obj src/text/font/boldttf.obj src/text/font/font.obj src/text/font/monottf.obj src/text/font/ttf.obj src/text/ft2.obj src/text/stbtt.obj src/text/text.obj src/unicode.obj src/widget/box.obj src/widget/button.obj src/widget/calendar.obj src/widget/checkbox.obj src/widget/combobox.obj src/widget/entry.obj src/widget/frame.obj src/widget/image.obj src/widget/label.obj src/widget/listbox.obj src/widget/menu.obj src/widget/numberentry.obj src/widget/opengl.obj src/widget/progressbar.obj src/widget/radiobox.obj src/widget/scrollbar.obj src/widget/separator.obj src/widget/submenu.obj src/widget/subwindow.obj src/widget/tab.obj src/widget/table.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(MW_LDFLAGS) option implib=src/Mw.lib name $@ file external/libz/src/adler32.obj file external/libz/src/compress.obj file external/libz/src/crc32.obj file external/libz/src/deflate.obj file external/libz/src/gzclose.obj file external/libz/src/gzlib.obj file external/libz/src/gzread.obj file external/libz/src/gzwrite.obj file external/libz/src/infback.obj file external/libz/src/inffast.obj file external/libz/src/inflate.obj file external/libz/src/inftrees.obj file external/libz/src/trees.obj file external/libz/src/uncompr.obj file external/libz/src/zutil.obj file external/stb_ds.obj file external/stb_image.obj file external/stb_truetype.obj file src/abstract/charset.obj file src/abstract/directory.obj file src/abstract/dynamic.obj file src/abstract/time.obj file src/backend/gdi.obj file src/color.obj file src/core.obj file src/cursor/arrow.obj file src/cursor/cross.obj file src/cursor/default.obj file src/cursor/hidden.obj file src/cursor/text.obj file src/default.obj file src/dialog/colorpicker.obj file src/dialog/directorychooser.obj file src/dialog/filechooser.obj file src/dialog/messagebox.obj file src/draw.obj file src/icon/back.obj file src/icon/clock.obj file src/icon/computer.obj file src/icon/directory.obj file src/icon/down.obj file src/icon/error.obj file src/icon/file.obj file src/icon/forward.obj file src/icon/info.obj file src/icon/left.obj file src/icon/news.obj file src/icon/note.obj file src/icon/right.obj file src/icon/search.obj file src/icon/up.obj file src/icon/warning.obj file src/lowlevel.obj file src/string.obj file src/text/font/boldfont.obj file src/text/font/boldmonottf.obj file src/text/font/boldttf.obj file src/text/font/font.obj file src/text/font/monottf.obj file src/text/font/ttf.obj file src/text/ft2.obj file src/text/stbtt.obj file src/text/text.obj file src/unicode.obj file src/widget/box.obj file src/widget/button.obj file src/widget/calendar.obj file src/widget/checkbox.obj file src/widget/combobox.obj file src/widget/entry.obj file src/widget/frame.obj file src/widget/image.obj file src/widget/label.obj file src/widget/listbox.obj file src/widget/menu.obj file src/widget/numberentry.obj file src/widget/opengl.obj file src/widget/progressbar.obj file src/widget/radiobox.obj file src/widget/scrollbar.obj file src/widget/separator.obj file src/widget/submenu.obj file src/widget/subwindow.obj file src/widget/tab.obj file src/widget/table.obj file src/widget/treeview.obj file src/widget/viewport.obj file src/widget/window.obj library clib3r.lib library opengl32.lib library gdi32.lib library user32.lib library advapi32.lib
!else
src/Mw.dll: external/stb_ds.obj src/abstract/charset.obj src/abstract/directory.obj src/abstract/dynamic.obj src/abstract/time.obj src/backend/gdi.obj src/color.obj src/core.obj src/default.obj src/dialog/colorpicker.obj src/dialog/directorychooser.obj src/dialog/filechooser.obj src/dialog/messagebox.obj src/draw.obj src/lowlevel.obj src/string.obj src/text/text.obj src/text/font/font.obj src/text/font/boldfont.obj src/unicode.obj src/widget/box.obj src/widget/button.obj src/widget/calendar.obj src/widget/checkbox.obj src/widget/combobox.obj src/widget/entry.obj src/widget/frame.obj src/widget/image.obj src/widget/label.obj src/widget/listbox.obj src/widget/menu.obj src/widget/numberentry.obj src/widget/progressbar.obj src/widget/radiobox.obj src/widget/scrollbar.obj src/widget/separator.obj src/widget/submenu.obj src/widget/subwindow.obj src/widget/tab.obj src/widget/table.obj src/widget/treeview.obj src/widget/viewport.obj src/widget/window.obj
$(LD) $(MW_LDFLAGS) option implib=src/Mw.lib name $@ file external/stb_ds.obj file src/abstract/charset.obj file src/abstract/directory.obj file src/abstract/dynamic.obj file src/abstract/time.obj file src/backend/gdi.obj file src/color.obj file src/core.obj file src/default.obj file src/dialog/colorpicker.obj file src/dialog/directorychooser.obj file src/dialog/filechooser.obj file src/dialog/messagebox.obj file src/draw.obj file src/lowlevel.obj file src/string.obj file src/text/text.obj file src/text/font/font.obj file src/text/font/boldfont.obj file src/unicode.obj file src/widget/box.obj file src/widget/button.obj file src/widget/calendar.obj file src/widget/checkbox.obj file src/widget/combobox.obj file src/widget/entry.obj file src/widget/frame.obj file src/widget/image.obj file src/widget/label.obj file src/widget/listbox.obj file src/widget/menu.obj file src/widget/numberentry.obj file src/widget/progressbar.obj file src/widget/radiobox.obj file src/widget/scrollbar.obj file src/widget/separator.obj file src/widget/submenu.obj file src/widget/subwindow.obj file src/widget/tab.obj file src/widget/table.obj file src/widget/treeview.obj file src/widget/viewport.obj file src/widget/window.obj library clibs.lib
!endif
external/libz/src/adler32.obj: external/libz/src/adler32.c
@ -474,8 +491,10 @@ src/widget/menu.obj: src/widget/menu.c
$(CC) $(MW_CFLAGS) -fo=$@ src/widget/menu.c
src/widget/numberentry.obj: src/widget/numberentry.c
$(CC) $(MW_CFLAGS) -fo=$@ src/widget/numberentry.c
!ifndef %mw16
src/widget/opengl.obj: src/widget/opengl.c
$(CC) $(MW_CFLAGS) -fo=$@ src/widget/opengl.c
!endif
src/widget/progressbar.obj: src/widget/progressbar.c
$(CC) $(MW_CFLAGS) -fo=$@ src/widget/progressbar.c
src/widget/radiobox.obj: src/widget/radiobox.c

View file

@ -2,8 +2,16 @@
MwWidget fpicker;
MwWidget window;
MwWidget button;
/* This example does nothing on Win16 because we don't support the color picker on it (yet?) */
#ifdef __WINDOWS__
MwWidget missing_text;
#else
MwWidget button;
#endif
/* don't bother with color picker on win16 */
#ifndef __WINDOWS__
void MWAPI file_callback(MwWidget handle, void* user_data, void* call_data) {
char hexColor[8];
MwRGB* rgb = call_data;
@ -29,6 +37,7 @@ void MWAPI file_picker(MwWidget handle, void* user_data, void* call_data) {
MwSetText(cpicker, MwNbackground, MwGetInteger(cpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
}
#endif
int main() {
MwLibraryInit();
@ -37,12 +46,18 @@ int main() {
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
#ifndef __WINDOWS__
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
MwNtext, "change window background",
NULL);
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
MwAddUserHandler(button, MwNactivateHandler, file_picker, NULL);
#else
missing_text = MwVaCreateWidget(MwLabelClass, NULL, window, 160, 180, 320, 120,
MwNtext, "Color picker doesn't yet exist on 16-bit Windows",
NULL);
#endif
MwLoop(window);
}

2445
external/stb_ds.h generated vendored

File diff suppressed because it is too large Load diff

11649
external/stb_image.h generated vendored

File diff suppressed because it is too large Load diff

View file

@ -49,6 +49,9 @@ typedef __int8 MwI8;
typedef unsigned __int8 MwU8;
#define MW_OTHER_TYPES_DEFINED
#elif defined(__WINDOWS__)
typedef long long MwI64;
typedef unsigned long long MwU64;
#else
/* out of hope */
typedef long MwI64;
@ -58,6 +61,16 @@ typedef unsigned long MwU64;
#ifdef MW_OTHER_TYPES_DEFINED
#undef MW_OTHER_TYPES_DEFINED
#else
#ifdef __WINDOWS__
typedef long MwI32;
typedef unsigned long MwU32;
typedef int MwI16;
typedef unsigned int MwU16;
typedef signed char MwI8;
typedef unsigned char MwU8;
#else
typedef int MwI32;
typedef unsigned int MwU32;
@ -67,6 +80,7 @@ typedef unsigned short MwU16;
typedef signed char MwI8;
typedef unsigned char MwU8;
#endif
#endif
typedef MwI64 MwOffset;

View file

@ -35,7 +35,11 @@ enum MwALIGNMENT {
/*!
* @brief Default
*/
#ifdef __WINDOWS__
#define MwDEFAULT 0x0ffff
#else
#define MwDEFAULT 0x0fffffff
#endif
/*!
* @brief Directory entry type

View file

@ -12,6 +12,9 @@
extern "C" {
#endif
#ifdef __WINDOWS__
#error Color Picker Widget is not avaliable on Win16
#else
/*!
* @brief Creates a color picker
* @param handle Widget
@ -19,6 +22,7 @@ extern "C" {
* @return Widget
*/
MWDECL MwWidget MWAPI MwColorPicker(MwWidget handle, const char* title);
#endif
#ifdef __cplusplus
}

View file

@ -162,6 +162,7 @@ MWDECL unsigned char* MWAPI MwPixmapGetRaw(MwLLPixmap pixmap);
*/
MWDECL void MWAPI MwPixmapGetSize(MwLLPixmap pixmap, MwRect* rect);
#ifndef __WINDOWS__
/*!
* @brief Creates a pixmap from XPM data
* @param handle Widget
@ -169,6 +170,7 @@ MWDECL void MWAPI MwPixmapGetSize(MwLLPixmap pixmap, MwRect* rect);
* @return Pixmap
*/
MWDECL MwLLPixmap MWAPI MwLoadXPM(MwWidget handle, char** data);
#endif
/*!
* @brief Creates a pixmap from icon data

View file

@ -334,6 +334,7 @@ MWDECL void (*MwLLRaise)(MwLL handle);
MWDECL void (*MwLLClip)(MwLL handle, MwRect* rect);
/* font renderer */
#ifndef __WINDOWS__
MWDECL void MwFLSetup(void);
#ifdef USE_FREETYPE2
@ -348,6 +349,7 @@ MWDECL int (*MwFLTextWidth)(MwFLFont ttf, const char* text);
MWDECL int (*MwFLTextHeight)(MwFLFont ttf, int count);
MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px);
MWDECL void (*MwFLFontFree)(void* handle);
#endif
#ifdef __cplusplus
}

View file

@ -42,6 +42,7 @@ struct _MwLLGDIPixmap {
RGBQUAD* quad;
HBITMAP hBitmap;
HDC hBitmapMem;
HBITMAP hMask;
HBITMAP hMask2;
};

View file

@ -20,11 +20,18 @@
#include <wchar.h>
#define MW_HAS_WCHAR
#endif
#ifdef _WIN32
#if defined(_WIN32) || defined(__WINDOWS__)
#include <direct.h>
#ifdef _MILSKO
#include <windows.h>
#if defined(__WINDOWS__)
#include <dos.h>
#define GetSysColorBrush(x) CreateSolidBrush(GetSysColor(x))
#endif
#ifndef HALFTONE
#define HALFTONE 4
#endif
#ifndef GWLP_USERDATA
#define GWLP_USERDATA GWL_USERDATA
#define GWLP_WNDPROC GWL_WNDPROC
@ -35,6 +42,9 @@
#define SetClassLongPtr SetClassLong
#define GetClassLongPtr GetClassLong
#endif
#ifndef GWL_USERDATA
#define GWL_USERDATA (-21)
#endif
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020a
#define GET_WHEEL_DELTA_WPARAM(x) ((short)HIWORD(x))
@ -89,9 +99,9 @@
#endif
/* Windows */
#if defined(_MILSKO) && defined(_MILSKO_BUILD) && defined(_WIN32)
#if defined(_MILSKO) && defined(_MILSKO_BUILD) && defined(_WIN32) || defined(__WINDOWS__)
#define MWDECL extern __declspec(dllexport)
#elif defined(_WIN32)
#elif defined(_WIN32) || defined(__WINDOWS__)
#define MWDECL extern __declspec(dllimport)
/* GCC/Clang */
/* First check if we have __has_attribute and can check for the existence of visibility */
@ -111,7 +121,7 @@
#define MWDECL extern
#endif
#if defined(_WIN32)
#if defined(_WIN32) || defined(__WINDOWS__)
#define MWAPI __cdecl
#else
#define MWAPI

View file

@ -23,14 +23,18 @@
#include <Mw/Abstract/Time.h>
#include <Mw/Abstract/CharSet.h>
#ifndef __WINDOWS__
#include <Mw/Resource/Icon.h>
#endif
#include <Mw/Resource/Cursor.h>
#include <Mw/Resource/Font.h>
#include <Mw/Dialog/MessageBox.h>
#include <Mw/Dialog/FileChooser.h>
#include <Mw/Dialog/DirectoryChooser.h>
#ifndef __WINDOWS__
#include <Mw/Dialog/ColorPicker.h>
#endif
#include <Mw/Widget/Box.h>
#include <Mw/Widget/Button.h>

View file

@ -13,6 +13,7 @@
extern "C" {
#endif
#ifndef __WINDOWS__
/*!
* @brief Default cursor
*/
@ -63,6 +64,8 @@ MWDECL MwCursor MwCursorHidden;
*/
MWDECL MwCursor MwCursorHiddenMask;
#endif
#ifdef __cplusplus
}
#endif

View file

@ -10,7 +10,7 @@
#include <Mw/TypeDefs.h>
#if !defined(MW_OPENGL_NO_INCLUDE) && !defined(__gl_h_)
#ifdef _WIN32
#if defined(_WIN32) || defined(__WINDOWS__)
#include <windows.h>
#elif defined(__APPLE__)
#else

View file

@ -1,11 +1,16 @@
#include <Mw/Milsko.h>
#ifdef _WIN32
#if defined(_WIN32)
typedef struct dir {
HANDLE hFind;
WIN32_FIND_DATA ffd;
int next;
} dir_t;
#elif defined(__WINDOWS__)
typedef struct dir {
struct find_t result;
int next;
} dir_t;
#elif defined(CLASSIC_MAC_OS)
typedef struct dir {
int dummy;
@ -19,7 +24,7 @@ typedef struct dir {
void* MwDirectoryOpen(const char* path) {
dir_t* dir = malloc(sizeof(*dir));
#ifdef _WIN32
#if defined(_WIN32)
char* p = malloc(strlen(path) + 2 + 1);
strcpy(p, path);
if(strchr(path, '/') != NULL) {
@ -35,6 +40,22 @@ void* MwDirectoryOpen(const char* path) {
}
free(p);
dir->next = 1;
#elif defined(__WINDOWS__)
char* p = malloc(strlen(path) + 2 + 1);
strcpy(p, path);
if(strchr(path, '/') != NULL) {
strcat(p, "/");
} else {
strcat(p, "\\");
}
strcat(p, "*.*");
if(_dos_findfirst(p, _A_NORMAL, &dir->result) != 0) {
free(p);
free(dir);
return NULL;
}
free(p);
dir->next = 1;
#elif defined(CLASSIC_MAC_OS)
/* todo */
#else
@ -51,8 +72,10 @@ void* MwDirectoryOpen(const char* path) {
void MwDirectoryClose(void* handle) {
dir_t* dir = handle;
#ifdef _WIN32
#if defined(_WIN32)
FindClose(dir->hFind);
#elif defined(__WINDOWS__)
/* nothing? */
#elif defined(CLASSIC_MAC_OS)
/* todo */
#else
@ -65,7 +88,7 @@ void MwDirectoryClose(void* handle) {
MwDirectoryEntry* MwDirectoryRead(void* handle) {
dir_t* dir = handle;
MwDirectoryEntry* entry = malloc(sizeof(*entry));
#ifdef _WIN32
#if defined(_WIN32)
ULARGE_INTEGER* l;
if(!dir->next) return NULL;
@ -88,6 +111,21 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) {
entry->mtime = l->QuadPart / 10000000 - 11644473600;
dir->next = FindNextFile(dir->hFind, &dir->ffd);
#elif defined(__WINDOWS__)
if(!dir->next) return NULL;
entry->name = MwStringDuplicate(dir->result.name);
if(dir->result.attrib & _A_SUBDIR) {
entry->type = MwDIRECTORY_DIRECTORY;
} else {
entry->type = MwDIRECTORY_FILE;
}
entry->size = dir->result.size;
entry->mtime = MwDosDateTimeToUnix(dir->result.wr_date, dir->result.wr_time);
dir->next = (_dos_findnext(&dir->result) == 0);
#elif defined(CLASSIC_MAC_OS)
/* todo */
#else
@ -126,7 +164,7 @@ void MwDirectoryFreeEntry(MwDirectoryEntry* entry) {
}
char* MwDirectoryCurrent(void) {
#ifdef _WIN32
#if defined(_WIN32) || defined(__WINDOWS__)
int len = GetCurrentDirectory(0, NULL);
char* out = malloc(len);
@ -140,7 +178,7 @@ char* MwDirectoryCurrent(void) {
#endif
}
#ifdef _WIN32
#if defined(_WIN32) || defined(__WINDOWS__)
#define DIRSEP '\\'
#else
#define DIRSEP '/'

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
#if defined(_WIN32)
#if defined(_WIN32) || defined(__WINDOWS__)
void* MwDynamicOpen(const char* path) {
return LoadLibrary(path);
}

View file

@ -1,6 +1,6 @@
#include <Mw/Milsko.h>
#if defined(_WIN32)
#if defined(_WIN32) || defined(__WINDOWS__)
long MwTimeGetTick(void) {
return GetTickCount();
}

View file

@ -8,14 +8,13 @@ typedef struct userdata {
int max_set;
} userdata_t;
#ifndef __WINDOWS__
static struct symtbl {
void* lib_dwmapi;
HRESULT(WINAPI* DwmSetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
} wsymtbl;
static int is_plgblt_reliable = 0;
#define DwmSetWindowAttribute wsymtbl.DwmSetWindowAttribute
/* Dark theme detection for classic Windows: check if the user has set their theme to be dark. */
@ -62,6 +61,15 @@ static void detect_darktheme(MwLL handle) {
MwLLDispatch(handle, dark_theme, &t);
}
#endif
/* There isn't any plgblt on Win16 at all */
#ifdef __WINDOWS__
#define is_plgblt_reliable 0
#else
static int is_plgblt_reliable = 0;
#endif
static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
userdata_t* u = (userdata_t*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
@ -125,7 +133,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
p.button = MwMOUSE_RIGHT;
}
SetCapture(NULL);
SetCapture(0);
MwLLDispatch(u->ll, up, &p);
} else if(msg == WM_MOUSEWHEEL) {
int d = GET_WHEEL_DELTA_WPARAM(wp);
@ -182,12 +190,18 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else if(msg == WM_CLOSE) {
MwLLDispatch(u->ll, close, NULL);
} else if(msg == WM_CHAR || msg == WM_SYSCHAR) {
int n = wp;
#ifndef __WINDOWS__
int n = wp;
#else
unsigned long n = wp;
#endif
const int base = 'A' - 1;
if(n != 0x1b && n <= 0x1f) {
n = (n + base) | MwKEY_CONTROL_FLAG;
#ifndef __WINDOWS__
if(!(GetKeyState(VK_LSHIFT) || GetKeyState(VK_RSHIFT))) n += 0x20;
#endif
}
if(HIBYTE(VkKeyScan(wp)) & 2) n |= MwKEY_CONTROL_FLAG;
if(msg == WM_SYSCHAR) n |= MwKEY_ALT_FLAG;
@ -198,7 +212,11 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else if(msg == WM_KILLFOCUS) {
MwLLDispatch(u->ll, focus_out, NULL);
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP || msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP) {
#ifndef __WINDOWS__
int n = -1;
#else
unsigned long n = -1;
#endif
if(wp == VK_MENU && msg == WM_KEYUP) return 0;
if(wp == VK_LEFT) n = MwKEY_LEFT;
if(wp == VK_RIGHT) n = MwKEY_RIGHT;
@ -207,8 +225,10 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
if(wp == VK_RETURN) n = MwKEY_ENTER;
if(wp == VK_BACK) n = MwKEY_BACKSPACE;
if(wp == VK_ESCAPE) n = MwKEY_ESCAPE;
#ifndef __WINDOWS__
if(wp == VK_LSHIFT) n = MwKEY_LEFTSHIFT;
if(wp == VK_RSHIFT) n = MwKEY_RIGHTSHIFT;
#endif
if(wp == VK_MENU) n = MwKEY_ALT;
if(wp == VK_CONTROL) n = MwKEY_CONTROL;
@ -255,7 +275,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
}
} else if(msg == WM_SETCURSOR) {
if(LOWORD(lp) != HTCLIENT) return DefWindowProc(hWnd, msg, wp, lp);
if(u->ll->gdi.cursor != NULL) SetCursor(u->ll->gdi.cursor);
if(u->ll->gdi.cursor != 0) SetCursor(u->ll->gdi.cursor);
} else if(msg == WM_USER) {
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
@ -263,9 +283,11 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
char* s = (char*)lp;
LPARAM style = GetWindowLongPtr(hWnd, GWL_STYLE);
#ifndef __WINDOWS__
if(!(style & WS_CHILD)) {
if(s != NULL && strcmp(s, "ImmersiveColorSet") == 0) detect_darktheme(u->ll);
}
#endif
} else {
return DefWindowProc(hWnd, msg, wp, lp);
}
@ -275,10 +297,16 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
MwLL r = malloc(sizeof(*r));
userdata_t* u = malloc(sizeof(*u));
WNDCLASSEX wc;
#ifdef __WINDOWS__
WNDCLASS wc;
#else
WNDCLASSEX wc;
#endif
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
#ifndef __WINDOWS__
wc.cbSize = sizeof(WNDCLASSEX);
#endif
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = wndproc;
wc.cbClsExtra = 0;
@ -286,14 +314,22 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
wc.hInstance = (HINSTANCE)GetModuleHandle(NULL);
wc.lpszClassName = "milsko";
wc.lpszMenuName = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = GetSysColorBrush(COLOR_MENU);
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = NULL;
#ifndef __WINDOWS__
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = NULL;
#else
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
#endif
MwLLCreateCommon(r);
#ifdef __WINDOWS__
RegisterClass(&wc);
#else
RegisterClassEx(&wc);
#endif
r->common.copy_buffer = 1;
r->common.type = MwLLBackendGDI;
@ -302,12 +338,12 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
if(parent == NULL) r->gdi.get_darktheme = 1;
r->gdi.force_render = 0;
r->gdi.grabbed = 0;
r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->gdi.hWnd, 0, wc.hInstance, NULL);
r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? 0 : parent->gdi.hWnd, 0, wc.hInstance, NULL);
r->gdi.hInstance = wc.hInstance;
r->gdi.cursor = NULL;
r->gdi.icon = NULL;
r->gdi.cursor = 0;
r->gdi.icon = 0;
r->gdi.clip = NULL;
r->gdi.clip = 0;
u->ll = r;
u->min_set = 0;
@ -322,7 +358,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
rc.right = width;
rc.bottom = height;
AdjustWindowRect(&rc, GetWindowLongPtr(r->gdi.hWnd, GWL_STYLE), FALSE);
SetWindowPos(r->gdi.hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE);
SetWindowPos(r->gdi.hWnd, 0, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE);
ShowWindow(r->gdi.hWnd, SW_NORMAL);
UpdateWindow(r->gdi.hWnd);
@ -330,7 +366,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
InvalidateRect(r->gdi.hWnd, NULL, FALSE);
}
SetWindowPos(r->gdi.hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
SetWindowPos(r->gdi.hWnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
return r;
}
@ -342,9 +378,9 @@ static void MwLLDestroyImpl(MwLL handle) {
SetWindowLongPtr(handle->gdi.hWnd, GWLP_USERDATA, (LPARAM)NULL);
DestroyWindow(handle->gdi.hWnd);
if(handle->gdi.clip != NULL) DeleteObject(handle->gdi.clip);
if(handle->gdi.clip) DeleteObject(handle->gdi.clip);
if(handle->gdi.cursor != NULL) DestroyCursor(handle->gdi.cursor);
if(handle->gdi.cursor) DestroyCursor(handle->gdi.cursor);
free(handle);
}
@ -396,7 +432,7 @@ static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
MwLLColor c = malloc(sizeof(*c));
c->gdi.brush = NULL;
c->gdi.brush = 0;
MwLLColorUpdate(handle, c, r, g, b);
@ -413,7 +449,7 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
if(g < 0) g = 0;
if(b < 0) b = 0;
if(c->gdi.brush != NULL) DeleteObject(c->gdi.brush);
if(c->gdi.brush != 0) DeleteObject(c->gdi.brush);
c->gdi.brush = CreateSolidBrush(GetNearestColor(dc, RGB(r, g, b)));
c->common.red = r;
c->common.green = g;
@ -441,12 +477,12 @@ static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsign
}
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
SetWindowPos(handle->gdi.hWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
SetWindowPos(handle->gdi.hWnd, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, w, h, SWP_NOMOVE | SWP_NOZORDER);
InvalidateRect(handle->gdi.hWnd, NULL, FALSE);
SetWindowPos(handle->gdi.hWnd, 0, 0, 0, w, h, SWP_NOMOVE | SWP_NOZORDER);
InvalidateRect(handle->gdi.hWnd, 0, FALSE);
}
static void MwLLSetTitleImpl(MwLL handle, const char* title) {
@ -467,11 +503,12 @@ static void MwLLNextEventImpl(MwLL handle) {
(void)handle;
#ifndef __WINDOWS__
if(handle->gdi.get_clipboard) {
HGLOBAL hg;
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != NULL) {
char* txt = malloc(GlobalSize(hg));
if(OpenClipboard(handle->gdi.hWnd) != 0 && (hg = GetClipboardData(CF_TEXT)) != 0) {
char* clp = GlobalLock(hg);
char* txt = malloc(GlobalSize(hg));
strcpy(txt, clp);
@ -485,11 +522,15 @@ static void MwLLNextEventImpl(MwLL handle) {
handle->gdi.get_clipboard = 0;
}
#endif
#ifndef __WINDOWS__
if(handle->gdi.get_darktheme) {
detect_darktheme(handle);
handle->gdi.get_darktheme = 0;
}
#endif
while(PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg, handle->gdi.hWnd, 0, 0);
TranslateMessage(&msg);
@ -498,9 +539,13 @@ static void MwLLNextEventImpl(MwLL handle) {
}
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
MwLLPixmap r = malloc(sizeof(*r));
HDC dc = GetDC(handle->gdi.hWnd);
MwLLPixmap r = malloc(sizeof(*r));
HDC dc = GetDC(handle->gdi.hWnd);
#ifndef __WINDOWS__
BITMAPINFOHEADER bmih;
#else
BITMAPINFO bmi;
#endif
r->common.raw = malloc(width * height * 4);
memcpy(r->common.raw, data, 4 * width * height);
@ -508,6 +553,7 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
r->common.width = width;
r->common.height = height;
#ifndef __WINDOWS__
bmih.biSize = sizeof(bmih);
bmih.biWidth = width;
bmih.biHeight = -(LONG)height;
@ -521,9 +567,15 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
bmih.biClrImportant = 0;
r->gdi.hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&r->gdi.quad, NULL, (DWORD)0);
#else
r->gdi.hBitmap = CreateCompatibleBitmap(dc, width, height);
r->gdi.hBitmapMem = CreateCompatibleDC(dc);
SelectObject(r->gdi.hBitmapMem, r->gdi.hBitmap);
SetDIBits(r->gdi.hBitmapMem, r->gdi.hBitmap, 0, height, r->common.raw, &bmi, DIB_RGB_COLORS);
#endif
r->gdi.hMask = NULL;
r->gdi.hMask2 = NULL;
r->gdi.hMask = 0;
r->gdi.hMask2 = 0;
ReleaseDC(handle->gdi.hWnd, dc);
@ -563,8 +615,8 @@ static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
}
}
if(r->gdi.hMask != NULL) DeleteObject(r->gdi.hMask);
if(r->gdi.hMask2 != NULL) DeleteObject(r->gdi.hMask2);
if(r->gdi.hMask != 0) DeleteObject(r->gdi.hMask);
if(r->gdi.hMask2 != 0) DeleteObject(r->gdi.hMask2);
r->gdi.hMask = CreateBitmap(r->common.width, r->common.height, 1, 1, words);
r->gdi.hMask2 = CreateBitmap(r->common.width, r->common.height, 1, 1, words2);
@ -598,18 +650,27 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
SelectObject(hmdc, pixmap->gdi.hBitmap);
#ifndef __WINDOWS__
if(!is_plgblt_reliable || PlgBlt(handle->gdi.hDC, p, hmdc, 0, 0, pixmap->common.width, pixmap->common.height, pixmap->gdi.hMask, 0, 0) == 0) {
#endif
SelectObject(hmdc, pixmap->gdi.hMask2);
StretchBlt(handle->gdi.hDC, rect->x, rect->y, rect->width, rect->height, hmdc, 0, 0, pixmap->common.width, pixmap->common.height, SRCAND);
SelectObject(hmdc, pixmap->gdi.hBitmap);
StretchBlt(handle->gdi.hDC, rect->x, rect->y, rect->width, rect->height, hmdc, 0, 0, pixmap->common.width, pixmap->common.height, SRCPAINT);
#ifndef __WINDOWS__
}
#endif
DeleteDC(hmdc);
}
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
/* it's probably (presumably) not possible to set the icon on 16-bit windows */
#ifdef __WINDOWS__
(void)handle;
(void)pixmap;
#else
ICONINFO ii;
memset(&ii, 0, sizeof(ii));
@ -623,6 +684,7 @@ static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
handle->gdi.icon = CreateIconIndirect(&ii);
SendMessage(handle->gdi.hWnd, WM_SETICON, ICON_SMALL, (LPARAM)handle->gdi.icon);
SendMessage(handle->gdi.hWnd, WM_SETICON, ICON_BIG, (LPARAM)handle->gdi.icon);
#endif
}
static void MwLLForceRenderImpl(MwLL handle) {
@ -683,11 +745,19 @@ HCURSOR MwLLGDICreateCursor(MwCursor* image, MwCursor* mask) {
}
static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
HCURSOR cursor = MwLLGDICreateCursor(image, mask);
if(image && mask) {
HCURSOR cursor = MwLLGDICreateCursor(image, mask);
if(handle->gdi.cursor != NULL) DestroyCursor(handle->gdi.cursor);
if(handle->gdi.icon != NULL) DestroyIcon(handle->gdi.icon);
handle->gdi.cursor = cursor;
if(handle->gdi.cursor != 0) DestroyCursor(handle->gdi.cursor);
if(handle->gdi.icon != 0) DestroyIcon(handle->gdi.icon);
handle->gdi.cursor = cursor;
}
/* Only on Win16: hide the cursor outright if image/mask are null */
#ifndef __WINDOWS__
else if(!image && !mask) {
ShowCursor(FALSE);
}
#endif
}
static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
@ -701,12 +771,16 @@ static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
GetClientRect(handle->gdi.hWnd, &rc2);
#ifdef __WINDOWS__
if(lp2 & WS_POPUP) {
#else
if(lp2 & WS_EX_TOOLWINDOW) {
#endif
SetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE, (LPARAM)lp);
} else {
SetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE, (LPARAM)WS_OVERLAPPEDWINDOW | lp);
}
SetParent(handle->gdi.hWnd, NULL);
SetParent(handle->gdi.hWnd, 0);
rc.left += point->x;
rc.top += point->y;
@ -752,7 +826,7 @@ static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
SetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE, lp);
SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
SetWindowPos(handle->gdi.hWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
}
static void MwLLFocusImpl(MwLL handle) {
@ -789,6 +863,11 @@ static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
}
static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_type) {
#ifdef __WINDOWS__
(void)handle;
(void)text;
(void)clipboard_type;
#else
HGLOBAL hg;
(void)clipboard_type;
if(OpenClipboard(handle->gdi.hWnd) != 0) {
@ -805,6 +884,7 @@ static void MwLLSetClipboardImpl(MwLL handle, const char* text, int clipboard_ty
CloseClipboard();
}
#endif
}
static void MwLLGetClipboardImpl(MwLL handle, int clipboard_type) {
@ -818,14 +898,17 @@ static void MwLLMakeToolWindowImpl(MwLL handle) {
int w, h;
SetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE, (LPARAM)lp);
#ifdef __WINDOWS__
SetWindowLongPtr(handle->gdi.hWnd, GWL_EXSTYLE, (LPARAM)WS_POPUP);
#else
SetWindowLongPtr(handle->gdi.hWnd, GWL_EXSTYLE, (LPARAM)WS_EX_TOOLWINDOW);
#endif
GetClientRect(handle->gdi.hWnd, &rc);
w = rc.right - rc.left;
h = rc.bottom - rc.top;
SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, w, h, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
SetWindowPos(handle->gdi.hWnd, 0, 0, 0, w, h, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
}
static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {
@ -860,13 +943,21 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
}
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
#ifdef __WINDOWS__
(void)handle;
(void)toggle;
#else
BOOL v = toggle ? TRUE : FALSE;
if(DwmSetWindowAttribute)
DwmSetWindowAttribute(handle->gdi.hWnd, 20, &v, sizeof(v));
#endif
}
static MwBool MwLLDoModernImpl(MwLL handle) {
#ifdef __WINDOWS__
return MwFALSE;
#else
OSVERSIONINFO osvi;
(void)handle;
@ -880,34 +971,35 @@ static MwBool MwLLDoModernImpl(MwLL handle) {
}
return MwTRUE;
#endif
}
static void MwLLRaiseImpl(MwLL handle) {
SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
SetWindowPos(handle->gdi.hWnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
static void MwLLClipImpl(MwLL handle, MwRect* rect) {
if(rect == NULL) {
SelectClipRgn(handle->gdi.hDC, NULL);
SelectClipRgn(handle->gdi.hDC, 0);
if(handle->gdi.clip != NULL) {
if(handle->gdi.clip) {
DeleteObject(handle->gdi.clip);
handle->gdi.clip = NULL;
handle->gdi.clip = 0;
}
} else {
HRGN clip = CreateRectRgn(rect->x, rect->y, rect->x + rect->width, rect->y + rect->height);
SelectClipRgn(handle->gdi.hDC, clip);
if(handle->gdi.clip != NULL) DeleteObject(handle->gdi.clip);
if(handle->gdi.clip != 0) DeleteObject(handle->gdi.clip);
handle->gdi.clip = clip;
}
}
static int MwLLGDICallInitImpl(void) {
#ifndef __WINDOWS__
void* ntdll;
memset(&wsymtbl, 0, sizeof(wsymtbl));
wsymtbl.lib_dwmapi = MwDynamicOpen("dwmapi.dll");
@ -919,6 +1011,7 @@ static int MwLLGDICallInitImpl(void) {
} else {
is_plgblt_reliable = 1;
}
#endif
/* TODO: check properly */
return 0;

File diff suppressed because it is too large Load diff

View file

@ -881,11 +881,17 @@ void MwVaListApply(MwWidget handle, va_list va) {
}
void MwSetDefault(MwWidget handle) {
#ifndef __WINDOWS__
if(handle->lowlevel != NULL) MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
#endif
}
void MwHideCursor(MwWidget handle) {
#ifndef __WINDOWS__
MwLLSetCursor(handle->lowlevel, &MwCursorHidden, &MwCursorHiddenMask);
#else
MwLLSetCursor(handle->lowlevel, NULL, NULL);
#endif
}
void MwDispatchUserHandler(MwWidget handle, const char* key, void* handler_data) {
@ -934,10 +940,14 @@ void MwDispatchError(int code, const char* message) {
if(error_handler != NULL) {
error_handler(code, message, error_user_data);
} else {
#ifdef _WIN32
#if defined(_WIN32) || defined(__WINDOWS__)
char buffer[1024];
MwStringPrintIntoBuffer(buffer, 1024, "Error: %s\r\nCode : %d\r\n\r\nMilsko is exiting.", message, code);
#if defined(__WINDOWS__)
MessageBox(NULL, buffer, "Error", MB_ICONHAND | MB_OK);
#else
MessageBox(NULL, buffer, "Error", MB_ICONERROR | MB_OK);
#endif
#else
fprintf(stderr, "Error: %s\nCode : %d\n\nMilsko is exiting.", message, code);
#endif
@ -1019,7 +1029,9 @@ int MwLibraryInit(void) {
MwColorTableInit();
#ifndef __WINDOWS__
MwFLSetup();
#endif
for(i = 0; calls[i] != NULL; i++) {
if(calls[i]() == 0) return 0;

View file

@ -1,5 +1,7 @@
#include <Mw/Milsko.h>
#ifndef __WINDOWS__
#define WIN_SIZE 464
#define PICKER_SIZE 364
#define IMG_POS_X(w) ((w - PICKER_SIZE) / 2)
@ -378,3 +380,5 @@ MwWidget MwColorPicker(MwWidget handle, const char* title) {
return window;
}
#endif

View file

@ -1,5 +1,7 @@
#include <Mw/Milsko.h>
#ifndef __WINDOWS__
#include "../external/stb_ds.h"
typedef struct filechooser {
@ -505,8 +507,9 @@ static void scan(MwWidget handle, const char* path, int record) {
}
static void setup_fallback_filechooser(MwWidget window, int dir) {
char* path;
MwLLPixmap icon;
char* path;
MwLLPixmap icon;
filechooser_t* fc = malloc(sizeof(*fc));
memset(fc, 0, sizeof(*fc));
@ -568,6 +571,32 @@ MwWidget MwFileChooserEx(MwWidget handle, const char* title, int dir) {
return window;
}
#else
MwWidget MwFileChooserEx(MwWidget handle, const char* title, int dir) {
MwWidget window;
int w, h;
int wx;
int wy;
w = 700;
h = w * 2 / 3;
if(handle == NULL) {
wx = wy = MwDEFAULT;
} else {
wx = MwGetInteger(handle, MwNx) + (MwGetInteger(handle, MwNwidth) - w) / 2;
wy = MwGetInteger(handle, MwNy) + (MwGetInteger(handle, MwNheight) - h) / 2;
}
window = MwVaCreateWidget(MwWindowClass, "filechooser", NULL, wx, wy, w, h,
MwNtitle, title,
NULL);
if(handle != NULL) MwReparent(window, handle);
return window;
}
#endif
MwWidget MwFileChooser(MwWidget handle, const char* title) {
return MwFileChooserEx(handle, title, 0);
}

View file

@ -68,9 +68,11 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi
if(flag & MwMB_BUTTONYES) spawn_button(window, w - (x += 8 + 80), h - 8 - 24, MwMB_BUTTONYES, "Yes");
if((flag & MwMB_ICONMASK) != 0) {
MwWidget icon;
MwLLPixmap px;
unsigned int* data = NULL;
MwWidget icon;
MwLLPixmap px;
MwU32* data = NULL;
#ifndef __WINDOWS__
icon = MwCreateWidget(MwImageClass, "image", window, 8, (h - 48) / 2, 48, 48);
@ -110,6 +112,7 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi
px = MwLoadIcon(icon, data);
MwSetVoid(icon, MwNpixmap, px);
#endif
left = 8 + 48 + 8;
}

View file

@ -115,6 +115,7 @@ void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) {
MwLLPolygon(handle->lowlevel, p, 4, color);
}
#ifndef __WINDOWS__
void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
MwLLPixmap pixmap;
int y;
@ -153,6 +154,7 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
free(data);
}
#endif
void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
MwDrawFrameWithBorder(handle, rect, color, invert, MwDefaultBorderWidth(handle));
@ -220,12 +222,17 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert
col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
color_set_disabled_if_disabled(handle, col);
#ifndef __WINDOWS__
if(MwGetInteger(handle, MwNmodernLook)) {
MwDrawRectFading(handle, rect, col);
} else {
} else
#else
{
MwDrawRect(handle, rect, col);
}
if(col != color) MwLLFreeColor(col);
#endif
if(col != color)
MwLLFreeColor(col);
}
void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
@ -352,6 +359,7 @@ static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color,
rect->height -= border * 2;
}
#ifndef __WINDOWS__
static void frame_border_complex(MwWidget handle, MwRect* rect, MwLLColor lighter, MwLLColor darker, int invert, int border, int diff, int same) {
MwPoint p[7];
@ -423,13 +431,17 @@ static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color
rect->width -= border * 2;
rect->height -= border * 2;
}
#endif
void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) {
border = translate_border(handle, border);
#ifndef __WINDOWS__
if(MwGetInteger(handle, MwNmodernLook)) {
MwDrawFrameEx_complex(handle, rect, color, invert, border, diff, same);
} else {
} else
#endif
{
MwDrawFrameEx_simple(handle, rect, color, invert, border, diff, same);
}
}
@ -894,6 +906,7 @@ typedef struct color {
int a;
} color_t;
#ifndef __WINDOWS__
MwLLPixmap MwLoadXPM(MwWidget handle, char** data) {
int col, row, colors, cpp;
unsigned char* rgb;
@ -966,3 +979,4 @@ MwLLPixmap MwLoadXPM(MwWidget handle, char** data) {
return px;
}
#endif

View file

@ -1,12 +1,14 @@
#include <Mw/Milsko.h>
#ifndef __WINDOWS
int (*MwFLDrawText)(MwWidget handle, MwFLFont font, MwPoint* point, const char* text, MwLLColor color) = NULL;
int (*MwFLTextWidth)(MwFLFont font, const char* text) = NULL;
int (*MwFLTextHeight)(MwFLFont font, int count) = NULL;
void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px) = NULL;
void (*MwFLFontFree)(void* handle) = NULL;
#endif
#if defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE)
#if (defined(USE_FREETYPE2) || defined(USE_STB_TRUETYPE)) && !defined(__WINDOWS__)
#define TTF
#endif
@ -292,6 +294,7 @@ static void bitmap_MwDrawText(MwWidget handle, MwPoint* point, const char* text,
free(px);
}
#ifndef __INWDOWS__
typedef int (*call_t)(void);
void MwFLSetup(void) {
call_t calls[] = {
@ -308,3 +311,4 @@ void MwFLSetup(void) {
if(calls[i]() == 0) return;
}
}
#endif

View file

@ -102,7 +102,9 @@ static void click(MwWidget handle) {
if(ent > arrlen(cb->list)) ent = arrlen(cb->list);
#ifndef __WINDOWS__
MwLLSetCursor(handle->lowlevel, &MwCursorArrow, &MwCursorArrowMask);
#endif
for(i = 0; i < arrlen(cb->list); i++) {
int l = MwTextWidth(handle, NULL, cb->list[i]) + MwDefaultBorderWidth(handle) * 2;
@ -113,7 +115,9 @@ static void click(MwWidget handle) {
MwNsingleClickSelectable, 1,
NULL);
#ifndef __WINDOWS__
MwLLSetCursor(((MwListBox)cb->listbox->internal)->frame->lowlevel, &MwCursorArrow, &MwCursorArrowMask);
#endif
for(i = 0; i < arrlen(cb->list); i++) {
MwListBoxSet(cb->listbox, -1, 0, cb->list[i]);
@ -128,7 +132,9 @@ static void click(MwWidget handle) {
MwLLMakeToolWindow(cb->listbox->lowlevel);
MwLLEndStateChange(cb->listbox->lowlevel);
} else {
#ifndef __WINDOWS__
MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
#endif
if(cb->listbox != NULL) {
MwDestroyWidget(cb->listbox);

View file

@ -10,7 +10,9 @@ static int wcreate(MwWidget handle) {
MwSetDefault(handle);
#ifndef __WINDOWS__
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
#endif
return 0;
}

View file

@ -4,6 +4,11 @@
#define Spacing 1
/* 16 bit windows */
#ifdef __WINDOWS__
#define HAVE_SEVEN_SEGMENT 0
#endif
static int wcreate(MwWidget handle) {
MwLabel lab = malloc(sizeof(*lab));
memset(lab, 0, sizeof(*lab));
@ -122,6 +127,7 @@ static void draw_h(MwWidget handle, unsigned char* raw, int x, int y, int stride
}
}
#ifndef HAVE_SEVEN_SEGMENT
static void draw_seven_segment(MwWidget handle) {
MwRect r;
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
@ -311,6 +317,7 @@ static void draw_seven_segment(MwWidget handle) {
MwLLDestroyPixmap(px);
}
#endif
static void draw_normal(MwWidget handle) {
MwRect r;
@ -377,9 +384,11 @@ static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNsevenSegment) == 0) {
MwLabel lab = handle->internal;
#ifndef HAVE_SEVEN_SEGMENT
if(MwGetInteger(handle, MwNsevenSegment))
lab->draw = draw_seven_segment;
else
#endif
lab->draw = draw_normal;
}
}

View file

@ -85,11 +85,13 @@ static void key(MwWidget handle, int code) {
static void mouse_move(MwWidget handle) {
MwEntry e = handle->internal;
int w = MwGetInteger(handle, MwNwidth);
#ifndef __WINDOWS__
if(handle->mouse_point.x >= (w - e->right)) {
MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
} else {
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
}
#endif
}
static void mouse_up(MwWidget handle, void* ptr) {