Re: Automatically generated code by Glade.. where to put certain functions?



"Manish Chakravarty" wrote:

thanx for replying to my previuos ques,
but the glade manual says that i have to edit the callbacks.c file to
get going..
here is what i want to do:
i have designed two window widgets using glade and when i press the OK
button on the first one, i want the second one to be displayed.
in which file do i place the code to do this stuff? i guess i cannot
do it in main.c and i callback.c it does not work.
i mean where do i put all the "GUI Logic" for the program. The glade
manual sucks

If I remember right the rules given by Glade are about the following:

- interface.c: don't touch it. Always rebuilt by Glade.
- support.c:   don't touch it. Only for internal use by Glade.
- callbacks.c: Glade adds empty functions here as you define signal
               handlers inside Glade. You're free to fill the empty
               functions with your code or add or remove custom
               functions (though for structural reasons you better
               don't!). If you remove functions created by Glade it
               is possible to let Glade recreate their empty frames.
               Apparently Glade never deletes code from this file.
- main.c:      you're free to edit this file, Glade won't touch it after
               its initial creation and changes being made by you.

You're free to create (and remove) additional .c + .h files on your own.
The .c files should just be included in the Makefile, of course. Always
keep in mind the related .h files (to avoid warnings or confusions).

So if your program is of limited size / complexity you're free to put a
bunch of functions and logic inside main.c. Of course, it's a better
idea to early consider additional .c files to store extensive program
logic in. If you have a number of complex windows (many widgets +
callbacks) then it might be a good idea to have one .c file per window.

Another suggestion is to to put only simple signal handler code inside
the Glade-given function bodies inside callbacks.c. As you add more and
more signal handlers (maybe for different windows), callbacks.c tends to
grow quickly and become harder to maintain if you don't.

My rule of thumb is to keep simple handlers (<=5 lines of code) inside
functions in callbacks.c and put more complex handlers into other .c
files. The handler in callbacks.c then only consists of a function call
to the actual (complex) handler function. You could call this a wrapper
function.



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