From 367f908d8ed5a3464b9676223a26ddf4e11bdb5b Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 7 Jan 1999 16:36:11 +0000 Subject: "Final" changes for first draft of 1.0 documentation. git-svn-id: file:///fltk/svn/fltk/trunk@187 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- documentation/subclassing.html | 668 +++++++++++++++++++---------------------- 1 file changed, 303 insertions(+), 365 deletions(-) (limited to 'documentation/subclassing.html') diff --git a/documentation/subclassing.html b/documentation/subclassing.html index 414cca67b..7ed03ed7a 100644 --- a/documentation/subclassing.html +++ b/documentation/subclassing.html @@ -1,427 +1,338 @@ -

5 - Adding and Extending Widgets

+

7 - Adding and Extending Widgets

-This chapter describes how to add your own widgets or extend existing widgets in FLTK. +This chapter describes how to add your own widgets or extend existing +widgets in FLTK.

Subclassing

-

Adding Syntax Highlighting to the Fl_Input Widget

+New widgets are created by subclassing an existing FLTK widget, +typically Fl_Widget for controls and Fl_Group for +containers. -

Drawing Functions

+

A control widget typically interacts with the user to receive and/or +display a value of some sort. -

Lines, Rectangles, and Curves, Oh, My!

+

A container widget holds a list of child widgets and handles moving, +sizing, showing, or hiding them as needed. Fl_Group is the +main container widget class in FLTK, and all of the other containers +(Fl_Pack, Fl_Scroll, Fl_Tabs, Fl_Tile, +and Fl_Window) are subclasses of it. -

Colors

+

You can also subclass other existing widgets to provide a different look +or user-interface. For example, the button widgets are all subclasses of +Fl_Button since they all interact with the user via a mouse button +click. The only difference is the code that draws the face of the button. -

Fonts

+

Making a Subclass of Fl_Widget

-

Images

+Your subclasses can directly descend from Fl_Widget or any +subclass of Fl_Widget. Fl_Widget has only four +virtual methods, and overriding some or all of these may be necessary. -

Writing a Table Widget

+

The Constructor

-

Methods

+The constructor should access the following arguments: -

Cut and Paste Support

- - - -Cut & paste -

Cut & paste

- -Fltk provides routines to cut and paste ASCII text (in the future this -may be UTF-8) between applications. It may be possible to cut/paste -non-ascii data under X by using Fl::add_handler(). - -

void Fl::paste(Fl_Widget *receiver)

void Fl::selection(Fl_Widget *owner, const char *stuff, int len); -

const char* Fl::selection(); -
int Fl::selection_length();

Fl_Widget *Fl::selection_owner() const; -
void Fl::selection_owner(Fl_Widget *);

Making a subclass of Fl_Widget

+The first form indicates that a partial update of the object is +needed. The bits in mask are OR'd into damage(). Your +draw() routine can examine these bits to limit what it is +drawing. The public method Fl_Widget::redraw() simply does +Fl_Widget::damage(FL_DAMAGE_ALL). -

Your subclasses can directly descend from Fl_Widget or any -subclass of Fl_Widget. Fl_Widget has only four virtual methods, and -overriding some or all of these may be necessary. +

The second form indicates that a region is damaged. If only these +calls are done in a window (no calls to damage(n)) then FLTK +will clip to the union of all these calls before drawing anything. +This can greatly speed up incremental displays. The mask bits are or'd +into damage() unless this is a Fl_Window widget. -

Parts of this document: +

The third form returns the bitwise-OR of all damage(n) +calls done since the last draw(). The public method +redraw() does damage(FL_DAMAGE_ALL), but the +implementation of your widget can call the private damage(n). -

+Fast inline versions of Fl_Widget::hide() and +Fl_Widget::show(). These do not send the FL_HIDE and +FL_SHOW events to the widget. - -

Constructing your Fl_Widget

+

int Fl_Widget::test_shortcut() const
+static int Fl_Widget::test_shortcut(const char *s)

-I recommend your constructor be of this form: +The first version tests Fl_Widget::label() against the current +event (which should be a FL_SHORTCUT event). If the label +contains a '&' character and the character after it matches the key +press, this returns true. This returns false if the +SHORTCUT_LABEL flag is off, if the label is NULL or +does not have a '&' character in it, or if the keypress does not match +the character. -

-    Class(int x, int y, int w, int h, const char* label = 0);
-
+

The second version lets you do this test against an arbitrary string. -

This will allow the class name to be typed into fluid and it will produce the correct call. +

uchar Fl_Widget::type() const
+void Fl_Widget::type(uchar t)

-

The constructor must call the constructor for the base class and -pass the same arguments. Fl_Widget's protected constructor sets x(), -y(), w(), h(), and label() to the passed values and initializes the -other instance variables to: - -

-    type(0);
-    box(FL_NO_BOX);
-    color(FL_GRAY);
-    selection_color(FL_GRAY);
-    labeltype(FL_NORMAL_LABEL);
-    labelstyle(FL_NORMAL_STYLE);
-    labelsize(FL_NORMAL_SIZE);
-    labelcolor(FL_BLACK);
-    align(FL_ALIGN_CENTER);
-    callback(default_callback,0);
-    flags(ACTIVE|VISIBLE);
-
- - -

Protected methods of Fl_Widget

- -

These methods are provided for subclasses to use. - -

uchar Fl_Widget::type() const; -
void Fl_Widget::type(uchar); -

void Fl_Widget::set_flag(SHORTCUT_LABEL);

int Fl_Widget::test_shortcut() const;
-static int Fl_Widget::test_shortcut(const char *);

void Fl_Widget::x(short); -
void Fl_Widget::y(short); -
void Fl_Widget::w(short); -
void Fl_Widget::h(short);

void Fl_Widget::damage(uchar mask);

void Fl_Widget::damage(uchar mask,int x,int y,int w,int -h);

void Fl_Widget::clear_damage(uchar value = 0);

uchar Fl_Widget::damage()

void Fl_Widget::set_visible(); -
void Fl_Widget::clear_visible();

void Fl_Widget::draw_box() const ;

void Fl_Widget::draw_box(Fl_Boxtype b,ulong c) const -;

void Fl_Widget::draw_label() const ;

void Fl_Widget::draw_label(int x,int y,int w,int h) const -;

void Fl_Widget::draw_label(int x,int y,int w,int -h,Fl_Align align) const ;

- -

virtual int Fl_Widget::handle()

- -The virtual method int Fl_Widget::handle(int -event) is called to handle each event passed to the widget. -It can: