diff options
| author | Fabien Costantini <fabien@onepost.net> | 2012-04-15 20:11:36 +0000 |
|---|---|---|
| committer | Fabien Costantini <fabien@onepost.net> | 2012-04-15 20:11:36 +0000 |
| commit | b31264e473d9475d80d7d4cf7964f2b0051bfcba (patch) | |
| tree | 9b8f8707323b980cd0254c7dba7c0562ed9cdfc9 | |
| parent | efe0b2b939a7135b957acd626e3877f2375d6d62 (diff) | |
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
| -rw-r--r-- | FL/Fl_Tree.H | 27 | ||||
| -rw-r--r-- | ide/Xcode3/FLTK.xcodeproj/project.pbxproj | 11 | ||||
| -rw-r--r-- | src/Fl_Tree.cxx | 33 | ||||
| -rw-r--r-- | test/tree.fl | 11 |
4 files changed, 69 insertions, 13 deletions
diff --git a/FL/Fl_Tree.H b/FL/Fl_Tree.H index 67278cca8..5b3591a95 100644 --- a/FL/Fl_Tree.H +++ b/FL/Fl_Tree.H @@ -186,11 +186,16 @@ enum Fl_Tree_Reason { FL_TREE_REASON_NONE=0, ///< unknown reason FL_TREE_REASON_SELECTED, ///< an item was 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_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 { Fl_Tree_Item *_root; // can be null! 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 // NEW: 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 // OLD: static data inside handle() method #endif @@ -280,7 +304,6 @@ public: void set_item_focus(Fl_Tree_Item *item); int is_selected(Fl_Tree_Item *item) const; int is_selected(const char *path); - ///////////////////////////////// // Item attribute related methods ///////////////////////////////// diff --git a/ide/Xcode3/FLTK.xcodeproj/project.pbxproj b/ide/Xcode3/FLTK.xcodeproj/project.pbxproj index ffcfa71f0..dfa1d4bb1 100644 --- a/ide/Xcode3/FLTK.xcodeproj/project.pbxproj +++ b/ide/Xcode3/FLTK.xcodeproj/project.pbxproj @@ -13066,10 +13066,16 @@ ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)"; ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "x86_64 i386 ppc"; 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_UNUSED_VARIABLE = YES; PREBINDING = NO; SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + VALID_ARCHS = "i386 x86_64"; }; name = Release; }; @@ -14154,14 +14160,15 @@ AC3226B9FE17327A0476ACA0 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; + ARCHS = "$(ONLY_ACTIVE_ARCH_PRE_XCODE_3_1)"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - ONLY_ACTIVE_ARCH = YES; + ONLY_ACTIVE_ARCH_PRE_XCODE_3_1 = "$(NATIVE_ARCH_ACTUAL)"; PREBINDING = NO; SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + VALID_ARCHS = "i386 x86_64"; }; name = Debug; }; diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx index 0635c7d05..08934ce03 100644 --- a/src/Fl_Tree.cxx +++ b/src/Fl_Tree.cxx @@ -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_reason = FL_TREE_REASON_NONE; _scrollbar_size = 0; // 0: uses Fl::scrollbar_size() - + #if FLTK_ABI_VERSION >= 10302 // NEW _lastselect = 0; + _itemReselectMode = FL_TREE_SELECTABLE_ONCE; #else // OLD: data initialized static inside handle() #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 if ( ! _root ) return(ret); 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)) { Fl::focus(this); } @@ -273,6 +275,7 @@ int Fl_Tree::handle(int e) { } else if ( o->event_on_label(_prefs) && // label clicked? (!o->widget() || !Fl::event_inside(o->widget())) && // not inside widget (!_vscroll->visible() || !Fl::event_inside(_vscroll)) ) { // not on scroller + switch ( _prefs.selectmode() ) { case FL_TREE_SELECT_NONE: break; @@ -995,13 +998,25 @@ int Fl_Tree::is_close(const char *path) const { /// - 0 - item was already selected, no change was made /// 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(); set_changed(); 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(0); @@ -1165,7 +1180,13 @@ int Fl_Tree::select_only(Fl_Tree_Item *selitem, int docallback) { int changed = 0; for ( Fl_Tree_Item *item = first(); item; item = item->next() ) { 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); ++changed; } else { diff --git a/test/tree.fl b/test/tree.fl index 003b1be07..8e6d90d34 100644 --- a/test/tree.fl +++ b/test/tree.fl @@ -45,6 +45,9 @@ Function {reason_as_name(Fl_Tree_Reason reason)} { case FL_TREE_REASON_DESELECTED: return("deselected"); case FL_TREE_REASON_OPENED: return("opened"); case FL_TREE_REASON_CLOSED: return("closed"); +\#if FLTK_ABI_VERSION >= 10302 + case FL_TREE_REASON_RESELECTED: return("reselected"); +\#endif default: return("???"); }} {} } @@ -221,7 +224,9 @@ Function {} {open label Tree user_data 1234 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(); if ( item ) { fprintf(stderr, "TREE CALLBACK: label='%s' userdata=%ld reason=%s\\n", @@ -231,7 +236,7 @@ if ( item ) { } else { fprintf(stderr, "TREE CALLBACK: reason=%s item=(no item -- probably multiple items were changed at once)\\n", 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 class Fl_Tree } {} @@ -1165,7 +1170,7 @@ while (item) { } 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 } } |
