Re: Widget movement signal in custom widget



Why don't you use a Gtk::Layout instead of a DrawingArea, then you can add the progressbar as a child widget and show it on button press and hide it on button release.

--
Marco

----- Original Message ----- From: "Matt Strange" <mstrange wans net>
To: <gtkmm-list gnome org>
Sent: Thursday, July 07, 2005 9:31 AM
Subject: Widget movement signal in custom widget


Hello All,
       I am trying to creating a custom widget which has a
Gtk::Progressbar floating above it in a popup Window.  The
Progressbar's window only appears when the mouse button is down (it's
hidden the rest of the time).  To keep the floating Progressbar in
the
correct position relative to the widget, I need to have the
Progressbar's popup window move whenever the custom widget is moved.
However, I cannot find the right signal for the "widget moved" event.
The generally recommended "configure_event" signal is only called on
resizing signals, even with all GdkEventFlags on.
       Assuming there is no better way to link this floating
Progressbar to the custom widget (e.g. a method which makes moving
the
Progressbar unnecessary), I would appreciate any help adding a method
to the CustomDrawingArea (see code below) which is called when the
widget is moved (`on_configure_event' attempts to do that in the
example code).
       The following code is modified from one of the Tutorial
Examples and is simply an overridden DrawingArea with the additional
Progressbar.  Note that `on_configure_event' is only called when the
widget is resized; `on_configure_event' is not called when the widget
is moved.

Thank you very much for your time,
Matt Strange

//test1.cpp
#include <iostream>
#include <gtkmm/main.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/window.h>
#include <gtkmm/progressbar.h>

class CustomDrawingArea : public Gtk::DrawingArea
{
public:
 CustomDrawingArea(int x_size = 0, int y_size = 0);
 ~CustomDrawingArea();
 virtual bool on_expose_event(GdkEventExpose* event);
 virtual bool on_configure_event(GdkEventConfigure* event);
 virtual bool on_button_press_event(GdkEventButton* event);
 virtual bool on_button_release_event(GdkEventButton* event);
protected:
 int m_width, m_height;
 Gtk::ProgressBar* _progressbar;
 Gtk::Window* _progressbar_window;
};

CustomDrawingArea::CustomDrawingArea(int x_size, int y_size)
 : DrawingArea(), m_width(x_size), m_height(y_size)
{
 set_size_request(m_width, m_height);
 // note: STRUCTURE_MASK should make the configure events
 // recievable...
 add_events(Gdk::STRUCTURE_MASK | Gdk::BUTTON_PRESS_MASK |
            Gdk::BUTTON_RELEASE_MASK);

 // make the progressbar & a popup window that it sits in
 _progressbar_window = new Gtk::Window(Gtk::WINDOW_POPUP);
 _progressbar = manage(new Gtk::ProgressBar);
 _progressbar->set_size_request(10,50);
 _progressbar->set_orientation(Gtk::PROGRESS_BOTTOM_TO_TOP);
 _progressbar_window->add(*_progressbar);
}
CustomDrawingArea::
~CustomDrawingArea()
{
 delete _progressbar_window;
}

bool CustomDrawingArea::on_expose_event(GdkEventExpose*)
{
 Glib::RefPtr<Gdk::Window> win = get_window();
 Glib::RefPtr<Gdk::GC> some_gc = Gdk::GC::create(win);

 Gdk::Color some_color("white");
 Glib::RefPtr<Gdk::Colormap> some_colormap =
       get_default_colormap();
 some_colormap->alloc_color(some_color);
 some_gc->set_foreground(some_color);

 //Draw circle
 win->draw_arc(some_gc, true, 0, 0, 50, 50, 0, 23040);

 return true;
}

bool
CustomDrawingArea::on_configure_event(GdkEventConfigure* event)
{
 std::cerr << "on_configure_event called\n";
 // ERROR: this is only called when the window is resized, how to
 // call when moved?
 int x,y;
 get_window()->get_origin(x,y);
 _progressbar_window->move(x+50,y);
 return true;
}

bool
CustomDrawingArea::on_button_press_event(GdkEventButton* event)
{
 _progressbar_window->show_all();
 return true;
}

bool
CustomDrawingArea::on_button_release_event(GdkEventButton* event)
{
 _progressbar_window->hide();
 return true;
}

int
main(int argc, char* argv[])
{
 Gtk::Main gtk_main(argc, argv);

 Gtk::Window window;
 CustomDrawingArea my_widget(200,200);

 window.add(my_widget);

 window.show_all();

 gtk_main.run(window);

 return 0;
}

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list





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