]> uap-core.de Git - note.git/commitdiff
add imageviewer to file notes
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 28 Jul 2026 18:58:55 +0000 (20:58 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 28 Jul 2026 18:58:55 +0000 (20:58 +0200)
17 files changed:
application/note/src/file.rs
application/note/src/window.rs
ui-rs/src/ui/image.rs
ui/common/args.c
ui/common/args.h
ui/gtk/image.c
ui/qt/toolkit.cpp
ui/qt/window.cpp
ui/ui/image.h
ui/ui/toolkit.h
ui/win32/container.c
ui/win32/container.h
ui/win32/menu.c
ui/win32/menu.h
ui/win32/text.c
ui/win32/text.h
ui/win32/window.c

index ef3ec5543ef5556eee7a03d66ff41d68fc7ec73d..077620ce338f2a9c6e144f4668568e7e8fcc07e3 100644 (file)
@@ -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 {
index db2bf6619d04c70effdc7a8bc3b4ebd3e2462c4d..95b65138c229ded7d1a0b552d9f4dc3e9a7af73e 100644 (file)
@@ -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<MainWindow>) -> UiObject<MainWi
                             textfield!(obj, hexpand = true, hfill = true, varname = "note_nodename", onchange_action = "note_nodename_change");
                             button!(obj, label = "Open", action = "open_extern");
                         });
+
+                        g.grid_row(|obj|{
+                            tabview!(obj, fill = true, colspan = 3, varname = "filenote_preview_tab", tabview_type = TabViewType::Invisible, |tabview|{
+                                tabview.tab("empty", |_obj| {});
+                                tabview.tab("image", |obj| {
+                                    imageviewer!(obj,
+                                        varname = "filenote_image",
+                                        fill = true,
+                                        useradjustable = true,
+                                        scrollview = true,
+                                        autoscale = true);
+                                });
+                            });
+                        });
                     });
                 });
             });
index eae4e3b6fe7a81c49c1c202686380d855618f178..db902f50a7d06d2d7499933358b1df5b149212f1 100644 (file)
 
 use std::ffi::{c_char, c_int, c_void, CString};
 use std::path::Path;
-use crate::ui::{ffi, toolkit, UiContext, UiImage};
+use crate::ui::{ffi, toolkit, ButtonBuilder, UiContext, UiImage};
 use crate::ui::ffi::{UiImageViewerArgs, UiLabelArgs};
 use crate::ui::label::{Label, LabelCreate};
 use crate::ui::widget::Widget;
 
-#[cfg(unix)]
-fn path_to_cstring(path: &Path) -> Result<CString, std::ffi::NulError> {
-    use std::os::unix::ffi::OsStrExt;
-    CString::new(path.as_os_str().as_bytes())
-}
 
-#[cfg(windows)]
-fn path_to_cstring(path: &Path) -> Result<CString, std::ffi::NulError> {
-    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<T> toolkit::UiObject<T> {
+    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<CString, std::ffi::NulError> {
+    use std::os::unix::ffi::OsStrExt;
+    CString::new(path.as_os_str().as_bytes())
+}
+
+#[cfg(windows)]
+fn path_to_cstring(path: &Path) -> Result<CString, std::ffi::NulError> {
+    CString::new(path.to_string_lossy().as_bytes())
+}
+
 /* -------------------------------- C functions -------------------------------- */
 
 unsafe extern "C" {
index b9bb8f0743495cae399dbf5045bc9219ad327a9e..4c950ff09bc7c6b509aa9c590bc3cd6005417e59 100644 (file)
@@ -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) {
index 7a8dbd73025e8521ab2d6bf49e2b57d960dbb3a4..b400f51e7a5094fabb543dd208d9347844650f32 100644 (file)
@@ -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);
index 8181126301707af9236baa3e9d096c49920f1f79..b323cd051214f482b88918284ad2b64459d46f26 100644 (file)
@@ -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;
index 548cfdda6d24c8eb66217ea2b1c3fb2f1bafd3a4..9bec60df6fbc34850571436c1f82c2e49e92a683 100644 (file)
@@ -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
+}
index 1c696065d1417013da5359c722531d629e7ae9c5..07d9d8373dbc9d02421cc7ddbcc2ac5314fc31a2 100644 (file)
@@ -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;
index 0730f7569d6bacd06c1d1b889146c955f6afbebe..f3498fab98e0b2e48028c243332f936e6d837ca7 100644 (file)
@@ -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);
index e56a3c5b6d484d04713546a4be0461a10211db1d..402d7a91d86e47dffaf0fb5bae67e80e6dc9284c 100644 (file)
@@ -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;
index 889ad5f86dc4aba3a174a06de9e276a41ca9a4a8..0d49b790ff22d04e6378dd4bc7402bbb21054da8 100644 (file)
@@ -99,14 +99,14 @@ UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs *args) {
     return box_create(obj, args, UI_BOX_HORIZONTAL);\r
 }\r
 \r
