1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textctrl.h"
21 #include <sys/types.h>
27 #if wxUSE_STD_IOSTREAM
37 #include "wx/button.h"
38 #include "wx/toplevel.h"
39 #include "wx/textctrl.h"
40 #include "wx/notebook.h"
41 #include "wx/tabctrl.h"
42 #include "wx/settings.h"
43 #include "wx/filefn.h"
46 #if defined(__BORLANDC__) && !defined(__WIN32__)
48 #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
55 #include <MacTextEditor.h>
56 #include "ATSUnicode.h"
57 #include "TextCommon.h"
58 #include "TextEncodingConverter.h"
59 #include "wx/mac/uma.h"
61 #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
63 extern wxControl
*wxFindControlFromMacControl(ControlHandle inControl
) ;
65 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
66 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
67 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
68 // an alternate path for carbon key events that routes automatically into the same wx flow of events
70 #include "MacTextEditor.h"
74 /* kmUPTextPart is the part code we return to indicate the user has clicked
75 in the text area of our control */
76 #define kmUPTextPart 1
78 /* kmUPScrollPart is the part code we return to indicate the user has clicked
79 in the scroll bar part of the control. */
80 #define kmUPScrollPart 2
83 /* routines for using existing user pane controls.
84 These routines are useful for cases where you would like to use an
85 existing user pane control in, say, a dialog window as a scrolling
88 /* mUPOpenControl initializes a user pane control so it will be drawn
89 and will behave as a scrolling text edit field inside of a window.
90 This routine performs all of the initialization steps necessary,
91 except it does not create the user pane control itself. theControl
92 should refer to a user pane control that you have either created
93 yourself or extracted from a dialog's control heirarchy using
94 the GetDialogItemAsControl routine. */
95 OSStatus
mUPOpenControl(ControlHandle theControl
, long wxStyle
);
97 /* Utility Routines */
103 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
104 routine. In our focus switching routine this part code is understood
105 as meaning 'the user has clicked in the control and we need to switch
106 the current focus to ourselves before we can continue'. */
107 #define kUserClickedToFocusPart 100
110 /* kmUPClickScrollDelayTicks is a time measurement in ticks used to
111 slow the speed of 'auto scrolling' inside of our clickloop routine.
112 This value prevents the text from wizzzzzing by while the mouse
113 is being held down inside of the text area. */
114 #define kmUPClickScrollDelayTicks 3
117 /* STPTextPaneVars is a structure used for storing the the mUP Control's
118 internal variables and state information. A handle to this record is
119 stored in the pane control's reference value field using the
120 SetControlReference routine. */
123 /* OS records referenced */
124 TXNObject fTXNRec
; /* the txn record */
125 TXNFrameID fTXNFrame
; /* the txn frame ID */
126 ControlHandle fUserPaneRec
; /* handle to the user pane control */
127 WindowPtr fOwner
; /* window containing control */
128 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
130 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
131 Boolean fIsActive
; /* true while the control is drawn in the active state */
132 Boolean fTEActive
; /* reflects the activation state of the text edit record */
133 Boolean fInDialogWindow
; /* true if displayed in a dialog window */
134 /* calculated locations */
135 Rect fRTextArea
; /* area where the text is drawn */
136 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
137 Rect fRTextOutline
; /* rectangle used to draw the border */
138 RgnHandle fTextBackgroundRgn
; /* background region for the text, erased before calling TEUpdate */
139 /* our focus advance override routine */
140 EventHandlerUPP handlerUPP
;
141 EventHandlerRef handlerRef
;
148 /* Univerals Procedure Pointer variables used by the
149 mUP Control. These variables are set up
150 the first time that mUPOpenControl is called. */
151 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
152 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
153 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
154 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
155 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
156 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
157 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
159 /* TPActivatePaneText activates or deactivates the text edit record
160 according to the value of setActive. The primary purpose of this
161 routine is to ensure each call is only made once. */
162 static void TPActivatePaneText(STPTextPaneVars
**tpvars
, Boolean setActive
) {
163 STPTextPaneVars
*varsp
;
165 if (varsp
->fTEActive
!= setActive
) {
167 varsp
->fTEActive
= setActive
;
169 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTEActive
);
172 TXNFocus( varsp
->fTXNRec
, varsp
->fTEActive
);
177 /* TPFocusPaneText set the focus state for the text record. */
178 static void TPFocusPaneText(STPTextPaneVars
**tpvars
, Boolean setFocus
) {
179 STPTextPaneVars
*varsp
;
181 if (varsp
->fInFocus
!= setFocus
) {
182 varsp
->fInFocus
= setFocus
;
183 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
188 /* TPPaneDrawProc is called to redraw the control and for update events
189 referring to the control. This routine erases the text area's background,
190 and redraws the text. This routine assumes the scroll bar has been
191 redrawn by a call to DrawControls. */
192 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
193 STPTextPaneVars
**tpvars
, *varsp
;
196 /* set up our globals */
198 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
199 if (tpvars
!= NULL
) {
200 state
= HGetState((Handle
) tpvars
);
201 HLock((Handle
) tpvars
);
204 /* save the drawing state */
205 SetPort((**tpvars
).fDrawingEnvironment
);
206 /* verify our boundary */
207 GetControlBounds(theControl
, &bounds
);
209 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
210 if ( ! EqualRect(&bounds
, &varsp
->fRFocusOutline
) ) {
211 // scrollbar is on the border, we add one
212 Rect oldbounds
= varsp
->fRFocusOutline
;
213 InsetRect( &oldbounds
, -1 , -1 ) ;
215 InvalWindowRect( GetControlOwner( theControl
) , &oldbounds
) ;
216 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
217 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
218 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
219 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
220 RectRgn(varsp
->fTextBackgroundRgn
, &varsp
->fRTextOutline
);
221 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
222 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
225 /* update the text region */
226 RGBColor white
= { 65535 , 65535 , 65535 } ;
227 RGBBackColor( &white
) ;
228 EraseRgn(varsp
->fTextBackgroundRgn
);
229 TXNDraw(varsp
->fTXNRec
, NULL
);
230 /* restore the drawing environment */
231 /* draw the text frame and focus frame (if necessary) */
232 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
233 if ((**tpvars
).fIsActive
&& varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, true);
234 /* release our globals */
235 HSetState((Handle
) tpvars
, state
);
241 /* TPPaneHitTestProc is called when the control manager would
242 like to determine what part of the control the mouse resides over.
243 We also call this routine from our tracking proc to determine how
244 to handle mouse clicks. */
245 static pascal ControlPartCode
TPPaneHitTestProc(ControlHandle theControl
, Point where
) {
246 STPTextPaneVars
**tpvars
;
247 ControlPartCode result
;
249 /* set up our locals and lock down our globals*/
251 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
252 if (tpvars
!= NULL
) {
253 state
= HGetState((Handle
) tpvars
);
254 HLock((Handle
) tpvars
);
255 /* find the region where we clicked */
256 if (PtInRect(where
, &(**tpvars
).fRTextArea
)) {
257 result
= kmUPTextPart
;
259 /* release oure globals */
260 HSetState((Handle
) tpvars
, state
);
269 /* TPPaneTrackingProc is called when the mouse is being held down
270 over our control. This routine handles clicks in the text area
271 and in the scroll bar. */
272 static pascal ControlPartCode
TPPaneTrackingProc(ControlHandle theControl
, Point startPt
, ControlActionUPP actionProc
) {
273 STPTextPaneVars
**tpvars
, *varsp
;
275 ControlPartCode partCodeResult
;
276 /* make sure we have some variables... */
278 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
279 if (tpvars
!= NULL
) {
281 state
= HGetState((Handle
) tpvars
);
282 HLock((Handle
) tpvars
);
284 /* we don't do any of these functions unless we're in focus */
285 if ( ! varsp
->fInFocus
) {
287 owner
= GetControlOwner(theControl
);
288 ClearKeyboardFocus(owner
);
289 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
291 /* find the location for the click */
292 switch (TPPaneHitTestProc(theControl
, startPt
)) {
294 /* handle clicks in the text part */
296 { SetPort((**tpvars
).fDrawingEnvironment
);
297 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
299 TXNClick( varsp
->fTXNRec
, (const EventRecord
*) wxTheApp
->MacGetCurrentEvent());
302 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
303 TXNClick( varsp
->fTXNRec
, &rec
);
310 HSetState((Handle
) tpvars
, state
);
312 return partCodeResult
;
316 /* TPPaneIdleProc is our user pane idle routine. When our text field
317 is active and in focus, we use this routine to set the cursor. */
318 static pascal void TPPaneIdleProc(ControlHandle theControl
) {
319 STPTextPaneVars
**tpvars
, *varsp
;
321 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
322 if (tpvars
!= NULL
) {
323 /* if we're not active, then we have nothing to say about the cursor */
324 if ((**tpvars
).fIsActive
) {
328 /* lock down the globals */
329 state
= HGetState((Handle
) tpvars
);
330 HLock((Handle
) tpvars
);
332 /* get the current mouse coordinates (in our window) */
333 SetPortWindowPort(GetControlOwner(theControl
));
334 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
336 /* there's a 'focus thing' and an 'unfocused thing' */
337 if (varsp
->fInFocus
) {
338 /* flash the cursor */
339 SetPort((**tpvars
).fDrawingEnvironment
);
340 TXNIdle(varsp
->fTXNRec
);
342 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
344 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
345 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
350 // SetThemeCursor(kThemeArrowCursor);
353 /* if it's in our bounds, set the cursor */
354 GetControlBounds(theControl
, &bounds
);
355 if (PtInRect(mousep
, &bounds
))
357 // SetThemeCursor(kThemeArrowCursor);
361 HSetState((Handle
) tpvars
, state
);
367 /* TPPaneKeyDownProc is called whenever a keydown event is directed
368 at our control. Here, we direct the keydown event to the text
369 edit record and redraw the scroll bar and text field as appropriate. */
370 static pascal ControlPartCode
TPPaneKeyDownProc(ControlHandle theControl
,
371 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
372 STPTextPaneVars
**tpvars
;
373 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
374 if (tpvars
!= NULL
) {
375 if ((**tpvars
).fInFocus
) {
376 /* turn autoscrolling on and send the key event to text edit */
377 SetPort((**tpvars
).fDrawingEnvironment
);
378 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
380 memset( &ev
, 0 , sizeof( ev
) ) ;
382 ev
.modifiers
= modifiers
;
383 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
384 TXNKeyDown( (**tpvars
).fTXNRec
, &ev
);
387 return kControlEntireControl
;
391 /* TPPaneActivateProc is called when the window containing
392 the user pane control receives activate events. Here, we redraw
393 the control and it's text as necessary for the activation state. */
394 static pascal void TPPaneActivateProc(ControlHandle theControl
, Boolean activating
) {
396 STPTextPaneVars
**tpvars
, *varsp
;
399 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
400 if (tpvars
!= NULL
) {
401 state
= HGetState((Handle
) tpvars
);
402 HLock((Handle
) tpvars
);
404 /* de/activate the text edit record */
405 SetPort((**tpvars
).fDrawingEnvironment
);
406 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
407 GetControlBounds(theControl
, &bounds
);
408 varsp
->fIsActive
= activating
;
409 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
410 /* redraw the frame */
411 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
412 if (varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
);
413 HSetState((Handle
) tpvars
, state
);
418 /* TPPaneFocusProc is called when every the focus changes to or
419 from our control. Herein, switch the focus appropriately
420 according to the parameters and redraw the control as
422 static pascal ControlPartCode
TPPaneFocusProc(ControlHandle theControl
, ControlFocusPart action
) {
423 ControlPartCode focusResult
;
424 STPTextPaneVars
**tpvars
, *varsp
;
427 focusResult
= kControlFocusNoPart
;
428 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
429 if (tpvars
!= NULL
&& IsControlVisible( theControl
) ) {
430 state
= HGetState((Handle
) tpvars
);
431 HLock((Handle
) tpvars
);
433 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
434 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
435 and kControlFocusNextPart will be received. When the user clicks in our field
436 and it is not the current focus, then the constant kUserClickedToFocusPart will
437 be received. The constant kControlFocusNoPart will be received when our control
438 is the current focus and the user clicks in another control. In your focus routine,
439 you should respond to these codes as follows:
441 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
442 the control and the focus rectangle as necessary.
444 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
445 depending on its current state. redraw the control and the focus rectangle
446 as appropriate for the new focus state. If the focus state is 'off', return the constant
447 kControlFocusNoPart, otherwise return a non-zero part code.
448 kUserClickedToFocusPart - is a constant defined for this example. You should
449 define your own value for handling click-to-focus type events. */
450 /* save the drawing state */
451 SetPort((**tpvars
).fDrawingEnvironment
);
452 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
453 /* calculate the next highlight state */
456 case kControlFocusNoPart
:
457 TPFocusPaneText(tpvars
, false);
458 focusResult
= kControlFocusNoPart
;
460 case kUserClickedToFocusPart
:
461 TPFocusPaneText(tpvars
, true);
464 case kControlFocusPrevPart
:
465 case kControlFocusNextPart
:
466 TPFocusPaneText(tpvars
, ( ! varsp
->fInFocus
));
467 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
470 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
471 /* redraw the text fram and focus rectangle to indicate the
473 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
474 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
&& varsp
->fInFocus
);
476 HSetState((Handle
) tpvars
, state
);
482 /* mUPOpenControl initializes a user pane control so it will be drawn
483 and will behave as a scrolling text edit field inside of a window.
484 This routine performs all of the initialization steps necessary,
485 except it does not create the user pane control itself. theControl
486 should refer to a user pane control that you have either created
487 yourself or extracted from a dialog's control heirarchy using
488 the GetDialogItemAsControl routine. */
489 OSStatus
mUPOpenControl(ControlHandle theControl
, long wxStyle
)
493 STPTextPaneVars
**tpvars
, *varsp
;
494 OSStatus err
= noErr
;
495 RGBColor rgbWhite
= {0xFFFF, 0xFFFF, 0xFFFF};
498 /* set up our globals */
499 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
500 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
501 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
502 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
503 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
504 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
505 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
507 /* allocate our private storage */
508 tpvars
= (STPTextPaneVars
**) NewHandleClear(sizeof(STPTextPaneVars
));
509 SetControlReference(theControl
, (long) tpvars
);
510 HLock((Handle
) tpvars
);
512 /* set the initial settings for our private data */
513 varsp
->fMultiline
= wxStyle
& wxTE_MULTILINE
;
514 varsp
->fInFocus
= false;
515 varsp
->fIsActive
= true;
516 varsp
->fTEActive
= true; // in order to get a deactivate
517 varsp
->fUserPaneRec
= theControl
;
518 theWindow
= varsp
->fOwner
= GetControlOwner(theControl
);
520 varsp
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
522 varsp
->fInDialogWindow
= ( GetWindowKind(varsp
->fOwner
) == kDialogWindowKind
);
523 /* set up the user pane procedures */
524 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
525 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
526 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
527 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
528 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
529 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
530 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
531 /* calculate the rectangles used by the control */
532 GetControlBounds(theControl
, &bounds
);
533 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
534 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
535 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
536 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
537 /* calculate the background region for the text. In this case, it's kindof
538 and irregular region because we're setting the scroll bar a little ways inside
540 RectRgn((varsp
->fTextBackgroundRgn
= NewRgn()), &varsp
->fRTextOutline
);
542 /* set up the drawing environment */
543 SetPort(varsp
->fDrawingEnvironment
);
545 /* create the new edit field */
547 TXNFrameOptions frameOptions
=
548 kTXNDontDrawCaretWhenInactiveMask
;
549 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
550 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
552 if ( wxStyle
& wxTE_MULTILINE
)
554 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
555 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
558 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
559 frameOptions
|= kTXNWantHScrollBarMask
;
562 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
563 frameOptions
|= kTXNWantVScrollBarMask
;
566 frameOptions
|= kTXNSingleLineOnlyMask
;
568 if ( wxStyle
& wxTE_READONLY
)
569 frameOptions
|= kTXNReadOnlyMask
;
571 TXNNewObject(NULL
, varsp
->fOwner
, &varsp
->fRTextArea
,
573 kTXNTextEditStyleFrameType
,
575 kTXNSystemDefaultEncoding
,
576 &varsp
->fTXNRec
, &varsp
->fTXNFrame
, (TXNObjectRefcon
) tpvars
);
578 if ( (wxStyle
& wxTE_MULTILINE
) && (wxStyle
& wxTE_DONTWRAP
) )
580 TXNControlTag tag
= kTXNWordWrapStateTag
;
582 dat
.uValue
= kTXNNoAutoWrap
;
583 TXNSetTXNObjectControls( varsp
->fTXNRec
, false , 1 , &tag
, &dat
) ;
589 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
591 TXNTypeAttributes typeAttr
[] =
593 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
594 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
595 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
598 err
= TXNSetTypeAttributes (varsp
->fTXNRec
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
601 /* set the field's background */
603 tback
.bgType
= kTXNBackgroundTypeRGB
;
604 tback
.bg
.color
= rgbWhite
;
605 TXNSetBackground( varsp
->fTXNRec
, &tback
);
607 /* unlock our storage */
608 HUnlock((Handle
) tpvars
);
609 /* perform final activations and setup for our text field. Here,
610 we assume that the window is going to be the 'active' window. */
611 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
619 #if !USE_SHARED_LIBRARY
620 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
622 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
623 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
624 EVT_CHAR(wxTextCtrl::OnChar
)
625 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
626 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
627 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
628 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
629 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
631 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
632 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
633 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
634 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
635 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
640 void wxTextCtrl::Init()
644 m_macTXNvars
= NULL
;
645 m_macUsesTXN
= false ;
650 m_maxLength
= TE_UNLIMITED_LENGTH
;
653 wxTextCtrl::~wxTextCtrl()
657 SetControlReference((ControlHandle
)m_macControl
, 0) ;
658 TXNDeleteObject((TXNObject
)m_macTXN
);
659 /* delete our private storage */
660 DisposeHandle((Handle
) m_macTXNvars
);
661 /* zero the control reference */
665 const short kVerticalMargin
= 2 ;
666 const short kHorizontalMargin
= 2 ;
668 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
671 const wxSize
& size
, long style
,
672 const wxValidator
& validator
,
673 const wxString
& name
)
677 m_macTXNvars
= NULL
;
678 m_macUsesTXN
= false ;
681 m_macUsesTXN
= ! (style
& wxTE_PASSWORD
) ;
683 m_macUsesTXN
&= (TXNInitTextension
!= (void*) kUnresolvedCFragSymbolAddress
) ;
685 // base initialization
686 if ( !wxTextCtrlBase::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
689 wxSize mySize
= size
;
692 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
693 m_macVerticalBorder
= 3 ;
697 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
698 m_macVerticalBorder
= 5 ;
705 if ( mySize.y == -1 )
708 if ( m_windowStyle & wxTE_MULTILINE )
711 mySize.y += 2 * m_macVerticalBorder ;
714 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, mySize
,style
, validator
, name
, &bounds
, title
) ;
716 if ( m_windowStyle
& wxTE_MULTILINE
)
718 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
719 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
721 m_windowStyle
|= wxTE_PROCESS_ENTER
;
724 if ( m_windowStyle
& wxTE_READONLY
)
731 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, "\p" , true , 0 , 0 , 1,
732 (style
& wxTE_PASSWORD
) ? kControlEditTextPasswordProc
: kControlEditTextProc
, (long) this ) ;
734 ::GetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*)((TEHandle
*)&m_macTE
) , &size
) ;
741 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
742 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
743 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
744 /* create the control */
745 m_macControl
= NewControl(MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, "\p", true, featurSet
, 0, featurSet
, kControlUserPaneProc
, 0);
746 /* set up the mUP specific features and data */
747 mUPOpenControl((ControlHandle
) m_macControl
, m_windowStyle
);
749 MacPostControlCreate() ;
753 wxCharBuffer text
= wxMacStringToCString( st
) ;
754 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, strlen(text
) , text
) ;
758 STPTextPaneVars
**tpvars
;
760 tpvars
= (STPTextPaneVars
**) GetControlReference((ControlHandle
) m_macControl
);
761 /* set the text in the record */
762 m_macTXN
= (**tpvars
).fTXNRec
;
764 TXNSetData( ((TXNObject
) m_macTXN
) , kTXNUnicodeTextData
, (void*)st
.wc_str(), st
.Length() * 2,
765 kTXNStartOffset
, kTXNEndOffset
);
767 wxCharBuffer text
= wxMacStringToCString( st
) ;
768 TXNSetData( ((TXNObject
) m_macTXN
) , kTXNTextData
, (void*)text
.data(), strlen( text
) ,
769 kTXNStartOffset
, kTXNEndOffset
);
771 m_macTXNvars
= tpvars
;
772 m_macUsesTXN
= true ;
773 TXNSetSelection( (TXNObject
) m_macTXN
, 0, 0);
774 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
780 wxString
wxTextCtrl::GetValue() const
787 err
= ::GetControlDataSize((ControlHandle
) m_macControl
, 0,
788 ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, &actualSize
) ;
791 return wxEmptyString
;
793 if ( actualSize
> 0 )
795 wxCharBuffer
buf(actualSize
) ;
796 ::GetControlData( (ControlHandle
) m_macControl
, 0,
797 ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
,
798 actualSize
, buf
.data() , &actualSize
) ;
799 result
= wxMacMakeStringFromCString( buf
) ;
806 err
= TXNGetDataEncoded( ((TXNObject
) m_macTXN
), kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
814 actualSize
= GetHandleSize( theText
) ;
815 if ( actualSize
> 0 )
817 wxChar
*ptr
= result
.GetWriteBuf(actualSize
*sizeof(wxChar
)) ;
818 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
819 ptr
[actualSize
] = 0 ;
820 result
.UngetWriteBuf( actualSize
) ;
822 DisposeHandle( theText
) ;
826 err
= TXNGetDataEncoded( ((TXNObject
) m_macTXN
), kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
834 actualSize
= GetHandleSize( theText
) ;
835 if ( actualSize
> 0 )
838 result
= wxMacMakeStringFromCString( *theText
, actualSize
) ;
841 DisposeHandle( theText
) ;
849 void wxTextCtrl::GetSelection(long* from
, long* to
) const
853 *from
= (**((TEHandle
) m_macTE
)).selStart
;
854 *to
= (**((TEHandle
) m_macTE
)).selEnd
;
858 TXNGetSelection( ((TXNObject
) m_macTXN
) , (TXNOffset
*) from
, (TXNOffset
*) to
) ;
862 void wxTextCtrl::SetValue(const wxString
& st
)
866 wxCharBuffer text
= wxMacStringToCString( st
) ;
867 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, strlen(text
) , text
) ;
871 bool formerEditable
= m_editable
;
872 if ( !formerEditable
)
875 TXNSetData( ((TXNObject
) m_macTXN
), kTXNUnicodeTextData
, (void*)st
.wc_str(), st
.Length() * 2 ,
876 kTXNStartOffset
, kTXNEndOffset
);
878 wxCharBuffer text
= wxMacStringToCString( st
) ;
879 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)text
.data(), strlen( text
) ,
880 kTXNStartOffset
, kTXNEndOffset
);
882 TXNSetSelection( (TXNObject
) m_macTXN
, 0, 0);
883 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
884 if ( !formerEditable
)
885 SetEditable(formerEditable
) ;
890 void wxTextCtrl::SetMaxLength(unsigned long len
)
895 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
899 bool formerEditable
= m_editable
;
900 if ( !formerEditable
)
902 TXNTypeAttributes typeAttr
[4] ;
903 Str255 fontName
= "\pMonaco" ;
904 SInt16 fontSize
= 12 ;
905 Style fontStyle
= normal
;
907 int attrCounter
= 0 ;
908 if ( style
.HasFont() )
910 const wxFont
&font
= style
.GetFont() ;
911 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
912 fontSize
= font
.GetPointSize() ;
913 if ( font
.GetUnderlined() )
914 fontStyle
|= underline
;
915 if ( font
.GetWeight() == wxBOLD
)
917 if ( font
.GetStyle() == wxITALIC
)
918 fontStyle
|= italic
;
920 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
921 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
922 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
923 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
924 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
925 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
926 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
927 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
928 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
932 if ( style
.HasTextColour() )
934 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
935 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
936 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
937 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
941 if ( attrCounter
> 0 )
945 #endif // __WXDEBUG__
946 TXNSetTypeAttributes ((TXNObject
)m_macTXN
, attrCounter
, typeAttr
, start
,end
);
947 wxASSERT_MSG( status
== noErr
, wxT("Couldn't set text attributes") ) ;
949 if ( !formerEditable
)
950 SetEditable(formerEditable
) ;
955 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
957 wxTextCtrlBase::SetDefaultStyle( style
) ;
958 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
962 // Clipboard operations
963 void wxTextCtrl::Copy()
969 TECopy( ((TEHandle
) m_macTE
) ) ;
977 TXNCopy((TXNObject
)m_macTXN
);
978 TXNConvertToPublicScrap();
983 void wxTextCtrl::Cut()
989 TECut( ((TEHandle
) m_macTE
) ) ;
997 TXNCut((TXNObject
)m_macTXN
);
998 TXNConvertToPublicScrap();
1000 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1001 event
.SetString( GetValue() ) ;
1002 event
.SetEventObject( this );
1003 GetEventHandler()->ProcessEvent(event
);
1007 void wxTextCtrl::Paste()
1011 if ( !m_macUsesTXN
)
1014 TEPaste( (TEHandle
) m_macTE
) ;
1015 MacRedrawControl() ;
1019 TXNConvertFromPublicScrap();
1020 TXNPaste((TXNObject
)m_macTXN
);
1021 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
1023 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1024 event
.SetString( GetValue() ) ;
1025 event
.SetEventObject( this );
1026 GetEventHandler()->ProcessEvent(event
);
1030 bool wxTextCtrl::CanCopy() const
1032 // Can copy if there's a selection
1034 GetSelection(& from
, & to
);
1035 return (from
!= to
);
1038 bool wxTextCtrl::CanCut() const
1040 if ( !IsEditable() )
1044 // Can cut if there's a selection
1046 GetSelection(& from
, & to
);
1047 return (from
!= to
);
1050 bool wxTextCtrl::CanPaste() const
1056 OSStatus err
= noErr
;
1059 err
= GetCurrentScrap( &scrapRef
);
1060 if ( err
!= noTypeErr
&& err
!= memFullErr
)
1062 ScrapFlavorFlags flavorFlags
;
1065 if (( err
= GetScrapFlavorFlags( scrapRef
, 'TEXT', &flavorFlags
)) == noErr
)
1067 if (( err
= GetScrapFlavorSize( scrapRef
, 'TEXT', &byteCount
)) == noErr
)
1077 if ( GetScrap( NULL
, 'TEXT' , &offset
) > 0 )
1085 void wxTextCtrl::SetEditable(bool editable
)
1087 if ( editable
!= m_editable
)
1089 m_editable
= editable
;
1090 if ( !m_macUsesTXN
)
1093 UMAActivateControl( (ControlHandle
) m_macControl
) ;
1095 UMADeactivateControl((ControlHandle
) m_macControl
) ;
1099 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1100 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1101 TXNSetTXNObjectControls( (TXNObject
) m_macTXN
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1106 void wxTextCtrl::SetInsertionPoint(long pos
)
1108 SetSelection( pos
, pos
) ;
1111 void wxTextCtrl::SetInsertionPointEnd()
1113 long pos
= GetLastPosition();
1114 SetInsertionPoint(pos
);
1117 long wxTextCtrl::GetInsertionPoint() const
1120 GetSelection( &begin
, &end
) ;
1124 long wxTextCtrl::GetLastPosition() const
1126 if ( !m_macUsesTXN
)
1128 return (**((TEHandle
) m_macTE
)).teLength
;
1134 OSErr err
= TXNGetDataEncoded( (TXNObject
) m_macTXN
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1142 actualsize
= GetHandleSize( theText
) ;
1143 DisposeHandle( theText
) ;
1149 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
1151 if ( !m_macUsesTXN
)
1153 ControlEditTextSelectionRec selection
;
1155 selection
.selStart
= from
;
1156 selection
.selEnd
= to
;
1157 ::SetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1158 TESetSelect( from
, to
, ((TEHandle
) m_macTE
) ) ;
1159 TEDelete( ((TEHandle
) m_macTE
) ) ;
1160 TEInsert( value
, value
.Length() , ((TEHandle
) m_macTE
) ) ;
1164 bool formerEditable
= m_editable
;
1165 if ( !formerEditable
)
1167 TXNSetSelection( ((TXNObject
) m_macTXN
) , from
, to
) ;
1168 TXNClear( ((TXNObject
) m_macTXN
) ) ;
1170 TXNSetData( ((TXNObject
) m_macTXN
), kTXNUnicodeTextData
, (void*)value
.wc_str(), value
.Length() * 2 ,
1171 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1173 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)value
.c_str(), value
.Length(),
1174 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1176 if ( !formerEditable
)
1177 SetEditable( formerEditable
) ;
1182 void wxTextCtrl::Remove(long from
, long to
)
1184 if ( !m_macUsesTXN
)
1186 ControlEditTextSelectionRec selection
;
1188 selection
.selStart
= from
;
1189 selection
.selEnd
= to
;
1190 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1191 TEDelete( ((TEHandle
) m_macTE
) ) ;
1195 bool formerEditable
= m_editable
;
1196 if ( !formerEditable
)
1198 TXNSetSelection( ((TXNObject
) m_macTXN
) , from
, to
) ;
1199 TXNClear( ((TXNObject
) m_macTXN
) ) ;
1200 if ( !formerEditable
)
1201 SetEditable( formerEditable
) ;
1206 void wxTextCtrl::SetSelection(long from
, long to
)
1208 if ( !m_macUsesTXN
)
1210 ControlEditTextSelectionRec selection
;
1211 if ((from
== -1) && (to
== -1))
1213 selection
.selStart
= 0 ;
1214 selection
.selEnd
= 32767 ;
1218 selection
.selStart
= from
;
1219 selection
.selEnd
= to
;
1222 TESetSelect( selection
.selStart
, selection
.selEnd
, ((TEHandle
) m_macTE
) ) ;
1223 ::SetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1227 STPTextPaneVars
**tpvars
;
1228 /* set up our locals */
1229 tpvars
= (STPTextPaneVars
**) GetControlReference((ControlHandle
) m_macControl
);
1230 /* and our drawing environment as the operation
1231 may force a redraw in the text area. */
1232 SetPort((**tpvars
).fDrawingEnvironment
);
1233 /* change the selection */
1234 if ((from
== -1) && (to
== -1))
1235 TXNSelectAll((TXNObject
) m_macTXN
);
1237 TXNSetSelection( (**tpvars
).fTXNRec
, from
, to
);
1238 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
1242 bool wxTextCtrl::LoadFile(const wxString
& file
)
1244 if ( wxTextCtrlBase::LoadFile(file
) )
1252 void wxTextCtrl::WriteText(const wxString
& st
)
1254 if ( !m_macUsesTXN
)
1256 wxCharBuffer text
= wxMacStringToCString( st
) ;
1257 TEInsert( text
, strlen(text
) , ((TEHandle
) m_macTE
) ) ;
1261 bool formerEditable
= m_editable
;
1262 if ( !formerEditable
)
1264 long start
, end
, dummy
;
1265 GetSelection( &start
, &dummy
) ;
1267 TXNSetData( ((TXNObject
) m_macTXN
), kTXNUnicodeTextData
, (void*)st
.wc_str(), st
.Length() * 2 ,
1268 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1270 wxCharBuffer text
= wxMacStringToCString( st
) ;
1271 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1272 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1274 GetSelection( &dummy
, &end
) ;
1275 SetStyle( start
, end
, GetDefaultStyle() ) ;
1276 if ( !formerEditable
)
1277 SetEditable( formerEditable
) ;
1279 MacRedrawControl() ;
1282 void wxTextCtrl::AppendText(const wxString
& text
)
1284 SetInsertionPointEnd();
1288 void wxTextCtrl::Clear()
1290 if ( !IsEditable() )
1294 if ( !m_macUsesTXN
)
1296 ::SetControlData((ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 0 , (char*) ((const char*)NULL
) ) ;
1300 TXNSetSelection( (TXNObject
)m_macTXN
, kTXNStartOffset
, kTXNEndOffset
) ;
1301 TXNClear((TXNObject
)m_macTXN
);
1306 bool wxTextCtrl::IsModified() const
1311 bool wxTextCtrl::IsEditable() const
1313 return IsEnabled() && m_editable
;
1316 bool wxTextCtrl::AcceptsFocus() const
1318 // we don't want focus if we can't be edited
1319 return /*IsEditable() && */ wxControl::AcceptsFocus();
1322 wxSize
wxTextCtrl::DoGetBestSize() const
1337 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
1339 int wText = DEFAULT_ITEM_WIDTH;
1341 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
1343 return wxSize(wText, hText);
1345 if ( m_windowStyle
& wxTE_MULTILINE
)
1349 hText
+= 2 * m_macVerticalBorder
;
1350 wText
+= 2 * m_macHorizontalBorder
;
1351 //else: for single line control everything is ok
1352 return wxSize(wText
, hText
);
1355 // ----------------------------------------------------------------------------
1357 // ----------------------------------------------------------------------------
1359 void wxTextCtrl::Undo()
1365 TXNUndo((TXNObject
)m_macTXN
);
1370 void wxTextCtrl::Redo()
1376 TXNRedo((TXNObject
)m_macTXN
);
1381 bool wxTextCtrl::CanUndo() const
1383 if ( !IsEditable() )
1389 return TXNCanUndo((TXNObject
)m_macTXN
,NULL
);
1394 bool wxTextCtrl::CanRedo() const
1396 if ( !IsEditable() )
1402 return TXNCanRedo((TXNObject
)m_macTXN
,NULL
);
1407 // Makes 'unmodified'
1408 void wxTextCtrl::DiscardEdits()
1413 int wxTextCtrl::GetNumberOfLines() const
1415 // TODO change this if possible to reflect real lines
1416 wxString content
= GetValue() ;
1419 for (size_t i
= 0; i
< content
.Length() ; i
++)
1421 if (content
[i
] == '\r') count
++;
1427 long wxTextCtrl::XYToPosition(long x
, long y
) const
1433 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
1438 void wxTextCtrl::ShowPosition(long pos
)
1443 int wxTextCtrl::GetLineLength(long lineNo
) const
1445 // TODO change this if possible to reflect real lines
1446 wxString content
= GetValue() ;
1450 for (size_t i
= 0; i
< content
.Length() ; i
++)
1452 if (count
== lineNo
)
1454 // Count chars in line then
1456 for (size_t j
= i
; j
< content
.Length(); j
++)
1459 if (content
[j
] == '\r') return count
;
1464 if (content
[i
] == '\r') count
++;
1469 wxString
wxTextCtrl::GetLineText(long lineNo
) const
1471 // TODO change this if possible to reflect real lines
1472 wxString content
= GetValue() ;
1476 for (size_t i
= 0; i
< content
.Length() ; i
++)
1478 if (count
== lineNo
)
1480 // Add chars in line then
1483 for (size_t j
= i
; j
< content
.Length(); j
++)
1485 if (content
[j
] == '\r')
1493 if (content
[i
] == '\r') count
++;
1495 return wxEmptyString
;
1502 void wxTextCtrl::Command(wxCommandEvent
& event
)
1504 SetValue (event
.GetString());
1505 ProcessCommand (event
);
1508 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
1510 // By default, load the first file into the text window.
1511 if (event
.GetNumberOfFiles() > 0)
1513 LoadFile(event
.GetFiles()[0]);
1517 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
1519 int key
= event
.GetKeyCode() ;
1520 bool eat_key
= false ;
1522 if ( key
== 'c' && event
.MetaDown() )
1529 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
1530 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
1531 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
1538 // assume that any key not processed yet is going to modify the control
1541 if ( key
== 'v' && event
.MetaDown() )
1547 if ( key
== 'x' && event
.MetaDown() )
1556 if (m_windowStyle
& wxPROCESS_ENTER
)
1558 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1559 event
.SetEventObject( this );
1560 event
.SetString( GetValue() );
1561 if ( GetEventHandler()->ProcessEvent(event
) )
1564 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1566 wxWindow
*parent
= GetParent();
1567 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
1568 parent
= parent
->GetParent() ;
1570 if ( parent
&& parent
->GetDefaultItem() )
1572 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
1574 if ( def
&& def
->IsEnabled() )
1576 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1577 event
.SetEventObject(def
);
1578 def
->Command(event
);
1583 // this will make wxWindows eat the ENTER key so that
1584 // we actually prevent line wrapping in a single line
1592 // always produce navigation event - even if we process TAB
1593 // ourselves the fact that we got here means that the user code
1594 // decided to skip processing of this TAB - probably to let it
1595 // do its default job.
1597 wxNavigationKeyEvent eventNav
;
1598 eventNav
.SetDirection(!event
.ShiftDown());
1599 eventNav
.SetWindowChange(event
.ControlDown());
1600 eventNav
.SetEventObject(this);
1602 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
1613 // perform keystroke handling
1615 if ( m_macUsesTXN
&& wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
1616 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
1621 if ( wxMacConvertEventToRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) )
1623 EventRecord
*ev
= &rec
;
1626 keychar
= short(ev
->message
& charCodeMask
);
1627 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1629 ::HandleControlKey( (ControlHandle
) m_macControl
, keycode
, keychar
, ev
->modifiers
) ;
1633 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1634 key
== WXK_RETURN
||
1635 key
== WXK_DELETE
||
1638 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1639 event1
.SetString( GetValue() ) ;
1640 event1
.SetEventObject( this );
1641 wxPostEvent(GetEventHandler(),event1
);
1645 void wxTextCtrl::MacSuperShown( bool show
)
1647 bool former
= m_macControlIsShown
;
1648 wxControl::MacSuperShown( show
) ;
1649 if ( (former
!= m_macControlIsShown
) && m_macUsesTXN
)
1651 if ( m_macControlIsShown
)
1652 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1653 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
,(**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1655 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1656 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1660 bool wxTextCtrl::Show(bool show
)
1662 bool former
= m_macControlIsShown
;
1664 bool retval
= wxControl::Show( show
) ;
1666 if ( former
!= m_macControlIsShown
&& m_macUsesTXN
)
1668 if ( m_macControlIsShown
)
1669 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1670 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
,(**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1672 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1673 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1679 // ----------------------------------------------------------------------------
1680 // standard handlers for standard edit menu events
1681 // ----------------------------------------------------------------------------
1683 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1688 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1693 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1698 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1703 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1708 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1710 event
.Enable( CanCut() );
1713 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1715 event
.Enable( CanCopy() );
1718 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1720 event
.Enable( CanPaste() );
1723 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1725 event
.Enable( CanUndo() );
1728 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1730 event
.Enable( CanRedo() );
1733 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1738 return wxWindow::MacSetupCursor( pt
) ;