-/* mUPCreateControl creates a new user pane control and then it passes it
- to mUPOpenControl to initialize it as a scrolling text user pane control. */
-OSStatus mUPCreateControl(WindowPtr theWindow, Rect *bounds, ControlHandle *theControl) {
- short featurSet;
- /* the following feature set can be specified in CNTL resources by using
- the value 1214. When creating a user pane control, we pass this value
- in the 'value' parameter. */
- featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle
- | kControlWantsActivate | kControlHandlesTracking | kControlHasSpecialBackground
- | kControlGetsFocusOnClick | kControlSupportsLiveFeedback;
- /* create the control */
- *theControl = NewControl(theWindow, bounds, "\p", true, featurSet, 0, featurSet, kControlUserPaneProc, 0);
- /* set up the mUP specific features and data */
- mUPOpenControl(*theControl);
- /* all done.... */
- return noErr;
-}
-
-
-/* mUPDisposeControl calls mUPCloseControl and then it calls DisposeControl. */
-OSStatus mUPDisposeControl(ControlHandle theControl) {
- /* deallocate the mUP specific data */
- mUPCloseControl(theControl);
- /* deallocate the user pane control itself */
- DisposeControl(theControl);
- return noErr;
-}
-
-
-
-
-/* IsmUPControl returns true if theControl is not NULL
- and theControl refers to a mUP Control. */
-Boolean IsmUPControl(ControlHandle theControl) {
- Size theSize;
- ControlUserPaneFocusUPP localFocusProc;
- /* a NULL control is not a mUP control */
- if (theControl == NULL) return false;
- /* check if the control is using our focus procedure */
- theSize = sizeof(localFocusProc);
- if (GetControlData(theControl, kControlEntireControl, kControlUserPaneFocusProcTag,
- sizeof(localFocusProc), &localFocusProc, &theSize) != noErr) return false;
- if (localFocusProc != gTPFocusProc) return false;
- /* all tests passed, it's a mUP control */
- return true;
-}
-
-
-/* mUPDoEditCommand performs the editing command specified
- in the editCommand parameter. The mUPControl's text
- and scroll bar are redrawn and updated as necessary. */
-void mUPDoEditCommand(ControlHandle theControl, short editCommand) {
- STPTextPaneVars **tpvars;
- /* set up our locals */
- tpvars = (STPTextPaneVars **) GetControlReference(theControl);
- /* and our drawing environment as the operation
- may force a redraw in the text area. */
- SetPort((**tpvars).fDrawingEnvironment);
- /* perform the editing command */
- switch (editCommand) {
- case kmUPCut:
- ClearCurrentScrap();
- TXNCut((**tpvars).fTXNRec);
- TXNConvertToPublicScrap();
- break;
- case kmUPCopy:
- ClearCurrentScrap();
- TXNCopy((**tpvars).fTXNRec);
- TXNConvertToPublicScrap();
- break;
- case kmUPPaste:
- TXNConvertFromPublicScrap();
- TXNPaste((**tpvars).fTXNRec);
- break;
- case kmUPClear:
- TXNClear((**tpvars).fTXNRec);
- break;
- }
-}
-
-
-
-
-/* mUPGetContents returns the entire contents of the control including the text
- and the formatting information. */
-OSStatus mUPGetContents(ControlHandle theControl, Handle *theContents) {
- STPTextPaneVars **tpvars;
- OSStatus err;
- short vRefNum;
- long dirID;
- FSSpec tspec;
- short trefnum;
- Boolean texists;
- long bytecount;
- Handle localdata;
- /* set up locals */
- trefnum = 0;
- texists = false;
- localdata = NULL;
- tpvars = (STPTextPaneVars **) GetControlReference(theControl);
- if (theContents == NULL) return paramErr;
- /* create a temporary file */
- err = FindFolder(kOnSystemDisk, kTemporaryFolderType, true, &vRefNum, &dirID);
- if (err != noErr) goto bail;
- FSMakeFSSpec(vRefNum, dirID, "\pmUPGetContents", &tspec);
- err = FSpCreate(&tspec, 'trsh', 'trsh', smSystemScript);
- if (err != noErr) goto bail;
- texists = true;
- /* open the file */
- err = FSpOpenDF(&tspec, fsRdWrPerm, &trefnum);
- if (err != noErr) goto bail;
- /* save the data */
- err = TXNSave( (**tpvars).fTXNRec, kTXNTextensionFile, 0, kTXNSystemDefaultEncoding, &tspec, trefnum, 0);
- if (err != noErr) goto bail;
- /* get the file length and set the position */
- err = GetEOF(trefnum, &bytecount);
- if (err != noErr) goto bail;
- err = SetFPos(trefnum, fsFromStart, 0);
- if (err != noErr) goto bail;
- /* copy the data fork to a handle */
- localdata = NewHandle(bytecount);
- if (localdata == NULL) { err = memFullErr; goto bail; }
- HLock(localdata);
- err = FSRead(trefnum, &bytecount, *localdata);
- HUnlock(localdata);
- if (err != noErr) goto bail;
- /* store result */
- *theContents = localdata;
- /* clean up */
- FSClose(trefnum);
- FSpDelete(&tspec);
- /* all done */
- return noErr;
-bail:
- if (trefnum != 0) FSClose(trefnum);
- if (texists) FSpDelete(&tspec);
- if (localdata != NULL) DisposeHandle(localdata);
- return err;
+static void SetTXNData( STPTextPaneVars *varsp, TXNObject txn , const wxString& st , TXNOffset start , TXNOffset end )
+{
+#if wxUSE_UNICODE
+#if SIZEOF_WCHAR_T == 2
+ size_t len = st.Len() ;
+ TXNSetData( txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2,
+ start, end);
+#else
+ wxMBConvUTF16BE converter ;
+ ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ;
+ UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ;
+ converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ;
+ TXNSetData( txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen ,
+ start, end);
+ free( unibuf ) ;
+#endif
+#else
+ wxCharBuffer text = st.mb_str(wxConvLocal) ;
+ TXNSetData( txn , kTXNTextData, (void*)text.data(), strlen( text ) ,
+ start, end);
+#endif