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
This commit is contained in:
Bill Spitzak 1999-10-15 09:01:48 +00:00
parent b9c6935372
commit a7904da09a
4 changed files with 84 additions and 65 deletions

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Input.cxx,v 1.10.2.2 1999/10/14 04:56:08 bill Exp $"
// "$Id: Fl_Input.cxx,v 1.10.2.3 1999/10/15 09:01:43 bill Exp $"
//
// Input widget for the Fast Light Tool Kit (FLTK).
//
@ -279,6 +279,8 @@ int Fl_Input::handle_key() {
}
int Fl_Input::handle(int event) {
static char first_click;
switch (event) {
case FL_FOCUS:
@ -311,27 +313,31 @@ int Fl_Input::handle(int event) {
case FL_PUSH:
compose = 0;
if (Fl::event_button() == 2) {
Fl::paste(*this);
#ifndef MOTIF // use -DMOTIF for Motif rather than Win32+Motif hybrid
if (Fl::focus()==this) return 1;
#endif
}
first_click = 0;
if (Fl::focus() != this) {
Fl::focus(this);
handle(FL_FOCUS); // cause minimal update
#ifndef MOTIF
position(size(),0); // select everything
Fl::event_is_click(0); // prevents next click from doing word-select
return 1;
#endif
handle(FL_FOCUS);
// Windoze-style: select everything on first click:
if (type() != FL_MULTILINE_INPUT) {
first_click = 1;
position(size(), 0); // select everything
Fl::event_is_click(0); // prevents next click from being a double click
return 1;
}
}
// don't remove selection when pasting in a replacement:
if (Fl::event_button() == 2 && mark() != position()) return 1;
break;
case FL_DRAG:
case FL_RELEASE:
if (Fl::event_button() == 2) return 0;
break;
if (Fl::event_button() == 2) {
Fl::event_is_click(0); // stop double click from picking a word
Fl::paste(*this);
} else if (!first_click) {
copy();
}
return 1;
}
Fl_Boxtype b = box();
return Fl_Input_::handletext(event,
@ -344,5 +350,5 @@ Fl_Input::Fl_Input(int x, int y, int w, int h, const char *l)
}
//
// End of "$Id: Fl_Input.cxx,v 1.10.2.2 1999/10/14 04:56:08 bill Exp $".
// End of "$Id: Fl_Input.cxx,v 1.10.2.3 1999/10/15 09:01:43 bill Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Input_.cxx,v 1.21 1999/03/04 18:09:18 mike Exp $"
// "$Id: Fl_Input_.cxx,v 1.21.2.1 1999/10/15 09:01:44 bill Exp $"
//
// Common input widget routines for the Fast Light Tool Kit (FLTK).
//
@ -170,7 +170,7 @@ void Fl_Input_::drawtext(int X, int Y, int W, int H) {
}
int selstart, selend;
if (Fl::focus()!=this && Fl::selection_owner()!=this && Fl::pushed()!=this)
if (Fl::focus()!=this && /*Fl::selection_owner()!=this &&*/ Fl::pushed()!=this)
selstart = selend = 0;
else if (position() <= mark()) {
selstart = position(); selend = mark();
@ -352,14 +352,18 @@ void Fl_Input_::handle_mouse(int X, int Y,
p = e;
if (e >= value_+size_) break;
}
const char *l, *r, *t;
const char *l, *r, *t; double f0 = 0;
for (l = p, r = e; l<r; ) {
double f;
t = l+(r-l+1)/2;
f = X-xscroll_+expandpos(p, t, buf, 0);
if (f <= Fl::event_x()) l = t;
if (f <= Fl::event_x()) {l = t; f0 = Fl::event_x()-f;}
else r = t-1;
}
if (l < e) { // see if closer to character on right:
double f1 = X-xscroll_+expandpos(p, l+1, buf, 0)-Fl::event_x();
if (f1 < f0) l = l+1;
}
newpos = l-value();
int newmark = drag ? mark() : newpos;
@ -394,7 +398,7 @@ int Fl_Input_::position(int p, int m) {
if (m<0) m = 0;
if (m>size()) m = size();
if (p == position_ && m == mark_) return 0;
if (Fl::selection_owner() == this) Fl::selection_owner(0);
//if (Fl::selection_owner() == this) Fl::selection_owner(0);
if (p != m) {
if (p != position_) minimal_update(position_, p);
if (m != mark_) minimal_update(mark_, m);
@ -590,16 +594,15 @@ int Fl_Input_::handletext(int event, int X, int Y, int W, int H) {
case FL_FOCUS:
if (mark_ == position_) {
minimal_update(size()+1);
} else if (Fl::selection_owner() != this)
} else //if (Fl::selection_owner() != this)
minimal_update(mark_, position_);
return 1;
case FL_UNFOCUS:
if (mark_ == position_) {
if (!(damage()&FL_DAMAGE_EXPOSE)) {minimal_update(position_); erase_cursor_only = 1;}
} else if (Fl::selection_owner() != this) {
} else //if (Fl::selection_owner() != this)
minimal_update(mark_, position_);
}
if (when() & FL_WHEN_RELEASE) maybe_do_callback();
return 1;
@ -616,10 +619,10 @@ int Fl_Input_::handletext(int event, int X, int Y, int W, int H) {
copy();
return 1;
case FL_SELECTIONCLEAR:
minimal_update(mark_, position_);
mark_ = position_;
return 1;
// case FL_SELECTIONCLEAR:
// minimal_update(mark_, position_);
// mark_ = position_;
// return 1;
case FL_PASTE: {
// strip trailing control characters and spaces before pasting:
@ -734,5 +737,5 @@ Fl_Input_::~Fl_Input_() {
}
//
// End of "$Id: Fl_Input_.cxx,v 1.21 1999/03/04 18:09:18 mike Exp $".
// End of "$Id: Fl_Input_.cxx,v 1.21.2.1 1999/10/15 09:01:44 bill Exp $".
//

View File

@ -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 $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: shape.cxx,v 1.5 1999/01/13 15:45:50 mike Exp $"
// "$Id: shape.cxx,v 1.5.2.1 1999/10/15 09:01:48 bill Exp $"
//
// Tiny OpenGL demo program for the Fast Light Tool Kit (FLTK).
//
@ -52,7 +52,7 @@ void shape_window::draw() {
if (!valid()) {
valid(1);
glLoadIdentity();
glViewport(0,0,w(),h());
glViewport(0, 0, w(), h());
}
// draw an amazing graphic:
glClear(GL_COLOR_BUFFER_BIT);
@ -111,5 +111,5 @@ int main(int argc, char **argv) {
}
//
// End of "$Id: shape.cxx,v 1.5 1999/01/13 15:45:50 mike Exp $".
// End of "$Id: shape.cxx,v 1.5.2.1 1999/10/15 09:01:48 bill Exp $".
//