[gtkmm-documentation] Add Gtk::Application example
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Add Gtk::Application example
- Date: Thu, 23 Dec 2010 19:22:08 +0000 (UTC)
commit a702f21f326af5aec9fe79b9b996a25d02a7f6ca
Author: Yannick Guesnet <yannick guesnet univ-rouen fr>
Date: Thu Dec 23 15:21:29 2010 +0100
Add Gtk::Application example
* examples/book/application/exampleapplication.cc: new
* examples/book/application/examplewindow.cc: new
* examples/book/application/main.cc: new
* examples/book/application/exampleapplication.h: new
* examples/book/application/examplewindow.h: new
* examples/Makefile.am: Adapted.
ChangeLog | 19 ++++++++
examples/Makefile.am | 12 ++++-
examples/book/application/exampleapplication.cc | 51 ++++++++++++++++++++++
examples/book/application/exampleapplication.h | 37 ++++++++++++++++
examples/book/application/examplewindow.cc | 53 +++++++++++++++++++++++
examples/book/application/examplewindow.h | 32 ++++++++++++++
examples/book/application/main.cc | 37 ++++++++++++++++
7 files changed, 239 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8057618..de03250 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2010-12-23 Murray Cumming <murrayc murrayc com>
+
+ Fix the build with --enable-warnings=fatal.
+
+ * configure.ac: Use -no-long-long to avoid an (apparently new) compiler
+ warning about long long not being supported by C++98. glibmm already had
+ this option, and now gtkmm does too.
+
+2010-12-23 Yannick Guesnet <yannick guesnet univ-rouen fr>
+
+ Add Gtk::Application example
+
+ * examples/book/application/exampleapplication.cc: new
+ * examples/book/application/examplewindow.cc: new
+ * examples/book/application/main.cc: new
+ * examples/book/application/exampleapplication.h: new
+ * examples/book/application/examplewindow.h: new
+ * examples/Makefile.am: Adapted.
+
2010-12-23 Chris Kühl <chrisk openismus com>
Fixed a couple typos in the tutorial.
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 05e88f8..c848792 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -8,9 +8,10 @@ LDADD = $(GTKMM_LIBS)
check_PROGRAMS = \
book/alignment/example \
+ book/application/example \
book/aspectframe/example \
book/assistant/example \
- book/base/base \
+ book/base/base \
book/box/example \
book/builder/basic/example \
book/builder/derived/example \
@@ -25,7 +26,7 @@ check_PROGRAMS = \
book/combobox/complex/example \
book/combobox/text/example \
book/combobox/entry_complex/example \
- book/combobox/entry_text/example \
+ book/combobox/entry_text/example \
book/custom/custom_container/example \
book/custom/custom_widget/example \
book/dialogs/aboutdialog/example \
@@ -126,6 +127,13 @@ dist_noinst_DATA = \
book/iconview/xmms.xpm \
book/menus_and_toolbars/rain.png
+book_application_example_SOURCES = \
+ book/application/exampleapplication.cc \
+ book/application/exampleapplication.h \
+ book/application/examplewindow.cc \
+ book/application/examplewindow.h \
+ book/application/main.cc
+
book_alignment_example_SOURCES = \
book/alignment/examplewindow.cc \
book/alignment/examplewindow.h \
diff --git a/examples/book/application/exampleapplication.cc b/examples/book/application/exampleapplication.cc
new file mode 100644
index 0000000..bc24e3f
--- /dev/null
+++ b/examples/book/application/exampleapplication.cc
@@ -0,0 +1,51 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "exampleapplication.h"
+#include "examplewindow.h"
+
+ExampleApplication::ExampleApplication(const Glib::ustring& appid, Gio::ApplicationFlags flags)
+: Gtk::Application(appid, flags)
+{
+}
+
+void ExampleApplication::new_window(const Glib::RefPtr<Gio::File>& file)
+{
+ Gtk::Window* window = new ExampleWindow(file);
+ add_window(*window);
+ window->signal_hide().connect(sigc::bind<Gtk::Window*>(sigc::mem_fun(*this,
+ &ExampleApplication::on_window_hide), window));
+ window->show();
+}
+
+void ExampleApplication::on_window_hide(Gtk::Window* window)
+{
+ delete window;
+}
+
+void ExampleApplication::on_activate()
+{
+ new_window(Glib::RefPtr<Gio::File>());
+}
+
+void ExampleApplication::on_open(const Gio::Application::type_vec_files& files,
+ const Glib::ustring& hint)
+{
+ for (unsigned int i = 0; i < files.size(); i++)
+ {
+ new_window(files[i]);
+ }
+}
diff --git a/examples/book/application/exampleapplication.h b/examples/book/application/exampleapplication.h
new file mode 100644
index 0000000..115f10a
--- /dev/null
+++ b/examples/book/application/exampleapplication.h
@@ -0,0 +1,37 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEAPPLICATION_H
+#define GTKMM_EXAMPLEAPPLICATION_H
+
+#include <gtkmm.h>
+
+class ExampleApplication: public Gtk::Application
+{
+public:
+ explicit ExampleApplication(const Glib::ustring& appid, Gio::ApplicationFlags flags =
+ Gio::APPLICATION_FLAGS_NONE);
+ void new_window(const Glib::RefPtr<Gio::File>& file);
+
+protected:
+ void on_activate();
+ void on_open(const Gio::Application::type_vec_files& files,
+ const Glib::ustring& hint);
+
+ void on_window_hide(Gtk::Window* window);
+};
+
+#endif /* GTKMM_EXAMPLEAPPLICATION_H */
diff --git a/examples/book/application/examplewindow.cc b/examples/book/application/examplewindow.cc
new file mode 100644
index 0000000..b2f6443
--- /dev/null
+++ b/examples/book/application/examplewindow.cc
@@ -0,0 +1,53 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <iostream>
+
+#include "examplewindow.h"
+
+ExampleWindow::ExampleWindow(const Glib::RefPtr<Gio::File>& file)
+{
+ set_title("Gio::Application example");
+
+ add(scrolled);
+ scrolled.add(view);
+
+ if (!file)
+ return;
+
+ try
+ {
+ char* contents = 0;
+ gsize length = 0;
+
+ if (file->load_contents(contents, length))
+ {
+ if(contents && length)
+ {
+ const Glib::ustring text(contents);
+ Glib::RefPtr<Gtk::TextBuffer> buffer;
+ buffer = view.get_buffer();
+ buffer->set_text(text);
+ }
+ g_free(contents);
+ }
+ } catch (const Glib::Error& e)
+ {
+ std::cerr << e.what() << std::endl;
+ };
+
+ show_all_children();
+}
diff --git a/examples/book/application/examplewindow.h b/examples/book/application/examplewindow.h
new file mode 100644
index 0000000..4f6cf92
--- /dev/null
+++ b/examples/book/application/examplewindow.h
@@ -0,0 +1,32 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H_
+#define GTKMM_EXAMPLEWINDOW_H_
+
+#include <gtkmm.h>
+
+class ExampleWindow: public Gtk::Window
+{
+public:
+ explicit ExampleWindow(const Glib::RefPtr<Gio::File>& file);
+
+private:
+ Gtk::ScrolledWindow scrolled;
+ Gtk::TextView view;
+};
+
+#endif /* GTKMM_EXAMPLEWINDOW_H */
diff --git a/examples/book/application/main.cc b/examples/book/application/main.cc
new file mode 100644
index 0000000..fbd3d57
--- /dev/null
+++ b/examples/book/application/main.cc
@@ -0,0 +1,37 @@
+/* gtkmm example Copyright (C) 2002 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <gtkmm.h>
+#include <iostream>
+
+#include "exampleapplication.h"
+
+void open(const Gio::Application::type_vec_files &files, const Glib::ustring& hint)
+{
+ std::cout << "signal open received" << std::endl;
+}
+
+int main(int argc, char *argv[])
+{
+ Gtk::Main kit(argc, argv);
+
+ ExampleApplication application("org.gtkmm.Test.bloatpad",
+ Gio::APPLICATION_HANDLES_OPEN);
+ application.signal_open().connect(sigc::ptr_fun(open));
+ int status = application.run(argc, argv);
+
+ return status;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]