DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L1739
Version: 1.2-feature


Please add support for setting icons per Fl_Browser rows.

Note that the included patch adds total of 47 lines to Fl_Browser.H and
Fl_Browser.cxx and doesn't usurp the data field. It adds three methods:
  void icon(int line, Fl_Image* icon);
  Fl_Image* icon(int line);
  void remove_icon(int line);


Link: http://www.fltk.org/str.php?L1739
Version: 1.2-feature
diff -Naur fltk-1.1/FL/Fl_Browser.H fltk-work/FL/Fl_Browser.H
--- fltk-1.1/FL/Fl_Browser.H    2007-06-22 12:26:30.000000000 +0200
+++ fltk-work/FL/Fl_Browser.H   2007-07-18 11:36:34.000000000 +0200
@@ -33,6 +33,7 @@
 #define Fl_Browser_H
 
 #include "Fl_Browser_.H"
+#include "Fl_Image.H"
 
 struct FL_BLINE;
 
@@ -123,6 +124,11 @@
   // for back compatability only:
   void replace(int a, const char* b) {text(a, b);}
   void display(int, int=1);
+
+  // icon support
+  void icon(int line, Fl_Image* icon);
+  Fl_Image* icon(int line);
+  void remove_icon(int line);
 };
 
 #endif
diff -Naur fltk-1.1/src/Fl_Browser.cxx fltk-work/src/Fl_Browser.cxx
--- fltk-1.1/src/Fl_Browser.cxx 2007-06-22 12:26:20.000000000 +0200
+++ fltk-work/src/Fl_Browser.cxx        2007-07-18 11:45:57.000000000 +0200
@@ -49,6 +49,7 @@
   FL_BLINE* prev;
   FL_BLINE* next;
   void* data;
+  Fl_Image* icon;
   short length;                // sizeof(txt)-1, may be longer than string
   char flags;          // selected, displayed
   char txt[1];         // start of allocated array
@@ -170,6 +171,7 @@
   t->flags = 0;
   strcpy(t->txt, newtext);
   t->data = d;
+  t->icon = 0;
   insert(line, t);
 }
 
@@ -189,6 +191,7 @@
     n->data = t->data;
     n->length = (short)l;
     n->flags = t->flags;
+    n->icon = t->icon;
     n->prev = t->prev;
     if (n->prev) n->prev->next = n; else first = n;
     n->next = t->next;
@@ -252,6 +255,8 @@
     }
   }
 
+  if (l->icon && (l->icon->h()+2)>hmax) hmax=l->icon->h()+2; // leave 2px 
above/below
+
   return hmax; // previous version returned hmax+2!
 }
 
@@ -301,6 +306,9 @@
   if (*str == format_char_ && str[1])
     str ++;
 
+  FL_BLINE* l = (FL_BLINE*)v;
+  if (ww==0 && l->icon) ww = l->icon->w();
+
   fl_font(font, tsize);
   return ww + int(fl_width(str)) + 6;
 }
@@ -316,6 +324,8 @@
 void Fl_Browser::item_draw(void* v, int X, int Y, int W, int H) const {
   char* str = ((FL_BLINE*)v)->txt;
   const int* i = column_widths();
+  bool first=true; // for icon
+  FL_BLINE*l = (FL_BLINE*)v; 
 
   while (W > 6) {      // do each tab-seperated field
     int w1 = W;        // width for this field
@@ -324,6 +334,17 @@
       e = strchr(str, column_char());
       if (e) {*e = 0; w1 = *i++;}
     }
+
+    // Icon drawing code
+    if (first) {
+       first=false;
+       if (l->icon != 0) {
+          l->icon->draw(X+2,Y+1); // leave 2px left, 1px above
+          int iconw = l->icon->w() + 2; 
+          X += iconw; W -= iconw; w1 -= iconw;
+       }
+    }
+
     int tsize = textsize();
     Fl_Font font = textfont();
     Fl_Color lcol = textcolor();
@@ -546,6 +567,31 @@
   swap(a,b);
 }
 
+void Fl_Browser::icon(int line, Fl_Image* icon) {
+       if (icon && line>0 && line<=lines) {
+               // update full_height_
+               FL_BLINE* bl = find_line(line);
+               int dh = icon->h() - item_height(bl) + 2; // leave 2px 
above/below
+               if (dh>0) full_height_ += dh; 
+               bl->icon=icon;
+               redraw_line(bl); 
+       }
+       if (icon==0) remove_icon(line);
+}
+Fl_Image* Fl_Browser::icon(int line) { return find_line(line)->icon; }
+void Fl_Browser::remove_icon(int line) { 
+       if (line>0 && line<=lines) {
+               FL_BLINE* bl = find_line(line);
+               if (!bl->icon) return;
+               int dh = bl->icon->h()+2; // leave 2px above/below
+               bl->icon=0; 
+               redraw_line(bl); 
+               // update_full_height_
+               dh -= item_height(bl);
+               if (dh>0) full_height_ -= dh; 
+       }
+}
+
 //
 // End of "$Id: Fl_Browser.cxx 5190 2006-06-09 16:16:34Z mike $".
 //
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to