Author: matt
Date: 2011-07-28 16:05:30 -0700 (Thu, 28 Jul 2011)
New Revision: 8882
Log:
Added a panel to support the File Type. This is a bit more complicated (and 
currently quite messy) because we want to be able to change multiple selections 
with a single dialog, as in the widget panel. Rough cut!

Modified:
   branches/branch-3.0/fluid/Fl_Type.cxx
   branches/branch-3.0/fluid/Fl_Type.h
   branches/branch-3.0/fluid/Fl_Widget_Type.cxx
   branches/branch-3.0/fluid/file.cxx
   branches/branch-3.0/fluid/workspace_panel.cxx
   branches/branch-3.0/fluid/workspace_panel.fl
   branches/branch-3.0/fluid/workspace_panel.h

Modified: branches/branch-3.0/fluid/Fl_Type.cxx
===================================================================
--- branches/branch-3.0/fluid/Fl_Type.cxx       2011-07-28 20:49:46 UTC (rev 
8881)
+++ branches/branch-3.0/fluid/Fl_Type.cxx       2011-07-28 23:05:30 UTC (rev 
8882)
@@ -1078,6 +1078,7 @@
 
 Fl_Workspace_Type::Fl_Workspace_Type()
 : Fl_Type(),
+  pEnv(Fl_Environment_Choice::ENV_ALL),
   pNUUID(0), pnUUID(0), 
   pUUIDName(0L), pUUID(0) 
 {
@@ -1311,6 +1312,7 @@
 
 // ------------ Generic File 
---------------------------------------------------
 
+extern fltk3::Window *the_file_panel;
 Fl_File_Type Fl_File_type;
 
 Fl_Type *Fl_File_Type::make() {
@@ -1346,13 +1348,6 @@
   }
 }
 
-void Fl_File_Type::open() {
-  const char *lName = fltk3::input("Enter a file name:", filename());
-  if (lName) {
-    filename(lName);
-  }
-}
-
 char Fl_File_Type::read_property(const char *c) {
   if (!strcmp(c,"filename_and_path")) {
     filename(read_word());
@@ -1421,6 +1416,47 @@
   return 0;
 }
 
+static int numselected = 0;
+static Fl_Type *current_widget;
+extern void* const LOAD;
+extern void propagate_load(fltk3::Group*, void*);
+
+// update the panel according to current widget set:
+static void load_file_panel() {
+  if (!the_file_panel) return;
+  
+  // find all the File Type subclasses currently selected:
+  numselected = 0;
+  current_widget = 0;
+  if (Fl_Type::current) {
+    if (Fl_Type::current->is_file())
+      current_widget=(Fl_Widget_Type*)Fl_Type::current;
+    for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+      if (o->is_file() && o->selected) {
+       numselected++;
+       if (!current_widget) current_widget = o;
+      }
+    }
+  }
+  if (numselected)
+    propagate_load(the_file_panel, LOAD);
+  else
+    the_file_panel->hide();
+}
+
+void Fl_File_Type::open() {
+  if (!the_file_panel) the_file_panel = make_file_panel();
+  load_file_panel();
+  if (numselected) the_file_panel->show();
+}
+
+//void Fl_File_Type::open() {
+//  const char *lName = fltk3::input("Enter a file name:", filename());
+//  if (lName) {
+//    filename(lName);
+//  }
+//}
+
 // ------------ Fluid File 
-----------------------------------------------------
 
 Fl_Fluid_File_Type Fl_Fluid_File_type;
@@ -1446,12 +1482,12 @@
   return o;
 }
 
-void Fl_Fluid_File_Type::open() {
-  const char *lName = fltk3::input("Enter a Fluid file name:", filename());
-  if (lName) {
-    filename(lName);
-  }
-}
+//void Fl_Fluid_File_Type::open() {
+//  const char *lName = fltk3::input("Enter a Fluid file name:", filename());
+//  if (lName) {
+//    filename(lName);
+//  }
+//}
 
 // ------------ Fluid File 
-----------------------------------------------------
 
@@ -1478,12 +1514,12 @@
   return o;
 }
 
-void Fl_Code_File_Type::open() {
-  const char *lName = fltk3::input("Enter a C/C++ file name:", filename());
-  if (lName) {
-    filename(lName);
-  }
-}
+//void Fl_Code_File_Type::open() {
+//  const char *lName = fltk3::input("Enter a C/C++ file name:", filename());
+//  if (lName) {
+//    filename(lName);
+//  }
+//}
 
 // ------------ Folder 
