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

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

Added code for object menus.

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
71static GtkWidget *window;
72/*
73 Main entry point. This function is called from the EMX wrapper. Be aware that gtk_init()
74 is already called in the wrapper.
75 */
76int createQuitWindow(void)
77{
78 /* GtkWidget is the storage type for widgets */
79
80 GtkWidget *button;
81
82 /* create a new window */
83 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
84
85 /* When the window is given the "delete_event" signal (this is given
86 * by the window manager, usually by the "close" option, or on the
87 * titlebar), we ask it to call the delete_event () function
88 * as defined above. The data passed to the callback
89 * function is NULL and is ignored in the callback function. */
90 g_signal_connect (G_OBJECT (window), "delete_event",
91 G_CALLBACK (delete_event), NULL);
92
93 /* Here we connect the "destroy" event to a signal handler.
94 * This event occurs when we call gtk_widget_destroy() on the window,
95 * or if we return FALSE in the "delete_event" callback. */
96 g_signal_connect (G_OBJECT (window), "destroy",
97 G_CALLBACK (destroy), NULL);
98
99 /* Sets the border width of the window. */
100 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
101
102 /* Creates a new button with the label "Hello World". */
103 button = gtk_button_new_with_label ("Quit");
104
105 /* When the button receives the "clicked" signal, it will call the
106 * function hello() passing it NULL as its argument. The hello()
107 * function is defined above. */
108 g_signal_connect (G_OBJECT (button), "clicked",
109 G_CALLBACK (quit), NULL);
110
111 /* This will cause the window to be destroyed by calling
112 * gtk_widget_destroy(window) when "clicked". Again, the destroy
113 * signal could come from here, or the window manager. */
114 g_signal_connect_swapped (G_OBJECT (button), "clicked",
115 G_CALLBACK (gtk_widget_destroy),
116 G_OBJECT (window));
117
118 /* This packs the button into the window (a gtk container). */
119 gtk_container_add (GTK_CONTAINER (window), button);
120
121 /* The final step is to display this newly created widget. */
122 gtk_widget_show (button);
123
124 /* and the window */
125 gtk_widget_show (window);
126
127 return 0;
128}
129
Note: See TracBrowser for help on using the repository browser.