summaryrefslogtreecommitdiff
path: root/src/Fl_Tabs.cxx
diff options
context:
space:
mode:
authorBill Spitzak <spitzak@gmail.com>1999-10-15 09:01:48 +0000
committerBill Spitzak <spitzak@gmail.com>1999-10-15 09:01:48 +0000
commita7904da09a890a8b6b2bbfc11a4a32308dc82023 (patch)
treec35977269fbb9eca44f8b65f346aa243db06ceb9 /src/Fl_Tabs.cxx
parentb9c69353729de435757ed4d843499c983899092f (diff)
I fixed Fl_Tabs so that child tabs can be added/removed without any
concern if they are selected, it uses the first visible() child to indicate the selected tab. Fixed up rather bogus fix for selecting entire text field when you click on it. This new version does not do it for multi-line and does not mess up the middle-mouse paste action. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@777 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Tabs.cxx')
-rw-r--r--src/Fl_Tabs.cxx74
1 files changed, 42 insertions, 32 deletions
diff --git a/src/Fl_Tabs.cxx b/src/Fl_Tabs.cxx
index 465f9dbd6..43355c84b 100644
--- a/src/Fl_Tabs.cxx
+++ b/src/Fl_Tabs.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Tabs.cxx,v 1.6.2.2 1999/07/22 07:27:11 bill Exp $"
+// "$Id: Fl_Tabs.cxx,v 1.6.2.3 1999/10/15 09:01:45 bill Exp $"
//
// Tab widget for the Fast Light Tool Kit (FLTK).
//
@@ -43,13 +43,13 @@
// Return value is the index of the selected item.
int Fl_Tabs::tab_positions(int* p, int* w) {
- int selected = 0;
+ int selected = -1;
Fl_Widget*const* a = array();
int i;
p[0] = 0;
for (i=0; i<children(); i++) {
Fl_Widget* o = *a++;
- if (o == value_) selected = i;
+ if (o->visible()) selected = i;
if (o->label()) {
int wt = 0; int ht = 0; o->measure_label(wt,ht);
w[i] = wt+TABSLOPE;
@@ -144,7 +144,6 @@ int Fl_Tabs::handle(int event) {
default:
DEFAULT:
- value(); // initialize value & visibility if value_ == 0
return Fl_Group::handle(event);
}
@@ -152,35 +151,41 @@ int Fl_Tabs::handle(int event) {
int Fl_Tabs::push(Fl_Widget *o) {
if (push_ == o) return 0;
- if (push_ && push_ != value_ || o && o != value_) damage(FL_DAMAGE_EXPOSE);
+ if (push_ && !push_->visible() || o && !o->visible())
+ damage(FL_DAMAGE_EXPOSE);
push_ = o;
return 1;
}
+// The value() is the first visible child (or the last child if none
+// are visible) and this also hides any other children.
+// This allows the tabs to be deleted, moved to other groups, and
+// show()/hide() called without it screwing up.
Fl_Widget* Fl_Tabs::value() {
- Fl_Widget *v = value_;
- if (!v) {
- // If value() has not been called, find first visible() child:
- Fl_Widget*const* a = array();
- for (int i=children(); i--;) {
- Fl_Widget* o = *a++;
- if (v) o->hide();
- else if (o->visible()) v = o;
- }
- if (!v) return 0; // no children...
- value_ = v;
+ Fl_Widget* v = 0;
+ Fl_Widget*const* a = array();
+ for (int i=children(); i--;) {
+ Fl_Widget* o = *a++;
+ if (v) o->hide();
+ else if (o->visible()) v = o;
+ else if (!i) {o->show(); v = o;}
}
return v;
}
-int Fl_Tabs::value(Fl_Widget *o) {
- if (value_ == o) return 0;
- Fl_Widget* oldvalue = value_;
- value_ = o;
- if (o) o->show();
- if (oldvalue) oldvalue->hide();
- redraw();
- do_callback();
+// Setting the value hides all other children, and makes this one
+// visible, iff it is really a child:
+int Fl_Tabs::value(Fl_Widget *newvalue) {
+ Fl_Widget*const* a = array();
+ for (int i=children(); i--;) {
+ Fl_Widget* o = *a++;
+ if (o == newvalue) {
+ if (o->visible()) return 0; // no change
+ o->show();
+ } else {
+ o->hide();
+ }
+ }
return 1;
}
@@ -197,8 +202,6 @@ void Fl_Tabs::draw() {
} else { // redraw the child
if (v) update_child(*v);
}
- if (!v) return;
-
if (damage() & (FL_DAMAGE_EXPOSE|FL_DAMAGE_ALL)) {
int p[128]; int w[128];
int selected = tab_positions(p,w);
@@ -208,8 +211,14 @@ void Fl_Tabs::draw() {
draw_tab(x()+p[i], x()+p[i+1], w[i], H, a[i], LEFT);
for (i=children()-1; i > selected; i--)
draw_tab(x()+p[i], x()+p[i+1], w[i], H, a[i], RIGHT);
- i = selected;
- draw_tab(x()+p[i], x()+p[i+1], w[i], H, a[i], SELECTED);
+ if (v) {
+ i = selected;
+ draw_tab(x()+p[i], x()+p[i+1], w[i], H, a[i], SELECTED);
+ } else {
+ // draw the edge when no selection:
+ fl_color(H >= 0 ? FL_LIGHT3 : FL_DARK3);
+ fl_xyline(x(), H >= 0 ? y()+H : y()+h()+H, x()+this->w());
+ }
}
}
@@ -255,11 +264,12 @@ void Fl_Tabs::draw_tab(int x1, int x2, int W, int H, Fl_Widget* o, int what) {
}
Fl_Tabs::Fl_Tabs(int X,int Y,int W, int H, const char *l) :
- Fl_Group(X,Y,W,H,l) {
- box(FL_THIN_UP_BOX);
- value_ = push_ = 0;
+ Fl_Group(X,Y,W,H,l)
+{
+ box(FL_THIN_UP_BOX);
+ push_ = 0;
}
//
-// End of "$Id: Fl_Tabs.cxx,v 1.6.2.2 1999/07/22 07:27:11 bill Exp $".
+// End of "$Id: Fl_Tabs.cxx,v 1.6.2.3 1999/10/15 09:01:45 bill Exp $".
//