---------------------------------------------------------
 

Modified: branches/branch-3.0/fluid/Fl_Type.h
===================================================================
--- branches/branch-3.0/fluid/Fl_Type.h 2011-07-28 20:49:46 UTC (rev 8881)
+++ branches/branch-3.0/fluid/Fl_Type.h 2011-07-28 23:05:30 UTC (rev 8882)
@@ -179,9 +179,11 @@
 };
 
 class Fl_Workspace_Type : public Fl_Type {  
+  unsigned int pEnv;
   int pNUUID, pnUUID;
   char **pUUIDName;
   char **pUUID;
+  
   void set_UUID(const char *name, const char *uuid);
   void set_UUID(int i, const char *uuid);
   int find_UUID(const char *name);
@@ -196,6 +198,8 @@
   virtual int is_workspace_type() const { return 1; }
   virtual int dnd_available();
   virtual int dnd_paste();
+  void environments(unsigned int e) { pEnv = e; }
+  unsigned int environments() { return pEnv; }
 };
 
 class Fl_Target_Type : public Fl_Workspace_Type {
@@ -281,7 +285,6 @@
   virtual int is_parent() const { return 1; } 
   virtual int is_fluid_file() const { return 1; }
   virtual int pixmapID() { return 53; }
-  virtual void open();
 };
 extern Fl_Fluid_File_Type Fl_Fluid_File_type;
 
@@ -295,7 +298,6 @@
   const char *type_name() { return "code_file"; }
   Fl_Type *make();
   virtual int pixmapID() { return 55; }
-  virtual void open();
 };
 extern Fl_Code_File_Type Fl_Code_File_type;
 

Modified: branches/branch-3.0/fluid/Fl_Widget_Type.cxx
===================================================================
--- branches/branch-3.0/fluid/Fl_Widget_Type.cxx        2011-07-28 20:49:46 UTC 
(rev 8881)
+++ branches/branch-3.0/fluid/Fl_Widget_Type.cxx        2011-07-28 23:05:30 UTC 
(rev 8882)
@@ -295,6 +295,7 @@
 #include <fltk3/show_colormap.h>
 
 static fltk3::Window *the_panel;
+fltk3::Window *the_file_panel;
 
 // All the callbacks use the argument to indicate whether to load or store.
 // This avoids the need for pointers to all the widgets, and keeps the
@@ -1889,6 +1890,7 @@
 // Called when ui changes what objects are selected:
 // p is selected object, null for all deletions (we must throw away
 // old panel in that case, as the object may no longer exist)
+// FIXME: do this for the_file_panel as well
 void selection_changed(Fl_Type *p) {
   // store all changes to the current selected objects:
   if (p && the_panel && the_panel->visible()) {

Modified: branches/branch-3.0/fluid/file.cxx
===================================================================
--- branches/branch-3.0/fluid/file.cxx  2011-07-28 20:49:46 UTC (rev 8881)
+++ branches/branch-3.0/fluid/file.cxx  2011-07-28 23:05:30 UTC (rev 8882)
@@ -463,10 +463,12 @@
 
     if (!strcmp(c,"wks_name")) {
       wks_name = strdup(read_word());
+      goto CONTINUE;
     }
     
     if (!strcmp(c,"wks_env")) {
       wks_env = atoi(read_word());
+      goto CONTINUE;
     }
 
     if (!strcmp(c, "snap") || !strcmp(c, "gridx") || !strcmp(c, "gridy")) {

Modified: branches/branch-3.0/fluid/workspace_panel.cxx
===================================================================
--- branches/branch-3.0/fluid/workspace_panel.cxx       2011-07-28 20:49:46 UTC 
(rev 8881)
+++ branches/branch-3.0/fluid/workspace_panel.cxx       2011-07-28 23:05:30 UTC 
(rev 8882)
@@ -80,8 +80,11 @@
   int n = strlen(buf);
   if (n>2) buf[n-2] = 0;
   pEnvList->copy_label(buf);
-};
 }
+
+if (callback())
+  do_callback();
+}
 void Fl_Environment_Choice::cb_pMenuAll(fltk3::Menu_* o, void* v) {
   ((Fl_Environment_Choice*)(o->parent()))->cb_pMenuAll_i(o,v);
 }
@@ -271,7 +274,153 @@
   } // fltk3::DoubleWindow* o
   return w;
 }
