blob: ec5c4f160f78afd0743b1b477d225079793b18df [file] [log] [blame]
Alexandre Julliard889f7421997-04-15 17:19:52 +00001/*
2 * Outdated !!!
3 *
4 * The edit control is under reconstruction
5 * New documentation will be provided when I'm done
6 *
7 * Please contact me before you send in bug fixes, as the code
8 * might have changed already. However, keep reporting those
9 * bugs ... I might not know about them, yet.
10 *
11 * Frans van Dorsselaer
12 * dorssel@MolPhys.LeidenUniv.nl
13 */
Alexandre Julliard329f0681996-04-14 13:21:20 +000014This file gives some information about the code in edit.c. If you want to
15change, add, or fix code, please read this text. If you're not interested
16in doing actual work on edit.c only C & D will be of interest to you.
Alexandre Julliard22945d51995-03-02 17:44:29 +000017
Alexandre Julliard329f0681996-04-14 13:21:20 +000018A) basic policy
19B) special functions
Alexandre Julliardc6c09441997-01-12 18:32:19 +000020C) not implemented / implementation ideas / implementation problems
21D) known bugs / features
Alexandre Julliard22945d51995-03-02 17:44:29 +000022
Alexandre Julliard329f0681996-04-14 13:21:20 +000023A) Basic Policy
Alexandre Julliard22945d51995-03-02 17:44:29 +000024
Alexandre Julliardc6c09441997-01-12 18:32:19 +000025All messages are handled by EditWndProc(), which is the only external
26function call. All other functions are static (local to edit.c).
27
28All Windows Messages (WM_XXX) are 32-bit, since the edit control is now a
2932-bit registered class. The message are dealt with through the helper
30functions EDIT_WM_XXX().
31
32The edit control messages can be either 16 or 32 bit, depending on the type
33of application that sends the message. Wherever possible EditWndProc()
34converts the 16-bit message parameters to parameters corresponding to their
3532-bit counterparts. The message is then handled by the appropriate
36EDIT_EM_XXX() helper function. Sometimes it is not possible to handle the
3716-bit and 32-bit versions in the same way, in which case both helper
38functions EDIT_EM_XXX16() and EDIT_EM_XXX() are defined.
39
40All other functions are called EDIT_XXX().
41
42Note: Sometimes a function is internally used a bit different than the specs
43of a similar function. For instance EDIT_SetSel() is used internally and
44should not be mixed up with EDIT_EM_SetSel(), a message handler that _does_
45conform to the specs of EM_SETSEL.
46
Alexandre Julliard329f0681996-04-14 13:21:20 +000047The code has been made in such a way, that functions try to call other
48(documented) functions if that is sufficient. This might sometimes not be
Alexandre Julliardc6c09441997-01-12 18:32:19 +000049the most efficient way, but it keeps the code clear. This way I tried to
50keep the number of functions that rely on the internal EDITSTATE structure
51as low as possible. For instance EDIT_WM_Cut() simply calls EDIT_WM_Copy()
52and EDIT_WM_Clear(). The latter two are well documented message handlers,
53so as long as they are right EDIT_WM_Cut() will never have to change again.
Alexandre Julliard22945d51995-03-02 17:44:29 +000054
Alexandre Julliard329f0681996-04-14 13:21:20 +000055Example:
56The best thing to do, when you want to know the offset of line 3, is calling
Alexandre Julliardc6c09441997-01-12 18:32:19 +000057EDIT_EM_LineIndex(). Again this is a well documented message handler.
58Don't look at es->LineDefs[2].offset. It would just be another reference to
59the internal structure, and that would make it more difficult to change
60things. Refer to EDIT_WM_???? and EDIT_EM_????? functions as much as
61possible.
Alexandre Julliard22945d51995-03-02 17:44:29 +000062
Alexandre Julliard329f0681996-04-14 13:21:20 +000063The WND * pointer is used internally whenever possible. Although it is not
64the real HWND, it improves performance enough to use it.
Alexandre Julliard22945d51995-03-02 17:44:29 +000065
Alexandre Julliard329f0681996-04-14 13:21:20 +000066All displaying is done by invalidating regions / rects. Only
67EDIT_EM_LineScroll() uses direct painting. This way things become much
68faster. Although sometimes the response time might appear to be slow, it
69would be much slower even, when everything would be painted instantly. This
70is especially true for scrollbar tracking and selection changes..
Alexandre Julliard22945d51995-03-02 17:44:29 +000071
Alexandre Julliardc6c09441997-01-12 18:32:19 +000072The text buffer is a kind of tricky. Initially the edit control allocates a
73HLOCAL32 buffer (32 bit linear memory handler). However, 16 bit application
74might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
75handler). From that moment on we have to keep using this 16 bit memory
76handler, because it is supposed to be valid at all times after EM_GETHANDLE.
77What we do is create a HLOCAL16 buffer, copy the text, and do pointer
78conversion.
79
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +000080
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +000081
Alexandre Julliard329f0681996-04-14 13:21:20 +000082B) Special functions
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +000083
Alexandre Julliardc6c09441997-01-12 18:32:19 +000084Several helper functions try to make your life easier when dealing with the
85allocated buffer. In principle Windows can move memory blocks around unless
86they are locked. Currently, WINE doesn't do this, but it might in the
87future.
88
89For this reason there is a nice EDIT_GetPointer() function, which locks the
90heap buffer *only once*, no matter how often it is called. It then returns a
91nice 32-bit pointer to linear memory. Calling EDIT_GetPointer() is very fast
92if the buffer is already locked, so you can call it whenever you feel it
93*might* be useful.
94
95At the end of EditWndProc(), EDIT_ReleasePointer() is automatically called
96which cleans up the initialized pointer. So you don't have to worry about
97unlocking the memory block. This way, the buffer gets locked / unlock only
98once every message, although EDIT_GetPointer() may actually have been called
99a hundred times. Only when the actual HLOCAL is needed (for example to
100ReAlloc), an extra call (besides the cleanup at the end of EditWndProc()) to
Alexandre Julliard329f0681996-04-14 13:21:20 +0000101EDIT_ReleasePointer() is needed. Look for instance in EDIT_MakeFit().
102
103This brings us to EDIT_MakeFit(). It automatically re-allocates the buffer
104if the size parameter > buffersize. If everything is successful TRUE is
105returned, otherwise FALSE. Only when the buffer contents may grow you need
106to call EDIT_MakeFit(). Currently this is only in EDIT_ReplaceSel() and
107EDIT_WM_SetText().
108
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000109EDIT_GetPointer(), EDIT_ReleasePointer and EDIT_MakeFit() are aware of the
110HLOCAL32 / HLOCAL16 business.
111
Alexandre Julliard329f0681996-04-14 13:21:20 +0000112EDIT_BuildLineDefs() is the most important function in edit.c. It builds
113the internal EDITSTATE structure. As soon as text *might* have changed, or
114when the appearance of the text on the screen *might* have changed, call
115this function ! This includes changes of screen size, change of the font,
116clipboard actions, etc. etc. Most other functions that rely on EDITSTATE,
117rely on the stuff this function builds.
118
119
120
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000121C) Not Implemented / Implementation Ideas / Implementation Problems
Alexandre Julliard329f0681996-04-14 13:21:20 +0000122
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000123Styles:
124
Alexandre Julliard329f0681996-04-14 13:21:20 +0000125- ES_CENTER
126- ES_RIGHT
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000127- ES_NUMBER (new since win95)
Alexandre Julliard329f0681996-04-14 13:21:20 +0000128- ES_OEMCONVERT
129- ES_WANTRETURN
Alexandre Julliard329f0681996-04-14 13:21:20 +0000130
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000131None of these should be difficult to include. I just didn't have the time
132yet. Feel free ...
133
134- ES_AUTOVSCROLL (every multi line control *is* auto vscroll)
135- ES_AUTOHSCROLL (every single line control *is* auto hscroll)
136 (for multi line controls it works : wordwrap)
137
138Much, much more difficult. It comes down to this: When there is no
139autoscrolling, the edit control should first check whether the new text
140(after a typed key for instance) would fit. If not, an EN_MAXTEXT should be
141sent. However, currently this would require the actual change to be made,
142then call EDIT_BuildLineDefs() and then find out that the new text doesn't
143fit. After all this, things should be put back in the state before the
144changes. Given the fact that even normal UNDO doesn't work ...
145
146Messages:
147
148- EM_SETRECT
149- EM_SETRECTNP
150- EM_SETMARGINS (new since win95)
151- EM_FMTLINES
152
153These shouldn't be really difficult either. They just confine the visual
154output to something different than the client rectangle. Currently the
155client area is used everywhere in the code. At some points this should
156really be so (GetClientRect32()), whereas at other points it should be the
157format rectangle (EDIT_EM_GetRect()). Both functions are now used, but
158inconsistently and mixed up ! If you implement the formatting rectangle /
159margins, be sure to check all references to RECT's, and how they are /
160should be obtained.
161
162- EM_FMTLINES
163
164This means: insert or remove the soft linebreak character (\r\r\n). Probably
165invented by MS to suit their implementation of the edit control. However,
166with WINE's implementation I've never come up with occasions where it is
167actually useful (we never insert \r\r\n, and applications always request
168removal). If you are a purist ... implementation shouldn't be difficult.
169Take care to check if the text still fits the buffer after insertion. If
170not, notify with EN_ERRSPACE.
171
172- WM_UNDO (=EM_UNDO)
173
174I'm working on it. It is, however, not trivial. Luckily the only function
175where actual text changes is EM_REPLACESEL, so this is the only spot where
176we have to worry about UNDO capabilities. Before you try: contact me. I
177already have ideas and might start implementing it myself really soon.
178
179- EM_SETWORDBREAKPROC
180
181Not really difficult. It used to work, but since we moved to 32 bits there
182are now two kinds of callback functions. And I don't know the 32-bit specs
183for the WordBreakProc() ... Look it up and uncomment the code that is still
184there for 16 bit callback.
185
186- EM_SCROLL
187
188Supposed to be the same as WM_VSCROLL, but not quite. In other words:
189poorly documented. Somebody that knows ?
Alexandre Julliard329f0681996-04-14 13:21:20 +0000190
191
192
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000193D) Known bugs / Features
Alexandre Julliard329f0681996-04-14 13:21:20 +0000194
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000195- The control still calls GetTabbedTextExtent() and TabbedTextOut() in
196 their 16 bit version (since the 32 bit versions don't yet exist).
197 Therefore the tab list is 16 bits (should be 32).
198- Scrollbar tracking is broken.
199- Lots of API calls are to 16 bit functions, because their 32 bit
200 versions haven't been implemented yet (e.g. clipboard).
201- Turning on WordWrap with 16-bit Notepad leaves part of the horizontal
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000202 scrollbar visible (problem with WM_ERASEBKGND ???).
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000203- FIXME's (grep for them).
Alexandre Julliard329f0681996-04-14 13:21:20 +0000204
205
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000206I am working on Undo capabilities. If you want to do things, other than bug
207fixes, please mail me so we can synchronize.
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +0000208
209Frans van Dorsselaer
210dorssel@rulhm1.LeidenUniv.nl