Re: Custom Signals



Ecmel Ercan wrote:
> I am working on a GTK+ program with a tabbed interface.  Each tab can
> display same or different kind of a container widget.  It is like MDI.
> 
> I have an Edit menu and this menu contains actions which are common to
> all documents.  The actions will be handled on a different fashion on
> each class of document.
> 
> For example, Edit Copy action should call a  function on the active tab.
> 
> In win32 I do this by defining a custom message and sending this signal
> to the active window and responding differently on each window's message
> handler.
> 
> Is there a way to achive this in GTK+?

Hi Ecmel, there are a bunch of ways to do this. 

I think the nicest is to define a base class (maybe called Document) for the
things you display in notebook pages, with an _edit() method. For each of the
sorts of things you show, make a subclass off Document and implement _edit(). In
your main window, track notebook tab changes somewhere (so you know what the
"current" document is), and then in the callback from the edit menu, just
trigger current_document->edit().

It's a little fiddly the first time you try setting up the classes with GTK's C
object model, but actually very straightforward once you get the hang of it.

John




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