Multi-window applications in gtkmm
- From: Joaquim Duran <joaquinduran adtelecom es>
- To: gtkmm-list gnome org
- Subject: Multi-window applications in gtkmm
- Date: Fri, 27 Jul 2007 10:58:11 +0200
Dear all,
As far I remember, some days ago someone asked if it is possible to
develop multi-window applications based on gtkmm, it get the answer that
a Notebook should be used (sorry, I haven't found the original messages).
I've written a small sample program to show the use of a very simple
multiple window applications.
I hope that in new versions of gtkmm, this feature will be included in
the library.
Thanks and Best Regards,
Joaquim Duran
#include <gtkmm.h>
#include <vector>
#include <iostream>
class MainWindow;
// TopWindow
class TopWindow: public Gtk::Window
{
public:
TopWindow(MainWindow &win);
virtual ~TopWindow();
protected:
virtual void onCloseBttnClicked();
private:
Gtk::Button close;
MainWindow *mw;
};
// Main Window
class MainWindow: public Gtk::Window
{
public:
MainWindow();
virtual ~MainWindow();
void closeTopWindow(TopWindow &twin);
protected:
void onNewBttnClicked();
private:
typedef std::vector<TopWindow*> vectTpWin;
vectTpWin topWins;
Gtk::Button btNew;
};
// Top Window Memeber Functions
TopWindow::TopWindow(MainWindow &win):
close("Close"),
mw(&win)
{
add(close);
close.signal_clicked().connect( sigc::mem_fun(*this,
&TopWindow::onCloseBttnClicked) );
set_title("TopWindow");
set_keep_above();
show_all_children();
}
TopWindow::~TopWindow()
{
}
void TopWindow::onCloseBttnClicked()
{
mw->closeTopWindow(*this);
}
// Main Windows member functions
MainWindow::MainWindow():
topWins(), btNew("New Top Window")
{
add(btNew);
btNew.signal_clicked().connect( sigc::mem_fun(*this,
&MainWindow::onNewBttnClicked) );
set_sensitive(true);
set_title("MainWindow");
show_all_children();
}
MainWindow::~MainWindow()
{
vectTpWin::iterator i = topWins.begin();
for (;i != topWins.end(); i++)
{
(*i)->hide();
delete(*i);
}
}
void MainWindow::onNewBttnClicked()
{
TopWindow* win = new TopWindow(*this);
topWins.push_back(win);
win->show();
}
void MainWindow::closeTopWindow(TopWindow &win)
{
#if 1
vectTpWin::iterator i =
std::find(topWins.begin(), topWins.end(), &win);
#else
vectTpWin::iterator i = topWins.begin();
while (i != topWins.end())
{
if ((*i) != &win)
{
i++;
}
else
{
break;
}
}
#endif
if (i == topWins.end())
{
std::cerr << "Ref window not found" << std::endl;
::exit(1);
}
(*i)->hide();
delete(*i);
topWins.erase(i);
}
// Main
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
MainWindow mwin;
mwin.show();
kit.run(mwin);
// TestWindow *tw = Gtk::Manage
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]