From 57cef6a4bde017e205e54271e769de0db596d893 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 23 Jul 2002 15:07:33 +0000 Subject: [PATCH] Remove extra 3 pixel offset when the size is below a certain amount; instead, use a constant +1 offset. Add another bit to flags_, VISIBLE_FOCUS, which provides per-widget keyboard focus control. The default is for all widgets to participate in keyboard focus navigation. Use the set_visible_focus(), clear_visible_focus(), and visible_focus() methods on Fl_Widget to control this. Clean up the Fl_Widget documentation and add missing stuff. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2543 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 3 + FL/Fl_Widget.H | 11 +- documentation/Fl_Widget.html | 564 ++++++++++++++++++++--------------- src/Fl.cxx | 5 +- src/Fl_Input_.cxx | 6 +- src/Fl_Widget.cxx | 7 +- 6 files changed, 340 insertions(+), 256 deletions(-) diff --git a/CHANGES b/CHANGES index 5de6d919a..d42636a01 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ CHANGES IN FLTK 1.1.0rc5 + - Added new visible focus flag bit and methods to + Fl_Widget, so it is now possible to do both global and + per-widget keyboard focus control. - Removed extra 3 pixel border around input fields. - No longer quote characters from 0x80 to 0x9f in input fields. diff --git a/FL/Fl_Widget.H b/FL/Fl_Widget.H index 958879364..a51bd7143 100644 --- a/FL/Fl_Widget.H +++ b/FL/Fl_Widget.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Widget.H,v 1.6.2.4.2.14 2002/05/13 05:05:11 spitzak Exp $" +// "$Id: Fl_Widget.H,v 1.6.2.4.2.15 2002/07/23 15:07:32 easysw Exp $" // // Widget header file for the Fast Light Tool Kit (FLTK). // @@ -85,7 +85,8 @@ protected: int flags() const {return flags_;} void set_flag(int c) {flags_ |= c;} void clear_flag(int c) {flags_ &= ~c;} - enum {INACTIVE=1, INVISIBLE=2, OUTPUT=4, SHORTCUT_LABEL=64, CHANGED=128}; + enum {INACTIVE=1, INVISIBLE=2, OUTPUT=4, SHORTCUT_LABEL=64, + CHANGED=128, VISIBLE_FOCUS=512}; FL_EXPORT void draw_box() const; FL_EXPORT void draw_box(Fl_Boxtype, Fl_Color) const; @@ -174,6 +175,10 @@ public: void set_changed() {flags_ |= CHANGED;} void clear_changed() {flags_ &= ~CHANGED;} FL_EXPORT int take_focus(); + void set_visible_focus() { flags_ |= VISIBLE_FOCUS; } + void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; } + void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); } + int visible_focus() { return flags_ & VISIBLE_FOCUS; } FL_EXPORT static void default_callback(Fl_Widget*, void*); void do_callback() {callback_(this,user_data_);} @@ -207,5 +212,5 @@ public: #endif // -// End of "$Id: Fl_Widget.H,v 1.6.2.4.2.14 2002/05/13 05:05:11 spitzak Exp $". +// End of "$Id: Fl_Widget.H,v 1.6.2.4.2.15 2002/07/23 15:07:32 easysw Exp $". // diff --git a/documentation/Fl_Widget.html b/documentation/Fl_Widget.html index ce6249cbd..19cb3dced 100644 --- a/documentation/Fl_Widget.html +++ b/documentation/Fl_Widget.html @@ -43,11 +43,14 @@ to call redraw() after these.

  • argument
  • box
  • callback
  • +
  • changed
  • +
  • clear_changed
  • +
  • clear_output
  • +
  • clear_visible
  • +
  • clear_visible_focus
  • - - + + - - -

    Fl_Color Fl_Widget::labelcolor() const -
    void Fl_Widget::labelcolor(Fl_Color)

    - -

    Gets or sets the label color. The default color is FL_BLACK. - -

    Fl_Font Fl_Widget::labelfont() const -
    void Fl_Widget::labelfont(Fl_Font)

    - -

    Gets or sets the font to use. Fonts are identified by small -8-bit indexes into a table. See the enumeration list for -predefined typefaces. The default value uses a Helvetica -typeface (Arial for Microsoft® Windows®). The function -Fl::set_font() can -define new typefaces. - -

    uchar Fl_Widget::labelsize() const -
    void Fl_Widget::labelsize(uchar)

    - -

    Gets or sets the font size in pixels. The default size is 14 -pixels. - -

    typedef void (Fl_Callback)(Fl_Widget*, void*) -
    Fl_Callback* Fl_Widget::callback() const -
    void Fl_Widget::callback(Fl_Callback*, void* = 0) -
    void Fl_Widget::callback(void (*)(Fl_Widget*, long), long = 0) -
    void Fl_Widget::callback(void (*)(Fl_Widget*))

    - -

    Gets or sets the current callback function for the widget. -Each widget has a single callback. - -

    void* Fl_Widget::user_data() const -
    void Fl_Widget::user_data(void*)

    - -

    Gets or sets the current user data (void *) argument -that is passed to the callback function.

    long Fl_Widget::argument() const
    void Fl_Widget::argument(long)

    @@ -291,16 +182,30 @@ that is passed to the callback function. -

    void Fl_Widget::do_callback() -
    void Fl_Widget::do_callback(Fl_Widget*, void* = 0) -
    void Fl_Widget::do_callback(Fl_Widget*, long)

    -

    Causes a widget to invoke its callback function, optionally -with arbitrary arguments. +

    Fl_Boxtype Fl_Widget::box() const +
    void Fl_Widget::box(Fl_Boxtype)

    + +

    Gets or sets the box type for the widget, which identifies a +routine that draws the background of the widget. See Box Types for the available +types. The default depends on the widget, but is usually +FL_NO_BOX or FL_UP_BOX. + + +

    typedef void (Fl_Callback)(Fl_Widget*, void*) +
    Fl_Callback* Fl_Widget::callback() const +
    void Fl_Widget::callback(Fl_Callback*, void* = 0) +
    void Fl_Widget::callback(void (*)(Fl_Widget*, long), long = 0) +
    void Fl_Widget::callback(void (*)(Fl_Widget*))

    + +

    Gets or sets the current callback function for the widget. +Each widget has a single callback. +

    int Fl_Widget::changed() const -
    void Fl_Widget::set_changed() -
    void Fl_Widget::clear_changed()

    +
    void Fl_Widget::clear_changed() +
    void Fl_Widget::set_changed()

    Fl_Widget::changed() is a flag that is turned on when the user changes the value stored in the widget. This is @@ -312,16 +217,53 @@ response to an "OK" button.

    Most widgets turn this flag off when they do the callback, and when the program sets the stored value.

    -

    Fl_When Fl_Widget::when() const -
    void Fl_Widget::when(Fl_When)

    -

    Fl_Widget::when() is a set of bitflags used by -subclasses of Fl_Widget to decide when to do the -callback. If the value is zero then the callback is never -done. Other values are described in the individual widgets. -This field is in the base class so that you can scan a panel and -do_callback() on all the ones that don't do their own -callbacks in response to an "OK" button. +

    void Fl_Window::clear_visible();

    + +

    Hides the widget; you must still redraw the parent to see a +change in the window. Normally you want to use the hide() method instead. + + +

    void Fl_Window::clear_visible_focus();

    + +

    Disables keyboard focus navigation with this widget; +normally, all widgets participate in keyboard focus navigation. + + +

    Fl_Color Fl_Widget::color() const +
    void Fl_Widget::color(Fl_Color) +
    void Fl_Widget::color(Fl_Color, Fl_Color)

    + +

    Gets or sets the background color of the widget. The color is +passed to the box routine. The color is either an index into an +internal table of RGB colors or an RGB color value generated +using fl_rgb_color(). The default for most widgets is +FL_GRAY. See the enumeration list for +predefined colors. Use Fl::set_color() to +redefine colors. + +

    The two color form sets both the background and selection +colors. See the description of the selection_color() +method for more information. + + +

    int Fl_Widget::contains(Fl_Widget* b) const

    + +

    Returns 1 if b is a child of this widget, or is +equal to this widget. Returns 0 if b is NULL. + + +

    uchar Fl_Widget::damage() const

    + +

    Non-zero if draw() needs to be +called. The damage value is actually a bit field that the widget +subclass can use to figure out what parts to draw. +

    static void Fl_Widget::default_callback(Fl_Widget*, void*)

    @@ -331,6 +273,216 @@ the queue returned by Fl::readqueue(). You may want to call this from your own callback. + +

    Fl_Image* Fl_Widget::deimage()
    +void Fl_Widget::deimage(Fl_Image* a)
    +void Fl_Widget::deimage(Fl_Image& a)

    + +

    Gets or sets the image to use as part of the widget label. +This image is used when drawing the widget in the inactive +state. + + +

    void Fl_Widget::do_callback() +
    void Fl_Widget::do_callback(Fl_Widget*, void* = 0) +
    void Fl_Widget::do_callback(Fl_Widget*, long)

    + +

    Causes a widget to invoke its callback function, optionally +with arbitrary arguments. + + +

    virtual int Fl_Widget::handle(int event)

    + +

    Handles the specified event. You normally don't call this +method directly, but instead let FLTK do it when the user +interacts with the widget. + + +

    Fl_Image* Fl_Widget::image()
    +void Fl_Widget::image(Fl_Image* a)
    +void Fl_Widget::image(Fl_Image& a)

    + +

    Gets or sets the image to use as part of the widget label. +This image is used when drawing the widget in the active state. + + +

    int Fl_Widget::inside(const Fl_Widget* a) +const

    + +

    Returns 1 if this widget is a child of a, or is +equal to a. Returns 0 if a is NULL. + + +

    const char* Fl_Widget::label() const +
    void Fl_Widget::label(const char*)

    + +

    Get or set the current label pointer. The label is shown +somewhere on or next to the widget. The passed pointer is stored +unchanged in the widget (the string is not copied), so if +you need to set the label to a formatted value, make sure the +buffer is static, global, or allocated. + + +

    Fl_Color Fl_Widget::labelcolor() const +
    void Fl_Widget::labelcolor(Fl_Color)

    + +

    Gets or sets the label color. The default color is FL_BLACK. + + +

    Fl_Font Fl_Widget::labelfont() const +
    void Fl_Widget::labelfont(Fl_Font)

    + +

    Gets or sets the font to use. Fonts are identified by small +8-bit indexes into a table. See the enumeration list for +predefined typefaces. The default value uses a Helvetica +typeface (Arial for Microsoft® Windows®). The function +Fl::set_font() can +define new typefaces. + + +

    uchar Fl_Widget::labelsize() const +
    void Fl_Widget::labelsize(uchar)

    + +

    Gets or sets the font size in pixels. The default size is 14 +pixels. + + +

    void Fl_Widget::label(Fl_Labeltype, +const char*) +
    uchar Fl_Widget::labeltype() const +
    void Fl_Widget::labeltype(Fl_Labeltype)

    + +

    Gets or sets the labeltype which +identifies the function that draws the label of the widget. This +is generally used for special effects such as embossing or for +using the label() pointer as another form of data such +as an icon. The value FL_NORMAL_LABEL prints the label +as plain text. + + +

    int Fl_Widget::output() const +
    void Fl_Widget::clear_output() +
    void Fl_Widget::set_output()

    + +

    output() means the same as !active() except +it does not change how the widget is drawn. The widget will not +receive any events. This is useful for making scrollbars or +buttons that work as displays rather than input devices. + + +

    Fl_Group *Fl_Widget::parent() const

    + +

    Returns a pointer to the parent widget. Usually this is a Fl_Group or Fl_Window. Returns +NULL if the widget has no parent. + + +

    void Fl_Widget::redraw()

    + +

    Marks the widget as needing its draw() routine called. + + +

    virtual void +Fl_Widget::resize(int x, int y, int w, int h) +
    void Fl_Widget::position(short x, short y) +
    void Fl_Widget::size(short w, short h)

    + +

    Change the size or position of the widget. This is a virtual +function so that the widget may implement its own handling of +resizing. The default version does not call the +redraw() method, but instead relies on the parent +widget to do so because the parent may know a faster way to +update the display, such as scrolling from the old position. + +

    position(x,y) is a shortcut for resize(x,y,w(),h()), +and size(w,h) is a shortcut for resize(x(),y(),w,h).

    + + +

    Fl_Color +Fl_Widget::selection_color() const +
    void Fl_Widget::selection_color(Fl_Color)

    + +

    Gets or sets the selection color, which is defined for Forms +compatibility and is usually used to color the widget when it is +selected, although some widgets use this color for other +purposes. You can set both colors at once with +color(a,b). + + +

    int Fl_Widget::takesevents() const

    + +

    This is the same as (active() && !output() +&& visible()) but is faster. + + +

    int Fl_Widget::take_focus()

    + Tries to make this widget be the Fl::focus() widget, by first +sending it an FL_FOCUS event, and if it returns non-zero, +setting Fl::focus() to this widget. You should use this +method to assign the focus to an widget. Returns true if the widget +accepted the focus. + + +

    const char *Fl_Widget::tooltip()
    +void Fl_Widget::tooltip(const char *t)

    + +

    Gets or sets a string of text to display in a popup tooltip +window when the user hovers the mouse over the widget. The +string is not copied, so make sure any formatted string +is stored in a static, global, or allocated buffer. + + +

    uchar Fl_Widget::type() const;

    + +

    Returns the widget type value, which is used for Forms +compatability and to simulate RTTI. + +

    short Fl_Widget::x() const +
    short Fl_Widget::y() const +
    short Fl_Widget::w() const +
    short Fl_Widget::h() const

    + +

    Returns the position of the upper-left corner of the widget +in its enclosing Fl_Window (not its parent if that is not +an Fl_Window), and its width and height. + + +

    void* Fl_Widget::user_data() const +
    void Fl_Widget::user_data(void*)

    + +

    Gets or sets the current user data (void *) argument +that is passed to the callback function. + + +

    Fl_Window* Fl_Widget::window() const;

    + +

    Returns a pointer to the primary Fl_Window widget. +Returns NULL if no window is associated with this +widget. Note: for an Fl_Window widget, this returns +its parent window (if any), not this window. + + +

    void Fl_Window::set_visible();

    + +

    Makes the widget visible; you must still redraw the parent +widget to see a change in the window. Normally you want to use +the show() method +instead. + + +

    void Fl_Window::set_visible_focus();

    + +

    Enables keyboard focus navigation with this widget; note, +however, that this will not necessarily mean that the widget +will accept focus, but for widgets that can accept focus, this +method enables it if it has been disabled. + +

    int Fl_Widget::visible() const
    int Fl_Widget::visible_r() const
    void Fl_Widget::show()
    @@ -349,101 +501,23 @@ visible, as this will send false FL_SHOW or FL_HIDE events to the widget. redraw() is called if necessary on this or the parent. -

    int Fl_Widget::active() const
    -int Fl_Widget::active_r() const
    -void Fl_Widget::activate()
    -void Fl_Widget::deactivate()

    +

    void Fl_Window::visible_focus();

    -

    Fl_Widget::active() returns whether the widget is -active. Fl_Widget::active_r() returns whether the -widget and all of its parents are active. An inactive widget -does not get any events, but it does get redrawn. A widget is -only active if active() is true on it and all of its -parents. +

    Returns non-zero if this widget will participate in keyboard +focus navigation. -

    Changing this value will send FL_ACTIVATE or -FL_DEACTIVATE to the widget if active_r() is true. -

    Currently you cannot deactivate Fl_Window widgets.

    -

    int Fl_Widget::output() const
    -void Fl_Widget::set_output()
    -void Fl_Widget::clear_output()

    +

    Fl_When Fl_Widget::when() const +
    void Fl_Widget::when(Fl_When)

    -

    output() means the same as !active() except -it does not change how the widget is drawn. The widget will not -receive any events. This is useful for making scrollbars or -buttons that work as displays rather than input devices. +

    Fl_Widget::when() is a set of bitflags used by +subclasses of Fl_Widget to decide when to do the +callback. If the value is zero then the callback is never +done. Other values are described in the individual widgets. +This field is in the base class so that you can scan a panel and +do_callback() on all the ones that don't do their own +callbacks in response to an "OK" button. -

    int Fl_Widget::takesevents() const

    - -

    This is the same as (active() && !output() -&& visible()) but is faster. - -

    void Fl_Widget::redraw()

    - -

    Marks the widget as needing its draw() routine called. - -

    uchar Fl_Widget::damage() const

    - -

    Non-zero if draw() needs to be -called. The damage value is actually a bit field that the widget -subclass can use to figure out what parts to draw. - -

    Fl_Group *Fl_Widget::parent() const

    - -

    Returns a pointer to the parent widget. Usually this is a Fl_Group or Fl_Window. Returns -NULL if the widget has no parent. - -

    int Fl_Widget::contains(Fl_Widget* b) const

    - -

    Returns 1 if b is a child of this widget, or is -equal to this widget. Returns 0 if b is NULL. - -

    int Fl_Widget::inside(const Fl_Widget* a) -const

    - -

    Returns 1 if this widget is a child of a, or is -equal to a. Returns 0 if a is NULL. - -

    int Fl_Widget::take_focus()

    - Tries to make this widget be the Fl::focus() widget, by first -sending it an FL_FOCUS event, and if it returns non-zero, -setting Fl::focus() to this widget. You should use this -method to assign the focus to an widget. Returns true if the widget -accepted the focus. - -

    Fl_Image* Fl_Widget::deimage()
    -void Fl_Widget::deimage(Fl_Image* a)
    -void Fl_Widget::deimage(Fl_Image& a)

    - -

    Gets or sets the image to use as part of the widget label. -This image is used when drawing the widget in the inactive -state. - -

    Fl_Image* Fl_Widget::image()
    -void Fl_Widget::image(Fl_Image* a)
    -void Fl_Widget::image(Fl_Image& a)

    - -

    Gets or sets the image to use as part of the widget label. -This image is used when drawing the widget in the active state. - -

    const char *Fl_Widget::tooltip()
    -void Fl_Widget::tooltip(const char *t)

    - -

    Gets or sets a string of text to display in a popup tooltip -window when the user hovers the mouse over the widget. The -string is not copied, so make sure any formatted string -is stored in a static, global, or allocated buffer. - -

    virtual int Fl_Widget::handle(int event)

    - -

    Handles the specified event. You normally don't call this -method directly, but instead let FLTK do it when the user -interacts with the widget. diff --git a/src/Fl.cxx b/src/Fl.cxx index ff06ffc7d..3ede09284 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl.cxx,v 1.24.2.41.2.42 2002/07/11 01:10:15 matthiaswm Exp $" +// "$Id: Fl.cxx,v 1.24.2.41.2.43 2002/07/23 15:07:33 easysw Exp $" // // Main event handling code for the Fast Light Tool Kit (FLTK). // @@ -419,6 +419,7 @@ static int send_handlers(int event) { Fl_Widget* fl_oldfocus; // kludge for Fl_Group... void Fl::focus(Fl_Widget *o) { + if (o && !o->visible_focus()) return; if (grab()) return; // don't do anything while grab is on Fl_Widget *p = focus_; if (o != p) { @@ -948,5 +949,5 @@ void Fl_Window::flush() { } // -// End of "$Id: Fl.cxx,v 1.24.2.41.2.42 2002/07/11 01:10:15 matthiaswm Exp $". +// End of "$Id: Fl.cxx,v 1.24.2.41.2.43 2002/07/23 15:07:33 easysw Exp $". // diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx index 9ddd8b551..fd91da44e 100644 --- a/src/Fl_Input_.cxx +++ b/src/Fl_Input_.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Input_.cxx,v 1.21.2.11.2.13 2002/07/20 05:56:44 easysw Exp $" +// "$Id: Fl_Input_.cxx,v 1.21.2.11.2.14 2002/07/23 15:07:33 easysw Exp $" // // Common input widget routines for the Fast Light Tool Kit (FLTK). // @@ -233,7 +233,7 @@ void Fl_Input_::drawtext(int X, int Y, int W, int H) { p = value(); // visit each line and draw it: int desc = height-fl_descent(); - int xpos = X-xscroll_; if (W > 12) xpos += 3; + int xpos = X - xscroll_ + 1; int ypos = -yscroll_; for (; ypos < H;) { @@ -872,5 +872,5 @@ Fl_Input_::~Fl_Input_() { } // -// End of "$Id: Fl_Input_.cxx,v 1.21.2.11.2.13 2002/07/20 05:56:44 easysw Exp $". +// End of "$Id: Fl_Input_.cxx,v 1.21.2.11.2.14 2002/07/23 15:07:33 easysw Exp $". // diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index d904e87d2..7d396eac7 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.18 2002/06/02 17:52:36 easysw Exp $" +// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.19 2002/07/23 15:07:33 easysw Exp $" // // Base widget class for the Fast Light Tool Kit (FLTK). // @@ -89,7 +89,7 @@ Fl_Widget::Fl_Widget(int X, int Y, int W, int H, const char* L) { callback_ = default_callback; user_data_ = 0; type_ = 0; - flags_ = 0; + flags_ = VISIBLE_FOCUS; damage_ = 0; box_ = FL_NO_BOX; color_ = FL_GRAY; @@ -115,6 +115,7 @@ int Fl_Widget::damage_resize(int X, int Y, int W, int H) { int Fl_Widget::take_focus() { if (!takesevents()) return 0; + if (!visible_focus()) return 0; if (!handle(FL_FOCUS)) return 0; // see if it wants it if (contains(Fl::focus())) return 1; // it called Fl::focus for us Fl::focus(this); @@ -241,5 +242,5 @@ int Fl_Widget::contains(const Fl_Widget *o) const { } // -// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.18 2002/06/02 17:52:36 easysw Exp $". +// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.19 2002/07/23 15:07:33 easysw Exp $". //