msvcrt: Move btowc implementation to mbcs.c file.
[wine.git] / dlls / comctl32 / syslink.c
blob802a8803e827014dea7695020b932051afe9c930
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
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "commctrl.h"
29 #include "comctl32.h"
30 #include "wine/debug.h"
31 #include "wine/list.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(syslink);
35 typedef struct
37 int nChars;
38 int nSkip;
39 RECT rc;
40 } DOC_TEXTBLOCK, *PDOC_TEXTBLOCK;
42 #define LIF_FLAGSMASK (LIF_STATE | LIF_ITEMID | LIF_URL)
43 #define LIS_MASK (LIS_FOCUSED | LIS_ENABLED | LIS_VISITED)
45 typedef enum
47 slText = 0,
48 slLink
49 } SL_ITEM_TYPE;
51 typedef struct _DOC_ITEM
53 struct list entry;
54 UINT nText; /* Number of characters of the text */
55 SL_ITEM_TYPE Type; /* type of the item */
56 PDOC_TEXTBLOCK Blocks; /* Array of text blocks */
57 union
59 struct
61 UINT state; /* Link state */
62 WCHAR *szID; /* Link ID string */
63 WCHAR *szUrl; /* Link URL string */
64 } Link;
65 struct
67 UINT Dummy;
68 } Text;
69 } u;
70 WCHAR Text[1]; /* Text of the document item */
71 } DOC_ITEM, *PDOC_ITEM;
73 typedef struct
75 HWND Self; /* The window handle for this control */
76 HWND Notify; /* The parent handle to receive notifications */
77 DWORD Style; /* Styles for this control */
78 struct list Items; /* Document items list */
79 BOOL HasFocus; /* Whether the control has the input focus */
80 int MouseDownID; /* ID of the link that the mouse button first selected */
81 HFONT Font; /* Handle to the font for text */
82 HFONT LinkFont; /* Handle to the font for links */
83 COLORREF TextColor; /* Color of the text */
84 COLORREF LinkColor; /* Color of links */
85 COLORREF VisitedColor; /* Color of visited links */
86 WCHAR BreakChar; /* Break Character for the current font */
87 BOOL IgnoreReturn; /* (infoPtr->Style & LWS_IGNORERETURN) on creation */
88 } SYSLINK_INFO;
90 /* Control configuration constants */
92 #define SL_LEFTMARGIN (0)
93 #define SL_TOPMARGIN (0)
94 #define SL_RIGHTMARGIN (0)
95 #define SL_BOTTOMMARGIN (0)
97 /***********************************************************************
98 * SYSLINK_FreeDocItem
99 * Frees all data and gdi objects associated with a document item
101 static VOID SYSLINK_FreeDocItem (PDOC_ITEM DocItem)
103 if(DocItem->Type == slLink)
105 Free(DocItem->u.Link.szID);
106 Free(DocItem->u.Link.szUrl);
109 Free(DocItem->Blocks);
111 /* we don't free Text because it's just a pointer to a character in the
112 entire window text string */
114 Free(DocItem);
117 /***********************************************************************
118 * SYSLINK_AppendDocItem
119 * Create and append a new document item.
121 static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UINT textlen,
122 SL_ITEM_TYPE type, PDOC_ITEM LastItem)
124 PDOC_ITEM Item;
126 textlen = min(textlen, lstrlenW(Text));
127 Item = Alloc(FIELD_OFFSET(DOC_ITEM, Text[textlen + 1]));
128 if(Item == NULL)
130 ERR("Failed to alloc DOC_ITEM structure!\n");
131 return NULL;
134 Item->nText = textlen;
135 Item->Type = type;
136 Item->Blocks = NULL;
137 lstrcpynW(Item->Text, Text, textlen + 1);
138 if (LastItem)
139 list_add_after(&LastItem->entry, &Item->entry);
140 else
141 list_add_tail(&infoPtr->Items, &Item->entry);
143 return Item;
146 /***********************************************************************
147 * SYSLINK_ClearDoc
148 * Clears the document tree
150 static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
152 DOC_ITEM *Item, *Item2;
154 LIST_FOR_EACH_ENTRY_SAFE(Item, Item2, &infoPtr->Items, DOC_ITEM, entry)
156 list_remove(&Item->entry);
157 SYSLINK_FreeDocItem(Item);
161 /***********************************************************************
162 * SYSLINK_ParseText
163 * Parses the window text string and creates a document. Returns the
164 * number of document items created.
166 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
168 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
169 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
170 PDOC_ITEM Last = NULL;
171 SL_ITEM_TYPE CurrentType = slText;
172 LPCWSTR lpID, lpUrl;
173 UINT lenId, lenUrl;
175 TRACE("(%p %s)\n", infoPtr, debugstr_w(Text));
177 for(current = Text; *current != 0;)
179 if(*current == '<')
181 if(!wcsnicmp(current, L"<a", 2) && (CurrentType == slText))
183 BOOL ValidParam = FALSE, ValidLink = FALSE;
185 if(*(current + 2) == '>')
187 /* we just have to deal with a <a> tag */
188 taglen = 3;
189 ValidLink = TRUE;
190 ValidParam = TRUE;
191 firsttag = current;
192 linklen = 0;
193 lpID = NULL;
194 lpUrl = NULL;
196 else if(*(current + 2) == infoPtr->BreakChar)
198 /* we expect parameters, parse them */
199 LPCWSTR *CurrentParameter = NULL, tmp;
200 UINT *CurrentParameterLen = NULL;
202 taglen = 3;
203 tmp = current + taglen;
204 lpID = NULL;
205 lpUrl = NULL;
207 CheckParameter:
208 /* compare the current position with all known parameters */
209 if(!wcsnicmp(tmp, L"href=\"", 6))
211 taglen += 6;
212 ValidParam = TRUE;
213 CurrentParameter = &lpUrl;
214 CurrentParameterLen = &lenUrl;
216 else if(!wcsnicmp(tmp, L"id=\"", 4))
218 taglen += 4;
219 ValidParam = TRUE;
220 CurrentParameter = &lpID;
221 CurrentParameterLen = &lenId;
223 else
225 ValidParam = FALSE;
228 if(ValidParam)
230 /* we got a known parameter, now search until the next " character.
231 If we can't find a " character, there's a syntax error and we just assume it's text */
232 ValidParam = FALSE;
233 *CurrentParameter = current + taglen;
234 *CurrentParameterLen = 0;
236 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
238 taglen++;
239 if(*tmp == '\"')
241 ValidParam = TRUE;
242 tmp++;
243 break;
245 (*CurrentParameterLen)++;
248 if(ValidParam)
250 /* we're done with this parameter, now there are only 2 possibilities:
251 * 1. another parameter is coming, so expect a ' ' (space) character
252 * 2. the tag is being closed, so expect a '<' character
254 if(*tmp == infoPtr->BreakChar)
256 /* we expect another parameter, do the whole thing again */
257 taglen++;
258 tmp++;
259 goto CheckParameter;
261 else if(*tmp == '>')
263 /* the tag is being closed, we're done */
264 ValidLink = TRUE;
265 taglen++;
270 if(ValidLink && ValidParam)
272 /* the <a ...> tag appears to be valid. save all information
273 so we can add the link if we find a valid </a> tag later */
274 CurrentType = slLink;
275 linktext = current + taglen;
276 linklen = 0;
277 firsttag = current;
279 else
281 taglen = 1;
282 lpID = NULL;
283 lpUrl = NULL;
284 if(textstart == NULL)
286 textstart = current;
290 else if (!wcsnicmp(current, L"</a>", 4) && (CurrentType == slLink) && firsttag)
292 /* there's a <a...> tag opened, first add the previous text, if present */
293 if(textstart != NULL && textlen > 0 && firsttag > textstart)
295 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
296 if(Last == NULL)
298 ERR("Unable to create new document item!\n");
299 return docitems;
301 docitems++;
302 textstart = NULL;
303 textlen = 0;
306 /* now it's time to add the link to the document */
307 current += 4;
308 if(linktext != NULL && linklen > 0)
310 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
311 if(Last == NULL)
313 ERR("Unable to create new document item!\n");
314 return docitems;
316 docitems++;
317 if(CurrentType == slLink)
319 int nc;
321 if(!(infoPtr->Style & WS_DISABLED))
323 Last->u.Link.state |= LIS_ENABLED;
325 /* Copy the tag parameters */
326 if(lpID != NULL)
328 nc = min(lenId, lstrlenW(lpID));
329 nc = min(nc, MAX_LINKID_TEXT - 1);
330 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
331 if(Last->u.Link.szID != NULL)
333 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
336 else
337 Last->u.Link.szID = NULL;
338 if(lpUrl != NULL)
340 nc = min(lenUrl, lstrlenW(lpUrl));
341 nc = min(nc, L_MAX_URL_LENGTH - 1);
342 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
343 if(Last->u.Link.szUrl != NULL)
345 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
348 else
349 Last->u.Link.szUrl = NULL;
351 linktext = NULL;
353 CurrentType = slText;
354 firsttag = NULL;
355 textstart = NULL;
356 continue;
358 else
360 /* we don't know what tag it is, so just continue */
361 taglen = 1;
362 linklen++;
363 if(CurrentType == slText && textstart == NULL)
365 textstart = current;
369 textlen += taglen;
370 current += taglen;
372 else
374 textlen++;
375 linklen++;
377 /* save the pointer of the current text item if we couldn't find a tag */
378 if(textstart == NULL && CurrentType == slText)
380 textstart = current;
383 current++;
387 if(textstart != NULL && textlen > 0)
389 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
390 if(Last == NULL)
392 ERR("Unable to create new document item!\n");
393 return docitems;
395 if(CurrentType == slLink)
397 int nc;
399 if(!(infoPtr->Style & WS_DISABLED))
401 Last->u.Link.state |= LIS_ENABLED;
403 /* Copy the tag parameters */
404 if(lpID != NULL)
406 nc = min(lenId, lstrlenW(lpID));
407 nc = min(nc, MAX_LINKID_TEXT - 1);
408 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
409 if(Last->u.Link.szID != NULL)
411 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
414 else
415 Last->u.Link.szID = NULL;
416 if(lpUrl != NULL)
418 nc = min(lenUrl, lstrlenW(lpUrl));
419 nc = min(nc, L_MAX_URL_LENGTH - 1);
420 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
421 if(Last->u.Link.szUrl != NULL)
423 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
426 else
427 Last->u.Link.szUrl = NULL;
429 docitems++;
432 if(linktext != NULL && linklen > 0)
434 /* we got an unclosed link, just display the text */
435 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
436 if(Last == NULL)
438 ERR("Unable to create new document item!\n");
439 return docitems;
441 docitems++;
444 return docitems;
447 /***********************************************************************
448 * SYSLINK_RepaintLink
449 * Repaints a link.
451 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
453 PDOC_TEXTBLOCK bl;
454 int n;
456 if(DocItem->Type != slLink)
458 ERR("DocItem not a link!\n");
459 return;
462 bl = DocItem->Blocks;
463 if (bl != NULL)
465 n = DocItem->nText;
467 while(n > 0)
469 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
470 n -= bl->nChars + bl->nSkip;
471 bl++;
476 /***********************************************************************
477 * SYSLINK_GetLinkItemByIndex
478 * Retrieves a document link by its index
480 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
482 DOC_ITEM *Current;
484 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
486 if ((Current->Type == slLink) && (iLink-- <= 0))
487 return Current;
489 return NULL;
492 /***********************************************************************
493 * SYSLINK_GetFocusLink
494 * Retrieves the link that has the LIS_FOCUSED bit
496 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
498 DOC_ITEM *Current;
499 int id = 0;
501 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
503 if(Current->Type == slLink)
505 if(Current->u.Link.state & LIS_FOCUSED)
507 if(LinkId != NULL)
508 *LinkId = id;
509 return Current;
511 id++;
515 return NULL;
518 /***********************************************************************
519 * SYSLINK_GetNextLink
520 * Gets the next link
522 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
524 DOC_ITEM *Next;
526 LIST_FOR_EACH_ENTRY(Next, Current ? &Current->entry : &infoPtr->Items, DOC_ITEM, entry)
528 if (Next->Type == slLink)
530 return Next;
533 return NULL;
536 /***********************************************************************
537 * SYSLINK_GetPrevLink
538 * Gets the previous link
540 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
542 DOC_ITEM *Prev;
544 LIST_FOR_EACH_ENTRY_REV(Prev, Current ? &Current->entry : list_tail(&infoPtr->Items), DOC_ITEM, entry)
546 if (Prev->Type == slLink)
548 return Prev;
552 return NULL;
555 /***********************************************************************
556 * SYSLINK_WrapLine
557 * Tries to wrap a line.
559 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int x, int *LineLen,
560 int nFit, LPSIZE Extent)
562 int i;
564 for (i = 0; i < nFit; i++) if (Text[i] == '\r' || Text[i] == '\n') break;
566 if (i == *LineLen) return FALSE;
568 /* check if we're in the middle of a word */
569 if (Text[i] != '\r' && Text[i] != '\n' && Text[i] != BreakChar)
571 /* search for the beginning of the word */
572 while (i && Text[i - 1] != BreakChar) i--;
574 if (i == 0)
576 Extent->cx = 0;
577 Extent->cy = 0;
578 if (x == SL_LEFTMARGIN) i = max( nFit, 1 );
581 *LineLen = i;
582 return TRUE;
585 /***********************************************************************
586 * SYSLINK_Render
587 * Renders the document in memory
589 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
591 RECT rc;
592 PDOC_ITEM Current;
593 HGDIOBJ hOldFont;
594 int x, y, LineHeight;
595 SIZE szDoc;
596 TEXTMETRICW tm;
598 szDoc.cx = szDoc.cy = 0;
600 rc = *pRect;
601 rc.right -= SL_RIGHTMARGIN;
602 rc.bottom -= SL_BOTTOMMARGIN;
604 if(rc.right - SL_LEFTMARGIN < 0)
605 rc.right = MAXLONG;
606 if (rc.bottom - SL_TOPMARGIN < 0)
607 rc.bottom = MAXLONG;
609 hOldFont = SelectObject(hdc, infoPtr->Font);
611 x = SL_LEFTMARGIN;
612 y = SL_TOPMARGIN;
613 GetTextMetricsW( hdc, &tm );
614 LineHeight = tm.tmHeight + tm.tmExternalLeading;
616 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
618 int n, nBlocks;
619 LPWSTR tx;
620 PDOC_TEXTBLOCK bl, cbl;
621 INT nFit;
622 SIZE szDim;
623 int SkipChars = 0;
625 if(Current->nText == 0)
627 continue;
630 tx = Current->Text;
631 n = Current->nText;
633 Free(Current->Blocks);
634 Current->Blocks = NULL;
635 bl = NULL;
636 nBlocks = 0;
638 if(Current->Type == slText)
640 SelectObject(hdc, infoPtr->Font);
642 else if(Current->Type == slLink)
644 SelectObject(hdc, infoPtr->LinkFont);
647 while(n > 0)
649 /* skip break characters unless they're the first of the doc item */
650 if(tx != Current->Text || x == SL_LEFTMARGIN)
652 if (n && *tx == '\r')
654 tx++;
655 SkipChars++;
656 n--;
658 if (n && *tx == '\n')
660 tx++;
661 SkipChars++;
662 n--;
664 while(n > 0 && (*tx) == infoPtr->BreakChar)
666 tx++;
667 SkipChars++;
668 n--;
672 if((n == 0 && SkipChars != 0) ||
673 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
675 int LineLen = n;
676 BOOL Wrap = FALSE;
677 PDOC_TEXTBLOCK nbl;
679 if(n != 0)
681 Wrap = SYSLINK_WrapLine(tx, infoPtr->BreakChar, x, &LineLen, nFit, &szDim);
683 if(LineLen == 0)
685 /* move one line down, the word didn't fit into the line */
686 x = SL_LEFTMARGIN;
687 y += LineHeight;
688 continue;
691 if(LineLen != n)
693 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
695 if(bl != NULL)
697 Free(bl);
698 bl = NULL;
699 nBlocks = 0;
701 break;
706 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
707 if (nbl != NULL)
709 bl = nbl;
710 nBlocks++;
712 cbl = bl + nBlocks - 1;
714 cbl->nChars = LineLen;
715 cbl->nSkip = SkipChars;
716 SetRect(&cbl->rc, x, y, x + szDim.cx, y + szDim.cy);
718 if (cbl->rc.right > szDoc.cx)
719 szDoc.cx = cbl->rc.right;
720 if (cbl->rc.bottom > szDoc.cy)
721 szDoc.cy = cbl->rc.bottom;
723 if(LineLen != 0)
725 x += szDim.cx;
726 if(Wrap)
728 x = SL_LEFTMARGIN;
729 y += LineHeight;
733 else
735 Free(bl);
736 bl = NULL;
737 nBlocks = 0;
739 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
740 break;
742 n -= LineLen;
743 tx += LineLen;
744 SkipChars = 0;
746 else
748 n--;
752 if(nBlocks != 0)
754 Current->Blocks = bl;
758 SelectObject(hdc, hOldFont);
760 pRect->right = pRect->left + szDoc.cx;
761 pRect->bottom = pRect->top + szDoc.cy;
764 /***********************************************************************
765 * SYSLINK_Draw
766 * Draws the SysLink control.
768 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
770 RECT rc;
771 PDOC_ITEM Current;
772 HFONT hOldFont;
773 COLORREF OldTextColor, OldBkColor;
774 HBRUSH hBrush;
775 UINT text_flags = ETO_CLIPPED;
776 UINT mode = GetBkMode( hdc );
778 hOldFont = SelectObject(hdc, infoPtr->Font);
779 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
780 OldBkColor = SetBkColor(hdc, comctl32_color.clrWindow);
782 GetClientRect(infoPtr->Self, &rc);
783 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
784 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
786 if(rc.right < 0 || rc.bottom < 0) return 0;
788 hBrush = (HBRUSH)SendMessageW(infoPtr->Notify, WM_CTLCOLORSTATIC,
789 (WPARAM)hdc, (LPARAM)infoPtr->Self);
790 if (!(infoPtr->Style & LWS_TRANSPARENT))
792 FillRect(hdc, &rc, hBrush);
793 if (GetBkMode( hdc ) == OPAQUE) text_flags |= ETO_OPAQUE;
795 else SetBkMode( hdc, TRANSPARENT );
797 DeleteObject(hBrush);
799 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
801 int n;
802 LPWSTR tx;
803 PDOC_TEXTBLOCK bl;
805 bl = Current->Blocks;
806 if(bl != NULL)
808 tx = Current->Text;
809 n = Current->nText;
811 if(Current->Type == slText)
813 SelectObject(hdc, infoPtr->Font);
814 SetTextColor(hdc, infoPtr->TextColor);
816 else
818 SelectObject(hdc, infoPtr->LinkFont);
819 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
822 while(n > 0)
824 tx += bl->nSkip;
825 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, text_flags, &bl->rc, tx, bl->nChars, NULL);
826 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
828 COLORREF PrevTextColor;
829 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
830 DrawFocusRect(hdc, &bl->rc);
831 SetTextColor(hdc, PrevTextColor);
833 tx += bl->nChars;
834 n -= bl->nChars + bl->nSkip;
835 bl++;
840 SetBkColor(hdc, OldBkColor);
841 SetTextColor(hdc, OldTextColor);
842 SelectObject(hdc, hOldFont);
843 SetBkMode(hdc, mode);
844 return 0;
848 /***********************************************************************
849 * SYSLINK_Paint
850 * Handles the WM_PAINT message.
852 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
854 HDC hdc;
855 PAINTSTRUCT ps;
857 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
858 if (hdc)
860 SYSLINK_Draw (infoPtr, hdc);
861 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
863 return 0;
866 /***********************************************************************
867 * SYSLINK_SetFont
868 * Set new Font for the SysLink control.
870 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
872 HDC hdc;
873 LOGFONTW lf;
874 TEXTMETRICW tm;
875 RECT rcClient;
876 HFONT hOldFont = infoPtr->Font;
877 infoPtr->Font = hFont;
879 /* free the underline font */
880 if(infoPtr->LinkFont != NULL)
882 DeleteObject(infoPtr->LinkFont);
883 infoPtr->LinkFont = NULL;
886 /* Render text position and word wrapping in memory */
887 if (GetClientRect(infoPtr->Self, &rcClient))
889 hdc = GetDC(infoPtr->Self);
890 if(hdc != NULL)
892 /* create a new underline font */
893 if(GetTextMetricsW(hdc, &tm) &&
894 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
896 lf.lfUnderline = TRUE;
897 infoPtr->LinkFont = CreateFontIndirectW(&lf);
898 infoPtr->BreakChar = tm.tmBreakChar;
900 else
902 ERR("Failed to create link font!\n");
905 SYSLINK_Render(infoPtr, hdc, &rcClient);
906 ReleaseDC(infoPtr->Self, hdc);
910 if(bRedraw)
912 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
915 return hOldFont;
918 /***********************************************************************
919 * SYSLINK_SetText
920 * Set new text for the SysLink control.
922 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
924 /* clear the document */
925 SYSLINK_ClearDoc(infoPtr);
927 if(Text == NULL || *Text == 0)
929 return TRUE;
932 /* let's parse the string and create a document */
933 if(SYSLINK_ParseText(infoPtr, Text) > 0)
935 RECT rcClient;
937 /* Render text position and word wrapping in memory */
938 if (GetClientRect(infoPtr->Self, &rcClient))
940 HDC hdc = GetDC(infoPtr->Self);
941 if (hdc != NULL)
943 SYSLINK_Render(infoPtr, hdc, &rcClient);
944 ReleaseDC(infoPtr->Self, hdc);
946 InvalidateRect(infoPtr->Self, NULL, TRUE);
951 return TRUE;
954 /***********************************************************************
955 * SYSLINK_SetFocusLink
956 * Updates the focus status bits and focuses the specified link.
957 * If no document item is specified, the focus bit will be removed from all links.
958 * Returns the previous focused item.
960 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
962 PDOC_ITEM Current, PrevFocus = NULL;
964 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
966 if(Current->Type == slLink)
968 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
970 PrevFocus = Current;
973 if(Current == DocItem)
975 Current->u.Link.state |= LIS_FOCUSED;
977 else
979 Current->u.Link.state &= ~LIS_FOCUSED;
984 return PrevFocus;
987 /***********************************************************************
988 * SYSLINK_SetItem
989 * Sets the states and attributes of a link item.
991 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
993 PDOC_ITEM di;
994 int nc;
995 PWSTR szId = NULL;
996 PWSTR szUrl = NULL;
997 BOOL Repaint = FALSE;
999 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1001 ERR("Invalid Flags!\n");
1002 return FALSE;
1005 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1006 if(di == NULL)
1008 ERR("Link %d couldn't be found\n", Item->iLink);
1009 return FALSE;
1012 if(Item->mask & LIF_ITEMID)
1014 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1015 szId = Alloc((nc + 1) * sizeof(WCHAR));
1016 if(szId)
1018 lstrcpynW(szId, Item->szID, nc + 1);
1020 else
1022 ERR("Unable to allocate memory for link id\n");
1023 return FALSE;
1027 if(Item->mask & LIF_URL)
1029 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1030 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1031 if(szUrl)
1033 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1035 else
1037 Free(szId);
1039 ERR("Unable to allocate memory for link url\n");
1040 return FALSE;
1044 if(Item->mask & LIF_ITEMID)
1046 Free(di->u.Link.szID);
1047 di->u.Link.szID = szId;
1050 if(Item->mask & LIF_URL)
1052 Free(di->u.Link.szUrl);
1053 di->u.Link.szUrl = szUrl;
1056 if(Item->mask & LIF_STATE)
1058 UINT oldstate = di->u.Link.state;
1059 /* clear the masked bits */
1060 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1061 /* copy the bits */
1062 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1063 Repaint = (oldstate != di->u.Link.state);
1065 /* update the focus */
1066 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1069 if(Repaint)
1071 SYSLINK_RepaintLink(infoPtr, di);
1074 return TRUE;
1077 /***********************************************************************
1078 * SYSLINK_GetItem
1079 * Retrieves the states and attributes of a link item.
1081 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1083 PDOC_ITEM di;
1085 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1087 ERR("Invalid Flags!\n");
1088 return FALSE;
1091 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1092 if(di == NULL)
1094 ERR("Link %d couldn't be found\n", Item->iLink);
1095 return FALSE;
1098 if(Item->mask & LIF_STATE)
1100 Item->state = (di->u.Link.state & Item->stateMask);
1101 if(!infoPtr->HasFocus)
1103 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1104 Item->state &= ~LIS_FOCUSED;
1108 if(Item->mask & LIF_ITEMID)
1110 if(di->u.Link.szID)
1112 lstrcpyW(Item->szID, di->u.Link.szID);
1114 else
1116 Item->szID[0] = 0;
1120 if(Item->mask & LIF_URL)
1122 if(di->u.Link.szUrl)
1124 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1126 else
1128 Item->szUrl[0] = 0;
1132 return TRUE;
1135 /***********************************************************************
1136 * SYSLINK_PtInDocItem
1137 * Determines if a point is in the region of a document item
1139 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1141 PDOC_TEXTBLOCK bl;
1142 int n;
1144 bl = DocItem->Blocks;
1145 if (bl != NULL)
1147 n = DocItem->nText;
1149 while(n > 0)
1151 if (PtInRect(&bl->rc, pt))
1153 return TRUE;
1155 n -= bl->nChars + bl->nSkip;
1156 bl++;
1160 return FALSE;
1163 /***********************************************************************
1164 * SYSLINK_HitTest
1165 * Determines the link the user clicked on.
1167 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1169 PDOC_ITEM Current;
1170 int id = 0;
1172 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
1174 if(Current->Type == slLink)
1176 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1178 HitTest->item.mask = 0;
1179 HitTest->item.iLink = id;
1180 HitTest->item.state = 0;
1181 HitTest->item.stateMask = 0;
1182 if(Current->u.Link.szID)
1184 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1186 else
1188 HitTest->item.szID[0] = 0;
1190 if(Current->u.Link.szUrl)
1192 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1194 else
1196 HitTest->item.szUrl[0] = 0;
1198 return TRUE;
1200 id++;
1204 return FALSE;
1207 /***********************************************************************
1208 * SYSLINK_GetIdealHeight
1209 * Returns the preferred height of a link at the current control's width.
1211 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1213 HDC hdc = GetDC(infoPtr->Self);
1214 if(hdc != NULL)
1216 LRESULT height;
1217 TEXTMETRICW tm;
1218 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1220 if(GetTextMetricsW(hdc, &tm))
1222 height = tm.tmHeight;
1224 else
1226 height = 0;
1228 SelectObject(hdc, hOldFont);
1229 ReleaseDC(infoPtr->Self, hdc);
1231 return height;
1233 return 0;
1236 /***********************************************************************
1237 * SYSLINK_SendParentNotify
1238 * Sends a WM_NOTIFY message to the parent window.
1240 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1242 NMLINK nml;
1244 nml.hdr.hwndFrom = infoPtr->Self;
1245 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1246 nml.hdr.code = code;
1248 nml.item.mask = 0;
1249 nml.item.iLink = iLink;
1250 nml.item.state = 0;
1251 nml.item.stateMask = 0;
1252 if(Link->u.Link.szID)
1254 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1256 else
1258 nml.item.szID[0] = 0;
1260 if(Link->u.Link.szUrl)
1262 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1264 else
1266 nml.item.szUrl[0] = 0;
1269 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1272 /***********************************************************************
1273 * SYSLINK_SetFocus
1274 * Handles receiving the input focus.
1276 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1278 PDOC_ITEM Focus;
1280 infoPtr->HasFocus = TRUE;
1282 /* We always select the first link, even if we activated the control using
1283 SHIFT+TAB. This is the default behavior */
1284 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1285 if(Focus != NULL)
1287 SYSLINK_SetFocusLink(infoPtr, Focus);
1288 SYSLINK_RepaintLink(infoPtr, Focus);
1290 return 0;
1293 /***********************************************************************
1294 * SYSLINK_KillFocus
1295 * Handles losing the input focus.
1297 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1299 PDOC_ITEM Focus;
1301 infoPtr->HasFocus = FALSE;
1302 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1304 if(Focus != NULL)
1306 SYSLINK_RepaintLink(infoPtr, Focus);
1309 return 0;
1312 /***********************************************************************
1313 * SYSLINK_LinkAtPt
1314 * Returns a link at the specified position
1316 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1318 PDOC_ITEM Current;
1319 int id = 0;
1321 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
1323 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1324 (!MustBeEnabled || (Current->u.Link.state & LIS_ENABLED)))
1326 if(LinkId != NULL)
1328 *LinkId = id;
1330 return Current;
1332 id++;
1335 return NULL;
1338 /***********************************************************************
1339 * SYSLINK_LButtonDown
1340 * Handles mouse clicks
1342 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1344 PDOC_ITEM Current, Old;
1345 int id;
1347 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1348 if(Current != NULL)
1350 SetFocus(infoPtr->Self);
1352 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1353 if(Old != NULL && Old != Current)
1355 SYSLINK_RepaintLink(infoPtr, Old);
1357 infoPtr->MouseDownID = id;
1358 SYSLINK_RepaintLink(infoPtr, Current);
1361 return 0;
1364 /***********************************************************************
1365 * SYSLINK_LButtonUp
1366 * Handles mouse clicks
1368 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1370 if(infoPtr->MouseDownID > -1)
1372 PDOC_ITEM Current;
1373 int id;
1375 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1376 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1378 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1382 infoPtr->MouseDownID = -1;
1384 return 0;
1387 /***********************************************************************
1388 * SYSLINK_OnEnter
1389 * Handles ENTER key events
1391 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1393 if(infoPtr->HasFocus && !infoPtr->IgnoreReturn)
1395 PDOC_ITEM Focus;
1396 int id;
1398 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1399 if(Focus)
1401 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1402 return TRUE;
1405 return FALSE;
1408 /***********************************************************************
1409 * SYSKEY_SelectNextPrevLink
1410 * Changes the currently focused link
1412 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1414 if(infoPtr->HasFocus)
1416 PDOC_ITEM Focus;
1417 int id;
1419 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1420 if(Focus != NULL)
1422 PDOC_ITEM NewFocus, OldFocus;
1424 if(Prev)
1425 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1426 else
1427 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1429 if(NewFocus != NULL)
1431 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1433 if(OldFocus && OldFocus != NewFocus)
1435 SYSLINK_RepaintLink(infoPtr, OldFocus);
1437 SYSLINK_RepaintLink(infoPtr, NewFocus);
1438 return TRUE;
1442 return FALSE;
1445 /***********************************************************************
1446 * SYSKEY_SelectNextPrevLink
1447 * Determines if there's a next or previous link to decide whether the control
1448 * should capture the tab key message
1450 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1452 PDOC_ITEM Focus, NewFocus;
1454 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1455 if(Prev)
1456 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1457 else
1458 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1460 return NewFocus == NULL;
1463 /***********************************************************************
1464 * SYSLINK_GetIdealSize
1465 * Calculates the ideal size of a link control at a given maximum width.
1467 static LONG SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, SIZE *lpSize)
1469 RECT rc;
1470 HDC hdc;
1472 rc.left = rc.top = rc.bottom = 0;
1473 rc.right = cxMaxWidth;
1475 hdc = GetDC(infoPtr->Self);
1476 if (hdc != NULL)
1478 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1480 SYSLINK_Render(infoPtr, hdc, &rc);
1482 SelectObject(hdc, hOldFont);
1483 ReleaseDC(infoPtr->Self, hdc);
1485 lpSize->cx = rc.right;
1486 lpSize->cy = rc.bottom;
1489 return rc.bottom;
1492 /***********************************************************************
1493 * SysLinkWindowProc
1495 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1496 WPARAM wParam, LPARAM lParam)
1498 SYSLINK_INFO *infoPtr;
1500 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1502 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1504 if (!infoPtr && message != WM_CREATE)
1505 return DefWindowProcW(hwnd, message, wParam, lParam);
1507 switch(message) {
1508 case WM_PRINTCLIENT:
1509 case WM_PAINT:
1510 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1512 case WM_ERASEBKGND:
1513 if (!(infoPtr->Style & LWS_TRANSPARENT))
1515 HDC hdc = (HDC)wParam;
1516 HBRUSH brush = CreateSolidBrush( comctl32_color.clrWindow );
1517 RECT rect;
1519 GetClipBox( hdc, &rect );
1520 FillRect( hdc, &rect, brush );
1521 DeleteObject( brush );
1522 return 1;
1524 return 0;
1526 case WM_SETCURSOR:
1528 LHITTESTINFO ht;
1529 DWORD mp = GetMessagePos();
1531 ht.pt.x = (short)LOWORD(mp);
1532 ht.pt.y = (short)HIWORD(mp);
1534 ScreenToClient(infoPtr->Self, &ht.pt);
1535 if(SYSLINK_HitTest (infoPtr, &ht))
1537 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1538 return TRUE;
1541 return DefWindowProcW(hwnd, message, wParam, lParam);
1544 case WM_SIZE:
1546 RECT rcClient;
1547 if (GetClientRect(infoPtr->Self, &rcClient))
1549 HDC hdc = GetDC(infoPtr->Self);
1550 if(hdc != NULL)
1552 SYSLINK_Render(infoPtr, hdc, &rcClient);
1553 ReleaseDC(infoPtr->Self, hdc);
1556 return 0;
1559 case WM_GETFONT:
1560 return (LRESULT)infoPtr->Font;
1562 case WM_SETFONT:
1563 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1565 case WM_SETTEXT:
1566 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1567 return DefWindowProcW(hwnd, message, wParam, lParam);
1569 case WM_LBUTTONDOWN:
1571 POINT pt;
1572 pt.x = (short)LOWORD(lParam);
1573 pt.y = (short)HIWORD(lParam);
1574 return SYSLINK_LButtonDown(infoPtr, &pt);
1576 case WM_LBUTTONUP:
1578 POINT pt;
1579 pt.x = (short)LOWORD(lParam);
1580 pt.y = (short)HIWORD(lParam);
1581 return SYSLINK_LButtonUp(infoPtr, &pt);
1584 case WM_KEYDOWN:
1586 switch(wParam)
1588 case VK_RETURN:
1589 SYSLINK_OnEnter(infoPtr);
1590 return 0;
1591 case VK_TAB:
1593 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1594 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1595 return 0;
1597 default:
1598 return DefWindowProcW(hwnd, message, wParam, lParam);
1602 case WM_GETDLGCODE:
1604 LRESULT Ret = DLGC_HASSETSEL;
1605 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1606 switch(vk)
1608 case VK_RETURN:
1609 Ret |= DLGC_WANTMESSAGE;
1610 break;
1611 case VK_TAB:
1613 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1614 if(!SYSLINK_NoNextLink(infoPtr, shift))
1616 Ret |= DLGC_WANTTAB;
1618 else
1620 Ret |= DLGC_WANTCHARS;
1622 break;
1625 return Ret;
1628 case WM_NCHITTEST:
1630 POINT pt;
1631 RECT rc;
1632 pt.x = (short)LOWORD(lParam);
1633 pt.y = (short)HIWORD(lParam);
1635 GetClientRect(infoPtr->Self, &rc);
1636 ScreenToClient(infoPtr->Self, &pt);
1637 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1639 return HTNOWHERE;
1642 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1644 return HTCLIENT;
1647 return HTTRANSPARENT;
1650 case LM_HITTEST:
1651 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1653 case LM_SETITEM:
1654 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1656 case LM_GETITEM:
1657 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1659 case LM_GETIDEALHEIGHT:
1660 if (lParam)
1661 return SYSLINK_GetIdealSize(infoPtr, (int)wParam, (SIZE *)lParam);
1662 else
1663 return SYSLINK_GetIdealHeight(infoPtr);
1665 case WM_SETFOCUS:
1666 return SYSLINK_SetFocus(infoPtr);
1668 case WM_KILLFOCUS:
1669 return SYSLINK_KillFocus(infoPtr);
1671 case WM_ENABLE:
1672 infoPtr->Style &= ~WS_DISABLED;
1673 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1674 InvalidateRect (infoPtr->Self, NULL, FALSE);
1675 return 0;
1677 case WM_STYLECHANGED:
1678 if (wParam == GWL_STYLE)
1680 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1682 InvalidateRect(infoPtr->Self, NULL, TRUE);
1684 return 0;
1686 case WM_CREATE:
1688 CREATESTRUCTW *cs = (CREATESTRUCTW*)lParam;
1690 /* allocate memory for info struct */
1691 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1692 if (!infoPtr) return -1;
1693 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1695 /* initialize the info struct */
1696 infoPtr->Self = hwnd;
1697 infoPtr->Notify = cs->hwndParent;
1698 infoPtr->Style = cs->style;
1699 infoPtr->Font = 0;
1700 infoPtr->LinkFont = 0;
1701 list_init(&infoPtr->Items);
1702 infoPtr->HasFocus = FALSE;
1703 infoPtr->MouseDownID = -1;
1704 infoPtr->TextColor = comctl32_color.clrWindowText;
1705 infoPtr->LinkColor = comctl32_color.clrHighlight;
1706 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1707 infoPtr->BreakChar = ' ';
1708 infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN;
1709 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1710 SYSLINK_SetText(infoPtr, cs->lpszName);
1711 return 0;
1713 case WM_DESTROY:
1714 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1715 SYSLINK_ClearDoc(infoPtr);
1716 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1717 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1718 SetWindowLongPtrW(hwnd, 0, 0);
1719 Free (infoPtr);
1720 return 0;
1722 case WM_SYSCOLORCHANGE:
1723 COMCTL32_RefreshSysColors();
1724 return 0;
1726 default:
1727 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1729 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1731 return DefWindowProcW(hwnd, message, wParam, lParam);
1736 /***********************************************************************
1737 * SYSLINK_Register [Internal]
1739 * Registers the SysLink window class.
1741 VOID SYSLINK_Register (void)
1743 WNDCLASSW wndClass;
1745 ZeroMemory (&wndClass, sizeof(wndClass));
1746 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1747 wndClass.lpfnWndProc = SysLinkWindowProc;
1748 wndClass.cbClsExtra = 0;
1749 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1750 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1751 wndClass.lpszClassName = WC_LINK;
1753 RegisterClassW (&wndClass);
1757 /***********************************************************************
1758 * SYSLINK_Unregister [Internal]
1760 * Unregisters the SysLink window class.
1762 VOID SYSLINK_Unregister (void)
1764 UnregisterClassW (WC_LINK, NULL);