Re: I want to use a Gtk+ widget...
- From: Robert Pearce <rob bdt-home demon co uk>
- To: gtkmm-list gnome org
- Subject: Re: I want to use a Gtk+ widget...
- Date: Thu, 21 Feb 2008 22:01:00 +0000
On Thu, 21 Feb 2008, Rob Stoddard <rstoddard telanetix com> wrote :
>
>Is it possible for me to use a Gtk+ widget, perhaps wrapping it
>(manually) in a class, rather than go through all the trouble of
>creating a gtkmm library?
Yes, it is. I had a similar issue with a custom GTK widget (modified
version of the "dial" example). I actually created a class derived from
Gtk::Frame to embed it in, because that was convenient for the GUI I was
creating, but the principle is similar.
Here's my constructor:
FramedMeter::FramedMeter ( Gtk::Adjustment * adj )
: Frame()
{
set_shadow_type ( Gtk::SHADOW_IN );
if ( adj )
{
MeterAdj = adj;
OwnsAdj = false;
}
else
{
MeterAdj = new Gtk::Adjustment ( 0, 0, 300, 0.01, 0.1, 0 );
OwnsAdj = true;
}
DialObject = GTK_DIAL ( gtk_dial_new ( MeterAdj->gobj(),
GTK_DIAL_METER, 0 ) );
gtk_container_add (GTK_CONTAINER (gobj()), GTK_WIDGET(DialObject) );
gtk_widget_show ( GTK_WIDGET(DialObject) );
}
As you can see, I use the normal GTK+ API to add the meter to the frame,
having got the GTK+ object for the frame using the gobj() method. I then
explicitly wrap a few functions I want, for example:
bool FramedMeter::SetLabel ( char * markup )
{
gtk_dial_set_label_markup ( DialObject, markup );
}
That approach gives me a C++ class that looks like a GTKmm object
because fundamentally it is - a Gtk::Frame - but provides the API I want
for my C-only GTK_DIAL.
If you don't want a frame, there are other less intrusive widgets you
could use. Or somebody may suggest a better approach :)
--
Rob Pearce http://www.bdt-home.demon.co.uk
The contents of this | Windows NT crashed.
message are purely | I am the Blue Screen of Death.
my opinion. Don't | No one hears your screams.
believe a word. |
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]