comctl32/tests: Move message testing helpers to header.
[wine.git] / dlls / comctl32 / syslink.c
blobf36177913c6237cf98b1202ec1ff9616f6e5561f
1 /*
2 * SysLink control
4 * Copyright 2004 - 2006 Thomas Weidenmueller <w3seek@reactos.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * NOTES
22 * This code was audited for completeness against the documented features
23 * of Comctl32.dll version 6.0 on Apr. 4, 2005, by Dimitrie O. Paun.
25 * Unless otherwise noted, we believe this code to be complete, as per
26 * the specification mentioned above.
27 * If you discover missing features, or bugs, please note them below.
30 #include <stdarg.h>
31 #include <string.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winnls.h"
37 #include "commctrl.h"
38 #include "comctl32.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(progress);
44 INT WINAPI StrCmpNIW(LPCWSTR,LPCWSTR,INT);
46 typedef struct
48 int nChars;
49 int nSkip;
50 RECT rc;
51 } DOC_TEXTBLOCK, *PDOC_TEXTBLOCK;
53 #define LIF_FLAGSMASK (LIF_STATE | LIF_ITEMID | LIF_URL)
54 #define LIS_MASK (LIS_FOCUSED | LIS_ENABLED | LIS_VISITED)
56 typedef enum
58 slText = 0,
59 slLink
60 } SL_ITEM_TYPE;
62 typedef struct _DOC_ITEM
64 struct _DOC_ITEM *Next; /* Address to the next item */
65 UINT nText; /* Number of characters of the text */
66 SL_ITEM_TYPE Type; /* type of the item */
67 PDOC_TEXTBLOCK Blocks; /* Array of text blocks */
68 union
70 struct
72 UINT state; /* Link state */
73 WCHAR *szID; /* Link ID string */
74 WCHAR *szUrl; /* Link URL string */
75 } Link;
76 struct
78 UINT Dummy;
79 } Text;
80 } u;
81 WCHAR Text[1]; /* Text of the document item */
82 } DOC_ITEM, *PDOC_ITEM;
84 typedef struct
86 HWND Self; /* The window handle for this control */
87 HWND Notify; /* The parent handle to receive notifications */
88 DWORD Style; /* Styles for this control */
89 PDOC_ITEM Items; /* Address to the first document item */
90 BOOL HasFocus; /* Whether the control has the input focus */
91 int MouseDownID; /* ID of the link that the mouse button first selected */
92 HFONT Font; /* Handle to the font for text */
93 HFONT LinkFont; /* Handle to the font for links */
94 COLORREF TextColor; /* Color of the text */
95 COLORREF LinkColor; /* Color of links */
96 COLORREF VisitedColor; /* Color of visited links */
97 WCHAR BreakChar; /* Break Character for the current font */
98 } SYSLINK_INFO;
100 static const WCHAR SL_LINKOPEN[] = { '<','a', 0 };
101 static const WCHAR SL_HREF[] = { 'h','r','e','f','=','\"',0 };
102 static const WCHAR SL_ID[] = { 'i','d','=','\"',0 };
103 static const WCHAR SL_LINKCLOSE[] = { '<','/','a','>',0 };
105 /* Control configuration constants */
107 #define SL_LEFTMARGIN (0)
108 #define SL_TOPMARGIN (0)
109 #define SL_RIGHTMARGIN (0)
110 #define SL_BOTTOMMARGIN (0)
112 /***********************************************************************
113 * SYSLINK_FreeDocItem
114 * Frees all data and gdi objects associated with a document item
116 static VOID SYSLINK_FreeDocItem (PDOC_ITEM DocItem)
118 if(DocItem->Type == slLink)
120 Free(DocItem->u.Link.szID);
121 Free(DocItem->u.Link.szUrl);
124 /* we don't free Text because it's just a pointer to a character in the
125 entire window text string */
127 Free(DocItem);
130 /***********************************************************************
131 * SYSLINK_AppendDocItem
132 * Create and append a new document item.
134 static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UINT textlen,
135 SL_ITEM_TYPE type, PDOC_ITEM LastItem)
137 PDOC_ITEM Item;
139 textlen = min(textlen, strlenW(Text));
140 Item = Alloc(FIELD_OFFSET(DOC_ITEM, Text[textlen + 1]));
141 if(Item == NULL)
143 ERR("Failed to alloc DOC_ITEM structure!\n");
144 return NULL;
147 Item->Next = NULL;
148 Item->nText = textlen;
149 Item->Type = type;
150 Item->Blocks = NULL;
152 if(LastItem != NULL)
154 LastItem->Next = Item;
156 else
158 infoPtr->Items = Item;
161 lstrcpynW(Item->Text, Text, textlen + 1);
163 return Item;
166 /***********************************************************************
167 * SYSLINK_ClearDoc
168 * Clears the document tree
170 static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
172 PDOC_ITEM Item, Next;
174 Item = infoPtr->Items;
175 while(Item != NULL)
177 Next = Item->Next;
178 SYSLINK_FreeDocItem(Item);
179 Item = Next;
182 infoPtr->Items = NULL;
185 /***********************************************************************
186 * SYSLINK_ParseText
187 * Parses the window text string and creates a document. Returns the
188 * number of document items created.
190 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
192 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
193 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
194 PDOC_ITEM Last = NULL;
195 SL_ITEM_TYPE CurrentType = slText;
196 LPCWSTR lpID, lpUrl;
197 UINT lenId, lenUrl;
199 for(current = Text; *current != 0;)
201 if(*current == '<')
203 if(!StrCmpNIW(current, SL_LINKOPEN, 2) && (CurrentType == slText))
205 BOOL ValidParam = FALSE, ValidLink = FALSE;
207 if(*(current + 2) == '>')
209 /* we just have to deal with a <a> tag */
210 taglen = 3;
211 ValidLink = TRUE;
212 ValidParam = TRUE;
213 firsttag = current;
214 linklen = 0;
215 lpID = NULL;
216 lpUrl = NULL;
218 else if(*(current + 2) == infoPtr->BreakChar)
220 /* we expect parameters, parse them */
221 LPCWSTR *CurrentParameter = NULL, tmp;
222 UINT *CurrentParameterLen = NULL;
224 taglen = 3;
225 tmp = current + taglen;
226 lpID = NULL;
227 lpUrl = NULL;
229 CheckParameter:
230 /* compare the current position with all known parameters */
231 if(!StrCmpNIW(tmp, SL_HREF, 6))
233 taglen += 6;
234 ValidParam = TRUE;
235 CurrentParameter = &lpUrl;
236 CurrentParameterLen = &lenUrl;
238 else if(!StrCmpNIW(tmp, SL_ID, 4))
240 taglen += 4;
241 ValidParam = TRUE;
242 CurrentParameter = &lpID;
243 CurrentParameterLen = &lenId;
245 else
247 ValidParam = FALSE;
250 if(ValidParam)
252 /* we got a known parameter, now search until the next " character.
253 If we can't find a " character, there's a syntax error and we just assume it's text */
254 ValidParam = FALSE;
255 *CurrentParameter = current + taglen;
256 *CurrentParameterLen = 0;
258 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
260 taglen++;
261 if(*tmp == '\"')
263 ValidParam = TRUE;
264 tmp++;
265 break;
267 (*CurrentParameterLen)++;
270 if(ValidParam)
272 /* we're done with this parameter, now there are only 2 possibilities:
273 * 1. another parameter is coming, so expect a ' ' (space) character
274 * 2. the tag is being closed, so expect a '<' character
276 if(*tmp == infoPtr->BreakChar)
278 /* we expect another parameter, do the whole thing again */
279 taglen++;
280 tmp++;
281 goto CheckParameter;
283 else if(*tmp == '>')
285 /* the tag is being closed, we're done */
286 ValidLink = TRUE;
287 taglen++;
292 if(ValidLink && ValidParam)
294 /* the <a ...> tag appears to be valid. save all information
295 so we can add the link if we find a valid </a> tag later */
296 CurrentType = slLink;
297 linktext = current + taglen;
298 linklen = 0;
299 firsttag = current;
301 else
303 taglen = 1;
304 lpID = NULL;
305 lpUrl = NULL;
306 if(textstart == NULL)
308 textstart = current;
312 else if(!StrCmpNIW(current, SL_LINKCLOSE, 4) && (CurrentType == slLink) && firsttag)
314 /* there's a <a...> tag opened, first add the previous text, if present */
315 if(textstart != NULL && textlen > 0 && firsttag > textstart)
317 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
318 if(Last == NULL)
320 ERR("Unable to create new document item!\n");
321 return docitems;
323 docitems++;
324 textstart = NULL;
325 textlen = 0;
328 /* now it's time to add the link to the document */
329 current += 4;
330 if(linktext != NULL && linklen > 0)
332 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
333 if(Last == NULL)
335 ERR("Unable to create new document item!\n");
336 return docitems;
338 docitems++;
339 if(CurrentType == slLink)
341 int nc;
343 if(!(infoPtr->Style & WS_DISABLED))
345 Last->u.Link.state |= LIS_ENABLED;
347 /* Copy the tag parameters */
348 if(lpID != NULL)
350 nc = min(lenId, strlenW(lpID));
351 nc = min(nc, MAX_LINKID_TEXT - 1);
352 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
353 if(Last->u.Link.szID != NULL)
355 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
358 else
359 Last->u.Link.szID = NULL;
360 if(lpUrl != NULL)
362 nc = min(lenUrl, strlenW(lpUrl));
363 nc = min(nc, L_MAX_URL_LENGTH - 1);
364 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
365 if(Last->u.Link.szUrl != NULL)
367 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
370 else
371 Last->u.Link.szUrl = NULL;
373 linktext = NULL;
375 CurrentType = slText;
376 firsttag = NULL;
377 textstart = NULL;
378 continue;
380 else
382 /* we don't know what tag it is, so just continue */
383 taglen = 1;
384 linklen++;
385 if(CurrentType == slText && textstart == NULL)
387 textstart = current;
391 textlen += taglen;
392 current += taglen;
394 else
396 textlen++;
397 linklen++;
399 /* save the pointer of the current text item if we couldn't find a tag */
400 if(textstart == NULL && CurrentType == slText)
402 textstart = current;
405 current++;
409 if(textstart != NULL && textlen > 0)
411 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
412 if(Last == NULL)
414 ERR("Unable to create new document item!\n");
415 return docitems;
417 if(CurrentType == slLink)
419 int nc;
421 if(!(infoPtr->Style & WS_DISABLED))
423 Last->u.Link.state |= LIS_ENABLED;
425 /* Copy the tag parameters */
426 if(lpID != NULL)
428 nc = min(lenId, strlenW(lpID));
429 nc = min(nc, MAX_LINKID_TEXT - 1);
430 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
431 if(Last->u.Link.szID != NULL)
433 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
436 else
437 Last->u.Link.szID = NULL;
438 if(lpUrl != NULL)
440 nc = min(lenUrl, strlenW(lpUrl));
441 nc = min(nc, L_MAX_URL_LENGTH - 1);
442 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
443 if(Last->u.Link.szUrl != NULL)
445 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
448 else
449 Last->u.Link.szUrl = NULL;
451 docitems++;
454 if(linktext != NULL && linklen > 0)
456 /* we got an unclosed link, just display the text */
457 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
458 if(Last == NULL)
460 ERR("Unable to create new document item!\n");
461 return docitems;
463 docitems++;
466 return docitems;
469 /***********************************************************************
470 * SYSLINK_RepaintLink
471 * Repaints a link.
473 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
475 PDOC_TEXTBLOCK bl;
476 int n;
478 if(DocItem->Type != slLink)
480 ERR("DocItem not a link!\n");
481 return;
484 bl = DocItem->Blocks;
485 if (bl != NULL)
487 n = DocItem->nText;
489 while(n > 0)
491 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
492 n -= bl->nChars + bl->nSkip;
493 bl++;
498 /***********************************************************************
499 * SYSLINK_GetLinkItemByIndex
500 * Retrieves a document link by its index
502 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
504 PDOC_ITEM Current = infoPtr->Items;
506 while(Current != NULL)
508 if((Current->Type == slLink) && (iLink-- <= 0))
510 return Current;
512 Current = Current->Next;
514 return NULL;
517 /***********************************************************************
518 * SYSLINK_GetFocusLink
519 * Retrieves the link that has the LIS_FOCUSED bit
521 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
523 PDOC_ITEM Current = infoPtr->Items;
524 int id = 0;
526 while(Current != NULL)
528 if((Current->Type == slLink))
530 if(Current->u.Link.state & LIS_FOCUSED)
532 if(LinkId != NULL)
533 *LinkId = id;
534 return Current;
536 id++;
538 Current = Current->Next;
540 return NULL;
543 /***********************************************************************
544 * SYSLINK_GetNextLink
545 * Gets the next link
547 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
549 for(Current = (Current != NULL ? Current->Next : infoPtr->Items);
550 Current != NULL;
551 Current = Current->Next)
553 if(Current->Type == slLink)
555 return Current;
558 return NULL;
561 /***********************************************************************
562 * SYSLINK_GetPrevLink
563 * Gets the previous link
565 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
567 if(Current == NULL)
569 /* returns the last link */
570 PDOC_ITEM Last = NULL;
572 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
574 if(Current->Type == slLink)
576 Last = Current;
579 return Last;
581 else
583 /* returns the previous link */
584 PDOC_ITEM Cur, Prev = NULL;
586 for(Cur = infoPtr->Items; Cur != NULL; Cur = Cur->Next)
588 if(Cur == Current)
590 break;
592 if(Cur->Type == slLink)
594 Prev = Cur;
597 return Prev;
601 /***********************************************************************
602 * SYSLINK_WrapLine
603 * Tries to wrap a line.
605 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int *LineLen,
606 int nFit, LPSIZE Extent)
608 WCHAR *Current;
610 if(nFit == *LineLen)
612 return FALSE;
615 *LineLen = nFit;
617 Current = Text + nFit;
619 /* check if we're in the middle of a word */
620 if((*Current) != BreakChar)
622 /* search for the beginning of the word */
623 while(Current > Text && (*(Current - 1)) != BreakChar)
625 Current--;
626 (*LineLen)--;
629 if((*LineLen) == 0)
631 Extent->cx = 0;
632 Extent->cy = 0;
634 return TRUE;
637 return TRUE;
640 /***********************************************************************
641 * SYSLINK_Render
642 * Renders the document in memory
644 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
646 RECT rc;
647 PDOC_ITEM Current;
648 HGDIOBJ hOldFont;
649 int x, y, LineHeight;
650 SIZE szDoc;
652 szDoc.cx = szDoc.cy = 0;
654 rc = *pRect;
655 rc.right -= SL_RIGHTMARGIN;
656 rc.bottom -= SL_BOTTOMMARGIN;
658 if(rc.right - SL_LEFTMARGIN < 0)
659 rc.right = MAXLONG;
660 if (rc.bottom - SL_TOPMARGIN < 0)
661 rc.bottom = MAXLONG;
663 hOldFont = SelectObject(hdc, infoPtr->Font);
665 x = SL_LEFTMARGIN;
666 y = SL_TOPMARGIN;
667 LineHeight = 0;
669 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
671 int n, nBlocks;
672 LPWSTR tx;
673 PDOC_TEXTBLOCK bl, cbl;
674 INT nFit;
675 SIZE szDim;
677 if(Current->nText == 0)
679 continue;
682 tx = Current->Text;
683 n = Current->nText;
685 Free(Current->Blocks);
686 Current->Blocks = NULL;
687 bl = NULL;
688 nBlocks = 0;
690 if(Current->Type == slText)
692 SelectObject(hdc, infoPtr->Font);
694 else if(Current->Type == slLink)
696 SelectObject(hdc, infoPtr->LinkFont);
699 while(n > 0)
701 int SkipChars = 0;
703 /* skip break characters unless they're the first of the doc item */
704 if(tx != Current->Text || x == SL_LEFTMARGIN)
706 while(n > 0 && (*tx) == infoPtr->BreakChar)
708 tx++;
709 SkipChars++;
710 n--;
714 if((n == 0 && SkipChars != 0) ||
715 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
717 int LineLen = n;
718 BOOL Wrap = FALSE;
719 PDOC_TEXTBLOCK nbl;
721 if(n != 0)
723 Wrap = SYSLINK_WrapLine(tx, infoPtr->BreakChar, &LineLen, nFit, &szDim);
725 if(LineLen == 0)
727 if(x > SL_LEFTMARGIN)
729 /* move one line down, the word didn't fit into the line */
730 x = SL_LEFTMARGIN;
731 y += LineHeight;
732 LineHeight = 0;
733 continue;
735 else
737 /* the word starts at the beginning of the line and doesn't
738 fit into the line, so break it at the last character that fits */
739 LineLen = max(nFit, 1);
743 if(LineLen != n)
745 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
747 if(bl != NULL)
749 Free(bl);
750 bl = NULL;
751 nBlocks = 0;
753 break;
758 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
759 if (nbl != NULL)
761 bl = nbl;
762 nBlocks++;
764 cbl = bl + nBlocks - 1;
766 cbl->nChars = LineLen;
767 cbl->nSkip = SkipChars;
768 cbl->rc.left = x;
769 cbl->rc.top = y;
770 cbl->rc.right = x + szDim.cx;
771 cbl->rc.bottom = y + szDim.cy;
773 if (cbl->rc.right > szDoc.cx)
774 szDoc.cx = cbl->rc.right;
775 if (cbl->rc.bottom > szDoc.cy)
776 szDoc.cy = cbl->rc.bottom;
778 if(LineLen != 0)
780 x += szDim.cx;
781 LineHeight = max(LineHeight, szDim.cy);
783 if(Wrap)
785 x = SL_LEFTMARGIN;
786 y += LineHeight;
787 LineHeight = 0;
791 else
793 Free(bl);
794 bl = NULL;
795 nBlocks = 0;
797 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
798 break;
800 n -= LineLen;
801 tx += LineLen;
803 else
805 n--;
809 if(nBlocks != 0)
811 Current->Blocks = bl;
815 SelectObject(hdc, hOldFont);
817 pRect->right = pRect->left + szDoc.cx;
818 pRect->bottom = pRect->top + szDoc.cy;
821 /***********************************************************************
822 * SYSLINK_Draw
823 * Draws the SysLink control.
825 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
827 RECT rc;
828 PDOC_ITEM Current;
829 HFONT hOldFont;
830 COLORREF OldTextColor, OldBkColor;
832 hOldFont = SelectObject(hdc, infoPtr->Font);
833 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
834 OldBkColor = SetBkColor(hdc, comctl32_color.clrBtnFace);
836 GetClientRect(infoPtr->Self, &rc);
837 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
838 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
840 if(rc.right < 0 || rc.bottom < 0) return 0;
842 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
844 int n;
845 LPWSTR tx;
846 PDOC_TEXTBLOCK bl;
848 bl = Current->Blocks;
849 if(bl != NULL)
851 tx = Current->Text;
852 n = Current->nText;
854 if(Current->Type == slText)
856 SelectObject(hdc, infoPtr->Font);
857 SetTextColor(hdc, infoPtr->TextColor);
859 else
861 SelectObject(hdc, infoPtr->LinkFont);
862 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
865 while(n > 0)
867 tx += bl->nSkip;
868 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, ETO_OPAQUE | ETO_CLIPPED, &bl->rc, tx, bl->nChars, NULL);
869 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
871 COLORREF PrevTextColor;
872 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
873 DrawFocusRect(hdc, &bl->rc);
874 SetTextColor(hdc, PrevTextColor);
876 tx += bl->nChars;
877 n -= bl->nChars + bl->nSkip;
878 bl++;
883 SetBkColor(hdc, OldBkColor);
884 SetTextColor(hdc, OldTextColor);
885 SelectObject(hdc, hOldFont);
887 return 0;
891 /***********************************************************************
892 * SYSLINK_Paint
893 * Handles the WM_PAINT message.
895 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
897 HDC hdc;
898 PAINTSTRUCT ps;
900 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
901 if (hdc)
903 SYSLINK_Draw (infoPtr, hdc);
904 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
906 return 0;
910 /***********************************************************************
911 * SYSLINK_SetFont
912 * Set new Font for the SysLink control.
914 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
916 HDC hdc;
917 LOGFONTW lf;
918 TEXTMETRICW tm;
919 RECT rcClient;
920 HFONT hOldFont = infoPtr->Font;
921 infoPtr->Font = hFont;
923 /* free the underline font */
924 if(infoPtr->LinkFont != NULL)
926 DeleteObject(infoPtr->LinkFont);
927 infoPtr->LinkFont = NULL;
930 /* Render text position and word wrapping in memory */
931 if (GetClientRect(infoPtr->Self, &rcClient))
933 hdc = GetDC(infoPtr->Self);
934 if(hdc != NULL)
936 /* create a new underline font */
937 if(GetTextMetricsW(hdc, &tm) &&
938 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
940 lf.lfUnderline = TRUE;
941 infoPtr->LinkFont = CreateFontIndirectW(&lf);
942 infoPtr->BreakChar = tm.tmBreakChar;
944 else
946 ERR("Failed to create link font!\n");
949 SYSLINK_Render(infoPtr, hdc, &rcClient);
950 ReleaseDC(infoPtr->Self, hdc);
954 if(bRedraw)
956 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
959 return hOldFont;
962 /***********************************************************************
963 * SYSLINK_SetText
964 * Set new text for the SysLink control.
966 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
968 /* clear the document */
969 SYSLINK_ClearDoc(infoPtr);
971 if(Text == NULL || *Text == 0)
973 return TRUE;
976 /* let's parse the string and create a document */
977 if(SYSLINK_ParseText(infoPtr, Text) > 0)
979 RECT rcClient;
981 /* Render text position and word wrapping in memory */
982 if (GetClientRect(infoPtr->Self, &rcClient))
984 HDC hdc = GetDC(infoPtr->Self);
985 if (hdc != NULL)
987 SYSLINK_Render(infoPtr, hdc, &rcClient);
988 ReleaseDC(infoPtr->Self, hdc);
990 InvalidateRect(infoPtr->Self, NULL, TRUE);
995 return TRUE;
998 /***********************************************************************
999 * SYSLINK_SetFocusLink
1000 * Updates the focus status bits and focusses the specified link.
1001 * If no document item is specified, the focus bit will be removed from all links.
1002 * Returns the previous focused item.
1004 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
1006 PDOC_ITEM Current, PrevFocus = NULL;
1008 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1010 if(Current->Type == slLink)
1012 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1014 PrevFocus = Current;
1017 if(Current == DocItem)
1019 Current->u.Link.state |= LIS_FOCUSED;
1021 else
1023 Current->u.Link.state &= ~LIS_FOCUSED;
1028 return PrevFocus;
1031 /***********************************************************************
1032 * SYSLINK_SetItem
1033 * Sets the states and attributes of a link item.
1035 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1037 PDOC_ITEM di;
1038 int nc;
1039 PWSTR szId = NULL;
1040 PWSTR szUrl = NULL;
1041 BOOL Repaint = FALSE;
1043 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1045 ERR("Invalid Flags!\n");
1046 return FALSE;
1049 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1050 if(di == NULL)
1052 ERR("Link %d couldn't be found\n", Item->iLink);
1053 return FALSE;
1056 if(Item->mask & LIF_ITEMID)
1058 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1059 szId = Alloc((nc + 1) * sizeof(WCHAR));
1060 if(szId)
1062 lstrcpynW(szId, Item->szID, nc + 1);
1064 else
1066 ERR("Unable to allocate memory for link id\n");
1067 return FALSE;
1071 if(Item->mask & LIF_URL)
1073 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1074 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1075 if(szUrl)
1077 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1079 else
1081 Free(szId);
1083 ERR("Unable to allocate memory for link url\n");
1084 return FALSE;
1088 if(Item->mask & LIF_ITEMID)
1090 Free(di->u.Link.szID);
1091 di->u.Link.szID = szId;
1094 if(Item->mask & LIF_URL)
1096 Free(di->u.Link.szUrl);
1097 di->u.Link.szUrl = szUrl;
1100 if(Item->mask & LIF_STATE)
1102 UINT oldstate = di->u.Link.state;
1103 /* clear the masked bits */
1104 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1105 /* copy the bits */
1106 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1107 Repaint = (oldstate != di->u.Link.state);
1109 /* update the focus */
1110 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1113 if(Repaint)
1115 SYSLINK_RepaintLink(infoPtr, di);
1118 return TRUE;
1121 /***********************************************************************
1122 * SYSLINK_GetItem
1123 * Retrieves the states and attributes of a link item.
1125 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1127 PDOC_ITEM di;
1129 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1131 ERR("Invalid Flags!\n");
1132 return FALSE;
1135 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1136 if(di == NULL)
1138 ERR("Link %d couldn't be found\n", Item->iLink);
1139 return FALSE;
1142 if(Item->mask & LIF_STATE)
1144 Item->state = (di->u.Link.state & Item->stateMask);
1145 if(!infoPtr->HasFocus)
1147 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1148 Item->state &= ~LIS_FOCUSED;
1152 if(Item->mask & LIF_ITEMID)
1154 if(di->u.Link.szID)
1156 lstrcpyW(Item->szID, di->u.Link.szID);
1158 else
1160 Item->szID[0] = 0;
1164 if(Item->mask & LIF_URL)
1166 if(di->u.Link.szUrl)
1168 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1170 else
1172 Item->szUrl[0] = 0;
1176 return TRUE;
1179 /***********************************************************************
1180 * SYSLINK_PtInDocItem
1181 * Determines if a point is in the region of a document item
1183 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1185 PDOC_TEXTBLOCK bl;
1186 int n;
1188 bl = DocItem->Blocks;
1189 if (bl != NULL)
1191 n = DocItem->nText;
1193 while(n > 0)
1195 if (PtInRect(&bl->rc, pt))
1197 return TRUE;
1199 n -= bl->nChars + bl->nSkip;
1200 bl++;
1204 return FALSE;
1207 /***********************************************************************
1208 * SYSLINK_HitTest
1209 * Determines the link the user clicked on.
1211 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1213 PDOC_ITEM Current;
1214 int id = 0;
1216 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1218 if(Current->Type == slLink)
1220 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1222 HitTest->item.mask = 0;
1223 HitTest->item.iLink = id;
1224 HitTest->item.state = 0;
1225 HitTest->item.stateMask = 0;
1226 if(Current->u.Link.szID)
1228 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1230 else
1232 HitTest->item.szID[0] = 0;
1234 if(Current->u.Link.szUrl)
1236 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1238 else
1240 HitTest->item.szUrl[0] = 0;
1242 return TRUE;
1244 id++;
1248 return FALSE;
1251 /***********************************************************************
1252 * SYSLINK_GetIdealHeight
1253 * Returns the preferred height of a link at the current control's width.
1255 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1257 HDC hdc = GetDC(infoPtr->Self);
1258 if(hdc != NULL)
1260 LRESULT height;
1261 TEXTMETRICW tm;
1262 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1264 if(GetTextMetricsW(hdc, &tm))
1266 height = tm.tmHeight;
1268 else
1270 height = 0;
1272 SelectObject(hdc, hOldFont);
1273 ReleaseDC(infoPtr->Self, hdc);
1275 return height;
1277 return 0;
1280 /***********************************************************************
1281 * SYSLINK_SendParentNotify
1282 * Sends a WM_NOTIFY message to the parent window.
1284 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1286 NMLINK nml;
1288 nml.hdr.hwndFrom = infoPtr->Self;
1289 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1290 nml.hdr.code = code;
1292 nml.item.mask = 0;
1293 nml.item.iLink = iLink;
1294 nml.item.state = 0;
1295 nml.item.stateMask = 0;
1296 if(Link->u.Link.szID)
1298 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1300 else
1302 nml.item.szID[0] = 0;
1304 if(Link->u.Link.szUrl)
1306 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1308 else
1310 nml.item.szUrl[0] = 0;
1313 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1316 /***********************************************************************
1317 * SYSLINK_SetFocus
1318 * Handles receiving the input focus.
1320 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1322 PDOC_ITEM Focus;
1324 infoPtr->HasFocus = TRUE;
1326 /* We always select the first link, even if we activated the control using
1327 SHIFT+TAB. This is the default behavior */
1328 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1329 if(Focus != NULL)
1331 SYSLINK_SetFocusLink(infoPtr, Focus);
1332 SYSLINK_RepaintLink(infoPtr, Focus);
1334 return 0;
1337 /***********************************************************************
1338 * SYSLINK_KillFocus
1339 * Handles losing the input focus.
1341 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1343 PDOC_ITEM Focus;
1345 infoPtr->HasFocus = FALSE;
1346 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1348 if(Focus != NULL)
1350 SYSLINK_RepaintLink(infoPtr, Focus);
1353 return 0;
1356 /***********************************************************************
1357 * SYSLINK_LinkAtPt
1358 * Returns a link at the specified position
1360 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1362 PDOC_ITEM Current;
1363 int id = 0;
1365 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1367 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1368 (!MustBeEnabled || (MustBeEnabled && (Current->u.Link.state & LIS_ENABLED))))
1370 if(LinkId != NULL)
1372 *LinkId = id;
1374 return Current;
1376 id++;
1379 return NULL;
1382 /***********************************************************************
1383 * SYSLINK_LButtonDown
1384 * Handles mouse clicks
1386 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1388 PDOC_ITEM Current, Old;
1389 int id;
1391 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1392 if(Current != NULL)
1394 SetFocus(infoPtr->Self);
1396 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1397 if(Old != NULL && Old != Current)
1399 SYSLINK_RepaintLink(infoPtr, Old);
1401 infoPtr->MouseDownID = id;
1402 SYSLINK_RepaintLink(infoPtr, Current);
1405 return 0;
1408 /***********************************************************************
1409 * SYSLINK_LButtonUp
1410 * Handles mouse clicks
1412 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1414 if(infoPtr->MouseDownID > -1)
1416 PDOC_ITEM Current;
1417 int id;
1419 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1420 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1422 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1426 infoPtr->MouseDownID = -1;
1428 return 0;
1431 /***********************************************************************
1432 * SYSLINK_OnEnter
1433 * Handles ENTER key events
1435 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1437 if(infoPtr->HasFocus)
1439 PDOC_ITEM Focus;
1440 int id;
1442 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1443 if(Focus != NULL)
1445 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1446 return TRUE;
1449 return FALSE;
1452 /***********************************************************************
1453 * SYSKEY_SelectNextPrevLink
1454 * Changes the currently focused link
1456 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1458 if(infoPtr->HasFocus)
1460 PDOC_ITEM Focus;
1461 int id;
1463 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1464 if(Focus != NULL)
1466 PDOC_ITEM NewFocus, OldFocus;
1468 if(Prev)
1469 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1470 else
1471 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1473 if(NewFocus != NULL)
1475 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1477 if(OldFocus && OldFocus != NewFocus)
1479 SYSLINK_RepaintLink(infoPtr, OldFocus);
1481 SYSLINK_RepaintLink(infoPtr, NewFocus);
1482 return TRUE;
1486 return FALSE;
1489 /***********************************************************************
1490 * SYSKEY_SelectNextPrevLink
1491 * Determines if there's a next or previous link to decide whether the control
1492 * should capture the tab key message
1494 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1496 PDOC_ITEM Focus, NewFocus;
1498 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1499 if(Prev)
1500 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1501 else
1502 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1504 return NewFocus == NULL;
1507 /***********************************************************************
1508 * SYSLINK_GetIdealSize
1509 * Calculates the ideal size of a link control at a given maximum width.
1511 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1513 RECT rc;
1514 HDC hdc;
1516 rc.left = rc.top = rc.bottom = 0;
1517 rc.right = cxMaxWidth;
1519 hdc = GetDC(infoPtr->Self);
1520 if (hdc != NULL)
1522 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1524 SYSLINK_Render(infoPtr, hdc, &rc);
1526 SelectObject(hdc, hOldFont);
1527 ReleaseDC(infoPtr->Self, hdc);
1529 lpSize->cx = rc.right;
1530 lpSize->cy = rc.bottom;
1534 /***********************************************************************
1535 * SysLinkWindowProc
1537 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1538 WPARAM wParam, LPARAM lParam)
1540 SYSLINK_INFO *infoPtr;
1542 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1544 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1546 if (!infoPtr && message != WM_CREATE)
1547 goto HandleDefaultMessage;
1549 switch(message) {
1550 case WM_PRINTCLIENT:
1551 case WM_PAINT:
1552 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1554 case WM_SETCURSOR:
1556 LHITTESTINFO ht;
1557 DWORD mp = GetMessagePos();
1559 ht.pt.x = (short)LOWORD(mp);
1560 ht.pt.y = (short)HIWORD(mp);
1562 ScreenToClient(infoPtr->Self, &ht.pt);
1563 if(SYSLINK_HitTest (infoPtr, &ht))
1565 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1566 return TRUE;
1568 /* let the default window proc handle this message */
1569 goto HandleDefaultMessage;
1572 case WM_SIZE:
1574 RECT rcClient;
1575 if (GetClientRect(infoPtr->Self, &rcClient))
1577 HDC hdc = GetDC(infoPtr->Self);
1578 if(hdc != NULL)
1580 SYSLINK_Render(infoPtr, hdc, &rcClient);
1581 ReleaseDC(infoPtr->Self, hdc);
1584 return 0;
1587 case WM_GETFONT:
1588 return (LRESULT)infoPtr->Font;
1590 case WM_SETFONT:
1591 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1593 case WM_SETTEXT:
1594 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1595 goto HandleDefaultMessage;
1597 case WM_LBUTTONDOWN:
1599 POINT pt;
1600 pt.x = (short)LOWORD(lParam);
1601 pt.y = (short)HIWORD(lParam);
1602 return SYSLINK_LButtonDown(infoPtr, &pt);
1604 case WM_LBUTTONUP:
1606 POINT pt;
1607 pt.x = (short)LOWORD(lParam);
1608 pt.y = (short)HIWORD(lParam);
1609 return SYSLINK_LButtonUp(infoPtr, &pt);
1612 case WM_KEYDOWN:
1614 switch(wParam)
1616 case VK_RETURN:
1617 SYSLINK_OnEnter(infoPtr);
1618 return 0;
1619 case VK_TAB:
1621 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1622 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1623 return 0;
1626 goto HandleDefaultMessage;
1629 case WM_GETDLGCODE:
1631 LRESULT Ret = DLGC_HASSETSEL;
1632 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1633 switch(vk)
1635 case VK_RETURN:
1636 Ret |= DLGC_WANTMESSAGE;
1637 break;
1638 case VK_TAB:
1640 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1641 if(!SYSLINK_NoNextLink(infoPtr, shift))
1643 Ret |= DLGC_WANTTAB;
1645 else
1647 Ret |= DLGC_WANTCHARS;
1649 break;
1652 return Ret;
1655 case WM_NCHITTEST:
1657 POINT pt;
1658 RECT rc;
1659 pt.x = (short)LOWORD(lParam);
1660 pt.y = (short)HIWORD(lParam);
1662 GetClientRect(infoPtr->Self, &rc);
1663 ScreenToClient(infoPtr->Self, &pt);
1664 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1666 return HTNOWHERE;
1669 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1671 return HTCLIENT;
1674 return HTTRANSPARENT;
1677 case LM_HITTEST:
1678 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1680 case LM_SETITEM:
1681 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1683 case LM_GETITEM:
1684 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1686 case LM_GETIDEALHEIGHT:
1687 if (lParam)
1689 /* LM_GETIDEALSIZE */
1690 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1692 return SYSLINK_GetIdealHeight(infoPtr);
1694 case WM_SETFOCUS:
1695 return SYSLINK_SetFocus(infoPtr);
1697 case WM_KILLFOCUS:
1698 return SYSLINK_KillFocus(infoPtr);
1700 case WM_ENABLE:
1701 infoPtr->Style &= ~WS_DISABLED;
1702 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1703 InvalidateRect (infoPtr->Self, NULL, FALSE);
1704 return 0;
1706 case WM_STYLECHANGED:
1707 if (wParam == GWL_STYLE)
1709 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1711 InvalidateRect(infoPtr->Self, NULL, TRUE);
1713 return 0;
1715 case WM_CREATE:
1716 /* allocate memory for info struct */
1717 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1718 if (!infoPtr) return -1;
1719 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1721 /* initialize the info struct */
1722 infoPtr->Self = hwnd;
1723 infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1724 infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style;
1725 infoPtr->Font = 0;
1726 infoPtr->LinkFont = 0;
1727 infoPtr->Items = NULL;
1728 infoPtr->HasFocus = FALSE;
1729 infoPtr->MouseDownID = -1;
1730 infoPtr->TextColor = comctl32_color.clrWindowText;
1731 infoPtr->LinkColor = comctl32_color.clrHighlight;
1732 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1733 infoPtr->BreakChar = ' ';
1734 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1735 SYSLINK_SetText(infoPtr, ((LPCREATESTRUCTW)lParam)->lpszName);
1736 return 0;
1738 case WM_DESTROY:
1739 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1740 SYSLINK_ClearDoc(infoPtr);
1741 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1742 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1743 SetWindowLongPtrW(hwnd, 0, 0);
1744 Free (infoPtr);
1745 return 0;
1747 case WM_SYSCOLORCHANGE:
1748 COMCTL32_RefreshSysColors();
1749 return 0;
1751 default:
1752 HandleDefaultMessage:
1753 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1755 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1757 return DefWindowProcW(hwnd, message, wParam, lParam);
1762 /***********************************************************************
1763 * SYSLINK_Register [Internal]
1765 * Registers the SysLink window class.
1767 VOID SYSLINK_Register (void)
1769 WNDCLASSW wndClass;
1771 ZeroMemory (&wndClass, sizeof(wndClass));
1772 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1773 wndClass.lpfnWndProc = SysLinkWindowProc;
1774 wndClass.cbClsExtra = 0;
1775 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1776 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1777 wndClass.lpszClassName = WC_LINK;
1779 RegisterClassW (&wndClass);
1783 /***********************************************************************
1784 * SYSLINK_Unregister [Internal]
1786 * Unregisters the SysLink window class.
1788 VOID SYSLINK_Unregister (void)
1790 UnregisterClassW (WC_LINK, NULL);