DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2763
Version: 1.3-feature
This patch adds an option to FL_HOLD_BROWSER (and FL_CHECKBOX_BROWSER if
STR2756 is applied) type Browser widgets that allows the selection bar to
be moved when using pgup, pgdn, home, and end keys as is normally
expected. This is consistent with Windows and most other GUI's.
Link: http://www.fltk.org/str.php?L2763
Version: 1.3-feature
Index: FL/Fl_Browser_.H
===================================================================
--- FL/Fl_Browser_.H (revision 9166)
+++ FL/Fl_Browser_.H (working copy)
@@ -71,7 +71,13 @@
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_FULL_KB_SELECT=8; // change selection bar on
pgup/pgdn/home/end
+
void update_top();
protected:
@@ -360,6 +366,15 @@
*/
void scrollbar_left() { scrollbar.align(FL_ALIGN_LEFT); }
void sort(int flags=0);
+
+ /**
+ enable or disable support for changing selection bar when keyboard
+ pgup/pgdn/home/end are used.
+ */
+ void enable_full_kb_select() { flags_ex_|=FLAG_EX_FULL_KB_SELECT; };
+ void disable_full_kb_select() { flags_ex_&=~FLAG_EX_FULL_KB_SELECT; };
+ bool using_full_kb_select() { return (flags_ex_ &
FLAG_EX_FULL_KB_SELECT)!=0; };
+
};
#endif
Index: src/Fl_Browser_.cxx
===================================================================
--- src/Fl_Browser_.cxx (revision 9166)
+++ src/Fl_Browser_.cxx (working copy)
@@ -704,6 +704,7 @@
// must do shortcuts first or the scrollbar will get them...
if (event == FL_ENTER || event == FL_LEAVE) return 1;
+ int X, Y, W, H; bbox(X, Y, W, H);
if (event == FL_KEYBOARD && type() >= FL_HOLD_BROWSER) {
void* l1 = selection_;
void* l = l1; if (!l) l = top_; if (!l) l = item_first();
@@ -722,7 +723,54 @@
}
}
return 1;
+ // check if class should handle moving selection bar when
+ // using the keyboard for home/end/pgup/pgdn.
+ if (using_full_kb_select() && item_first()!=NULL) {
+ switch (Fl::event_key()) {
+ case FL_Home:
+ if (selection_!=item_first()) {
+ select_only(item_first(), when());
+ }
+ // allow scrollbar to adjust
+ break;
+ case FL_End:
+ for (void *nl;(nl=item_next(l));l=nl);
+ if (selection_!=l) {
+ select_only(l, when());
+ }
+ // allow scrollbar to adjust
+ break;
+ case FL_Page_Down:
+ case FL_Page_Up:
+ // figure out entries per box (assumes all items are same height)
+ int itemheight=item_height(item_first());
+ int linesperbox=(H+itemheight-1)/itemheight;
+ // adjust one less for proper paging
+ // (first(pgup)/last(pgdn) item of previous page becomes
last(pgup)/first(pgdn) item)
+ linesperbox--;
+ // determine if we prevent scrollbar from getting key press
+ bool eatkey=!displayed(l);
+ // find the line to highlight
+ while (linesperbox>0) {
+ void *nl=(Fl::event_key()==FL_Page_Down) ? item_next(l) :
item_prev(l);
+ if (!nl) break;
+ l=nl;
+ if (item_height(l)>0) {
+ linesperbox--;
+ }
+ }
+ if (selection_!=l) {
+ select_only(l, when());
+ }
+ // abort if we had to bring this selection into view
+ if (eatkey) {
+ return 1;
+ }
+ // allow scrollbar to adjust
+ break;
+ }
}
+
} else {
switch (Fl::event_key()) {
case FL_Enter:
@@ -767,7 +815,6 @@
if (Fl_Group::handle(event)) return 1;
if (wp.deleted()) return 1;
- int X, Y, W, H; bbox(X, Y, W, H);
int my;
// NOTE:
// instead of:
@@ -974,6 +1021,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