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

[STR New]

Link: http://www.fltk.org/str.php?L2757
Version: 1.3-feature


Attached file "browser-shortcut-items-2.patch"...


Link: http://www.fltk.org/str.php?L2757
Version: 1.3-feature
Index: FL/Fl_Browser_.H
===================================================================
--- FL/Fl_Browser_.H    (revision 9205)
+++ FL/Fl_Browser_.H    (working copy)
@@ -71,7 +71,10 @@
   void *redraw1,*redraw2; // minimal update pointers
   void* max_width_item;        // which item has max_width_
   int scrollbar_size_; // size of scrollbar trough
+  int flags_ex_;  // extended flags for class
 
+  static const int FLAG_EX_SHORTCUT=1;           // support shortcuts on 
browser items
+
   void update_top();
 
 protected:
@@ -360,6 +363,24 @@
   */
   void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); }
   void sort(int flags=0);
+  /**
+    enable/disable supporting shortcuts on browser items
+  */
+  void enable_item_shortcuts() { flags_ex_|=FLAG_EX_SHORTCUT; };
+  void disable_item_shortcuts() { flags_ex_&=~FLAG_EX_SHORTCUT; };
+  bool using_item_shortcuts() const { return (flags_ex_ & 
FLAG_EX_SHORTCUT)!=0; };
+
+  /**
+    change the way shortcuts are handled.  enabling alt shortcuts causes
+    the shortcut to work when the browser doesn't have focus and alt-key
+    combination is used.  if alt shortcuts are not enabled then the short
+    cuts only work within the browser when it has focus.  alt-key allows
+    selection outside the browser group.  Note that this has no affect
+    unless shortcuts are enabled.
+  */
+  void enable_alt_shortcuts() { flags_ex_|=FLAG_EX_SHORTCUT_ALT; };
+  void disable_alt_shortcuts() { flags_ex_&=~FLAG_EX_SHORTCUT_ALT; };
+  bool using_alt_shortcuts() const { return (flags_ex_ & 
FLAG_EX_SHORTCUT_ALT)!=0; };
 };
 
 #endif
Index: src/Fl_Browser.cxx
===================================================================
--- src/Fl_Browser.cxx  (revision 9205)
+++ src/Fl_Browser.cxx  (working copy)
@@ -583,7 +583,11 @@
       lcol = fl_contrast(lcol, selection_color());
     if (!active_r()) lcol = fl_inactive(lcol);
     fl_color(lcol);
+    if (using_item_shortcuts()) {
+      fl_draw_shortcut=1;
+    }
     fl_draw(str, X+3, Y, w1-6, H, e ? Fl_Align(talign|FL_ALIGN_CLIP) : talign, 
0, 0);
+    fl_draw_shortcut=0;
     if (!e) break; // no more fields...
     *e = column_char(); // put the separator back
     X += w1;
Index: src/Fl_Browser_.cxx
===================================================================
--- src/Fl_Browser_.cxx (revision 9205)
+++ src/Fl_Browser_.cxx (working copy)
@@ -704,6 +704,38 @@
 
   // must do shortcuts first or the scrollbar will get them...
   if (event == FL_ENTER || event == FL_LEAVE) return 1;
+
+  if (event == FL_SHORTCUT && using_item_shortcuts() && 
(Fl::event_state(FL_ALT)==0 || using_alt_shortcuts())) {
+    void* l = selection_;
+    if (!l) l = item_first();
+    void *li=l;
+    while (l) {
+      // check for shortcut key pressed
+      if (test_shortcut(item_text(l),  Fl::focus() != this)) {
+        // determine what type of selection to make
+        take_focus();
+        if (type()==FL_HOLD_BROWSER || type()==FL_CHECKBOX_BROWSER) {
+          select_only(l, when());
+          if (type()==FL_CHECKBOX_BROWSER) {
+            checked(l, -1);
+          }
+        }
+        else {
+          selection_ = l;
+          select(l, !item_selected(l), when() & ~FL_WHEN_ENTER_KEY);
+        }
+        return 1;
+      }
+      // next item
+      if ((l=item_next(l))==NULL) {
+        // wrap back to start of list
+        l=item_first();
+      }
+      // exit once back to starting point
+      if (l==li) break;
+    }
+  }
+  else
   if (event == FL_KEYBOARD && type() >= FL_HOLD_BROWSER) {
     void* l1 = selection_;
     void* l = l1; if (!l) l = top_; if (!l) l = item_first();
@@ -974,6 +1006,7 @@
   max_width_item = 0;
   scrollbar_size_ = 0;
   redraw1 = redraw2 = 0;
+  flags_ex_= 0;
   end();
 }
 
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to