Tk Source Code

Check-in [6b6c9d82]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6b6c9d82f7115caa390550124086a4644c56e600
User & Date: dgp 2011-12-22 18:43:12
Context
2012-01-19
19:53
[Bug-3021557]: Moving the cursor in elided text freezes Tk check-in: 34eab8bf user: jan.nijtmans tags: trunk
2011-12-22
18:43
3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald. check-in: 6b6c9d82 user: dgp tags: trunk
18:42
3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald. check-in: 39071084 user: dgp tags: core-8-5-branch
2011-12-13
11:22
Make example follow best practices. check-in: 0c6e7a48 user: dkf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to win/tkWinMenu.c.

209
210
211
212
213
214
215
216
217
218
219




220
221

222
223


224


225
226
227

228

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
 */

static int
GetNewID(
    TkMenuEntry *mePtr,		/* The menu we are working with. */
    WORD *menuIDPtr)		/* The resulting id. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    WORD curID = tsdPtr->lastCommandID + 1;





    /*
     * The following code relies on WORD wrapping when the highest value is

     * incremented.
     */





    while (curID != tsdPtr->lastCommandID) {
	Tcl_HashEntry *commandEntryPtr;
	int newEntry;



    	commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
		((char *) NULL) + curID, &newEntry);
    	if (newEntry == 1) {
	    Tcl_SetHashValue(commandEntryPtr, mePtr);
	    *menuIDPtr = curID;
	    tsdPtr->lastCommandID = curID;
	    return TCL_OK;
    	}
    	curID++;
    }
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeID --
 *







|

|

>
>
>
>
|
<
>
|
|
>
>
|
>
>
|
<
<
>
|
>
|
|
|




|
<

<







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233


234
235
236
237
238
239
240
241
242
243
244

245

246
247
248
249
250
251
252
 */

static int
GetNewID(
    TkMenuEntry *mePtr,		/* The menu we are working with. */
    WORD *menuIDPtr)		/* The resulting id. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    WORD curID = tsdPtr->lastCommandID;

    while (1) {
	Tcl_HashEntry *commandEntryPtr;
	int new;

	/*

	 * Try the next ID number, taking care to wrap rather than stray
	 * into the system menu IDs.  [Bug 3235256]
	 */
	if (++curID >= 0xF000) {
	    curID = 1;
	}

	/* Return error when we've checked all IDs without success. */
	if (curID == tsdPtr->lastCommandID) {


	    return TCL_ERROR;
	}

	commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
		(char *) curID, &new);
	if (new) {
	    Tcl_SetHashValue(commandEntryPtr, mePtr);
	    *menuIDPtr = curID;
	    tsdPtr->lastCommandID = curID;
	    return TCL_OK;
	}

    }

}

/*
 *----------------------------------------------------------------------
 *
 * FreeID --
 *