 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Do you want HiEdit internaly |
| Yes |
|
52% |
[ 37 ] |
| No, I like Edit control |
|
28% |
[ 20 ] |
| Other (please explain) |
|
19% |
[ 14 ] |
|
| Total Votes : 71 |
|
| Author |
Message |
Normand
Joined: 21 May 2007 Posts: 63
|
Posted: Sun Dec 06, 2009 2:44 am Post subject: Line-wrap simulation |
|
|
Word wrap simulator
HiEdit control doesn't support word wrap. At least, not yet. Here is the way I imagined to overpass this limitation.
Be sure your content have only Windows standard break lines (CR+LF), then press Ctrl+W to begin. A dialog box will appear. Type the line length you want, then press Enter. The content will be displayed at the length asked for without any cut within a word. To get back the original line length, press Ctrl+W, then type zero (0) followed by Enter and that's it.
How does it work?
The mechanism is based on the fact that a Windows standard break line (CR+LF) and a Unix-like break line (LF) have exactly the same aspect in a HiEdit control.
Suppose you asked for a 72 characters line lenght. For each line longer than 72 characters, the program will check if it's possible to cut at the position asked for. If yes, a sole line feed character (LF) will be used to make the cut. If no, the program go to the previous position and do the same check, and so on, until a cut will be possible.
To prevent cut within a word, a cut is considered possible only after a space or one of the following characters:
!$%),./:;>?]}…»
By doing so, it will be easy to remove this kind of break line (LF) without removing the other (CR+LF). And so, get the content back to the original line length.
| Code: | ^W:: ; Press Ctrl+W (like word wrap)
Gui,-MaximizeBox -MinimizeBox ; to get the dialog box.
Gui,Add,Text,,How many characters:
Gui,Add,Edit,vLL Number Limit4 W54 ys ; LL stands for line length.
Gui,Add,Button,W81 H24 xs y+16 Default,OK
Gui,Show,,Line length
Return
GuiEscape: ; Closing the dialog box
GuiClose: ; or pressing Escape key
Gui,Destroy ; will destroy the GUI.
Return
ButtonOK: ; Pressing the OK button
Gui,Submit ; first, submit the GUI
Gui,Destroy ; then, destroy it.
If (LL<>0 && LL<20) ; To prevent a too short line length.
Return
T:=HE_GetTextRange(hEdit,0,-1)
T:=RegExReplace(T,"(\S)\n","$1 ",1) ; Replace all Unix-like break line
T:=RegExReplace(T," \n"," ",1) ; by a space... and only one.
SendMessage,0xB1,0,-1,,ahk_id %hEdit% ; By doing so, you get back the
SendMessage,0xC2,,&T,,ahk_id %hEdit% ; original line length.
If LL=0
Return
FR= ; Clear Final Result's variable.
L=1 ; Start at the first line.
Val:=LL ; Start with the line length asked for.
TLN:=HE_GetLineCount(hEdit) ; Get the number of lines in the control.
Loop,%TLN% ; For each line...
{ ; Get the line's text.
ControlGet,TLC,Line,%L%,,ahk_id %hEdit%
If StrLen(TLC)<Val ; If it's shorter than the line length
FR.=TLC ; asked for, keep it entirely and go to
Else ; the next line.
{
Cisor:
cut:=LL-1
Loop ; If it's not, verify if it's possible to
{ ; cut at the current position.
StringMid,CCC,TLC,cut,1
If CCC Not In ,,, ,!,$,`%,),.,/,:,;,>,?,],},…,»
cut-- ; If not, check for the previous...
Else ; ...and so on,
Break ; until it will be...
}
StringLeft,CG,TLC,cut ; ...then do it...
FR.=CG . "`n"
StringTrimLeft,TLC,TLC,cut ; ...and do the same thing
If StrLen(TLC)<Val ; with the rest of the line until
FR.=TLC ; its length will be less than
Else ; the line length asked for.
GoTo,Cisor
}
L++ ; Then, do the same with the next line...
If L=TLN ; ...except if this was the last.
Break
}
FR:=RegExReplace(FR,"([^ ])(`n) ","$1$2",1) ; Remove all trailing space.
SendMessage,0xB1,0,-1,,ahk_id %hEdit% ; Then, select all and
SendMessage,0xC2,,&FR,,ahk_id %hEdit% ; replace it with Final
Return ; Result's contents.
|
Edit
To cut a line manually, a command that inserts a single line feed (LF) character may be useful.
Here it is: | Code: | | !Enter::Send {Asc 010} ; Alt+Enter |
_________________ Normand Lamoureux
Last edited by Normand on Wed Dec 30, 2009 7:34 pm; edited 1 time in total |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4116 Location: Belgrade
|
Posted: Sun Dec 06, 2009 3:30 pm Post subject: |
|
|
*Very* nice workaround.
People should keep in mind however that this is enough for read only text.
Editing text will mess things up. I'll put this as a link on first page.
Thank you. _________________
 |
|
| Back to top |
|
 |
Normand
Joined: 21 May 2007 Posts: 63
|
Posted: Sun Dec 06, 2009 4:15 pm Post subject: |
|
|
Thanks for your good word, majkinetor.
Only useful in reading mode, your're right.
When I use HiEdit to read a book, I only have to use my word wrap simulator function once, and it's done.
But when I take notes (writing mode), I have to cut my lines periodically. It still usable, but not as much. _________________ Normand Lamoureux |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 537 Location: Texas, USA
|
Posted: Thu Dec 17, 2009 6:59 am Post subject: |
|
|
I want to use my own context menu when using the HiEdit control. I've created a very usable work-around (RButton hotkey) that shows my context menu but every once in a while the built-in context menu for the HiEdit control shows it's ugly head.
Does anyone know of a way to disable the built-in context menu for the HiEdit control?
Any help would be appreciated. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4116 Location: Belgrade
|
Posted: Thu Dec 17, 2009 10:01 am Post subject: |
|
|
I tried RButton here and I don't have that effect.
But you may want to try to subclass control and handle WM_RBUTTON*** yourself. _________________
 |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 2198 Location: GERMANY
|
Posted: Thu Dec 17, 2009 10:29 am Post subject: |
|
|
| jballi wrote: | I want to use my own context menu when using the HiEdit control. I've created a very usable work-around (RButton hotkey) that shows my context menu but every once in a while the built-in context menu for the HiEdit control shows it's ugly head.
Does anyone know of a way to disable the built-in context menu for the HiEdit control?
Any help would be appreciated. |
Have you used  | Code: | #IfWinActive ...
RButton::... |
_________________ AutoHotFile - ToolTip(n,text,title,options) |
|
| Back to top |
|
 |
Normand
Joined: 21 May 2007 Posts: 63
|
Posted: Thu Dec 17, 2009 12:46 pm Post subject: |
|
|
Since there are many ways to open context menu, I personally use the following code:
| Code: | #IfWinActive, (...) ahk_class AutoHotkeyGUI
(...)
+F10::
AppsKey::
RButton::
|
By the way, every new HiEdit's file tab is named *File following by a number. It's OK in English, but how to change it for a French or a Spanish version?
A similar problem occur with "First Tab", "Previous Tab", "Next Tab" and "Last Tab" tooltips.
Generally, a unique-language built-in feature is not the best. _________________ Normand Lamoureux |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4116 Location: Belgrade
|
Posted: Thu Dec 17, 2009 1:40 pm Post subject: |
|
|
Aha, I see what you mean.
Problem happens because of how AHK handles clicks.
Its reported problem I think, I hate to search docs/forum for it, but it seems like something reported several times and its about click that activates the application.
In _Test.ahk you can see that in effect if you click on the destkop, then right click on HiEdit. Original menu will appear.
Or, interestingly, click on the menu, then while menu is still open, right click the HiEdit and this can't be prevented even with non application specific hotkey.
The BIG question remains - why blue behavior? Is it a bug ? I thought so initially, but not now.
What turns to be the problem is how control and AHK handle right clicks. AHK handles Downs, while HiEdit triggers on Ups.
So, solution seem to be:
| Code: | #IfWinActive, HiEdit Test
RButton up:: tooltip ej
#IfWinActive |
| Quote: | | By the way, every new HiEdit's file tab is named *File following by a number. It's OK in English, but how to change it for a French or a Spanish version? |
I opened dll in hex editor, found "*File" pattern, changed it (there is room for text) to something else and it worked. Maybe you can create language-patch if that is important for you so you will be able to one-click change future versions. _________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 537 Location: Texas, USA
|
Posted: Thu Dec 17, 2009 2:17 pm Post subject: |
|
|
| HotKeyIt wrote: | Have you used  | Code: | #IfWinActive ...
RButton::... |
|
That's what I'm doing but the built-in context menu still shows up every once in a while.
| majkinetor wrote: | | But you may want to try to subclass control and handle WM_RBUTTON*** yourself. |
I put in a trap for the WM_RBUTTONUP message. I still need to do some additional testing but it looks like this stops the built-in context menu. I'm a little surprised that I doesn't override the RButton hotkey but now that I think about it, the RButton hotkey fires on WM_RBUTTONDOWN. I was hoping for a built-in HiEdit option to do the job but this should work. Thanks for your help. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4116 Location: Belgrade
|
Posted: Thu Dec 17, 2009 4:59 pm Post subject: |
|
|
RButton up  _________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 537 Location: Texas, USA
|
Posted: Fri Dec 18, 2009 4:50 am Post subject: |
|
|
| majkinetor wrote: | RButton up  |
Just a quick follow up...
I created a context-sensitive RButton Up hotkey that shows a menu. The hotkey works without incident at first but after a short while, the mouse stops working correctly and I was unable to click correctly on the taskbar and other windows. For example, clicking on items in a Windows Explorer item would bring up the Explorer's context menu. These mouse problems occurred after I exited the script. I rebooted the machine to make sure it wasn't a fluke but the problem presented itself again and again.
I abandoned the RButton Up hotkey and created a OnMessage trap for the WM_RBUTTONUP message. So far the code is working without any of the side effects of the hotkey.
I just wanted to report my experiences just in case anyone else was experiencing problems using the RButton Up hotkey to show a menu.
Them be my thoughts... |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4116 Location: Belgrade
|
Posted: Fri Dec 18, 2009 9:49 am Post subject: |
|
|
Mhm.... I confirm this experience. I wonder how this can be xplained. Context sensitive RButton up influenceing left click in entire system... _________________
 |
|
| Back to top |
|
 |
Drugwash
Joined: 08 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Mon Dec 21, 2009 3:18 pm Post subject: |
|
|
Pardon me for barging in, but in my experience I stumbled into a similar experience of left-click executing context menu, many times, on my machine, after application crash or while testing applications that wouldn't work correctly in Win9x.
The conclusion I got to is that the behavior should not be bound to AHK or the running script but to certain system library that starts misbehaving under specifing circumstances. Could even be related to the video driver - try selecting Refresh from the Desktop context menu, see if it fixes anything. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4116 Location: Belgrade
|
Posted: Mon Dec 21, 2009 4:36 pm Post subject: |
|
|
I am sure u are talking about different thing. _________________
 |
|
| Back to top |
|
 |
gongchao6330
Joined: 25 Mar 2009 Posts: 12
|
Posted: Tue Dec 22, 2009 6:20 am Post subject: |
|
|
| Thanks for your good work! Does this control support column mode, just like untraedit does? |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|