File: | MenuButton.c |
Location: | line 180, column 12 |
Description: | Dereference of null pointer |
1 | /* | |||||
2 | Copyright (c) 1989, 1994 X Consortium | |||||
3 | ||||||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |||||
5 | of this software and associated documentation files (the "Software"), to deal | |||||
6 | in the Software without restriction, including without limitation the rights | |||||
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||||
8 | copies of the Software, and to permit persons to whom the Software is | |||||
9 | furnished to do so, subject to the following conditions: | |||||
10 | ||||||
11 | The above copyright notice and this permission notice shall be included in | |||||
12 | all copies or substantial portions of the Software. | |||||
13 | ||||||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
17 | X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |||||
18 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||||
19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||||
20 | ||||||
21 | Except as contained in this notice, the name of the X Consortium shall not be | |||||
22 | used in advertising or otherwise to promote the sale, use or other dealings | |||||
23 | in this Software without prior written authorization from the X Consortium. | |||||
24 | * | |||||
25 | */ | |||||
26 | ||||||
27 | ||||||
28 | /*********************************************************************** | |||||
29 | * | |||||
30 | * MenuButton Widget | |||||
31 | * | |||||
32 | ***********************************************************************/ | |||||
33 | ||||||
34 | /* | |||||
35 | * MenuButton.c - Source code for MenuButton widget. | |||||
36 | * | |||||
37 | * This is the source code for the Athena MenuButton widget. | |||||
38 | * It is intended to provide an easy method of activating pulldown menus. | |||||
39 | * | |||||
40 | * Date: May 2, 1989 | |||||
41 | * | |||||
42 | * By: Chris D. Peterson | |||||
43 | * MIT X Consortium | |||||
44 | * kit@expo.lcs.mit.edu | |||||
45 | */ | |||||
46 | ||||||
47 | #ifdef HAVE_CONFIG_H1 | |||||
48 | #include "config.h" | |||||
49 | #endif | |||||
50 | #include <stdio.h> | |||||
51 | #include <X11/IntrinsicP.h> | |||||
52 | #include <X11/StringDefs.h> | |||||
53 | ||||||
54 | #include <X11/Xaw3d/XawInit.h> | |||||
55 | #include <X11/Xaw3d/MenuButtoP.h> | |||||
56 | ||||||
57 | static void ClassInitialize(void); | |||||
58 | static void PopupMenu(Widget, XEvent *, String *, Cardinal *); | |||||
59 | ||||||
60 | #define superclass((CommandWidgetClass)&commandClassRec) ((CommandWidgetClass)&commandClassRec) | |||||
61 | ||||||
62 | static char defaultTranslations[] = | |||||
63 | "<EnterWindow>: highlight()\n\ | |||||
64 | <LeaveWindow>: reset()\n\ | |||||
65 | Any<BtnDown>: reset() PopupMenu()"; | |||||
66 | ||||||
67 | /**************************************************************** | |||||
68 | * | |||||
69 | * Full class record constant | |||||
70 | * | |||||
71 | ****************************************************************/ | |||||
72 | ||||||
73 | /* Private Data */ | |||||
74 | ||||||
75 | #define offset(field) XtOffsetOf(MenuButtonRec, field)__builtin_offsetof(MenuButtonRec, field) | |||||
76 | static XtResource resources[] = { | |||||
77 | { | |||||
78 | XtNmenuName"menuName", XtCMenuName"MenuName", XtRString((char*)&XtStrings[1797]), sizeof(String), | |||||
79 | offset(menu_button.menu_name), XtRString((char*)&XtStrings[1797]), (XtPointer)"menu"}, | |||||
80 | }; | |||||
81 | #undef offset | |||||
82 | ||||||
83 | static XtActionsRec actionsList[] = | |||||
84 | { | |||||
85 | {"PopupMenu", PopupMenu} | |||||
86 | }; | |||||
87 | ||||||
88 | MenuButtonClassRec menuButtonClassRec = { | |||||
89 | { | |||||
90 | (WidgetClass) superclass((CommandWidgetClass)&commandClassRec), /* superclass */ | |||||
91 | "MenuButton", /* class_name */ | |||||
92 | sizeof(MenuButtonRec), /* size */ | |||||
93 | ClassInitialize, /* class_initialize */ | |||||
94 | NULL((void*)0), /* class_part_initialize */ | |||||
95 | FALSE0, /* class_inited */ | |||||
96 | NULL((void*)0), /* initialize */ | |||||
97 | NULL((void*)0), /* initialize_hook */ | |||||
98 | XtInheritRealize((XtRealizeProc) _XtInherit), /* realize */ | |||||
99 | actionsList, /* actions */ | |||||
100 | XtNumber(actionsList)((Cardinal) (sizeof(actionsList) / sizeof(actionsList[0]))), /* num_actions */ | |||||
101 | resources, /* resources */ | |||||
102 | XtNumber(resources)((Cardinal) (sizeof(resources) / sizeof(resources[0]))), /* resource_count */ | |||||
103 | NULLQUARK((XrmQuark) 0), /* xrm_class */ | |||||
104 | FALSE0, /* compress_motion */ | |||||
105 | TRUE1, /* compress_exposure */ | |||||
106 | TRUE1, /* compress_enterleave */ | |||||
107 | FALSE0, /* visible_interest */ | |||||
108 | NULL((void*)0), /* destroy */ | |||||
109 | XtInheritResize((XtWidgetProc) _XtInherit), /* resize */ | |||||
110 | XtInheritExpose((XtExposeProc) _XtInherit), /* expose */ | |||||
111 | NULL((void*)0), /* set_values */ | |||||
112 | NULL((void*)0), /* set_values_hook */ | |||||
113 | XtInheritSetValuesAlmost((XtAlmostProc) _XtInherit), /* set_values_almost */ | |||||
114 | NULL((void*)0), /* get_values_hook */ | |||||
115 | NULL((void*)0), /* accept_focus */ | |||||
116 | XtVersion(11 * 1000 + 6), /* version */ | |||||
117 | NULL((void*)0), /* callback_private */ | |||||
118 | defaultTranslations, /* tm_table */ | |||||
119 | XtInheritQueryGeometry((XtGeometryHandler) _XtInherit), /* query_geometry */ | |||||
120 | XtInheritDisplayAccelerator((XtStringProc) _XtInherit), /* display_accelerator */ | |||||
121 | NULL((void*)0) /* extension */ | |||||
122 | }, /* CoreClass fields initialization */ | |||||
123 | { | |||||
124 | XtInheritChangeSensitive((Boolean (*)(Widget))_XtInherit) /* change_sensitive */ | |||||
125 | }, /* SimpleClass fields initialization */ | |||||
126 | { | |||||
127 | XtInheritXaw3dShadowDraw((void (*)(Widget, XEvent *, Region, XtRelief, Boolean))_XtInherit ), /* shadowdraw */ | |||||
128 | }, /* ThreeDClass fields initialization */ | |||||
129 | { | |||||
130 | 0, /* field not used */ | |||||
131 | }, /* LabelClass fields initialization */ | |||||
132 | { | |||||
133 | 0, /* field not used */ | |||||
134 | }, /* CommandClass fields initialization */ | |||||
135 | { | |||||
136 | 0, /* field not used */ | |||||
137 | } /* MenuButtonClass fields initialization */ | |||||
138 | }; | |||||
139 | ||||||
140 | /* for public consumption */ | |||||
141 | WidgetClass menuButtonWidgetClass = (WidgetClass) &menuButtonClassRec; | |||||
142 | ||||||
143 | /**************************************************************** | |||||
144 | * | |||||
145 | * Private Procedures | |||||
146 | * | |||||
147 | ****************************************************************/ | |||||
148 | ||||||
149 | static void | |||||
150 | ClassInitialize(void) | |||||
151 | { | |||||
152 | XawInitializeWidgetSet(); | |||||
153 | XtRegisterGrabAction(PopupMenu, True1, | |||||
154 | (unsigned int)(ButtonPressMask(1L<<2) | ButtonReleaseMask(1L<<3)), | |||||
155 | GrabModeAsync1, GrabModeAsync1); | |||||
156 | } | |||||
157 | ||||||
158 | /* ARGSUSED */ | |||||
159 | static void | |||||
160 | PopupMenu(Widget w, XEvent *event, String *params, Cardinal *num_params) | |||||
161 | { | |||||
162 | MenuButtonWidget mbw = (MenuButtonWidget) w; | |||||
| ||||||
163 | Widget menu = NULL((void*)0), temp; | |||||
164 | Arg arglist[2]; | |||||
165 | Cardinal num_args; | |||||
166 | int menu_x, menu_y, menu_width, menu_height, button_height; | |||||
167 | Position button_x, button_y; | |||||
168 | ||||||
169 | temp = w; | |||||
170 | while(temp != NULL((void*)0)) { | |||||
171 | menu = XtNameToWidget(temp, mbw->menu_button.menu_name); | |||||
172 | if (menu == NULL((void*)0)) | |||||
173 | temp = XtParent(temp)((temp)->core.parent); | |||||
174 | else | |||||
175 | break; | |||||
176 | } | |||||
177 | ||||||
178 | if (menu == NULL((void*)0)) { | |||||
179 | char error_buf[BUFSIZ1024]; | |||||
180 | (void) sprintf(error_buf, "MenuButton: %s %s.",__builtin___sprintf_chk (error_buf, 0, __builtin_object_size ( error_buf, 2 > 1 ? 1 : 0), "MenuButton: %s %s.", "Could not find menu widget named" , mbw->menu_button.menu_name) | |||||
| ||||||
181 | "Could not find menu widget named", mbw->menu_button.menu_name)__builtin___sprintf_chk (error_buf, 0, __builtin_object_size ( error_buf, 2 > 1 ? 1 : 0), "MenuButton: %s %s.", "Could not find menu widget named" , mbw->menu_button.menu_name); | |||||
182 | XtAppWarning(XtWidgetToApplicationContext(w), error_buf); | |||||
183 | return; | |||||
184 | } | |||||
185 | if (!XtIsRealized(menu)(XtWindowOfObject(menu) != 0L)) | |||||
186 | XtRealizeWidget(menu); | |||||
187 | ||||||
188 | menu_width = menu->core.width + 2 * menu->core.border_width; | |||||
189 | button_height = w->core.height + 2 * w->core.border_width; | |||||
190 | menu_height = menu->core.height + 2 * menu->core.border_width; | |||||
191 | ||||||
192 | XtTranslateCoords(w, 0, 0, &button_x, &button_y); | |||||
193 | menu_x = button_x; | |||||
194 | menu_y = button_y + button_height; | |||||
195 | ||||||
196 | if (menu_x >= 0) { | |||||
197 | int scr_width = WidthOfScreen(XtScreen(menu))((((menu)->core.screen))->width); | |||||
198 | if (menu_x + menu_width > scr_width) | |||||
199 | menu_x = scr_width - menu_width; | |||||
200 | } | |||||
201 | if (menu_x < 0) | |||||
202 | menu_x = 0; | |||||
203 | ||||||
204 | if (menu_y >= 0) { | |||||
205 | int scr_height = HeightOfScreen(XtScreen(menu))((((menu)->core.screen))->height); | |||||
206 | if (menu_y + menu_height > scr_height) | |||||
207 | menu_y = scr_height - menu_height; | |||||
208 | } | |||||
209 | if (menu_y < 0) | |||||
210 | menu_y = 0; | |||||
211 | ||||||
212 | num_args = 0; | |||||
213 | XtSetArg(arglist[num_args], XtNx, menu_x)((void)( (arglist[num_args]).name = (((char*)&XtStrings[885 ])), (arglist[num_args]).value = (XtArgVal)(menu_x) )); num_args++; | |||||
214 | XtSetArg(arglist[num_args], XtNy, menu_y)((void)( (arglist[num_args]).name = (((char*)&XtStrings[887 ])), (arglist[num_args]).value = (XtArgVal)(menu_y) )); num_args++; | |||||
215 | XtSetValues(menu, arglist, num_args); | |||||
216 | ||||||
217 | XtPopupSpringLoaded(menu); | |||||
218 | } | |||||
219 |