RE: best way to use multiple windows

2005-07-19 Thread Foster, Gareth
 Isn't that dangerous if exceptions are thrown? Why not let 
 the compiler
 do the dirty work? Remember that just the gtkmm instances like a
 Gtk::Dialog are created on the stack, but they create their 
 underlaying
 GTK+ objects on the heap. This method seems to be the C++ way for me.
 
 But if you like using dynamically allocated memory here, go on. I just
 wanted to add another alternative how to display popup dialogs :)
 

C 

1, You shoot yourself in the foot. 2,   You shoot yourself in the foot and
then no one else can figure out what you did.


C++

You accidentially create a dozen instances of yourself and shoot them all in
the foot. Providing emergency medical assistance is impossible since you
can't tell which are bitwise copies and which are just pointing at others
and saying, That's me, over there.
___
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: best way to use multiple windows

2005-07-18 Thread John Taber
Well, it is heap vs stack - I am not sure which is really better for 
normal gui applications.  But I have always created my dialogs as 
pointers - it just seems more traditional c++.


MyPopupDialog *dlg = new MyPopupDialog(...) {
//set dialog to modal (but it can sometimes get hidden by other
// dialog which is annoying
// set up dialog display here
// let okay/cancel buttons set return variable flag and hide dialog
onokaybutton() {
returnFlag = 1;
dlg-hide();
}
// if flag true can have code engine or main dialog still read
// values from popup dlg here
delete dlg;

I find it is not too difficult to match the delete with the new.


Armin Burgmeier wrote:

Hi,

my approach to this is to derive such windows from Gtk::Dialog and to
add two buttons with Gtk::RESPONSE_OK and Gtk::RESPONSE_CANCEL. To show
the dialog, simply do

MyDialog dialog(*this, foo, bar);
if(dialog.run() == Gtk::RESPONSE_OK)
{
  // Take settings into main app
}

Gtk::Dialog::run blocks in a main loop until the user closes the window
by either pressing one of the buttons or closing the window (which fits
perfectly if you want modal windows). After your function returns, the
dialog will be destroyed automatically as it runs out of scope, so you
do not have to worry about memory management.

 - Armin
___
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



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


Re: best way to use multiple windows

2005-07-18 Thread John Taber

Armin Burgmeier wrote:

John Taber wrote:


Well, it is heap vs stack - I am not sure which is really better for
normal gui applications.  But I have always created my dialogs as
pointers - it just seems more traditional c++.


Isn't that dangerous if exceptions are thrown? Why not let the compiler


Yeah, I think c++ in general is pretty dangerous:)  And I guess that's 
why there is java and C#.  I'm always open to better ideas.  Whatever is 
the fastest, simplest, cleanest.  We've always called all our widgets 
with pointers as well, since we've never really taken the time to figure 
out what the memory hit is, especially if there are a few layers of 
dialogs open as per the original question in the thread and not sure 
what happens if one of the widgets is a 500 mb image.  But your idea of 
the dialog container on stack but widgets on heap would be efficient if 
it doesn't cause other problems - and I guess you're saying gtkmm takes 
care of that.

John




do the dirty work? Remember that just the gtkmm instances like a
Gtk::Dialog are created on the stack, but they create their underlaying
GTK+ objects on the heap. This method seems to be the C++ way for me.

But if you like using dynamically allocated memory here, go on. I just
wanted to add another alternative how to display popup dialogs :)

 - Armin
___
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



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


Re: best way to use multiple windows

2005-07-18 Thread Armin Burgmeier
John Taber wrote:
 Well, it is heap vs stack - I am not sure which is really better for
 normal gui applications.  But I have always created my dialogs as
 pointers - it just seems more traditional c++.
Isn't that dangerous if exceptions are thrown? Why not let the compiler
do the dirty work? Remember that just the gtkmm instances like a
Gtk::Dialog are created on the stack, but they create their underlaying
GTK+ objects on the heap. This method seems to be the C++ way for me.

But if you like using dynamically allocated memory here, go on. I just
wanted to add another alternative how to display popup dialogs :)

 - Armin
___
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: best way to use multiple windows

2005-07-17 Thread Antonio Coralles
Thiago Guzella wrote:

 Greetings everyone,


 I am writing a simple GTKmm (btw, GTKmm 2.4) application, which has a
 main window, a menu, etc, using glade (just to place the widgets).
 Some options in the menu (such as preferences) are required to open
 a modal window, with apply and revert buttons, allowing the user to
 tweak the app; pretty straightforward :)

 My question is: what is the best way to implement such feature? should
 i make the preferences window a member variable of the main window
 class, create it (i.e.: alloc memory) when it is requested?? if so,
 how should i handle the window closing? my first guess would be to
 send a signal to the main window to hide the preferences window and
 release the memory used by it, so that the main window will regain
 focus.

Well, my approach to this problem is to make all subwindows normal
member-varables of their parents. This may result in some memory
overhead, but it keeps things simple, especially, when your subwindow
communicates with your parent via sigc::signals. The application i'm
working on has dozens of subwindows and needs about 20 MB of memory when
no file is opened, while a  a completly plain window, without a single
button, box or something else, needs slightly more than 14MB on my system.

Thus, i think it may be too much work with too little advantages to
new/delete your subwindows as needed, allthhough this still remains
interesting. Maybe someone with more insights to gtkmm/gtk internals
than me can give us some advise. If i would implement such a behavour,
my first try would be to override on_hide() like this [that is just a
guess, never tried it]

void SubWindow::on_hide()
{
   Gtk::Window::on_hide();
   m_sig_hide.emit(); //you parent should connect to this signal and
delete your window
}

However, i would not be surprised if that leads to a SIGSEGV, as the
window, and m_sig_hide will be deleted before the function exits 

Antonio
___
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: best way to use multiple windows

2005-07-17 Thread Murray Cumming
On Sun, 2005-07-17 at 18:31 +0200, Antonio Coralles wrote:
 However, i would not be surprised if that leads to a SIGSEGV, as the
 window, and m_sig_hide will be deleted before the function exits 

libsigc++ copes with that.

-- 
Murray Cumming
[EMAIL PROTECTED]
www.murrayc.com
www.openismus.com

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


Re: best way to use multiple windows

2005-07-17 Thread Armin Burgmeier
Hi,

my approach to this is to derive such windows from Gtk::Dialog and to
add two buttons with Gtk::RESPONSE_OK and Gtk::RESPONSE_CANCEL. To show
the dialog, simply do

MyDialog dialog(*this, foo, bar);
if(dialog.run() == Gtk::RESPONSE_OK)
{
  // Take settings into main app
}

Gtk::Dialog::run blocks in a main loop until the user closes the window
by either pressing one of the buttons or closing the window (which fits
perfectly if you want modal windows). After your function returns, the
dialog will be destroyed automatically as it runs out of scope, so you
do not have to worry about memory management.

 - Armin
___
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list