-UiContainerX* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding) {\r
+UiContainer* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding) {\r
     UiBoxContainer *container = cxZalloc(obj->ctx->allocator, sizeof(UiBoxContainer));\r
     container->container.hwnd = hwnd;\r
     container->container.add = ui_box_container_add;\r
     container->layout = ui_grid_layout_create(obj->ctx->allocator, spacing, spacing);\r
     container->layout->padding = padding;\r
     container->orientation = orientation;\r
-    return (UiContainerX*)container;\r
+    return (UiContainer*)container;\r
 }\r
 \r
 void ui_box_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layout) {\r
@@ -156,7 +156,7 @@ UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) {
     UiGridWidget *widget = w32_widget_create(&grid_layout_widget_class, hwnd, sizeof(UiGridWidget));\r
     ui_container_add(container, (W32Widget*)widget, &layout);\r
 \r
-    UiContainerX *gridContainer = ui_grid_container_create(obj, hwnd, args->columnspacing, args->rowspacing, INSETS_ZERO);\r
+    UiContainer *gridContainer = ui_grid_container_create(obj, hwnd, args->columnspacing, args->rowspacing, INSETS_ZERO);\r
     uic_object_push_container(obj, gridContainer);\r
 \r
     UiGridLayoutContainer *grid = (UiGridLayoutContainer*)gridContainer;\r
@@ -169,13 +169,13 @@ UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) {
     return (W32Widget*)widget;\r
 }\r
 \r