+extern void* const LOAD;
+extern fltk3::Window *the_file_panel;
 
+static void file_panel_name_cb(fltk3::Input *i, void *v) {
+  if (v == LOAD) {
+        /*
+        i->static_value(current_widget->label());
+        if (strlen(i->value()) >= oldlabellen) {
+          oldlabellen = strlen(i->value())+128;
+          oldlabel = (char*)realloc(oldlabel,oldlabellen);
+        }
+        strcpy(oldlabel,i->value());
+        */
+      } else {
+        int mod = 0;
+        for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+          if (o->selected && o->is_file()) {
+            ((Fl_File_Type*)o)->filename(i->value());
+            mod = 1;
+          }
+        }
+        if (mod) set_modflag(1);
+      }
+  
+  /*
+  void name_cb(fltk3::Input* o, void *v) {
+    if (v == LOAD) {
+      static char buf[1024];
+      if (numselected != 1) {
+        snprintf(buf, sizeof(buf), "Widget Properties (%d widgets)", 
numselected);
+        o->hide();
+      } else {
+        o->static_value(current_widget->name());
+        o->show();
+        snprintf(buf, sizeof(buf), "%s Properties", current_widget->title());
+      }
+      
+      the_panel->label(buf);
+    } else {
+      if (numselected == 1) {
+        current_widget->name(o->value());
+        // I don't update window title, as it probably is being closed
+        // and wm2 (a window manager) barfs if you retitle and then
+        // hide a window:
+        // 
((fltk3::Window*)(o->parent()->parent()->parent()))->label(current_widget->title());
+      }
+    }
+  }
+  */
+}
+
+static void file_panel_env_cb(Fl_Environment_Choice *i, void *v) {
+  if (v == LOAD) {
+        /*
+        i->static_value(current_widget->label());
+        if (strlen(i->value()) >= oldlabellen) {
+          oldlabellen = strlen(i->value())+128;
+          oldlabel = (char*)realloc(oldlabel,oldlabellen);
+        }
+        strcpy(oldlabel,i->value());
+        */
+        // FIXME: current_widget needed
+        for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+          if (o->selected && o->is_file()) {
+            i->value(((Fl_File_Type*)o)->environments());
+            return;
+          }
+        }
+      } else {
+        int mod = 0;
+        for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+          if (o->selected && o->is_file()) {
+            ((Fl_File_Type*)o)->environments(i->value());
+            mod = 1;
+          }
+        }
+        if (mod) set_modflag(1);
+      }
+}
+
+static void file_panel_ok_cb(fltk3::Widget*, void*) {
+  fltk3::Widget*const* a = the_file_panel->array();
+      for (int i=the_file_panel->children(); i--;) {
+        fltk3::Widget* o = *a++;
+        if (o->changed()) {
+          o->do_callback();
+          //if (haderror) return;
+          o->clear_changed();
+        }
+      }
+    the_file_panel->hide();
+}
+
+fltk3::DoubleWindow* make_file_panel() {
+  fltk3::DoubleWindow* w;
+  { fltk3::DoubleWindow* o = new fltk3::DoubleWindow(405, 136);
+    w = o;
+    o->labelsize(11);
+    o->align(fltk3::Align(fltk3::ALIGN_CLIP|fltk3::ALIGN_INSIDE));
+    o->hotspot(o);
+    { fltk3::Group* o = new fltk3::Group(75, 15, 309, 20, "File Name:");
+      o->labelfont(1);
+      o->labelsize(11);
+      o->callback((fltk3::Callback*)propagate_load);
+      o->align(fltk3::Align(fltk3::ALIGN_LEFT));
+      { fltk3::Input* o = new fltk3::Input(75, 15, 170, 20);
+        o->tooltip("The label text for the widget.\nUse Ctrl-J for newlines.");
+        o->labelfont(1);
+        o->labelsize(11);
+        o->textsize(11);
+        o->callback((fltk3::Callback*)file_panel_name_cb);
+        o->when(fltk3::WHEN_CHANGED);
+        fltk3::Group::current()->resizable(o);
+      } // fltk3::Input* o
+      o->end();
+    } // fltk3::Group* o
+    { Fl_Environment_Choice* o = new Fl_Environment_Choice(75, 45, 170, 40);
+      o->box(fltk3::FLAT_BOX);
+      o->color(fltk3::BACKGROUND_COLOR);
+      o->selection_color(fltk3::SELECTION_COLOR);
+      o->labeltype(fltk3::NORMAL_LABEL);
+      o->labelfont(0);
+      o->labelsize(14);
+      o->labelcolor(fltk3::FOREGROUND_COLOR);
+      o->callback((fltk3::Callback*)file_panel_env_cb);
+      o->align(fltk3::Align(fltk3::ALIGN_CENTER));
+      o->when(fltk3::WHEN_RELEASE_ALWAYS);
+    } // Fl_Environment_Choice* o
+    { fltk3::Group* o = new fltk3::Group(9, 100, 400, 20);
+      o->labelsize(11);
+      { fltk3::Box* o = new fltk3::Box(9, 100, 321, 20);
+        o->labelsize(11);
+        fltk3::Group::current()->resizable(o);
+      } // fltk3::Box* o
+      { fltk3::ReturnButton* o = new fltk3::ReturnButton(330, 100, 64, 20, 
"Close");
+        o->labelsize(11);
+        o->callback((fltk3::Callback*)file_panel_ok_cb);
+      } // fltk3::ReturnButton* o
+      o->end();
+    } // fltk3::Group* o
+    o->size_range(o->w(), o->h());
+    o->end();
+    o->resizable(o);
+  } // fltk3::DoubleWindow* o
+  return w;
+}
+
 //
 // End of "$Id$".
 //

