added some special textfields (GTK)

Fri, 29 Jan 2016 18:48:56 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 29 Jan 2016 18:48:56 +0100
changeset 121
1cc365c34125
parent 120
49bc645df8b7
child 122
e82b01d17a78

added some special textfields (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/common/context.c file | annotate | diff | comparison | revisions
ui/gtk/container.c file | annotate | diff | comparison | revisions
ui/gtk/graphics.c file | annotate | diff | comparison | revisions
ui/gtk/range.c file | annotate | diff | comparison | revisions
ui/gtk/text.c file | annotate | diff | comparison | revisions
ui/ui/text.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Jan 27 20:55:37 2016 +0100
+++ b/application/main.c	Fri Jan 29 18:48:56 2016 +0100
@@ -141,27 +141,20 @@
     ui_context_closefunc(obj->ctx, window_close, NULL);
     
 ///*
-    ui_scrolledwindow(obj);
+    ui_vbox_sp(obj, 8, 4);
+    
+    ui_textfield(obj, NULL);
+    ui_passwordfield(obj, NULL);
+    ui_frameless_textfield(obj, NULL);
     
-    ui_vbox(obj);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
-    ui_button(obj, "Test", NULL, NULL);
+    ui_layout_fill(obj, FALSE);
+    ui_hbox_sp(obj, 0, 10);
+    ui_textfield_w(obj, 10, NULL);
+    ui_textfield_w(obj, 40, NULL);
+    ui_textfield(obj, NULL);
+    ui_end(obj);
     
-    ui_end(obj);
+    ui_textarea(obj, NULL);
     
     ui_end(obj);
 //*/
--- a/ui/common/context.c	Wed Jan 27 20:55:37 2016 +0100
+++ b/ui/common/context.c	Fri Jan 29 18:48:56 2016 +0100
@@ -432,6 +432,10 @@
 }
 
 int* ui_active_groups(UiContext *ctx, int *ngroups) {
+    if(!ctx->groups) {
+        return NULL;
+    }
+    
     int nelm = ucx_list_size(ctx->groups);
     int *groups = calloc(sizeof(int), nelm);
     
@@ -470,7 +474,9 @@
         ui_set_enabled(gw->widget, enable);
     }
     
-    free(groups);
+    if(groups) {
+        free(groups);
+    }
 }
 
 void uic_add_group_widget(UiContext *ctx, void *widget, UcxList *groups) {
--- a/ui/gtk/container.c	Wed Jan 27 20:55:37 2016 +0100
+++ b/ui/gtk/container.c	Fri Jan 29 18:48:56 2016 +0100
@@ -194,7 +194,12 @@
 }
 
 void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
+    // TODO: check if the widget implements GtkScrollable
+#ifdef UI_GTK3
     gtk_container_add(GTK_CONTAINER(ct->widget), widget);
+#else
+    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(ct->widget), widget);
+#endif
     ui_reset_layout(ct->layout);
     ct->current = widget;
 }
--- a/ui/gtk/graphics.c	Wed Jan 27 20:55:37 2016 +0100
+++ b/ui/gtk/graphics.c	Fri Jan 29 18:48:56 2016 +0100
@@ -88,8 +88,8 @@
         *width = gtk_widget_get_allocated_width(drawingarea);
         *height = gtk_widget_get_allocated_height(drawingarea);
 #else
-        *width = widget->allocation.width;
-        *height = widget->allocation.height;
+        *width = drawingarea->allocation.width;
+        *height = drawingarea->allocation.height;
 #endif
 }
 
