1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
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 wxApp
*wxTheApp
;
64 extern wxControl
*wxFindControlFromMacControl(ControlHandle inControl
) ;
66 // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon
67 // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the
68 // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have
69 // an alternate path for carbon key events that routes automatically into the same wx flow of events
71 #include "MacTextEditor.h"
75 /* kmUPTextPart is the part code we return to indicate the user has clicked
76 in the text area of our control */
77 #define kmUPTextPart 1
79 /* kmUPScrollPart is the part code we return to indicate the user has clicked
80 in the scroll bar part of the control. */
81 #define kmUPScrollPart 2
84 /* routines for using existing user pane controls.
85 These routines are useful for cases where you would like to use an
86 existing user pane control in, say, a dialog window as a scrolling
89 /* mUPOpenControl initializes a user pane control so it will be drawn
90 and will behave as a scrolling text edit field inside of a window.
91 This routine performs all of the initialization steps necessary,
92 except it does not create the user pane control itself. theControl
93 should refer to a user pane control that you have either created
94 yourself or extracted from a dialog's control heirarchy using
95 the GetDialogItemAsControl routine. */
96 OSStatus
mUPOpenControl(ControlHandle theControl
, long wxStyle
);
98 /* Utility Routines */
104 /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus
105 routine. In our focus switching routine this part code is understood
106 as meaning 'the user has clicked in the control and we need to switch
107 the current focus to ourselves before we can continue'. */
108 #define kUserClickedToFocusPart 100
111 /* kmUPClickScrollDelayTicks is a time measurement in ticks used to
112 slow the speed of 'auto scrolling' inside of our clickloop routine.
113 This value prevents the text from wizzzzzing by while the mouse
114 is being held down inside of the text area. */
115 #define kmUPClickScrollDelayTicks 3
118 /* STPTextPaneVars is a structure used for storing the the mUP Control's
119 internal variables and state information. A handle to this record is
120 stored in the pane control's reference value field using the
121 SetControlReference routine. */
124 /* OS records referenced */
125 TXNObject fTXNRec
; /* the txn record */
126 TXNFrameID fTXNFrame
; /* the txn frame ID */
127 ControlHandle fUserPaneRec
; /* handle to the user pane control */
128 WindowPtr fOwner
; /* window containing control */
129 GrafPtr fDrawingEnvironment
; /* grafport where control is drawn */
131 Boolean fInFocus
; /* true while the focus rect is drawn around the control */
132 Boolean fIsActive
; /* true while the control is drawn in the active state */
133 Boolean fTEActive
; /* reflects the activation state of the text edit record */
134 Boolean fInDialogWindow
; /* true if displayed in a dialog window */
135 /* calculated locations */
136 Rect fRTextArea
; /* area where the text is drawn */
137 Rect fRFocusOutline
; /* rectangle used to draw the focus box */
138 Rect fRTextOutline
; /* rectangle used to draw the border */
139 RgnHandle fTextBackgroundRgn
; /* background region for the text, erased before calling TEUpdate */
140 /* our focus advance override routine */
141 EventHandlerUPP handlerUPP
;
142 EventHandlerRef handlerRef
;
149 /* Univerals Procedure Pointer variables used by the
150 mUP Control. These variables are set up
151 the first time that mUPOpenControl is called. */
152 ControlUserPaneDrawUPP gTPDrawProc
= NULL
;
153 ControlUserPaneHitTestUPP gTPHitProc
= NULL
;
154 ControlUserPaneTrackingUPP gTPTrackProc
= NULL
;
155 ControlUserPaneIdleUPP gTPIdleProc
= NULL
;
156 ControlUserPaneKeyDownUPP gTPKeyProc
= NULL
;
157 ControlUserPaneActivateUPP gTPActivateProc
= NULL
;
158 ControlUserPaneFocusUPP gTPFocusProc
= NULL
;
160 /* TPActivatePaneText activates or deactivates the text edit record
161 according to the value of setActive. The primary purpose of this
162 routine is to ensure each call is only made once. */
163 static void TPActivatePaneText(STPTextPaneVars
**tpvars
, Boolean setActive
) {
164 STPTextPaneVars
*varsp
;
166 if (varsp
->fTEActive
!= setActive
) {
168 varsp
->fTEActive
= setActive
;
170 TXNActivate(varsp
->fTXNRec
, varsp
->fTXNFrame
, varsp
->fTEActive
);
173 TXNFocus( varsp
->fTXNRec
, varsp
->fTEActive
);
178 /* TPFocusPaneText set the focus state for the text record. */
179 static void TPFocusPaneText(STPTextPaneVars
**tpvars
, Boolean setFocus
) {
180 STPTextPaneVars
*varsp
;
182 if (varsp
->fInFocus
!= setFocus
) {
183 varsp
->fInFocus
= setFocus
;
184 TXNFocus( varsp
->fTXNRec
, varsp
->fInFocus
);
189 /* TPPaneDrawProc is called to redraw the control and for update events
190 referring to the control. This routine erases the text area's background,
191 and redraws the text. This routine assumes the scroll bar has been
192 redrawn by a call to DrawControls. */
193 static pascal void TPPaneDrawProc(ControlRef theControl
, ControlPartCode thePart
) {
194 STPTextPaneVars
**tpvars
, *varsp
;
197 /* set up our globals */
199 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
200 if (tpvars
!= NULL
) {
201 state
= HGetState((Handle
) tpvars
);
202 HLock((Handle
) tpvars
);
205 /* save the drawing state */
206 SetPort((**tpvars
).fDrawingEnvironment
);
207 /* verify our boundary */
208 GetControlBounds(theControl
, &bounds
);
210 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
211 if ( ! EqualRect(&bounds
, &varsp
->fRFocusOutline
) ) {
212 // scrollbar is on the border, we add one
213 Rect oldbounds
= varsp
->fRFocusOutline
;
214 InsetRect( &oldbounds
, -1 , -1 ) ;
216 InvalWindowRect( GetControlOwner( theControl
) , &oldbounds
) ;
217 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
218 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
219 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
220 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
221 RectRgn(varsp
->fTextBackgroundRgn
, &varsp
->fRTextOutline
);
222 TXNSetFrameBounds( varsp
->fTXNRec
, varsp
->fRTextArea
.top
, varsp
->fRTextArea
.left
,
223 varsp
->fRTextArea
.bottom
, varsp
->fRTextArea
.right
, varsp
->fTXNFrame
);
226 /* update the text region */
227 RGBColor white
= { 65535 , 65535 , 65535 } ;
228 RGBBackColor( &white
) ;
229 EraseRgn(varsp
->fTextBackgroundRgn
);
230 TXNDraw(varsp
->fTXNRec
, NULL
);
231 /* restore the drawing environment */
232 /* draw the text frame and focus frame (if necessary) */
233 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
234 if ((**tpvars
).fIsActive
&& varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, true);
235 /* release our globals */
236 HSetState((Handle
) tpvars
, state
);
242 /* TPPaneHitTestProc is called when the control manager would
243 like to determine what part of the control the mouse resides over.
244 We also call this routine from our tracking proc to determine how
245 to handle mouse clicks. */
246 static pascal ControlPartCode
TPPaneHitTestProc(ControlHandle theControl
, Point where
) {
247 STPTextPaneVars
**tpvars
;
248 ControlPartCode result
;
250 /* set up our locals and lock down our globals*/
252 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
253 if (tpvars
!= NULL
) {
254 state
= HGetState((Handle
) tpvars
);
255 HLock((Handle
) tpvars
);
256 /* find the region where we clicked */
257 if (PtInRect(where
, &(**tpvars
).fRTextArea
)) {
258 result
= kmUPTextPart
;
260 /* release oure globals */
261 HSetState((Handle
) tpvars
, state
);
270 /* TPPaneTrackingProc is called when the mouse is being held down
271 over our control. This routine handles clicks in the text area
272 and in the scroll bar. */
273 static pascal ControlPartCode
TPPaneTrackingProc(ControlHandle theControl
, Point startPt
, ControlActionUPP actionProc
) {
274 STPTextPaneVars
**tpvars
, *varsp
;
276 ControlPartCode partCodeResult
;
277 /* make sure we have some variables... */
279 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
280 if (tpvars
!= NULL
) {
282 state
= HGetState((Handle
) tpvars
);
283 HLock((Handle
) tpvars
);
285 /* we don't do any of these functions unless we're in focus */
286 if ( ! varsp
->fInFocus
) {
288 owner
= GetControlOwner(theControl
);
289 ClearKeyboardFocus(owner
);
290 SetKeyboardFocus(owner
, theControl
, kUserClickedToFocusPart
);
292 /* find the location for the click */
293 switch (TPPaneHitTestProc(theControl
, startPt
)) {
295 /* handle clicks in the text part */
297 { SetPort((**tpvars
).fDrawingEnvironment
);
298 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
299 TXNClick( varsp
->fTXNRec
, (const EventRecord
*) wxTheApp
->MacGetCurrentEvent());
305 HSetState((Handle
) tpvars
, state
);
307 return partCodeResult
;
311 /* TPPaneIdleProc is our user pane idle routine. When our text field
312 is active and in focus, we use this routine to set the cursor. */
313 static pascal void TPPaneIdleProc(ControlHandle theControl
) {
314 STPTextPaneVars
**tpvars
, *varsp
;
316 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
317 if (tpvars
!= NULL
) {
318 /* if we're not active, then we have nothing to say about the cursor */
319 if ((**tpvars
).fIsActive
) {
323 /* lock down the globals */
324 state
= HGetState((Handle
) tpvars
);
325 HLock((Handle
) tpvars
);
327 /* get the current mouse coordinates (in our window) */
328 SetPortWindowPort(GetControlOwner(theControl
));
329 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
331 /* there's a 'focus thing' and an 'unfocused thing' */
332 if (varsp
->fInFocus
) {
333 /* flash the cursor */
334 SetPort((**tpvars
).fDrawingEnvironment
);
335 TXNIdle(varsp
->fTXNRec
);
337 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
339 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
340 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
345 // SetThemeCursor(kThemeArrowCursor);
348 /* if it's in our bounds, set the cursor */
349 GetControlBounds(theControl
, &bounds
);
350 if (PtInRect(mousep
, &bounds
))
352 // SetThemeCursor(kThemeArrowCursor);
356 HSetState((Handle
) tpvars
, state
);
362 /* TPPaneKeyDownProc is called whenever a keydown event is directed
363 at our control. Here, we direct the keydown event to the text
364 edit record and redraw the scroll bar and text field as appropriate. */
365 static pascal ControlPartCode
TPPaneKeyDownProc(ControlHandle theControl
,
366 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
367 STPTextPaneVars
**tpvars
;
368 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
369 if (tpvars
!= NULL
) {
370 if ((**tpvars
).fInFocus
) {
371 /* turn autoscrolling on and send the key event to text edit */
372 SetPort((**tpvars
).fDrawingEnvironment
);
373 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
375 memset( &ev
, 0 , sizeof( ev
) ) ;
377 ev
.modifiers
= modifiers
;
378 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
379 TXNKeyDown( (**tpvars
).fTXNRec
, &ev
);
382 return kControlEntireControl
;
386 /* TPPaneActivateProc is called when the window containing
387 the user pane control receives activate events. Here, we redraw
388 the control and it's text as necessary for the activation state. */
389 static pascal void TPPaneActivateProc(ControlHandle theControl
, Boolean activating
) {
391 STPTextPaneVars
**tpvars
, *varsp
;
394 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
395 if (tpvars
!= NULL
) {
396 state
= HGetState((Handle
) tpvars
);
397 HLock((Handle
) tpvars
);
399 /* de/activate the text edit record */
400 SetPort((**tpvars
).fDrawingEnvironment
);
401 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
402 GetControlBounds(theControl
, &bounds
);
403 varsp
->fIsActive
= activating
;
404 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
405 /* redraw the frame */
406 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
407 if (varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
);
408 HSetState((Handle
) tpvars
, state
);
413 /* TPPaneFocusProc is called when every the focus changes to or
414 from our control. Herein, switch the focus appropriately
415 according to the parameters and redraw the control as
417 static pascal ControlPartCode
TPPaneFocusProc(ControlHandle theControl
, ControlFocusPart action
) {
418 ControlPartCode focusResult
;
419 STPTextPaneVars
**tpvars
, *varsp
;
422 focusResult
= kControlFocusNoPart
;
423 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
424 if (tpvars
!= NULL
) {
425 state
= HGetState((Handle
) tpvars
);
426 HLock((Handle
) tpvars
);
428 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
429 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
430 and kControlFocusNextPart will be received. When the user clicks in our field
431 and it is not the current focus, then the constant kUserClickedToFocusPart will
432 be received. The constant kControlFocusNoPart will be received when our control
433 is the current focus and the user clicks in another control. In your focus routine,
434 you should respond to these codes as follows:
436 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
437 the control and the focus rectangle as necessary.
439 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
440 depending on its current state. redraw the control and the focus rectangle
441 as appropriate for the new focus state. If the focus state is 'off', return the constant
442 kControlFocusNoPart, otherwise return a non-zero part code.
443 kUserClickedToFocusPart - is a constant defined for this example. You should
444 define your own value for handling click-to-focus type events. */
445 /* save the drawing state */
446 SetPort((**tpvars
).fDrawingEnvironment
);
447 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
448 /* calculate the next highlight state */
451 case kControlFocusNoPart
:
452 TPFocusPaneText(tpvars
, false);
453 focusResult
= kControlFocusNoPart
;
455 case kUserClickedToFocusPart
:
456 TPFocusPaneText(tpvars
, true);
459 case kControlFocusPrevPart
:
460 case kControlFocusNextPart
:
461 TPFocusPaneText(tpvars
, ( ! varsp
->fInFocus
));
462 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
465 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
466 /* redraw the text fram and focus rectangle to indicate the
468 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
469 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
&& varsp
->fInFocus
);
471 HSetState((Handle
) tpvars
, state
);
477 /* mUPOpenControl initializes a user pane control so it will be drawn
478 and will behave as a scrolling text edit field inside of a window.
479 This routine performs all of the initialization steps necessary,
480 except it does not create the user pane control itself. theControl
481 should refer to a user pane control that you have either created
482 yourself or extracted from a dialog's control heirarchy using
483 the GetDialogItemAsControl routine. */
484 OSStatus
mUPOpenControl(ControlHandle theControl
, long wxStyle
)
488 STPTextPaneVars
**tpvars
, *varsp
;
489 OSStatus err
= noErr
;
490 RGBColor rgbWhite
= {0xFFFF, 0xFFFF, 0xFFFF};
493 /* set up our globals */
494 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
495 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
496 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
497 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
498 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
499 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
500 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
502 /* allocate our private storage */
503 tpvars
= (STPTextPaneVars
**) NewHandleClear(sizeof(STPTextPaneVars
));
504 SetControlReference(theControl
, (long) tpvars
);
505 HLock((Handle
) tpvars
);
507 /* set the initial settings for our private data */
508 varsp
->fMultiline
= wxStyle
& wxTE_MULTILINE
;
509 varsp
->fInFocus
= false;
510 varsp
->fIsActive
= true;
511 varsp
->fTEActive
= true; // in order to get a deactivate
512 varsp
->fUserPaneRec
= theControl
;
513 theWindow
= varsp
->fOwner
= GetControlOwner(theControl
);
515 varsp
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
517 varsp
->fInDialogWindow
= ( GetWindowKind(varsp
->fOwner
) == kDialogWindowKind
);
518 /* set up the user pane procedures */
519 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
520 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
521 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
522 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
523 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
524 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
525 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
526 /* calculate the rectangles used by the control */
527 GetControlBounds(theControl
, &bounds
);
528 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
529 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
530 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
531 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
532 /* calculate the background region for the text. In this case, it's kindof
533 and irregular region because we're setting the scroll bar a little ways inside
535 RectRgn((varsp
->fTextBackgroundRgn
= NewRgn()), &varsp
->fRTextOutline
);
537 /* set up the drawing environment */
538 SetPort(varsp
->fDrawingEnvironment
);
540 /* create the new edit field */
542 TXNFrameOptions frameOptions
=
543 kTXNDontDrawCaretWhenInactiveMask
;
544 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
545 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
547 if ( wxStyle
& wxTE_MULTILINE
)
549 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
550 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
553 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
554 frameOptions
|= kTXNWantHScrollBarMask
;
557 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
558 frameOptions
|= kTXNWantVScrollBarMask
;
561 frameOptions
|= kTXNSingleLineOnlyMask
;
563 if ( wxStyle
& wxTE_READONLY
)
564 frameOptions
|= kTXNReadOnlyMask
;
566 TXNNewObject(NULL
, varsp
->fOwner
, &varsp
->fRTextArea
,
568 kTXNTextEditStyleFrameType
,
570 kTXNSystemDefaultEncoding
,
571 &varsp
->fTXNRec
, &varsp
->fTXNFrame
, (TXNObjectRefcon
) tpvars
);
577 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
579 TXNTypeAttributes typeAttr
[] =
581 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
582 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
583 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
586 err
= TXNSetTypeAttributes (varsp
->fTXNRec
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
589 /* set the field's background */
590 tback
.bgType
= kTXNBackgroundTypeRGB
;
591 tback
.bg
.color
= rgbWhite
;
592 TXNSetBackground( varsp
->fTXNRec
, &tback
);
594 /* unlock our storage */
595 HUnlock((Handle
) tpvars
);
596 /* perform final activations and setup for our text field. Here,
597 we assume that the window is going to be the 'active' window. */
598 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
606 #if !USE_SHARED_LIBRARY
607 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
609 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
610 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
611 EVT_CHAR(wxTextCtrl::OnChar
)
612 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
613 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
614 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
615 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
616 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
618 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
619 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
620 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
621 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
622 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
627 wxTextCtrl::wxTextCtrl()
631 m_macTXNvars
= NULL
;
632 m_macUsesTXN
= false ;
634 m_maxLength
= TE_UNLIMITED_LENGTH
;
637 wxTextCtrl::~wxTextCtrl()
641 SetControlReference((ControlHandle
)m_macControl
, 0) ;
642 TXNDeleteObject((TXNObject
)m_macTXN
);
643 /* delete our private storage */
644 DisposeHandle((Handle
) m_macTXNvars
);
645 /* zero the control reference */
649 const short kVerticalMargin
= 2 ;
650 const short kHorizontalMargin
= 2 ;
652 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
655 const wxSize
& size
, long style
,
656 const wxValidator
& validator
,
657 const wxString
& name
)
661 m_macTXNvars
= NULL
;
662 m_macUsesTXN
= false ;
665 m_macUsesTXN
= ! (style
& wxTE_PASSWORD
) ;
667 m_macUsesTXN
&= (TXNInitTextension
!= (void*) kUnresolvedCFragSymbolAddress
) ;
669 // base initialization
670 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
673 wxSize mySize
= size
;
676 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
677 m_macVerticalBorder
= 3 ;
681 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
682 m_macVerticalBorder
= 5 ;
689 if ( mySize.y == -1 )
692 if ( m_windowStyle & wxTE_MULTILINE )
695 mySize.y += 2 * m_macVerticalBorder ;
698 MacPreControlCreate( parent
, id
, "" , pos
, mySize
,style
, validator
, name
, &bounds
, title
) ;
700 if ( m_windowStyle
& wxTE_MULTILINE
)
702 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
703 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
705 m_windowStyle
|= wxTE_PROCESS_ENTER
;
708 if ( m_windowStyle
& wxTE_READONLY
)
715 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, "\p" , true , 0 , 0 , 1,
716 (style
& wxTE_PASSWORD
) ? kControlEditTextPasswordProc
: kControlEditTextProc
, (long) this ) ;
718 ::GetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &((TEHandle
) m_macTE
) , &size
) ;
725 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
726 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
727 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
728 /* create the control */
729 m_macControl
= NewControl(MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, "\p", true, featurSet
, 0, featurSet
, kControlUserPaneProc
, 0);
730 /* set up the mUP specific features and data */
731 mUPOpenControl((ControlHandle
) m_macControl
, m_windowStyle
);
735 parent->MacGetTopLevelWindow()->MacInstallEventHandler() ;
739 MacPostControlCreate() ;
743 if( wxApp::s_macDefaultEncodingIsPC
)
744 value
= wxMacMakeMacStringFromPC( st
) ;
750 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
754 STPTextPaneVars
**tpvars
;
756 tpvars
= (STPTextPaneVars
**) GetControlReference((ControlHandle
) m_macControl
);
757 /* set the text in the record */
758 TXNSetData( (**tpvars
).fTXNRec
, kTXNTextData
, (void*)value
.c_str(), value
.Length(),
759 kTXNStartOffset
, kTXNEndOffset
);
760 m_macTXN
= (**tpvars
).fTXNRec
;
761 m_macTXNvars
= tpvars
;
762 m_macUsesTXN
= true ;
763 TXNSetSelection( (TXNObject
) m_macTXN
, 0, 0);
764 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
770 wxString
wxTextCtrl::GetValue() const
776 ::GetControlData( (ControlHandle
) m_macControl
, 0,
777 ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
,
778 32767 , wxBuffer
, &actualsize
) ;
783 OSStatus err
= TXNGetDataEncoded( ((TXNObject
) m_macTXN
), kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
791 actualsize
= GetHandleSize( theText
) ;
793 strncpy( wxBuffer
, *theText
, actualsize
) ;
794 DisposeHandle( theText
) ;
798 wxBuffer
[actualsize
] = 0 ;
802 if( wxApp::s_macDefaultEncodingIsPC
)
804 value
= wxMacMakePCStringFromMac( wxBuffer
) ;
805 value
.Replace( "\r", "\n" );
814 void wxTextCtrl::GetSelection(long* from
, long* to
) const
818 *from
= (**((TEHandle
) m_macTE
)).selStart
;
819 *to
= (**((TEHandle
) m_macTE
)).selEnd
;
823 TXNGetSelection( ((TXNObject
) m_macTXN
) , (TXNOffset
*) from
, (TXNOffset
*) to
) ;
827 void wxTextCtrl::SetValue(const wxString
& st
)
831 if( wxApp::s_macDefaultEncodingIsPC
)
833 value
= wxMacMakeMacStringFromPC( st
) ;
834 value
.Replace( "\n", "\r" );
842 ::SetControlData((ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, value
.Length() , (char*) ((const char*)value
) ) ;
846 bool formerEditable
= IsEditable() ;
847 if ( !formerEditable
)
849 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)value
.c_str(), value
.Length(),
850 kTXNStartOffset
, kTXNEndOffset
);
851 TXNSetSelection( (TXNObject
) m_macTXN
, 0, 0);
852 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
853 if ( !formerEditable
)
854 SetEditable(formerEditable
) ;
859 void wxTextCtrl::SetMaxLength(unsigned long len
)
864 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
868 bool formerEditable
= IsEditable() ;
869 if ( !formerEditable
)
871 TXNTypeAttributes typeAttr
[4] ;
872 Str255 fontName
= "\pMonaco" ;
873 SInt16 fontSize
= 12 ;
874 Style fontStyle
= normal
;
876 int attrCounter
= 0 ;
877 if ( style
.HasFont() )
879 const wxFont
&font
= style
.GetFont() ;
880 CopyCStringToPascal( font
.GetFaceName().c_str() , fontName
) ;
881 fontSize
= font
.GetPointSize() ;
882 if ( font
.GetUnderlined() )
883 fontStyle
|= underline
;
884 if ( font
.GetWeight() == wxBOLD
)
886 if ( font
.GetStyle() == wxITALIC
)
887 fontStyle
|= italic
;
889 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
890 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
891 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
892 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
893 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
894 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
895 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
896 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
897 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
901 if ( style
.HasTextColour() )
903 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
904 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
905 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
906 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
910 if ( attrCounter
> 0 )
912 OSStatus status
= TXNSetTypeAttributes ((TXNObject
)m_macTXN
, attrCounter
, typeAttr
,
914 wxASSERT_MSG( status
== noErr
, "Couldn't set text attributes" ) ;
916 if ( !formerEditable
)
917 SetEditable(formerEditable
) ;
922 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
924 wxTextCtrlBase::SetDefaultStyle( style
) ;
925 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
929 // Clipboard operations
930 void wxTextCtrl::Copy()
936 TECopy( ((TEHandle
) m_macTE
) ) ;
944 TXNCopy((TXNObject
)m_macTXN
);
945 TXNConvertToPublicScrap();
950 void wxTextCtrl::Cut()
956 TECut( ((TEHandle
) m_macTE
) ) ;
964 TXNCut((TXNObject
)m_macTXN
);
965 TXNConvertToPublicScrap();
967 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
968 event
.SetString( GetValue() ) ;
969 event
.SetEventObject( this );
970 GetEventHandler()->ProcessEvent(event
);
974 void wxTextCtrl::Paste()
981 TEPaste( (TEHandle
) m_macTE
) ;
986 TXNConvertFromPublicScrap();
987 TXNPaste((TXNObject
)m_macTXN
);
988 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
990 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
991 event
.SetString( GetValue() ) ;
992 event
.SetEventObject( this );
993 GetEventHandler()->ProcessEvent(event
);
997 bool wxTextCtrl::CanCopy() const
999 // Can copy if there's a selection
1001 GetSelection(& from
, & to
);
1002 return (from
!= to
);
1005 bool wxTextCtrl::CanCut() const
1007 if ( !IsEditable() )
1011 // Can cut if there's a selection
1013 GetSelection(& from
, & to
);
1014 return (from
!= to
);
1017 bool wxTextCtrl::CanPaste() const
1023 OSStatus err
= noErr
;
1026 err
= GetCurrentScrap( &scrapRef
);
1027 if ( err
!= noTypeErr
&& err
!= memFullErr
)
1029 ScrapFlavorFlags flavorFlags
;
1032 if (( err
= GetScrapFlavorFlags( scrapRef
, 'TEXT', &flavorFlags
)) == noErr
)
1034 if (( err
= GetScrapFlavorSize( scrapRef
, 'TEXT', &byteCount
)) == noErr
)
1044 if ( GetScrap( NULL
, 'TEXT' , &offset
) > 0 )
1052 void wxTextCtrl::SetEditable(bool editable
)
1054 if ( editable
!= m_editable
)
1056 m_editable
= editable
;
1057 if ( !m_macUsesTXN
)
1060 UMAActivateControl( (ControlHandle
) m_macControl
) ;
1062 UMADeactivateControl((ControlHandle
) m_macControl
) ;
1066 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1067 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1068 TXNSetTXNObjectControls( (TXNObject
) m_macTXN
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1073 void wxTextCtrl::SetInsertionPoint(long pos
)
1075 SetSelection( pos
, pos
) ;
1078 void wxTextCtrl::SetInsertionPointEnd()
1080 long pos
= GetLastPosition();
1081 SetInsertionPoint(pos
);
1084 long wxTextCtrl::GetInsertionPoint() const
1087 GetSelection( &begin
, &end
) ;
1091 long wxTextCtrl::GetLastPosition() const
1093 if ( !m_macUsesTXN
)
1095 return (**((TEHandle
) m_macTE
)).teLength
;
1101 OSErr err
= TXNGetDataEncoded( (TXNObject
) m_macTXN
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1109 actualsize
= GetHandleSize( theText
) ;
1110 DisposeHandle( theText
) ;
1116 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
1118 if ( !m_macUsesTXN
)
1120 ControlEditTextSelectionRec selection
;
1122 selection
.selStart
= from
;
1123 selection
.selEnd
= to
;
1124 ::SetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1125 TESetSelect( from
, to
, ((TEHandle
) m_macTE
) ) ;
1126 TEDelete( ((TEHandle
) m_macTE
) ) ;
1127 TEInsert( value
, value
.Length() , ((TEHandle
) m_macTE
) ) ;
1131 bool formerEditable
= IsEditable() ;
1132 if ( !formerEditable
)
1134 TXNSetSelection( ((TXNObject
) m_macTXN
) , from
, to
) ;
1135 TXNClear( ((TXNObject
) m_macTXN
) ) ;
1136 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)value
.c_str(), value
.Length(),
1137 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1138 if ( !formerEditable
)
1139 SetEditable( formerEditable
) ;
1144 void wxTextCtrl::Remove(long from
, long to
)
1146 if ( !m_macUsesTXN
)
1148 ControlEditTextSelectionRec selection
;
1150 selection
.selStart
= from
;
1151 selection
.selEnd
= to
;
1152 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1153 TEDelete( ((TEHandle
) m_macTE
) ) ;
1157 bool formerEditable
= IsEditable() ;
1158 if ( !formerEditable
)
1160 TXNSetSelection( ((TXNObject
) m_macTXN
) , from
, to
) ;
1161 TXNClear( ((TXNObject
) m_macTXN
) ) ;
1162 if ( !formerEditable
)
1163 SetEditable( formerEditable
) ;
1168 void wxTextCtrl::SetSelection(long from
, long to
)
1171 if ( !m_macUsesTXN
)
1173 ControlEditTextSelectionRec selection
;
1174 selection
.selStart
= from
;
1175 selection
.selEnd
= to
;
1177 TESetSelect( selection
.selStart
, selection
.selEnd
, ((TEHandle
) m_macTE
) ) ;
1178 ::SetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1182 STPTextPaneVars
**tpvars
;
1183 /* set up our locals */
1184 tpvars
= (STPTextPaneVars
**) GetControlReference((ControlHandle
) m_macControl
);
1185 /* and our drawing environment as the operation
1186 may force a redraw in the text area. */
1187 SetPort((**tpvars
).fDrawingEnvironment
);
1188 /* change the selection */
1189 TXNSetSelection( (**tpvars
).fTXNRec
, from
, to
);
1190 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
1194 bool wxTextCtrl::LoadFile(const wxString
& file
)
1196 if ( wxTextCtrlBase::LoadFile(file
) )
1204 void wxTextCtrl::WriteText(const wxString
& text
)
1207 if( wxApp::s_macDefaultEncodingIsPC
)
1209 value
= wxMacMakeMacStringFromPC( text
) ;
1210 value
.Replace( "\n", "\r" );
1215 if ( !m_macUsesTXN
)
1217 TEInsert( value
, value
.Length() , ((TEHandle
) m_macTE
) ) ;
1221 bool formerEditable
= IsEditable() ;
1222 if ( !formerEditable
)
1224 long start
, end
, dummy
;
1225 GetSelection( &start
, &dummy
) ;
1226 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*) (const char*)value
, value
.Length(),
1227 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1228 GetSelection( &dummy
, &end
) ;
1229 SetStyle( start
, end
, GetDefaultStyle() ) ;
1230 if ( !formerEditable
)
1231 SetEditable( formerEditable
) ;
1233 MacRedrawControl() ;
1236 void wxTextCtrl::AppendText(const wxString
& text
)
1238 SetInsertionPointEnd();
1242 void wxTextCtrl::Clear()
1244 if ( !IsEditable() )
1248 if ( !m_macUsesTXN
)
1250 ::SetControlData((ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 0 , (char*) ((const char*)NULL
) ) ;
1254 TXNSetSelection( (TXNObject
)m_macTXN
, kTXNStartOffset
, kTXNEndOffset
) ;
1255 TXNClear((TXNObject
)m_macTXN
);
1260 bool wxTextCtrl::IsModified() const
1265 bool wxTextCtrl::IsEditable() const
1267 return IsEnabled() && m_editable
;
1270 bool wxTextCtrl::AcceptsFocus() const
1272 // we don't want focus if we can't be edited
1273 return /*IsEditable() && */ wxControl::AcceptsFocus();
1276 wxSize
wxTextCtrl::DoGetBestSize() const
1291 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
1293 int wText = DEFAULT_ITEM_WIDTH;
1295 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
1297 return wxSize(wText, hText);
1299 if ( m_windowStyle
& wxTE_MULTILINE
)
1303 hText
+= 2 * m_macVerticalBorder
;
1304 wText
+= 2 * m_macHorizontalBorder
;
1305 //else: for single line control everything is ok
1306 return wxSize(wText
, hText
);
1309 // ----------------------------------------------------------------------------
1311 // ----------------------------------------------------------------------------
1313 void wxTextCtrl::Undo()
1320 void wxTextCtrl::Redo()
1327 bool wxTextCtrl::CanUndo() const
1332 bool wxTextCtrl::CanRedo() const
1337 // Makes 'unmodified'
1338 void wxTextCtrl::DiscardEdits()
1343 int wxTextCtrl::GetNumberOfLines() const
1345 // TODO change this if possible to reflect real lines
1346 wxString content
= GetValue() ;
1349 for (size_t i
= 0; i
< content
.Length() ; i
++)
1351 if (content
[i
] == '\r') count
++;
1357 long wxTextCtrl::XYToPosition(long x
, long y
) const
1363 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
1368 void wxTextCtrl::ShowPosition(long pos
)
1373 int wxTextCtrl::GetLineLength(long lineNo
) const
1375 // TODO change this if possible to reflect real lines
1376 wxString content
= GetValue() ;
1380 for (size_t i
= 0; i
< content
.Length() ; i
++)
1382 if (count
== lineNo
)
1384 // Count chars in line then
1386 for (size_t j
= i
; j
< content
.Length(); j
++)
1389 if (content
[j
] == '\r') return count
;
1394 if (content
[i
] == '\r') count
++;
1399 wxString
wxTextCtrl::GetLineText(long lineNo
) const
1401 // TODO change this if possible to reflect real lines
1402 wxString content
= GetValue() ;
1406 for (size_t i
= 0; i
< content
.Length() ; i
++)
1408 if (count
== lineNo
)
1410 // Add chars in line then
1413 for (size_t j
= i
; j
< content
.Length(); j
++)
1415 if (content
[j
] == '\r')
1423 if (content
[i
] == '\r') count
++;
1432 void wxTextCtrl::Command(wxCommandEvent
& event
)
1434 SetValue (event
.GetString());
1435 ProcessCommand (event
);
1438 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
1440 // By default, load the first file into the text window.
1441 if (event
.GetNumberOfFiles() > 0)
1443 LoadFile(event
.GetFiles()[0]);
1447 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
1449 int key
= event
.GetKeyCode() ;
1450 bool eat_key
= false ;
1452 if ( key
== 'c' && event
.MetaDown() )
1459 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
1460 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
1461 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
1467 if ( key
== 'v' && event
.MetaDown() )
1473 if ( key
== 'x' && event
.MetaDown() )
1482 if (m_windowStyle
& wxPROCESS_ENTER
)
1484 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1485 event
.SetEventObject( this );
1486 event
.SetString( GetValue() );
1487 if ( GetEventHandler()->ProcessEvent(event
) )
1490 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1492 wxWindow
*parent
= GetParent();
1493 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
1494 parent
= parent
->GetParent() ;
1496 if ( parent
&& parent
->GetDefaultItem() )
1498 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
1500 if ( def
&& def
->IsEnabled() )
1502 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1503 event
.SetEventObject(def
);
1504 def
->Command(event
);
1509 // this will make wxWindows eat the ENTER key so that
1510 // we actually prevent line wrapping in a single line
1518 // always produce navigation event - even if we process TAB
1519 // ourselves the fact that we got here means that the user code
1520 // decided to skip processing of this TAB - probably to let it
1521 // do its default job.
1523 wxNavigationKeyEvent eventNav
;
1524 eventNav
.SetDirection(!event
.ShiftDown());
1525 eventNav
.SetWindowChange(event
.ControlDown());
1526 eventNav
.SetEventObject(this);
1528 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
1542 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1543 key
== WXK_RETURN
||
1544 key
== WXK_DELETE
||
1547 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1548 event1
.SetString( GetValue() ) ;
1549 event1
.SetEventObject( this );
1550 wxPostEvent(GetEventHandler(),event1
);
1554 void wxTextCtrl::MacSuperShown( bool show
)
1556 bool former
= m_macControlIsShown
;
1557 wxControl::MacSuperShown( show
) ;
1558 if ( (former
!= m_macControlIsShown
) && m_macUsesTXN
)
1560 if ( m_macControlIsShown
)
1561 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1562 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
,(**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1564 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1565 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1569 bool wxTextCtrl::Show(bool show
)
1571 bool former
= m_macControlIsShown
;
1573 bool retval
= wxControl::Show( show
) ;
1575 if ( former
!= m_macControlIsShown
&& show
)
1577 if ( m_macControlIsShown
)
1578 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1579 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
,(**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1581 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1582 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1588 // ----------------------------------------------------------------------------
1589 // standard handlers for standard edit menu events
1590 // ----------------------------------------------------------------------------
1592 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1597 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1602 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1607 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1612 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1617 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1619 event
.Enable( CanCut() );
1622 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1624 event
.Enable( CanCopy() );
1627 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1629 event
.Enable( CanPaste() );
1632 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1634 event
.Enable( CanUndo() );
1637 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1639 event
.Enable( CanRedo() );
1642 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1647 return wxWindow::MacSetupCursor( pt
) ;