File: main.hg

package info (click to toggle)
gtkmm3.0 3.24.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 22,680 kB
  • sloc: xml: 121,333; cpp: 8,531; sh: 4,250; makefile: 262; perl: 236
file content (298 lines) | stat: -rw-r--r-- 10,808 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
 * Copyright (C) 1998-2003 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


#include <gtk/gtk.h>

#include <sigc++/sigc++.h>
#include <gdkmm/types.h>
#include <glibmm/optioncontext.h>

_DEFS(gtkmm,gtk)

#m4 _PUSH(SECTION_CC_PRE_INCLUDES)
#undef GTK_DISABLE_DEPRECATED
#define GDK_DISABLE_DEPRECATION_WARNINGS 1
#m4 _POP()

namespace Gtk
{

_DEPRECATE_IFDEF_START

class Widget;
class Window;

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

#ifndef DOXYGEN_SHOULD_SKIP_THIS
//Actually, I'd like to just keep these out of the alphabetical list. murrayc.


/// KeySnooper Signal Class (internal)
class KeySnooperSig
{
public:
  typedef sigc::slot<int, Widget*, GdkEventKey*> SlotType;

  sigc::connection connect(const SlotType& slot);

protected:
  static int gtk_callback(GtkWidget* widget, GdkEventKey* event, gpointer data);
};

#endif /* DOXYGEN_SHOULD_SKIP_THIS */

_DEPRECATE_IFDEF_END


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

/** 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:
 * @code
 * int main(int argc, char *argv[])
 * {
 *   Gtk::Main kit(argc, argv);
 *   ... create some widgets and windows...
 *   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.
   *
   * 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
   * <tt>--help</tt> output. Note that your program will
   * be terminated after writing out the help output.
   *
   * @param argc a reference to the number of command line arguments.
   * @param argv a reference to the array of command line arguments.
   * @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);

  /** 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.)
   *
   * @param argc a pointer to the number of command line arguments.
   * @param argv a pointer to the array of command line arguments.
   * @param 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.
   *
   * @deprecated Use Gtk::Application instead.
   */
  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.
   *
   * @param argc a reference to the number of command line arguments.
   * @param argv a reference to the array of command line arguments.
   * @param 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.
   *
   * @deprecated Use Gtk::Application instead.
   */
  Main(int& argc, char**& argv, bool set_locale = true);

  /** Initialization without command-line arguments.
   *
   * @param 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.
   *
   * @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.
   *
   * @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();

  /** 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.
   *
   * @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();

_DEPRECATE_IFDEF_END

  //TODO: Move these general methods out of Main when we really remove Main,
  //one day when Gtk::Application can really do everything, which should probably
  //include handling OptionContext properly. murrayc.

  //This attempts to provide the same functionality as gtk_get_option_group():
  /** 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.
   *
   * @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);


  /** 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
   * pending() first.
   *
   * @param blocking Whether the caller must wait until the next event is noticed, or return immediately if there are no events.
   * @result true if quit() has been called for the innermost main loop.
   */
  static bool iteration(bool blocking = true);

  /** 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.
   * @code
   * // computation going on
   * while( Gtk::Main::events_pending() )
   *   Gtk::Main::iteration();
   *
   * // computation continued
   * @endcode
   *
   * @result true if any events are pending, false otherwise.
   */
  static bool events_pending();

_DEPRECATE_IFDEF_START

  /** KeySnooper signal
   * Allows you to channel keypresses to a signal handler
   * without registering with the widget.
   *
   * @return 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.
   *
   * @deprecated Key snooping should not be done. Events should be handled by widgets.
   */
  static KeySnooperSig& signal_key_snooper();
_DEPRECATE_IFDEF_END

  /** Initialize the table of wrap_new functions.
   * This doesn't need an instance of Gtk::Main.
   * This would usually only be used by the init() methods of libraries that depend on gtkmm.
   */
  static void init_gtkmm_internals();

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);

  virtual void run_impl();
  virtual void quit_impl();
  virtual guint level_impl();
  virtual bool iteration_impl(bool blocking);
  virtual bool events_pending_impl();

  // Signal handlers:
  virtual void on_window_hide();

  // Signal proxies:
  static KeySnooperSig signal_key_snooper_;

private:
  static Main* instance_;
_DEPRECATE_IFDEF_END
};

} // namespace Gtk