--- a/ui/gtk/range.c	Wed Jan 27 20:55:37 2016 +0100
+++ b/ui/gtk/range.c	Fri Jan 29 18:48:56 2016 +0100
@@ -119,7 +119,7 @@
 
 void   ui_scrollbar_setextent(UiRange *range, double extent) {
     GtkAdjustment *a = gtk_range_get_adjustment(GTK_RANGE(range->obj));
-#ifdef ui_GTK2LEGACY
+#ifdef UI_GTK2LEGACY
     a->page_size = extent;
 #else
     gtk_adjustment_set_page_size(a, extent);
--- a/ui/gtk/text.c	Wed Jan 27 20:55:37 2016 +0100
+++ b/ui/gtk/text.c	Fri Jan 29 18:48:56 2016 +0100
@@ -455,15 +455,18 @@
 }
 
 
-UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
-    return ui_textfield_w(obj, 0, value);
-}
-
-UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) {
+static UIWIDGET create_textfield(UiObject *obj, int width, UiBool frameless, UiBool password, UiString *value) {
     GtkWidget *textfield = gtk_entry_new();
     if(width > 0) {
         gtk_entry_set_width_chars(GTK_ENTRY(textfield), width);
     }
+    if(frameless) {
+        // TODO: gtk2legacy workaroud
+        gtk_entry_set_has_frame(GTK_ENTRY(textfield), FALSE);
+    }
+    if(password) {
+        gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE);
+    }
     
     UiContainer *ct = uic_get_current_container(obj);
     ct->add(ct, textfield, FALSE);
@@ -484,21 +487,57 @@
     return textfield;
 }
 
-UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
-    return ui_textfield_wnv(obj, 0, varname);
-}
-
-UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) {
+static UIWIDGET create_textfield_nv(UiObject *obj, int width, UiBool frameless, UiBool password, char *varname) {
     UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING);
     if(var) {
         UiString *value = var->value;
-        return ui_textfield_w(obj, width, value);
+        return create_textfield(obj, width, frameless, password, value);
     } else {
         // TODO: error
     }
     return NULL;
 }
 
+UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
+    return create_textfield(obj, 0, FALSE, FALSE, value);
+}
+
+UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) {
+    return create_textfield(obj, width, FALSE, FALSE, value);
+}
+
+UIWIDGET ui_frameless_textfield(UiObject *obj, UiString *value) {
+    return create_textfield(obj, 0, TRUE, FALSE, value);
+}
+
+UIWIDGET ui_passwordfield(UiObject *obj, UiString *value) {
+    return create_textfield(obj, 0, FALSE, TRUE, value);
+}
+
+UIWIDGET ui_passwordfield_w(UiObject *obj, int width, UiString *value) {
+    return create_textfield(obj, width, FALSE, TRUE, value);
+}
+
+UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
+    return create_textfield_nv(obj, 0, FALSE, FALSE, varname);
+}
+
+UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) {
+    return create_textfield_nv(obj, width, FALSE, FALSE, varname);
+}
+
+UIWIDGET ui_frameless_textfield_nv(UiObject *obj, char *varname) {
+    return create_textfield_nv(obj, 0, TRUE, FALSE, varname);
+}
+
+UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname) {
+    return create_textfield_nv(obj, 0, FALSE, TRUE, varname);
+}
+
+UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) {
+    return create_textfield_nv(obj, width, FALSE, TRUE, varname);
+}
+
 char* ui_textfield_get(UiString *str) {
     if(str->value) {
         g_free(str->value);
--- a/ui/ui/text.h	Wed Jan 27 20:55:37 2016 +0100
+++ b/ui/ui/text.h	Fri Jan 29 18:48:56 2016 +0100
@@ -47,6 +47,15 @@
 UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value);
 UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname);
 
+UIWIDGET ui_frameless_textfield(UiObject *obj, UiString *value);
+UIWIDGET ui_frameless_textfield_nv(UiObject *obj, char *varname);
+
+UIWIDGET ui_passwordfield(UiObject *obj, UiString *value);
+UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname);
+UIWIDGET ui_passwordfield_w(UiObject *obj, int width, UiString *value);
+UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname);
+
+        
 #ifdef	__cplusplus
 }
 #endif

mercurial