comctl32/syslink: Implement LWS_TRANSPARENT style.
[wine.git] / dlls / comctl32 / syslink.c
bloba1a6039118999438a3f0949aed73ae3dd5e24636
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 COLORREF BackColor; /* Background color, set on creation */
98 WCHAR BreakChar; /* Break Character for the current font */
99 } SYSLINK_INFO;
101 static const WCHAR SL_LINKOPEN[] = { '<','a', 0 };
102 static const WCHAR SL_HREF[] = { 'h','r','e','f','=','\"',0 };
103 static const WCHAR SL_ID[] = { 'i','d','=','\"',0 };
104 static const WCHAR SL_LINKCLOSE[] = { '<','/','a','>',0 };
106 /* Control configuration constants */
108 #define SL_LEFTMARGIN (0)
109 #define SL_TOPMARGIN (0)
110 #define SL_RIGHTMARGIN (0)
111 #define SL_BOTTOMMARGIN (0)
113 /***********************************************************************
114 * SYSLINK_FreeDocItem
115 * Frees all data and gdi objects associated with a document item
117 static VOID SYSLINK_FreeDocItem (PDOC_ITEM DocItem)
119 if(DocItem->Type == slLink)
121 Free(DocItem->u.Link.szID);
122 Free(DocItem->u.Link.szUrl);
125 /* we don't free Text because it's just a pointer to a character in the
126 entire window text string */
128 Free(DocItem);
131 /***********************************************************************
132 * SYSLINK_AppendDocItem
133 * Create and append a new document item.
135 static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UINT textlen,
136 SL_ITEM_TYPE type, PDOC_ITEM LastItem)
138 PDOC_ITEM Item;
140 textlen = min(textlen, strlenW(Text));
141 Item = Alloc(FIELD_OFFSET(DOC_ITEM, Text[textlen + 1]));
142 if(Item == NULL)
144 ERR("Failed to alloc DOC_ITEM structure!\n");
145 return NULL;
148 Item->Next = NULL;
149 Item->nText = textlen;
150 Item->Type = type;
151 Item->Blocks = NULL;
153 if(LastItem != NULL)
155 LastItem->Next = Item;
157 else
159 infoPtr->Items = Item;
162 lstrcpynW(Item->Text, Text, textlen + 1);
164 return Item;
167 /***********************************************************************
168 * SYSLINK_ClearDoc
169 * Clears the document tree
171 static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
173 PDOC_ITEM Item, Next;
175 Item = infoPtr->Items;
176 while(Item != NULL)
178 Next = Item->Next;
179 SYSLINK_FreeDocItem(Item);
180 Item = Next;
183 infoPtr->Items = NULL;
186 /***********************************************************************
187 * SYSLINK_ParseText
188 * Parses the window text string and creates a document. Returns the
189 * number of document items created.
191 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
193 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
194 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
195 PDOC_ITEM Last = NULL;
196 SL_ITEM_TYPE CurrentType = slText;
197 LPCWSTR lpID, lpUrl;
198 UINT lenId, lenUrl;
200 for(current = Text; *current != 0;)
202 if(*current == '<')
204 if(!StrCmpNIW(current, SL_LINKOPEN, 2) && (CurrentType == slText))
206 BOOL ValidParam = FALSE, ValidLink = FALSE;
208 if(*(current + 2) == '>')
210 /* we just have to deal with a <a> tag */
211 taglen = 3;
212 ValidLink = TRUE;
213 ValidParam = TRUE;
214 firsttag = current;
215 linklen = 0;
216 lpID = NULL;
217 lpUrl = NULL;
219 else if(*(current + 2) == infoPtr->BreakChar)
221 /* we expect parameters, parse them */
222 LPCWSTR *CurrentParameter = NULL, tmp;
223 UINT *CurrentParameterLen = NULL;
225 taglen = 3;
226 tmp = current + taglen;
227 lpID = NULL;
228 lpUrl = NULL;
230 CheckParameter:
231 /* compare the current position with all known parameters */
232 if(!StrCmpNIW(tmp, SL_HREF, 6))
234 taglen += 6;
235 ValidParam = TRUE;
236 CurrentParameter = &lpUrl;
237 CurrentParameterLen = &lenUrl;
239 else if(!StrCmpNIW(tmp, SL_ID, 4))
241 taglen += 4;
242 ValidParam = TRUE;
243 CurrentParameter = &lpID;
244 CurrentParameterLen = &lenId;
246 else
248 ValidParam = FALSE;
251 if(ValidParam)
253 /* we got a known parameter, now search until the next " character.
254 If we can't find a " character, there's a syntax error and we just assume it's text */
255 ValidParam = FALSE;
256 *CurrentParameter = current + taglen;
257 *CurrentParameterLen = 0;
259 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
261 taglen++;
262 if(*tmp == '\"')
264 ValidParam = TRUE;
265 tmp++;
266 break;
268 (*CurrentParameterLen)++;
271 if(ValidParam)
273 /* we're done with this parameter, now there are only 2 possibilities:
274 * 1. another parameter is coming, so expect a ' ' (space) character
275 * 2. the tag is being closed, so expect a '<' character
277 if(*tmp == infoPtr->BreakChar)
279 /* we expect another parameter, do the whole thing again */
280 taglen++;
281 tmp++;
282 goto CheckParameter;
284 else if(*tmp == '>')
286 /* the tag is being closed, we're done */
287 ValidLink = TRUE;
288 taglen++;
293 if(ValidLink && ValidParam)
295 /* the <a ...> tag appears to be valid. save all information
296 so we can add the link if we find a valid </a> tag later */
297 CurrentType = slLink;
298 linktext = current + taglen;
299 linklen = 0;
300 firsttag = current;
302 else
304 taglen = 1;
305 lpID = NULL;
306 lpUrl = NULL;
307 if(textstart == NULL)
309 textstart = current;
313 else if(!StrCmpNIW(current, SL_LINKCLOSE, 4) && (CurrentType == slLink) && firsttag)
315 /* there's a <a...> tag opened, first add the previous text, if present */
316 if(textstart != NULL && textlen > 0 && firsttag > textstart)
318 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
319 if(Last == NULL)
321 ERR("Unable to create new document item!\n");
322 return docitems;
324 docitems++;
325 textstart = NULL;
326 textlen = 0;
329 /* now it's time to add the link to the document */
330 current += 4;
331 if(linktext != NULL && linklen > 0)
333 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
334 if(Last == NULL)
336 ERR("Unable to create new document item!\n");
337 return docitems;
339 docitems++;
340 if(CurrentType == slLink)
342 int nc;
344 if(!(infoPtr->Style & WS_DISABLED))
346 Last->u.Link.state |= LIS_ENABLED;
348 /* Copy the tag parameters */
349 if(lpID != NULL)
351 nc = min(lenId, strlenW(lpID));
352 nc = min(nc, MAX_LINKID_TEXT - 1);
353 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
354 if(Last->u.Link.szID != NULL)
356 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
359 else
360 Last->u.Link.szID = NULL;
361 if(lpUrl != NULL)
363 nc = min(lenUrl, strlenW(lpUrl));
364 nc = min(nc, L_MAX_URL_LENGTH - 1);
365 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
366 if(Last->u.Link.szUrl != NULL)
368 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
371 else
372 Last->u.Link.szUrl = NULL;
374 linktext = NULL;
376 CurrentType = slText;
377 firsttag = NULL;
378 textstart = NULL;
379 continue;
381 else
383 /* we don't know what tag it is, so just continue */
384 taglen = 1;
385 linklen++;
386 if(CurrentType == slText && textstart == NULL)
388 textstart = current;
392 textlen += taglen;
393 current += taglen;
395 else
397 textlen++;
398 linklen++;
400 /* save the pointer of the current text item if we couldn't find a tag */
401 if(textstart == NULL && CurrentType == slText)
403 textstart = current;
406 current++;
410 if(textstart != NULL && textlen > 0)
412 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
413 if(Last == NULL)
415 ERR("Unable to create new document item!\n");
416 return docitems;
418 if(CurrentType == slLink)
420 int nc;
422 if(!(infoPtr->Style & WS_DISABLED))
424 Last->u.Link.state |= LIS_ENABLED;
426 /* Copy the tag parameters */
427 if(lpID != NULL)
429 nc = min(lenId, strlenW(lpID));
430 nc = min(nc, MAX_LINKID_TEXT - 1);
431 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
432 if(Last->u.Link.szID != NULL)
434 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
437 else
438 Last->u.Link.szID = NULL;
439 if(lpUrl != NULL)
441 nc = min(lenUrl, strlenW(lpUrl));
442 nc = min(nc, L_MAX_URL_LENGTH - 1);
443 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
444 if(Last->u.Link.szUrl != NULL)
446 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
449 else
450 Last->u.Link.szUrl = NULL;
452 docitems++;
455 if(linktext != NULL && linklen > 0)
457 /* we got an unclosed link, just display the text */
458 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
459 if(Last == NULL)
461 ERR("Unable to create new document item!\n");
462 return docitems;
464 docitems++;
467 return docitems;
470 /***********************************************************************
471 * SYSLINK_RepaintLink
472 * Repaints a link.
474 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
476 PDOC_TEXTBLOCK bl;
477 int n;
479 if(DocItem->Type != slLink)
481 ERR("DocItem not a link!\n");
482 return;
485 bl = DocItem->Blocks;
486 if (bl != NULL)
488 n = DocItem->nText;
490 while(n > 0)
492 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
493 n -= bl->nChars + bl->nSkip;
494 bl++;
499 /***********************************************************************
500 * SYSLINK_GetLinkItemByIndex
501 * Retrieves a document link by its index
503 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
505 PDOC_ITEM Current = infoPtr->Items;
507 while(Current != NULL)
509 if((Current->Type == slLink) && (iLink-- <= 0))
511 return Current;
513 Current = Current->Next;
515 return NULL;
518 /***********************************************************************
519 * SYSLINK_GetFocusLink
520 * Retrieves the link that has the LIS_FOCUSED bit
522 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
524 PDOC_ITEM Current = infoPtr->Items;
525 int id = 0;
527 while(Current != NULL)
529 if((Current->Type == slLink))
531 if(Current->u.Link.state & LIS_FOCUSED)
533 if(LinkId != NULL)
534 *LinkId = id;
535 return Current;
537 id++;
539 Current = Current->Next;
541 return NULL;
544 /***********************************************************************
545 * SYSLINK_GetNextLink
546 * Gets the next link
548 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
550 for(Current = (Current != NULL ? Current->Next : infoPtr->Items);
551 Current != NULL;
552 Current = Current->Next)
554 if(Current->Type == slLink)
556 return Current;
559 return NULL;
562 /***********************************************************************
563 * SYSLINK_GetPrevLink
564 * Gets the previous link
566 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
568 if(Current == NULL)
570 /* returns the last link */
571 PDOC_ITEM Last = NULL;
573 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
575 if(Current->Type == slLink)
577 Last = Current;
580 return Last;
582 else
584 /* returns the previous link */
585 PDOC_ITEM Cur, Prev = NULL;
587 for(Cur = infoPtr->Items; Cur != NULL; Cur = Cur->Next)
589 if(Cur == Current)
591 break;
593 if(Cur->Type == slLink)
595 Prev = Cur;
598 return Prev;
602 /***********************************************************************
603 * SYSLINK_WrapLine
604 * Tries to wrap a line.
606 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int *LineLen,
607 int nFit, LPSIZE Extent)
609 WCHAR *Current;
611 if(nFit == *LineLen)
613 return FALSE;
616 *LineLen = nFit;
618 Current = Text + nFit;
620 /* check if we're in the middle of a word */
621 if((*Current) != BreakChar)
623 /* search for the beginning of the word */
624 while(Current > Text && (*(Current - 1)) != BreakChar)
626 Current--;
627 (*LineLen)--;
630 if((*LineLen) == 0)
632 Extent->cx = 0;
633 Extent->cy = 0;
635 return TRUE;
638 return TRUE;
641 /***********************************************************************
642 * SYSLINK_Render
643 * Renders the document in memory
645 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
647 RECT rc;
648 PDOC_ITEM Current;
649 HGDIOBJ hOldFont;
650 int x, y, LineHeight;
651 SIZE szDoc;
653 szDoc.cx = szDoc.cy = 0;
655 rc = *pRect;
656 rc.right -= SL_RIGHTMARGIN;
657 rc.bottom -= SL_BOTTOMMARGIN;
659 if(rc.right - SL_LEFTMARGIN < 0)
660 rc.right = MAXLONG;
661 if (rc.bottom - SL_TOPMARGIN < 0)
662 rc.bottom = MAXLONG;
664 hOldFont = SelectObject(hdc, infoPtr->Font);
666 x = SL_LEFTMARGIN;
667 y = SL_TOPMARGIN;
668 LineHeight = 0;
670 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
672 int n, nBlocks;
673 LPWSTR tx;
674 PDOC_TEXTBLOCK bl, cbl;
675 INT nFit;
676 SIZE szDim;
678 if(Current->nText == 0)
680 continue;
683 tx = Current->Text;
684 n = Current->nText;
686 Free(Current->Blocks);
687 Current->Blocks = NULL;
688 bl = NULL;
689 nBlocks = 0;
691 if(Current->Type == slText)
693 SelectObject(hdc, infoPtr->Font);
695 else if(Current->Type == slLink)
697 SelectObject(hdc, infoPtr->LinkFont);
700 while(n > 0)
702 int SkipChars = 0;
704 /* skip break characters unless they're the first of the doc item */
705 if(tx != Current->Text || x == SL_LEFTMARGIN)
707 while(n > 0 && (*tx) == infoPtr->BreakChar)
709 tx++;
710 SkipChars++;
711 n--;
715 if((n == 0 && SkipChars != 0) ||
716 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
718 int LineLen = n;
719 BOOL Wrap = FALSE;
720 PDOC_TEXTBLOCK nbl;
722 if(n != 0)
724 Wrap = SYSLINK_WrapLine(tx, infoPtr->BreakChar, &LineLen, nFit, &szDim);
726 if(LineLen == 0)
728 if(x > SL_LEFTMARGIN)
730 /* move one line down, the word didn't fit into the line */
731 x = SL_LEFTMARGIN;
732 y += LineHeight;
733 LineHeight = 0;
734 continue;
736 else
738 /* the word starts at the beginning of the line and doesn't
739 fit into the line, so break it at the last character that fits */
740 LineLen = max(nFit, 1);
744 if(LineLen != n)
746 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
748 if(bl != NULL)
750 Free(bl);
751 bl = NULL;
752 nBlocks = 0;
754 break;
759 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
760 if (nbl != NULL)
762 bl = nbl;
763 nBlocks++;
765 cbl = bl + nBlocks - 1;
767 cbl->nChars = LineLen;
768 cbl->nSkip = SkipChars;
769 cbl->rc.left = x;
770 cbl->rc.top = y;
771 cbl->rc.right = x + szDim.cx;
772 cbl->rc.bottom = y + szDim.cy;
774 if (cbl->rc.right > szDoc.cx)
775 szDoc.cx = cbl->rc.right;
776 if (cbl->rc.bottom > szDoc.cy)
777 szDoc.cy = cbl->rc.bottom;
779 if(LineLen != 0)
781 x += szDim.cx;
782 LineHeight = max(LineHeight, szDim.cy);
784 if(Wrap)
786 x = SL_LEFTMARGIN;
787 y += LineHeight;
788 LineHeight = 0;
792 else
794 Free(bl);
795 bl = NULL;
796 nBlocks = 0;
798 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
799 break;
801 n -= LineLen;
802 tx += LineLen;
804 else
806 n--;
810 if(nBlocks != 0)
812 Current->Blocks = bl;
816 SelectObject(hdc, hOldFont);
818 pRect->right = pRect->left + szDoc.cx;
819 pRect->bottom = pRect->top + szDoc.cy;
822 /***********************************************************************
823 * SYSLINK_Draw
824 * Draws the SysLink control.
826 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
828 RECT rc;
829 PDOC_ITEM Current;
830 HFONT hOldFont;
831 COLORREF OldTextColor, OldBkColor;
833 hOldFont = SelectObject(hdc, infoPtr->Font);
834 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
835 OldBkColor = SetBkColor(hdc, infoPtr->BackColor);
837 GetClientRect(infoPtr->Self, &rc);
838 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
839 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
841 if(rc.right < 0 || rc.bottom < 0) return 0;
843 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
845 int n;
846 LPWSTR tx;
847 PDOC_TEXTBLOCK bl;
849 bl = Current->Blocks;
850 if(bl != NULL)
852 tx = Current->Text;
853 n = Current->nText;
855 if(Current->Type == slText)
857 SelectObject(hdc, infoPtr->Font);
858 SetTextColor(hdc, infoPtr->TextColor);
860 else
862 SelectObject(hdc, infoPtr->LinkFont);
863 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
866 while(n > 0)
868 tx += bl->nSkip;
869 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, ETO_OPAQUE | ETO_CLIPPED, &bl->rc, tx, bl->nChars, NULL);
870 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
872 COLORREF PrevTextColor;
873 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
874 DrawFocusRect(hdc, &bl->rc);
875 SetTextColor(hdc, PrevTextColor);
877 tx += bl->nChars;
878 n -= bl->nChars + bl->nSkip;
879 bl++;
884 SetBkColor(hdc, OldBkColor);
885 SetTextColor(hdc, OldTextColor);
886 SelectObject(hdc, hOldFont);
888 return 0;
892 /***********************************************************************
893 * SYSLINK_Paint
894 * Handles the WM_PAINT message.
896 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
898 HDC hdc;
899 PAINTSTRUCT ps;
901 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
902 if (hdc)
904 SYSLINK_Draw (infoPtr, hdc);
905 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
907 return 0;
910 /***********************************************************************
911 * SYSLINK_EraseBkgnd
912 * Handles the WM_ERASEBKGND message.
914 static LRESULT SYSLINK_EraseBkgnd (const SYSLINK_INFO *infoPtr, HDC hdc)
916 HBRUSH hbr;
917 RECT r;
919 GetClientRect(infoPtr->Self, &r);
920 hbr = CreateSolidBrush(infoPtr->BackColor);
921 FillRect(hdc, &r, hbr);
922 DeleteObject(hbr);
924 return 1;
927 /***********************************************************************
928 * SYSLINK_SetFont
929 * Set new Font for the SysLink control.
931 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
933 HDC hdc;
934 LOGFONTW lf;
935 TEXTMETRICW tm;
936 RECT rcClient;
937 HFONT hOldFont = infoPtr->Font;
938 infoPtr->Font = hFont;
940 /* free the underline font */
941 if(infoPtr->LinkFont != NULL)
943 DeleteObject(infoPtr->LinkFont);
944 infoPtr->LinkFont = NULL;
947 /* Render text position and word wrapping in memory */
948 if (GetClientRect(infoPtr->Self, &rcClient))
950 hdc = GetDC(infoPtr->Self);
951 if(hdc != NULL)
953 /* create a new underline font */
954 if(GetTextMetricsW(hdc, &tm) &&
955 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
957 lf.lfUnderline = TRUE;
958 infoPtr->LinkFont = CreateFontIndirectW(&lf);
959 infoPtr->BreakChar = tm.tmBreakChar;
961 else
963 ERR("Failed to create link font!\n");
966 SYSLINK_Render(infoPtr, hdc, &rcClient);
967 ReleaseDC(infoPtr->Self, hdc);
971 if(bRedraw)
973 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
976 return hOldFont;
979 /***********************************************************************
980 * SYSLINK_SetText
981 * Set new text for the SysLink control.
983 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
985 /* clear the document */
986 SYSLINK_ClearDoc(infoPtr);
988 if(Text == NULL || *Text == 0)
990 return TRUE;
993 /* let's parse the string and create a document */
994 if(SYSLINK_ParseText(infoPtr, Text) > 0)
996 RECT rcClient;
998 /* Render text position and word wrapping in memory */
999 if (GetClientRect(infoPtr->Self, &rcClient))
1001 HDC hdc = GetDC(infoPtr->Self);
1002 if (hdc != NULL)
1004 SYSLINK_Render(infoPtr, hdc, &rcClient);
1005 ReleaseDC(infoPtr->Self, hdc);
1007 InvalidateRect(infoPtr->Self, NULL, TRUE);
1012 return TRUE;
1015 /***********************************************************************
1016 * SYSLINK_SetFocusLink
1017 * Updates the focus status bits and focusses the specified link.
1018 * If no document item is specified, the focus bit will be removed from all links.
1019 * Returns the previous focused item.
1021 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
1023 PDOC_ITEM Current, PrevFocus = NULL;
1025 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1027 if(Current->Type == slLink)
1029 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1031 PrevFocus = Current;
1034 if(Current == DocItem)
1036 Current->u.Link.state |= LIS_FOCUSED;
1038 else
1040 Current->u.Link.state &= ~LIS_FOCUSED;
1045 return PrevFocus;
1048 /***********************************************************************
1049 * SYSLINK_SetItem
1050 * Sets the states and attributes of a link item.
1052 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1054 PDOC_ITEM di;
1055 int nc;
1056 PWSTR szId = NULL;
1057 PWSTR szUrl = NULL;
1058 BOOL Repaint = FALSE;
1060 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1062 ERR("Invalid Flags!\n");
1063 return FALSE;
1066 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1067 if(di == NULL)
1069 ERR("Link %d couldn't be found\n", Item->iLink);
1070 return FALSE;
1073 if(Item->mask & LIF_ITEMID)
1075 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1076 szId = Alloc((nc + 1) * sizeof(WCHAR));
1077 if(szId)
1079 lstrcpynW(szId, Item->szID, nc + 1);
1081 else
1083 ERR("Unable to allocate memory for link id\n");
1084 return FALSE;
1088 if(Item->mask & LIF_URL)
1090 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1091 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1092 if(szUrl)
1094 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1096 else
1098 Free(szId);
1100 ERR("Unable to allocate memory for link url\n");
1101 return FALSE;
1105 if(Item->mask & LIF_ITEMID)
1107 Free(di->u.Link.szID);
1108 di->u.Link.szID = szId;
1111 if(Item->mask & LIF_URL)
1113 Free(di->u.Link.szUrl);
1114 di->u.Link.szUrl = szUrl;
1117 if(Item->mask & LIF_STATE)
1119 UINT oldstate = di->u.Link.state;
1120 /* clear the masked bits */
1121 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1122 /* copy the bits */
1123 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1124 Repaint = (oldstate != di->u.Link.state);
1126 /* update the focus */
1127 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1130 if(Repaint)
1132 SYSLINK_RepaintLink(infoPtr, di);
1135 return TRUE;
1138 /***********************************************************************
1139 * SYSLINK_GetItem
1140 * Retrieves the states and attributes of a link item.
1142 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1144 PDOC_ITEM di;
1146 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1148 ERR("Invalid Flags!\n");
1149 return FALSE;
1152 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1153 if(di == NULL)
1155 ERR("Link %d couldn't be found\n", Item->iLink);
1156 return FALSE;
1159 if(Item->mask & LIF_STATE)
1161 Item->state = (di->u.Link.state & Item->stateMask);
1162 if(!infoPtr->HasFocus)
1164 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1165 Item->state &= ~LIS_FOCUSED;
1169 if(Item->mask & LIF_ITEMID)
1171 if(di->u.Link.szID)
1173 lstrcpyW(Item->szID, di->u.Link.szID);
1175 else
1177 Item->szID[0] = 0;
1181 if(Item->mask & LIF_URL)
1183 if(di->u.Link.szUrl)
1185 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1187 else
1189 Item->szUrl[0] = 0;
1193 return TRUE;
1196 /***********************************************************************
1197 * SYSLINK_PtInDocItem
1198 * Determines if a point is in the region of a document item
1200 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1202 PDOC_TEXTBLOCK bl;
1203 int n;
1205 bl = DocItem->Blocks;
1206 if (bl != NULL)
1208 n = DocItem->nText;
1210 while(n > 0)
1212 if (PtInRect(&bl->rc, pt))
1214 return TRUE;
1216 n -= bl->nChars + bl->nSkip;
1217 bl++;
1221 return FALSE;
1224 /***********************************************************************
1225 * SYSLINK_HitTest
1226 * Determines the link the user clicked on.
1228 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1230 PDOC_ITEM Current;
1231 int id = 0;
1233 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1235 if(Current->Type == slLink)
1237 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1239 HitTest->item.mask = 0;
1240 HitTest->item.iLink = id;
1241 HitTest->item.state = 0;
1242 HitTest->item.stateMask = 0;
1243 if(Current->u.Link.szID)
1245 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1247 else
1249 HitTest->item.szID[0] = 0;
1251 if(Current->u.Link.szUrl)
1253 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1255 else
1257 HitTest->item.szUrl[0] = 0;
1259 return TRUE;
1261 id++;
1265 return FALSE;
1268 /***********************************************************************
1269 * SYSLINK_GetIdealHeight
1270 * Returns the preferred height of a link at the current control's width.
1272 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1274 HDC hdc = GetDC(infoPtr->Self);
1275 if(hdc != NULL)
1277 LRESULT height;
1278 TEXTMETRICW tm;
1279 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1281 if(GetTextMetricsW(hdc, &tm))
1283 height = tm.tmHeight;
1285 else
1287 height = 0;
1289 SelectObject(hdc, hOldFont);
1290 ReleaseDC(infoPtr->Self, hdc);
1292 return height;
1294 return 0;
1297 /***********************************************************************
1298 * SYSLINK_SendParentNotify
1299 * Sends a WM_NOTIFY message to the parent window.
1301 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1303 NMLINK nml;
1305 nml.hdr.hwndFrom = infoPtr->Self;
1306 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1307 nml.hdr.code = code;
1309 nml.item.mask = 0;
1310 nml.item.iLink = iLink;
1311 nml.item.state = 0;
1312 nml.item.stateMask = 0;
1313 if(Link->u.Link.szID)
1315 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1317 else
1319 nml.item.szID[0] = 0;
1321 if(Link->u.Link.szUrl)
1323 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1325 else
1327 nml.item.szUrl[0] = 0;
1330 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1333 /***********************************************************************
1334 * SYSLINK_SetFocus
1335 * Handles receiving the input focus.
1337 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1339 PDOC_ITEM Focus;
1341 infoPtr->HasFocus = TRUE;
1343 /* We always select the first link, even if we activated the control using
1344 SHIFT+TAB. This is the default behavior */
1345 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1346 if(Focus != NULL)
1348 SYSLINK_SetFocusLink(infoPtr, Focus);
1349 SYSLINK_RepaintLink(infoPtr, Focus);
1351 return 0;
1354 /***********************************************************************
1355 * SYSLINK_KillFocus
1356 * Handles losing the input focus.
1358 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1360 PDOC_ITEM Focus;
1362 infoPtr->HasFocus = FALSE;
1363 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1365 if(Focus != NULL)
1367 SYSLINK_RepaintLink(infoPtr, Focus);
1370 return 0;
1373 /***********************************************************************
1374 * SYSLINK_LinkAtPt
1375 * Returns a link at the specified position
1377 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1379 PDOC_ITEM Current;
1380 int id = 0;
1382 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1384 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1385 (!MustBeEnabled || (MustBeEnabled && (Current->u.Link.state & LIS_ENABLED))))
1387 if(LinkId != NULL)
1389 *LinkId = id;
1391 return Current;
1393 id++;
1396 return NULL;
1399 /***********************************************************************
1400 * SYSLINK_LButtonDown
1401 * Handles mouse clicks
1403 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1405 PDOC_ITEM Current, Old;
1406 int id;
1408 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1409 if(Current != NULL)
1411 SetFocus(infoPtr->Self);
1413 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1414 if(Old != NULL && Old != Current)
1416 SYSLINK_RepaintLink(infoPtr, Old);
1418 infoPtr->MouseDownID = id;
1419 SYSLINK_RepaintLink(infoPtr, Current);
1422 return 0;
1425 /***********************************************************************
1426 * SYSLINK_LButtonUp
1427 * Handles mouse clicks
1429 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1431 if(infoPtr->MouseDownID > -1)
1433 PDOC_ITEM Current;
1434 int id;
1436 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1437 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1439 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1443 infoPtr->MouseDownID = -1;
1445 return 0;
1448 /***********************************************************************
1449 * SYSLINK_OnEnter
1450 * Handles ENTER key events
1452 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1454 if(infoPtr->HasFocus)
1456 PDOC_ITEM Focus;
1457 int id;
1459 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1460 if(Focus != NULL)
1462 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1463 return TRUE;
1466 return FALSE;
1469 /***********************************************************************
1470 * SYSKEY_SelectNextPrevLink
1471 * Changes the currently focused link
1473 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1475 if(infoPtr->HasFocus)
1477 PDOC_ITEM Focus;
1478 int id;
1480 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1481 if(Focus != NULL)
1483 PDOC_ITEM NewFocus, OldFocus;
1485 if(Prev)
1486 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1487 else
1488 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1490 if(NewFocus != NULL)
1492 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1494 if(OldFocus && OldFocus != NewFocus)
1496 SYSLINK_RepaintLink(infoPtr, OldFocus);
1498 SYSLINK_RepaintLink(infoPtr, NewFocus);
1499 return TRUE;
1503 return FALSE;
1506 /***********************************************************************
1507 * SYSKEY_SelectNextPrevLink
1508 * Determines if there's a next or previous link to decide whether the control
1509 * should capture the tab key message
1511 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1513 PDOC_ITEM Focus, NewFocus;
1515 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1516 if(Prev)
1517 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1518 else
1519 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1521 return NewFocus == NULL;
1524 /***********************************************************************
1525 * SYSLINK_GetIdealSize
1526 * Calculates the ideal size of a link control at a given maximum width.
1528 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1530 RECT rc;
1531 HDC hdc;
1533 rc.left = rc.top = rc.bottom = 0;
1534 rc.right = cxMaxWidth;
1536 hdc = GetDC(infoPtr->Self);
1537 if (hdc != NULL)
1539 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1541 SYSLINK_Render(infoPtr, hdc, &rc);
1543 SelectObject(hdc, hOldFont);
1544 ReleaseDC(infoPtr->Self, hdc);
1546 lpSize->cx = rc.right;
1547 lpSize->cy = rc.bottom;
1551 /***********************************************************************
1552 * SysLinkWindowProc
1554 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1555 WPARAM wParam, LPARAM lParam)
1557 SYSLINK_INFO *infoPtr;
1559 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1561 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1563 if (!infoPtr && message != WM_CREATE)
1564 goto HandleDefaultMessage;
1566 switch(message) {
1567 case WM_PRINTCLIENT:
1568 case WM_PAINT:
1569 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1571 case WM_ERASEBKGND:
1572 return SYSLINK_EraseBkgnd(infoPtr, (HDC)wParam);
1574 case WM_SETCURSOR:
1576 LHITTESTINFO ht;
1577 DWORD mp = GetMessagePos();
1579 ht.pt.x = (short)LOWORD(mp);
1580 ht.pt.y = (short)HIWORD(mp);
1582 ScreenToClient(infoPtr->Self, &ht.pt);
1583 if(SYSLINK_HitTest (infoPtr, &ht))
1585 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1586 return TRUE;
1588 /* let the default window proc handle this message */
1589 goto HandleDefaultMessage;
1592 case WM_SIZE:
1594 RECT rcClient;
1595 if (GetClientRect(infoPtr->Self, &rcClient))
1597 HDC hdc = GetDC(infoPtr->Self);
1598 if(hdc != NULL)
1600 SYSLINK_Render(infoPtr, hdc, &rcClient);
1601 ReleaseDC(infoPtr->Self, hdc);
1604 return 0;
1607 case WM_GETFONT:
1608 return (LRESULT)infoPtr->Font;
1610 case WM_SETFONT:
1611 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1613 case WM_SETTEXT:
1614 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1615 goto HandleDefaultMessage;
1617 case WM_LBUTTONDOWN:
1619 POINT pt;
1620 pt.x = (short)LOWORD(lParam);
1621 pt.y = (short)HIWORD(lParam);
1622 return SYSLINK_LButtonDown(infoPtr, &pt);
1624 case WM_LBUTTONUP:
1626 POINT pt;
1627 pt.x = (short)LOWORD(lParam);
1628 pt.y = (short)HIWORD(lParam);
1629 return SYSLINK_LButtonUp(infoPtr, &pt);
1632 case WM_KEYDOWN:
1634 switch(wParam)
1636 case VK_RETURN:
1637 SYSLINK_OnEnter(infoPtr);
1638 return 0;
1639 case VK_TAB:
1641 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1642 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1643 return 0;
1646 goto HandleDefaultMessage;
1649 case WM_GETDLGCODE:
1651 LRESULT Ret = DLGC_HASSETSEL;
1652 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1653 switch(vk)
1655 case VK_RETURN:
1656 Ret |= DLGC_WANTMESSAGE;
1657 break;
1658 case VK_TAB:
1660 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1661 if(!SYSLINK_NoNextLink(infoPtr, shift))
1663 Ret |= DLGC_WANTTAB;
1665 else
1667 Ret |= DLGC_WANTCHARS;
1669 break;
1672 return Ret;
1675 case WM_NCHITTEST:
1677 POINT pt;
1678 RECT rc;
1679 pt.x = (short)LOWORD(lParam);
1680 pt.y = (short)HIWORD(lParam);
1682 GetClientRect(infoPtr->Self, &rc);
1683 ScreenToClient(infoPtr->Self, &pt);
1684 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1686 return HTNOWHERE;
1689 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1691 return HTCLIENT;
1694 return HTTRANSPARENT;
1697 case LM_HITTEST:
1698 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1700 case LM_SETITEM:
1701 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1703 case LM_GETITEM:
1704 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1706 case LM_GETIDEALHEIGHT:
1707 if (lParam)
1709 /* LM_GETIDEALSIZE */
1710 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1712 return SYSLINK_GetIdealHeight(infoPtr);
1714 case WM_SETFOCUS:
1715 return SYSLINK_SetFocus(infoPtr);
1717 case WM_KILLFOCUS:
1718 return SYSLINK_KillFocus(infoPtr);
1720 case WM_ENABLE:
1721 infoPtr->Style &= ~WS_DISABLED;
1722 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1723 InvalidateRect (infoPtr->Self, NULL, FALSE);
1724 return 0;
1726 case WM_STYLECHANGED:
1727 if (wParam == GWL_STYLE)
1729 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1731 InvalidateRect(infoPtr->Self, NULL, TRUE);
1733 return 0;
1735 case WM_CREATE:
1736 /* allocate memory for info struct */
1737 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1738 if (!infoPtr) return -1;
1739 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1741 /* initialize the info struct */
1742 infoPtr->Self = hwnd;
1743 infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1744 infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style;
1745 infoPtr->Font = 0;
1746 infoPtr->LinkFont = 0;
1747 infoPtr->Items = NULL;
1748 infoPtr->HasFocus = FALSE;
1749 infoPtr->MouseDownID = -1;
1750 infoPtr->TextColor = comctl32_color.clrWindowText;
1751 infoPtr->LinkColor = comctl32_color.clrHighlight;
1752 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1753 infoPtr->BackColor = infoPtr->Style & LWS_TRANSPARENT ?
1754 comctl32_color.clrWindow : comctl32_color.clrBtnFace;
1755 infoPtr->BreakChar = ' ';
1756 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1757 SYSLINK_SetText(infoPtr, ((LPCREATESTRUCTW)lParam)->lpszName);
1758 return 0;
1760 case WM_DESTROY:
1761 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1762 SYSLINK_ClearDoc(infoPtr);
1763 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1764 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1765 SetWindowLongPtrW(hwnd, 0, 0);
1766 Free (infoPtr);
1767 return 0;
1769 case WM_SYSCOLORCHANGE:
1770 COMCTL32_RefreshSysColors();
1771 if (infoPtr->Style & LWS_TRANSPARENT)
1772 infoPtr->BackColor = comctl32_color.clrWindow;
1773 return 0;
1775 default:
1776 HandleDefaultMessage:
1777 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1779 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1781 return DefWindowProcW(hwnd, message, wParam, lParam);
1786 /***********************************************************************
1787 * SYSLINK_Register [Internal]
1789 * Registers the SysLink window class.
1791 VOID SYSLINK_Register (void)
1793 WNDCLASSW wndClass;
1795 ZeroMemory (&wndClass, sizeof(wndClass));
1796 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1797 wndClass.lpfnWndProc = SysLinkWindowProc;
1798 wndClass.cbClsExtra = 0;
1799 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1800 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1801 wndClass.lpszClassName = WC_LINK;
1803 RegisterClassW (&wndClass);
1807 /***********************************************************************
1808 * SYSLINK_Unregister [Internal]
1810 * Unregisters the SysLink window class.
1812 VOID SYSLINK_Unregister (void)
1814 UnregisterClassW (WC_LINK, NULL);