-UiContainerX* ui_grid_container_create(UiObject *obj, HWND hwnd, short columnspacing, short rowspacing, GridEdgeInsets padding) {\r
+UiContainer* ui_grid_container_create(UiObject *obj, HWND hwnd, short columnspacing, short rowspacing, GridEdgeInsets padding) {\r
     UiGridLayoutContainer *container = cxZalloc(obj->ctx->allocator, sizeof(UiGridLayoutContainer));\r
     container->container.hwnd = hwnd;\r
     container->container.add = ui_grid_container_add;\r
     container->layout = ui_grid_layout_create(obj->ctx->allocator, columnspacing, rowspacing);\r
     container->layout->padding = padding;\r
-    return (UiContainerX*)container;\r
+    return (UiContainer*)container;\r
 }\r
 \r
 void ui_grid_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layout) {\r
@@ -204,12 +204,12 @@ void ui_grid_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout
 /* ---------------------------- Container Helper ---------------------------- */\r
 \r
 void ui_container_begin_close(UiObject *obj) {\r
-    UiContainerX *ct = obj->container_end;\r
+    UiContainer *ct = obj->container_end;\r
     ct->close = 1;\r
 }\r
 \r
 int ui_container_finish(UiObject *obj) {\r
-    UiContainerX *ct = obj->container_end;\r
+    UiContainer *ct = obj->container_end;\r
     if(ct->close) {\r
         ui_end_new(obj);\r
         return 0;\r
index 2d0ca9dc9d06bdccf3d19d3f77e90c959f947ce9..8314644ae633a281f6615748c614b3e52b32be8e 100644 (file)
@@ -63,7 +63,7 @@ typedef struct UiRect {
 \r
 \r
 struct UiContainerPrivate {\r
-    UiContainerX    container;\r
+    UiContainer     container;\r
     HWND            (*parent)(UiContainerPrivate*);\r
     void            (*add)(UiContainerPrivate*, W32Widget*, UiLayout*);\r
     UiContainerType type;\r
@@ -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);\r
 W32Size ui_grid_layout_get_preferred_size(W32Widget *widget);\r
 \r
-UiContainerX* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding);\r
+UiContainer* ui_box_container_create(UiObject *obj, HWND hwnd, UiBoxOrientation orientation, short spacing, GridEdgeInsets padding);\r
 void ui_box_container_add(UiContainerPrivate *ctn, W32Widget *widget, UiLayout *layout);\r
 \r
-UiContainerX* ui_grid_container_create(\r
+UiContainer* ui_grid_container_create(\r
     UiObject *obj,\r
     HWND hwnd,\r
     short columnspacing,\r
index 16171de222e80b150420633d0d4f8d6c8815cb87..1fde17afe256dd3c824dc9619c6ce4bc18fc565b 100644 (file)
@@ -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);\r
     ls->index = pos;\r
     ls->getvalue = il->getvalue;\r
+    ls->getvaluedata = NULL; // TODO\r
     ls->callback = il->callback;\r
     ls->userdata = il->userdata;\r
     ls->addseparator = il->addseparator;\r
@@ -339,12 +340,15 @@ void ui_update_menuitem_list(UiActiveMenuItemList *list) {
     }\r
     cxListClear(list->command_ids); // TODO: we could reuse some of the ids\r
 \r
-    ui_getvaluefunc getvalue = list->getvalue;\r
+    ui_getvaluefunc2 getvalue = list->getvalue;\r
+    void *getvaluedata = list->getvaluedata;\r
     void* elm = ui_list_first(ls);\r
 \r
     int pos = list->index;\r
+    int row = 0;\r
     while(elm) {\r
-        char *label = (char*) (getvalue ? getvalue(elm, 0) : elm);\r
+        UiBool freeResult = FALSE;\r
+        char *label = (char*) (getvalue ? getvalue(ls, elm, row, 0, getvaluedata, &freeResult) : elm);\r
         if (!label) {\r
             label = "";\r
         }\r
@@ -353,7 +357,12 @@ void ui_update_menuitem_list(UiActiveMenuItemList *list) {
         InsertMenu(list->menu, pos++, MF_STRING, id, label);\r
         cxListAdd(list->command_ids, &id);\r
 \r
+        if (freeResult) {\r
+            free(label);\r
+        }\r
+\r
         elm = ui_list_next(ls);\r
+        row++;\r
     }\r
 }\r
 \r
index efb5d48ce76a864fb7e0f2c231c618990363ee7d..d7874f6d1b647d2a2e24bc4badafe412abb2e639 100644 (file)
@@ -55,7 +55,8 @@ struct UiActiveMenuItemList {
     CxList           *command_ids;\r
     int              index;\r
     UiVar            *var;\r
-    ui_getvaluefunc  getvalue;\r
+    ui_getvaluefunc2 getvalue;\r
+    void             *getvaluedata;\r
     ui_callback      callback;\r
     void             *userdata;\r
     bool             addseparator;\r
index cc5f400e1d50e5df24f7e1b7438c5b58435ebb8a..87c61505ac5f2e578f7e6ed7ee5c4b59d5d95614 100644 (file)
@@ -127,7 +127,7 @@ char* ui_textarea_getsubstr(UiText *text, int begin, int end) {
     return NULL;\r
 }\r
 \r
-void  ui_textarea_insert(UiText *text, int pos, char *str) {\r
+void  ui_textarea_insert(UiText *text, int pos, const char *str) {\r
 \r
 }\r
 \r
index 7eed5dbe98395b87ef0a6d3f46fa5bce40ec799d..1bbf6527e41658a4692dced26904ad45281a3bd5 100644 (file)
@@ -53,7 +53,7 @@ void  ui_textarea_restore(UiText *text);
 void  ui_textarea_set(UiText *text, const char *str);\r
 char* ui_textarea_get(UiText *text);\r
 char* ui_textarea_getsubstr(UiText *text, int begin, int end);\r
-void  ui_textarea_insert(UiText *text, int pos, char *str);\r
+void  ui_textarea_insert(UiText *text, int pos, const char *str);\r
 void  ui_textarea_setposition(UiText *text, int pos);\r
 int   ui_textarea_position(UiText *text);\r
 void  ui_textarea_setselection(UiText *text, int begin, int end);\r
index c0a51b0c75d5b47d299fd48221eef84bd71555cd..0dcd6cce1e26d820d1afd7d7407723938c8af0ca 100644 (file)
@@ -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;