mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 13:13:00 +00:00

[RICHED20] Sync to Wine-10.0 Sync wine/rbtree.h to Wine-10.0 as changes in riched20 require this. Also added a define to allow directx code to compile. Sync riched20 to Wine-10.0 and its tests using the script. Signed-off-by: Francois Gouget <fgouget@free.fr> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 9f72c5601173728c52626342a1ec6c9a4c70670f by Francois Gouget <fgouget@free.fr> Update WINESYNC.txt Update precomp.h fix build [WINESYNC]: riched20 is now in sync with wine-staging wine-10.0 [WINESYNC] riched20: Only call ME_SendRequestResize when control is in-place active. Prevent GetClientRect from being called when not in-place active. wine commit id e61db557ab8473a490c84301dbb4b4665b6c9c9f by Charlotte Pabst <cpabst@codeweavers.com> [WINESYNC] riched20: Exit from editor_ensure_visible when control is not in-place active. According to microsoft documentation, ScrollWindowEx, SetScrollPos and SetScrollRange may only be called while the control is in-place active. This fixes a segmentation fault in an application. wine commit id dafaadcb4addd9af334433666a4bc2e7aa6eb9ff by Charlotte Pabst <cpabst@codeweavers.com> [WINESYNC] riched20/tests: Test that ScrollWindowEx and GetClientRect are only called when control is in-place active. wine commit id f1301cedbea51be107017bb8545956bcfd02b610 by Charlotte Pabst <cpabst@codeweavers.com> Update editor.c [WINESYNC] riched20: Release IME input context when done using it. wine commit id 3f51fb96c162e8d3314627b3db25564fa7d9d419 by Zhiyi Zhang <zzhang@codeweavers.com> [WINESYNC] riched20: In para_set_fmt protect against out of bound cTabStop values. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56730 wine commit id 7b2ff977739df25252d46552d2447af50c23040e by Fabian Maurer <dark.shadow4@web.de> Update editor.c [WINESYNC] riched20: Don't write past end of buffer. Signed-off-by: Eric Pouech <epouech@codeweavers.com> wine commit id 5cbe3a6cb186cffed20e3fea5f88abd0880d3914 by Eric Pouech <epouech@codeweavers.com> [WINESYNC] riched20: Don't crash when no OLE obj is present. This was generating a lot of crashes in riched20 tests. Signed-off-by: Eric Pouech <epouech@codeweavers.com> wine commit id 015aae30cf2217164f631d1c03abfc9ea63bb43d by Eric Pouech <epouech@codeweavers.com> Update editor.c [WINESYNC] riched20: Use CRT allocation functions. wine commit id 42579f1dcd2f14e765e2f53ceb5b46fff5623f10 by Alex Henrie <alexhenrie24@gmail.com> [WINESYNC] riched20/tests: Make the editor paste test failures more informative and unique. Knowing the content of the edit field is more useful than knowing the strcmp() result. The text field may contain carriage returns and linefeeds so use wine_dbgstr_a() so they are clearly visible in the failure message. Also prefix the ok messages with a unique string to indicate which test_WM_PASTE() test failed. wine commit id b8950d04e439f649f2167477a36ee453ad8b81ef by Francois Gouget <fgouget@codeweavers.com> [WINESYNC] riched20: Don't call wrap_marked_paras_dc() before the editor is fully initialized. Today, CreateTextServices() sometimes triggers an assertion failure in select_style(). When ME_MakeEditor() calls ME_MakeFirstParagraph(), the editor (ME_TextEditor) is not in a fully initialized state. For example, the font cache (pFontCache) is not fully initialized, which sometimes makes select_style() believe that the cache slots are fully occupied. Fix this by delaying the call to wrap_marked_paras_dc() until the editor is fully initialized. Also, delay the call to ITextHost::TxReleaseDC() until after wrap_marked_paras_dc(), since we need the device context a bit longer. Fixes: b70eb32c5f3e506181d9e1e9fbef62e9baf3674d wine commit id 548d7179e3b2b9961321a4df50644c9b3874a295 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Factor out device context acquisition from ME_MakeFirstParagraph. This lets ME_MakeEditor() reuse the device context throughout the editor initialization process. wine commit id 03036f42e1afa9c79246dcee6b9fe876286b1aa4 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Don't call ME_UpdateRepaint inside set_selection(). This partially reverts c5daf6a30f21 (riched20: Call ME_UpdateRepaint instead of editor_ensure_visible in set_selection.) Fixes: c5daf6a30f21acd20263692b278acba49e014cc1 wine commit id ac5110131493b8b05795e8825285e41ca40ab6f1 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Add tests for change notifications caused by EM_SETSEL{,EX}. wine commit id c35926e49825f7a3d48ba826085fe1ae3d2a7e27 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Wrap marked paragraphs at Text Services initialization. Today, CreateTextServices() returns an Rich Edit object without row start and end marks, which are expected to exist by many Rich Edit operations as well as EM_* message handlers. This leads to a crash when certain messages (e.g., EM_SCROLLCARET) are sent to the Rich Edit object via ITextServices::TxSendMessage(), unless ME_WrapMarkedParagraphs() has been called beforehand. Fix this by calling wrap_marked_paras_dc() early in the initialization process. This is not a problem for windowed Rich Edit controls, which already calls ME_WrapMarkedParagraphs() before the user or application starts interacting with it. wine commit id b70eb32c5f3e506181d9e1e9fbef62e9baf3674d by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Use nameless unions/structs. wine commit id 26826d3af8b1969de389f3d6702d7c8b805126e1 by Alexandre Julliard <julliard@winehq.org> Update editor.h [WINESYNC] riched20: Remove DECLSPEC_HIDDEN usage. wine commit id c04ab166498b5841ecde620a9bd0b74969b01596 by Alistair Leslie-Hughes <leslie_alistair@hotmail.com> [WINESYNC] riched20: Call ME_UpdateRepaint instead of editor_ensure_visible in set_selection. To prevent cases where ME_WrapMarkedParagraphs has not been called causing a NULL pointer when editor_ensure_visible tries to get the row from the cursor. wine commit id c5daf6a30f21acd20263692b278acba49e014cc1 by Santino Mazza <smazza@codeweavers.com> [WINESYNC] riched20: Update paragraph position in marked tree. nCharOfs is the key for paragraphs added to the marked tree If it is updated, re-add the entry to update its position wine commit id f1aa3f37ef326b7cbf8fc94e982c9f0b398181c4 by Daniel Lehman <dlehman25@gmail.com> Update editor.c [WINESYNC] riched20: Update the editor IME position on GCS_RESULTSTR. So that a GCS_RESULTSTR followed by GCS_COMPSTR, without interruping the composition, begins inserting the new composition text after the result instead of before it. wine commit id de45bc33a73eac5dbc3502b4a43cd48399507c73 by Rémi Bernon <rbernon@codeweavers.com> [WINESYNC] riched20/tests: Fix a typo in a comment. wine commit id 145e3c758b9594596835e291b2fcb3c80e4c0479 by Francois Gouget <fgouget@free.fr> [WINESYNC] riched20/tests: Don't specify DT_WORDBREAK in _check_txgetnaturalsize(). Today, test_TxGetNaturalSize() creates a pop-up window with a fixed size (extent) of 100 x 100. The test function then proceeds to compute the natural size of rich edit control that fits the sample text "TestSomeText" and compare it to the RECT calculated by DrawText. Apparently, this test fails if the width of the sample text "TestSomeText" exceeds the width of the test window's client area. In this case, DrawText() with DT_WORDBREAK breaks the text into the two lines due to text wrapping; however, Rich Edit's ITextServices::TxGetNaturalSize implementation does not seem to perform text wrapping on overflow. This results in extent mismatch. (Note that the test may either succeed or fail depending on the current font used for DEFAULT_GUI_FONT, which defaults to Tahoma according to Microsoft's documentation. To reproduce this failure, it may be necessary to switch fonts or change the width of the pop-up window.) Fix this by omitting the DT_WORDBREAK flag for the DrawText() call in _check_txgetnaturalsize(). Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54637 wine commit id f54a1dac64c89aea3fe02ae8c0d6eef43a0aa117 by Jinoh Kang <jinoh.kang.kr@gmail.com> Update editstr.h [WINESYNC] riched20: Implement ITextDocument::Freeze and ITextDocument::Unfreeze. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54617 wine commit id 3fe15349d39ccf31026a92eae30f83f65c91cb1f by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Don't assume that TxDraw preserves the device context's brush selection. Today, RichEditWndProc_common assumes that ITextServices::TxDraw preserves the brush selection of the given device context. However, this invariant may be broken by misbehaving embedded OLE objects in the text document. Fix this by not assuming that the return value of the second SelectObject() call equals the brush passed to the first SelectObject() call in RichEditWndProc_common's WM_PAINT / WM_PRINTCLIENT case. wine commit id 2027be7e0370c92595f126a0b0dd167a635d50a2 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Test for ITextDocument::Freeze and ITextDocument::Unfreeze. wine commit id 3105fad82b9bae390fcd710a2fc10a18988b4622 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Don't set para unless committing cursor move in ME_MoveCursorWords. Introduce a temporary variable, `other_para`, so that we don't end up returning incorrect para (with stale run) inside the output cursor. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54564 wine commit id 7e28fa5c558f1417f8f033cb843424778bbfb8b8 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Test for word movement across paragraph boundary. wine commit id 21d25b17c2cae8eb2d2376ce42b76e3f61eb0bba by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Fix the EM_GETSELTEXT tests in Hindi on Windows. On Windows EM_GETSELTEXT fails with an invalid parameter error in the Hindi locale but works in most other locales, including UTF-8 ones. So check for this issue and adjust the expected results accordingly. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54559 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54565 wine commit id 37cd13abdf5d91c7b3f25b39fa14976bc3a3e3a3 by Francois Gouget <fgouget@codeweavers.com> [WINESYNC] riched20/tests: EM_GETSELTEXT's wparam is not used and should be 0. wine commit id baa41970647a7e548701a72bea2e4aa2a61ca27e by Francois Gouget <fgouget@codeweavers.com> [WINESYNC] riched20/tests: Add context to the EM_FORMATRANGE tests. wine commit id 020145248371bbfd2e473e79ba873e8313dde72d by Francois Gouget <fgouget@codeweavers.com> [WINESYNC] riched20/tests: Check clipboard content after destroying the editor window. Destroying the editor window should render all the formats so they are still available after. wine commit id b5b5b0b365639b889a0240d4992e16174b428f75 by Francois Gouget <fgouget@codeweavers.com> [WINESYNC] riched20/tests: Add retry loop around OpenClipboard() to avoid access denial. Reusing existing helper from user32 & comctl32. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47888 Signed-off-by: Eric Pouech <eric.pouech@gmail.com> wine commit id 25743d46f4103c7345c955b87b4134a065fb5f1d by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20/tests: Ensure clipboard has been pasted before testing the result. The patch does reduce error failures locally. For the record: - WM_PASTE in undo operations haven't been transformed (as it requires UNDO stack manipulation in a coherent way across platforms) Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47888 Signed-off-by: Eric Pouech <eric.pouech@gmail.com> wine commit id 4fd5252f635817b431673accaba718c7481f48f6 by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20: Support SFF_SELECTION when streaming in plain text. Signed-off-by: Eric Pouech <eric.pouech@gmail.com> wine commit id 1b7a918bd7ec8bc2c51bcb76525b56b17c5ff0c0 by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20/tests: Add tests when pasting in plain text mode. Signed-off-by: Eric Pouech <eric.pouech@gmail.com> wine commit id 82fa1048b5cc7d9c6a2a289403f25adbdd8158c7 by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20: Obtain the composition start index after deleting selection. Today, the Rich Edit control handles the WM_IME_STARTCOMPOSITION message by the computing the composition start position (imeStartIndex) _before_ calling ME_DeleteSelection(), which shifts the character positions after the range of deletion. If the selection were not empty, imeStartIndex immediately becomes stale, since it does not take into account the number of deleted characters before it. Fix this by computing imeStartIndex after the ME_DeleteSelection() call. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54318 wine commit id 8c43577f0f9b4422d3641457c595c3998bd54a18 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Call GlobalReAlloc with GMEM_MOVEABLE flag. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53474 wine commit id dfd44bb979ee2052eceff094083147e9879fa807 by Rémi Bernon <rbernon@codeweavers.com> [WINESYNC] riched20: Fix failing test in UTF8 locales. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52875 Signed-off-by: Eric Pouech <eric.pouech@gmail.com> wine commit id 5902cfd2990261189ce9af27981a95ac12fa2a5d by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20: Don't emit EN_CHANGE events during window creation. wine commit id 5c997de8dc1e4885266fa884a2fb74f840e3bedc by Evan Tang <etang@codeweavers.com> [WINESYNC] riched20: Add test for EN_CHANGE events during window creation. GenoPro isn't very happy if it receives one wine commit id 0b069106b0e0f141d6925d3e10166be89fc59145 by Evan Tang <etang@codeweavers.com> [WINESYNC] riched20: Move test class creation to a helper function. wine commit id f9083961ed187777d660796f7136addc04fff8b0 by Evan Tang <etang@codeweavers.com> [WINESYNC] riched20/tests: Use ARRAY_SIZE instead of open coding it. wine commit id 90b6288f54afdc4430dac146779a92b89f4d1219 by Michael Stefaniuc <mstefani@winehq.org> [WINESYNC] riched20/test: Add scrolling test for richole. Signed-off-by: Santino Mazza <mazzasantino1206@gmail.com> wine commit id 059c70d736baa164a1b246e949acd006cf83ab5a by Santino Mazza <mazzasantino1206@gmail.com> [WINESYNC] riched20: Ensure that cursor is visible when selecting text. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=40444 Signed-off-by: Santino Mazza <mazzasantino1206@gmail.com> wine commit id 25209c162fc209124b369abbad55d915d31909b2 by Santino Mazza <mazzasantino1206@gmail.com> [WINESYNC] riched20/tests: When selection is out of view, the scrollbar should move. Signed-off-by: Santino Mazza <mazzasantino1206@gmail.com> wine commit id ee131e9eba7dad090f0baf4a73fab2d62dc73b52 by Santino Mazza <mazzasantino1206@gmail.com> [WINESYNC] riched20: Remove duplicate code. Signed-off-by: David Kahurani <k.kahurani@gmail.com> wine commit id 3588479e1a674e5f43f1acb9e7c0aa8cecf98f25 by David Kahurani <k.kahurani@gmail.com> [WINESYNC] riched20: Implement ITextDocument::Undo and ITextDocument::Redo. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53289 Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id ded8227774570a1ea320dc34f2de0033f85b3ce7 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Add undo control state variable to ME_TextEditor. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id 40c54854e61d8adfca21e2fa9260712e4f5453e9 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Factor out undo-ignored status check. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id 0cd86e010e41eebdc1a4c142f9cc6a4948554d0e by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Ensure MEPF_COMPLEX is unset when in password input mode. Otherwise, Wine may crash while attempting to fetch the script shaping information, which does not exist since shape_para() was not called. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53335 Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id f77f12ba3b1dad9ebdcb116c66b137e9103a0d1b by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Test for ITextDocument::Undo and ITextDocument::Redo. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id 73284ea18891a152dce989ffff59e2c527f94c73 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Commit and wrap paragraphs after changing text properties. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53170 Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id 0974f047b57357252ec94bea119e5291250a446c by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Draw OLE objects with IViewObject implementation. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52752 Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id ecc607c6da96a5c2e8988f3021e98b442fe24c12 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Fetch extent from object if REOBJECT::sizel is unset. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id 164897e6c94d3eee4798f82a730472a5a847f9b2 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Add tests for drawing embedded OLE objects. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> wine commit id a7d29d1625f7e02df4fbf59ef4e4a999d39edde0 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Fix the spelling of a comment. Signed-off-by: Francois Gouget <fgouget@free.fr> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id f9fa5f9e523b45766f715c6981c6a6ab5f183157 by Francois Gouget <fgouget@free.fr> [WINESYNC] riched20: Implement callback to IRichEditOleCallback_QueryInsertObject. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 10667b39aad6710668f60c1ba8f10e50aeb87242 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20/tests: Add tests for IRichEditOleCallback_QueryInsertObject. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 95b4072cc774ba7a7eabb0d4c114b933b7d71105 by Jinoh Kang <jinoh.kang.kr@gmail.com> Update richole.c [WINESYNC] riched20: Set REOBJECT's cp correctly in IRichEditOle::GetObject. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52705 Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 194ba06c403fd72fbfb95048385c9ca4838af169 by Jinoh Kang <jinoh.kang.kr@gmail.com> [WINESYNC] riched20: Add back-reference to outer ME_Run from struct re_object. Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 05796c4e2a4acb91e6035c536b4d0e1f7e16896d by Jinoh Kang <jinoh.kang.kr@gmail.com> fix [WINESYNC] riched20/tests: Enable compilation with long types. Signed-off-by: Eric Pouech <eric.pouech@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 9e90cecdc603d79c6332a03884ed8d4851ef2e88 by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20/tests: Use correct integral type. Signed-off-by: Eric Pouech <eric.pouech@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 8b66db027d4112bfd4287b03d5c7b6f33994adc3 by Eric Pouech <eric.pouech@gmail.com> fix build, sync rbtree.h [WINESYNC] riched20: Enable compilation with long types. Signed-off-by: Eric Pouech <eric.pouech@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 42d0e56643740a0eac5913a9f176e789457cb475 by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20/tests: Add a test to see what richedit class flavours should be available. Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id d54a0e2bea4548bb5d9c0cca9f918d7c46591e23 by Dmitry Timoshkov <dmitry@baikal.ru> [WINESYNC] riched20: Use correct integral type. Signed-off-by: Eric Pouech <eric.pouech@gmail.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 63a643f7f42ecd0c2625a5f5704b5b9647349e7b by Eric Pouech <eric.pouech@gmail.com> [WINESYNC] riched20/tests: Avoid "misleading indentation" warnings. Signed-off-by: Fabian Maurer <dark.shadow4@web.de> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 2d6fad7bda2f2e21a871f405a6b0c3e70ebf6a6a by Fabian Maurer <dark.shadow4@web.de> [WINESYNC] include: Remove the wine_ prefix on rbtree functions. Add defines for frequently-used functions. For compatibility with vkd3d. Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 3527230c461b6baba9c29e69b575ada85bdbbc43 by Alexandre Julliard <julliard@winehq.org> [WINESYNC] riched20: Defer releasing the host if inside a notify callback. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51521 Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 8138159f20d6453443861570689e0f14018051da by Huw Davies <huw@codeweavers.com> [WINESYNC] riched20: Return the nearest char pos if the coords are outside the format rect. For the two tests that remain todo_wine, the results differ between riched20 and msftedit, with Wine's implementation matching msftedit. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52041 Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 363508454d5f8f1fc5916bda47e6429756b7dc8f by Huw Davies <huw@codeweavers.com> [WINESYNC] riched20: Check font_cache in select_style() too. Signed-off-by: Serge Gautherie <winehq-git_serge_180711@gautherie.fr> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 177f808aa86e5442be1a0a92ddccc4904bf2e743 by Serge Gautherie <winehq-git_serge_180711@gautherie.fr> [WINESYNC] riched20: Use the standard va_list instead of __ms_va_list. Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 5b15bf33255bd373cbf26ec373d16a8234ec6b1c by Alexandre Julliard <julliard@winehq.org> [WINESYNC] riched20: Use regular allocation helpers for text services objects. Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 2064c206c0b67edb8524f572166b974ba9cbd6fe by Nikolay Sivov <nsivov@codeweavers.com> [WINESYNC] riched20: Remove New() allocation macro. Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 1d5c9defb19fca6cfb1107384fc2325d391726d6 by Nikolay Sivov <nsivov@codeweavers.com> [WINESYNC] riched20: Don't create custom heap. Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 8bff437e9d5e047e689d8b32f62995785c0cd48e by Dmitry Timoshkov <dmitry@baikal.ru> [WINESYNC] riched20/tests: Don't cast NULL. Signed-off-by: Michael Stefaniuc <mstefani@winehq.org> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id b701c3df99fbd6d4df7eaa11327bb11db95d8676 by Michael Stefaniuc <mstefani@winehq.org> [WINESYNC] riched20/tests: Add more tests for testing EM_GETTEXTEX with OLE objects. Signed-off-by: Jactry Zeng <jzeng@codeweavers.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 40988d6c3886d0f7a914c45ea68264bfc8540859 by Jactry Zeng <jzeng@codeweavers.com> Update richole.c [WINESYNC] riched20: Allow to insert OLE object at specified offset. Signed-off-by: Jactry Zeng <jzeng@codeweavers.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id 8c894382dde5b9da88b0e9f23a753d5e851a43d6 by Jactry Zeng <jzeng@codeweavers.com> Update richole.c [WINESYNC] riched20/tests: Lock hGlobal before use. Signed-off-by: Jactry Zeng <jzeng@codeweavers.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> wine commit id f9c8c95856ded333be35ff41ab40a246bfe345b6 by Jactry Zeng <jzeng@codeweavers.com> Co-authored-by: winesync <ros-dev@reactos.org>
1161 lines
36 KiB
C
1161 lines
36 KiB
C
/*
|
|
* RichEdit - Paragraph wrapping. Don't try to understand it. You've been
|
|
* warned !
|
|
*
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*/
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
/*
|
|
* Unsolved problems:
|
|
*
|
|
* - center and right align in WordPad omits all spaces at the start, we don't
|
|
* - objects/images are not handled yet
|
|
* - no tabs
|
|
*/
|
|
|
|
typedef struct tagME_WrapContext
|
|
{
|
|
ME_Style *style;
|
|
ME_Context *context;
|
|
int nLeftMargin, nRightMargin;
|
|
int nFirstMargin; /* Offset to first line's text, always to the text itself even if a para number is present */
|
|
int nParaNumOffset; /* Offset to the para number */
|
|
int nAvailWidth; /* Width avail for text to wrap into. Does not include any para number text */
|
|
int nRow;
|
|
POINT pt;
|
|
BOOL bOverflown, bWordWrap;
|
|
ME_Paragraph *para;
|
|
ME_Run *pRowStart;
|
|
ME_Run *pLastSplittableRun;
|
|
} ME_WrapContext;
|
|
|
|
static BOOL get_run_glyph_buffers( ME_Run *run )
|
|
{
|
|
free( run->glyphs );
|
|
run->glyphs = malloc( run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR) + sizeof(int) + sizeof(GOFFSET)) );
|
|
if (!run->glyphs) return FALSE;
|
|
|
|
run->vis_attrs = (SCRIPT_VISATTR*)((char*)run->glyphs + run->max_glyphs * sizeof(WORD));
|
|
run->advances = (int*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR)));
|
|
run->offsets = (GOFFSET*)((char*)run->glyphs + run->max_glyphs * (sizeof(WORD) + sizeof(SCRIPT_VISATTR) + sizeof(int)));
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static HRESULT shape_run( ME_Context *c, ME_Run *run )
|
|
{
|
|
HRESULT hr;
|
|
int i;
|
|
|
|
if (!run->glyphs)
|
|
{
|
|
run->max_glyphs = 1.5 * run->len + 16; /* This is suggested in the uniscribe documentation */
|
|
run->max_glyphs = (run->max_glyphs + 7) & ~7; /* Keep alignment simple */
|
|
get_run_glyph_buffers( run );
|
|
}
|
|
|
|
if (run->max_clusters < run->len)
|
|
{
|
|
free( run->clusters );
|
|
run->max_clusters = run->len * 2;
|
|
run->clusters = malloc( run->max_clusters * sizeof(WORD) );
|
|
}
|
|
|
|
select_style( c, run->style );
|
|
while (1)
|
|
{
|
|
hr = ScriptShape( c->hDC, &run->style->script_cache, get_text( run, 0 ), run->len, run->max_glyphs,
|
|
&run->script_analysis, run->glyphs, run->clusters, run->vis_attrs, &run->num_glyphs );
|
|
if (hr != E_OUTOFMEMORY) break;
|
|
if (run->max_glyphs > 10 * run->len) break; /* something has clearly gone wrong */
|
|
run->max_glyphs *= 2;
|
|
get_run_glyph_buffers( run );
|
|
}
|
|
|
|
if (SUCCEEDED(hr))
|
|
hr = ScriptPlace( c->hDC, &run->style->script_cache, run->glyphs, run->num_glyphs, run->vis_attrs,
|
|
&run->script_analysis, run->advances, run->offsets, NULL );
|
|
|
|
if (SUCCEEDED(hr))
|
|
{
|
|
for (i = 0, run->nWidth = 0; i < run->num_glyphs; i++)
|
|
run->nWidth += run->advances[i];
|
|
}
|
|
|
|
return hr;
|
|
}
|
|
|
|
/******************************************************************************
|
|
* calc_run_extent
|
|
*
|
|
* Updates the size of the run (fills width, ascent and descent). The height
|
|
* is calculated based on whole row's ascent and descent anyway, so no need
|
|
* to use it here.
|
|
*/
|
|
static void calc_run_extent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Run *run)
|
|
{
|
|
if (run->nFlags & MERF_HIDDEN) run->nWidth = 0;
|
|
else
|
|
{
|
|
SIZE size = ME_GetRunSizeCommon( c, para, run, run->len, startx, &run->nAscent, &run->nDescent );
|
|
run->nWidth = size.cx;
|
|
}
|
|
}
|
|
|
|
/******************************************************************************
|
|
* split_run_extents
|
|
*
|
|
* Splits a run into two in a given place. It also updates the screen position
|
|
* and size (extent) of the newly generated runs.
|
|
*/
|
|
static ME_Run *split_run_extents( ME_WrapContext *wc, ME_Run *run, int nVChar )
|
|
{
|
|
ME_TextEditor *editor = wc->context->editor;
|
|
ME_Run *run2;
|
|
ME_Cursor cursor = { wc->para, run, nVChar };
|
|
|
|
assert( run->nCharOfs != -1 );
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
TRACE("Before split: %s(%ld, %ld)\n", debugstr_run( run ),
|
|
run->pt.x, run->pt.y);
|
|
|
|
run_split( editor, &cursor );
|
|
|
|
run2 = cursor.run;
|
|
run2->script_analysis = run->script_analysis;
|
|
|
|
shape_run( wc->context, run );
|
|
shape_run( wc->context, run2 );
|
|
calc_run_extent(wc->context, wc->para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
|
|
|
|
run2->pt.x = run->pt.x + run->nWidth;
|
|
run2->pt.y = run->pt.y;
|
|
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
TRACE("After split: %s(%ld, %ld), %s(%ld, %ld)\n",
|
|
debugstr_run( run ), run->pt.x, run->pt.y,
|
|
debugstr_run( run2 ), run2->pt.x, run2->pt.y);
|
|
|
|
return cursor.run;
|
|
}
|
|
|
|
/******************************************************************************
|
|
* find_split_point
|
|
*
|
|
* Returns a character position to split inside the run given a run-relative
|
|
* pixel horizontal position. This version rounds left (ie. if the second
|
|
* character is at pixel position 8, then for cx=0..7 it returns 0).
|
|
*/
|
|
static int find_split_point( ME_Context *c, int cx, ME_Run *run )
|
|
{
|
|
if (!run->len || cx <= 0) return 0;
|
|
return ME_CharFromPointContext( c, cx, run, FALSE, FALSE );
|
|
}
|
|
|
|
static ME_Row *row_create( int height, int baseline, int width )
|
|
{
|
|
ME_DisplayItem *item = ME_MakeDI(diStartRow);
|
|
|
|
item->member.row.nHeight = height;
|
|
item->member.row.nBaseline = baseline;
|
|
item->member.row.nWidth = width;
|
|
return &item->member.row;
|
|
}
|
|
|
|
static void ME_BeginRow(ME_WrapContext *wc)
|
|
{
|
|
ME_Cell *cell;
|
|
|
|
wc->pRowStart = NULL;
|
|
wc->bOverflown = FALSE;
|
|
wc->pLastSplittableRun = NULL;
|
|
wc->bWordWrap = wc->context->editor->bWordWrap;
|
|
if (wc->para->nFlags & (MEPF_ROWSTART | MEPF_ROWEND))
|
|
{
|
|
wc->nAvailWidth = 0;
|
|
wc->bWordWrap = FALSE;
|
|
if (wc->para->nFlags & MEPF_ROWEND)
|
|
{
|
|
cell = table_row_end_cell( wc->para );
|
|
cell->nWidth = 0;
|
|
}
|
|
}
|
|
else if (para_cell( wc->para ))
|
|
{
|
|
int width;
|
|
|
|
cell = para_cell( wc->para );
|
|
width = cell->nRightBoundary;
|
|
if (cell_prev( cell )) width -= cell_prev( cell )->nRightBoundary;
|
|
else
|
|
{
|
|
int rowIndent = table_row_end( wc->para )->fmt.dxStartIndent;
|
|
width -= rowIndent;
|
|
}
|
|
cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0);
|
|
|
|
wc->nAvailWidth = cell->nWidth
|
|
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
|
|
wc->bWordWrap = TRUE;
|
|
}
|
|
else
|
|
wc->nAvailWidth = wc->context->nAvailWidth
|
|
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
|
|
|
|
wc->pt.x = wc->context->pt.x;
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
para_in_table( wc->para ))
|
|
/* Shift the text down because of the border. */
|
|
wc->pt.y++;
|
|
}
|
|
|
|
static void layout_row( ME_Run *start, ME_Run *last )
|
|
{
|
|
ME_Run *run;
|
|
int i, num_runs = 0;
|
|
int buf[16 * 5]; /* 5 arrays - 4 of int & 1 of BYTE, alloc space for 5 of ints */
|
|
int *vis_to_log = buf, *log_to_vis, *widths, *pos;
|
|
BYTE *levels;
|
|
BOOL found_black = FALSE;
|
|
|
|
for (run = last; run; run = run_prev( run ))
|
|
{
|
|
if (!found_black) found_black = !(run->nFlags & (MERF_WHITESPACE | MERF_ENDPARA));
|
|
if (found_black) num_runs++;
|
|
if (run == start) break;
|
|
}
|
|
|
|
TRACE("%d runs\n", num_runs);
|
|
if (!num_runs) return;
|
|
|
|
if (num_runs > ARRAY_SIZE( buf ) / 5)
|
|
vis_to_log = malloc( num_runs * sizeof(int) * 5 );
|
|
|
|
log_to_vis = vis_to_log + num_runs;
|
|
widths = vis_to_log + 2 * num_runs;
|
|
pos = vis_to_log + 3 * num_runs;
|
|
levels = (BYTE*)(vis_to_log + 4 * num_runs);
|
|
|
|
for (i = 0, run = start; i < num_runs; run = run_next( run ))
|
|
{
|
|
levels[i] = run->script_analysis.s.uBidiLevel;
|
|
widths[i] = run->nWidth;
|
|
TRACE( "%d: level %d width %d\n", i, levels[i], widths[i] );
|
|
i++;
|
|
}
|
|
|
|
ScriptLayout( num_runs, levels, vis_to_log, log_to_vis );
|
|
|
|
pos[0] = run->para->pt.x;
|
|
for (i = 1; i < num_runs; i++)
|
|
pos[i] = pos[i - 1] + widths[ vis_to_log[ i - 1 ] ];
|
|
|
|
for (i = 0, run = start; i < num_runs; run = run_next( run ))
|
|
{
|
|
run->pt.x = pos[ log_to_vis[ i ] ];
|
|
TRACE( "%d: x = %ld\n", i, run->pt.x );
|
|
i++;
|
|
}
|
|
|
|
if (vis_to_log != buf) free( vis_to_log );
|
|
}
|
|
|
|
static void ME_InsertRowStart( ME_WrapContext *wc, ME_Run *last )
|
|
{
|
|
ME_Run *run;
|
|
ME_Row *row;
|
|
BOOL bSkippingSpaces = TRUE;
|
|
int ascent = 0, descent = 0, width = 0, shift = 0, align = 0;
|
|
|
|
/* Include height of para numbering label */
|
|
if (wc->nRow == 0 && wc->para->fmt.wNumbering)
|
|
{
|
|
ascent = wc->para->para_num.style->tm.tmAscent;
|
|
descent = wc->para->para_num.style->tm.tmDescent;
|
|
}
|
|
|
|
for (run = last; run; run = run_prev( run ))
|
|
{
|
|
/* ENDPARA run shouldn't affect row height, except if it's the only run in the paragraph */
|
|
if (run == wc->pRowStart || !(run->nFlags & MERF_ENDPARA))
|
|
{
|
|
if (run->nAscent > ascent) ascent = run->nAscent;
|
|
if (run->nDescent > descent) descent = run->nDescent;
|
|
if (bSkippingSpaces)
|
|
{
|
|
/* Exclude space characters from run width.
|
|
* Other whitespace or delimiters are not treated this way. */
|
|
int len = run->len;
|
|
WCHAR *text = get_text( run, len - 1 );
|
|
|
|
assert(len);
|
|
if (~run->nFlags & MERF_GRAPHICS)
|
|
while (len && *(text--) == ' ') len--;
|
|
if (len)
|
|
{
|
|
if (len == run->len)
|
|
width += run->nWidth;
|
|
else
|
|
width += ME_PointFromCharContext( wc->context, run, len, FALSE );
|
|
}
|
|
bSkippingSpaces = !len;
|
|
}
|
|
else if (!(run->nFlags & MERF_ENDPARA))
|
|
width += run->nWidth;
|
|
}
|
|
if (run == wc->pRowStart) break;
|
|
}
|
|
|
|
wc->para->nWidth = max( wc->para->nWidth, width );
|
|
row = row_create( ascent + descent, ascent, width );
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
(wc->para->fmt.dwMask & PFM_TABLE) && (wc->para->fmt.wEffects & PFE_TABLE))
|
|
{
|
|
/* The text was shifted down in ME_BeginRow so move the wrap context
|
|
* back to where it should be. */
|
|
wc->pt.y--;
|
|
/* The height of the row is increased by the borders. */
|
|
row->nHeight += 2;
|
|
}
|
|
row->pt = wc->pt;
|
|
row->nLMargin = (!wc->nRow ? wc->nFirstMargin : wc->nLeftMargin);
|
|
row->nRMargin = wc->nRightMargin;
|
|
assert(wc->para->fmt.dwMask & PFM_ALIGNMENT);
|
|
align = wc->para->fmt.wAlignment;
|
|
if (align == PFA_CENTER) shift = max((wc->nAvailWidth-width)/2, 0);
|
|
if (align == PFA_RIGHT) shift = max(wc->nAvailWidth-width, 0);
|
|
|
|
if (wc->para->nFlags & MEPF_COMPLEX) layout_row( wc->pRowStart, last );
|
|
|
|
row->pt.x = row->nLMargin + shift;
|
|
|
|
for (run = wc->pRowStart; run; run = run_next( run ))
|
|
{
|
|
run->pt.x += row->nLMargin + shift;
|
|
if (run == last) break;
|
|
}
|
|
|
|
if (wc->nRow == 0 && wc->para->fmt.wNumbering)
|
|
{
|
|
wc->para->para_num.pt.x = wc->nParaNumOffset + shift;
|
|
wc->para->para_num.pt.y = wc->pt.y + row->nBaseline;
|
|
}
|
|
|
|
ME_InsertBefore( run_get_di( wc->pRowStart ), row_get_di( row ) );
|
|
wc->nRow++;
|
|
wc->pt.y += row->nHeight;
|
|
ME_BeginRow( wc );
|
|
}
|
|
|
|
static void ME_WrapEndParagraph( ME_WrapContext *wc )
|
|
{
|
|
if (wc->pRowStart) ME_InsertRowStart( wc, wc->para->eop_run );
|
|
|
|
if (wc->context->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
wc->para->fmt.dwMask & PFM_TABLE && wc->para->fmt.wEffects & PFE_TABLE)
|
|
{
|
|
/* ME_BeginRow was called an extra time for the paragraph, and it shifts the
|
|
* text down by one pixel for the border, so fix up the wrap context. */
|
|
wc->pt.y--;
|
|
}
|
|
}
|
|
|
|
static void ME_WrapSizeRun( ME_WrapContext *wc, ME_Run *run )
|
|
{
|
|
/* FIXME compose style (out of character and paragraph styles) here */
|
|
|
|
ME_UpdateRunFlags( wc->context->editor, run );
|
|
|
|
calc_run_extent( wc->context, wc->para,
|
|
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run );
|
|
}
|
|
|
|
|
|
static int find_non_whitespace(const WCHAR *s, int len, int start)
|
|
{
|
|
int i;
|
|
for (i = start; i < len && ME_IsWSpace( s[i] ); i++)
|
|
;
|
|
|
|
return i;
|
|
}
|
|
|
|
/* note: these two really return the first matching offset (starting from EOS)+1
|
|
* in other words, an offset of the first trailing white/black */
|
|
|
|
/* note: returns offset of the first trailing whitespace */
|
|
static int reverse_find_non_whitespace(const WCHAR *s, int start)
|
|
{
|
|
int i;
|
|
for (i = start; i > 0 && ME_IsWSpace( s[i - 1] ); i--)
|
|
;
|
|
|
|
return i;
|
|
}
|
|
|
|
/* note: returns offset of the first trailing nonwhitespace */
|
|
static int reverse_find_whitespace(const WCHAR *s, int start)
|
|
{
|
|
int i;
|
|
for (i = start; i > 0 && !ME_IsWSpace( s[i - 1] ); i--)
|
|
;
|
|
|
|
return i;
|
|
}
|
|
|
|
static ME_Run *ME_MaximizeSplit( ME_WrapContext *wc, ME_Run *run, int i )
|
|
{
|
|
ME_Run *new_run, *iter = run;
|
|
int j;
|
|
if (!i)
|
|
return NULL;
|
|
j = reverse_find_non_whitespace( get_text( run, 0 ), i );
|
|
if (j > 0)
|
|
{
|
|
new_run = split_run_extents( wc, iter, j );
|
|
wc->pt.x += iter->nWidth;
|
|
return new_run;
|
|
}
|
|
else
|
|
{
|
|
new_run = iter;
|
|
/* omit all spaces before split point */
|
|
while (iter != wc->pRowStart)
|
|
{
|
|
iter = run_prev( iter );
|
|
if (iter->nFlags & MERF_WHITESPACE)
|
|
{
|
|
new_run = iter;
|
|
continue;
|
|
}
|
|
if (iter->nFlags & MERF_ENDWHITE)
|
|
{
|
|
i = reverse_find_non_whitespace( get_text( iter, 0 ), iter->len );
|
|
new_run = split_run_extents( wc, iter, i );
|
|
wc->pt = new_run->pt;
|
|
return new_run;
|
|
}
|
|
/* this run is the end of spaces, so the run edge is a good point to split */
|
|
wc->pt = new_run->pt;
|
|
wc->bOverflown = TRUE;
|
|
TRACE( "Split point is: %s|%s\n", debugstr_run( iter ), debugstr_run( new_run ) );
|
|
return new_run;
|
|
}
|
|
wc->pt = iter->pt;
|
|
return iter;
|
|
}
|
|
}
|
|
|
|
static ME_Run *ME_SplitByBacktracking( ME_WrapContext *wc, ME_Run *run, int loc )
|
|
{
|
|
ME_Run *new_run;
|
|
int i, idesp, len;
|
|
|
|
idesp = i = find_split_point( wc->context, loc, run );
|
|
len = run->len;
|
|
assert( len > 0 );
|
|
assert( i < len );
|
|
if (i)
|
|
{
|
|
/* don't split words */
|
|
i = reverse_find_whitespace( get_text( run, 0 ), i );
|
|
new_run = ME_MaximizeSplit(wc, run, i);
|
|
if (new_run) return new_run;
|
|
}
|
|
TRACE("Must backtrack to split at: %s\n", debugstr_run( run ));
|
|
if (wc->pLastSplittableRun)
|
|
{
|
|
if (wc->pLastSplittableRun->nFlags & (MERF_GRAPHICS|MERF_TAB))
|
|
{
|
|
wc->pt = wc->pLastSplittableRun->pt;
|
|
return wc->pLastSplittableRun;
|
|
}
|
|
else if (wc->pLastSplittableRun->nFlags & MERF_SPLITTABLE)
|
|
{
|
|
/* the following two lines are just to check if we forgot to call UpdateRunFlags earlier,
|
|
they serve no other purpose */
|
|
ME_UpdateRunFlags(wc->context->editor, run);
|
|
assert((wc->pLastSplittableRun->nFlags & MERF_SPLITTABLE));
|
|
|
|
run = wc->pLastSplittableRun;
|
|
len = run->len;
|
|
/* don't split words */
|
|
i = reverse_find_whitespace( get_text( run, 0 ), len );
|
|
if (i == len)
|
|
i = reverse_find_non_whitespace( get_text( run, 0 ), len );
|
|
new_run = split_run_extents(wc, run, i);
|
|
wc->pt = new_run->pt;
|
|
return new_run;
|
|
}
|
|
else
|
|
{
|
|
/* restart from the first run beginning with spaces */
|
|
wc->pt = wc->pLastSplittableRun->pt;
|
|
return wc->pLastSplittableRun;
|
|
}
|
|
}
|
|
TRACE("Backtracking failed, trying desperate: %s\n", debugstr_run( run ));
|
|
/* OK, no better idea, so assume we MAY split words if we can split at all*/
|
|
if (idesp)
|
|
return split_run_extents(wc, run, idesp);
|
|
else
|
|
if (wc->pRowStart && run != wc->pRowStart)
|
|
{
|
|
/* don't need to break current run, because it's possible to split
|
|
before this run */
|
|
wc->bOverflown = TRUE;
|
|
return run;
|
|
}
|
|
else
|
|
{
|
|
/* split point inside first character - no choice but split after that char */
|
|
if (len != 1)
|
|
/* the run is more than 1 char, so we may split */
|
|
return split_run_extents( wc, run, 1 );
|
|
|
|
/* the run is one char, can't split it */
|
|
return run;
|
|
}
|
|
}
|
|
|
|
static ME_Run *ME_WrapHandleRun( ME_WrapContext *wc, ME_Run *run )
|
|
{
|
|
ME_Run *new_run;
|
|
int len;
|
|
|
|
if (!wc->pRowStart) wc->pRowStart = run;
|
|
run->pt.x = wc->pt.x;
|
|
run->pt.y = wc->pt.y;
|
|
ME_WrapSizeRun( wc, run );
|
|
len = run->len;
|
|
|
|
if (wc->bOverflown) /* just skipping final whitespaces */
|
|
{
|
|
/* End paragraph run can't overflow to the next line by itself. */
|
|
if (run->nFlags & MERF_ENDPARA) return run_next( run );
|
|
|
|
if (run->nFlags & MERF_WHITESPACE)
|
|
{
|
|
wc->pt.x += run->nWidth;
|
|
/* skip runs consisting of only whitespaces */
|
|
return run_next( run );
|
|
}
|
|
|
|
if (run->nFlags & MERF_STARTWHITE)
|
|
{
|
|
/* try to split the run at the first non-white char */
|
|
int black;
|
|
black = find_non_whitespace( get_text( run, 0 ), run->len, 0 );
|
|
if (black)
|
|
{
|
|
ME_Run *new_run;
|
|
wc->bOverflown = FALSE;
|
|
new_run = split_run_extents( wc, run, black );
|
|
calc_run_extent( wc->context, wc->para,
|
|
wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run );
|
|
ME_InsertRowStart( wc, run );
|
|
return new_run;
|
|
}
|
|
}
|
|
/* black run: the row goes from pRowStart to the previous run */
|
|
ME_InsertRowStart( wc, run_prev( run ) );
|
|
return run;
|
|
}
|
|
/* simply end the current row and move on to next one */
|
|
if (run->nFlags & MERF_ENDROW)
|
|
{
|
|
ME_InsertRowStart( wc, run );
|
|
return run_next( run );
|
|
}
|
|
|
|
/* will current run fit? */
|
|
if (wc->bWordWrap &&
|
|
wc->pt.x + run->nWidth - wc->context->pt.x > wc->nAvailWidth)
|
|
{
|
|
int loc = wc->context->pt.x + wc->nAvailWidth - wc->pt.x;
|
|
/* total white run or end para */
|
|
if (run->nFlags & (MERF_WHITESPACE | MERF_ENDPARA)) {
|
|
/* let the overflow logic handle it */
|
|
wc->bOverflown = TRUE;
|
|
return run;
|
|
}
|
|
/* TAB: we can split before */
|
|
if (run->nFlags & MERF_TAB) {
|
|
wc->bOverflown = TRUE;
|
|
if (wc->pRowStart == run)
|
|
/* Don't split before the start of the run, or we will get an
|
|
* endless loop. */
|
|
return run_next( run );
|
|
else
|
|
return run;
|
|
}
|
|
/* graphics: we can split before, if run's width is smaller than row's width */
|
|
if ((run->nFlags & MERF_GRAPHICS) && run->nWidth <= wc->nAvailWidth) {
|
|
wc->bOverflown = TRUE;
|
|
return run;
|
|
}
|
|
/* can we separate out the last spaces ? (to use overflow logic later) */
|
|
if (run->nFlags & MERF_ENDWHITE)
|
|
{
|
|
/* we aren't sure if it's *really* necessary, it's a good start however */
|
|
int black = reverse_find_non_whitespace( get_text( run, 0 ), len );
|
|
split_run_extents( wc, run, black );
|
|
/* handle both parts again */
|
|
return run;
|
|
}
|
|
/* determine the split point by backtracking */
|
|
new_run = ME_SplitByBacktracking( wc, run, loc );
|
|
if (new_run == wc->pRowStart)
|
|
{
|
|
if (run->nFlags & MERF_STARTWHITE)
|
|
{
|
|
/* We had only spaces so far, so we must be on the first line of the
|
|
* paragraph (or the first line after MERF_ENDROW forced the line
|
|
* break within the paragraph), since no other lines of the paragraph
|
|
* start with spaces. */
|
|
|
|
/* The lines will only contain spaces, and the rest of the run will
|
|
* overflow onto the next line. */
|
|
wc->bOverflown = TRUE;
|
|
return run;
|
|
}
|
|
/* Couldn't split the first run, possible because we have a large font
|
|
* with a single character that caused an overflow.
|
|
*/
|
|
wc->pt.x += run->nWidth;
|
|
return run_next( run );
|
|
}
|
|
if (run != new_run) /* found a suitable split point */
|
|
{
|
|
wc->bOverflown = TRUE;
|
|
return new_run;
|
|
}
|
|
/* we detected that it's best to split on start of this run */
|
|
if (wc->bOverflown)
|
|
return new_run;
|
|
ERR("failure!\n");
|
|
/* not found anything - writing over margins is the only option left */
|
|
}
|
|
if ((run->nFlags & (MERF_SPLITTABLE | MERF_STARTWHITE))
|
|
|| ((run->nFlags & (MERF_GRAPHICS|MERF_TAB)) && (run != wc->pRowStart)))
|
|
{
|
|
wc->pLastSplittableRun = run;
|
|
}
|
|
wc->pt.x += run->nWidth;
|
|
return run_next( run );
|
|
}
|
|
|
|
static int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
|
|
{
|
|
int sp = 0, ls = 0;
|
|
if (!(para->fmt.dwMask & PFM_LINESPACING)) return 0;
|
|
|
|
/* FIXME: how to compute simply the line space in ls ??? */
|
|
/* FIXME: does line spacing include the line itself ??? */
|
|
switch (para->fmt.bLineSpacingRule)
|
|
{
|
|
case 0: sp = ls; break;
|
|
case 1: sp = (3 * ls) / 2; break;
|
|
case 2: sp = 2 * ls; break;
|
|
case 3: sp = ME_twips2pointsY(c, para->fmt.dyLineSpacing); if (sp < ls) sp = ls; break;
|
|
case 4: sp = ME_twips2pointsY(c, para->fmt.dyLineSpacing); break;
|
|
case 5: sp = para->fmt.dyLineSpacing / 20; break;
|
|
default: FIXME("Unsupported spacing rule value %d\n", para->fmt.bLineSpacingRule);
|
|
}
|
|
if (c->editor->nZoomNumerator == 0)
|
|
return sp;
|
|
else
|
|
return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
|
|
}
|
|
|
|
static void ME_PrepareParagraphForWrapping( ME_TextEditor *editor, ME_Context *c, ME_Paragraph *para )
|
|
{
|
|
ME_DisplayItem *p;
|
|
|
|
para->nWidth = 0;
|
|
/* remove row start items as they will be reinserted by the
|
|
* paragraph wrapper anyway */
|
|
editor->total_rows -= para->nRows;
|
|
para->nRows = 0;
|
|
for (p = para_get_di( para ); p != para->next_para; p = p->next)
|
|
{
|
|
if (p->type == diStartRow)
|
|
{
|
|
ME_DisplayItem *pRow = p;
|
|
p = p->prev;
|
|
ME_Remove( pRow );
|
|
ME_DestroyDisplayItem( pRow );
|
|
}
|
|
}
|
|
|
|
/* join runs that can be joined */
|
|
for (p = para_get_di( para )->next; p != para->next_para; p = p->next)
|
|
{
|
|
assert(p->type != diStartRow); /* should have been deleted above */
|
|
if (p->type == diRun)
|
|
{
|
|
while (p->next->type == diRun && ME_CanJoinRuns( &p->member.run, &p->next->member.run ))
|
|
run_join( c->editor, &p->member.run );
|
|
}
|
|
}
|
|
}
|
|
|
|
static HRESULT itemize_para( ME_Context *c, ME_Paragraph *para )
|
|
{
|
|
ME_Run *run;
|
|
SCRIPT_ITEM buf[16], *items = buf;
|
|
int items_passed = ARRAY_SIZE( buf ), num_items, cur_item;
|
|
SCRIPT_CONTROL control = { LANG_USER_DEFAULT, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
|
|
FALSE, FALSE, 0 };
|
|
SCRIPT_STATE state = { 0, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0 };
|
|
HRESULT hr;
|
|
|
|
if (para->fmt.dwMask & PFM_RTLPARA && para->fmt.wEffects & PFE_RTLPARA)
|
|
state.uBidiLevel = 1;
|
|
|
|
TRACE( "Base embedding level %d\n", state.uBidiLevel );
|
|
|
|
while (1)
|
|
{
|
|
hr = ScriptItemize( para->text->szData, para->text->nLen, items_passed, &control,
|
|
&state, items, &num_items );
|
|
if (hr != E_OUTOFMEMORY) break; /* may not be enough items if hr == E_OUTOFMEMORY */
|
|
if (items_passed > para->text->nLen + 1) break; /* something else has gone wrong */
|
|
items_passed *= 2;
|
|
if (items == buf)
|
|
items = malloc( items_passed * sizeof( *items ) );
|
|
else
|
|
items = realloc( items, items_passed * sizeof( *items ) );
|
|
if (!items) break;
|
|
}
|
|
if (FAILED( hr )) goto end;
|
|
|
|
if (TRACE_ON( richedit ))
|
|
{
|
|
TRACE( "got items:\n" );
|
|
for (cur_item = 0; cur_item < num_items; cur_item++)
|
|
{
|
|
TRACE( "\t%d - %d RTL %d bidi level %d\n", items[cur_item].iCharPos, items[cur_item+1].iCharPos - 1,
|
|
items[cur_item].a.fRTL, items[cur_item].a.s.uBidiLevel );
|
|
}
|
|
|
|
TRACE( "before splitting runs into ranges\n" );
|
|
for (run = para_first_run( para ); run; run = run_next( run ))
|
|
TRACE( "\t%d: %s\n", run->nCharOfs, debugstr_run( run ) );
|
|
}
|
|
|
|
/* split runs into ranges at item boundaries */
|
|
for (run = para_first_run( para ), cur_item = 0; run; run = run_next( run ))
|
|
{
|
|
if (run->nCharOfs == items[cur_item+1].iCharPos) cur_item++;
|
|
|
|
items[cur_item].a.fLogicalOrder = TRUE;
|
|
run->script_analysis = items[cur_item].a;
|
|
|
|
if (run->nFlags & MERF_ENDPARA) break; /* don't split eop runs */
|
|
|
|
if (run->nCharOfs + run->len > items[cur_item+1].iCharPos)
|
|
{
|
|
ME_Cursor cursor = { para, run, items[cur_item + 1].iCharPos - run->nCharOfs };
|
|
run_split( c->editor, &cursor );
|
|
}
|
|
}
|
|
|
|
if (TRACE_ON( richedit ))
|
|
{
|
|
TRACE( "after splitting into ranges\n" );
|
|
for (run = para_first_run( para ); run; run = run_next( run ))
|
|
TRACE( "\t%d: %s\n", run->nCharOfs, debugstr_run( run ) );
|
|
}
|
|
|
|
para->nFlags |= MEPF_COMPLEX;
|
|
|
|
end:
|
|
if (items != buf) free( items );
|
|
return hr;
|
|
}
|
|
|
|
|
|
static HRESULT shape_para( ME_Context *c, ME_Paragraph *para )
|
|
{
|
|
ME_Run *run;
|
|
HRESULT hr;
|
|
|
|
for (run = para_first_run( para ); run; run = run_next( run ))
|
|
{
|
|
hr = shape_run( c, run );
|
|
if (FAILED( hr ))
|
|
{
|
|
para->nFlags &= ~MEPF_COMPLEX;
|
|
return hr;
|
|
}
|
|
}
|
|
return hr;
|
|
}
|
|
|
|
static void ME_WrapTextParagraph( ME_TextEditor *editor, ME_Context *c, ME_Paragraph *para )
|
|
{
|
|
ME_Run *run;
|
|
ME_WrapContext wc;
|
|
int border = 0;
|
|
int linespace = 0;
|
|
|
|
if (!(para->nFlags & MEPF_REWRAP)) return;
|
|
|
|
ME_PrepareParagraphForWrapping( editor, c, para );
|
|
|
|
/* Calculate paragraph numbering label */
|
|
para_num_init( c, para );
|
|
|
|
/* For now treating all non-password text as complex for better testing */
|
|
if (!c->editor->password_char /* &&
|
|
ScriptIsComplex( tp->member.para.text->szData, tp->member.para.text->nLen, SIC_COMPLEX ) == S_OK */)
|
|
{
|
|
if (SUCCEEDED( itemize_para( c, para ) ))
|
|
shape_para( c, para );
|
|
}
|
|
else
|
|
{
|
|
/* If the user has just converted a normal rich editor with already
|
|
* existing text into a password input, the text may contain paragraphs
|
|
* with MEPF_COMPLEX set. Since we don't really shape any paragraphs
|
|
* here, we need to ensure that the MEPF_COMPLEX flag is unset.
|
|
*/
|
|
para->nFlags &= ~MEPF_COMPLEX;
|
|
}
|
|
|
|
wc.context = c;
|
|
wc.para = para;
|
|
wc.style = NULL;
|
|
wc.nParaNumOffset = 0;
|
|
if (para->nFlags & MEPF_ROWEND)
|
|
wc.nFirstMargin = wc.nLeftMargin = wc.nRightMargin = 0;
|
|
else
|
|
{
|
|
int dxStartIndent = para->fmt.dxStartIndent;
|
|
if (para_cell( wc.para )) dxStartIndent += table_row_end( para )->fmt.dxOffset;
|
|
|
|
wc.nLeftMargin = ME_twips2pointsX( c, dxStartIndent + para->fmt.dxOffset );
|
|
wc.nFirstMargin = ME_twips2pointsX( c, dxStartIndent );
|
|
if (para->fmt.wNumbering)
|
|
{
|
|
wc.nParaNumOffset = wc.nFirstMargin;
|
|
dxStartIndent = max( ME_twips2pointsX(c, para->fmt.wNumberingTab),
|
|
para->para_num.width );
|
|
wc.nFirstMargin += dxStartIndent;
|
|
}
|
|
wc.nRightMargin = ME_twips2pointsX( c, para->fmt.dxRightIndent );
|
|
|
|
if (wc.nFirstMargin < 0) wc.nFirstMargin = 0;
|
|
if (wc.nLeftMargin < 0) wc.nLeftMargin = 0;
|
|
}
|
|
if (c->editor->bEmulateVersion10 && /* v1.0 - 3.0 */
|
|
para->fmt.dwMask & PFM_TABLE && para->fmt.wEffects & PFE_TABLE)
|
|
{
|
|
wc.nFirstMargin += ME_twips2pointsX( c, para->fmt.dxOffset * 2 );
|
|
}
|
|
wc.nRow = 0;
|
|
wc.pt.y = 0;
|
|
if (para->fmt.dwMask & PFM_SPACEBEFORE)
|
|
wc.pt.y += ME_twips2pointsY( c, para->fmt.dySpaceBefore );
|
|
if (!(para->fmt.dwMask & PFM_TABLE && para->fmt.wEffects & PFE_TABLE) &&
|
|
para->fmt.dwMask & PFM_BORDER)
|
|
{
|
|
border = ME_GetParaBorderWidth( c, para->fmt.wBorders );
|
|
if (para->fmt.wBorders & 1)
|
|
{
|
|
wc.nFirstMargin += border;
|
|
wc.nLeftMargin += border;
|
|
}
|
|
if (para->fmt.wBorders & 2) wc.nRightMargin -= border;
|
|
if (para->fmt.wBorders & 4) wc.pt.y += border;
|
|
}
|
|
|
|
linespace = ME_GetParaLineSpace( c, para );
|
|
|
|
ME_BeginRow( &wc );
|
|
run = para_first_run( para );
|
|
while (run)
|
|
{
|
|
run = ME_WrapHandleRun( &wc, run );
|
|
if (wc.nRow && run == wc.pRowStart) wc.pt.y += linespace;
|
|
}
|
|
ME_WrapEndParagraph( &wc );
|
|
if (!(para->fmt.dwMask & PFM_TABLE && para->fmt.wEffects & PFE_TABLE) &&
|
|
(para->fmt.dwMask & PFM_BORDER) && (para->fmt.wBorders & 8))
|
|
wc.pt.y += border;
|
|
if (para->fmt.dwMask & PFM_SPACEAFTER)
|
|
wc.pt.y += ME_twips2pointsY( c, para->fmt.dySpaceAfter );
|
|
|
|
para->nFlags &= ~MEPF_REWRAP;
|
|
para->nHeight = wc.pt.y;
|
|
para->nRows = wc.nRow;
|
|
editor->total_rows += wc.nRow;
|
|
}
|
|
|
|
struct repaint_range
|
|
{
|
|
ME_Paragraph *start, *end;
|
|
};
|
|
|
|
static void update_repaint( ME_Paragraph *para, struct repaint_range *repaint )
|
|
{
|
|
if (!repaint->start) repaint->start = para;
|
|
repaint->end = para;
|
|
}
|
|
|
|
static void adjust_para_y( ME_Paragraph *para, ME_Context *c, struct repaint_range *repaint )
|
|
{
|
|
ME_Cell *cell;
|
|
|
|
if (para->nFlags & MEPF_ROWSTART)
|
|
{
|
|
ME_Paragraph *end_row_para = table_row_end( para );
|
|
int borderWidth = 0;
|
|
|
|
cell = table_row_first_cell( para );
|
|
cell->pt = c->pt;
|
|
/* Offset the text by the largest top border width. */
|
|
while (cell_next( cell ))
|
|
{
|
|
borderWidth = max( borderWidth, cell->border.top.width );
|
|
cell = cell_next( cell );
|
|
}
|
|
if (borderWidth > 0)
|
|
{
|
|
borderWidth = max(ME_twips2pointsY(c, borderWidth), 1);
|
|
while (cell)
|
|
{
|
|
cell->yTextOffset = borderWidth;
|
|
cell = cell_prev( cell );
|
|
}
|
|
c->pt.y += borderWidth;
|
|
}
|
|
if (end_row_para->fmt.dxStartIndent > 0)
|
|
{
|
|
cell = table_row_first_cell( para );
|
|
cell->pt.x += ME_twips2pointsX( c, end_row_para->fmt.dxStartIndent );
|
|
c->pt.x = cell->pt.x;
|
|
}
|
|
}
|
|
else if (para->nFlags & MEPF_ROWEND)
|
|
{
|
|
/* Set all the cells to the height of the largest cell */
|
|
ME_Paragraph *start_row_para = table_row_start( para );
|
|
int prevHeight, nHeight, bottomBorder = 0;
|
|
|
|
cell = table_row_end_cell( para );
|
|
para->nWidth = cell->pt.x + cell->nWidth;
|
|
if (!(para_next( para )->nFlags & MEPF_ROWSTART))
|
|
{
|
|
/* Last row, the bottom border is added to the height. */
|
|
while ((cell = cell_prev( cell )))
|
|
bottomBorder = max( bottomBorder, cell->border.bottom.width );
|
|
|
|
bottomBorder = ME_twips2pointsY(c, bottomBorder);
|
|
cell = table_row_end_cell( para );
|
|
}
|
|
prevHeight = cell->nHeight;
|
|
nHeight = cell_prev( cell )->nHeight + bottomBorder;
|
|
cell->nHeight = nHeight;
|
|
para->nHeight = nHeight;
|
|
while (cell_prev( cell ))
|
|
{
|
|
cell = cell_prev( cell );
|
|
cell->nHeight = nHeight;
|
|
}
|
|
|
|
/* Also set the height of the start row paragraph */
|
|
start_row_para->nHeight = nHeight;
|
|
c->pt.x = start_row_para->pt.x;
|
|
c->pt.y = cell->pt.y + nHeight;
|
|
if (prevHeight < nHeight)
|
|
{
|
|
/* The height of the cells has grown, so invalidate the bottom of
|
|
* the cells. */
|
|
update_repaint( para, repaint );
|
|
cell = cell_prev( table_row_end_cell( para ) );
|
|
while (cell)
|
|
{
|
|
update_repaint( cell_end_para( cell ), repaint );
|
|
cell = cell_prev( cell );
|
|
}
|
|
}
|
|
}
|
|
else if ((cell = para_cell( para )) && para == cell_end_para( cell ))
|
|
{
|
|
/* The next paragraph is in the next cell in the table row. */
|
|
cell->nHeight = c->pt.y + para->nHeight - cell->pt.y;
|
|
|
|
/* Propagate the largest height to the end so that it can be easily
|
|
* sent back to all the cells at the end of the row. */
|
|
if (cell_prev( cell ))
|
|
cell->nHeight = max( cell->nHeight, cell_prev( cell )->nHeight );
|
|
|
|
c->pt.x = cell->pt.x + cell->nWidth;
|
|
c->pt.y = cell->pt.y;
|
|
cell_next( cell )->pt = c->pt;
|
|
if (!(para_next( para )->nFlags & MEPF_ROWEND))
|
|
c->pt.y += cell->yTextOffset;
|
|
}
|
|
else
|
|
{
|
|
if ((cell = para_cell( para ))) /* Next paragraph in the same cell. */
|
|
c->pt.x = cell->pt.x;
|
|
else /* Normal paragraph */
|
|
c->pt.x = 0;
|
|
c->pt.y += para->nHeight;
|
|
}
|
|
}
|
|
|
|
BOOL wrap_marked_paras_dc( ME_TextEditor *editor, HDC hdc, BOOL invalidate )
|
|
{
|
|
ME_Paragraph *para, *next;
|
|
struct wine_rb_entry *entry, *next_entry = NULL;
|
|
ME_Context c;
|
|
int totalWidth = editor->nTotalWidth, prev_width;
|
|
struct repaint_range repaint = { NULL, NULL };
|
|
|
|
if (!editor->marked_paras.root) return FALSE;
|
|
|
|
ME_InitContext( &c, editor, hdc );
|
|
|
|
entry = rb_head( editor->marked_paras.root );
|
|
while (entry)
|
|
{
|
|
para = WINE_RB_ENTRY_VALUE( entry, ME_Paragraph, marked_entry );
|
|
|
|
/* If the first entry lies inside a table, go back to the start
|
|
of the table to ensure cell heights are kept in sync. */
|
|
if (!next_entry && para_in_table( para ) && para != table_outer_para( para ))
|
|
{
|
|
para = table_outer_para( para );
|
|
next_entry = entry;
|
|
}
|
|
else
|
|
next_entry = rb_next( entry );
|
|
|
|
c.pt = para->pt;
|
|
prev_width = para->nWidth;
|
|
ME_WrapTextParagraph( editor, &c, para );
|
|
if (prev_width == totalWidth && para->nWidth < totalWidth)
|
|
totalWidth = get_total_width(editor);
|
|
else
|
|
totalWidth = max(totalWidth, para->nWidth);
|
|
|
|
update_repaint( para, &repaint );
|
|
adjust_para_y( para, &c, &repaint );
|
|
|
|
if (para_next( para ))
|
|
{
|
|
if (c.pt.x != para_next( para )->pt.x || c.pt.y != para_next( para )->pt.y ||
|
|
para_in_table( para ))
|
|
{
|
|
next = para;
|
|
while (para_next( next ) && &next->marked_entry != next_entry &&
|
|
next != &editor->pBuffer->pLast->member.para)
|
|
{
|
|
update_repaint( para_next( next ), &repaint );
|
|
para_next( next )->pt = c.pt;
|
|
adjust_para_y( para_next( next ), &c, &repaint );
|
|
next = para_next( next );
|
|
}
|
|
}
|
|
}
|
|
entry = next_entry;
|
|
}
|
|
wine_rb_destroy( &editor->marked_paras, NULL, NULL );
|
|
|
|
editor->sizeWindow.cx = c.rcView.right-c.rcView.left;
|
|
editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top;
|
|
|
|
editor->nTotalLength = editor->pBuffer->pLast->member.para.pt.y;
|
|
editor->nTotalWidth = totalWidth;
|
|
|
|
ME_DestroyContext(&c);
|
|
|
|
if (invalidate && (repaint.start || editor->nTotalLength < editor->nLastTotalLength))
|
|
para_range_invalidate( editor, repaint.start, repaint.end);
|
|
return !!repaint.start;
|
|
}
|
|
|
|
BOOL ME_WrapMarkedParagraphs( ME_TextEditor *editor )
|
|
{
|
|
HDC hdc = ITextHost_TxGetDC( editor->texthost );
|
|
BOOL ret = wrap_marked_paras_dc( editor, hdc, TRUE );
|
|
ITextHost_TxReleaseDC( editor->texthost, hdc );
|
|
return ret;
|
|
}
|
|
|
|
void para_range_invalidate( ME_TextEditor *editor, ME_Paragraph *start_para,
|
|
ME_Paragraph *last_para )
|
|
{
|
|
RECT rc;
|
|
int ofs;
|
|
|
|
rc = editor->rcFormat;
|
|
ofs = editor->vert_si.nPos;
|
|
|
|
if (start_para)
|
|
{
|
|
start_para = table_outer_para( start_para );
|
|
last_para = table_outer_para( last_para );
|
|
rc.top += start_para->pt.y - ofs;
|
|
} else {
|
|
rc.top += editor->nTotalLength - ofs;
|
|
}
|
|
if (editor->nTotalLength < editor->nLastTotalLength)
|
|
rc.bottom = editor->rcFormat.top + editor->nLastTotalLength - ofs;
|
|
else
|
|
rc.bottom = editor->rcFormat.top + last_para->pt.y + last_para->nHeight - ofs;
|
|
ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
|
|
}
|
|
|
|
|
|
void
|
|
ME_SendRequestResize(ME_TextEditor *editor, BOOL force)
|
|
{
|
|
if (editor->nEventMask & ENM_REQUESTRESIZE)
|
|
{
|
|
RECT rc;
|
|
|
|
ITextHost_TxGetClientRect(editor->texthost, &rc);
|
|
|
|
if (force || rc.bottom != editor->nTotalLength)
|
|
{
|
|
REQRESIZE info;
|
|
|
|
info.nmhdr.hwndFrom = NULL;
|
|
info.nmhdr.idFrom = 0;
|
|
info.nmhdr.code = EN_REQUESTRESIZE;
|
|
info.rc = rc;
|
|
info.rc.right = editor->nTotalWidth;
|
|
info.rc.bottom = editor->nTotalLength;
|
|
|
|
editor->nEventMask &= ~ENM_REQUESTRESIZE;
|
|
ITextHost_TxNotify(editor->texthost, info.nmhdr.code, &info);
|
|
editor->nEventMask |= ENM_REQUESTRESIZE;
|
|
}
|
|
}
|
|
}
|