Skip to content

Commit

Permalink
Deprecate Gtk::Main in favor of Gtk::Application.
Browse files Browse the repository at this point in the history
* gtk/src/main.[hg|ccg]: Deprecate most of this API.
* demos/gtk-demo/example_change_display.cc:
* demos/gtk-demo/main.cc: Use Gtk::Application instead of Gtk::Main.
  • Loading branch information
murraycu committed Mar 3, 2012
1 parent db626c9 commit e8fa79e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 23 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
2012-03-02 Murray Cumming <murrayc@murrayc.com>

Deprecate Gtk::Main in favor of Gtk::Application.

* gtk/src/main.[hg|ccg]: Deprecate most of this API.
* demos/gtk-demo/example_change_display.cc:
* demos/gtk-demo/main.cc: Use Gtk::Application instead of Gtk::Main.

2012-03-02 Murray Cumming <murrayc@murrayc.com>

ColorSelection*: Document these as deprecated.
Expand Down
6 changes: 3 additions & 3 deletions demos/gtk-demo/main.cc
Expand Up @@ -24,10 +24,10 @@

int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Glib::RefPtr<Gtk::Application> app =
Gtk::Application::create(argc, argv, "org.gtkmm.demos.demo");

DemoWindow window;

kit.run(window);
return 0;
return app->run(window);
}
6 changes: 3 additions & 3 deletions demos/pixbuf-demo.cc
Expand Up @@ -192,20 +192,20 @@ int main(int argc, char** argv)
{
try
{
Gtk::Main main_instance (&argc, &argv);
Glib::RefPtr<Gtk::Application> app =
Gtk::Application::create(argc, argv, "org.gtkmm.demos.pixbuf-demo");

Gtk::Window window;
window.add(*Gtk::manage(new DemoRenderArea()));

window.set_resizable(false);
window.show_all();

Gtk::Main::run(window);
return app->run(window);
}
catch(const Glib::Error& error)
{
std::cerr << error.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
19 changes: 12 additions & 7 deletions gtk/src/main.ccg
Expand Up @@ -33,6 +33,8 @@
#include <gdkmm/wrap_init.h>
#include <gtkmm/wrap_init.h>

_DEPRECATE_IFDEF_START

namespace
{

Expand Down Expand Up @@ -202,6 +204,8 @@ void GtkMainConnectionNode::list_notify_all()

} // anonymous namespace

_DEPRECATE_IFDEF_END


namespace Gtk
{
Expand Down Expand Up @@ -239,17 +243,12 @@ gint KeySnooperSig::gtk_callback(GtkWidget* widget, GdkEventKey* event, gpointer
return 0;
}

_DEPRECATE_IFDEF_END

/**** Gtk::Main -- static data *********************************************/

_DEPRECATE_IFDEF_START
KeySnooperSig Main::signal_key_snooper_;
_DEPRECATE_IFDEF_END

Main* Main::instance_ = 0;


/**** Gtk::Main -- construction/destruction ********************************/

Main::Main(int& argc, char**& argv, bool set_locale)
Expand Down Expand Up @@ -394,16 +393,19 @@ guint Main::level()
return instance_->level_impl();
}

_DEPRECATE_IFDEF_END

bool Main::iteration(bool blocking)
{
return instance_->iteration_impl(blocking);
return gtk_main_iteration_do(blocking);
}

bool Main::events_pending()
{
return instance_->events_pending_impl();
return gtk_events_pending();
}

_DEPRECATE_IFDEF_START

/**** Gtk::Main -- static signal accessors *********************************/

Expand Down Expand Up @@ -445,5 +447,8 @@ void Main::on_window_hide()
quit_impl();
}

_DEPRECATE_IFDEF_END

} /* namespace Gtk */


57 changes: 47 additions & 10 deletions gtk/src/main.hg
Expand Up @@ -33,10 +33,11 @@ _DEFS(gtkmm,gtk)
#define GDK_DISABLE_DEPRECATION_WARNINGS 1
#m4 _POP()


