Re: Canvas basics



On Sat, Jan 08, 2005 at 11:26:45PM +0000, Roger Leigh wrote:

If you don't mind, could I pick your brain about other bits of
Gnumeric?

sure.
 
I'd like to let the mouse wheel and Alt + mouse wheel scroll
horizontally and vertically when over any of the canvas widgets.  Do I
need to create synthetic scroll events or pass the events to the
scrollbars somehow?  Do I need to catch this through "event" in the
CanvasItems, or can I handle it as a proper GdkEvent in the Canvas
widget itself?

With Gtk2 this is nice and clean, not like gtk1 where you had to
look for buttons 4&5.

Just put a handler for "scroll-event" onto the window.
Have a look at gnumeric/src/workbook-control-gui.c:wbcg_scroll_wheel_support_cb
for an example.

The larger question here is selecting some sort of standard for how
the mouse wheel should behave.  We use
    - scroll up/down left/right from the mouse for movement (there
      are mice with multiple wheels)
    - Alt transposes the direction
    - Ctrl zooms in and out
    - Shift is an MS Excel (tm) specific modifier
 
The other thing I'd like to do is set a GdkCursor to show when the
mouse moves over certain items, like the edge of the current selection
or the drag handle in the bottom right corner.  Is this simple to do?

You can look at an example in gnumeric/src/item-bar.c:item_bar_event
        case GDK_ENTER_NOTIFY:
        case GDK_MOTION_NOTIFY:
                ib_set_cursor (ib, x, y);

I saw that there was a gnome_canvas_item_grab() method, but can this
only be called from the event handler?  If so, I'm a little unsure
when it's appropriate to grab() and ungrab().

No grab is necessary here.  Those are needed when dragging outside
the window (eg autoscrolling during resize).  Be _very_ careful with
grabs.  They can seem to lock the screen.

When there are frozen panes we can have up to 4 canvases for the
grid.

That's pretty cool.  Just a thought: would it make sense to have a
view/model separation for the canvas?  This would allow one to have a
CanvasView displaying an underlying CanvasModel.  You would then be
able to manipulate the model like you can now, but you would be able
to have multiple view panes and magnifiactions of the same model
(though this would require text to scale properly--perhaps you could
draw using physical units of measurement instead of an abstract
scale?).

sounds like diacanvas.
Gnumeric has such a separation (actually we have model -> view -> control)
but handles things at a slightly different level.  Unfortunately
we never sat down with the diafolk to merge efforts.

- - once placed on the canvas, items (e.g. CanvasGroups) can only be
  moved relatively, rather than to absolute coordinates, AFAICT.
  This would be handy for when I want to move an item to a specific
  location.

This is a side effect of the basic approach to groups in the canvas.
You can fake your way around it as necessary.

- - gnome_canvas_item_new allows one to set object properties on the
  created item.  However, it does not pass them to g_object_new, so
  they can't be used as construction parameters.  (Though I can't
  remember why I wanted this now.)
That is indeed irritating.  Likely a throw back to the old
pre-gobject days that is still visible because canvas doesn't see
much maintenance.

If you don't need anti-aliasing you may want to look at foocanvas, a
smaller lighter canvas used in gnumeric and nautilus.



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