added scrollbar (Motif)

Wed, 27 Jan 2016 12:52:39 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 27 Jan 2016 12:52:39 +0100
changeset 119
d7a7fb79b5f7
parent 118
bb21210e9cac
child 120
49bc645df8b7

added scrollbar (Motif)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/range.h file | annotate | diff | comparison | revisions
ui/motif/graphics.c file | annotate | diff | comparison | revisions
ui/motif/objs.mk file | annotate | diff | comparison | revisions
ui/motif/range.c file | annotate | diff | comparison | revisions
ui/motif/range.h file | annotate | diff | comparison | revisions
ui/motif/toolkit.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Jan 27 12:10:42 2016 +0100
+++ b/application/main.c	Wed Jan 27 12:52:39 2016 +0100
@@ -60,6 +60,7 @@
 
 void action_scroll(UiEvent *event, void *data) {
     ui_drawingarea_redraw(drawingarea);
+    printf("scroll\n");
 }
 
 void draw(UiEvent *event, UiGraphics *g, void *data) {
@@ -142,6 +143,8 @@
 ///*
     ui_hbox(obj);
     
+//*
+    ui_vbox(obj);
     drawingarea = ui_drawingarea(obj, draw, NULL);
     ctxmenu = ui_contextmenu_w(obj, drawingarea);
     ui_widget_menuitem(obj, "Test1", NULL, NULL);
@@ -149,10 +152,12 @@
     ui_widget_menuitem(obj, "Test3", NULL, NULL);
     ui_widget_menuitem(obj, "Test4", NULL, NULL);
     ui_drawingarea_mousehandler(obj, drawingarea, click, NULL);
+    ui_end(obj);
+//*/
     
     ui_vscrollbar(obj, &range, action_scroll, NULL);
-    range.setrange(&range, 0, 400);
-    range.setextent(&range, 1);
+    range.setrange(&range, 0, 100);
+    range.setextent(&range, 20);
     range.set(&range, 0);
     
     ui_end(obj);
--- a/ui/gtk/range.h	Wed Jan 27 12:10:42 2016 +0100
+++ b/ui/gtk/range.h	Wed Jan 27 12:52:39 2016 +0100
@@ -25,6 +25,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+
 #ifndef RANGE_H
 #define RANGE_H
 
--- a/ui/motif/graphics.c	Wed Jan 27 12:10:42 2016 +0100
+++ b/ui/motif/graphics.c	Wed Jan 27 12:52:39 2016 +0100
@@ -28,6 +28,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <X11/Intrinsic.h>
+#include <X11/IntrinsicP.h>
 
 #include "graphics.h"
 
@@ -134,6 +136,16 @@
     }
 }
 