namespace Gtk
{

_DEPRECATE_IFDEF_START

class Widget;
class Window;

Expand All @@ -45,7 +46,7 @@ class Window;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
//Actually, I'd like to just keep these out of the alphabetical list. murrayc.

_DEPRECATE_IFDEF_START

/// KeySnooper Signal Class (internal)
class KeySnooperSig
{
Expand All @@ -57,10 +58,11 @@ public:
protected:
static int gtk_callback(GtkWidget* widget, GdkEventKey* event, gpointer data);
};
_DEPRECATE_IFDEF_END

#endif /* DOXYGEN_SHOULD_SKIP_THIS */

_DEPRECATE_IFDEF_END


//**********************************************************************

Expand All @@ -85,11 +87,14 @@ _DEPRECATE_IFDEF_END
* kit.run(window);
* }
* @endcode
*
* @deprecated Use Gtk::Application instead.
*/
class Main : public sigc::trackable
{
public:

_DEPRECATE_IFDEF_START
//This offers the same functionality as gtk_init_with_args():
/** Scans the argument vector, and strips off all parameters parsed by GTK+ or your @a option_context.
* Add a Glib::OptionGroup to the Glib::OptionContext to parse your own command-line arguments.
Expand All @@ -110,6 +115,8 @@ public:
* @param option_context A Glib::OptionContext containing Glib::OptionGroups which described the command-line arguments taken by your program.
*
* @throw Glib::OptionError
*
* @deprecated Use Gtk::Application instead.
*/
Main(int& argc, char**& argv, Glib::OptionContext& option_context);

Expand All @@ -127,6 +134,8 @@ public:
* setlocale(LC_ALL, ""). You would want to pass false if you wanted to set
* the locale for your program to something other than the user's locale, or
* if you wanted to set different values for different locale categories.
*
* @deprecated Use Gtk::Application instead.
*/
Main(int* argc, char*** argv, bool set_locale = true);

Expand All @@ -139,6 +148,8 @@ public:
* setlocale(LC_ALL, ""). You would want to pass false if you wanted to set
* the locale for your program to something other than the user's locale, or
* if you wanted to set different values for different locale categories.
*
* @deprecated Use Gtk::Application instead.
*/
Main(int& argc, char**& argv, bool set_locale = true);

Expand All @@ -148,19 +159,28 @@ public:
* setlocale(LC_ALL, ""). You would want to pass false if you wanted to set
* the locale for your program to something other than the user's locale, or
* if you wanted to set different values for different locale categories.
*
* @deprecated Use Gtk::Application instead.
*/
explicit Main(bool set_locale = true);


/**
* @deprecated Use Gtk::Application instead.
*/
virtual ~Main();

/// Access to the one global instance of Gtk::Main.
/** Access to the one global instance of Gtk::Main.
*
* @deprecated Use Gtk::Application instead.
*/
static Gtk::Main* instance();

/** Start the event loop.
* This begins the event loop which handles events. No
* events propagate until this has been called. It may be
* called recursively to popup dialogs
*
* @deprecated Use Gtk::Application instead.
*/
static void run();

Expand All @@ -169,13 +189,20 @@ public:
* the application, but just call hide() on your Window class.
*
* @param window The window to show. This method will return when the window is hidden.
*
* @deprecated Use Gtk::Application instead.
*/
static void run(Window& window);

/** Makes the innermost invocation of the main loop return when it regains control.
*
* @deprecated Use Gtk::Application instead.
*/
static void quit();

/**
* @deprecated Use Gtk::Application instead.
*/
static guint level();

//This attempts to provide the same functionality as gtk_get_option_group():
Expand All @@ -188,9 +215,14 @@ public:
*
* @param option_context Option Context to which the group will be added.
* @param open_default_display Whether to open the default display when parsing the commandline arguments.
*
* @deprecated Use Gtk::Application instead.
*/
static void add_gtk_option_group(Glib::OptionContext& option_context, bool open_default_display = true);

_DEPRECATE_IFDEF_END


/** Runs a single iteration of the main loop.
* If no events are waiting to be processed GTK+ will block until the next event is noticed.
* If you don't want to block then pass false for @a blocking or check if any events are pending with
Expand All @@ -217,6 +249,7 @@ public:
static bool events_pending();

_DEPRECATE_IFDEF_START

/** KeySnooper signal
* Allows you to channel keypresses to a signal handler
* without registering with the widget.
Expand All @@ -230,14 +263,19 @@ _DEPRECATE_IFDEF_START
* @deprecated Key snooping should not be done. Events should be handled by widgets.
*/
static KeySnooperSig& signal_key_snooper();
_DEPRECATE_IFDEF_END

// Initialize table of wrap_new functions.
// Doesn't need an instance of Gtk::Main.
/** Initialize the table of wrap_new functions.
* This doesn't need an instance of Gtk::Main.
*
* @deprecated Use Gtk::Application instead.
*/
static void init_gtkmm_internals();

_DEPRECATE_IFDEF_END

protected:

_DEPRECATE_IFDEF_START
void init(int* argc, char*** argv, bool set_locale);
// TODO: implement this to use the new Glib::OptionEntry argument parsing classes.
//void init(int* argc, char*** argv, const std::string& parameter_string, const std::vector<const Glib::OptionEntry&>& entries, const std::string& translation_domain);
Expand All @@ -251,13 +289,12 @@ protected:
// Signal handlers:
virtual void on_window_hide();

_DEPRECATE_IFDEF_START
// Signal proxies:
static KeySnooperSig signal_key_snooper_;
_DEPRECATE_IFDEF_END

private:
static Main* instance_;
_DEPRECATE_IFDEF_END
};

} // namespace Gtk
Expand Down

0 comments on commit e8fa79e

Please sign in to comment.