# Gtk::Main Class Reference

Main application class. More...

Inheritance diagram for Gtk::Main:
[legend]
Collaboration diagram for Gtk::Main:
[legend]

List of all members.

## Public Member Functions

| Main (int& argc, char**& argv, Glib::OptionContext& option_context)
| Scans the argument vector, and strips off all parameters parsed by GTK+ or your option_context.
| Main (int* argc, char*** argv, bool set_locale=true)
| Scans the argument vector, and strips off all parameters known to GTK+.
| Main (int& argc, char**& argv, bool set_locale=true)
| Scans the argument vector, and strips off all parameters known to GTK+.
| Main (bool set_locale=true)
| Initialization without command-line arguments.
virtual | ~Main ()

## Static Public Member Functions

static Gtk::Main* | instance ()
| Access to the one global instance of Gtk::Main.
static void | run ()
| Start the event loop.
static void | run (Window& window)
| Returns from the main loop when the window is closed.
static void | quit ()
| Makes the innermost invocation of the main loop return when it regains control.
static guint | level ()
static void | add_gtk_option_group (Glib::OptionContext& option_context, bool open_default_display=true)
| Add a Glib::OptionGroup, for the commandline arguments recognized by GTK+ and GDK, to a Glib::OptionContext, so that these commandline arguments will be processed in addition to the existing commandline arguments specified by the Glib::OptionContext.
static bool | iteration (bool blocking=true)
| Runs a single iteration of the main loop.
static bool | events_pending ()
| Checks if any events are pending.
static KeySnooperSig& | signal_key_snooper ()
| KeySnooper signal Allows you to channel keypresses to a signal handler without registering with the widget.
static void | init_gtkmm_internals ()

## Protected Member Functions

void | init (int* argc, char*** argv, bool set_locale)
virtual void | run_impl ()
virtual void | quit_impl ()
virtual guint | level_impl ()
virtual bool | iteration_impl (bool blocking)
virtual bool | events_pending_impl ()
virtual void | on_window_hide ()

## Static Protected Attributes

static KeySnooperSig | signal_key_snooper_

## Detailed Description

Main application class.

Every application must have one of these objects. It may not be global and must be the first gtkmm object created. It is a singleton so declaring more than one will simply access the first created.

You would normally use this class in your main() function to initialize gtkmm and optionally to give argc and argv to the GTK+ initialization. After calling Gtk::Main::run(), you may use Gtk::Main::quit() to exit from the application, or just pass your main window to run(), to make run() return when that window closes.

A minimal gtkmm application would be something like this:

     int main(int argc, char *argv[])
     {
       Gtk::Main kit(argc, argv);
       ... create some widgets and windows...
       kit.run(window);
     }

## Constructor & Destructor Documentation

Gtk::Main::Main | ( | int & | argc,
|  | char **& | argv,
|  | Glib::OptionContext & | option_context
| ) |  |

Scans the argument vector, and strips off all parameters parsed by GTK+ or your option_context.

Add a Glib::OptionGroup to the Glib::OptionContext to parse your own command-line arguments.

Note: The argument strings themself won't be modified, although the pointers to them might change. This makes it possible to create your own argv of string literals, which have the type 'const char[]' in standard C++. (You might need to use const_cast<>, though.)

This function automatically generates nicely formatted <option>--help</option> output. Note that your program will be terminated after writing out the help output.

Parameters:

  argc | a reference to the number of command line arguments.
  argv | a reference to the array of command line arguments. a string which is displayed in the first line of <option>--help</option> output, after <literal><replaceable>programname</replaceable> [OPTION...]</literal>
  option_context | A Glib::OptionContext containing Glib::OptionGroups which described the command-line arguments taken by your program.

Exceptions:

  Glib::OptionError |

Gtk::Main::Main | ( | int * | argc,
|  | char *** | argv,
|  | bool | set_locale = `true`
| ) |  |

Scans the argument vector, and strips off all parameters known to GTK+.

Your application may then handle the remaining arguments.

Note: The argument strings themself won't be modified, although the pointers to them might change. This makes it possible to create your own argv of string literals, which have the type 'const char[]' in standard C++. (You might need to use const_cast<>, though.)

