diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2010-07-10 09:44:45 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2010-07-10 09:44:45 +0000 |
| commit | 32716d6b1e8a90cbe61b60994323029ec6abe85c (patch) | |
| tree | 9c047f9cbf6a6581ef408dfabdab0aebde240a1b /src | |
| parent | 8306c3d0b31d4e60a9ba9c4d0ca4ed6a32226de1 (diff) | |
Updated the Fluid IDE support for the current source file structure. Changed the Fl_Tree rendering code around a bit to make the tree more like MSWindows on Windows and more like Apple on Apple machines. I hope you guys like it. I also moved the function to load Fl_Preferences into an Fl_Tree into the Fl_Tree class where it belongs.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7672 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_File_Chooser2.cxx | 2 | ||||
| -rw-r--r-- | src/Fl_Input_.cxx | 6 | ||||
| -rw-r--r-- | src/Fl_Preferences.cxx | 33 | ||||
| -rw-r--r-- | src/Fl_Text_Buffer.cxx | 2 | ||||
| -rw-r--r-- | src/Fl_Tree.cxx | 51 | ||||
| -rw-r--r-- | src/Fl_Tree_Item.cxx | 23 | ||||
| -rw-r--r-- | src/Fl_Tree_Prefs.cxx | 44 |
7 files changed, 116 insertions, 45 deletions
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx index f7e095e86..33b7e3f2e 100644 --- a/src/Fl_File_Chooser2.cxx +++ b/src/Fl_File_Chooser2.cxx @@ -1031,6 +1031,8 @@ Fl_File_Chooser::filter(const char *p) // I - Pattern(s) if (!allfiles) showChoice->add(all_files_label); showChoice->add(custom_filter_label); + + // TODO: add a menu item to switch hidden files on and off showChoice->value(0); showChoiceCB(); diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx index 67b9fe709..d39fe62d6 100644 --- a/src/Fl_Input_.cxx +++ b/src/Fl_Input_.cxx @@ -722,12 +722,12 @@ static void undobuffersize(int n) { <tt>when() & FL_WHEN_CHANGED</tt> and there is a change. Set \p b and \p e equal to not delete anything. - Set insert to \c NULL to not insert anything. + Set \p text to \c NULL to not insert anything. - \p ilen must be zero or strlen(insert), this + \p ilen can be zero or <tt>strlen(text)</tt>, which saves a tiny bit of time if you happen to already know the length of the insertion, or can be used to insert a portion of a - string or a string containing <tt>nul</tt>'s. + string. \p b and \p e are clamped to the <tt>0..size()</tt> range, so it is safe to pass any values. diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx index 466a4f5d6..7a5a72b36 100644 --- a/src/Fl_Preferences.cxx +++ b/src/Fl_Preferences.cxx @@ -380,17 +380,6 @@ Fl_Preferences::~Fl_Preferences() /** - Copy the database hierarchy to an Fl_Tree browser from this node down. - */ -char Fl_Preferences::copyTo(Fl_Tree *tree) -{ - if (!tree->root()) - tree->add(name()); - return node->copyTo(tree, tree->root()); -} - - -/** Returns the number of groups that are contained within a group. \return 0 for no groups at all @@ -1762,28 +1751,6 @@ void Fl_Preferences::Node::deleteIndex() { indexed_ = 0; } -char Fl_Preferences::Node::copyTo(Fl_Tree *tree, Fl_Tree_Item *ti) -{ - ti->label(name()); - ti->user_data(this); - Node *nd = child_; - for ( ; nd; nd = nd->next_) { - Fl_Tree_Item *tic = tree->insert(ti, 0, 0); - nd->copyTo(tree, tic); - tic->close(); - } - int i, n = nEntry_; - for (i=0; i<n; i++) { - char buf[80]; - const char *name = entry_[i].name; - const char *value = entry_[i].value; - fl_snprintf(buf, 80, "%s: %s", name, value); - tree->add(ti, buf); - } - return 0; -} - - /** * \brief Create a plugin. * diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index 5c87340b6..74e04688a 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -1909,7 +1909,7 @@ static void addPadding(char *string, int startIndent, int toIndent, if (useTabs) { while (indent < toIndent) { - static char t = '\t'; + //static char t = '\t'; len = Fl_Text_Buffer::character_width("\t", indent, tabDist); if (len > 1 && indent + len <= toIndent) { *outPtr++ = '\t'; diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx index 25d509c97..54b56ee63 100644 --- a/src/Fl_Tree.cxx +++ b/src/Fl_Tree.cxx @@ -7,6 +7,7 @@ #include <string.h> #include <FL/Fl_Tree.H> +#include <FL/Fl_Preferences.H> #define SCROLL_W 15 @@ -426,6 +427,56 @@ int Fl_Tree::select_only(Fl_Tree_Item *selitem, int docallback) { return(changed); } +/** + * Read a preferences database into the tree widget. + * A preferences database is a hierarchical collection of data which can be + * directly loaded into the tree view for inspection. + * \param[in] prefs the Fl_Preferences database + */ +void Fl_Tree::load(Fl_Preferences &prefs) +{ + int i, j, n, pn = strlen(prefs.path()); + char *p; + const char *path = prefs.path(); + if (strcmp(path, ".")==0) + path += 1; // root path is empty + else + path += 2; // child path starts with "./" + n = prefs.groups(); + for (i=0; i<n; i++) { + Fl_Preferences prefsChild(prefs, i); + add(prefsChild.path()+2); // children always start with "./" + load(prefsChild); + } + n = prefs.entries(); + for (i=0; i<n; i++) { + // We must remove all fwd slashes in the key and value strings. Replace with backslash. + char *key = strdup(prefs.entry(i)); + int kn = strlen(key); + for (j=0; j<kn; j++) { + if (key[j]=='/') key[j]='\\'; + } + char *val; prefs.get(key, val, ""); + int vn = strlen(val); + for (j=0; j<vn; j++) { + if (val[j]=='/') val[j]='\\'; + } + if (vn<40) { + int sze = pn + strlen(key) + vn; + p = (char*)malloc(sze+5); + sprintf(p, "%s/%s = %s", path, key, val); + } else { + int sze = pn + strlen(key) + 40; + p = (char*)malloc(sze+5); + sprintf(p, "%s/%s = %.40s...", path, key, val); + } + add(p[0]=='/'?p+1:p); + free(p); + free(val); + free(key); + } +} + // // End of "$Id$". // diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx index 18a1cfac4..24f33cd2c 100644 --- a/src/Fl_Tree_Item.cxx +++ b/src/Fl_Tree_Item.cxx @@ -481,6 +481,11 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, int H = _labelsize; if(usericon() && H < usericon()->h()) H = usericon()->h(); H += prefs.linespacing() + fl_descent(); + // adjust horizontally if we draw no connecting lines + if ( is_root() && prefs.connectorstyle() == FL_TREE_CONNECTOR_NONE ) { + X -= prefs.openicon()->w(); + W += prefs.openicon()->w(); + } // Colors, fonts Fl_Color fg = _selected ? prefs.bgcolor() : _labelfgcolor; Fl_Color bg = _selected ? prefs.selectcolor() : _labelbgcolor; @@ -497,9 +502,9 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, int textw=0, texth=0; fl_measure(_label, textw, texth, 0); int textycenter = Y+(H/2); - int &icon_x = _collapse_xywh[0] = X-1; - int &icon_y = _collapse_xywh[1] = textycenter - (prefs.openicon()->h()/2); int &icon_w = _collapse_xywh[2] = prefs.openicon()->w(); + int &icon_x = _collapse_xywh[0] = X + (icon_w + prefs.connectorwidth())/2 - 3; + int &icon_y = _collapse_xywh[1] = textycenter - (prefs.openicon()->h()/2); _collapse_xywh[3] = prefs.openicon()->h(); // Horizontal connector values int hstartx = X+icon_w/2-1; @@ -514,7 +519,11 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, // Draw connectors if ( prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) { // Horiz connector between center of icon and text - draw_horizontal_connector(hstartx, hendx, textycenter, prefs); + // if this is root, the connector should not dangle in thin air on the left + if (is_root()) + draw_horizontal_connector(hcenterx, hendx, textycenter, prefs); + else + draw_horizontal_connector(hstartx, hendx, textycenter, prefs); if ( has_children() && is_open() ) { // Small vertical line down to children draw_vertical_connector(hcenterx, textycenter, Y+H, prefs); @@ -538,9 +547,11 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, } } // Background for this item - int &bx = _label_xywh[0] = X+(icon_w/2-1+prefs.connectorwidth()); + int cw1 = icon_w+prefs.connectorwidth()/2, cw2 = prefs.connectorwidth(); + int cwidth = cw1>cw2 ? cw1 : cw2; + int &bx = _label_xywh[0] = X+(icon_w/2-1+cwidth); int &by = _label_xywh[1] = Y; - int &bw = _label_xywh[2] = W-(icon_w/2-1+prefs.connectorwidth()); + int &bw = _label_xywh[2] = W-(icon_w/2-1+cwidth); int &bh = _label_xywh[3] = H; // Draw bg only if different from tree's bg if ( bg != tree->color() || is_selected() ) { @@ -554,7 +565,7 @@ void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, } } // Draw user icon (if any) - int useroff = (icon_w/2-1+prefs.connectorwidth()); + int useroff = (icon_w/2-1+cwidth); if ( usericon() ) { // Item has user icon? Use it useroff += prefs.usericonmarginleft(); diff --git a/src/Fl_Tree_Prefs.cxx b/src/Fl_Tree_Prefs.cxx index 4adee203d..04afda404 100644 --- a/src/Fl_Tree_Prefs.cxx +++ b/src/Fl_Tree_Prefs.cxx @@ -34,6 +34,22 @@ // These can be replaced via prefs.openicon()/closeicon() // static const char *L_open_xpm[] = { +#ifdef __APPLE__ + "11 11 2 1", + ". c None", + "@ c #000000", + "...@.......", + "...@@......", + "...@@@.....", + "...@@@@....", + "...@@@@@...", + "...@@@@@@..", + "...@@@@@...", + "...@@@@....", + "...@@@.....", + "...@@......", + "...@......." +#else "11 11 3 1", ". c #fefefe", "# c #444444", @@ -48,10 +64,28 @@ static const char *L_open_xpm[] = { "#....@....#", "#.........#", "#.........#", - "###########"}; + "###########" +#endif +}; static Fl_Pixmap L_openpixmap(L_open_xpm); static const char *L_close_xpm[] = { +#ifdef __APPLE__ + "11 11 2 1", + ". c None", + "@ c #000000", + "...........", + "...........", + "...........", + "...........", + "...........", + "@@@@@@@@@@@", + ".@@@@@@@@@.", + "..@@@@@@@..", + "...@@@@@...", + "....@@@....", + ".....@....." +#else "11 11 3 1", ". c #fefefe", "# c #444444", @@ -66,7 +100,9 @@ static const char *L_close_xpm[] = { "#.........#", "#.........#", "#.........#", - "###########"}; + "###########" +#endif +}; static Fl_Pixmap L_closepixmap(L_close_xpm); /// Sets the default icon to be used as the 'open' icon @@ -105,7 +141,11 @@ Fl_Tree_Prefs::Fl_Tree_Prefs() { _selectcolor = FL_DARK_BLUE; _inactivecolor = FL_GRAY; _connectorcolor = Fl_Color(43); +#ifdef __APPLE__ + _connectorstyle = FL_TREE_CONNECTOR_NONE; +#else _connectorstyle = FL_TREE_CONNECTOR_DOTTED; +#endif _openimage = &L_openpixmap; _closeimage = &L_closepixmap; _userimage = 0; |
