--- a/ui/motif/toolkit.c Fri Nov 29 22:21:36 2024 +0100 +++ b/ui/motif/toolkit.c Thu Dec 12 20:01:43 2024 +0100 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 2014 Olaf Wintermann. All rights reserved. + * 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: @@ -33,15 +33,21 @@ #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 char *application_name; +static const char *application_name; static ui_callback startup_func; static void *startup_data; @@ -68,6 +74,11 @@ "*rt*fontType: FONT_IS_XFT", "*rt*fontName: Sans", "*rt*fontSize: 11", + + "*window_frame.shadowType: SHADOW_ETCHED_OUT", + "*window_frame.shadowThickness: 1", + "*togglebutton.shadowThickness: 1", + "*togglebutton.highlightThickness: 2", NULL }; @@ -76,8 +87,9 @@ read(event_pipe[0], &ptr, sizeof(void*)); } -void ui_init(char *appname, int argc, char **argv) { +void ui_init(const char *appname, int argc, char **argv) { application_name = appname; + uic_init_global_context(); XtToolkitInitialize(); XtSetLanguageProc(NULL, NULL, NULL); @@ -85,15 +97,10 @@ XtAppSetFallbackResources(app, fallback); display = XtOpenDisplay(app, NULL, appname, appname, NULL, 0, &argc, argv); - char **missing = NULL; - int nm = 0; - char *def = NULL; - XCreateFontSet(display, "-dt-interface system-medium-r-normal-s*utf*", &missing, &nm, &def); uic_docmgr_init(); - ui_toolbar_init(); - ui_stock_init(); - + uic_menu_init(); + uic_toolbar_init(); uic_load_app_properties(); if(pipe(event_pipe)) { @@ -108,11 +115,11 @@ NULL); } -char* ui_appname() { +const char* ui_appname() { return application_name; } -Display* ui_get_display() { +Display* ui_motif_get_display() { return display; } @@ -157,11 +164,12 @@ void ui_show(UiObject *obj) { uic_check_group_widgets(obj->ctx); XtRealizeWidget(obj->widget); - ui_window_dark_theme(XtDisplay(obj->widget), XtWindow(obj->widget)); // TODO: if } -// implemented in window.c -//void ui_close(UiObject *obj) +void ui_close(UiObject *obj) { + +} + void ui_set_enabled(UIWIDGET widget, int enabled) { XtSetSensitive(widget, enabled); @@ -182,17 +190,16 @@ } static Boolean ui_job_finished(void *data) { - printf("WorkProc\n"); UiJob *job = data; - - 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); + 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; } @@ -201,7 +208,6 @@ UiJob *job = data; int result = job->job_func(job->job_data); if(!result) { - printf("XtAppAddWorkProc\n"); write(event_pipe[1], &job, sizeof(void*)); // hack XtAppAddWorkProc(app, ui_job_finished, job); @@ -221,7 +227,6 @@ } void ui_clipboard_set(char *str) { - printf("copy: {%s}\n", str); int length = strlen(str) + 1; Display *dp = XtDisplayOfObject(active_window); @@ -287,6 +292,9 @@ 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); @@ -300,3 +308,23 @@ (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); + } +} +