summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tkBind.c38
-rw-r--r--generic/tkGC.c7
-rw-r--r--generic/tkInt.h1
-rw-r--r--generic/tkSelect.c4
-rw-r--r--generic/tkTextDisp.c2
-rw-r--r--generic/tkWindow.c2
-rw-r--r--macosx/tkMacOSXDialog.c79
-rw-r--r--unix/tkUnixCursor.c1
-rw-r--r--unix/tkUnixXId.c1
-rw-r--r--win/tkWinSend.c1
10 files changed, 89 insertions, 47 deletions
diff --git a/generic/tkBind.c b/generic/tkBind.c
index 61b44df..285b3f7 100644
--- a/generic/tkBind.c
+++ b/generic/tkBind.c
@@ -1267,7 +1267,7 @@ Tk_BindEvent(
*/
if ((eventPtr->type >= TK_LASTEVENT) || !flagArray[eventPtr->type]) {
- return;
+ return;
}
dispPtr = ((TkWindow *) tkwin)->dispPtr;
@@ -2878,7 +2878,7 @@ GetAllVirtualEvents(
* Any other fields in eventPtr which are not specified by the pattern
* string or the optional arguments, are set to 0.
*
- * The event may be handled sychronously or asynchronously, depending on
+ * The event may be handled synchronously or asynchronously, depending on
* the value specified by the optional "-when" option. The default
* setting is synchronous.
*
@@ -3466,12 +3466,7 @@ HandleEventGenerate(
if ((warp != 0) && Tk_IsMapped(tkwin)) {
TkDisplay *dispPtr = TkGetDisplay(event.general.xmotion.display);
- /*
- * TODO: No protection is in place to handle dispPtr destruction
- * before DoWarp is called back.
- */
-
- Tk_Window warpWindow = Tk_IdToWindow(dispPtr->display,
+Tk_Window warpWindow = Tk_IdToWindow(dispPtr->display,
event.general.xmotion.window);
if (!(dispPtr->flags & TK_DISPLAY_IN_WARP)) {
@@ -4321,6 +4316,33 @@ TkpGetBindingXEvent(
}
/*
+ *----------------------------------------------------------------------
+ *
+ * TkpCancelWarp --
+ *
+ * This function cancels an outstanding pointer warp and
+ * is called during tear down of the display.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TkpCancelWarp(
+ TkDisplay *dispPtr)
+{
+ if (dispPtr->flags & TK_DISPLAY_IN_WARP) {
+ Tcl_CancelIdleCall(DoWarp, dispPtr);
+ dispPtr->flags &= ~TK_DISPLAY_IN_WARP;
+ }
+}
+
+/*
* Local Variables:
* mode: c
* c-basic-offset: 4
diff --git a/generic/tkGC.c b/generic/tkGC.c
index 5663ede..c424e30 100644
--- a/generic/tkGC.c
+++ b/generic/tkGC.c
@@ -314,7 +314,6 @@ Tk_FreeGC(
gcPtr = Tcl_GetHashValue(idHashPtr);
gcPtr->refCount--;
if (gcPtr->refCount == 0) {
- Tk_FreeXId(gcPtr->display, (XID) XGContextFromGC(gcPtr->gc));
XFreeGC(gcPtr->display, gcPtr->gc);
Tcl_DeleteHashEntry(gcPtr->valueHashPtr);
Tcl_DeleteHashEntry(idHashPtr);
@@ -351,12 +350,6 @@ TkGCCleanup(
entryPtr != NULL; entryPtr = Tcl_NextHashEntry(&search)) {
gcPtr = Tcl_GetHashValue(entryPtr);
- /*
- * This call is not needed, as it is only used on Unix to restore the
- * Id to the stack pool, and we don't want to use them anymore.
- * Tk_FreeXId(gcPtr->display, (XID) XGContextFromGC(gcPtr->gc));
- */
-
XFreeGC(gcPtr->display, gcPtr->gc);
Tcl_DeleteHashEntry(gcPtr->valueHashPtr);
Tcl_DeleteHashEntry(entryPtr);
diff --git a/generic/tkInt.h b/generic/tkInt.h
index f00d833..a28cae4 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -1223,6 +1223,7 @@ MODULE_SCOPE int TkInitTkCmd(Tcl_Interp *interp,
MODULE_SCOPE int TkInitFontchooser(Tcl_Interp *interp,
ClientData clientData);
MODULE_SCOPE void TkpWarpPointer(TkDisplay *dispPtr);
+MODULE_SCOPE void TkpCancelWarp(TkDisplay *dispPtr);
MODULE_SCOPE int TkListCreateFrame(ClientData clientData,
Tcl_Interp *interp, Tcl_Obj *listObj,
int toplevel, Tcl_Obj *nameObj);
diff --git a/generic/tkSelect.c b/generic/tkSelect.c
index ab9018a..d763411 100644
--- a/generic/tkSelect.c
+++ b/generic/tkSelect.c
@@ -190,8 +190,8 @@ Tk_CreateSelHandler(
* should make a copy for this selPtr.
*/
- unsigned cmdInfoLen = Tk_Offset(CommandInfo, command) +
- ((CommandInfo *)clientData)->cmdLength + 1;
+ unsigned cmdInfoLen = Tk_Offset(CommandInfo, command) + 1 +
+ ((CommandInfo *)clientData)->cmdLength;
selPtr->clientData = ckalloc(cmdInfoLen);
memcpy(selPtr->clientData, clientData, cmdInfoLen);
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index 371e910..03d11e1 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -7561,7 +7561,7 @@ TkTextCharLayoutProc(
ciPtr = &bciPtr->ci;
} else {
bciPtr = baseCharChunkPtr->clientData;
- ciPtr = ckalloc(sizeof(CharInfo));
+ ciPtr = ckalloc(Tk_Offset(CharInfo, chars) + 1);
baseString = &bciPtr->baseChars;
}
diff --git a/generic/tkWindow.c b/generic/tkWindow.c
index 690a841..2848ff5 100644
--- a/generic/tkWindow.c
+++ b/generic/tkWindow.c
@@ -239,6 +239,8 @@ TkCloseDisplay(
{
TkClipCleanup(dispPtr);
+ TkpCancelWarp(dispPtr);
+
if (dispPtr->name != NULL) {
ckfree(dispPtr->name);
}
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index cd289d2..42cd1e5 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -24,9 +24,11 @@
#define modalOther -1
#define modalError -2
-/*Vars for filtering in "open file" dialog.*/
+/*Vars for filtering in "open file" and "save file" dialogs.*/
NSMutableArray *openFileTypes;
+NSMutableArray *saveFileTypes;
NSOpenPanel *openpanel;
+NSSavePanel *savepanel;
static const char *const colorOptionStrings[] = {
"-initialcolor", "-parent", "-title", NULL
@@ -262,6 +264,16 @@ static NSURL *getFileURL(NSString *directory, NSString *filename) {
}
+- (void)saveFormat:(id)sender {
+ NSPopUpButton *button = (NSPopUpButton *)sender;
+ NSInteger selectedItemIndex = [button indexOfSelectedItem];
+ saveFileTypes = nil;
+ saveFileTypes = [NSMutableArray array];
+ [saveFileTypes addObject:[button titleOfSelectedItem]];
+ [savepanel setAllowedFileTypes:saveFileTypes];
+
+}
+
@end
#pragma mark -
@@ -410,7 +422,6 @@ Tk_GetOpenFileObjCmd(
NSString *directory = nil, *filename = nil;
NSString *message, *title, *type;
NSWindow *parent;
- // NSOpenPanel *panel = [NSOpenPanel openPanel];
openpanel = [NSOpenPanel openPanel];
NSInteger modalReturnCode = modalError;
BOOL parentIsKey = NO;
@@ -518,7 +529,6 @@ Tk_GetOpenFileObjCmd(
}
}
- /*Accessory view for file filtering. Adapted from http://codefromabove.com/2015/01/nssavepanel-adding-an-accessory-view/ */
NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 200, 32.0)];
NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
[label setEditable:NO];
@@ -634,7 +644,7 @@ Tk_GetSaveFileObjCmd(
NSString *message, *title, *type;
NSWindow *parent;
NSMutableArray *fileTypes = nil;
- NSSavePanel *panel = [NSSavePanel savePanel];
+ savepanel = [NSSavePanel savePanel];
NSInteger modalReturnCode = modalError;
BOOL parentIsKey = NO;
@@ -678,13 +688,13 @@ Tk_GetSaveFileObjCmd(
if (len) {
filename = [[[NSString alloc] initWithUTF8String:str]
autorelease];
- [panel setNameFieldStringValue:filename];
+ [savepanel setNameFieldStringValue:filename];
}
break;
case SAVE_MESSAGE:
message = [[NSString alloc] initWithUTF8String:
Tcl_GetString(objv[i + 1])];
- [panel setMessage:message];
+ [savepanel setMessage:message];
[message release];
break;
case SAVE_PARENT:
@@ -698,7 +708,7 @@ Tk_GetSaveFileObjCmd(
case SAVE_TITLE:
title = [[NSString alloc] initWithUTF8String:
Tcl_GetString(objv[i + 1])];
- [panel setTitle:title];
+ [savepanel setTitle:title];
[title release];
break;
case SAVE_TYPEVARIABLE:
@@ -715,8 +725,7 @@ Tk_GetSaveFileObjCmd(
}
}
if (fl.filters || defaultType) {
- fileTypes = [NSMutableArray array];
- [fileTypes addObject:defaultType ? defaultType : (id)kUTTypeContent];
+ saveFileTypes = [NSMutableArray array];
for (FileFilter *filterPtr = fl.filters; filterPtr;
filterPtr = filterPtr->next) {
for (FileFilterClause *clausePtr = filterPtr->clauses; clausePtr;
@@ -725,23 +734,41 @@ Tk_GetSaveFileObjCmd(
globPtr = globPtr->next) {
str = globPtr->pattern;
while (*str && (*str == '*' || *str == '.')) {
- str++;
- }
+ str++;
+ }
if (*str) {
type = [[NSString alloc] initWithUTF8String:str];
- if (![fileTypes containsObject:type]) {
- [fileTypes addObject:type];
+ if (![saveFileTypes containsObject:type]) {
+ [saveFileTypes addObject:type];
}
[type release];
}
}
}
}
- [panel setAllowedFileTypes:fileTypes];
- [panel setAllowsOtherFileTypes:YES];
+
+
+ NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 200, 32.0)];
+ NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
+ [label setEditable:NO];
+ [label setStringValue:@"Enable:"];
+ [label setBordered:NO];
+ [label setBezeled:NO];
+ [label setDrawsBackground:NO];
+
+ NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 140, 22.0) pullsDown:NO];
+ [popupButton addItemsWithTitles:saveFileTypes];
+ [popupButton setAction:@selector(saveFormat:)];
+
+ [accessoryView addSubview:label];
+ [accessoryView addSubview:popupButton];
+ [savepanel setAllowedFileTypes:saveFileTypes];
+
+ [savepanel setAccessoryView:accessoryView];
+ [savepanel setAllowsOtherFileTypes:YES];
}
- [panel setCanSelectHiddenExtension:YES];
- [panel setExtensionHidden:NO];
+ [savepanel setCanSelectHiddenExtension:YES];
+ [savepanel setExtensionHidden:NO];
if (cmdObj) {
callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
if (Tcl_IsShared(cmdObj)) {
@@ -756,7 +783,7 @@ Tk_GetSaveFileObjCmd(
if (haveParentOption && parent && ![parent attachedSheet]) {
parentIsKey = [parent isKeyWindow];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
- [panel beginSheetForDirectory:directory
+ [savepanel beginSheetForDirectory:directory
file:filename
modalForWindow:parent
modalDelegate:NSApp
@@ -764,22 +791,22 @@ Tk_GetSaveFileObjCmd(
@selector(tkFilePanelDidEnd:returnCode:contextInfo:)
contextInfo:callbackInfo];
#else
- [panel setDirectoryURL:getFileURL(directory, filename)];
- [panel beginSheetModalForWindow:parent
+ [savepanel setDirectoryURL:getFileURL(directory, filename)];
+ [savepanel beginSheetModalForWindow:parent
completionHandler:^(NSInteger returnCode)
- { [NSApp tkFilePanelDidEnd:panel
+ { [NSApp tkFilePanelDidEnd:savepanel
returnCode:returnCode
contextInfo:callbackInfo ]; } ];
#endif
- modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
+ modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:savepanel];
} else {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
- modalReturnCode = [panel runModalForDirectory:directory file:filename];
+ modalReturnCode = [savepanel runModalForDirectory:directory file:filename];
#else
- [panel setDirectoryURL:getFileURL(directory, filename)];
- modalReturnCode = [panel runModal];
+ [savepanel setDirectoryURL:getFileURL(directory, filename)];
+ modalReturnCode = [savepanel runModal];
#endif
- [NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
+ [NSApp tkFilePanelDidEnd:savepanel returnCode:modalReturnCode
contextInfo:callbackInfo];
}
result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
diff --git a/unix/tkUnixCursor.c b/unix/tkUnixCursor.c
index 5266bde..8afb92d 100644
--- a/unix/tkUnixCursor.c
+++ b/unix/tkUnixCursor.c
@@ -639,7 +639,6 @@ TkpFreeCursor(
TkUnixCursor *unixCursorPtr = (TkUnixCursor *) cursorPtr;
XFreeCursor(unixCursorPtr->display, (Cursor) unixCursorPtr->info.cursor);
- Tk_FreeXId(unixCursorPtr->display, (XID) unixCursorPtr->info.cursor);
}
/*
diff --git a/unix/tkUnixXId.c b/unix/tkUnixXId.c
index 668f228..ec2451c 100644
--- a/unix/tkUnixXId.c
+++ b/unix/tkUnixXId.c
@@ -96,7 +96,6 @@ Tk_FreePixmap(
Pixmap pixmap) /* Identifier for pixmap. */
{
XFreePixmap(display, pixmap);
- Tk_FreeXId(display, (XID) pixmap);
}
diff --git a/win/tkWinSend.c b/win/tkWinSend.c
index c999c0b..fca8561 100644
--- a/win/tkWinSend.c
+++ b/win/tkWinSend.c
@@ -619,7 +619,6 @@ BuildMoniker(
LPMONIKER pmkItem = NULL;
Tcl_DString dString;
- Tcl_DStringInit(&dString);
Tcl_WinUtfToTChar(name, -1, &dString);
hr = CreateFileMoniker((LPOLESTR)Tcl_DStringValue(&dString), &pmkItem);
Tcl_DStringFree(&dString);