Modified: branches/branch-3.0/fluid/workspace_panel.fl
===================================================================
--- branches/branch-3.0/fluid/workspace_panel.fl        2011-07-28 20:49:46 UTC 
(rev 8881)
+++ branches/branch-3.0/fluid/workspace_panel.fl        2011-07-28 23:05:30 UTC 
(rev 8882)
@@ -1,7 +1,8 @@
 # data file for the Fltk User Interface Designer (fluid)
 version 3.0000 
 header_name {.h} 
-code_name {.cxx}
+code_name {.cxx} 
+wks_name FLTK
 comment {//
 // "$Id$"
 //
@@ -56,7 +57,7 @@
   decl {enum { ENV_NONE=0, ENV_ALL=0x007f, ENV_ALL_SHELL=0x0003, 
ENV_MAKE=0x0001, ENV_CMAKE=0x0002, ENV_ALL_VC=0x001c, ENV_VC6=0x0004, 
ENV_VC2008=0x0008, ENV_VC2010=0x0010, ENV_ALL_XC=0x0060, ENV_XC3=0x0020, 
ENV_XC4=0x0040 };} {public local
   }
   {fltk3::MenuButton} pEnvMenu {
-    label Environent
+    label Environent open
     xywh {0 0 170 20} labelsize 12
   } {
     MenuItem pMenuAll {
@@ -114,7 +115,10 @@
   int n = strlen(buf);
   if (n>2) buf[n-2] = 0;
   pEnvList->copy_label(buf);
-}}
+}
+
+if (callback())
+  do_callback();} selected
       xywh {0 0 100 20} labelsize 12 divider
     }
     Submenu {} {
@@ -254,7 +258,7 @@
         callback {if (wks_name) free(wks_name);
 wks_name = strdup(pName->value());
 wks_env = pEnv->value();
-workspace_panel->hide();} selected
+workspace_panel->hide();}
         xywh {160 130 95 25} labelsize 12
       }
     }
