source: trunk/desktop/src/quitwindow.c@ 98

Last change on this file since 98 was 98, checked in by cinc, 19 years ago

Initial checkin of desktop sources

File size: 4.8 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2* Version: CDDL 1.0/LGPL 2.1
3*
4* The contents of this file are subject to the COMMON DEVELOPMENT AND
5* DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
6* this file except in compliance with the License. You may obtain a copy of
7* the License at http://www.sun.com/cddl/
8*
9* Software distributed under the License is distributed on an "AS IS" basis,
10* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11* for the specific language governing rights and limitations under the
12* License.
13*
14* The Original Code is "NOM" Netlabs Object Model
15*
16* The Initial Developer of the Original Code is
17* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
18* Portions created by the Initial Developer are Copyright (C) 2005-2006
19* the Initial Developer. All Rights Reserved.
20*
21* Contributor(s):
22*
23* Alternatively, the contents of this file may be used under the terms of
24* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
25* case the provisions of the LGPL are applicable instead of those above. If
26* you wish to allow use of your version of this file only under the terms of
27* the LGPL, and not to allow others to use your version of this file under
28* the terms of the CDDL, indicate your decision by deleting the provisions
29* above and replace them with the notice and other provisions required by the
30* LGPL. If you do not delete the provisions above, a recipient may use your
31* version of this file under the terms of any one of the CDDL or the LGPL.
32*
33* ***** END LICENSE BLOCK ***** */
34
35#include <os2.h>
36#include <stdio.h>
37#include <gtk/gtk.h>
38
39
40/* This is a callback function. The data arguments are ignored
41 * in this example. More on callbacks below. */
42static void quit( GtkWidget *widget,
43 gpointer data )
44{
45}
46
47static gboolean delete_event( GtkWidget *widget,
48 GdkEvent *event,
49 gpointer data )
50{
51 /* If you return FALSE in the "delete_event" signal handler,
52 * GTK will emit the "destroy" signal. Returning TRUE means
53 * you don't want the window to be destroyed.
54 * This is useful for popping up 'are you sure you want to quit?'
55 * type dialogs. */
56
57 g_print ("delete event occurred\n");
58
59 /* Change TRUE to FALSE and the main window will be destroyed with
60 * a "delete_event". */
61 return FALSE;
62}
63
64/* Another callback */
65static void destroy( GtkWidget *widget,
66 gpointer data )
67{
68 gtk_main_quit ();
69}
70
71/*
72 Main entry point. This function is called from the EMX wrapper. Be aware that gtk_init()
73 is already called in the wrapper.
74 */
75int createQuitWindow(void)
76{
77 /* GtkWidget is the storage type for widgets */
78 GtkWidget *window;
79 GtkWidget *button;
80
81 /* create a new window */
82 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
83
84 /* When the window is given the "delete_event" signal (this is given
85 * by the window manager, usually by the "close" option, or on the
86 * titlebar), we ask it to call the delete_event () function
87 * as defined above. The data passed to the callback
88 * function is NULL and is ignored in the callback function. */
89 g_signal_connect (G_OBJECT (window), "delete_event",
90 G_CALLBACK (delete_event), NULL);
91
92 /* Here we connect the "destroy" event to a signal handler.
93 * This event occurs when we call gtk_widget_destroy() on the window,
94 * or if we return FALSE in the "delete_event" callback. */
95 g_signal_connect (G_OBJECT (window), "destroy",
96 G_CALLBACK (destroy), NULL);
97
98 /* Sets the border width of the window. */
99 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
100
101 /* Creates a new button with the label "Hello World". */
102 button = gtk_button_new_with_label ("Quit");
103
104 /* When the button receives the "clicked" signal, it will call the
105 * function hello() passing it NULL as its argument. The hello()
106 * function is defined above. */
107 g_signal_connect (G_OBJECT (button), "clicked",
108 G_CALLBACK (quit), NULL);
109
110 /* This will cause the window to be destroyed by calling
111 * gtk_widget_destroy(window) when "clicked". Again, the destroy
112 * signal could come from here, or the window manager. */
113 g_signal_connect_swapped (G_OBJECT (button), "clicked",
114 G_CALLBACK (gtk_widget_destroy),
115 G_OBJECT (window));
116
117 /* This packs the button into the window (a gtk container). */
118 gtk_container_add (GTK_CONTAINER (window), button);
119
120 /* The final step is to display this newly created widget. */
121 gtk_widget_show (button);
122
123 /* and the window */
124 gtk_widget_show (window);
125
126 return 0;
127}
128
Note: See TracBrowser for help on using the repository browser.