AutoHotkey Community

It is currently May 27th, 2012, 12:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 240 posts ]  Go to page Previous  1 ... 9, 10, 11, 12, 13, 14, 15, 16  Next

Do you want HiEdit internaly
Yes
No, I like Edit control
Other (please explain)
You may select 1 option

View results
Author Message
 Post subject: Line-wrap simulation
PostPosted: December 6th, 2009, 2:44 am 
Offline

Joined: May 21st, 2007, 4:47 pm
Posts: 85
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 December 30th, 2009, 7:34 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2009, 3:30 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
*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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2009, 4:15 pm 
Offline

Joined: May 21st, 2007, 4:47 pm
Posts: 85
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 6:59 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 10:01 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 10:29 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
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::...

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 12:46 pm 
Offline

Joined: May 21st, 2007, 4:47 pm
Posts: 85
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 1:40 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 2:17 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 4:59 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
RButton up :)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2009, 4:50 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2009, 9:49 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Mhm.... I confirm this experience. I wonder how this can be xplained. Context sensitive RButton up influenceing left click in entire system...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2009, 3:18 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2009, 4:36 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I am sure u are talking about different thing.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2009, 6:20 am 
Offline

Joined: March 25th, 2009, 2:04 pm
Posts: 24
Thanks for your good work! Does this control support column mode, just like untraedit does?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 240 posts ]  Go to page Previous  1 ... 9, 10, 11, 12, 13, 14, 15, 16  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Cristi®, Google Feedfetcher, Stigg and 43 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group