@@ -274,7 +278,7 @@
 } {
   {fltk3::Window} {} {
     label {Application Target} open
-    xywh {464 218 307 281} type Double visible
+    xywh {550 437 307 281} type Double visible
   } {
     {fltk3::Input} {} {
       label {Name:}
@@ -311,6 +315,142 @@
   }
 } 
 
+decl {extern void* const LOAD;} {private global
+} 
+
+decl {extern fltk3::Window *the_file_panel;} {private global
+} 
+
+Function {file_panel_name_cb(fltk3::Input *i, void *v)} {open private 
return_type void
+} {
+  code {if (v == LOAD) {
+      /*
+      i->static_value(current_widget->label());
+      if (strlen(i->value()) >= oldlabellen) {
+        oldlabellen = strlen(i->value())+128;
+        oldlabel = (char*)realloc(oldlabel,oldlabellen);
+      }
+      strcpy(oldlabel,i->value());
+      */
+    } else {
+      int mod = 0;
+      for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+        if (o->selected && o->is_file()) {
+          ((Fl_File_Type*)o)->filename(i->value());
+          mod = 1;
+        }
+      }
+      if (mod) set_modflag(1);
+    }
+
+/*
+void name_cb(fltk3::Input* o, void *v) {
+  if (v == LOAD) {
+    static char buf[1024];
+    if (numselected != 1) {
+      snprintf(buf, sizeof(buf), "Widget Properties (%d widgets)", 
numselected);
+      o->hide();
+    } else {
+      o->static_value(current_widget->name());
+      o->show();
+      snprintf(buf, sizeof(buf), "%s Properties", current_widget->title());
+    }
+    
+    the_panel->label(buf);
+  } else {
+    if (numselected == 1) {
+      current_widget->name(o->value());
+      // I don't update window title, as it probably is being closed
+      // and wm2 (a window manager) barfs if you retitle and then
+      // hide a window:
+      // 
((fltk3::Window*)(o->parent()->parent()->parent()))->label(current_widget->title());
+    }
+  }
+}
+*/} {}
+} 
+
+Function {file_panel_env_cb(Fl_Environment_Choice *i, void *v)} {open private 
return_type void
+} {
+  code {if (v == LOAD) {
+      /*
+      i->static_value(current_widget->label());
+      if (strlen(i->value()) >= oldlabellen) {
+        oldlabellen = strlen(i->value())+128;
+        oldlabel = (char*)realloc(oldlabel,oldlabellen);
+      }
+      strcpy(oldlabel,i->value());
+      */
+      // FIXME: current_widget needed
+      for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+        if (o->selected && o->is_file()) {
+          i->value(((Fl_File_Type*)o)->environments());
+          return;
+        }
+      }
+    } else {
+      int mod = 0;
+      for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
+        if (o->selected && o->is_file()) {
+          ((Fl_File_Type*)o)->environments(i->value());
+          mod = 1;
+        }
+      }
+      if (mod) set_modflag(1);
+    }} {}
+} 
+
+Function {file_panel_ok_cb(fltk3::Widget*, void*)} {open private return_type 
void
+} {
+  code {fltk3::Widget*const* a = the_file_panel->array();
+    for (int i=the_file_panel->children(); i--;) {
+      fltk3::Widget* o = *a++;
+      if (o->changed()) {
+        o->do_callback();
+        //if (haderror) return;
+        o->clear_changed();
+      }
+    }
+  the_file_panel->hide();} {}
+} 
+
+Function {make_file_panel()} {open
+} {
+  {fltk3::Window} {} {open
+    xywh {510 319 405 136} type Double labelsize 11 align 80 resizable hotspot
+    code0 {o->size_range(o->w(), o->h());} visible
+  } {
+    {fltk3::Group} {} {
+      label {File Name:}
+      callback propagate_load open
+      xywh {75 15 309 20} labelfont 1 labelsize 11 align 4
+    } {
+      {fltk3::Input} {} {
+        callback file_panel_name_cb
+        tooltip {The label text for the widget.
+Use Ctrl-J for newlines.} xywh {75 15 170 20} labelfont 1 labelsize 11 when 1 
textsize 11 resizable
+      }
+    }
+    {fltk3::MenuButton} {} {
+      callback file_panel_env_cb open
+      xywh {75 45 170 40} box FLAT_BOX
+      class Fl_Environment_Choice
+    } {}
+    {fltk3::Group} {} {open
+      xywh {9 100 400 20} labelsize 11
+    } {
+      {fltk3::Box} {} {
+        xywh {9 100 321 20} labelsize 11 resizable
+      }
+      {fltk3::ReturnButton} {} {
+        label Close
+        callback file_panel_ok_cb
+        xywh {330 100 64 20} labelsize 11
+      }
+    }
+  }
+} 
+
 comment {
 //
 // End of "$Id$".

Modified: branches/branch-3.0/fluid/workspace_panel.h
===================================================================
--- branches/branch-3.0/fluid/workspace_panel.h 2011-07-28 20:49:46 UTC (rev 
8881)
+++ branches/branch-3.0/fluid/workspace_panel.h 2011-07-28 23:05:30 UTC (rev 
8882)
@@ -67,6 +67,9 @@
 #include <fltk3/Choice.h>
 #include <fltk3/Output.h>
 fltk3::DoubleWindow* make_app_target_panel();
+extern void propagate_load(fltk3::Group*, void*);
+#include <fltk3/ReturnButton.h>
+fltk3::DoubleWindow* make_file_panel();
 #endif
 
 //

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to