1
2 /* $XConsortium: MenuProc.c /main/8 1996/01/17 10:50:38 lehors $ */
3 /*
4 * Motif
5 *
6 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
7 *
8 * These libraries and programs are free software; you can
9 * redistribute them and/or modify them under the terms of the GNU
10 * Lesser General Public License as published by the Free Software
11 * Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * These libraries and programs are distributed in the hope that
15 * they will be useful, but WITHOUT ANY WARRANTY; without even the
16 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17 * PURPOSE. See the GNU Lesser General Public License for more
18 * details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with these librararies and programs; if not, write
22 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
23 * Floor, Boston, MA 02110-1301 USA
24 *
25 */
26 /*
27 * HISTORY
28 */
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32
33
34 /*
35 * The following functions are used to separate the private class function
36 * in RowColumn from the buttons that may be children of the RowColumn.
37 * This is simply an interface supplied so that the buttons will not have
38 * to have intimate knowledge of the RowColumn class functions.
39 */
40
41 #include <Xm/XmP.h>
42 #include <Xm/MenuProcP.h>
43 #include "MenuProcI.h"
44 #include "GadgetUtiI.h"
45 #include "XmI.h"
46
47 static XtPointer menuProcEntry = NULL;
48
49 /*
50 * this routine is called at RowColumn class init to
51 * save the address of the menuProcedureEntry routine.
52 */
53
54 void
_XmSaveMenuProcContext(XtPointer address)55 _XmSaveMenuProcContext(
56 XtPointer address )
57 {
58 menuProcEntry = address;
59 }
60
61
62 /*
63 * This routine is used by the button children of the RowColumn (currently
64 * all label and labelgadget subclasses) to get the address of the
65 * menuProcedureEntry routine. It is called by the buttons class init
66 * routines.
67 */
68 XtPointer
_XmGetMenuProcContext(void)69 _XmGetMenuProcContext( void )
70 {
71 return menuProcEntry;
72 }
73
74
75 /* temp hold for core class translations used during subclass'
76 * InitializePrehook & InitializePosthook
77 */
78 static XContext SaveTranslationsContext = 0;
79
80
81 /************************************************************************
82 *
83 * _XmSaveCoreClassTranslations
84 *
85 * Save away the core class translations during the initialization
86 * routines. This is used by rowcol and subclasses of Label that set their
87 * translations during initialization depending on whether they are in
88 * a menu. The InitializePrehook calls this routine to save the
89 * core class translations.
90 ************************************************************************/
91 void
_XmSaveCoreClassTranslations(Widget widget)92 _XmSaveCoreClassTranslations(
93 Widget widget)
94 {
95 _XmProcessLock();
96 if (SaveTranslationsContext == 0)
97 SaveTranslationsContext = XUniqueContext();
98
99 XSaveContext(XtDisplay(widget), (XID)widget, SaveTranslationsContext,
100 (char *)(widget->core.widget_class->core_class.tm_table));
101 _XmProcessUnlock();
102 }
103
104 /************************************************************************
105 *
106 * _XmRestoreCoreClassTranslations
107 *
108 * Restore the core class translations during the initialization
109 * routines. This is used by rowcol and subclasses of Label that set their
110 * translations during initialization depending on whether they are in
111 * a menu. The InitializePosthook calls this routine to restore the
112 * core class translations.
113 ************************************************************************/
114 void
_XmRestoreCoreClassTranslations(Widget widget)115 _XmRestoreCoreClassTranslations(
116 Widget widget)
117 {
118 String saved_translations;
119
120 _XmProcessLock();
121 if (SaveTranslationsContext &&
122 (!XFindContext(XtDisplay(widget), (XID)widget,
123 SaveTranslationsContext, (XtPointer)&saved_translations)))
124 widget->core.widget_class->core_class.tm_table = saved_translations;
125 #ifdef DEBUG
126 else /* This should'nt happen ! */
127 abort();
128 #endif
129 _XmProcessUnlock();
130 }
131
132
133 /*************************************************
134 * This function extracts a time from an event or
135 * returns the last processed time if the event
136 * is NULL or isn't an event with a timestamp
137 *************************************************/
138
139 /*ARGSUSED*/
140 Time
_XmGetDefaultTime(Widget wid,XEvent * event)141 _XmGetDefaultTime(Widget wid,
142 XEvent *event)
143 {
144 if (event == NULL)
145 return(XtLastTimestampProcessed(XtDisplay(wid)));
146 else if (event -> type == ButtonPress ||
147 event -> type == ButtonRelease)
148 return(event -> xbutton.time);
149 else if (event -> type == KeyPress ||
150 event -> type == KeyRelease)
151 return(event -> xkey.time);
152 else if (event -> type == MotionNotify)
153 return(event -> xmotion.time);
154 else if (event -> type == EnterNotify ||
155 event -> type == LeaveNotify)
156 return(event -> xcrossing.time);
157 else
158 return(XtLastTimestampProcessed(XtDisplay(wid)));
159 }
160