first composite widget - a simple notepad widget - loads (and saves) to a
authorCarsten Haitzler <raster@rasterman.com>
Tue, 21 Oct 2008 12:01:00 +0000 (12:01 +0000)
committerCarsten Haitzler <raster@rasterman.com>
Tue, 21 Oct 2008 12:01:00 +0000 (12:01 +0000)
given filename. done for you. just tell it the file.

SVN revision: 36925

12 files changed:
data/themes/default.edc
data/themes/icon_apps.png [new file with mode: 0644]
data/themes/icon_arrow_down.png [new file with mode: 0644]
data/themes/icon_arrow_left.png [new file with mode: 0644]
data/themes/icon_arrow_right.png [new file with mode: 0644]
data/themes/icon_arrow_up.png [new file with mode: 0644]
data/themes/icon_close.png [new file with mode: 0644]
data/themes/icon_home.png [new file with mode: 0644]
src/bin/test.c
src/lib/Elementary.h
src/lib/Makefile.am
src/lib/elc_notepad.c [new file with mode: 0644]

index 45e8dc5..153732a 100644 (file)
@@ -327,6 +327,8 @@ collections {
            signal: "load";
            source: "";
            script {
+              set_state(PART:"sb_hbar_clip", "hidden", 0.0);
+              set_state(PART:"sb_vbar_clip", "hidden", 0.0);
               set_int(sbvis_h, 0);
               set_int(sbvis_v, 0);
               set_int(sbvis_timer, 0);
@@ -468,6 +470,15 @@ collections {
               aspect_preference: VERTICAL;
               rel2.offset: 4 -5;
            }
+           description { state: "icononly" 0.0;
+              inherit: "default" 0.0;
+              visible: 1;
+              align: 0.5 0.5;
+              aspect: 1.0 1.0;
+              rel2.offset: -5 -5;
+              rel2.relative: 1.0 1.0;
+              aspect_preference: VERTICAL;
+           }
         }
          part {
            name:          "elm.text";
@@ -522,14 +533,14 @@ collections {
         program {
            name:   "button_click";
            signal: "mouse,down,1";
-           source: "button_image";
+           source: "over2";
            action: STATE_SET "clicked" 0.0;
            target: "button_image";
         }
         program {
            name:   "button_unclick";
            signal: "mouse,up,1";
-           source: "button_image";
+           source: "over2";
            action: STATE_SET "default" 0.0;
            target: "button_image";
         }
@@ -542,20 +553,39 @@ collections {
         program { name: "text_show";
            signal: "elm,state,text,visible";
            source: "elm";
-           action:  STATE_SET "visible" 0.0;
-           target: "elm.text";
+           script {
+              new st[31];
+              new Float:vl;
+              get_state(PART:"elm.swallow.content", st, 30, vl);
+              if (!strcmp(st, "icononly"))
+                set_state(PART:"elm.swallow.content", "visible", 0.0);
+              set_state(PART:"elm.text", "visible", 0.0);
+           }
         }
         program { name: "text_hide";
            signal: "elm,state,text,hidden";
            source: "elm";
-           action:  STATE_SET "default" 0.0;
-           target: "elm.text";
+           script {
+              new st[31];
+              new Float:vl;
+              get_state(PART:"elm.swallow.content", st, 30, vl);
+              if (!strcmp(st, "visible"))
+                set_state(PART:"elm.swallow.content", "icononly", 0.0);
+              set_state(PART:"elm.text", "default", 0.0);
+           }
         }
         program { name: "icon_show";
            signal: "elm,state,icon,visible";
            source: "elm";
-           action:  STATE_SET "visible" 0.0;
-           target: "elm.swallow.content";
+           script {
+              new st[31];
+              new Float:vl;
+              get_state(PART:"elm.text", st, 30, vl);
+              if (!strcmp(st, "visible"))
+                set_state(PART:"elm.swallow.content", "visible", 0.0);
+              else
+                set_state(PART:"elm.swallow.content", "icononly", 0.0);
+           }
         }
         program { name: "icon_hide";
            signal: "elm,state,icon,hidden";
@@ -2881,10 +2911,34 @@ collections {
       }
    }
 ///////////////////////////////////////////////////////////////////////////////
-   group { name: "elm/icon/base/default"; min: 10 10;
-      images.image: "bt_base1.png" COMP; parts { part { name: "base";
+   group { name: "elm/icon/home/default"; min: 32 32;
+      images.image: "icon_home.png" COMP; parts { part { name: "base";
+        description { state: "default" 0.0; aspect: 1.0 1.0;
+           image.normal: "icon_home.png"; } } } }
+   group { name: "elm/icon/close/default"; min: 32 32;
+      images.image: "icon_close.png" COMP; parts { part { name: "base";
+        description { state: "default" 0.0; aspect: 1.0 1.0;
+           image.normal: "icon_close.png"; } } } }
+   group { name: "elm/icon/apps/default"; min: 32 32;
+      images.image: "icon_apps.png" COMP; parts { part { name: "base";
+        description { state: "default" 0.0; aspect: 1.0 1.0;
+           image.normal: "icon_apps.png"; } } } }
+   group { name: "elm/icon/arrow_up/default"; min: 32 32;
+      images.image: "icon_arrow_up.png" COMP; parts { part { name: "base";
+        description { state: "default" 0.0; aspect: 1.0 1.0;
+           image.normal: "icon_arrow_up.png"; } } } }
+   group { name: "elm/icon/arrow_down/default"; min: 32 32;
+      images.image: "icon_arrow_down.png" COMP; parts { part { name: "base";
+        description { state: "default" 0.0; aspect: 1.0 1.0;
+           image.normal: "icon_arrow_down.png"; } } } }
+   group { name: "elm/icon/arrow_left/default"; min: 32 32;
+      images.image: "icon_arrow_left.png" COMP; parts { part { name: "base";
+        description { state: "default" 0.0; aspect: 1.0 1.0;
+           image.normal: "icon_arrow_left.png"; } } } }
+   group { name: "elm/icon/arrow_right/default"; min: 32 32;
+      images.image: "icon_arrow_right.png" COMP; parts { part { name: "base";
         description { state: "default" 0.0; aspect: 1.0 1.0;
-           image.normal: "bt_base1.png"; } } } }
+           image.normal: "icon_arrow_right.png"; } } } }
    
 ///////////////////////////////////////////////////////////////////////////////
    group { name: "elm/contact/base/default";
diff --git a/data/themes/icon_apps.png b/data/themes/icon_apps.png
new file mode 100644 (file)
index 0000000..a3b90c6
Binary files /dev/null and b/data/themes/icon_apps.png differ
diff --git a/data/themes/icon_arrow_down.png b/data/themes/icon_arrow_down.png
new file mode 100644 (file)
index 0000000..899373f
Binary files /dev/null and b/data/themes/icon_arrow_down.png differ
diff --git a/data/themes/icon_arrow_left.png b/data/themes/icon_arrow_left.png
new file mode 100644 (file)
index 0000000..6651510
Binary files /dev/null and b/data/themes/icon_arrow_left.png differ
diff --git a/data/themes/icon_arrow_right.png b/data/themes/icon_arrow_right.png
new file mode 100644 (file)
index 0000000..58fa68d
Binary files /dev/null and b/data/themes/icon_arrow_right.png differ
diff --git a/data/themes/icon_arrow_up.png b/data/themes/icon_arrow_up.png
new file mode 100644 (file)
index 0000000..46584db
Binary files /dev/null and b/data/themes/icon_arrow_up.png differ
diff --git a/data/themes/icon_close.png b/data/themes/icon_close.png
new file mode 100644 (file)
index 0000000..d0a5166
Binary files /dev/null and b/data/themes/icon_close.png differ
diff --git a/data/themes/icon_home.png b/data/themes/icon_home.png
new file mode 100644 (file)
index 0000000..a395fff
Binary files /dev/null and b/data/themes/icon_home.png differ
index b8a916e..5ebdf28 100644 (file)
@@ -763,8 +763,6 @@ my_bt_14(void *data, Evas_Object *obj, void *event_info)
    elm_box_pack_end(bx, sc);
    
    en = elm_entry_add(win);
-   // FIXME: HACK! not exposed!
-   evas_object_propagate_events_set(en, 0);
    elm_entry_entry_set(en,
                       "This is an entry widget in this window that<br>"
                       "uses markup <b>like this</> for styling and<br>"
@@ -829,6 +827,104 @@ my_bt_14(void *data, Evas_Object *obj, void *event_info)
 }
 
 static void
+my_notepad_bt_1(void *data, Evas_Object *obj, void *event_info)
+{
+   Evas_Object *en = data;
+}
+
+static void
+my_notepad_bt_2(void *data, Evas_Object *obj, void *event_info)
+{
+   Evas_Object *en = data;
+}
+
+static void
+my_notepad_bt_3(void *data, Evas_Object *obj, void *event_info)
+{
+   Evas_Object *en = data;
+}
+
+static void
+my_bt_15(void *data, Evas_Object *obj, void *event_info)
+{
+   Evas_Object *win, *bg, *bx, *bx2, *bt, *ic, *np;
+   char buf[PATH_MAX];
+   
+   win = elm_win_add(NULL, "notepad", ELM_WIN_BASIC);
+   elm_win_title_set(win, "Notepad");
+   elm_win_autodel_set(win, 1);
+
+   bg = elm_bg_add(win);
+   elm_win_resize_object_add(win, bg);
+   evas_object_size_hint_weight_set(bg, 1.0, 1.0);
+   evas_object_show(bg);
+   
+   bx = elm_box_add(win);
+   evas_object_size_hint_weight_set(bx, 1.0, 1.0);
+   elm_win_resize_object_add(win, bx);
+   evas_object_show(bx);
+
+   np = elm_notepad_add(win);
+   elm_notepad_file_set(np, "note.txt", ELM_TEXT_FORMAT_MARKUP_UTF8);
+   evas_object_size_hint_weight_set(np, 1.0, 1.0);
+   evas_object_size_hint_align_set(np, -1.0, -1.0);
+   elm_box_pack_end(bx, np);
+   evas_object_show(np);
+   
+   bx2 = elm_box_add(win);
+   elm_box_horizontal_set(bx2, 1);
+   elm_box_homogenous_set(bx2, 1);
+   evas_object_size_hint_weight_set(bx2, 1.0, 0.0);
+   evas_object_size_hint_align_set(bx2, -1.0, -1.0);
+   
+   bt = elm_button_add(win);
+   ic = elm_icon_add(win);
+   elm_icon_standard_set(ic, "arrow_left");
+   elm_icon_scale_set(ic, 1, 0);
+   elm_button_icon_set(bt, ic);
+   evas_object_show(ic);
+   evas_object_smart_callback_add(bt, "clicked", my_notepad_bt_1, np);
+   evas_object_size_hint_align_set(bt, -1.0, -1.0);
+   evas_object_size_hint_weight_set(bt, 1.0, 0.0);
+   elm_box_pack_end(bx2, bt);
+   evas_object_show(bt);
+   
+   bt = elm_button_add(win);
+   ic = elm_icon_add(win);
+   elm_icon_standard_set(ic, "close");
+   elm_icon_scale_set(ic, 1, 0);
+   elm_button_icon_set(bt, ic);
+   evas_object_show(ic);
+   evas_object_smart_callback_add(bt, "clicked", my_notepad_bt_2, np);
+   evas_object_size_hint_align_set(bt, -1.0, -1.0);
+   evas_object_size_hint_weight_set(bt, 1.0, 0.0);
+   elm_box_pack_end(bx2, bt);
+   evas_object_show(bt);
+   
+   bt = elm_button_add(win);
+   ic = elm_icon_add(win);
+   elm_icon_standard_set(ic, "arrow_right");
+   elm_icon_scale_set(ic, 1, 0);
+   elm_button_icon_set(bt, ic);
+   evas_object_show(ic);
+   evas_object_smart_callback_add(bt, "clicked", my_notepad_bt_3, np);
+   evas_object_size_hint_align_set(bt, -1.0, -1.0);
+   evas_object_size_hint_weight_set(bt, 1.0, 0.0);
+   elm_box_pack_end(bx2, bt);
+   evas_object_show(bt);
+   
+   elm_box_pack_end(bx, bx2);
+   evas_object_show(bx2);
+
+   // FIXME: HACK! not exposed! (should expose some later?)
+   elm_widget_focus_set(np, 1);
+
+   evas_object_resize(win, 320, 300);
+   
+   evas_object_show(win);
+}
+
+static void
 my_win_main(void)
 {
    Evas_Object *win, *bg, *bx0, *lb, *bx, *bt, *sc, *fr;
@@ -1018,6 +1114,13 @@ my_win_main(void)
    evas_object_size_hint_align_set(bt, -1.0, 0.0);
    elm_box_pack_end(bx, bt);
    evas_object_show(bt);
+   
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "Notepad");
+   evas_object_smart_callback_add(bt, "clicked", my_bt_15, NULL);
+   evas_object_size_hint_align_set(bt, -1.0, 0.0);
+   elm_box_pack_end(bx, bt);
+   evas_object_show(bt);
 
    /* set an initial window size */
    evas_object_resize(win, 320, 520);
index d8cc6d2..fb72ecf 100644 (file)
@@ -99,6 +99,7 @@ extern "C" {
 
    EAPI Evas_Object *elm_icon_add(Evas_Object *parent);
    EAPI void         elm_icon_file_set(Evas_Object *obj, const char *file, const char *group);
+   EAPI void         elm_icon_standard_set(Evas_Object *obj, const char *name);
    EAPI void         elm_icon_smooth_set(Evas_Object *obj, Evas_Bool smooth);
    EAPI void         elm_icon_no_scale_set(Evas_Object *obj, Evas_Bool no_scale);
    EAPI void         elm_icon_scale_set(Evas_Object *obj, Evas_Bool scale_up, Evas_Bool scale_down);
@@ -198,6 +199,20 @@ extern "C" {
     * "cursor,changed" - the cursor changed position
     * "anchor,X,clicked,N" - achor called 'X' was clicked with button 'N'
     */
+   
+   /* composite widgets - these basically put together basic widgets above
+    * in convenient packages that do more than basic stuff */
+
+   typedef enum _Elm_Text_Format
+     {
+       ELM_TEXT_FORMAT_PLAIN_UTF8,
+       ELM_TEXT_FORMAT_MARKUP_UTF8
+     } Elm_Text_Format;
+   EAPI Evas_Object *elm_notepad_add(Evas_Object *parent);
+   EAPI void         elm_notepad_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format);
+   /* smart callbacks called:
+    */
+   
        
 // FIXME: fixes to do
 // * current sizing tree inefficient
@@ -207,12 +222,6 @@ extern "C" {
 // * frame needs to be able to use custom frame style
 // * button needs to be able to use custom frame style
 // * toggle needs to be able to use custom frame style
-//    
-// FIXME: immediate hitlist for widgets:
-// ENTRY: 1 or more line text entry
-// 
-// POPSEL: a button that when pressed uses a hover to display a h/v box or
-//         a table of options surrounding the button with scroll butons at
-//         the end and the ability to drag and scroll
+
    
 #endif
index 68d700b..a2aa669 100644 (file)
@@ -36,6 +36,8 @@ elm_entry.c \
 elm_contact.c \
 elm_contactlist.c \
 \
+elc_notepad.c \
+\
 els_pan.c \
 els_pan.h \
 els_scroller.c \
diff --git a/src/lib/elc_notepad.c b/src/lib/elc_notepad.c
new file mode 100644 (file)
index 0000000..9c27d0b
--- /dev/null
@@ -0,0 +1,222 @@
+#include <Elementary.h>
+#include "elm_priv.h"
+
+typedef struct _Widget_Data Widget_Data;
+
+struct _Widget_Data
+{
+   Evas_Object *scroller, *entry;
+   const char *file;
+   Elm_Text_Format format;
+   Ecore_Timer *delay_write;
+   Evas_Bool can_write : 1;
+   Evas_Bool auto_write : 1;
+};
+
+static void _del_hook(Evas_Object *obj);
+static void _sizing_eval(Evas_Object *obj);
+static void _on_focus_hook(void *data, Evas_Object *obj);
+static void _load(Evas_Object *obj);
+static void _save(Evas_Object *obj);
+
+static void
+_del_hook(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (wd->file) evas_stringshare_del(wd->file);
+   if (wd->delay_write)
+     {
+       ecore_timer_del(wd->delay_write);
+       _save(obj);
+     }
+   free(wd);
+}
+
+static void
+_sizing_eval(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
+   
+   evas_object_size_hint_min_set(obj, minw, minh);
+   evas_object_size_hint_max_set(obj, maxw, maxh);
+}
+
+static void
+_on_focus_hook(void *data, Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   elm_widget_focus_set(wd->entry, 1);
+}
+
+static char *
+_load_markup_utf8(const char *file)
+{
+   FILE *f;
+   long size;
+   char *text = NULL;
+   
+   f = fopen(file, "r");
+   if (!f) return NULL;
+   fseek(f, 0, SEEK_END);
+   size = ftell(f);
+   if (size > 0)
+     {
+       rewind(f);
+       text = malloc(size + 1);
+       if (text)
+         {
+            if (fread(text, size, 1, f))
+              {
+                 text[size] = 0;
+              }
+            else
+              {
+                 free(text);
+                 text = NULL;
+              }
+         }
+     }
+   fclose(f);
+   return text;
+}
+
+static void
+_load(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   char *text;
+   
+   if (!wd->file)
+     {
+       elm_entry_entry_set(wd->entry, "");
+       return;
+     }
+   switch (wd->format)
+     {
+      case ELM_TEXT_FORMAT_PLAIN_UTF8:
+       break;
+      case ELM_TEXT_FORMAT_MARKUP_UTF8:
+       text = _load_markup_utf8(wd->file);
+       break;
+      default:
+       elm_entry_entry_set(wd->entry, "Unknown Text Format");
+       break;
+     }
+   if (text)
+     {
+       elm_entry_entry_set(wd->entry, text);
+       free(text);
+     }
+   else
+     elm_entry_entry_set(wd->entry, "");
+}
+
+static void
+_save_markup_utf8(const char *file, const char *text)
+{
+   FILE *f;
+
+   if ((!text) || (text[0] == 0))
+     {
+       ecore_file_unlink(file);
+       return;
+     }
+   f = fopen(file, "w");
+   if (!f)
+     {
+       // FIXME: report a write error
+       return;
+     }
+   fputs(text, f); // FIXME: catch error
+   fputs("\n", f); // FIXME: catch error
+   fclose(f);
+}
+
+static void
+_save(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd->file) return;
+   switch (wd->format)
+     {
+      case ELM_TEXT_FORMAT_PLAIN_UTF8:
+       break;
+      case ELM_TEXT_FORMAT_MARKUP_UTF8:
+       _save_markup_utf8(wd->file, elm_entry_entry_get(wd->entry));
+       break;
+      default:
+       break;
+     }
+}
+
+static int
+_delay_write(void *data)
+{
+   Widget_Data *wd = elm_widget_data_get(data);
+   _save(data);
+   wd->delay_write = NULL;
+   return 0;
+}
+
+static void
+_entry_changed(void *data, Evas_Object *obj, void *event_info)
+{
+   Widget_Data *wd = elm_widget_data_get(data);
+   if (wd->delay_write)
+     {
+       ecore_timer_del(wd->delay_write);
+       wd->delay_write = NULL;
+     }
+   if (!wd->auto_write) return;
+   wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
+}
+    
+EAPI Evas_Object *
+elm_notepad_add(Evas_Object *parent)
+{
+   Evas_Object *obj;
+   Evas *e;
+   Widget_Data *wd;
+   
+   wd = ELM_NEW(Widget_Data);
+   e = evas_object_evas_get(parent);
+   obj = elm_widget_add(e);
+   elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
+   elm_widget_data_set(obj, wd);
+   elm_widget_del_hook_set(obj, _del_hook);
+   elm_widget_can_focus_set(obj, 0);
+   
+   wd->scroller = elm_scroller_add(parent);
+   elm_widget_resize_object_set(obj, wd->scroller);
+   wd->entry = elm_entry_add(parent);
+   evas_object_size_hint_weight_set(wd->entry, 1.0, 0.0);
+   evas_object_size_hint_align_set(wd->entry, -1.0, -1.0);
+   elm_scroller_content_set(wd->scroller, wd->entry);
+   evas_object_show(wd->entry);
+
+   elm_entry_entry_set(wd->entry, "");
+   evas_object_smart_callback_add(wd->entry, "changed", _entry_changed, obj);
+   
+   wd->auto_write = 1;
+   
+   _sizing_eval(obj);
+   return obj;
+}
+
+EAPI void
+elm_notepad_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (wd->delay_write)
+     {
+       ecore_timer_del(wd->delay_write);
+       wd->delay_write = NULL;
+     }
+   _save(obj);
+   if (wd->file) evas_stringshare_del(wd->file);
+   wd->file = NULL;
+   if (file) wd->file = evas_stringshare_add(file);
+   wd->format = format;
+   _load(obj);
+}