4 days ago
prepare buildsystem for win32
.hgignore | file | annotate | diff | comparison | revisions | |
application/Makefile | file | annotate | diff | comparison | revisions | |
application/main.c | file | annotate | diff | comparison | revisions | |
ui/Makefile | file | annotate | diff | comparison | revisions | |
ui/common/condvar.c | file | annotate | diff | comparison | revisions | |
ui/common/objs.mk | file | annotate | diff | comparison | revisions | |
ui/common/threadpool.c | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/ui/widget.h | file | annotate | diff | comparison | revisions | |
ui/win32/Makefile | file | annotate | diff | comparison | revisions | |
ui/win32/objs.mk | file | annotate | diff | comparison | revisions | |
ui/win32/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/win32/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/.hgignore Mon Mar 24 20:37:16 2025 +0100 +++ b/.hgignore Tue Mar 25 13:31:30 2025 +0100 @@ -6,4 +6,5 @@ relre:^make/vs/.*vcxproj\.user relre:^make/xcode/toolkit/toolkit.xcodeproj/xcuserdata/.* relre:^make/xcode/toolkit/toolkit.xcodeproj/project.xcworkspace/xcuserdata/.* -relre:^ui/winui/Generated Files/.* \ No newline at end of file +relre:^ui/winui/Generated Files/.* +relre:^.idea/.*
--- a/application/Makefile Mon Mar 24 20:37:16 2025 +0100 +++ b/application/Makefile Tue Mar 25 13:31:30 2025 +0100 @@ -37,7 +37,7 @@ all: ../build/bin/mk12 -../build/bin/mk12: $(OBJ) $(BUILD_ROOT)/build/lib/libuitk.a +../build/bin/mk12: $(OBJ) $(BUILD_ROOT)/build/lib/libuitk$(LIB_EXT) $(CC) -o ../build/bin/mk12$(APP_EXT) $(OBJ) -L$(BUILD_ROOT)/build/lib -luitk -lucx $(LDFLAGS) $(TK_LDFLAGS) ../build/application/%$(OBJ_EXT): %.c
--- a/application/main.c Mon Mar 24 20:37:16 2025 +0100 +++ b/application/main.c Tue Mar 25 13:31:30 2025 +0100 @@ -37,7 +37,7 @@ #include "cx/string.h" #include "cx/list.h" -#if !defined(UI_COCOA) && !defined(UI_MOTIF) +#if !defined(UI_COCOA) && !defined(UI_MOTIF) && !defined(UI_WIN32) typedef struct { UiString *str1; @@ -770,3 +770,11 @@ } #endif + +#ifdef UI_WIN32 + +int main(int argc, char **argv) { + return 0; +} + +#endif
--- a/ui/Makefile Mon Mar 24 20:37:16 2025 +0100 +++ b/ui/Makefile Tue Mar 25 13:31:30 2025 +0100 @@ -42,6 +42,6 @@ include $(TOOLKIT)/Makefile -$(COMMON_OBJPRE)%.o: common/%.c +$(COMMON_OBJPRE)%$(OBJ_EXT): common/%.c $(CC) -o $@ -c -I../ucx/ $(CFLAGS) $(TK_CFLAGS) $<
--- a/ui/common/condvar.c Mon Mar 24 20:37:16 2025 +0100 +++ b/ui/common/condvar.c Tue Mar 25 13:31:30 2025 +0100 @@ -26,6 +26,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _WIN32 + #include "condvar.h" #include <stdlib.h> @@ -68,3 +70,5 @@ free(p); } + +#endif \ No newline at end of file
--- a/ui/common/objs.mk Mon Mar 24 20:37:16 2025 +0100 +++ b/ui/common/objs.mk Tue Mar 25 13:31:30 2025 +0100 @@ -29,18 +29,18 @@ COMMON_SRC_DIR = ui/common/ COMMON_OBJPRE = $(OBJ_DIR)$(COMMON_SRC_DIR) -COMMON_OBJ = context.o -COMMON_OBJ += document.o -COMMON_OBJ += object.o -COMMON_OBJ += types.o -COMMON_OBJ += menu.o -COMMON_OBJ += properties.o -COMMON_OBJ += menu.o -COMMON_OBJ += toolbar.o -COMMON_OBJ += ucx_properties.o -COMMON_OBJ += threadpool.o -COMMON_OBJ += condvar.o +COMMON_OBJ = context$(OBJ_EXT) +COMMON_OBJ += document$(OBJ_EXT) +COMMON_OBJ += object$(OBJ_EXT) +COMMON_OBJ += types$(OBJ_EXT) +COMMON_OBJ += menu$(OBJ_EXT) +COMMON_OBJ += properties$(OBJ_EXT) +COMMON_OBJ += menu$(OBJ_EXT) +COMMON_OBJ += toolbar$(OBJ_EXT) +COMMON_OBJ += ucx_properties$(OBJ_EXT) +COMMON_OBJ += threadpool$(OBJ_EXT) +COMMON_OBJ += condvar$(OBJ_EXT) TOOLKITOBJS += $(COMMON_OBJ:%=$(COMMON_OBJPRE)%) -TOOLKITSOURCE += $(COMMON_OBJ:%.o=common/%.c) +TOOLKITSOURCE += $(COMMON_OBJ:%$(OBJ_EXT)=common/%.c)
--- a/ui/common/threadpool.c Mon Mar 24 20:37:16 2025 +0100 +++ b/ui/common/threadpool.c Tue Mar 25 13:31:30 2025 +0100 @@ -26,11 +26,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _WIN32 + #include "threadpool.h" #include "context.h" -#ifndef _WIN32 - #include <pthread.h> #include <stdio.h> #include <string.h>
--- a/ui/ui/toolkit.h Mon Mar 24 20:37:16 2025 +0100 +++ b/ui/ui/toolkit.h Tue Mar 25 13:31:30 2025 +0100 @@ -78,6 +78,17 @@ #define UIMENU void* #endif + +#elif UI_WIN32 + +#include <Windows.h> + +#define UIEXPORT __declspec(dllexport) + +#define UIWIDGET void* +#define UIWINDOW void* +#define UIMENU void* + #elif UI_WINUI #define UIEXPORT __declspec(dllexport)
--- a/ui/ui/widget.h Mon Mar 24 20:37:16 2025 +0100 +++ b/ui/ui/widget.h Tue Mar 25 13:31:30 2025 +0100 @@ -55,6 +55,8 @@ typedef UIWIDGET (*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata); #elif defined(UI_WINUI) typedef UIWIDGET(*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata); +#elif defined(UI_WIN32) +typedef UIWIDGET(*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata); #endif UIEXPORT UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/Makefile Tue Mar 25 13:31:30 2025 +0100 @@ -0,0 +1,33 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2012 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +$(WIN32_OBJPRE)%.obj: win32/%.c + $(CC) -o $@ -c -I../ucx $(CFLAGS) $(TK_CFLAGS) $< + +$(UI_LIB): $(OBJ) + $(AR) $(ARFLAGS) $(UI_LIB) $(OBJ)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/objs.mk Tue Mar 25 13:31:30 2025 +0100 @@ -0,0 +1,35 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2012 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +WIN32_SRC_DIR = ui/win32/ +WIN32_OBJPRE = $(OBJ_DIR)$(WIN32_SRC_DIR) + +WIN32OBJ = toolkit.obj + +TOOLKITOBJS += $(WIN32OBJ:%=$(WIN32_OBJPRE)%) +TOOLKITSOURCE += $(WIN32OBJ:%.obj=win32/%.c)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/toolkit.c Tue Mar 25 13:31:30 2025 +0100 @@ -0,0 +1,334 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2024 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <pthread.h> + +#include "toolkit.h" +#include "toolbar.h" +#include "container.h" +#include "stock.h" +#include "../common/menu.h" +#include "../common/toolbar.h" +#include "../common/document.h" +#include "../common/properties.h" +#include <cx/buffer.h> + +#include <X11/Intrinsic.h> +#include <Xm/CutPaste.h> + +static XtAppContext app; +static Display *display; +static Widget active_window; +static const char *application_name; + +static ui_callback startup_func; +static void *startup_data; +static ui_callback open_func; +void *open_data; +static ui_callback exit_func; +void *exit_data; + +static ui_callback appclose_fnc; +static void *appclose_udata; + +static int is_toplevel_realized = 0; + +int event_pipe[2]; + + +static String fallback[] = { + //"*fontList: -dt-interface system-medium-r-normal-s*utf*:", + "*renderTable: rt", + "*rt*fontType: FONT_IS_XFT", + "*rt*fontName: Sans", + "*rt*fontSize: 11", + + "*progresss_spinner*renderTable*fontType: FONT_IS_FONT", + "*progresss_spinner*renderTable*fontName: Cursor", + + "*window_frame.shadowType: SHADOW_ETCHED_OUT", + "*window_frame.shadowThickness: 1", + "*togglebutton.shadowThickness: 1", + "*togglebutton.highlightThickness: 2", + + "*ui_test.background: red", + NULL +}; + +void input_proc(XtPointer data, int *source, XtInputId *iid) { + void *ptr; + read(event_pipe[0], &ptr, sizeof(void*)); +} + +void ui_init(const char *appname, int argc, char **argv) { + application_name = appname; + uic_init_global_context(); + + XtToolkitInitialize(); + XtSetLanguageProc(NULL, NULL, NULL); + app = XtCreateApplicationContext(); + XtAppSetFallbackResources(app, fallback); + + display = XtOpenDisplay(app, NULL, appname, appname, NULL, 0, &argc, argv); + + uic_docmgr_init(); + uic_menu_init(); + uic_toolbar_init(); + uic_load_app_properties(); + + if(pipe(event_pipe)) { + fprintf(stderr, "UiError: Cannot create event pipe\n"); + exit(-1); + } + XtAppAddInput( + app, + event_pipe[0], + (XtPointer)XtInputReadMask, + input_proc, + NULL); +} + +const char* ui_appname() { + return application_name; +} + +Display* ui_motif_get_display() { + return display; +} + +void ui_onstartup(ui_callback f, void *userdata) { + startup_func = f; + startup_data = userdata; +} + +void ui_onopen(ui_callback f, void *userdata) { + open_func = f; + open_data = userdata; +} + +void ui_onexit(ui_callback f, void *userdata) { + exit_func = f; + exit_data = userdata; +} + +void ui_main() { + if(startup_func) { + startup_func(NULL, startup_data); + } + XtAppMainLoop(app); + if(exit_func) { + exit_func(NULL, exit_data); + } + uic_store_app_properties(); +} + +void ui_exit_mainloop() { + XtAppSetExitFlag(app); +} + +void ui_secondary_event_loop(int *loop) { + while(*loop && !XtAppGetExitFlag(app)) { + XEvent event; + XtAppNextEvent(app, &event); + XtDispatchEvent(&event); + } +} + +void ui_show(UiObject *obj) { + uic_check_group_widgets(obj->ctx); + if(!XtIsRealized(obj->widget)) { + XtRealizeWidget(obj->widget); + obj->ref++; + } +} + +void ui_close(UiObject *obj) { + +} + + +void ui_set_enabled(UIWIDGET widget, int enabled) { + XtSetSensitive(widget, enabled); +} + +void ui_set_show_all(UIWIDGET widget, int value) { + if(!value) { + XtUnmanageChild(widget); + } +} + +void ui_set_visible(UIWIDGET widget, int visible) { + if(visible) { + XtManageChild(widget); + } else { + XtUnmanageChild(widget); + } +} + +static Boolean ui_job_finished(void *data) { + UiJob *job = data; + if(job->finish_callback) { + UiEvent event; + event.obj = job->obj; + event.window = job->obj->window; + event.document = job->obj->ctx->document; + event.intval = 0; + event.eventdata = NULL; + job->finish_callback(&event, job->finish_data); + } + free(job); + return TRUE; +} + +static void* ui_jobthread(void *data) { + UiJob *job = data; + int result = job->job_func(job->job_data); + if(!result) { + write(event_pipe[1], &job, sizeof(void*)); // hack + XtAppAddWorkProc(app, ui_job_finished, job); + + } + return NULL; +} + +void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { + UiJob *job = malloc(sizeof(UiJob)); + job->obj = obj; + job->job_func = tf; + job->job_data = td; + job->finish_callback = f; + job->finish_data = fd; + pthread_t pid; + pthread_create(&pid, NULL, ui_jobthread, job); +} + +void ui_clipboard_set(char *str) { + int length = strlen(str) + 1; + + Display *dp = XtDisplayOfObject(active_window); + Window window = XtWindowOfObject(active_window); + + XmString label = XmStringCreateLocalized("toolkit_clipboard"); + long id = 0; + + while(XmClipboardStartCopy( + dp, + window, + label, + CurrentTime, + NULL, + NULL, + &id) == ClipboardLocked); + XmStringFree(label); + + while(XmClipboardCopy( + dp, + window, + id, + "STRING", + str, + length, + 1, + NULL) == ClipboardLocked); + + while(XmClipboardEndCopy(dp, window, id) == ClipboardLocked); +} + +char* ui_clipboard_get() { + Display *dp = XtDisplayOfObject(active_window); + Window window = XtWindowOfObject(active_window); + + long id; + size_t size = 128; + char *buf = malloc(size); + + int r; + for(;;) { + r = XmClipboardRetrieve(dp, window, "STRING", buf, size, NULL, &id); + if(r == ClipboardSuccess) { + break; + } else if(r == ClipboardTruncate) { + size *= 2; + buf = realloc(buf, size); + } else if(r == ClipboardNoData) { + free(buf); + buf = NULL; + break; + } + } + + return buf; +} + +void ui_set_active_window(Widget w) { + active_window = w; +} + +Widget ui_get_active_window() { + return active_window; +} + +/* + * doesn't work with gnome anymore + */ +void ui_window_dark_theme(Display *dp, Window window) { + Atom atom = XInternAtom(dp, "_GTK_THEME_VARIANT", False); + Atom type = XInternAtom(dp, "UTF8_STRING", False); + XChangeProperty( + dp, + window, + atom, + type, + 8, + PropModeReplace, + (const unsigned char*)"dark", + 4); +} + +void ui_destroy_eventdata(Widget w, XtPointer data, XtPointer d) { + free(data); +} + +void ui_set_widget_groups(UiContext *ctx, Widget widget, const int *groups) { + if(!groups) { + return; + } + size_t ngroups = uic_group_array_size(groups); + ui_set_widget_ngroups(ctx, widget, groups, ngroups); +} + +void ui_set_widget_ngroups(UiContext *ctx, Widget widget, const int *groups, size_t ngroups) { + if(ngroups > 0) { + uic_add_group_widget_i(ctx, widget, (ui_enablefunc)ui_set_enabled, groups, ngroups); + ui_set_enabled(widget, FALSE); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/win32/toolkit.h Tue Mar 25 13:31:30 2025 +0100 @@ -0,0 +1,48 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2024 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TOOLKIT_H +#define TOOLKIT_H + +#include <inttypes.h> +#include "../ui/toolkit.h" +#include "../common/context.h" +#include "../common/object.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif /* TOOLKIT_H */ +