[Mono-list] Building a new control, Need a starting point

Michael Hutchinson m.j.hutchinson at gmail.com
Fri May 22 18:08:55 EDT 2009


On Mon, May 11, 2009 at 3:54 AM, Joshua Hayworth
<joshua at hayworthfamily.com> wrote:
> Hello there,
>
> Disclaimer: I'm a mono newbie. My day job is in a Windows/.NET dev shop.
>
> I'd like to attempt to build an outliner control (very similar to the one
> you would see in the opml editor [http://editor.opml.org/]).
>
> Under normal circumstances I might inherit from
> System.Windows.Forms.Control, override the OnPaint method, and go from
> there.
>
> If I was to write the control with the intention of using the GTK#
> libraries, where would be a good place to start? Is there any existing
> controls (without DllImports) that I could take a look at as an example?

There are a number of controls around, e.g. big ones like
MonoDevelop's Mono.TextEditor, Banshee's ListView, etc, or smaller
ones like MD's Toolbox.

Or a really simple one that just wraps text to a fixed width, breaking
on camel case:
http://anonsvn.mono-project.com/viewvc/trunk/monodevelop/main/src/core/MonoDevelop.Components/MonoDevelop.Components/FixedWidthWrapLabel.cs?view=markup

You can just subclass Widget, but if you subclass DrawingArea it sets
up a GdkWindow for you. If you need input, your widget needs a
GdkWindow; If not, you just paint onto some portion of the parent's
GdkWindow. IIRC when creating the GdkWindow you have to pass a mask of
the kinds of events you want to subscribe to - mouse, keyboard, DnD,
etc.

You need to handle the width request and allocation events to handle
layout -- you need to handle whatever allocation you get, regardless
of what you requested. Then handle the expose event to do the
painting. If your widget has requested mouse, keyboard, DnD, etc
events, you can handle those events too (all of this using the On*
overrides, of course).

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Mono-list mailing list