Derived FLTK Classes

by: cable_guy_67 - Jun 27, 2005

A FLTK Phone Book UI

I have been playing with some ideas to compartmentalize my FLTK applications and a member at GIDForums asked about how to extend your own widget classes. So I, in my over the top way, designed a UI that will work with a infinite array Phone Book I wrote. The PBook is not implemented yet but the UI is designed. All that is left is to create the remaining callbacks and interface it with the PBook class.

There are a lot of little things that may be of interest.

A simple how to for deriving classes and using those classes as original fltk types.

In class callbacks.

Exiting without calling exit().

Reusable custom widgets.

Flicker protector group.

Menu array pointers.

Now, that being said, this is not even vaguely complete. The phone book portion is still in console form and it was rudementary at best. It is based on a self extending concept that builds a page of objects at a time and uses an overloaded operator[] for indexing. Currently it is a singly linked list. To be useful it will need to become doubly linked and have a current pointer added.

The idea is to have the UI have two views. A single entry and a page of entries that matches the paging system of the PBook database. It should have simple sorting based on one of the fields in the record. Nothing ground-breaking but it seemed both simple and interesting enough for the real project, which was trying to get reusability and ease of creation for FLTK widgets. Simple things but hopefully very useful in the long run. It will also serve to give someone starting with FLTK some room to improve on their own.

Now, I'm not exactly a professional at this so feel free to point out ways that this could be done better. One thing that concerns me is the data base object. It seems to make sense that it would be seperately maintained from the UI. From within the UI I can always find my way back to the main window (see the exit menu callback) but I am not entirely sure how I will handle the database itself. Working within FLTK's event loop still gives me a bit of a headache sometimes. One of the nice things about it though is that FLTK works with C++ code and has a very straightforward method of get/put using overloading the return type which I use in the phone book portion of the code.

Well, that's about enough for an introduction. In order to build this you will need to have FLTK 1.1.x installed and use the command line:

I have built it with the current subversion repo on Windows 2000 using the CygWin GNU tools. It should be portable especially in it's current state as I try to use the C++ standard and no STL. I do like to use <string> though so that is the only place I can think of being a problem. When I get to it I will post the working version of the project. If anyone wants to pitch in, feel free. Any OOP comentary will be most welcome as well. Here is what it currently looks like.