1 |
/* $Header: /cvsroot/esrg/sfesrg/esrgpcpj/shared/tk_base/tkmacwinmenu.c,v 1.1.1.1 2001/06/13 05:05:02 dtashley Exp $ */
|
2 |
|
3 |
/*
|
4 |
* tkMacWinMenu.c --
|
5 |
*
|
6 |
* This module implements the common elements of the Mac and Windows
|
7 |
* specific features of menus. This file is not used for UNIX.
|
8 |
*
|
9 |
* Copyright (c) 1996-1997 by Sun Microsystems, Inc.
|
10 |
*
|
11 |
* See the file "license.terms" for information on usage and redistribution
|
12 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
13 |
*
|
14 |
* RCS: @(#) $Id: tkmacwinmenu.c,v 1.1.1.1 2001/06/13 05:05:02 dtashley Exp $
|
15 |
*/
|
16 |
|
17 |
#include "tkMenu.h"
|
18 |
|
19 |
typedef struct ThreadSpecificData {
|
20 |
int postCommandGeneration;
|
21 |
} ThreadSpecificData;
|
22 |
static Tcl_ThreadDataKey dataKey;
|
23 |
|
24 |
|
25 |
static int PreprocessMenu _ANSI_ARGS_((TkMenu *menuPtr));
|
26 |
|
27 |
|
28 |
/*
|
29 |
*----------------------------------------------------------------------
|
30 |
*
|
31 |
* PreprocessMenu --
|
32 |
*
|
33 |
* The guts of the preprocessing. Recursive.
|
34 |
*
|
35 |
* Results:
|
36 |
* The return value is a standard Tcl result (errors can occur
|
37 |
* while the postcommands are being processed).
|
38 |
*
|
39 |
* Side effects:
|
40 |
* Since commands can get executed while this routine is being executed,
|
41 |
* the entire world can change.
|
42 |
*
|
43 |
*----------------------------------------------------------------------
|
44 |
*/
|
45 |
|
46 |
static int
|
47 |
PreprocessMenu(menuPtr)
|
48 |
TkMenu *menuPtr;
|
49 |
{
|
50 |
int index, result, finished;
|
51 |
TkMenu *cascadeMenuPtr;
|
52 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
|
53 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
|
54 |
|
55 |
Tcl_Preserve((ClientData) menuPtr);
|
56 |
|
57 |
/*
|
58 |
* First, let's process the post command on ourselves. If this command
|
59 |
* destroys this menu, or if there was an error, we are done.
|
60 |
*/
|
61 |
|
62 |
result = TkPostCommand(menuPtr);
|
63 |
if ((result != TCL_OK) || (menuPtr->tkwin == NULL)) {
|
64 |
goto done;
|
65 |
}
|
66 |
|
67 |
/*
|
68 |
* Now, we go through structure and process all of the commands.
|
69 |
* Since the structure is changing, we stop after we do one command,
|
70 |
* and start over. When we get through without doing any, we are done.
|
71 |
*/
|
72 |
|
73 |
|
74 |
do {
|
75 |
finished = 1;
|
76 |
for (index = 0; index < menuPtr->numEntries; index++) {
|
77 |
if ((menuPtr->entries[index]->type == CASCADE_ENTRY)
|
78 |
&& (menuPtr->entries[index]->namePtr != NULL)) {
|
79 |
if ((menuPtr->entries[index]->childMenuRefPtr != NULL)
|
80 |
&& (menuPtr->entries[index]->childMenuRefPtr->menuPtr
|
81 |
!= NULL)) {
|
82 |
cascadeMenuPtr =
|
83 |
menuPtr->entries[index]->childMenuRefPtr->menuPtr;
|
84 |
if (cascadeMenuPtr->postCommandGeneration !=
|
85 |
tsdPtr->postCommandGeneration) {
|
86 |
cascadeMenuPtr->postCommandGeneration =
|
87 |
tsdPtr->postCommandGeneration;
|
88 |
result = PreprocessMenu(cascadeMenuPtr);
|
89 |
if (result != TCL_OK) {
|
90 |
goto done;
|
91 |
}
|
92 |
finished = 0;
|
93 |
break;
|
94 |
}
|
95 |
}
|
96 |
}
|
97 |
}
|
98 |
} while (!finished);
|
99 |
|
100 |
done:
|
101 |
Tcl_Release((ClientData)menuPtr);
|
102 |
return result;
|
103 |
}
|
104 |
|
105 |
/*
|
106 |
*----------------------------------------------------------------------
|
107 |
*
|
108 |
* TkPreprocessMenu --
|
109 |
*
|
110 |
* On the Mac and on Windows, all of the postcommand processing has
|
111 |
* to be done on the entire tree underneath the main window to be
|
112 |
* posted. This means that we have to traverse the menu tree and
|
113 |
* issue the postcommands for all of the menus that have cascades
|
114 |
* attached. Since the postcommands can change the menu structure while
|
115 |
* we are traversing, we have to be extremely careful. Basically, the
|
116 |
* idea is to traverse the structure until we succesfully process
|
117 |
* one postcommand. Then we start over, and do it again until
|
118 |
* we traverse the whole structure without processing any postcommands.
|
119 |
*
|
120 |
* We are also going to set up the cascade back pointers in here
|
121 |
* since we have to traverse the entire structure underneath the menu
|
122 |
* anyway, We can clear the postcommand marks while we do that.
|
123 |
*
|
124 |
* Results:
|
125 |
* The return value is a standard Tcl result (errors can occur
|
126 |
* while the postcommands are being processed).
|
127 |
*
|
128 |
* Side effects:
|
129 |
* Since commands can get executed while this routine is being executed,
|
130 |
* the entire world can change.
|
131 |
*
|
132 |
*----------------------------------------------------------------------
|
133 |
*/
|
134 |
|
135 |
int
|
136 |
TkPreprocessMenu(menuPtr)
|
137 |
TkMenu *menuPtr;
|
138 |
{
|
139 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
|
140 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
|
141 |
|
142 |
tsdPtr->postCommandGeneration++;
|
143 |
menuPtr->postCommandGeneration = tsdPtr->postCommandGeneration;
|
144 |
return PreprocessMenu(menuPtr);
|
145 |
}
|
146 |
|
147 |
|
148 |
/* $History: tkMacWinMenu.c $
|
149 |
*
|
150 |
* ***************** Version 1 *****************
|
151 |
* User: Dtashley Date: 1/02/01 Time: 2:59a
|
152 |
* Created in $/IjuScripter, IjuConsole/Source/Tk Base
|
153 |
* Initial check-in.
|
154 |
*/
|
155 |
|
156 |
/* End of TKMACWINMENU.C */ |