Parameters:

  argc | a pointer to the number of command line arguments.
  argv | a pointer to the array of command line arguments.
  set_locale | Passing false prevents GTK+ from automatically calling 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.

Gtk::Main::Main | ( | int & | argc,
|  | char **& | argv,
|  | bool | set_locale = `true`
| ) |  |

Scans the argument vector, and strips off all parameters known to GTK+.

Your application may then handle the remaining arguments.

Parameters:

  argc | a reference to the number of command line arguments.
  argv | a reference to the array of command line arguments.
  set_locale | Passing false prevents GTK+ from automatically calling 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.

Gtk::Main::Main | ( | bool | set_locale = `true` | ) | `[explicit]`

Initialization without command-line arguments.

Parameters:

  set_locale | Passing false prevents GTK+ from automatically calling 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.

virtual Gtk::Main::~Main | ( |  | ) | `[virtual]`

## Member Function Documentation

static void Gtk::Main::add_gtk_option_group | ( | Glib::OptionContext & | option_context,
|  | bool | open_default_display = `true`
| ) |  | `[static]`

Add a Glib::OptionGroup, for the commandline arguments recognized by GTK+ and GDK, to a Glib::OptionContext, so that these commandline arguments will be processed in addition to the existing commandline arguments specified by the Glib::OptionContext.

You do not need to use this method if you pass your Glib::OptionContext to the Main constructor, because it adds the gtk option group automatically.

Parameters:

  option_context | Option Context to which the group will be added.
  open_default_display | Whether to open the default display when parsing the commandline arguments.

static bool Gtk::Main::events_pending | ( |  | ) | `[static]`

Checks if any events are pending.

This can be used to update the GUI and invoke timeouts etc. while doing some time intensive computation.

Example: Updating the GUI during a long computation.

     // computation going on
     while( Gtk::Main::events_pending() )
       Gtk::Main::iteration();

     // computation continued

Returns:
  true if any events are pending, false otherwise.

virtual bool Gtk::Main::events_pending_impl | ( |  | ) | `[protected, virtual]`

void Gtk::Main::init | ( | int * | argc,
|  | char *** | argv,
|  | bool | set_locale
| ) |  | `[protected]`

static void Gtk::Main::init_gtkmm_internals | ( |  | ) | `[static]`

static Gtk::Main* Gtk::Main::instance | ( |  | ) | `[static]`

Access to the one global instance of Gtk::Main.

static bool Gtk::Main::iteration | ( | bool | blocking = `true` | ) | `[static]`

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 blocking or check if any events are pending with pending() first.

Parameters:

  blocking | Whether the caller must wait until the next event is noticed, or return immediately if there are no events.

Returns:
  true if quit() has been called for the innermost main loop.

virtual bool Gtk::Main::iteration_impl | ( | bool | blocking | ) | `[protected, virtual]`

static guint Gtk::Main::level | ( |  | ) | `[static]`

virtual guint Gtk::Main::level_impl | ( |  | ) | `[protected, virtual]`

virtual void Gtk::Main::on_window_hide | ( |  | ) | `[protected, virtual]`

static void Gtk::Main::quit | ( |  | ) | `[static]`

Makes the innermost invocation of the main loop return when it regains control.

virtual void Gtk::Main::quit_impl | ( |  | ) | `[protected, virtual]`

static void Gtk::Main::run | ( | Window& | window | ) | `[static]`

Returns from the main loop when the window is closed.

When using this override, you should not use Gtk::Main::quit() to close the application, but just call hide() on your Window class.

Parameters:

  window | The window to show. This method will return when the window is hidden.

static void Gtk::Main::run | ( |  | ) | `[static]`

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

virtual void Gtk::Main::run_impl | ( |  | ) | `[protected, virtual]`

static KeySnooperSig& Gtk::Main::signal_key_snooper | ( |  | ) | `[static]`

KeySnooper signal Allows you to channel keypresses to a signal handler without registering with the widget.

Returns:
  KeySnooperSig A Signal to which you can connect a sigc::slot< int, Widget *, GdkEventKey * >

It is the responsibility of the snooper to pass the keypress to the widget, however, care must be taken that the keypress is not passed twice.

## Member Data Documentation

KeySnooperSig Gtk::Main::signal_key_snooper_`[static, protected]`

The documentation for this class was generated from the following file:

- gtkmm/main.h