STR 2827 implementation. Implemented Reselect code and related API all within ABI controlled preprocessor blocks because of new attribute defintion would break ABI anyway. Because the code is already ABI controlled, I took the opportunity to keep keep the REASON enum sorted. Added test code in Tree.fl adequately.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9347 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Fabien Costantini
2012-04-15 20:11:36 +00:00
parent efe0b2b939
commit b31264e473
4 changed files with 69 additions and 13 deletions
+25 -2
View File
@@ -186,11 +186,16 @@ enum Fl_Tree_Reason {
FL_TREE_REASON_NONE=0, ///< unknown reason FL_TREE_REASON_NONE=0, ///< unknown reason
FL_TREE_REASON_SELECTED, ///< an item was selected FL_TREE_REASON_SELECTED, ///< an item was selected
FL_TREE_REASON_DESELECTED, ///< an item was de-selected FL_TREE_REASON_DESELECTED, ///< an item was de-selected
#if FLTK_ABI_VERSION >= 10302
FL_TREE_REASON_RESELECTED, ///< an item was re-selected
#endif
FL_TREE_REASON_OPENED, ///< an item was opened FL_TREE_REASON_OPENED, ///< an item was opened
FL_TREE_REASON_CLOSED ///< an item was closed FL_TREE_REASON_CLOSED ///< an item was closed
}; };
/// \enum Fl_Tree_Item_Select_Mode
/// Defines the ways an item can be (re) selected.
///
class FL_EXPORT Fl_Tree : public Fl_Group { class FL_EXPORT Fl_Tree : public Fl_Group {
Fl_Tree_Item *_root; // can be null! Fl_Tree_Item *_root; // can be null!
Fl_Tree_Item *_item_focus; // item that has focus box Fl_Tree_Item *_item_focus; // item that has focus box
@@ -202,6 +207,25 @@ class FL_EXPORT Fl_Tree : public Fl_Group {
#if FLTK_ABI_VERSION >= 10302 #if FLTK_ABI_VERSION >= 10302
// NEW: // NEW:
Fl_Tree_Item *_lastselect; Fl_Tree_Item *_lastselect;
// NEW:
public:
enum Fl_Tree_Item_Reselect_Mode
{
FL_TREE_SELECTABLE_ONCE=0, /// backward compatible default: an item can only be selected once
FL_TREE_SELECTABLE_ALWAYS, /// needed for new RESELECT feature
};
//! Returns the current item re/selection mode
Fl_Tree_Item_Reselect_Mode item_reselect_mode() const {
return _itemReselectMode;
}
//! Sets the item re/selection mode
void item_reselect_mode(Fl_Tree_Item_Reselect_Mode mode) {
_itemReselectMode = mode;
}
private:
Fl_Tree_Item_Reselect_Mode _itemReselectMode;
#else #else
// OLD: static data inside handle() method // OLD: static data inside handle() method
#endif #endif
@@ -280,7 +304,6 @@ public:
void set_item_focus(Fl_Tree_Item *item); void set_item_focus(Fl_Tree_Item *item);
int is_selected(Fl_Tree_Item *item) const; int is_selected(Fl_Tree_Item *item) const;
int is_selected(const char *path); int is_selected(const char *path);
///////////////////////////////// /////////////////////////////////
// Item attribute related methods // Item attribute related methods
///////////////////////////////// /////////////////////////////////
+9 -2
View File
@@ -13066,10 +13066,16 @@
ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)"; ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)";
ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "x86_64 i386 ppc"; ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "x86_64 i386 ppc";
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_SSE41_EXTENSIONS = NO;
GCC_ENABLE_SSE42_EXTENSIONS = YES;
GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 3;
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO; PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
VALID_ARCHS = "i386 x86_64";
}; };
name = Release; name = Release;
}; };
@@ -14154,14 +14160,15 @@
AC3226B9FE17327A0476ACA0 /* Debug */ = { AC3226B9FE17327A0476ACA0 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ARCHS = "$(NATIVE_ARCH_ACTUAL)"; ARCHS = "$(ONLY_ACTIVE_ARCH_PRE_XCODE_3_1)";
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH_PRE_XCODE_3_1 = "$(NATIVE_ARCH_ACTUAL)";
PREBINDING = NO; PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
VALID_ARCHS = "i386 x86_64";
}; };
name = Debug; name = Debug;
}; };
+27 -6
View File
@@ -98,10 +98,11 @@ Fl_Tree::Fl_Tree(int X, int Y, int W, int H, const char *L) : Fl_Group(X,Y,W,H,L
_callback_item = 0; _callback_item = 0;
_callback_reason = FL_TREE_REASON_NONE; _callback_reason = FL_TREE_REASON_NONE;
_scrollbar_size = 0; // 0: uses Fl::scrollbar_size() _scrollbar_size = 0; // 0: uses Fl::scrollbar_size()
#if FLTK_ABI_VERSION >= 10302 #if FLTK_ABI_VERSION >= 10302
// NEW // NEW
_lastselect = 0; _lastselect = 0;
_itemReselectMode = FL_TREE_SELECTABLE_ONCE;
#else #else
// OLD: data initialized static inside handle() // OLD: data initialized static inside handle()
#endif #endif
@@ -257,7 +258,8 @@ int Fl_Tree::handle(int e) {
// fprintf(stderr, "ERCODEBUG: Fl_Tree::handle(): Event was %s (%d)\n", fl_eventnames[e], e); // DEBUGGING // fprintf(stderr, "ERCODEBUG: Fl_Tree::handle(): Event was %s (%d)\n", fl_eventnames[e], e); // DEBUGGING
if ( ! _root ) return(ret); if ( ! _root ) return(ret);
switch ( e ) { switch ( e ) {
case FL_PUSH: { // clicked on a tree item? case FL_PUSH: {
// clicked on a tree item?
if (Fl::visible_focus() && handle(FL_FOCUS)) { if (Fl::visible_focus() && handle(FL_FOCUS)) {
Fl::focus(this); Fl::focus(this);
} }
@@ -273,6 +275,7 @@ int Fl_Tree::handle(int e) {
} else if ( o->event_on_label(_prefs) && // label clicked? } else if ( o->event_on_label(_prefs) && // label clicked?
(!o->widget() || !Fl::event_inside(o->widget())) && // not inside widget (!o->widget() || !Fl::event_inside(o->widget())) && // not inside widget
(!_vscroll->visible() || !Fl::event_inside(_vscroll)) ) { // not on scroller (!_vscroll->visible() || !Fl::event_inside(_vscroll)) ) { // not on scroller
switch ( _prefs.selectmode() ) { switch ( _prefs.selectmode() ) {
case FL_TREE_SELECT_NONE: case FL_TREE_SELECT_NONE:
break; break;
@@ -995,13 +998,25 @@ int Fl_Tree::is_close(const char *path) const {
/// - 0 - item was already selected, no change was made /// - 0 - item was already selected, no change was made
/// ///
int Fl_Tree::select(Fl_Tree_Item *item, int docallback) { int Fl_Tree::select(Fl_Tree_Item *item, int docallback) {
if ( ! item->is_selected() ) { int alreadySelected = item->is_selected();
if ( !alreadySelected
#if FLTK_ABI_VERSION >= 10302
|| item_reselect_mode()==FL_TREE_SELECTABLE_ALWAYS
#endif
) {
item->select(); item->select();
set_changed(); set_changed();
if ( docallback ) { if ( docallback ) {
do_callback_for_item(item, FL_TREE_REASON_SELECTED); do_callback_for_item(item,
#if FLTK_ABI_VERSION >= 10302
alreadySelected ? FL_TREE_REASON_RESELECTED :FL_TREE_REASON_SELECTED);
#else
FL_TREE_REASON_SELECTED);
#endif
} }
redraw();
redraw();
return(1); return(1);
} }
return(0); return(0);
@@ -1165,7 +1180,13 @@ int Fl_Tree::select_only(Fl_Tree_Item *selitem, int docallback) {
int changed = 0; int changed = 0;
for ( Fl_Tree_Item *item = first(); item; item = item->next() ) { for ( Fl_Tree_Item *item = first(); item; item = item->next() ) {
if ( item == selitem ) { if ( item == selitem ) {
if ( item->is_selected() ) continue; // don't count if already selected if ( item->is_selected()
#if FLTK_ABI_VERSION >= 10302
&& item_reselect_mode()!=FL_TREE_SELECTABLE_ALWAYS
#endif
) continue; // don't count if already selected
select(item, docallback); select(item, docallback);
++changed; ++changed;
} else { } else {
+8 -3
View File
@@ -45,6 +45,9 @@ Function {reason_as_name(Fl_Tree_Reason reason)} {
case FL_TREE_REASON_DESELECTED: return("deselected"); case FL_TREE_REASON_DESELECTED: return("deselected");
case FL_TREE_REASON_OPENED: return("opened"); case FL_TREE_REASON_OPENED: return("opened");
case FL_TREE_REASON_CLOSED: return("closed"); case FL_TREE_REASON_CLOSED: return("closed");
\#if FLTK_ABI_VERSION >= 10302
case FL_TREE_REASON_RESELECTED: return("reselected");
\#endif
default: return("???"); default: return("???");
}} {} }} {}
} }
@@ -221,7 +224,9 @@ Function {} {open
label Tree label Tree
user_data 1234 user_data 1234
callback {G_cb_counter++; // Increment callback counter whenever tree callback is invoked callback {G_cb_counter++; // Increment callback counter whenever tree callback is invoked
\#if FLTK_ABI_VERSION >= 10302
tree->item_reselect_mode(Fl_Tree::FL_TREE_SELECTABLE_ALWAYS);
\#endif
Fl_Tree_Item *item = tree->callback_item(); Fl_Tree_Item *item = tree->callback_item();
if ( item ) { if ( item ) {
fprintf(stderr, "TREE CALLBACK: label='%s' userdata=%ld reason=%s\\n", fprintf(stderr, "TREE CALLBACK: label='%s' userdata=%ld reason=%s\\n",
@@ -231,7 +236,7 @@ if ( item ) {
} else { } else {
fprintf(stderr, "TREE CALLBACK: reason=%s item=(no item -- probably multiple items were changed at once)\\n", fprintf(stderr, "TREE CALLBACK: reason=%s item=(no item -- probably multiple items were changed at once)\\n",
reason_as_name(tree->callback_reason())); reason_as_name(tree->callback_reason()));
}} open }} open selected
tooltip {Test tree} xywh {15 22 280 411} box DOWN_BOX color 55 selection_color 15 tooltip {Test tree} xywh {15 22 280 411} box DOWN_BOX color 55 selection_color 15
class Fl_Tree class Fl_Tree
} {} } {}
@@ -1165,7 +1170,7 @@ while (item) {
} }
item = item->next(); item = item->next();
} }
tree->redraw();} selected tree->redraw();}
tooltip {Adds 20,000 items to the selected item's parent} xywh {530 398 95 16} labelsize 9 tooltip {Adds 20,000 items to the selected item's parent} xywh {530 398 95 16} labelsize 9
} }
} }