Gtk-- Reference: Gtk::Main

Class Index | Cross Index | Namespace Index

# Class Gtk::Main

Main application class
Contained in: Gtk
Derived from: SigC::Object
Derived by: none

#include <gtk--/main.h>

### public function member index:
`` | `Main` | `(`int`* `argc`, `char`* **`argv`, `bool` `have_locale`=false)`;
`` | `Main` | `(`int`& `argc`, `char`* *&`argv`, `bool` `have_locale`=false)`;
``static` `gint`` | `events_pending` | `()`;
``static` `void`` | `grab_add` | `(`Widget`& `widget`)`;
``static` `Widget`*` | `grab_get_current` | `()`;
``static` `void`` | `grab_remove` | `(`Widget`& `widget`)`;
``static` `void`` | `gtk_false` | `()`;
``static` `void`` | `gtk_true` | `()`;
``static` `Main`*` | `instance` | `()`;
``static` `void`` | `iteration` | `(`bool` `blocking`=TRUE)`;
``static` `void`` | `run` | `()`;
`` | `~Main` | `()`;
### protected function member index:
`` | `Main` | `()`;
``virtual` `gint`` | `events_pending_impl` | `()`;
``void`` | `init` | `(`int`* `argc`, `char`* **`argv`, `bool` `have_locale`)`;
``void`` | `init_gtkmm_internals` | `()`;
``virtual` `void`` | `iteration_impl` | `(`bool` `blocking`)`;
``virtual` `void`` | `quit_impl` | `()`;
``virtual` `void`` | `run_impl` | `()`;

## Description:

Every application must have one of these objects. It may not be global and must be the first Gtk object created. ``Gtk`::Kit` is an alias for ``Gtk`::`Main``. It is a singleton so declaring more than one will simply access the first created.

Normal use of this class is in `` function to give ``argc`` and ``argv`` to the gtk initialization. Widgets can use `quit` for example to exit from the application.

The internals of the widget have been disguised as signals so that the user can easily connect using the same methods used throughout the widget interface.

Minimal gtk-- application is something like this:

        void main(int argc, char *argv[]) {
          Gtk::Kit kit(argc, argv);
          ... create some widgets ...
          kit.run();
        }

## Function Member Descriptions:

Gtk::Main::grab_add - Grabs events to a widget modal

``static` `void`` `grab_add``(`Widget`& `widget`)`;

> Prevents events to everything else than given widget and its childs. This way you can create modal dialogs(not recommended).

Gtk::Main::grab_get_current - Returns the widget which is grabbing events

``static` `Widget`*` `grab_get_current``()`;
Gtk::Main::grab_remove - Removes event grab

``static` `void`` `grab_remove``(`Widget`& `widget`)`;
Gtk::Main::instance - Access to one global instance of Gtk::Main.

``static` `Main`*` `instance``()`;
Gtk::Main::run - Start the widget loop.

``static` `void`` `run``()`;
``virtual` `void`` `run_impl``()`;

> This begins the event loop which handles events. No events propagate until this has been called. It may be called recursively to popup dialogs.

## Variable Member Descriptions:

Gtk::Main::idle - Idle signal

``static` `IdleSig`` ``idle`;`

> idle provides a way to setup a callback that will be called when gtk has nothing else to do, when the execution has returned from all callbacks etc.

> Return value of the callback will determine if the callback is removed. 0 means callback is removed, 1 means it'll be called again after gtk next time has nothing to do.

> Example:

>         gint thisclass::mymethod() { return 1; }
>         Main::idle.connect(slot(this,&thisclass::mymethod));

> You can supply an integer priority to the `idle` call; by default, it's `GTK_PRIORITY_DEFAULT`, lower numbers are higher priority.

Gtk::Main::input - Input signal

``static` `InputSig`` ``input`;`

> input provides a way to monitor a file descriptor for activity for a number of conditions. Conditions can be any combination of `GDK_INPUT_READ, GDK_INPUT_WRITE, GDK_INPUT_EXCEPTION`.

> The first argument of the callback is the file descriptor with activity, the second denotes the kind of activity.

> See also open(2), fileno(3) and socket(2) for ways of obtaining a file descriptor.

> This is largely a wrapper for gdk_input_add_full, which in turn uses select(2).

> Example:

>         void thisclass::mymethod(int fd, GdkInputCondition cond) { }
>         int fd = open("bob", O_RDONLY);
>         Main::input.connect(slot(this, &thisclass::mymethod), fd,
>           GdkInputCondition(GDK_INPUT_READ | GDK_INPUT_EXCEPTION));

Gtk::Main::key_snooper - KeySnooper signal

``static` `KeySnooperSig`` ``key_snooper`;`

> key_snooper provides a way to channel keypresses to a callback without registering with the widget.

> Callbacks will get the name of the widget and the keypress event. It is the responsibility of the snooper to pass the keypress to the widget, however, care must be given that the keypress is not passed twice.

Gtk::Main::quit - Quit signal

``static` `QuitSig`` ``quit`;`

> quit is an emitable signal which terminates the application. You can connect callbacks to it to invoke actions when the user has requested the application should terminate.

> Example:

>       Connecting to:
>         gint thisclass::mymethod() { return 1; }
>         Main::quit.connect(slot(this,&thisclass::mymethod);

>       Invoking when:
>         Gtk_Button button;

>         button.clicked.connect(Main::quit.slot());

>       Calling directly:
>         Main::quit();

Gtk::Main::timeout - Timeout signal

``static` `TimeoutSig`` ``timeout`;`

> timeout provides a way to setup a callback that will be called when certain time has elapsed.

> Return value of the callback will determine if the callback is removed. 0 means callback is removed, 1 means it'll call it again after the time has again elapsed.

> Example:

>         gint thisclass::mymethod() { return 1; }
>         Main::timeout.connect(slot(this,&thisclass::mymethod),100);