[PATCH 45/45] [WinHelp]: support for relative offsets inside pages

Eric Pouech eric.pouech at orange.fr
Sun Mar 23 04:22:04 CDT 2008




A+
---

 programs/winhelp/hlpfile.c |   20 ++++++++++++++------
 programs/winhelp/hlpfile.h |    5 ++++-
 programs/winhelp/winhelp.c |   12 +++++++++---
 3 files changed, 27 insertions(+), 10 deletions(-)


diff --git a/programs/winhelp/hlpfile.c b/programs/winhelp/hlpfile.c
index d5bf229..46a05cf 100644
--- a/programs/winhelp/hlpfile.c
+++ b/programs/winhelp/hlpfile.c
@@ -1025,7 +1025,8 @@ unsigned HLPFILE_HalfPointsToTwips(unsigned pts)
  *
  *           HLPFILE_BrowseParagraph
  */
-BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BYTE *end)
+static BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd,
+                                    BYTE *buf, BYTE *end, unsigned* parlen)
 {
     UINT               textsize;
     BYTE              *format, *format_end;
@@ -1040,6 +1041,7 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
 
     if (buf + 0x19 > end) {WINE_WARN("header too small\n"); return FALSE;};
 
+    *parlen = 0;
     blocksize = GET_UINT(buf, 0);
     size = GET_UINT(buf, 0x4);
     datalen = GET_UINT(buf, 0x10);
@@ -1068,7 +1070,7 @@ BOOL HLPFILE_BrowseParagraph(HLPFILE *hlpfile, struct RtfData* rd, BYTE *buf, BY
     format_end = buf + GET_UINT(buf, 0x10);
 
     fetch_long(&format);
-    fetch_ushort(&format);
+    *parlen = fetch_ushort(&format);
 
     if (buf[0x14] == 0x23)
     {
@@ -1470,12 +1472,13 @@ done:
     return ret;
 }
 
-BOOL    HLPFILE_BrowsePage(HLPFILE_PAGE* page, struct RtfData* rd, unsigned font_scale)
+BOOL    HLPFILE_BrowsePage(HLPFILE_PAGE* page, struct RtfData* rd,
+                           unsigned font_scale, unsigned relative)
 {
     HLPFILE     *hlpfile = page->file;
     BYTE        *buf, *end;
     DWORD       ref = page->reference;
-    unsigned    index, offset, old_index = -1, count = 0, cpg;
+    unsigned    index, offset, old_index = -1, count = 0, offs = 0, cpg, parlen;
     char        tmp[1024];
     const char* ck = NULL;
 
@@ -1485,6 +1488,8 @@ BOOL    HLPFILE_BrowsePage(HLPFILE_PAGE* page, struct RtfData* rd, unsigned font
     rd->first_link = rd->current_link = NULL;
     rd->force_color = FALSE;
     rd->font_scale = font_scale;
+    rd->relative = relative;
+    rd->char_pos_rel = 0;
 
     switch (hlpfile->charset)
     {
@@ -1588,7 +1593,7 @@ BOOL    HLPFILE_BrowsePage(HLPFILE_PAGE* page, struct RtfData* rd, unsigned font
         buf = hlpfile->topic_map[index] + offset;
         if (buf + 0x15 >= hlpfile->topic_end) {WINE_WARN("extra\n"); break;}
         end = min(buf + GET_UINT(buf, 0), hlpfile->topic_end);
-        if (index != old_index) {old_index = index;}
+        if (index != old_index) {offs = 0; old_index = index;}
 
         switch (buf[0x14])
 	{
@@ -1597,7 +1602,10 @@ BOOL    HLPFILE_BrowsePage(HLPFILE_PAGE* page, struct RtfData* rd, unsigned font
             break;
 	case 0x20:
         case 0x23:
-            if (!HLPFILE_BrowseParagraph(hlpfile, rd, buf, end)) return FALSE;
+            if (!HLPFILE_BrowseParagraph(hlpfile, rd, buf, end, &parlen)) return FALSE;
+            if (relative >= index * 0x8000 + offs)
+                rd->char_pos_rel = rd->char_pos;
+            offs += parlen;
             break;
 
 	default:
diff --git a/programs/winhelp/hlpfile.h b/programs/winhelp/hlpfile.h
index 8dd58a5..8d61ffd 100644
--- a/programs/winhelp/hlpfile.h
+++ b/programs/winhelp/hlpfile.h
@@ -176,6 +176,9 @@ struct RtfData {
     HLPFILE_LINK*first_link;
     HLPFILE_LINK*current_link;
     BOOL        force_color;
+    unsigned    relative;       /* offset within page to lookup for */
+    unsigned    char_pos_rel;   /* char_pos correspondinf to relative */
 };
 
-BOOL          HLPFILE_BrowsePage(HLPFILE_PAGE*, struct RtfData* rd, unsigned font_scale);
+BOOL          HLPFILE_BrowsePage(HLPFILE_PAGE*, struct RtfData* rd,
+                                 unsigned font_scale, unsigned relative);
diff --git a/programs/winhelp/winhelp.c b/programs/winhelp/winhelp.c
index 9c59609..ffa3957 100644
--- a/programs/winhelp/winhelp.c
+++ b/programs/winhelp/winhelp.c
@@ -1045,6 +1045,10 @@ static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff,
 
 static void WINHELP_FillRichEdit(HWND hTextWnd, WINHELP_WINDOW *win, ULONG relative)
 {
+    unsigned    cp = 0;
+    POINTL      ptl;
+    POINT       pt;
+
     SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0);
     SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color);
     /* set word-wrap to window size (undocumented) */
@@ -1054,7 +1058,7 @@ static void WINHELP_FillRichEdit(HWND hTextWnd, WINHELP_WINDOW *win, ULONG relat
         struct RtfData  rd;
         EDITSTREAM      es;
 
-        if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale))
+        if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale, relative))
         {
             rd.where = rd.data;
             es.dwCookie = (DWORD_PTR)&rd;
@@ -1063,13 +1067,15 @@ static void WINHELP_FillRichEdit(HWND hTextWnd, WINHELP_WINDOW *win, ULONG relat
 
             SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
             win->page_links = rd.first_link;
+            cp = rd.char_pos_rel;
         }
         /* FIXME: else leaking potentially the rd.first_link chain */
         HeapFree(GetProcessHeap(), 0, rd.data);
     }
+    SendMessage(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0);
+    pt.x = 0; pt.y = ptl.y;
+    SendMessage(hTextWnd, EM_SETSCROLLPOS, 0, (WPARAM)&pt);
     SendMessage(hTextWnd, WM_SETREDRAW, TRUE, 0);
-    SendMessage(hTextWnd, EM_SETSEL, 0, 0);
-    SendMessage(hTextWnd, EM_SCROLLCARET, 0, 0);
     InvalidateRect(hTextWnd, NULL, TRUE);
 }
 





More information about the wine-patches mailing list