Hi all!
I'm trying to add bookmarks feature to rich edit (it works as simple edit, i.e. no RTF formats).
I store bookmarks in linked list, where each member is a structure which has pointers to the next, previous and line number of bookmark. Now suppose we have bookmarks for lines 2 and 4, then place the caret on line 3 and press Enter. Lines count grows up by one, lines number 3 and 4 move down and second bookmark is now on the former third line which becomes the fourth.
Obviously I should rebuild the list when the lines count is changed. But for doing that I have to know the lines count BEFORE any keyboard or clipboard (cut/paste) action and I haven't found so far any notification for lines count change. Both EN_CHANGE and EN_UPDATE are fired after the changes happen.
Or may be there is another way for adding bookmarks?
Thank you
Andre,
From memory the total line count is taken internally so it does not scan the file each time to get the number. You could probably get away with triggering the SendMessage from both key and mouse input to get what you want. This is easy enough to do from a callback for the edit control by trapping WM_CHAR and WM_MOUSEMOVE.
Quote from: lamer on August 14, 2008, 10:14:40 AM
Both EN_CHANGE and EN_UPDATE are fired after the changes happen.
Try WM_NOTIFY. Here is a snippet from my own editor (mb is an equate for
invoke MessageBox, 0, ):
CASE WM_NOTIFY
mov edx, lParam ; Pointer to NOTIFY structure
mov eax, [edx.NMHDR.code] ; message+8 = code
.if eax==070Bh ;EN_LINK for EM_AUTOURLDETECT
mov eax, [edx.ENLINK.msg]
.if eax==WM_LBUTTONDOWN
mb chr$("Congrats"), chr$("A Link!"), MB_OK
.endif
.elseif eax==EN_PROTECTED
mov eax, [edx.ENLINK.msg]
.if eax!=769 && eax!=1092 ; copy & formatting
mb addr allowCpt, pApp,
MB_YESNO or MB_DEFBUTTON2
.if eax==IDNO
dec tmp ; don't allow
.endif
.endif
Quote
Or may be there is another way for adding bookmarks?
Thank you
You can embed pointers to them as hidden text. That's how I handle it in RichMasm (attached). However, I have chosen to use the RichEdit features fully, for highlighting specific problems in the code etc.; that implies that I have to export a plain text file for assembling my code. There are pros and cons...
[attachment deleted by admin]
Thank you very much.
I hoped to find any magic solution :wink, but to all appearances there is no way - just catch message by message. WM_KEYDOWN and EN_UPDATE work pretty good, but I still doubt about cutting/pasting.
Quote from: lamer on August 14, 2008, 05:49:57 PM
I hoped to find any magic solution :wink, but to all appearances there is no way
Try WM_NOTIFY. It looks complicated, but it works. I catch attempts to change text
before they happen, EDIT: but the text has to be protected in order to get the notification
before the change. An ugly workaround but I don't see another option, except maybe catching a WM_CHAR message.
Why do you think it's ugly? I completely forgot about EN_PROTECTED - but that's IMHO exactly the magic solution :clap:
Glad you liked it - but imho M$ could have provided a proper notification... RichEdit is a very, very messy control.