RE: [gtkmm] Child Windows?



I am only a few weeks ahead of you in using gtkmm, but I will try to answer
the questions below.  Someone else may want to jump in if my answers are
wrong!

--Howdy

  =============================
  Howdy Pierce
  Cardinal Peak, LLC

  email: howdy cardinalpeak com
  work: (303) 665-3962
  =============================

> -----Original Message-----
> From: gtkmm-list-admin gnome org [mailto:gtkmm-list-admin gnome org]On
> Behalf Of Gene Ruebsamen
> Sent: Monday, March 10, 2003 2:42 PM
> To: gtkmm-list gnome org
> Subject: [gtkmm] Child Windows?
>
>
> Hello,
>
> I am new to Gtkmm, so please go easy on me.
>
> I work for a large corporation, and we are evaluating Gtk+2.2 as
> our Graphical
> toolkit. I am starting to learn Gtkmm, and though the
> documentation is sparse,
> the API is fairly clear and easy to follow.  I do, however, have
> several basic
> questions that seem to not be addressed in the documentation.
>
> I am working an an application that currently has one main
> Gtk::Window class;
> however, this application needs to have alot of user custimizable
> options.  My
> original thinking was that the user would click on a button that
> brings up a
> new instance of my Options class (which is derived from
> Gtk::Window); however,
> I have been running into problems with having two instances of
> Gtk::Window (the
> main app window and the options window) and have some questions
> that hopefully
> someone can answer for me:
>
> (1) What is the proper way to display a user "Options" window?
> Should I create
> a new class inherited from Gtk::Dialog? Or is it okay to have two
> instances of
> Gtk::Window?

I don't know what you're doing exactly that causes problems with the second
window, but in general that should work.  I have many windows -- up to 5 or
6 visible at any one time.  For each window, I derive a window class (in
your case maybe the OptionsDialog class) from Gtk::Window.

To cause the Options window to appear, just instantiate a object of its
class.  Typically I do this in a signal handler which is a member function
of the main window:

  	OptionsDialog *my_options_dialog = new OptionsDialog(this);

	// note this function will display the dialog and return immediately
	// as a result, you need to do this on the heap and not the stack,
	//  otherwise the options dialog will appear and disappear immediately
	//  as the object is created and immediately destroyed


The constructor for OptionsDialog has a signature like:

	OptionsDialog( MainWindow *parent )

...with maybe some extra arguments depending on your application.

What you probably want is to have the new window centered on its parent, the
main window; to do this, add the following code snippets in the
OptionsDialog constructor:

	// .. create child widgets, call child->show() on each

	// this positions the dialog on its parent and causes it to appear
	set_transient_for(*parent);
	set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG);
	set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
	show();

Finally, you need to be able to destroy the OptionsDialog object when the
user closes the window.  To do this, you call "delete this" from within an
OptionsDialog member function.  For a typical dialog, you will want to hook
up three signal handlers:

 	void OptionsDialog::on_ok_clicked()
	{
		// .. do something here to process the data in the dialog

		delete this;
	}

	void OptionsDialog::on_cancel_clicked()
	{
		// do nothing, user canceled
		delete this;
	}

	bool OptionsDialog::on_window_delete_event(GdkEventAny *ev)
	{
		// user clicked the WM close button; same as cancel
		delete this;
		return true;
	}

> (2) If it is ok to have two instances of Gtk::Window, how can I force the
> options window to be the child of the main application window,
> and why can't I
> show the 2nd Gtk::Window instance??

Yes, it's ok.  I don't know why it isn't working for you -- would need to
see the code.  Hopefully the above helps.

> (3) Are there any other resources for
> information/tutorials/documentation on
> Gtkmm-2.2 other than the main Gtkmm website?

I've found the website to be ok: the information is usually there, although
frequently obtuse.  I'm not bitching though, since I don't want to spend
time writing it myself ;-)

You should understand that gtkmm is a C++ wrapper around gtk, so sometimes
it helps to read the gtk documentation also (available at
http://developer.gnome.org/doc/API/2.0/gtk/index.html )

>
> Thanks in Advance!
>
> --
> Gene Ruebsamen
>
>
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
> _______________________________________________
> 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]