+void ui_drawingarea_getsize(UIWIDGET drawingarea, int *width, int *height) {
+    // TODO
+}
+
+void ui_drawingarea_redraw(UIWIDGET drawingarea) {
+    XClearArea(XtDisplay(drawingarea), drawingarea->core.window, 0, 0, drawingarea->core.width, drawingarea->core.height, True);
+    
+}
+
+
 /* -------------------- text layout functions -------------------- */
 UiTextLayout* ui_text(UiGraphics *g) {
     UiTextLayout *text = malloc(sizeof(UiTextLayout));
--- a/ui/motif/objs.mk	Wed Jan 27 12:10:42 2016 +0100
+++ b/ui/motif/objs.mk	Wed Jan 27 12:52:39 2016 +0100
@@ -41,6 +41,7 @@
 MOTIFOBJ += list.o
 MOTIFOBJ += tree.o
 MOTIFOBJ += graphics.o
+MOTIFOBJ += range.o
 
 TOOLKITOBJS += $(MOTIFOBJ:%=$(MOTIF_OBJPRE)%)
 TOOLKITSOURCE += $(MOTIFOBJ:%.o=motif/%.c)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/motif/range.c	Wed Jan 27 12:52:39 2016 +0100
@@ -0,0 +1,138 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2016 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 "range.h"
+#include "container.h"
+#include "../../ucx/mempool.h"
+#include "../common/context.h"
+#include "../common/object.h"
+
+
+static UIWIDGET ui_scrollbar(UiObject *obj, UiOrientation orientation, UiRange *range, ui_callback f, void *userdata) {
+    UiContainer *ct = uic_get_current_container(obj);
+    
+    int n = 0;
+    Arg args[16];
+    XtSetArg(args[n], XmNorientation, orientation == UI_HORIZONTAL ? XmHORIZONTAL : XmVERTICAL);
+    n++;
+    XtSetArg (args[n], XmNmaximum, 10);
+    n++;
+    XtSetArg (args[n], XmNsliderSize, 1);
+    n++;
+    Widget parent = ct->prepare(ct, args, &n, FALSE);
+    Widget scrollbar = XmCreateScrollBar(parent, "scrollbar", args, n);
+    XtManageChild(scrollbar);
+    ct->add(ct, scrollbar);
+    
+    if(range) {
+        range->get = ui_scrollbar_get;
+        range->set = ui_scrollbar_set;
+        range->setrange = ui_scrollbar_setrange;
+        range->setextent = ui_scrollbar_setextent;
+        range->obj = scrollbar;
+    }
+    
+    if(f) {
+        UiEventData *event = ucx_mempool_malloc(
+                obj->ctx->mempool,
+                sizeof(UiEventData));
+        event->obj = obj;
+        event->userdata = userdata;
+        event->callback = f;
+        event->value = 0;
+        XtAddCallback(
+                scrollbar,
+                XmNvalueChangedCallback,
+                (XtCallbackProc)ui_scrollbar_callback,
+                event);
+    }
+    
+    return scrollbar;
+}
+
+UIWIDGET ui_hscrollbar(UiObject *obj, UiRange *range, ui_callback f, void *userdata) {
+    return ui_scrollbar(obj, UI_HORIZONTAL, range, f, userdata);
+}
+
+UIWIDGET ui_vscrollbar(UiObject *obj, UiRange *range, ui_callback f, void *userdata) {
+    return ui_scrollbar(obj, UI_VERTICAL, range, f, userdata);
+}
+
+void ui_scrollbar_callback(Widget scrollbar, UiEventData *event, XtPointer cdata) {
+    UiEvent e;
+    e.obj = event->obj;
+    e.window = event->obj->window;
+    e.document = event->obj->ctx->document;
+    e.intval = event->value;
+    event->callback(&e, event->userdata);
+}
+
+double ui_scrollbar_get(UiRange *range) {
+    int intval;
+    XtVaGetValues(
+            range->obj,
+            XmNvalue,
+            &intval,
+            NULL);
+    double value = (double)intval / 10;
+    range->value = value;
+    return value;
+}
+
+void   ui_scrollbar_set(UiRange *range, double value) {
+    XtVaSetValues(
+            range->obj,
+            XmNvalue,
+            (int)(value * 10),
+            NULL);
+    range->value = value;
+}
+
+void   ui_scrollbar_setrange(UiRange *range, double min, double max) {
+    XtVaSetValues(
+            range->obj,
+            XmNminimum,
+            (int)(min * 10),
+            XmNmaximum,
+            (int)(max * 10),
+            NULL);
+    range->min = min;
+    range->max = max;
+}
+
+void   ui_scrollbar_setextent(UiRange *range, double extent) {
+    XtVaSetValues(
+            range->obj,
+            XmNsliderSize,
+            (int)(extent * 10),
+            NULL);
+    range->extent = extent;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/motif/range.h	Wed Jan 27 12:52:39 2016 +0100
@@ -0,0 +1,51 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2016 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 RANGE_H
+#define RANGE_H
+
+#include "toolkit.h"
+#include "../ui/range.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void ui_scrollbar_callback(Widget scrollbar, UiEventData *event, XtPointer cdata);
+double ui_scrollbar_get(UiRange *range);
+void   ui_scrollbar_set(UiRange *range, double value);
+void   ui_scrollbar_setrange(UiRange *range, double min, double max);
+void   ui_scrollbar_setextent(UiRange *range, double extent);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RANGE_H */
+
--- a/ui/motif/toolkit.h	Wed Jan 27 12:10:42 2016 +0100
+++ b/ui/motif/toolkit.h	Wed Jan 27 12:52:39 2016 +0100
@@ -55,6 +55,9 @@
     void          *finish_data;
 } UiJob;
 
+typedef enum UiOrientation UiOrientation;
+enum UiOrientation { UI_HORIZONTAL = 0, UI_VERTICAL };
+
 void ui_exit_mainloop();
 
 void ui_set_active_window(Widget w);

mercurial