Re: Gnome2::Canvas



On Sunday, March 14, 2004, at 05:08 AM, john knops wrote:

1. Why is it called Gnome2::Canvas. Isn't Gnome built with Gtk so wouldn't Gtk2::Canvas be a better name?

these are not the definitive answers (i couldn't find what i wanted in thirty seconds of googling) but here goes:

a) it was written for gnome
b) it has dependencies that gtk+ does not (libart, namely)
c) because it's not actually part of the gtk+ project, so putting their widget into the Gtk namespace would be rude and would make it difficult for gtk+ to add a canvas widget in the future. (GtkSpell, GtkHTML, and GtkDatabox are all offenders here.)


2. Where does it fit in the Gtk hierarchy tree?

the manpage for the previously released versions which don't require the bleeding edge Glib don't show this, but the current and about-to-be-released stable versions do:

  HIERARCHY
         Glib::Object
         +----Gtk2::Object
               +----Gtk2::Widget
                     +----Gtk2::Container
                           +----Gtk2::Layout
                                 +----Gnome2::Canvas



3. When creating a canvas item why the call to $root? eg.
my $root =$canvas->root;
my $item = Gnome2::Canvas::Item->new ($root,
                                      'Gnome2::Canvas::Ellipse');
Am I correct in thinking that no other widget makes this sort of call so why does this one need it?

for better or worse, this is an artifact of the way the interaction between GnomeCanvas and GnomeCanvasItem was designed. a GnomeCanvasItem knows the canvas to which it belongs, and it also knows its parent. it is not valid to have a GnomeCanvasItem which is not associated with a GnomeCanvas; so, you tell the item factory what parent to use for the new item, which implies the canvas.

the fragment you posted is a direct port from the corresponding C code:

  root = gnome_canvas_root (canvas);
  item = gnome_canvas_item_new (root, GNOME_TYPE_CANVAS_ELLIPSE, NULL);

note that it doesn't have to be "root" --- you could instead do:

$group1 = Gnome2::Canvas::Item->new ($canvas->root, 'Gnome2::Canvas::Group');
  Gnome2::Canvas::Item->new ($group1, 'Gnome2::Canvas::Rect');
  Gnome2::Canvas::Item->new ($group1, 'Gnome2::Canvas::Ellipse');
$group2 = Gnome2::Canvas::Item->new ($canvas->root, 'Gnome2::Canvas::Group');
  Gnome2::Canvas::Item->new ($group2, 'Gnome2::Canvas::Rect');
  Gnome2::Canvas::Item->new ($group2, 'Gnome2::Canvas::Ellipse');

more info:

http://developer.gnome.org/doc/whitepapers/canvas/canvas.html

--
"that's it! you're a genius!" "yes. that's what i think. do you think i deserve a raise?"
        - dialogue from 'Godzilla versus Mothra', 1964




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