Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Dec 11, 2019 2:35 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to disable built-in undo on TextArea?
PostPosted: Mon Feb 20, 2012 4:47 pm 
Offline

Joined: Tue Nov 28, 2006 7:35 am
Posts: 19
I wrote a simple undo/redo engine for TextArea. My subclass has menuhandlers for Undo, Redo and Paste. The Paste menuhandler stores the text from clipboard and insertion point, after that, it inserts the clipboard's content into control's text. The Undo menuhandler removes that stored text from control's text. The Redo menuhandler inserts stored text again.
Everything works fine, i can undo and redo. But if no undo available and Undo menu is disabled, when i press a shortcut for undo (Ctrl+Z), looks like the TextArea's built-in undo engine invoked.

Example: Empty textarea. I paste text from clipboard. Undoing it, my code works. Undo menuitem disabled. Pressing shortcut for undo. Previously pasted text appears again. Pressing again. The text disappears. Pressing again and nothing happens.

Looks like my undo engine's changes in text threated as simple text changes by TextArea's built-in undo, but i can't understand why built-in undo works when menuitem disabled...

How can i disable this built in undo???


Top
 Profile  
Reply with quote  
 Post subject: Re: How to disable built-in undo on TextArea?
PostPosted: Tue Feb 21, 2012 6:11 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
With MBS Plugins, simply do this in text area open event:

dim t as NSTextViewMBS = me.NSTextViewMBS
t.undoManager.disableUndoRegistration


Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: How to disable built-in undo on TextArea?
PostPosted: Tue Feb 21, 2012 2:24 pm 
Offline

Joined: Tue Nov 28, 2006 7:35 am
Posts: 19
Finally i've found a workaround. Maybe it's not as elegant as it would be, but for me it works. It resets the undo flag of an edit control.

Make a method with following code and call it at the end of TextChange eventhandler:

#if TargetWin32
Declare Function SendMessageA Lib "User32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
Declare Function SendMessageW Lib "User32" Alias "SendMessageW" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
// EM_EMPTYUNDOBUFFER = &hCD
If System.IsFunctionAvailable( "SendMessageW", "User32" ) Then
Call SendMessageW(Self.Handle, &hCD, 0, 0)
Else
Call SendMessageW(Self.Handle, &hCD, 0, 0)
End If
#endif


Top
 Profile  
Reply with quote  
 Post subject: Re: How to disable built-in undo on TextArea?
PostPosted: Tue Feb 21, 2012 5:11 pm 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Oh, sorry. My idea was for Cocoa on Mac OS X.

For your code, well, please use SendMessageW in your else part.
But you can use SendMessageW only. It's always available.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: How to disable built-in undo on TextArea?
PostPosted: Wed Feb 22, 2012 5:24 am 
Offline

Joined: Tue Nov 28, 2006 7:35 am
Posts: 19
Thanks for the remark. The corrected code:

#if TargetWin32
Declare Function SendMessageA Lib "User32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
Declare Function SendMessageW Lib "User32" Alias "SendMessageW" (hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
// EM_EMPTYUNDOBUFFER = &hCD
If System.IsFunctionAvailable( "SendMessageW", "User32" ) Then
Call SendMessageW(Self.Handle, &hCD, 0, 0)
Else
Call SendMessageA(Self.Handle, &hCD, 0, 0)
End If
#endif


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group