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 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
) ) ;
300 TXNClick( varsp
->fTXNRec
, (const EventRecord
*) wxTheApp
->MacGetCurrentEvent());
303 ConvertEventRefToEventRecord( (EventRef
) wxTheApp
->MacGetCurrentEvent() , &rec
) ;
304 TXNClick( varsp
->fTXNRec
, &rec
);
311 HSetState((Handle
) tpvars
, state
);
313 return partCodeResult
;
317 /* TPPaneIdleProc is our user pane idle routine. When our text field
318 is active and in focus, we use this routine to set the cursor. */
319 static pascal void TPPaneIdleProc(ControlHandle theControl
) {
320 STPTextPaneVars
**tpvars
, *varsp
;
322 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
323 if (tpvars
!= NULL
) {
324 /* if we're not active, then we have nothing to say about the cursor */
325 if ((**tpvars
).fIsActive
) {
329 /* lock down the globals */
330 state
= HGetState((Handle
) tpvars
);
331 HLock((Handle
) tpvars
);
333 /* get the current mouse coordinates (in our window) */
334 SetPortWindowPort(GetControlOwner(theControl
));
335 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
337 /* there's a 'focus thing' and an 'unfocused thing' */
338 if (varsp
->fInFocus
) {
339 /* flash the cursor */
340 SetPort((**tpvars
).fDrawingEnvironment
);
341 TXNIdle(varsp
->fTXNRec
);
343 if (PtInRect(mousep
, &varsp
->fRTextArea
)) {
345 RectRgn((theRgn
= NewRgn()), &varsp
->fRTextArea
);
346 TXNAdjustCursor(varsp
->fTXNRec
, theRgn
);
351 // SetThemeCursor(kThemeArrowCursor);
354 /* if it's in our bounds, set the cursor */
355 GetControlBounds(theControl
, &bounds
);
356 if (PtInRect(mousep
, &bounds
))
358 // SetThemeCursor(kThemeArrowCursor);
362 HSetState((Handle
) tpvars
, state
);
368 /* TPPaneKeyDownProc is called whenever a keydown event is directed
369 at our control. Here, we direct the keydown event to the text
370 edit record and redraw the scroll bar and text field as appropriate. */
371 static pascal ControlPartCode
TPPaneKeyDownProc(ControlHandle theControl
,
372 SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
) {
373 STPTextPaneVars
**tpvars
;
374 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
375 if (tpvars
!= NULL
) {
376 if ((**tpvars
).fInFocus
) {
377 /* turn autoscrolling on and send the key event to text edit */
378 SetPort((**tpvars
).fDrawingEnvironment
);
379 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
381 memset( &ev
, 0 , sizeof( ev
) ) ;
383 ev
.modifiers
= modifiers
;
384 ev
.message
= (( keyCode
<< 8 ) & keyCodeMask
) + ( charCode
& charCodeMask
) ;
385 TXNKeyDown( (**tpvars
).fTXNRec
, &ev
);
388 return kControlEntireControl
;
392 /* TPPaneActivateProc is called when the window containing
393 the user pane control receives activate events. Here, we redraw
394 the control and it's text as necessary for the activation state. */
395 static pascal void TPPaneActivateProc(ControlHandle theControl
, Boolean activating
) {
397 STPTextPaneVars
**tpvars
, *varsp
;
400 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
401 if (tpvars
!= NULL
) {
402 state
= HGetState((Handle
) tpvars
);
403 HLock((Handle
) tpvars
);
405 /* de/activate the text edit record */
406 SetPort((**tpvars
).fDrawingEnvironment
);
407 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
408 GetControlBounds(theControl
, &bounds
);
409 varsp
->fIsActive
= activating
;
410 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
411 /* redraw the frame */
412 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
413 if (varsp
->fInFocus
) DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
);
414 HSetState((Handle
) tpvars
, state
);
419 /* TPPaneFocusProc is called when every the focus changes to or
420 from our control. Herein, switch the focus appropriately
421 according to the parameters and redraw the control as
423 static pascal ControlPartCode
TPPaneFocusProc(ControlHandle theControl
, ControlFocusPart action
) {
424 ControlPartCode focusResult
;
425 STPTextPaneVars
**tpvars
, *varsp
;
428 focusResult
= kControlFocusNoPart
;
429 tpvars
= (STPTextPaneVars
**) GetControlReference(theControl
);
430 if (tpvars
!= NULL
) {
431 state
= HGetState((Handle
) tpvars
);
432 HLock((Handle
) tpvars
);
434 /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is
435 tabbing forwards (or shift tabbing backwards) through the items in the dialog,
436 and kControlFocusNextPart will be received. When the user clicks in our field
437 and it is not the current focus, then the constant kUserClickedToFocusPart will
438 be received. The constant kControlFocusNoPart will be received when our control
439 is the current focus and the user clicks in another control. In your focus routine,
440 you should respond to these codes as follows:
442 kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw
443 the control and the focus rectangle as necessary.
445 kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off
446 depending on its current state. redraw the control and the focus rectangle
447 as appropriate for the new focus state. If the focus state is 'off', return the constant
448 kControlFocusNoPart, otherwise return a non-zero part code.
449 kUserClickedToFocusPart - is a constant defined for this example. You should
450 define your own value for handling click-to-focus type events. */
451 /* save the drawing state */
452 SetPort((**tpvars
).fDrawingEnvironment
);
453 wxMacWindowClipper
clipper( wxFindControlFromMacControl(theControl
) ) ;
454 /* calculate the next highlight state */
457 case kControlFocusNoPart
:
458 TPFocusPaneText(tpvars
, false);
459 focusResult
= kControlFocusNoPart
;
461 case kUserClickedToFocusPart
:
462 TPFocusPaneText(tpvars
, true);
465 case kControlFocusPrevPart
:
466 case kControlFocusNextPart
:
467 TPFocusPaneText(tpvars
, ( ! varsp
->fInFocus
));
468 focusResult
= varsp
->fInFocus
? 1 : kControlFocusNoPart
;
471 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
472 /* redraw the text fram and focus rectangle to indicate the
474 DrawThemeEditTextFrame(&varsp
->fRTextOutline
, varsp
->fIsActive
? kThemeStateActive
: kThemeStateInactive
);
475 DrawThemeFocusRect(&varsp
->fRFocusOutline
, varsp
->fIsActive
&& varsp
->fInFocus
);
477 HSetState((Handle
) tpvars
, state
);
483 /* mUPOpenControl initializes a user pane control so it will be drawn
484 and will behave as a scrolling text edit field inside of a window.
485 This routine performs all of the initialization steps necessary,
486 except it does not create the user pane control itself. theControl
487 should refer to a user pane control that you have either created
488 yourself or extracted from a dialog's control heirarchy using
489 the GetDialogItemAsControl routine. */
490 OSStatus
mUPOpenControl(ControlHandle theControl
, long wxStyle
)
494 STPTextPaneVars
**tpvars
, *varsp
;
495 OSStatus err
= noErr
;
496 RGBColor rgbWhite
= {0xFFFF, 0xFFFF, 0xFFFF};
499 /* set up our globals */
500 if (gTPDrawProc
== NULL
) gTPDrawProc
= NewControlUserPaneDrawUPP(TPPaneDrawProc
);
501 if (gTPHitProc
== NULL
) gTPHitProc
= NewControlUserPaneHitTestUPP(TPPaneHitTestProc
);
502 if (gTPTrackProc
== NULL
) gTPTrackProc
= NewControlUserPaneTrackingUPP(TPPaneTrackingProc
);
503 if (gTPIdleProc
== NULL
) gTPIdleProc
= NewControlUserPaneIdleUPP(TPPaneIdleProc
);
504 if (gTPKeyProc
== NULL
) gTPKeyProc
= NewControlUserPaneKeyDownUPP(TPPaneKeyDownProc
);
505 if (gTPActivateProc
== NULL
) gTPActivateProc
= NewControlUserPaneActivateUPP(TPPaneActivateProc
);
506 if (gTPFocusProc
== NULL
) gTPFocusProc
= NewControlUserPaneFocusUPP(TPPaneFocusProc
);
508 /* allocate our private storage */
509 tpvars
= (STPTextPaneVars
**) NewHandleClear(sizeof(STPTextPaneVars
));
510 SetControlReference(theControl
, (long) tpvars
);
511 HLock((Handle
) tpvars
);
513 /* set the initial settings for our private data */
514 varsp
->fMultiline
= wxStyle
& wxTE_MULTILINE
;
515 varsp
->fInFocus
= false;
516 varsp
->fIsActive
= true;
517 varsp
->fTEActive
= true; // in order to get a deactivate
518 varsp
->fUserPaneRec
= theControl
;
519 theWindow
= varsp
->fOwner
= GetControlOwner(theControl
);
521 varsp
->fDrawingEnvironment
= (GrafPtr
) GetWindowPort(theWindow
);
523 varsp
->fInDialogWindow
= ( GetWindowKind(varsp
->fOwner
) == kDialogWindowKind
);
524 /* set up the user pane procedures */
525 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneDrawProcTag
, sizeof(gTPDrawProc
), &gTPDrawProc
);
526 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneHitTestProcTag
, sizeof(gTPHitProc
), &gTPHitProc
);
527 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneTrackingProcTag
, sizeof(gTPTrackProc
), &gTPTrackProc
);
528 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneIdleProcTag
, sizeof(gTPIdleProc
), &gTPIdleProc
);
529 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneKeyDownProcTag
, sizeof(gTPKeyProc
), &gTPKeyProc
);
530 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneActivateProcTag
, sizeof(gTPActivateProc
), &gTPActivateProc
);
531 SetControlData(theControl
, kControlEntireControl
, kControlUserPaneFocusProcTag
, sizeof(gTPFocusProc
), &gTPFocusProc
);
532 /* calculate the rectangles used by the control */
533 GetControlBounds(theControl
, &bounds
);
534 SetRect(&varsp
->fRFocusOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
535 SetRect(&varsp
->fRTextOutline
, bounds
.left
, bounds
.top
, bounds
.right
, bounds
.bottom
);
536 SetRect(&varsp
->fRTextArea
, bounds
.left
+ 2 , bounds
.top
+ (varsp
->fMultiline
? 0 : 2) ,
537 bounds
.right
- (varsp
->fMultiline
? 0 : 2), bounds
.bottom
- (varsp
->fMultiline
? 0 : 2));
538 /* calculate the background region for the text. In this case, it's kindof
539 and irregular region because we're setting the scroll bar a little ways inside
541 RectRgn((varsp
->fTextBackgroundRgn
= NewRgn()), &varsp
->fRTextOutline
);
543 /* set up the drawing environment */
544 SetPort(varsp
->fDrawingEnvironment
);
546 /* create the new edit field */
548 TXNFrameOptions frameOptions
=
549 kTXNDontDrawCaretWhenInactiveMask
;
550 if ( ! ( wxStyle
& wxTE_NOHIDESEL
) )
551 frameOptions
|= kTXNDontDrawSelectionWhenInactiveMask
;
553 if ( wxStyle
& wxTE_MULTILINE
)
555 if ( ! ( wxStyle
& wxTE_DONTWRAP
) )
556 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
559 frameOptions
|= kTXNAlwaysWrapAtViewEdgeMask
;
560 frameOptions
|= kTXNWantHScrollBarMask
;
563 if ( !(wxStyle
& wxTE_NO_VSCROLL
) )
564 frameOptions
|= kTXNWantVScrollBarMask
;
567 frameOptions
|= kTXNSingleLineOnlyMask
;
569 if ( wxStyle
& wxTE_READONLY
)
570 frameOptions
|= kTXNReadOnlyMask
;
572 TXNNewObject(NULL
, varsp
->fOwner
, &varsp
->fRTextArea
,
574 kTXNTextEditStyleFrameType
,
576 kTXNSystemDefaultEncoding
,
577 &varsp
->fTXNRec
, &varsp
->fTXNFrame
, (TXNObjectRefcon
) tpvars
);
583 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
585 TXNTypeAttributes typeAttr
[] =
587 { kTXNQDFontNameAttribute
, kTXNQDFontNameAttributeSize
, { (void*) fontName
} } ,
588 { kTXNQDFontSizeAttribute
, kTXNFontSizeAttributeSize
, { (void*) (fontSize
<< 16) } } ,
589 { kTXNQDFontStyleAttribute
, kTXNQDFontStyleAttributeSize
, { (void*) normal
} } ,
592 err
= TXNSetTypeAttributes (varsp
->fTXNRec
, sizeof( typeAttr
) / sizeof(TXNTypeAttributes
) , typeAttr
,
595 /* set the field's background */
597 tback
.bgType
= kTXNBackgroundTypeRGB
;
598 tback
.bg
.color
= rgbWhite
;
599 TXNSetBackground( varsp
->fTXNRec
, &tback
);
601 /* unlock our storage */
602 HUnlock((Handle
) tpvars
);
603 /* perform final activations and setup for our text field. Here,
604 we assume that the window is going to be the 'active' window. */
605 TPActivatePaneText(tpvars
, varsp
->fIsActive
&& varsp
->fInFocus
);
613 #if !USE_SHARED_LIBRARY
614 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
616 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
617 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
618 EVT_CHAR(wxTextCtrl::OnChar
)
619 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
620 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
621 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
622 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
623 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
625 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
626 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
627 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
628 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
629 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
634 wxTextCtrl::wxTextCtrl()
638 m_macTXNvars
= NULL
;
639 m_macUsesTXN
= false ;
641 m_maxLength
= TE_UNLIMITED_LENGTH
;
644 wxTextCtrl::~wxTextCtrl()
648 SetControlReference((ControlHandle
)m_macControl
, 0) ;
649 TXNDeleteObject((TXNObject
)m_macTXN
);
650 /* delete our private storage */
651 DisposeHandle((Handle
) m_macTXNvars
);
652 /* zero the control reference */
656 const short kVerticalMargin
= 2 ;
657 const short kHorizontalMargin
= 2 ;
659 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
662 const wxSize
& size
, long style
,
663 const wxValidator
& validator
,
664 const wxString
& name
)
668 m_macTXNvars
= NULL
;
669 m_macUsesTXN
= false ;
672 m_macUsesTXN
= ! (style
& wxTE_PASSWORD
) ;
674 m_macUsesTXN
&= (TXNInitTextension
!= (void*) kUnresolvedCFragSymbolAddress
) ;
676 // base initialization
677 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
680 wxSize mySize
= size
;
683 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
684 m_macVerticalBorder
= 3 ;
688 m_macHorizontalBorder
= 5 ; // additional pixels around the real control
689 m_macVerticalBorder
= 5 ;
696 if ( mySize.y == -1 )
699 if ( m_windowStyle & wxTE_MULTILINE )
702 mySize.y += 2 * m_macVerticalBorder ;
705 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, mySize
,style
, validator
, name
, &bounds
, title
) ;
707 if ( m_windowStyle
& wxTE_MULTILINE
)
709 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
710 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
712 m_windowStyle
|= wxTE_PROCESS_ENTER
;
715 if ( m_windowStyle
& wxTE_READONLY
)
722 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, "\p" , true , 0 , 0 , 1,
723 (style
& wxTE_PASSWORD
) ? kControlEditTextPasswordProc
: kControlEditTextProc
, (long) this ) ;
725 ::GetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextTEHandleTag
, sizeof( TEHandle
) , (char*) &((TEHandle
) m_macTE
) , &size
) ;
732 featurSet
= kControlSupportsEmbedding
| kControlSupportsFocus
| kControlWantsIdle
733 | kControlWantsActivate
| kControlHandlesTracking
| kControlHasSpecialBackground
734 | kControlGetsFocusOnClick
| kControlSupportsLiveFeedback
;
735 /* create the control */
736 m_macControl
= NewControl(MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, "\p", true, featurSet
, 0, featurSet
, kControlUserPaneProc
, 0);
737 /* set up the mUP specific features and data */
738 mUPOpenControl((ControlHandle
) m_macControl
, m_windowStyle
);
740 MacPostControlCreate() ;
744 wxCharBuffer text
= wxMacStringToCString( st
) ;
745 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, strlen(text
) , text
) ;
749 STPTextPaneVars
**tpvars
;
751 tpvars
= (STPTextPaneVars
**) GetControlReference((ControlHandle
) m_macControl
);
752 /* set the text in the record */
753 m_macTXN
= (**tpvars
).fTXNRec
;
755 TXNSetData( ((TXNObject
) m_macTXN
) , kTXNUnicodeTextData
, (void*)st
.wc_str(), st
.Length() * 2,
756 kTXNStartOffset
, kTXNEndOffset
);
758 wxCharBuffer text
= wxMacStringToCString( st
) ;
759 TXNSetData( ((TXNObject
) m_macTXN
) , kTXNTextData
, (void*)text
.data(), strlen( text
) ,
760 kTXNStartOffset
, kTXNEndOffset
);
762 m_macTXNvars
= tpvars
;
763 m_macUsesTXN
= true ;
764 TXNSetSelection( (TXNObject
) m_macTXN
, 0, 0);
765 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
771 wxString
wxTextCtrl::GetValue() const
778 err
= ::GetControlDataSize((ControlHandle
) m_macControl
, 0,
779 ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, &actualSize
) ;
782 return wxEmptyString
;
784 if ( actualSize
> 0 )
786 wxCharBuffer
buf(actualSize
) ;
787 ::GetControlData( (ControlHandle
) m_macControl
, 0,
788 ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
,
789 actualSize
, buf
.data() , &actualSize
) ;
790 result
= wxMacMakeStringFromCString( buf
) ;
797 err
= TXNGetDataEncoded( ((TXNObject
) m_macTXN
), kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNUnicodeTextData
);
805 actualSize
= GetHandleSize( theText
) ;
806 if ( actualSize
> 0 )
808 wxChar
*ptr
= result
.GetWriteBuf(actualSize
*sizeof(wxChar
)) ;
809 wxStrncpy( ptr
, (wxChar
*) *theText
, actualSize
) ;
810 ptr
[actualSize
] = 0 ;
811 result
.UngetWriteBuf( actualSize
) ;
813 DisposeHandle( theText
) ;
817 err
= TXNGetDataEncoded( ((TXNObject
) m_macTXN
), kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
825 actualSize
= GetHandleSize( theText
) ;
826 if ( actualSize
> 0 )
829 result
= wxMacMakeStringFromCString( *theText
, actualSize
) ;
832 DisposeHandle( theText
) ;
840 void wxTextCtrl::GetSelection(long* from
, long* to
) const
844 *from
= (**((TEHandle
) m_macTE
)).selStart
;
845 *to
= (**((TEHandle
) m_macTE
)).selEnd
;
849 TXNGetSelection( ((TXNObject
) m_macTXN
) , (TXNOffset
*) from
, (TXNOffset
*) to
) ;
853 void wxTextCtrl::SetValue(const wxString
& st
)
857 wxCharBuffer text
= wxMacStringToCString( st
) ;
858 ::SetControlData( (ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, strlen(text
) , text
) ;
862 bool formerEditable
= m_editable
;
863 if ( !formerEditable
)
866 TXNSetData( ((TXNObject
) m_macTXN
), kTXNUnicodeTextData
, (void*)st
.wc_str(), st
.Length() * 2 ,
867 kTXNStartOffset
, kTXNEndOffset
);
869 wxCharBuffer text
= wxMacStringToCString( st
) ;
870 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)text
.data(), strlen( text
) ,
871 kTXNStartOffset
, kTXNEndOffset
);
873 TXNSetSelection( (TXNObject
) m_macTXN
, 0, 0);
874 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
875 if ( !formerEditable
)
876 SetEditable(formerEditable
) ;
881 void wxTextCtrl::SetMaxLength(unsigned long len
)
886 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
890 bool formerEditable
= m_editable
;
891 if ( !formerEditable
)
893 TXNTypeAttributes typeAttr
[4] ;
894 Str255 fontName
= "\pMonaco" ;
895 SInt16 fontSize
= 12 ;
896 Style fontStyle
= normal
;
898 int attrCounter
= 0 ;
899 if ( style
.HasFont() )
901 const wxFont
&font
= style
.GetFont() ;
902 wxMacStringToPascal( font
.GetFaceName() , fontName
) ;
903 fontSize
= font
.GetPointSize() ;
904 if ( font
.GetUnderlined() )
905 fontStyle
|= underline
;
906 if ( font
.GetWeight() == wxBOLD
)
908 if ( font
.GetStyle() == wxITALIC
)
909 fontStyle
|= italic
;
911 typeAttr
[attrCounter
].tag
= kTXNQDFontNameAttribute
;
912 typeAttr
[attrCounter
].size
= kTXNQDFontNameAttributeSize
;
913 typeAttr
[attrCounter
].data
.dataPtr
= (void*) fontName
;
914 typeAttr
[attrCounter
+1].tag
= kTXNQDFontSizeAttribute
;
915 typeAttr
[attrCounter
+1].size
= kTXNFontSizeAttributeSize
;
916 typeAttr
[attrCounter
+1].data
.dataValue
= (fontSize
<< 16) ;
917 typeAttr
[attrCounter
+2].tag
= kTXNQDFontStyleAttribute
;
918 typeAttr
[attrCounter
+2].size
= kTXNQDFontStyleAttributeSize
;
919 typeAttr
[attrCounter
+2].data
.dataValue
= fontStyle
;
923 if ( style
.HasTextColour() )
925 typeAttr
[attrCounter
].tag
= kTXNQDFontColorAttribute
;
926 typeAttr
[attrCounter
].size
= kTXNQDFontColorAttributeSize
;
927 typeAttr
[attrCounter
].data
.dataPtr
= (void*) &color
;
928 color
= MAC_WXCOLORREF(style
.GetTextColour().GetPixel()) ;
932 if ( attrCounter
> 0 )
934 OSStatus status
= TXNSetTypeAttributes ((TXNObject
)m_macTXN
, attrCounter
, typeAttr
,
936 wxASSERT_MSG( status
== noErr
, wxT("Couldn't set text attributes") ) ;
938 if ( !formerEditable
)
939 SetEditable(formerEditable
) ;
944 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
946 wxTextCtrlBase::SetDefaultStyle( style
) ;
947 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
951 // Clipboard operations
952 void wxTextCtrl::Copy()
958 TECopy( ((TEHandle
) m_macTE
) ) ;
966 TXNCopy((TXNObject
)m_macTXN
);
967 TXNConvertToPublicScrap();
972 void wxTextCtrl::Cut()
978 TECut( ((TEHandle
) m_macTE
) ) ;
986 TXNCut((TXNObject
)m_macTXN
);
987 TXNConvertToPublicScrap();
989 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
990 event
.SetString( GetValue() ) ;
991 event
.SetEventObject( this );
992 GetEventHandler()->ProcessEvent(event
);
996 void wxTextCtrl::Paste()
1000 if ( !m_macUsesTXN
)
1003 TEPaste( (TEHandle
) m_macTE
) ;
1004 MacRedrawControl() ;
1008 TXNConvertFromPublicScrap();
1009 TXNPaste((TXNObject
)m_macTXN
);
1010 SetStyle( kTXNUseCurrentSelection
, kTXNUseCurrentSelection
, GetDefaultStyle() ) ;
1012 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1013 event
.SetString( GetValue() ) ;
1014 event
.SetEventObject( this );
1015 GetEventHandler()->ProcessEvent(event
);
1019 bool wxTextCtrl::CanCopy() const
1021 // Can copy if there's a selection
1023 GetSelection(& from
, & to
);
1024 return (from
!= to
);
1027 bool wxTextCtrl::CanCut() const
1029 if ( !IsEditable() )
1033 // Can cut if there's a selection
1035 GetSelection(& from
, & to
);
1036 return (from
!= to
);
1039 bool wxTextCtrl::CanPaste() const
1045 OSStatus err
= noErr
;
1048 err
= GetCurrentScrap( &scrapRef
);
1049 if ( err
!= noTypeErr
&& err
!= memFullErr
)
1051 ScrapFlavorFlags flavorFlags
;
1054 if (( err
= GetScrapFlavorFlags( scrapRef
, 'TEXT', &flavorFlags
)) == noErr
)
1056 if (( err
= GetScrapFlavorSize( scrapRef
, 'TEXT', &byteCount
)) == noErr
)
1066 if ( GetScrap( NULL
, 'TEXT' , &offset
) > 0 )
1074 void wxTextCtrl::SetEditable(bool editable
)
1076 if ( editable
!= m_editable
)
1078 m_editable
= editable
;
1079 if ( !m_macUsesTXN
)
1082 UMAActivateControl( (ControlHandle
) m_macControl
) ;
1084 UMADeactivateControl((ControlHandle
) m_macControl
) ;
1088 TXNControlTag tag
[] = { kTXNIOPrivilegesTag
} ;
1089 TXNControlData data
[] = { { editable
? kTXNReadWrite
: kTXNReadOnly
} } ;
1090 TXNSetTXNObjectControls( (TXNObject
) m_macTXN
, false , sizeof(tag
) / sizeof (TXNControlTag
) , tag
, data
) ;
1095 void wxTextCtrl::SetInsertionPoint(long pos
)
1097 SetSelection( pos
, pos
) ;
1100 void wxTextCtrl::SetInsertionPointEnd()
1102 long pos
= GetLastPosition();
1103 SetInsertionPoint(pos
);
1106 long wxTextCtrl::GetInsertionPoint() const
1109 GetSelection( &begin
, &end
) ;
1113 long wxTextCtrl::GetLastPosition() const
1115 if ( !m_macUsesTXN
)
1117 return (**((TEHandle
) m_macTE
)).teLength
;
1123 OSErr err
= TXNGetDataEncoded( (TXNObject
) m_macTXN
, kTXNStartOffset
, kTXNEndOffset
, &theText
, kTXNTextData
);
1131 actualsize
= GetHandleSize( theText
) ;
1132 DisposeHandle( theText
) ;
1138 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
1140 if ( !m_macUsesTXN
)
1142 ControlEditTextSelectionRec selection
;
1144 selection
.selStart
= from
;
1145 selection
.selEnd
= to
;
1146 ::SetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1147 TESetSelect( from
, to
, ((TEHandle
) m_macTE
) ) ;
1148 TEDelete( ((TEHandle
) m_macTE
) ) ;
1149 TEInsert( value
, value
.Length() , ((TEHandle
) m_macTE
) ) ;
1153 bool formerEditable
= m_editable
;
1154 if ( !formerEditable
)
1156 TXNSetSelection( ((TXNObject
) m_macTXN
) , from
, to
) ;
1157 TXNClear( ((TXNObject
) m_macTXN
) ) ;
1159 TXNSetData( ((TXNObject
) m_macTXN
), kTXNUnicodeTextData
, (void*)value
.wc_str(), value
.Length() * 2 ,
1160 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1162 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)value
.c_str(), value
.Length(),
1163 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1165 if ( !formerEditable
)
1166 SetEditable( formerEditable
) ;
1171 void wxTextCtrl::Remove(long from
, long to
)
1173 if ( !m_macUsesTXN
)
1175 ControlEditTextSelectionRec selection
;
1177 selection
.selStart
= from
;
1178 selection
.selEnd
= to
;
1179 ::SetControlData( (ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1180 TEDelete( ((TEHandle
) m_macTE
) ) ;
1184 bool formerEditable
= m_editable
;
1185 if ( !formerEditable
)
1187 TXNSetSelection( ((TXNObject
) m_macTXN
) , from
, to
) ;
1188 TXNClear( ((TXNObject
) m_macTXN
) ) ;
1189 if ( !formerEditable
)
1190 SetEditable( formerEditable
) ;
1195 void wxTextCtrl::SetSelection(long from
, long to
)
1201 to
= GetLastPosition();
1203 if ( !m_macUsesTXN
)
1205 ControlEditTextSelectionRec selection
;
1206 selection
.selStart
= from
;
1207 selection
.selEnd
= to
;
1209 TESetSelect( selection
.selStart
, selection
.selEnd
, ((TEHandle
) m_macTE
) ) ;
1210 ::SetControlData((ControlHandle
) m_macControl
, 0, kControlEditTextSelectionTag
, sizeof( selection
) , (char*) &selection
) ;
1214 STPTextPaneVars
**tpvars
;
1215 /* set up our locals */
1216 tpvars
= (STPTextPaneVars
**) GetControlReference((ControlHandle
) m_macControl
);
1217 /* and our drawing environment as the operation
1218 may force a redraw in the text area. */
1219 SetPort((**tpvars
).fDrawingEnvironment
);
1220 /* change the selection */
1221 TXNSetSelection( (**tpvars
).fTXNRec
, from
, to
);
1222 TXNShowSelection( (TXNObject
) m_macTXN
, kTXNShowStart
);
1226 bool wxTextCtrl::LoadFile(const wxString
& file
)
1228 if ( wxTextCtrlBase::LoadFile(file
) )
1236 void wxTextCtrl::WriteText(const wxString
& st
)
1238 if ( !m_macUsesTXN
)
1240 wxCharBuffer text
= wxMacStringToCString( st
) ;
1241 TEInsert( text
, strlen(text
) , ((TEHandle
) m_macTE
) ) ;
1245 bool formerEditable
= m_editable
;
1246 if ( !formerEditable
)
1248 long start
, end
, dummy
;
1249 GetSelection( &start
, &dummy
) ;
1251 TXNSetData( ((TXNObject
) m_macTXN
), kTXNUnicodeTextData
, (void*)st
.wc_str(), st
.Length() * 2 ,
1252 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1254 wxCharBuffer text
= wxMacStringToCString( st
) ;
1255 TXNSetData( ((TXNObject
) m_macTXN
), kTXNTextData
, (void*)text
.data(), strlen( text
) ,
1256 kTXNUseCurrentSelection
, kTXNUseCurrentSelection
);
1258 GetSelection( &dummy
, &end
) ;
1259 SetStyle( start
, end
, GetDefaultStyle() ) ;
1260 if ( !formerEditable
)
1261 SetEditable( formerEditable
) ;
1263 MacRedrawControl() ;
1266 void wxTextCtrl::AppendText(const wxString
& text
)
1268 SetInsertionPointEnd();
1272 void wxTextCtrl::Clear()
1274 if ( !IsEditable() )
1278 if ( !m_macUsesTXN
)
1280 ::SetControlData((ControlHandle
) m_macControl
, 0, ( m_windowStyle
& wxTE_PASSWORD
) ? kControlEditTextPasswordTag
: kControlEditTextTextTag
, 0 , (char*) ((const char*)NULL
) ) ;
1284 TXNSetSelection( (TXNObject
)m_macTXN
, kTXNStartOffset
, kTXNEndOffset
) ;
1285 TXNClear((TXNObject
)m_macTXN
);
1290 bool wxTextCtrl::IsModified() const
1295 bool wxTextCtrl::IsEditable() const
1297 return IsEnabled() && m_editable
;
1300 bool wxTextCtrl::AcceptsFocus() const
1302 // we don't want focus if we can't be edited
1303 return /*IsEditable() && */ wxControl::AcceptsFocus();
1306 wxSize
wxTextCtrl::DoGetBestSize() const
1321 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
1323 int wText = DEFAULT_ITEM_WIDTH;
1325 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
1327 return wxSize(wText, hText);
1329 if ( m_windowStyle
& wxTE_MULTILINE
)
1333 hText
+= 2 * m_macVerticalBorder
;
1334 wText
+= 2 * m_macHorizontalBorder
;
1335 //else: for single line control everything is ok
1336 return wxSize(wText
, hText
);
1339 // ----------------------------------------------------------------------------
1341 // ----------------------------------------------------------------------------
1343 void wxTextCtrl::Undo()
1349 TXNUndo((TXNObject
)m_macTXN
);
1354 void wxTextCtrl::Redo()
1360 TXNRedo((TXNObject
)m_macTXN
);
1365 bool wxTextCtrl::CanUndo() const
1367 if ( !IsEditable() )
1373 return TXNCanUndo((TXNObject
)m_macTXN
,NULL
);
1378 bool wxTextCtrl::CanRedo() const
1380 if ( !IsEditable() )
1386 return TXNCanRedo((TXNObject
)m_macTXN
,NULL
);
1391 // Makes 'unmodified'
1392 void wxTextCtrl::DiscardEdits()
1397 int wxTextCtrl::GetNumberOfLines() const
1399 // TODO change this if possible to reflect real lines
1400 wxString content
= GetValue() ;
1403 for (size_t i
= 0; i
< content
.Length() ; i
++)
1405 if (content
[i
] == '\r') count
++;
1411 long wxTextCtrl::XYToPosition(long x
, long y
) const
1417 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
1422 void wxTextCtrl::ShowPosition(long pos
)
1427 int wxTextCtrl::GetLineLength(long lineNo
) const
1429 // TODO change this if possible to reflect real lines
1430 wxString content
= GetValue() ;
1434 for (size_t i
= 0; i
< content
.Length() ; i
++)
1436 if (count
== lineNo
)
1438 // Count chars in line then
1440 for (size_t j
= i
; j
< content
.Length(); j
++)
1443 if (content
[j
] == '\r') return count
;
1448 if (content
[i
] == '\r') count
++;
1453 wxString
wxTextCtrl::GetLineText(long lineNo
) const
1455 // TODO change this if possible to reflect real lines
1456 wxString content
= GetValue() ;
1460 for (size_t i
= 0; i
< content
.Length() ; i
++)
1462 if (count
== lineNo
)
1464 // Add chars in line then
1467 for (size_t j
= i
; j
< content
.Length(); j
++)
1469 if (content
[j
] == '\r')
1477 if (content
[i
] == '\r') count
++;
1479 return wxEmptyString
;
1486 void wxTextCtrl::Command(wxCommandEvent
& event
)
1488 SetValue (event
.GetString());
1489 ProcessCommand (event
);
1492 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
1494 // By default, load the first file into the text window.
1495 if (event
.GetNumberOfFiles() > 0)
1497 LoadFile(event
.GetFiles()[0]);
1501 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
1503 int key
= event
.GetKeyCode() ;
1504 bool eat_key
= false ;
1506 if ( key
== 'c' && event
.MetaDown() )
1513 if ( !IsEditable() && key
!= WXK_LEFT
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_UP
&& key
!= WXK_TAB
&&
1514 !( key
== WXK_RETURN
&& ( (m_windowStyle
& wxPROCESS_ENTER
) || (m_windowStyle
& wxTE_MULTILINE
) ) )
1515 /* && key != WXK_PRIOR && key != WXK_NEXT && key != WXK_HOME && key != WXK_END */
1521 if ( key
== 'v' && event
.MetaDown() )
1527 if ( key
== 'x' && event
.MetaDown() )
1536 if (m_windowStyle
& wxPROCESS_ENTER
)
1538 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1539 event
.SetEventObject( this );
1540 event
.SetString( GetValue() );
1541 if ( GetEventHandler()->ProcessEvent(event
) )
1544 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1546 wxWindow
*parent
= GetParent();
1547 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
) {
1548 parent
= parent
->GetParent() ;
1550 if ( parent
&& parent
->GetDefaultItem() )
1552 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
1554 if ( def
&& def
->IsEnabled() )
1556 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1557 event
.SetEventObject(def
);
1558 def
->Command(event
);
1563 // this will make wxWindows eat the ENTER key so that
1564 // we actually prevent line wrapping in a single line
1572 // always produce navigation event - even if we process TAB
1573 // ourselves the fact that we got here means that the user code
1574 // decided to skip processing of this TAB - probably to let it
1575 // do its default job.
1577 wxNavigationKeyEvent eventNav
;
1578 eventNav
.SetDirection(!event
.ShiftDown());
1579 eventNav
.SetWindowChange(event
.ControlDown());
1580 eventNav
.SetEventObject(this);
1582 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
1596 if ( ( key
>= 0x20 && key
< WXK_START
) ||
1597 key
== WXK_RETURN
||
1598 key
== WXK_DELETE
||
1601 wxCommandEvent
event1(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1602 event1
.SetString( GetValue() ) ;
1603 event1
.SetEventObject( this );
1604 wxPostEvent(GetEventHandler(),event1
);
1608 void wxTextCtrl::MacSuperShown( bool show
)
1610 bool former
= m_macControlIsShown
;
1611 wxControl::MacSuperShown( show
) ;
1612 if ( (former
!= m_macControlIsShown
) && m_macUsesTXN
)
1614 if ( m_macControlIsShown
)
1615 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1616 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
,(**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1618 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1619 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1623 bool wxTextCtrl::Show(bool show
)
1625 bool former
= m_macControlIsShown
;
1627 bool retval
= wxControl::Show( show
) ;
1629 if ( former
!= m_macControlIsShown
&& m_macUsesTXN
)
1631 if ( m_macControlIsShown
)
1632 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1633 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
,(**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1635 TXNSetFrameBounds( (TXNObject
) m_macTXN
, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.top
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.left
,
1636 (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.bottom
+ 30000, (**(STPTextPaneVars
**)m_macTXNvars
).fRTextArea
.right
, (**(STPTextPaneVars
**)m_macTXNvars
).fTXNFrame
);
1642 // ----------------------------------------------------------------------------
1643 // standard handlers for standard edit menu events
1644 // ----------------------------------------------------------------------------
1646 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1651 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1656 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1661 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1666 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1671 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1673 event
.Enable( CanCut() );
1676 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1678 event
.Enable( CanCopy() );
1681 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1683 event
.Enable( CanPaste() );
1686 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1688 event
.Enable( CanUndo() );
1691 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1693 event
.Enable( CanRedo() );
1696 bool wxTextCtrl::MacSetupCursor( const wxPoint
& pt
)
1701 return wxWindow::MacSetupCursor( pt
) ;