Re: Program Structure



I would suggest that writing object-oriented code in C is hard, especially
to get a clear, clean result. (I know people do it, that's not the point).
This situation calls out for an object oriented language like C++ in which
the widget IS the structure.  There's a perfectly reasonable C++ interface for
gtk called gtk--.  I really think it worth some initial effort to try C++.
You don't have to learn the whole complex powerful flexible blahblahblah
content of the language to use it's basic OO capabilities.

I'm not currently a big gtk-- user ( I've passed beyond the earthly state of
C++ to the splendid world of Python! ), but your discussion seems to cry out
for C++.  Again, C++ is essentially a clean superset of C, so the transition
can be completely gradual.  Just learn how to create a class with constructors
and methods; I think you'll find it makes the problems discussed here melt
away.


On Sun, 8 Apr 2001 02:47:07 -0700 (PDT)
<learfox furry ao net> wrote:

I was under the impression that this destroys the widget OOP concept.
I was not wanting to make a global variable of any sort, even a structure.
I have gone ahead and passed structures or pointers by callback to each
part in my program:

Well it orients a part of yer program as one object, say one `window'
as one object. Because yer trying to make something *useful* from
something that is OOP, not make an OOP out of something already OOP
(that's often used in wrappers and portability libraries).


/* I have to put a widget I will modify */
menu_selection_ callback (ctree_ptr)
{
    create_dialog
}

/* I have to create a structure to pass more  args */
file_selection_ok_button_callback(struct(ctree_ptr, selection_dialog_ptr))
{
    ...
}

(Note: this is not actual code)

This passing of pointers is not too bad, but creating structures just to pass

information seems a little tedious.  Can the callbacks employ more than one
generic pointer arg?

Oh, I use a global `core structure', ie:

typedef struct {

      inventory_struct **inventory_window;
      int total_inventory_window;

} core_struct;

This one is allocated in main(), then passed to each widget as the signal
callback data.  There's no global variables involved as this one is
declared locally in main().


I guess I could make one big structure as you said and pass it through  the
chain.
That way I can reduce confusion as to what I am passsing and keep the data
from
being global.  It will have to be static though.

static can mean a lot of things in C>

But I think I know what yer trying to say, I've been writing GTK+ apps for
two years now using various styles and I've found this to be the most
practical.

Sometimes I would dereferance if the signal handler is for a widget
gauranteed to be within a structure like inventory_window.


Am I making this thing to hard?  Should I just make a bunch of globals?
Are globals really that bad?

Yes they are if you go into C++, best advice is to make one local variable
in main() called the core_struct, and dynamically allocate it.

That struct will hold pointers to all substructures, each substructure
is like a window with a bunch of GtkWidgets in there.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

-- 
Your mouse has moved.
Windows NT must be restarted for the change to take effect.
Reboot now?  [OK]




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