summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2002-07-19 09:22:34 (GMT)
committervincentdarley <vincentdarley>2002-07-19 09:22:34 (GMT)
commitec7ab4e9c2f83c55f14c1102fdc60c8f6fb2b586 (patch)
tree17ddf287f87edf5ebd2f5f14899a2d9d97757dda
parent235b71b841c362bc965ce1de8d8cb30e17a281b5 (diff)
downloadtk-ec7ab4e9c2f83c55f14c1102fdc60c8f6fb2b586.zip
tk-ec7ab4e9c2f83c55f14c1102fdc60c8f6fb2b586.tar.gz
tk-ec7ab4e9c2f83c55f14c1102fdc60c8f6fb2b586.tar.bz2
Jim's patch for encodings
-rw-r--r--macosx/tkMacOSXAppInit.c28
-rw-r--r--macosx/tkMacOSXClipboard.c7
-rw-r--r--macosx/tkMacOSXDialog.c10
-rw-r--r--macosx/tkMacOSXInit.c84
-rw-r--r--macosx/tkMacOSXInt.h4
-rw-r--r--macosx/tkMacOSXKeyEvent.c7
-rw-r--r--macosx/tkMacOSXKeyboard.c8
-rw-r--r--macosx/tkMacOSXMenu.c15
8 files changed, 107 insertions, 56 deletions
diff --git a/macosx/tkMacOSXAppInit.c b/macosx/tkMacOSXAppInit.c
index c940cf7..fa7d626 100644
--- a/macosx/tkMacOSXAppInit.c
+++ b/macosx/tkMacOSXAppInit.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXAppInit.c,v 1.1.2.6 2002/06/10 05:38:26 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXAppInit.c,v 1.1.2.7 2002/07/19 09:22:34 vincentdarley Exp $
*/
#include <pthread.h>
#include "tk.h"
@@ -67,13 +67,6 @@ extern int Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
*----------------------------------------------------------------------
*/
-OSStatus
-myWindowHandler (EventHandlerCallRef inHandlerCallRef,
- EventRef inEvent, void *inUserData)
-{
- return noErr;
-}
-
int
main(argc, argv)
int argc; /* Number of command-line arguments. */
@@ -185,7 +178,6 @@ int
Tcl_AppInit(interp)
Tcl_Interp *interp; /* Interpreter for application. */
{
- SInt16 refNum;
char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
Tcl_Obj *pathPtr;
@@ -295,24 +287,6 @@ Tcl_AppInit(interp)
Tcl_SetVar(interp, "tcl_rcFileName", "~/.wishrc", TCL_GLOBAL_ONLY);
- {
- Rect windowRect = {50, 50, 150, 150};
- WindowRef windowRef;
- EventTargetRef target;
- struct EventTypeSpec myEventSpec = {kEventClassMouse, kEventMouseDown};
- Boolean isValid;
- OSStatus result;
-
- CreateNewWindow (kDocumentWindowClass, kWindowStandardHandlerAttribute,
- &windowRect, &windowRef);
- result = InstallStandardEventHandler (GetWindowEventTarget (windowRef));
- result = InstallWindowEventHandler (windowRef, NewEventHandlerUPP (myWindowHandler),
- 1, &myEventSpec, NULL, NULL);
- TransitionWindow(windowRef, kWindowZoomTransitionEffect, kWindowShowTransitionAction,
- NULL);
-
- }
-
return TCL_OK;
error:
diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c
index e62200a..c817081 100644
--- a/macosx/tkMacOSXClipboard.c
+++ b/macosx/tkMacOSXClipboard.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXClipboard.c,v 1.1.2.3 2002/07/18 23:45:18 vincentdarley Exp $
+ * RCS: @(#) $Id: tkMacOSXClipboard.c,v 1.1.2.4 2002/07/19 09:22:34 vincentdarley Exp $
*/
#include "tkInt.h"
@@ -19,8 +19,6 @@
#include <Carbon/Carbon.h>
-extern Tcl_Encoding macRomanEncoding;
-
/*
*----------------------------------------------------------------------
@@ -93,7 +91,8 @@ TkSelGetSelection(
return TCL_ERROR;
}
- Tcl_ExternalToUtfDString(macRomanEncoding, buf, length, &encodedText);
+ Tcl_ExternalToUtfDString(TkMacOSXCarbonEncoding, buf, length,
+ &encodedText);
result = (*proc)(clientData, interp,
Tcl_DStringValue(&encodedText));
Tcl_DStringFree(&encodedText);
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index 81b7d24..fdc4eeb 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.1.2.4 2002/07/18 23:45:18 vincentdarley Exp $
+ * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.1.2.5 2002/07/19 09:22:34 vincentdarley Exp $
*/
#include <Carbon/Carbon.h>
@@ -905,8 +905,12 @@ NavServicesGetFile(
pathValid = 1;
}
if (pathValid) {
- /* Tested this and NULL=utf-8 encoding is good here */
- Tcl_ExternalToUtfDString(NULL, pathPtr, -1, &fileName);
+ /*
+ * Tested this and NULL=utf-8 encoding is
+ * good here
+ */
+ Tcl_ExternalToUtfDString(NULL, pathPtr, -1,
+ &fileName);
if (multiple) {
Tcl_ListObjAppendElement(interp, theResult,
Tcl_NewStringObj(Tcl_DStringValue(&fileName),
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
index 04117bf..d6f9e03 100644
--- a/macosx/tkMacOSXInit.c
+++ b/macosx/tkMacOSXInit.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXInit.c,v 1.1.2.5 2002/07/18 23:45:18 vincentdarley Exp $
+ * RCS: @(#) $Id: tkMacOSXInit.c,v 1.1.2.6 2002/07/19 09:22:34 vincentdarley Exp $
*/
#include "tkInt.h"
@@ -22,7 +22,55 @@
*/
#include "tkInitScript.h"
-Tcl_Encoding macRomanEncoding = NULL;
+/*
+ * The following structures are used to map the script/language codes of a
+ * font to the name that should be passed to Tcl_GetEncoding() to obtain
+ * the encoding for that font. The set of numeric constants is fixed and
+ * defined by Apple.
+ */
+
+typedef struct Map {
+ int numKey;
+ char *strKey;
+} Map;
+
+static Map scriptMap[] = {
+ {smRoman, "macRoman"},
+ {smJapanese, "macJapan"},
+ {smTradChinese, "macChinese"},
+ {smKorean, "macKorean"},
+ {smArabic, "macArabic"},
+ {smHebrew, "macHebrew"},
+ {smGreek, "macGreek"},
+ {smCyrillic, "macCyrillic"},
+ {smRSymbol, "macRSymbol"},
+ {smDevanagari, "macDevanagari"},
+ {smGurmukhi, "macGurmukhi"},
+ {smGujarati, "macGujarati"},
+ {smOriya, "macOriya"},
+ {smBengali, "macBengali"},
+ {smTamil, "macTamil"},
+ {smTelugu, "macTelugu"},
+ {smKannada, "macKannada"},
+ {smMalayalam, "macMalayalam"},
+ {smSinhalese, "macSinhalese"},
+ {smBurmese, "macBurmese"},
+ {smKhmer, "macKhmer"},
+ {smThai, "macThailand"},
+ {smLaotian, "macLaos"},
+ {smGeorgian, "macGeorgia"},
+ {smArmenian, "macArmenia"},
+ {smSimpChinese, "macSimpChinese"},
+ {smTibetan, "macTIbet"},
+ {smMongolian, "macMongolia"},
+ {smGeez, "macEthiopia"},
+ {smEastEurRoman, "macCentEuro"},
+ {smVietnamese, "macVietnam"},
+ {smExtArabic, "macSindhi"},
+ {NULL, NULL}
+};
+
+Tcl_Encoding TkMacOSXCarbonEncoding = NULL;
/*
@@ -50,12 +98,10 @@ TkpInit(interp)
char tkLibPath[1024];
int result;
static int menusInitialized = false;
+ static int carbonEncodingInitialized = false;
- if (macRomanEncoding == NULL) {
- macRomanEncoding = Tcl_GetEncoding(NULL, "macRoman");
- }
-
- /* Since it is possible for TkInit to be called multiple times
+ /*
+ * Since it is possible for TkInit to be called multiple times
* and we don't want to do the menu initialization multiple times
* we protect against doing it more than once.
*/
@@ -66,6 +112,30 @@ TkpInit(interp)
TkMacOSXInitAppleEvents(interp);
TkMacOSXInitMenus(interp);
}
+
+ if (carbonEncodingInitialized == false) {
+ CFStringEncoding encoding;
+ char *encodingStr = NULL;
+ int i;
+
+ encoding = CFStringGetSystemEncoding();
+
+ for (i = 0; scriptMap[i].strKey != NULL; i++) {
+ if (scriptMap[i].numKey == encoding) {
+ encodingStr = scriptMap[i].strKey;
+ break;
+ }
+ }
+ if (encodingStr == NULL) {
+ encodingStr = "macRoman";
+ }
+
+ TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, encodingStr);
+ if (TkMacOSXCarbonEncoding == NULL) {
+ TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, NULL);
+ }
+ }
+
Tcl_SetVar2(interp, "tcl_platform", "windowingsystem",
"aqua", TCL_GLOBAL_ONLY);
diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h
index 0a10090..750d966 100644
--- a/macosx/tkMacOSXInt.h
+++ b/macosx/tkMacOSXInt.h
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXInt.h,v 1.1.2.1 2001/10/15 09:22:00 wolfsuit Exp $
+ * RCS: @(#) $Id: tkMacOSXInt.h,v 1.1.2.2 2002/07/19 09:22:34 vincentdarley Exp $
*/
#ifndef _TKMACINT
@@ -135,6 +135,8 @@ extern int tkPictureIsOpen; /* If this is 1, we are drawing to a pic
extern TkMacOSXWindowList *tkMacOSXWindowListPtr;
/* The list of toplevels */
+extern Tcl_Encoding TkMacOSXCarbonEncoding;
+
#include "tkIntPlatDecls.h"
#endif /* _TKMACINT */
diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c
index 6481abb..7c3474c 100644
--- a/macosx/tkMacOSXKeyEvent.c
+++ b/macosx/tkMacOSXKeyEvent.c
@@ -55,8 +55,6 @@
#include "tkPort.h"
#include "tkMacOSXEvent.h"
-extern Tcl_Encoding macRomanEncoding;
-
typedef struct {
WindowRef whichWindow;
Point global;
@@ -100,7 +98,7 @@ int TkMacOSXProcessKeyboardEvent(
TkMacOSXEvent * eventPtr,
MacEventStatus * statusPtr)
{
- UInt32 savedKeyCode = 0;
+ static UInt32 savedKeyCode = 0;
OSStatus status;
KeyEventData keyEventData;
Window window;
@@ -243,7 +241,8 @@ GenerateKeyEvent( EventKind eKind,
}
byte = (e->message&charCodeMask);
if ((savedKeyCode == 0) &&
- (Tcl_ExternalToUtf(NULL, macRomanEncoding, (char *) &byte, 1, 0, NULL,
+ (Tcl_ExternalToUtf(NULL, TkMacOSXCarbonEncoding,
+ (char *) &byte, 1, 0, NULL,
buf, sizeof(buf), NULL, NULL, NULL) != TCL_OK)) {
/*
* This event specifies a lead byte. Wait for the second byte
diff --git a/macosx/tkMacOSXKeyboard.c b/macosx/tkMacOSXKeyboard.c
index fc6baa6..a2778a3 100644
--- a/macosx/tkMacOSXKeyboard.c
+++ b/macosx/tkMacOSXKeyboard.c
@@ -9,15 +9,14 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXKeyboard.c,v 1.1.2.2 2002/07/18 23:45:18 vincentdarley Exp $
+ * RCS: @(#) $Id: tkMacOSXKeyboard.c,v 1.1.2.3 2002/07/19 09:22:34 vincentdarley Exp $
*/
#include "tkInt.h"
#include "X11/Xlib.h"
#include "X11/keysym.h"
#include <Carbon/Carbon.h>
-
-extern Tcl_Encoding macRomanEncoding;
+#include "tkMacOSXInt.h"
typedef struct {
short keycode; /* Macintosh keycode */
@@ -249,7 +248,8 @@ TkpGetString(
len = 0;
}
}
- return Tcl_ExternalToUtfDString(macRomanEncoding, string, len, dsPtr);
+ return Tcl_ExternalToUtfDString(TkMacOSXCarbonEncoding, string,
+ len, dsPtr);
}
/*
diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c
index dfb62a3..22934d4 100644
--- a/macosx/tkMacOSXMenu.c
+++ b/macosx/tkMacOSXMenu.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.1.2.6 2002/07/18 23:45:18 vincentdarley Exp $
+ * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.1.2.7 2002/07/19 09:22:34 vincentdarley Exp $
*/
#include "tkMacOSXInt.h"
#include "tkMenuButton.h"
@@ -25,8 +25,6 @@
#include "tkMacOSXDebug.h"
#include <CoreFoundation/CFString.h>
-extern Tcl_Encoding macRomanEncoding;
-
typedef struct MacMenu {
MenuRef menuHdl; /* The Menu Manager data structure. */
Rect menuRect; /* The rectangle as calculated in the
@@ -3809,9 +3807,14 @@ TkpMenuInit(void)
tkThemeMenuItemDrawingUPP
= NewMenuItemDrawingUPP(tkThemeMenuItemDrawingProc);
- Tcl_ExternalToUtf(NULL, macRomanEncoding, "\311", /* ellipsis character */
- -1, 0, NULL, elipsisString,
- TCL_UTF_MAX + 1, NULL, NULL, NULL);
+ /*
+ * We should just hardcode the utf-8 ellipsis character into
+ * 'elipsisString' here
+ */
+ Tcl_ExternalToUtf(NULL, Tcl_GetEncoding(NULL, "macRoman"),
+ "\311", /* ellipsis character */
+ -1, 0, NULL, elipsisString,
+ TCL_UTF_MAX + 1, NULL, NULL, NULL);
useMDEFVar = Tcl_NewStringObj("::tk::mac::useCustomMDEF", -1);
}