quartz: Free two assert calls from having side effects.
[wine/testsucceed.git] / dlls / comctl32 / syslink.c
blobb2dfdad8efe38e3a512fdff30a42c77e813aba64
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(syslink);
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 BOOL IgnoreReturn; /* (infoPtr->Style & LWS_IGNORERETURN) on creation */
100 } SYSLINK_INFO;
102 static const WCHAR SL_LINKOPEN[] = { '<','a', 0 };
103 static const WCHAR SL_HREF[] = { 'h','r','e','f','=','\"',0 };
104 static const WCHAR SL_ID[] = { 'i','d','=','\"',0 };
105 static const WCHAR SL_LINKCLOSE[] = { '<','/','a','>',0 };
107 /* Control configuration constants */
109 #define SL_LEFTMARGIN (0)
110 #define SL_TOPMARGIN (0)
111 #define SL_RIGHTMARGIN (0)
112 #define SL_BOTTOMMARGIN (0)
114 /***********************************************************************
115 * SYSLINK_FreeDocItem
116 * Frees all data and gdi objects associated with a document item
118 static VOID SYSLINK_FreeDocItem (PDOC_ITEM DocItem)
120 if(DocItem->Type == slLink)
122 Free(DocItem->u.Link.szID);
123 Free(DocItem->u.Link.szUrl);
126 /* we don't free Text because it's just a pointer to a character in the
127 entire window text string */
129 Free(DocItem);
132 /***********************************************************************
133 * SYSLINK_AppendDocItem
134 * Create and append a new document item.
136 static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UINT textlen,
137 SL_ITEM_TYPE type, PDOC_ITEM LastItem)
139 PDOC_ITEM Item;
141 textlen = min(textlen, strlenW(Text));
142 Item = Alloc(FIELD_OFFSET(DOC_ITEM, Text[textlen + 1]));
143 if(Item == NULL)
145 ERR("Failed to alloc DOC_ITEM structure!\n");
146 return NULL;
149 Item->Next = NULL;
150 Item->nText = textlen;
151 Item->Type = type;
152 Item->Blocks = NULL;
154 if(LastItem != NULL)
156 LastItem->Next = Item;
158 else
160 infoPtr->Items = Item;
163 lstrcpynW(Item->Text, Text, textlen + 1);
165 return Item;
168 /***********************************************************************
169 * SYSLINK_ClearDoc
170 * Clears the document tree
172 static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
174 PDOC_ITEM Item, Next;
176 Item = infoPtr->Items;
177 while(Item != NULL)
179 Next = Item->Next;
180 SYSLINK_FreeDocItem(Item);
181 Item = Next;
184 infoPtr->Items = NULL;
187 /***********************************************************************
188 * SYSLINK_ParseText
189 * Parses the window text string and creates a document. Returns the
190 * number of document items created.
192 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
194 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
195 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
196 PDOC_ITEM Last = NULL;
197 SL_ITEM_TYPE CurrentType = slText;
198 LPCWSTR lpID, lpUrl;
199 UINT lenId, lenUrl;
201 TRACE("(%p %s)\n", infoPtr, debugstr_w(Text));
203 for(current = Text; *current != 0;)
205 if(*current == '<')
207 if(!StrCmpNIW(current, SL_LINKOPEN, 2) && (CurrentType == slText))
209 BOOL ValidParam = FALSE, ValidLink = FALSE;
211 if(*(current + 2) == '>')
213 /* we just have to deal with a <a> tag */
214 taglen = 3;
215 ValidLink = TRUE;
216 ValidParam = TRUE;
217 firsttag = current;
218 linklen = 0;
219 lpID = NULL;
220 lpUrl = NULL;
222 else if(*(current + 2) == infoPtr->BreakChar)
224 /* we expect parameters, parse them */
225 LPCWSTR *CurrentParameter = NULL, tmp;
226 UINT *CurrentParameterLen = NULL;
228 taglen = 3;
229 tmp = current + taglen;
230 lpID = NULL;
231 lpUrl = NULL;
233 CheckParameter:
234 /* compare the current position with all known parameters */
235 if(!StrCmpNIW(tmp, SL_HREF, 6))
237 taglen += 6;
238 ValidParam = TRUE;
239 CurrentParameter = &lpUrl;
240 CurrentParameterLen = &lenUrl;
242 else if(!StrCmpNIW(tmp, SL_ID, 4))
244 taglen += 4;
245 ValidParam = TRUE;
246 CurrentParameter = &lpID;
247 CurrentParameterLen = &lenId;
249 else
251 ValidParam = FALSE;
254 if(ValidParam)
256 /* we got a known parameter, now search until the next " character.
257 If we can't find a " character, there's a syntax error and we just assume it's text */
258 ValidParam = FALSE;
259 *CurrentParameter = current + taglen;
260 *CurrentParameterLen = 0;
262 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
264 taglen++;
265 if(*tmp == '\"')
267 ValidParam = TRUE;
268 tmp++;
269 break;
271 (*CurrentParameterLen)++;
274 if(ValidParam)
276 /* we're done with this parameter, now there are only 2 possibilities:
277 * 1. another parameter is coming, so expect a ' ' (space) character
278 * 2. the tag is being closed, so expect a '<' character
280 if(*tmp == infoPtr->BreakChar)
282 /* we expect another parameter, do the whole thing again */
283 taglen++;
284 tmp++;
285 goto CheckParameter;
287 else if(*tmp == '>')
289 /* the tag is being closed, we're done */
290 ValidLink = TRUE;
291 taglen++;
296 if(ValidLink && ValidParam)
298 /* the <a ...> tag appears to be valid. save all information
299 so we can add the link if we find a valid </a> tag later */
300 CurrentType = slLink;
301 linktext = current + taglen;
302 linklen = 0;
303 firsttag = current;
305 else
307 taglen = 1;
308 lpID = NULL;
309 lpUrl = NULL;
310 if(textstart == NULL)
312 textstart = current;
316 else if(!StrCmpNIW(current, SL_LINKCLOSE, 4) && (CurrentType == slLink) && firsttag)
318 /* there's a <a...> tag opened, first add the previous text, if present */
319 if(textstart != NULL && textlen > 0 && firsttag > textstart)
321 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
322 if(Last == NULL)
324 ERR("Unable to create new document item!\n");
325 return docitems;
327 docitems++;
328 textstart = NULL;
329 textlen = 0;
332 /* now it's time to add the link to the document */
333 current += 4;
334 if(linktext != NULL && linklen > 0)
336 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
337 if(Last == NULL)
339 ERR("Unable to create new document item!\n");
340 return docitems;
342 docitems++;
343 if(CurrentType == slLink)
345 int nc;
347 if(!(infoPtr->Style & WS_DISABLED))
349 Last->u.Link.state |= LIS_ENABLED;
351 /* Copy the tag parameters */
352 if(lpID != NULL)
354 nc = min(lenId, strlenW(lpID));
355 nc = min(nc, MAX_LINKID_TEXT - 1);
356 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
357 if(Last->u.Link.szID != NULL)
359 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
362 else
363 Last->u.Link.szID = NULL;
364 if(lpUrl != NULL)
366 nc = min(lenUrl, strlenW(lpUrl));
367 nc = min(nc, L_MAX_URL_LENGTH - 1);
368 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
369 if(Last->u.Link.szUrl != NULL)
371 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
374 else
375 Last->u.Link.szUrl = NULL;
377 linktext = NULL;
379 CurrentType = slText;
380 firsttag = NULL;
381 textstart = NULL;
382 continue;
384 else
386 /* we don't know what tag it is, so just continue */
387 taglen = 1;
388 linklen++;
389 if(CurrentType == slText && textstart == NULL)
391 textstart = current;
395 textlen += taglen;
396 current += taglen;
398 else
400 textlen++;
401 linklen++;
403 /* save the pointer of the current text item if we couldn't find a tag */
404 if(textstart == NULL && CurrentType == slText)
406 textstart = current;
409 current++;
413 if(textstart != NULL && textlen > 0)
415 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
416 if(Last == NULL)
418 ERR("Unable to create new document item!\n");
419 return docitems;
421 if(CurrentType == slLink)
423 int nc;
425 if(!(infoPtr->Style & WS_DISABLED))
427 Last->u.Link.state |= LIS_ENABLED;
429 /* Copy the tag parameters */
430 if(lpID != NULL)
432 nc = min(lenId, strlenW(lpID));
433 nc = min(nc, MAX_LINKID_TEXT - 1);
434 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
435 if(Last->u.Link.szID != NULL)
437 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
440 else
441 Last->u.Link.szID = NULL;
442 if(lpUrl != NULL)
444 nc = min(lenUrl, strlenW(lpUrl));
445 nc = min(nc, L_MAX_URL_LENGTH - 1);
446 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
447 if(Last->u.Link.szUrl != NULL)
449 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
452 else
453 Last->u.Link.szUrl = NULL;
455 docitems++;
458 if(linktext != NULL && linklen > 0)
460 /* we got an unclosed link, just display the text */
461 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
462 if(Last == NULL)
464 ERR("Unable to create new document item!\n");
465 return docitems;
467 docitems++;
470 return docitems;
473 /***********************************************************************
474 * SYSLINK_RepaintLink
475 * Repaints a link.
477 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
479 PDOC_TEXTBLOCK bl;
480 int n;
482 if(DocItem->Type != slLink)
484 ERR("DocItem not a link!\n");
485 return;
488 bl = DocItem->Blocks;
489 if (bl != NULL)
491 n = DocItem->nText;
493 while(n > 0)
495 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
496 n -= bl->nChars + bl->nSkip;
497 bl++;
502 /***********************************************************************
503 * SYSLINK_GetLinkItemByIndex
504 * Retrieves a document link by its index
506 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
508 PDOC_ITEM Current = infoPtr->Items;
510 while(Current != NULL)
512 if((Current->Type == slLink) && (iLink-- <= 0))
514 return Current;
516 Current = Current->Next;
518 return NULL;
521 /***********************************************************************
522 * SYSLINK_GetFocusLink
523 * Retrieves the link that has the LIS_FOCUSED bit
525 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
527 PDOC_ITEM Current = infoPtr->Items;
528 int id = 0;
530 while(Current != NULL)
532 if(Current->Type == slLink)
534 if(Current->u.Link.state & LIS_FOCUSED)
536 if(LinkId != NULL)
537 *LinkId = id;
538 return Current;
540 id++;
542 Current = Current->Next;
544 return NULL;
547 /***********************************************************************
548 * SYSLINK_GetNextLink
549 * Gets the next link
551 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
553 for(Current = (Current != NULL ? Current->Next : infoPtr->Items);
554 Current != NULL;
555 Current = Current->Next)
557 if(Current->Type == slLink)
559 return Current;
562 return NULL;
565 /***********************************************************************
566 * SYSLINK_GetPrevLink
567 * Gets the previous link
569 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
571 if(Current == NULL)
573 /* returns the last link */
574 PDOC_ITEM Last = NULL;
576 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
578 if(Current->Type == slLink)
580 Last = Current;
583 return Last;
585 else
587 /* returns the previous link */
588 PDOC_ITEM Cur, Prev = NULL;
590 for(Cur = infoPtr->Items; Cur != NULL; Cur = Cur->Next)
592 if(Cur == Current)
594 break;
596 if(Cur->Type == slLink)
598 Prev = Cur;
601 return Prev;
605 /***********************************************************************
606 * SYSLINK_WrapLine
607 * Tries to wrap a line.
609 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int *LineLen,
610 int nFit, LPSIZE Extent)
612 WCHAR *Current;
614 if(nFit == *LineLen)
616 return FALSE;
619 *LineLen = nFit;
621 Current = Text + nFit;
623 /* check if we're in the middle of a word */
624 if((*Current) != BreakChar)
626 /* search for the beginning of the word */
627 while(Current > Text && (*(Current - 1)) != BreakChar)
629 Current--;
630 (*LineLen)--;
633 if((*LineLen) == 0)
635 Extent->cx = 0;
636 Extent->cy = 0;
638 return TRUE;
641 return TRUE;
644 /***********************************************************************
645 * SYSLINK_Render
646 * Renders the document in memory
648 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
650 RECT rc;
651 PDOC_ITEM Current;
652 HGDIOBJ hOldFont;
653 int x, y, LineHeight;
654 SIZE szDoc;
656 szDoc.cx = szDoc.cy = 0;
658 rc = *pRect;
659 rc.right -= SL_RIGHTMARGIN;
660 rc.bottom -= SL_BOTTOMMARGIN;
662 if(rc.right - SL_LEFTMARGIN < 0)
663 rc.right = MAXLONG;
664 if (rc.bottom - SL_TOPMARGIN < 0)
665 rc.bottom = MAXLONG;
667 hOldFont = SelectObject(hdc, infoPtr->Font);
669 x = SL_LEFTMARGIN;
670 y = SL_TOPMARGIN;
671 LineHeight = 0;
673 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
675 int n, nBlocks;
676 LPWSTR tx;
677 PDOC_TEXTBLOCK bl, cbl;
678 INT nFit;
679 SIZE szDim;
681 if(Current->nText == 0)
683 continue;
686 tx = Current->Text;
687 n = Current->nText;
689 Free(Current->Blocks);
690 Current->Blocks = NULL;
691 bl = NULL;
692 nBlocks = 0;
694 if(Current->Type == slText)
696 SelectObject(hdc, infoPtr->Font);
698 else if(Current->Type == slLink)
700 SelectObject(hdc, infoPtr->LinkFont);
703 while(n > 0)
705 int SkipChars = 0;
707 /* skip break characters unless they're the first of the doc item */
708 if(tx != Current->Text || x == SL_LEFTMARGIN)
710 while(n > 0 && (*tx) == infoPtr->BreakChar)
712 tx++;
713 SkipChars++;
714 n--;
718 if((n == 0 && SkipChars != 0) ||
719 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
721 int LineLen = n;
722 BOOL Wrap = FALSE;
723 PDOC_TEXTBLOCK nbl;
725 if(n != 0)
727 Wrap = SYSLINK_WrapLine(tx, infoPtr->BreakChar, &LineLen, nFit, &szDim);
729 if(LineLen == 0)
731 if(x > SL_LEFTMARGIN)
733 /* move one line down, the word didn't fit into the line */
734 x = SL_LEFTMARGIN;
735 y += LineHeight;
736 LineHeight = 0;
737 continue;
739 else
741 /* the word starts at the beginning of the line and doesn't
742 fit into the line, so break it at the last character that fits */
743 LineLen = max(nFit, 1);
747 if(LineLen != n)
749 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
751 if(bl != NULL)
753 Free(bl);
754 bl = NULL;
755 nBlocks = 0;
757 break;
762 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
763 if (nbl != NULL)
765 bl = nbl;
766 nBlocks++;
768 cbl = bl + nBlocks - 1;
770 cbl->nChars = LineLen;
771 cbl->nSkip = SkipChars;
772 cbl->rc.left = x;
773 cbl->rc.top = y;
774 cbl->rc.right = x + szDim.cx;
775 cbl->rc.bottom = y + szDim.cy;
777 if (cbl->rc.right > szDoc.cx)
778 szDoc.cx = cbl->rc.right;
779 if (cbl->rc.bottom > szDoc.cy)
780 szDoc.cy = cbl->rc.bottom;
782 if(LineLen != 0)
784 x += szDim.cx;
785 LineHeight = max(LineHeight, szDim.cy);
787 if(Wrap)
789 x = SL_LEFTMARGIN;
790 y += LineHeight;
791 LineHeight = 0;
795 else
797 Free(bl);
798 bl = NULL;
799 nBlocks = 0;
801 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
802 break;
804 n -= LineLen;
805 tx += LineLen;
807 else
809 n--;
813 if(nBlocks != 0)
815 Current->Blocks = bl;
819 SelectObject(hdc, hOldFont);
821 pRect->right = pRect->left + szDoc.cx;
822 pRect->bottom = pRect->top + szDoc.cy;
825 /***********************************************************************
826 * SYSLINK_Draw
827 * Draws the SysLink control.
829 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
831 RECT rc;
832 PDOC_ITEM Current;
833 HFONT hOldFont;
834 COLORREF OldTextColor, OldBkColor;
835 HBRUSH hBrush;
837 hOldFont = SelectObject(hdc, infoPtr->Font);
838 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
839 OldBkColor = SetBkColor(hdc, infoPtr->BackColor);
841 GetClientRect(infoPtr->Self, &rc);
842 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
843 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
845 if(rc.right < 0 || rc.bottom < 0) return 0;
847 hBrush = (HBRUSH)SendMessageW(infoPtr->Notify, WM_CTLCOLORSTATIC,
848 (WPARAM)hdc, (LPARAM)infoPtr->Self);
849 if (!hBrush)
850 hBrush = CreateSolidBrush(infoPtr->BackColor);
851 FillRect(hdc, &rc, hBrush);
852 DeleteObject(hBrush);
854 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
856 int n;
857 LPWSTR tx;
858 PDOC_TEXTBLOCK bl;
860 bl = Current->Blocks;
861 if(bl != NULL)
863 tx = Current->Text;
864 n = Current->nText;
866 if(Current->Type == slText)
868 SelectObject(hdc, infoPtr->Font);
869 SetTextColor(hdc, infoPtr->TextColor);
871 else
873 SelectObject(hdc, infoPtr->LinkFont);
874 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
877 while(n > 0)
879 tx += bl->nSkip;
880 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, ETO_OPAQUE | ETO_CLIPPED, &bl->rc, tx, bl->nChars, NULL);
881 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
883 COLORREF PrevTextColor;
884 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
885 DrawFocusRect(hdc, &bl->rc);
886 SetTextColor(hdc, PrevTextColor);
888 tx += bl->nChars;
889 n -= bl->nChars + bl->nSkip;
890 bl++;
895 SetBkColor(hdc, OldBkColor);
896 SetTextColor(hdc, OldTextColor);
897 SelectObject(hdc, hOldFont);
899 return 0;
903 /***********************************************************************
904 * SYSLINK_Paint
905 * Handles the WM_PAINT message.
907 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
909 HDC hdc;
910 PAINTSTRUCT ps;
912 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
913 if (hdc)
915 SYSLINK_Draw (infoPtr, hdc);
916 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
918 return 0;
921 /***********************************************************************
922 * SYSLINK_SetFont
923 * Set new Font for the SysLink control.
925 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
927 HDC hdc;
928 LOGFONTW lf;
929 TEXTMETRICW tm;
930 RECT rcClient;
931 HFONT hOldFont = infoPtr->Font;
932 infoPtr->Font = hFont;
934 /* free the underline font */
935 if(infoPtr->LinkFont != NULL)
937 DeleteObject(infoPtr->LinkFont);
938 infoPtr->LinkFont = NULL;
941 /* Render text position and word wrapping in memory */
942 if (GetClientRect(infoPtr->Self, &rcClient))
944 hdc = GetDC(infoPtr->Self);
945 if(hdc != NULL)
947 /* create a new underline font */
948 if(GetTextMetricsW(hdc, &tm) &&
949 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
951 lf.lfUnderline = TRUE;
952 infoPtr->LinkFont = CreateFontIndirectW(&lf);
953 infoPtr->BreakChar = tm.tmBreakChar;
955 else
957 ERR("Failed to create link font!\n");
960 SYSLINK_Render(infoPtr, hdc, &rcClient);
961 ReleaseDC(infoPtr->Self, hdc);
965 if(bRedraw)
967 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
970 return hOldFont;
973 /***********************************************************************
974 * SYSLINK_SetText
975 * Set new text for the SysLink control.
977 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
979 /* clear the document */
980 SYSLINK_ClearDoc(infoPtr);
982 if(Text == NULL || *Text == 0)
984 return TRUE;
987 /* let's parse the string and create a document */
988 if(SYSLINK_ParseText(infoPtr, Text) > 0)
990 RECT rcClient;
992 /* Render text position and word wrapping in memory */
993 if (GetClientRect(infoPtr->Self, &rcClient))
995 HDC hdc = GetDC(infoPtr->Self);
996 if (hdc != NULL)
998 SYSLINK_Render(infoPtr, hdc, &rcClient);
999 ReleaseDC(infoPtr->Self, hdc);
1001 InvalidateRect(infoPtr->Self, NULL, TRUE);
1006 return TRUE;
1009 /***********************************************************************
1010 * SYSLINK_SetFocusLink
1011 * Updates the focus status bits and focusses the specified link.
1012 * If no document item is specified, the focus bit will be removed from all links.
1013 * Returns the previous focused item.
1015 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
1017 PDOC_ITEM Current, PrevFocus = NULL;
1019 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1021 if(Current->Type == slLink)
1023 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1025 PrevFocus = Current;
1028 if(Current == DocItem)
1030 Current->u.Link.state |= LIS_FOCUSED;
1032 else
1034 Current->u.Link.state &= ~LIS_FOCUSED;
1039 return PrevFocus;
1042 /***********************************************************************
1043 * SYSLINK_SetItem
1044 * Sets the states and attributes of a link item.
1046 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1048 PDOC_ITEM di;
1049 int nc;
1050 PWSTR szId = NULL;
1051 PWSTR szUrl = NULL;
1052 BOOL Repaint = FALSE;
1054 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1056 ERR("Invalid Flags!\n");
1057 return FALSE;
1060 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1061 if(di == NULL)
1063 ERR("Link %d couldn't be found\n", Item->iLink);
1064 return FALSE;
1067 if(Item->mask & LIF_ITEMID)
1069 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1070 szId = Alloc((nc + 1) * sizeof(WCHAR));
1071 if(szId)
1073 lstrcpynW(szId, Item->szID, nc + 1);
1075 else
1077 ERR("Unable to allocate memory for link id\n");
1078 return FALSE;
1082 if(Item->mask & LIF_URL)
1084 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1085 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1086 if(szUrl)
1088 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1090 else
1092 Free(szId);
1094 ERR("Unable to allocate memory for link url\n");
1095 return FALSE;
1099 if(Item->mask & LIF_ITEMID)
1101 Free(di->u.Link.szID);
1102 di->u.Link.szID = szId;
1105 if(Item->mask & LIF_URL)
1107 Free(di->u.Link.szUrl);
1108 di->u.Link.szUrl = szUrl;
1111 if(Item->mask & LIF_STATE)
1113 UINT oldstate = di->u.Link.state;
1114 /* clear the masked bits */
1115 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1116 /* copy the bits */
1117 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1118 Repaint = (oldstate != di->u.Link.state);
1120 /* update the focus */
1121 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1124 if(Repaint)
1126 SYSLINK_RepaintLink(infoPtr, di);
1129 return TRUE;
1132 /***********************************************************************
1133 * SYSLINK_GetItem
1134 * Retrieves the states and attributes of a link item.
1136 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1138 PDOC_ITEM di;
1140 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1142 ERR("Invalid Flags!\n");
1143 return FALSE;
1146 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1147 if(di == NULL)
1149 ERR("Link %d couldn't be found\n", Item->iLink);
1150 return FALSE;
1153 if(Item->mask & LIF_STATE)
1155 Item->state = (di->u.Link.state & Item->stateMask);
1156 if(!infoPtr->HasFocus)
1158 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1159 Item->state &= ~LIS_FOCUSED;
1163 if(Item->mask & LIF_ITEMID)
1165 if(di->u.Link.szID)
1167 lstrcpyW(Item->szID, di->u.Link.szID);
1169 else
1171 Item->szID[0] = 0;
1175 if(Item->mask & LIF_URL)
1177 if(di->u.Link.szUrl)
1179 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1181 else
1183 Item->szUrl[0] = 0;
1187 return TRUE;
1190 /***********************************************************************
1191 * SYSLINK_PtInDocItem
1192 * Determines if a point is in the region of a document item
1194 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1196 PDOC_TEXTBLOCK bl;
1197 int n;
1199 bl = DocItem->Blocks;
1200 if (bl != NULL)
1202 n = DocItem->nText;
1204 while(n > 0)
1206 if (PtInRect(&bl->rc, pt))
1208 return TRUE;
1210 n -= bl->nChars + bl->nSkip;
1211 bl++;
1215 return FALSE;
1218 /***********************************************************************
1219 * SYSLINK_HitTest
1220 * Determines the link the user clicked on.
1222 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1224 PDOC_ITEM Current;
1225 int id = 0;
1227 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1229 if(Current->Type == slLink)
1231 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1233 HitTest->item.mask = 0;
1234 HitTest->item.iLink = id;
1235 HitTest->item.state = 0;
1236 HitTest->item.stateMask = 0;
1237 if(Current->u.Link.szID)
1239 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1241 else
1243 HitTest->item.szID[0] = 0;
1245 if(Current->u.Link.szUrl)
1247 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1249 else
1251 HitTest->item.szUrl[0] = 0;
1253 return TRUE;
1255 id++;
1259 return FALSE;
1262 /***********************************************************************
1263 * SYSLINK_GetIdealHeight
1264 * Returns the preferred height of a link at the current control's width.
1266 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1268 HDC hdc = GetDC(infoPtr->Self);
1269 if(hdc != NULL)
1271 LRESULT height;
1272 TEXTMETRICW tm;
1273 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1275 if(GetTextMetricsW(hdc, &tm))
1277 height = tm.tmHeight;
1279 else
1281 height = 0;
1283 SelectObject(hdc, hOldFont);
1284 ReleaseDC(infoPtr->Self, hdc);
1286 return height;
1288 return 0;
1291 /***********************************************************************
1292 * SYSLINK_SendParentNotify
1293 * Sends a WM_NOTIFY message to the parent window.
1295 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1297 NMLINK nml;
1299 nml.hdr.hwndFrom = infoPtr->Self;
1300 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1301 nml.hdr.code = code;
1303 nml.item.mask = 0;
1304 nml.item.iLink = iLink;
1305 nml.item.state = 0;
1306 nml.item.stateMask = 0;
1307 if(Link->u.Link.szID)
1309 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1311 else
1313 nml.item.szID[0] = 0;
1315 if(Link->u.Link.szUrl)
1317 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1319 else
1321 nml.item.szUrl[0] = 0;
1324 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1327 /***********************************************************************
1328 * SYSLINK_SetFocus
1329 * Handles receiving the input focus.
1331 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1333 PDOC_ITEM Focus;
1335 infoPtr->HasFocus = TRUE;
1337 /* We always select the first link, even if we activated the control using
1338 SHIFT+TAB. This is the default behavior */
1339 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1340 if(Focus != NULL)
1342 SYSLINK_SetFocusLink(infoPtr, Focus);
1343 SYSLINK_RepaintLink(infoPtr, Focus);
1345 return 0;
1348 /***********************************************************************
1349 * SYSLINK_KillFocus
1350 * Handles losing the input focus.
1352 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1354 PDOC_ITEM Focus;
1356 infoPtr->HasFocus = FALSE;
1357 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1359 if(Focus != NULL)
1361 SYSLINK_RepaintLink(infoPtr, Focus);
1364 return 0;
1367 /***********************************************************************
1368 * SYSLINK_LinkAtPt
1369 * Returns a link at the specified position
1371 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1373 PDOC_ITEM Current;
1374 int id = 0;
1376 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1378 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1379 (!MustBeEnabled || (MustBeEnabled && (Current->u.Link.state & LIS_ENABLED))))
1381 if(LinkId != NULL)
1383 *LinkId = id;
1385 return Current;
1387 id++;
1390 return NULL;
1393 /***********************************************************************
1394 * SYSLINK_LButtonDown
1395 * Handles mouse clicks
1397 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1399 PDOC_ITEM Current, Old;
1400 int id;
1402 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1403 if(Current != NULL)
1405 SetFocus(infoPtr->Self);
1407 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1408 if(Old != NULL && Old != Current)
1410 SYSLINK_RepaintLink(infoPtr, Old);
1412 infoPtr->MouseDownID = id;
1413 SYSLINK_RepaintLink(infoPtr, Current);
1416 return 0;
1419 /***********************************************************************
1420 * SYSLINK_LButtonUp
1421 * Handles mouse clicks
1423 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1425 if(infoPtr->MouseDownID > -1)
1427 PDOC_ITEM Current;
1428 int id;
1430 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1431 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1433 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1437 infoPtr->MouseDownID = -1;
1439 return 0;
1442 /***********************************************************************
1443 * SYSLINK_OnEnter
1444 * Handles ENTER key events
1446 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1448 if(infoPtr->HasFocus && !infoPtr->IgnoreReturn)
1450 PDOC_ITEM Focus;
1451 int id;
1453 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1454 if(Focus)
1456 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1457 return TRUE;
1460 return FALSE;
1463 /***********************************************************************
1464 * SYSKEY_SelectNextPrevLink
1465 * Changes the currently focused link
1467 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1469 if(infoPtr->HasFocus)
1471 PDOC_ITEM Focus;
1472 int id;
1474 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1475 if(Focus != NULL)
1477 PDOC_ITEM NewFocus, OldFocus;
1479 if(Prev)
1480 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1481 else
1482 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1484 if(NewFocus != NULL)
1486 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1488 if(OldFocus && OldFocus != NewFocus)
1490 SYSLINK_RepaintLink(infoPtr, OldFocus);
1492 SYSLINK_RepaintLink(infoPtr, NewFocus);
1493 return TRUE;
1497 return FALSE;
1500 /***********************************************************************
1501 * SYSKEY_SelectNextPrevLink
1502 * Determines if there's a next or previous link to decide whether the control
1503 * should capture the tab key message
1505 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1507 PDOC_ITEM Focus, NewFocus;
1509 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1510 if(Prev)
1511 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1512 else
1513 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1515 return NewFocus == NULL;
1518 /***********************************************************************
1519 * SYSLINK_GetIdealSize
1520 * Calculates the ideal size of a link control at a given maximum width.
1522 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1524 RECT rc;
1525 HDC hdc;
1527 rc.left = rc.top = rc.bottom = 0;
1528 rc.right = cxMaxWidth;
1530 hdc = GetDC(infoPtr->Self);
1531 if (hdc != NULL)
1533 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1535 SYSLINK_Render(infoPtr, hdc, &rc);
1537 SelectObject(hdc, hOldFont);
1538 ReleaseDC(infoPtr->Self, hdc);
1540 lpSize->cx = rc.right;
1541 lpSize->cy = rc.bottom;
1545 /***********************************************************************
1546 * SysLinkWindowProc
1548 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1549 WPARAM wParam, LPARAM lParam)
1551 SYSLINK_INFO *infoPtr;
1553 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1555 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1557 if (!infoPtr && message != WM_CREATE)
1558 return DefWindowProcW(hwnd, message, wParam, lParam);
1560 switch(message) {
1561 case WM_PRINTCLIENT:
1562 case WM_PAINT:
1563 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1565 case WM_ERASEBKGND:
1566 return 0;
1568 case WM_SETCURSOR:
1570 LHITTESTINFO ht;
1571 DWORD mp = GetMessagePos();
1573 ht.pt.x = (short)LOWORD(mp);
1574 ht.pt.y = (short)HIWORD(mp);
1576 ScreenToClient(infoPtr->Self, &ht.pt);
1577 if(SYSLINK_HitTest (infoPtr, &ht))
1579 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1580 return TRUE;
1583 return DefWindowProcW(hwnd, message, wParam, lParam);
1586 case WM_SIZE:
1588 RECT rcClient;
1589 if (GetClientRect(infoPtr->Self, &rcClient))
1591 HDC hdc = GetDC(infoPtr->Self);
1592 if(hdc != NULL)
1594 SYSLINK_Render(infoPtr, hdc, &rcClient);
1595 ReleaseDC(infoPtr->Self, hdc);
1598 return 0;
1601 case WM_GETFONT:
1602 return (LRESULT)infoPtr->Font;
1604 case WM_SETFONT:
1605 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1607 case WM_SETTEXT:
1608 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1609 return DefWindowProcW(hwnd, message, wParam, lParam);
1611 case WM_LBUTTONDOWN:
1613 POINT pt;
1614 pt.x = (short)LOWORD(lParam);
1615 pt.y = (short)HIWORD(lParam);
1616 return SYSLINK_LButtonDown(infoPtr, &pt);
1618 case WM_LBUTTONUP:
1620 POINT pt;
1621 pt.x = (short)LOWORD(lParam);
1622 pt.y = (short)HIWORD(lParam);
1623 return SYSLINK_LButtonUp(infoPtr, &pt);
1626 case WM_KEYDOWN:
1628 switch(wParam)
1630 case VK_RETURN:
1631 SYSLINK_OnEnter(infoPtr);
1632 return 0;
1633 case VK_TAB:
1635 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1636 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1637 return 0;
1639 default:
1640 return DefWindowProcW(hwnd, message, wParam, lParam);
1644 case WM_GETDLGCODE:
1646 LRESULT Ret = DLGC_HASSETSEL;
1647 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1648 switch(vk)
1650 case VK_RETURN:
1651 Ret |= DLGC_WANTMESSAGE;
1652 break;
1653 case VK_TAB:
1655 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1656 if(!SYSLINK_NoNextLink(infoPtr, shift))
1658 Ret |= DLGC_WANTTAB;
1660 else
1662 Ret |= DLGC_WANTCHARS;
1664 break;
1667 return Ret;
1670 case WM_NCHITTEST:
1672 POINT pt;
1673 RECT rc;
1674 pt.x = (short)LOWORD(lParam);
1675 pt.y = (short)HIWORD(lParam);
1677 GetClientRect(infoPtr->Self, &rc);
1678 ScreenToClient(infoPtr->Self, &pt);
1679 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1681 return HTNOWHERE;
1684 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1686 return HTCLIENT;
1689 return HTTRANSPARENT;
1692 case LM_HITTEST:
1693 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1695 case LM_SETITEM:
1696 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1698 case LM_GETITEM:
1699 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1701 case LM_GETIDEALHEIGHT:
1702 if (lParam)
1704 /* LM_GETIDEALSIZE */
1705 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1707 return SYSLINK_GetIdealHeight(infoPtr);
1709 case WM_SETFOCUS:
1710 return SYSLINK_SetFocus(infoPtr);
1712 case WM_KILLFOCUS:
1713 return SYSLINK_KillFocus(infoPtr);
1715 case WM_ENABLE:
1716 infoPtr->Style &= ~WS_DISABLED;
1717 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1718 InvalidateRect (infoPtr->Self, NULL, FALSE);
1719 return 0;
1721 case WM_STYLECHANGED:
1722 if (wParam == GWL_STYLE)
1724 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1726 InvalidateRect(infoPtr->Self, NULL, TRUE);
1728 return 0;
1730 case WM_CREATE:
1731 /* allocate memory for info struct */
1732 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1733 if (!infoPtr) return -1;
1734 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1736 /* initialize the info struct */
1737 infoPtr->Self = hwnd;
1738 infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1739 infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style;
1740 infoPtr->Font = 0;
1741 infoPtr->LinkFont = 0;
1742 infoPtr->Items = NULL;
1743 infoPtr->HasFocus = FALSE;
1744 infoPtr->MouseDownID = -1;
1745 infoPtr->TextColor = comctl32_color.clrWindowText;
1746 infoPtr->LinkColor = comctl32_color.clrHighlight;
1747 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1748 infoPtr->BackColor = infoPtr->Style & LWS_TRANSPARENT ?
1749 comctl32_color.clrWindow : comctl32_color.clrBtnFace;
1750 infoPtr->BreakChar = ' ';
1751 infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN;
1752 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1753 SYSLINK_SetText(infoPtr, ((LPCREATESTRUCTW)lParam)->lpszName);
1754 return 0;
1756 case WM_DESTROY:
1757 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1758 SYSLINK_ClearDoc(infoPtr);
1759 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1760 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1761 SetWindowLongPtrW(hwnd, 0, 0);
1762 Free (infoPtr);
1763 return 0;
1765 case WM_SYSCOLORCHANGE:
1766 COMCTL32_RefreshSysColors();
1767 if (infoPtr->Style & LWS_TRANSPARENT)
1768 infoPtr->BackColor = comctl32_color.clrWindow;
1769 return 0;
1771 default:
1772 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1774 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1776 return DefWindowProcW(hwnd, message, wParam, lParam);
1781 /***********************************************************************
1782 * SYSLINK_Register [Internal]
1784 * Registers the SysLink window class.
1786 VOID SYSLINK_Register (void)
1788 WNDCLASSW wndClass;
1790 ZeroMemory (&wndClass, sizeof(wndClass));
1791 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1792 wndClass.lpfnWndProc = SysLinkWindowProc;
1793 wndClass.cbClsExtra = 0;
1794 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1795 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1796 wndClass.lpszClassName = WC_LINK;
1798 RegisterClassW (&wndClass);
1802 /***********************************************************************
1803 * SYSLINK_Unregister [Internal]
1805 * Unregisters the SysLink window class.
1807 VOID SYSLINK_Unregister (void)
1809 UnregisterClassW (WC_LINK, NULL);