From e05c94dbd560a0fab4bad2eb16f46aecb1fe8bb2 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 28 Jul 2026 20:58:55 +0200 Subject: [PATCH] add imageviewer to file notes --- application/note/src/file.rs | 52 ++++++++++++ application/note/src/window.rs | 16 +++- ui-rs/src/ui/image.rs | 37 +++++++-- ui/common/args.c | 147 +++++++++++++++++++++++++++++++++ ui/common/args.h | 36 ++++++++ ui/gtk/image.c | 8 +- ui/qt/toolkit.cpp | 7 +- ui/qt/window.cpp | 2 +- ui/ui/image.h | 10 ++- ui/ui/toolkit.h | 4 +- ui/win32/container.c | 14 ++-- ui/win32/container.h | 6 +- ui/win32/menu.c | 13 ++- ui/win32/menu.h | 3 +- ui/win32/text.c | 2 +- ui/win32/text.h | 2 +- ui/win32/window.c | 2 +- 17 files changed, 322 insertions(+), 39 deletions(-) diff --git a/application/note/src/file.rs b/application/note/src/file.rs index ef3ec55..077620c 100644 --- a/application/note/src/file.rs +++ b/application/note/src/file.rs @@ -25,6 +25,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +use std::ffi::{OsStr}; use std::mem; use std::path::{Path, PathBuf}; use std::rc::Rc; @@ -52,8 +53,14 @@ pub struct FileNote { #[bind("note_type")] pub note_type: UiInteger, + #[bind("filenote_preview_tab")] + pub preview_tab: UiInteger, + #[bind("note_nodename")] pub note_nodename: UiString, + + #[bind("filenote_image")] + pub image: UiImage, } #[ui_actions] @@ -72,7 +79,9 @@ impl FileNote { is_opening: false, note_type: Default::default(), + preview_tab: Default::default(), note_nodename: Default::default(), + image: Default::default(), } } @@ -83,10 +92,53 @@ impl FileNote { n.note_type.set(NoteTypeTabView::File as i64); n.note_nodename.set(model.nodename.as_str()); + + n.query_local_path(); }); doc_cast!(doc, dyn NoteViewModel) } + fn query_local_path(&mut self) { + let Some(doc) = self.doc.get_doc() else { + return; + }; + if self.is_opening { + return; + } + + if let NoteId::Id(note_id) = self.id { + self.is_opening = true; + let proxy = doc.doc_proxy(); + self.backend.open_extern(note_id, |result|{ + proxy.call_mainthread(move |_doc, note|{ + note.is_opening = false; + match result { + OpenExternResult::Ok((path, istmp)) => { + // TODO: implement better file type detection + // idealy save content type in the note + match path.extension().and_then(OsStr::to_str) { + Some("png") => { + let result = note.image.load_image_file(path.as_path()); + if result.is_ok() { + // TODO: replace 1 with enum value + note.preview_tab.set(1); + } + }, + _ => {} + } + + note.local_path = Some(path); + note.is_tmp_file = istmp; + } + _ => { + println!("open_extern failed"); + } + } + }); + }); + } + } + #[action] pub fn open_extern(&mut self, _event: &ActionEvent) { if self.is_opening { diff --git a/application/note/src/window.rs b/application/note/src/window.rs index db2bf66..95b6513 100644 --- a/application/note/src/window.rs +++ b/application/note/src/window.rs @@ -28,7 +28,7 @@ use std::any::Any; use backend::backend::{BackendHandle, BroadcastMessage, NoteId}; -use ui_rs::{action, button, grid, hbox, label, sourcelist, tableview, tabview, textarea, textfield, ui_actions, UiModel}; +use ui_rs::{action, button, grid, hbox, imageviewer, label, sourcelist, tableview, tabview, textarea, textfield, ui_actions, UiModel}; use ui_rs::ui::*; use crate::{App, AppStates}; use entity::collection::{Model as Collection, Node}; @@ -262,6 +262,20 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject Result { - use std::os::unix::ffi::OsStrExt; - CString::new(path.as_os_str().as_bytes()) -} -#[cfg(windows)] -fn path_to_cstring(path: &Path) -> Result { - CString::new(path.to_string_lossy().as_bytes()) +#[macro_export] +macro_rules! imageviewer { + ($parent:expr, $($tt:tt)*) => { + $crate::widget!($parent, imageviewer, $($tt)*) + }; } + impl UiImage { pub fn init(&mut self, ctx: &UiContext, name: Option<&str>) { let c_string = name.map(|n| CString::new(n).unwrap()); @@ -309,6 +307,27 @@ impl<'a, T> ImageViewerBuilder<'a, T> { } } +impl toolkit::UiObject { + pub fn imageviewer<'a>(&'a mut self) -> ImageViewerBuilder<'a, T> { + unsafe { + let args = ui_imageviewer_args_new(); + ImageViewerBuilder { args: args, obj: self } + } + } +} + + +#[cfg(unix)] +fn path_to_cstring(path: &Path) -> Result { + use std::os::unix::ffi::OsStrExt; + CString::new(path.as_os_str().as_bytes()) +} + +#[cfg(windows)] +fn path_to_cstring(path: &Path) -> Result { + CString::new(path.to_string_lossy().as_bytes()) +} + /* -------------------------------- C functions -------------------------------- */ unsafe extern "C" { diff --git a/ui/common/args.c b/ui/common/args.c index b9bb8f0..4c950ff 100644 --- a/ui/common/args.c +++ b/ui/common/args.c @@ -2775,6 +2775,153 @@ void ui_spinbox_args_free(UiSpinBoxArgs *args) { } +/* ------------------------- UiImageViewerArgs ----------------------------*/ + +UiImageViewerArgs* ui_imageviewer_args_new(void) { + UiImageViewerArgs *args = malloc(sizeof(UiImageViewerArgs)); + memset(args, 0, sizeof(UiImageViewerArgs)); + return args; +} + +void ui_imageviewer_args_set_fill(UiImageViewerArgs *args, UiBool fill) { + args->fill = fill; +} + +void ui_imageviewer_args_set_hexpand(UiImageViewerArgs *args, UiBool value) { + args->hexpand = value; +} + +void ui_imageviewer_args_set_vexpand(UiImageViewerArgs *args, UiBool value) { + args->vexpand = value; +} + +void ui_imageviewer_args_set_hfill(UiImageViewerArgs *args, UiBool value) { + args->hfill = value; +} + +void ui_imageviewer_args_set_vfill(UiImageViewerArgs *args, UiBool value) { + args->vfill = value; +} + +void ui_imageviewer_args_set_override_defaults(UiImageViewerArgs *args, UiBool value) { + args->override_defaults = value; +} + +void ui_imageviewer_args_set_margin(UiImageViewerArgs *args, int value) { + args->margin = value; +} + +void ui_imageviewer_args_set_margin_left(UiImageViewerArgs *args, int value) { + args->margin_left = value; +} + +void ui_imageviewer_args_set_margin_right(UiImageViewerArgs *args, int value) { + args->margin_right = value; +} + +void ui_imageviewer_args_set_margin_top(UiImageViewerArgs *args, int value) { + args->margin_top = value; +} + +void ui_imageviewer_args_set_margin_bottom(UiImageViewerArgs *args, int value) { + args->margin_bottom = value; +} + +void ui_imageviewer_args_set_colspan(UiImageViewerArgs *args, int colspan) { + args->colspan = colspan; +} + +void ui_imageviewer_args_set_rowspan(UiImageViewerArgs *args, int rowspan) { + args->rowspan = rowspan; +} + +void ui_imageviewer_args_set_name(UiImageViewerArgs *args, const char *name) { + args->name = strdup(name); +} + +void ui_imageviewer_args_set_style_class(UiImageViewerArgs *args, const char *classname) { + args->style_class = strdup(classname); +} + +void ui_imageviewer_args_set_varname(UiImageViewerArgs *args, const char *varname) { + args->varname = strdup(varname); +} + +void ui_imageviewer_args_set_value(UiImageViewerArgs *args, UiGeneric *value) { + args->value = value; +} + +void ui_imageviewer_args_set_visibility_states(UiImageViewerArgs *args, int *states, int numstates) { + args->visibility_states = calloc(numstates+1, sizeof(int)); + memcpy((void*)args->visibility_states, states, numstates * sizeof(int)); + ((int*)args->visibility_states)[numstates] = -1; +} + +void ui_imageviewer_args_set_scrollarea(UiImageViewerArgs *args, UiBool value) { + args->scrollarea = value; +} + +void ui_imageviewer_args_set_autoscale(UiImageViewerArgs *args, UiBool value) { + args->autoscale = value; +} + +void ui_imageviewer_args_set_adjustwidgetsize(UiImageViewerArgs *args, UiBool value) { + args->adjustwidgetsize = value; +} + +void ui_imageviewer_args_set_useradjustable(UiImageViewerArgs *args, UiBool value) { + args->useradjustable = value; +} + +void ui_imageviewer_args_set_image_padding(UiImageViewerArgs *args, int value) { + args->image_padding = value; +} + +void ui_imageviewer_args_set_image_padding_left(UiImageViewerArgs *args, int value) { + args->image_padding_left = value; +} + +void ui_imageviewer_args_set_image_padding_right(UiImageViewerArgs *args, int value) { + args->image_padding_right = value; +} + +void ui_imageviewer_args_set_image_padding_top(UiImageViewerArgs *args, int value) { + args->image_padding_top = value; +} + +void ui_imageviewer_args_set_image_padding_bottom(UiImageViewerArgs *args, int value) { + args->image_padding_bottom = value; +} + +void ui_imageviewer_args_set_contextmenu(UiImageViewerArgs *args, UiMenuBuilder *menubuilder) { + args->contextmenu = menubuilder; +} + +void ui_imageviewer_args_set_onbuttonpress(UiImageViewerArgs *args, ui_callback callback) { + args->onbuttonpress = callback; +} + +void ui_imageviewer_args_set_onbuttonpressdata(UiImageViewerArgs *args, void *onbuttonpressdata) { + args->onbuttonpressdata = onbuttonpressdata; +} + +void ui_imageviewer_args_set_onbuttonrelease(UiImageViewerArgs *args, ui_callback callback) { + args->onbuttonrelease = callback; +} + +void ui_imageviewer_args_set_onbuttonreleasedata(UiImageViewerArgs *args, void *onbuttonreleasedata) { + args->onbuttonreleasedata = onbuttonreleasedata; +} + +void ui_imageviewer_args_free(UiImageViewerArgs *args) { + free((void*)args->name); + free((void*)args->style_class); + free((void*)args->varname); + free((void*)args->visibility_states); + free(args); +} + + /* ------------------------- UiWebviewArgs ----------------------------*/ UiWebviewArgs* ui_webview_args_new(void) { diff --git a/ui/common/args.h b/ui/common/args.h index 7a8dbd7..b400f51 100644 --- a/ui/common/args.h +++ b/ui/common/args.h @@ -39,6 +39,7 @@ #include "../ui/list.h" #include "../ui/text.h" #include "../ui/webview.h" +#include "../ui/image.h" #include "../ui/widget.h" #ifdef __cplusplus @@ -639,6 +640,41 @@ UIEXPORT void ui_spinbox_args_set_states(UiSpinBoxArgs *args, int *states, int n UIEXPORT void ui_spinbox_args_set_visibility_states(UiSpinBoxArgs *args, int *states, int numstates); UIEXPORT void ui_spinbox_args_free(UiSpinBoxArgs *args); +UIEXPORT UiImageViewerArgs* ui_imageviewer_args_new(void); +UIEXPORT void ui_imageviewer_args_set_fill(UiImageViewerArgs *args, UiBool fill); +UIEXPORT void ui_imageviewer_args_set_hexpand(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_vexpand(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_hfill(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_vfill(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_override_defaults(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_margin(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_margin_left(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_margin_right(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_margin_top(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_margin_bottom(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_colspan(UiImageViewerArgs *args, int colspan); +UIEXPORT void ui_imageviewer_args_set_rowspan(UiImageViewerArgs *args, int rowspan); +UIEXPORT void ui_imageviewer_args_set_name(UiImageViewerArgs *args, const char *name); +UIEXPORT void ui_imageviewer_args_set_style_class(UiImageViewerArgs *args, const char *classname); +UIEXPORT void ui_imageviewer_args_set_varname(UiImageViewerArgs *args, const char *varname); +UIEXPORT void ui_imageviewer_args_set_value(UiImageViewerArgs *args, UiGeneric *value); +UIEXPORT void ui_imageviewer_args_set_visibility_states(UiImageViewerArgs *args, int *states, int numstates); +UIEXPORT void ui_imageviewer_args_set_scrollarea(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_autoscale(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_adjustwidgetsize(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_useradjustable(UiImageViewerArgs *args, UiBool value); +UIEXPORT void ui_imageviewer_args_set_image_padding(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_image_padding_left(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_image_padding_right(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_image_padding_top(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_image_padding_bottom(UiImageViewerArgs *args, int value); +UIEXPORT void ui_imageviewer_args_set_contextmenu(UiImageViewerArgs *args, UiMenuBuilder *menubuilder); +UIEXPORT void ui_imageviewer_args_set_onbuttonpress(UiImageViewerArgs *args, ui_callback callback); +UIEXPORT void ui_imageviewer_args_set_onbuttonpressdata(UiImageViewerArgs *args, void *onbuttonpressdata); +UIEXPORT void ui_imageviewer_args_set_onbuttonrelease(UiImageViewerArgs *args, ui_callback callback); +UIEXPORT void ui_imageviewer_args_set_onbuttonreleasedata(UiImageViewerArgs *args, void *onbuttonreleasedata); +UIEXPORT void ui_imageviewer_args_free(UiImageViewerArgs *args); + UIEXPORT UiWebviewArgs* ui_webview_args_new(void); UIEXPORT void ui_webview_args_set_fill(UiWebviewArgs *args, UiBool fill); UIEXPORT void ui_webview_args_set_hexpand(UiWebviewArgs *args, UiBool value); diff --git a/ui/gtk/image.c b/ui/gtk/image.c index 8181126..b323cd0 100644 --- a/ui/gtk/image.c +++ b/ui/gtk/image.c @@ -209,7 +209,7 @@ static void imageviewer_reset(UiImageViewer *imgviewer) { imgviewer->user_scale = 1; } -UIWIDGET ui_imageviewer_reset(UIWIDGET w) { +void ui_imageviewer_reset(UIWIDGET w) { UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer"); if(imgviewer) { imageviewer_reset(imgviewer); @@ -217,21 +217,21 @@ UIWIDGET ui_imageviewer_reset(UIWIDGET w) { } } -UIWIDGET ui_imageviewer_set_autoscale(UIWIDGET w, UiBool set) { +void ui_imageviewer_set_autoscale(UIWIDGET w, UiBool set) { UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer"); if(imgviewer) { imgviewer->autoscale = set; } } -UIWIDGET ui_imageviewer_set_adjustwidgetsize(UIWIDGET w, UiBool set) { +void ui_imageviewer_set_adjustwidgetsize(UIWIDGET w, UiBool set) { UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer"); if(imgviewer) { imgviewer->adjustwidgetsize = set; } } -UIWIDGET ui_imageviewer_set_useradjustable(UIWIDGET w, UiBool set) { +void ui_imageviewer_set_useradjustable(UIWIDGET w, UiBool set) { UiImageViewer *imgviewer = g_object_get_data(G_OBJECT(w), "uiimageviewer"); if(imgviewer) { imgviewer->useradjustable = set; diff --git a/ui/qt/toolkit.cpp b/ui/qt/toolkit.cpp index 548cfdd..9bec60d 100644 --- a/ui/qt/toolkit.cpp +++ b/ui/qt/toolkit.cpp @@ -131,7 +131,7 @@ void UiEventWrapper::slot() { e.window = obj->window; e.document = obj->ctx->document; e.eventdata = NULL; - e.eventdatatype = 0; + e.eventdatatype = UI_EVENT_DATA_NULL; e.intval = 0; e.set = ui_get_setop(); if(prepare_event) { @@ -169,7 +169,7 @@ void UiQAction::trigger() { e.window = obj->window; e.document = obj->ctx->document; e.eventdata = NULL; - e.eventdatatype = 0; + e.eventdatatype = UI_EVENT_DATA_NULL; e.intval = 0; e.set = ui_get_setop(); if(prepare_event) { @@ -185,3 +185,6 @@ void ui_action_enable(UiQAction *action, int enable) { action->setEnabled((bool)enable); } +void ui_call_mainthread(ui_threadfunc tf, void* td) { + // TODO +} diff --git a/ui/qt/window.cpp b/ui/qt/window.cpp index 1c69606..07d9d83 100644 --- a/ui/qt/window.cpp +++ b/ui/qt/window.cpp @@ -113,7 +113,7 @@ void ui_dialog_create(UiObject *parent, UiDialogArgs *args) { evt.document = evt.obj->ctx->document; evt.window = evt.obj->window; evt.eventdata = NULL; - evt.eventdatatype = 0; + evt.eventdatatype = UI_EVENT_DATA_NULL; evt.intval = 0; if(msgBox.clickedButton() == btn1) { evt.intval = 1; diff --git a/ui/ui/image.h b/ui/ui/image.h index 0730f75..f3498fa 100644 --- a/ui/ui/image.h +++ b/ui/ui/image.h @@ -80,16 +80,18 @@ typedef struct UiImageViewerArgs { void *onbuttonpressdata; ui_callback onbuttonrelease; void *onbuttonreleasedata; + + const int *visibility_states; } UiImageViewerArgs; #define ui_imageviewer(obj, ...) ui_imageviewer_create(obj, &(UiImageViewerArgs){ __VA_ARGS__ } ) UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs *args); -UIEXPORT UIWIDGET ui_imageviewer_reset(UIWIDGET w); -UIEXPORT UIWIDGET ui_imageviewer_set_autoscale(UIWIDGET w, UiBool set); -UIEXPORT UIWIDGET ui_imageviewer_set_adjustwidgetsize(UIWIDGET w, UiBool set); -UIEXPORT UIWIDGET ui_imageviewer_set_useradjustable(UIWIDGET w, UiBool set); +UIEXPORT void ui_imageviewer_reset(UIWIDGET w); +UIEXPORT void ui_imageviewer_set_autoscale(UIWIDGET w, UiBool set); +UIEXPORT void ui_imageviewer_set_adjustwidgetsize(UIWIDGET w, UiBool set); +UIEXPORT void ui_imageviewer_set_useradjustable(UIWIDGET w, UiBool set); UIEXPORT int ui_image_load_file(UiGeneric *obj, const char *path); UIEXPORT int ui_image_load_data(UiGeneric *obj, const void *imgdata, size_t size); diff --git a/ui/ui/toolkit.h b/ui/ui/toolkit.h index e56a3c5..402d7a9 100644 --- a/ui/ui/toolkit.h +++ b/ui/ui/toolkit.h @@ -91,6 +91,7 @@ typedef void* UIMENU; // NSMenu* #elif UI_WIN32 #include "win32.h" +typedef SSIZE_T ssize_t; #define UIWIDGET W32Widget* #define UIWINDOW void* @@ -213,8 +214,6 @@ typedef struct UiListSelection UiListSelection; typedef struct UiTextStyle UiTextStyle; typedef struct UiColor UiColor; -typedef enum UiEventType UiEventType; - /* begin opaque types */ typedef struct UiContext UiContext; typedef struct UiContainer UiContainer; @@ -336,6 +335,7 @@ enum UiEventType { UI_EVENT_DATA_FILE_LIST, UI_EVENT_DATA_TYPED_OBJECT }; +typedef enum UiEventType UiEventType; struct UiEvent { UiObject *obj; diff --git a/ui/win32/container.c b/ui/win32/container.c index 889ad5f..0d49b79 100644 --- a/ui/win32/container.c +++ b/ui/win32/container.c @@ -99,14 +99,14 @@ UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs *args) { return box_create(obj, args, UI_BOX_HORIZONTAL); } -UiContainerX* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding) { +UiContainer* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding) { UiBoxContainer *container = cxZalloc(obj->ctx->allocator, sizeof(UiBoxContainer)); container->container.hwnd = hwnd; container->container.add = ui_box_container_add; container->layout = ui_grid_layout_create(obj->ctx->allocator, spacing, spacing); container->layout->padding = padding; container->orientation = orientation; - return (UiContainerX*)container; + return (UiContainer*)container; } void ui_box_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layout) { @@ -156,7 +156,7 @@ UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { UiGridWidget *widget = w32_widget_create(&grid_layout_widget_class, hwnd, sizeof(UiGridWidget)); ui_container_add(container, (W32Widget*)widget, &layout); - UiContainerX *gridContainer = ui_grid_container_create(obj, hwnd, args->columnspacing, args->rowspacing, INSETS_ZERO); + UiContainer *gridContainer = ui_grid_container_create(obj, hwnd, args->columnspacing, args->rowspacing, INSETS_ZERO); uic_object_push_container(obj, gridContainer); UiGridLayoutContainer *grid = (UiGridLayoutContainer*)gridContainer; @@ -169,13 +169,13 @@ UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { return (W32Widget*)widget; } -UiContainerX* ui_grid_container_create(UiObject *obj, HWND hwnd, short columnspacing, short rowspacing, GridEdgeInsets padding) { +UiContainer* ui_grid_container_create(UiObject *obj, HWND hwnd, short columnspacing, short rowspacing, GridEdgeInsets padding) { UiGridLayoutContainer *container = cxZalloc(obj->ctx->allocator, sizeof(UiGridLayoutContainer)); container->container.hwnd = hwnd; container->container.add = ui_grid_container_add; container->layout = ui_grid_layout_create(obj->ctx->allocator, columnspacing, rowspacing); container->layout->padding = padding; - return (UiContainerX*)container; + return (UiContainer*)container; } void ui_grid_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layout) { @@ -204,12 +204,12 @@ void ui_grid_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout /* ---------------------------- Container Helper ---------------------------- */ void ui_container_begin_close(UiObject *obj) { - UiContainerX *ct = obj->container_end; + UiContainer *ct = obj->container_end; ct->close = 1; } int ui_container_finish(UiObject *obj) { - UiContainerX *ct = obj->container_end; + UiContainer *ct = obj->container_end; if(ct->close) { ui_end_new(obj); return 0; diff --git a/ui/win32/container.h b/ui/win32/container.h index 2d0ca9d..8314644 100644 --- a/ui/win32/container.h +++ b/ui/win32/container.h @@ -63,7 +63,7 @@ typedef struct UiRect { struct UiContainerPrivate { - UiContainerX container; + UiContainer container; HWND (*parent)(UiContainerPrivate*); void (*add)(UiContainerPrivate*, W32Widget*, UiLayout*); UiContainerType type; @@ -101,10 +101,10 @@ void ui_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layo int ui_grid_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); W32Size ui_grid_layout_get_preferred_size(W32Widget *widget); -UiContainerX* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding); +UiContainer* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding); void ui_box_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layout); -UiContainerX* ui_grid_container_create( +UiContainer* ui_grid_container_create( UiObject *obj, HWND hwnd, short columnspacing, diff --git a/ui/win32/menu.c b/ui/win32/menu.c index 16171de..1fde17a 100644 --- a/ui/win32/menu.c +++ b/ui/win32/menu.c @@ -289,6 +289,7 @@ void ui_add_menu_list(HMENU parent, int pos, UiMenuItemI *item, UiObject *obj) { ls->command_ids = cxArrayListCreate(a, sizeof(uint64_t), 16); ls->index = pos; ls->getvalue = il->getvalue; + ls->getvaluedata = NULL; // TODO ls->callback = il->callback; ls->userdata = il->userdata; ls->addseparator = il->addseparator; @@ -339,12 +340,15 @@ void ui_update_menuitem_list(UiActiveMenuItemList *list) { } cxListClear(list->command_ids); // TODO: we could reuse some of the ids - ui_getvaluefunc getvalue = list->getvalue; + ui_getvaluefunc2 getvalue = list->getvalue; + void *getvaluedata = list->getvaluedata; void* elm = ui_list_first(ls); int pos = list->index; + int row = 0; while(elm) { - char *label = (char*) (getvalue ? getvalue(elm, 0) : elm); + UiBool freeResult = FALSE; + char *label = (char*) (getvalue ? getvalue(ls, elm, row, 0, getvaluedata, &freeResult) : elm); if (!label) { label = ""; } @@ -353,7 +357,12 @@ void ui_update_menuitem_list(UiActiveMenuItemList *list) { InsertMenu(list->menu, pos++, MF_STRING, id, label); cxListAdd(list->command_ids, &id); + if (freeResult) { + free(label); + } + elm = ui_list_next(ls); + row++; } } diff --git a/ui/win32/menu.h b/ui/win32/menu.h index efb5d48..d7874f6 100644 --- a/ui/win32/menu.h +++ b/ui/win32/menu.h @@ -55,7 +55,8 @@ struct UiActiveMenuItemList { CxList *command_ids; int index; UiVar *var; - ui_getvaluefunc getvalue; + ui_getvaluefunc2 getvalue; + void *getvaluedata; ui_callback callback; void *userdata; bool addseparator; diff --git a/ui/win32/text.c b/ui/win32/text.c index cc5f400..87c6150 100644 --- a/ui/win32/text.c +++ b/ui/win32/text.c @@ -127,7 +127,7 @@ char* ui_textarea_getsubstr(UiText *text, int begin, int end) { return NULL; } -void ui_textarea_insert(UiText *text, int pos, char *str) { +void ui_textarea_insert(UiText *text, int pos, const char *str) { } diff --git a/ui/win32/text.h b/ui/win32/text.h index 7eed5db..1bbf652 100644 --- a/ui/win32/text.h +++ b/ui/win32/text.h @@ -53,7 +53,7 @@ void ui_textarea_restore(UiText *text); void ui_textarea_set(UiText *text, const char *str); char* ui_textarea_get(UiText *text); char* ui_textarea_getsubstr(UiText *text, int begin, int end); -void ui_textarea_insert(UiText *text, int pos, char *str); +void ui_textarea_insert(UiText *text, int pos, const char *str); void ui_textarea_setposition(UiText *text, int pos); int ui_textarea_position(UiText *text); void ui_textarea_setselection(UiText *text, int begin, int end); diff --git a/ui/win32/window.c b/ui/win32/window.c index c0a51b0..0dcd6cc 100644 --- a/ui/win32/window.c +++ b/ui/win32/window.c @@ -105,7 +105,7 @@ static UiObject* create_window(const char *title, bool simple) { UpdateWindow(hwnd); - UiContainerX *container = ui_box_container_create(obj, hwnd, UI_BOX_VERTICAL, 0, INSETS_ZERO); + UiContainer *container = ui_box_container_create(obj, hwnd, UI_BOX_VERTICAL, 0, INSETS_ZERO); uic_object_push_container(obj, container); UiBoxContainer *box = (UiBoxContainer*)container; -- 2.52.0