/[dtapublic]/projs/ets/trunk/src/c_tk_base_7_5_w_mods/tkmacwinmenu.c
ViewVC logotype

Diff of /projs/ets/trunk/src/c_tk_base_7_5_w_mods/tkmacwinmenu.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.70  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25