[gtkmm-documentation] Application example: Use ExampleApplication via RefPtr.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Application example: Use ExampleApplication via RefPtr.
- Date: Tue, 18 Jan 2011 22:16:26 +0000 (UTC)
commit 780c1884844c5b281706e797a5f3fd63ced04d4a
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Jan 18 23:16:17 2011 +0100
Application example: Use ExampleApplication via RefPtr.
* examples/book/application/exampleapplication.[h|cc]: Make the constructor
protected and add a create() method.
* examples/book/application/main.cc: Use ExampleApplication via RefPtr,
because that is how Gtk::Application should be used.
ChangeLog | 9 +++++++++
examples/book/application/exampleapplication.cc | 10 ++++++++--
examples/book/application/exampleapplication.h | 8 ++++++--
examples/book/application/main.cc | 10 +++++-----
4 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6ad4592..802d060 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2011-01-18 Murray Cumming <murrayc murrayc com>
+ Application example: Use ExampleApplication via RefPtr.
+
+ * examples/book/application/exampleapplication.[h|cc]: Make the constructor
+ protected and add a create() method.
+ * examples/book/application/main.cc: Use ExampleApplication via RefPtr,
+ because that is how Gtk::Application should be used.
+
+2011-01-18 Murray Cumming <murrayc murrayc com>
+
Application example: Added comments.
* examples/book/application/exampleapplication.cc:
diff --git a/examples/book/application/exampleapplication.cc b/examples/book/application/exampleapplication.cc
index a23a5c8..62fa783 100644
--- a/examples/book/application/exampleapplication.cc
+++ b/examples/book/application/exampleapplication.cc
@@ -18,11 +18,17 @@
#include "examplewindow.h"
#include <iostream>
-ExampleApplication::ExampleApplication(const Glib::ustring& appid, Gio::ApplicationFlags flags)
-: Gtk::Application(appid, flags)
+ExampleApplication::ExampleApplication(const Glib::ustring& application_id, Gio::ApplicationFlags flags)
+: Gtk::Application(application_id, flags)
{
}
+Glib::RefPtr<ExampleApplication> ExampleApplication::create(const Glib::ustring& application_id,
+ Gio::ApplicationFlags flags)
+{
+ return Glib::RefPtr<ExampleApplication>( new ExampleApplication(application_id, flags) );
+}
+
void ExampleApplication::create_window(const Glib::RefPtr<Gio::File>& file)
{
Gtk::Window* window = new ExampleWindow(file);
diff --git a/examples/book/application/exampleapplication.h b/examples/book/application/exampleapplication.h
index 3841c86..cdea1e6 100644
--- a/examples/book/application/exampleapplication.h
+++ b/examples/book/application/exampleapplication.h
@@ -21,10 +21,14 @@
class ExampleApplication: public Gtk::Application
{
-public:
- explicit ExampleApplication(const Glib::ustring& appid,
+protected:
+ explicit ExampleApplication(const Glib::ustring& application_id,
Gio::ApplicationFlags flags = Gio::APPLICATION_FLAGS_NONE);
+public:
+ static Glib::RefPtr<ExampleApplication> create(const Glib::ustring& application_id,
+ Gio::ApplicationFlags flags = Gio::APPLICATION_FLAGS_NONE);
+
protected:
//Overrides of default signal handlers:
virtual void on_activate();
diff --git a/examples/book/application/main.cc b/examples/book/application/main.cc
index 2089d3a..d5770d6 100644
--- a/examples/book/application/main.cc
+++ b/examples/book/application/main.cc
@@ -29,15 +29,15 @@ int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv); //TODO: Make this unnecessary: Put it in Gtk::Application.
- ExampleApplication application(
- "org.gtkmm.examples.application",
- Gio::APPLICATION_HANDLES_OPEN);
- application.signal_open().connect( sigc::ptr_fun(on_open) );
+ Glib::RefPtr<ExampleApplication> application =
+ ExampleApplication::create("org.gtkmm.examples.application",
+ Gio::APPLICATION_HANDLES_OPEN);
+ application->signal_open().connect( sigc::ptr_fun(on_open) );
// Start the application, showing the initial window,
// and opening extra windows for any files that it is asked to open,
// for instance as a command-line parameter.
// run() will return when the last window has been closed by the user.
- const int status = application.run(argc, argv);
+ const int status = application->run(argc, argv);
return status;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]