[gtkmm] Application: Avoid the need to use Gtk::Main.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Application: Avoid the need to use Gtk::Main.
- Date: Mon, 13 Feb 2012 08:54:05 +0000 (UTC)
commit 7e892726fee50411166b19521d3cf9de249f099a
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Feb 10 13:07:48 2012 +0100
Application: Avoid the need to use Gtk::Main.
* gtk/src/application.[hg|cc]: Add an init_gtkmm() method, for use in
the create() methods of derived Application classes. This is necessary
to allow the Application constructor to succeed, because it uses
g_object_new().
create(): Use it here too, though I wonder if anyone would actually use
Gtk::Application without deriving.
This lets developers no use Gtk::Main at all, as long as they call their
Application's create() method at the same early point in their code.
This does not allow the developer to defer GTK+ initialization to when they
call g_application_run(), and even to avoid GTK+ initialization compeletely
in the local instance, as is possible with the C API, but we did not allow
that before either.
ChangeLog | 18 ++++++++++++++++++
gtk/src/application.ccg | 28 ++++++++++++++++++++++++++++
gtk/src/application.hg | 17 ++++++++++++++---
3 files changed, 60 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 979d4be..531509a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2012-02-10 Murray Cumming <murrayc murrayc com>
+
+ Application: Avoid the need to use Gtk::Main.
+
+ * gtk/src/application.[hg|cc]: Add an init_gtkmm() method, for use in
+ the create() methods of derived Application classes. This is necessary
+ to allow the Application constructor to succeed, because it uses
+ g_object_new().
+ create(): Use it here too, though I wonder if anyone would actually use
+ Gtk::Application without deriving.
+ This lets developers no use Gtk::Main at all, as long as they call their
+ Application's create() method at the same early point in their code.
+
+ This does not allow the developer to defer GTK+ initialization to when they
+ call g_application_run(), and even to avoid GTK+ initialization compeletely
+ in the local instance, as is possible with the C API, but we did not allow
+ that before either.
+
2012-02-08 Josà Alburquerque <jaalburquerque gmail com>
ActionGroup: Restore accidentally removed signal.
diff --git a/gtk/src/application.ccg b/gtk/src/application.ccg
index 7ae968c..58124fc 100644
--- a/gtk/src/application.ccg
+++ b/gtk/src/application.ccg
@@ -34,6 +34,7 @@
namespace Gtk
{
+
static void init_gtkmm_internals()
{
static bool init_done = false;
@@ -81,10 +82,37 @@ Application::Application(int argc, char** argv, const Glib::ustring& application
m_argc(argc),
m_argv(argv)
{
+}
+
+Glib::RefPtr<Application> Application::create(const Glib::ustring& application_id, Gio::ApplicationFlags flags)
+{
+ //Let the constructor succeed:
+ init_gtkmm();
+
+ return Glib::RefPtr<Application>( new Application(application_id, flags) );
+}
+
+Glib::RefPtr<Application> Application::create(int argc, char** argv, const Glib::ustring& application_id, Gio::ApplicationFlags flags)
+{
+ //Let the constructor succeed:
+ init_gtkmm(argc, argv);
+
+ return Glib::RefPtr<Application>( new Application(argc, argv, application_id, flags) );
+}
+
+void Application::init_gtkmm()
+{
+ gtk_init(0, 0);
+ init_gtkmm_internals();
+}
+
+void Application::init_gtkmm(int& argc, char**& argv)
+{
gtk_init(&argc, &argv);
init_gtkmm_internals();
}
+
void Application::on_activate_showwindow()
{
if(m_main_window)
diff --git a/gtk/src/application.hg b/gtk/src/application.hg
index 1b538e0..b4e10e8 100644
--- a/gtk/src/application.hg
+++ b/gtk/src/application.hg
@@ -67,10 +67,9 @@ protected:
public:
-#m4 _CONVERSION(`Gio::ApplicationFlags',`GApplicationFlags',`(GApplicationFlags)($3)')
- _WRAP_CREATE(const Glib::ustring& application_id, Gio::ApplicationFlags flags = Gio::APPLICATION_FLAGS_NONE)
+ Glib::RefPtr<Application> create(const Glib::ustring& application_id, Gio::ApplicationFlags flags = Gio::APPLICATION_FLAGS_NONE);
- _WRAP_CREATE(int argc, char** argv, const Glib::ustring& application_id, Gio::ApplicationFlags flags = Gio::APPLICATION_FLAGS_NONE)
+ Glib::RefPtr<Application> create(int argc, char** argv, const Glib::ustring& application_id, Gio::ApplicationFlags flags = Gio::APPLICATION_FLAGS_NONE);
#m4 _CONVERSION(`GList*',`std::vector<Window*>',`Glib::ListHandler<Window*>::list_to_vector($3, Glib::OWNERSHIP_NONE)')
_WRAP_METHOD(std::vector<Window*> get_windows(), gtk_application_get_windows)
@@ -155,6 +154,18 @@ public:
* @newin{3,0}
*/
int run();
+
+protected:
+
+ /** Initialize GTK+ and gtkmm.
+ * This should be used by derived classes in their create() methods.
+ */
+ static void init_gtkmm();
+
+ /** Initialize GTK+ and gtkmm.
+ * This should be used by derived classes in their create() methods.
+ */
+ static void init_gtkmm(int& argc, char**& argv);
private:
/** This is just a way to call Glib::init() (which calls g_type_init()) before
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]