Re: GtkOptionMenu



On Thu, Mar 06, 2003 at 11:21:07AM -0000, martyn 2 russell bt com wrote:
Again, this is an FAQ similar to the question about how to get and set the
label for a menu.  Perhaps there should be an API call for this...?


There's no API call because it's normally a really bad way to write
the program - it's a FAQ because it's the first way people think of,
not because you should actually do it.

One reason it's bad is that almost all real-life programs other than
in-house apps end up internationalized, and this code breaks as soon
as you internationalize the program. (Except in the case where the
option menu contains non-predetermined strings, such as database query
results. Even then though, the option menu text must be in UTF-8, and
your actual data may not be.)

It's better to use object data
(g_object_set_data()/g_object_get_data()) or simply the option menu
index (gtk_option_menu_get_history()) instead of the label.

As a general guideline for GUI programming, you should never use your
widgets as your data structure. Anytime you do that it's hard to
change around the UI and hard to port to other toolkits and you
usually end up with spaghetti code.

The program should be structured around the data structures and
algorithms that make sense for the application, then layer the GUI on
top of that non-invasively. This is another way of stating that you
should have a "model" separate from your "view"

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]