gdi32: Avoid redundant computation of the gradient bounding rectangle.
[wine/multimedia.git] / dlls / comctl32 / syslink.c
bloba5ba3dd422de6d81927752198b2e3a41fc843373
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 WCHAR BreakChar; /* Break Character for the current font */
98 BOOL IgnoreReturn; /* (infoPtr->Style & LWS_IGNORERETURN) on creation */
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 TRACE("(%p %s)\n", infoPtr, debugstr_w(Text));
202 for(current = Text; *current != 0;)
204 if(*current == '<')
206 if(!StrCmpNIW(current, SL_LINKOPEN, 2) && (CurrentType == slText))
208 BOOL ValidParam = FALSE, ValidLink = FALSE;
210 if(*(current + 2) == '>')
212 /* we just have to deal with a <a> tag */
213 taglen = 3;
214 ValidLink = TRUE;
215 ValidParam = TRUE;
216 firsttag = current;
217 linklen = 0;
218 lpID = NULL;
219 lpUrl = NULL;
221 else if(*(current + 2) == infoPtr->BreakChar)
223 /* we expect parameters, parse them */
224 LPCWSTR *CurrentParameter = NULL, tmp;
225 UINT *CurrentParameterLen = NULL;
227 taglen = 3;
228 tmp = current + taglen;
229 lpID = NULL;
230 lpUrl = NULL;
232 CheckParameter:
233 /* compare the current position with all known parameters */
234 if(!StrCmpNIW(tmp, SL_HREF, 6))
236 taglen += 6;
237 ValidParam = TRUE;
238 CurrentParameter = &lpUrl;
239 CurrentParameterLen = &lenUrl;
241 else if(!StrCmpNIW(tmp, SL_ID, 4))
243 taglen += 4;
244 ValidParam = TRUE;
245 CurrentParameter = &lpID;
246 CurrentParameterLen = &lenId;
248 else
250 ValidParam = FALSE;
253 if(ValidParam)
255 /* we got a known parameter, now search until the next " character.
256 If we can't find a " character, there's a syntax error and we just assume it's text */
257 ValidParam = FALSE;
258 *CurrentParameter = current + taglen;
259 *CurrentParameterLen = 0;
261 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
263 taglen++;
264 if(*tmp == '\"')
266 ValidParam = TRUE;
267 tmp++;
268 break;
270 (*CurrentParameterLen)++;
273 if(ValidParam)
275 /* we're done with this parameter, now there are only 2 possibilities:
276 * 1. another parameter is coming, so expect a ' ' (space) character
277 * 2. the tag is being closed, so expect a '<' character
279 if(*tmp == infoPtr->BreakChar)
281 /* we expect another parameter, do the whole thing again */
282 taglen++;
283 tmp++;
284 goto CheckParameter;
286 else if(*tmp == '>')
288 /* the tag is being closed, we're done */
289 ValidLink = TRUE;
290 taglen++;
295 if(ValidLink && ValidParam)
297 /* the <a ...> tag appears to be valid. save all information
298 so we can add the link if we find a valid </a> tag later */
299 CurrentType = slLink;
300 linktext = current + taglen;
301 linklen = 0;
302 firsttag = current;
304 else
306 taglen = 1;
307 lpID = NULL;
308 lpUrl = NULL;
309 if(textstart == NULL)
311 textstart = current;
315 else if(!StrCmpNIW(current, SL_LINKCLOSE, 4) && (CurrentType == slLink) && firsttag)
317 /* there's a <a...> tag opened, first add the previous text, if present */
318 if(textstart != NULL && textlen > 0 && firsttag > textstart)
320 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
321 if(Last == NULL)
323 ERR("Unable to create new document item!\n");
324 return docitems;
326 docitems++;
327 textstart = NULL;
328 textlen = 0;
331 /* now it's time to add the link to the document */
332 current += 4;
333 if(linktext != NULL && linklen > 0)
335 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
336 if(Last == NULL)
338 ERR("Unable to create new document item!\n");
339 return docitems;
341 docitems++;
342 if(CurrentType == slLink)
344 int nc;
346 if(!(infoPtr->Style & WS_DISABLED))
348 Last->u.Link.state |= LIS_ENABLED;
350 /* Copy the tag parameters */
351 if(lpID != NULL)
353 nc = min(lenId, strlenW(lpID));
354 nc = min(nc, MAX_LINKID_TEXT - 1);
355 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
356 if(Last->u.Link.szID != NULL)
358 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
361 else
362 Last->u.Link.szID = NULL;
363 if(lpUrl != NULL)
365 nc = min(lenUrl, strlenW(lpUrl));
366 nc = min(nc, L_MAX_URL_LENGTH - 1);
367 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
368 if(Last->u.Link.szUrl != NULL)
370 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
373 else
374 Last->u.Link.szUrl = NULL;
376 linktext = NULL;
378 CurrentType = slText;
379 firsttag = NULL;
380 textstart = NULL;
381 continue;
383 else
385 /* we don't know what tag it is, so just continue */
386 taglen = 1;
387 linklen++;
388 if(CurrentType == slText && textstart == NULL)
390 textstart = current;
394 textlen += taglen;
395 current += taglen;
397 else
399 textlen++;
400 linklen++;
402 /* save the pointer of the current text item if we couldn't find a tag */
403 if(textstart == NULL && CurrentType == slText)
405 textstart = current;
408 current++;
412 if(textstart != NULL && textlen > 0)
414 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
415 if(Last == NULL)
417 ERR("Unable to create new document item!\n");
418 return docitems;
420 if(CurrentType == slLink)
422 int nc;
424 if(!(infoPtr->Style & WS_DISABLED))
426 Last->u.Link.state |= LIS_ENABLED;
428 /* Copy the tag parameters */
429 if(lpID != NULL)
431 nc = min(lenId, strlenW(lpID));
432 nc = min(nc, MAX_LINKID_TEXT - 1);
433 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
434 if(Last->u.Link.szID != NULL)
436 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
439 else
440 Last->u.Link.szID = NULL;
441 if(lpUrl != NULL)
443 nc = min(lenUrl, strlenW(lpUrl));
444 nc = min(nc, L_MAX_URL_LENGTH - 1);
445 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
446 if(Last->u.Link.szUrl != NULL)
448 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
451 else
452 Last->u.Link.szUrl = NULL;
454 docitems++;
457 if(linktext != NULL && linklen > 0)
459 /* we got an unclosed link, just display the text */
460 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
461 if(Last == NULL)
463 ERR("Unable to create new document item!\n");
464 return docitems;
466 docitems++;
469 return docitems;
472 /***********************************************************************
473 * SYSLINK_RepaintLink
474 * Repaints a link.
476 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
478 PDOC_TEXTBLOCK bl;
479 int n;
481 if(DocItem->Type != slLink)
483 ERR("DocItem not a link!\n");
484 return;
487 bl = DocItem->Blocks;
488 if (bl != NULL)
490 n = DocItem->nText;
492 while(n > 0)
494 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
495 n -= bl->nChars + bl->nSkip;
496 bl++;
501 /***********************************************************************
502 * SYSLINK_GetLinkItemByIndex
503 * Retrieves a document link by its index
505 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
507 PDOC_ITEM Current = infoPtr->Items;
509 while(Current != NULL)
511 if((Current->Type == slLink) && (iLink-- <= 0))
513 return Current;
515 Current = Current->Next;
517 return NULL;
520 /***********************************************************************
521 * SYSLINK_GetFocusLink
522 * Retrieves the link that has the LIS_FOCUSED bit
524 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
526 PDOC_ITEM Current = infoPtr->Items;
527 int id = 0;
529 while(Current != NULL)
531 if(Current->Type == slLink)
533 if(Current->u.Link.state & LIS_FOCUSED)
535 if(LinkId != NULL)
536 *LinkId = id;
537 return Current;
539 id++;
541 Current = Current->Next;
543 return NULL;
546 /***********************************************************************
547 * SYSLINK_GetNextLink
548 * Gets the next link
550 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
552 for(Current = (Current != NULL ? Current->Next : infoPtr->Items);
553 Current != NULL;
554 Current = Current->Next)
556 if(Current->Type == slLink)
558 return Current;
561 return NULL;
564 /***********************************************************************
565 * SYSLINK_GetPrevLink
566 * Gets the previous link
568 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
570 if(Current == NULL)
572 /* returns the last link */
573 PDOC_ITEM Last = NULL;
575 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
577 if(Current->Type == slLink)
579 Last = Current;
582 return Last;
584 else
586 /* returns the previous link */
587 PDOC_ITEM Cur, Prev = NULL;
589 for(Cur = infoPtr->Items; Cur != NULL; Cur = Cur->Next)
591 if(Cur == Current)
593 break;
595 if(Cur->Type == slLink)
597 Prev = Cur;
600 return Prev;
604 /***********************************************************************
605 * SYSLINK_WrapLine
606 * Tries to wrap a line.
608 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int x, int *LineLen,
609 int nFit, LPSIZE Extent)
611 int i;
613 for (i = 0; i < nFit; i++) if (Text[i] == '\n') break;
615 if (i == *LineLen) return FALSE;
617 /* check if we're in the middle of a word */
618 if (Text[i] != '\n' && Text[i] != BreakChar)
620 /* search for the beginning of the word */
621 while (i && Text[i - 1] != BreakChar) i--;
623 if (i == 0)
625 Extent->cx = 0;
626 Extent->cy = 0;
627 if (x == SL_LEFTMARGIN) i = max( nFit, 1 );
630 *LineLen = i;
631 return TRUE;
634 /***********************************************************************
635 * SYSLINK_Render
636 * Renders the document in memory
638 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
640 RECT rc;
641 PDOC_ITEM Current;
642 HGDIOBJ hOldFont;
643 int x, y, LineHeight;
644 SIZE szDoc;
645 TEXTMETRICW tm;
647 szDoc.cx = szDoc.cy = 0;
649 rc = *pRect;
650 rc.right -= SL_RIGHTMARGIN;
651 rc.bottom -= SL_BOTTOMMARGIN;
653 if(rc.right - SL_LEFTMARGIN < 0)
654 rc.right = MAXLONG;
655 if (rc.bottom - SL_TOPMARGIN < 0)
656 rc.bottom = MAXLONG;
658 hOldFont = SelectObject(hdc, infoPtr->Font);
660 x = SL_LEFTMARGIN;
661 y = SL_TOPMARGIN;
662 GetTextMetricsW( hdc, &tm );
663 LineHeight = tm.tmHeight + tm.tmExternalLeading;
665 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
667 int n, nBlocks;
668 LPWSTR tx;
669 PDOC_TEXTBLOCK bl, cbl;
670 INT nFit;
671 SIZE szDim;
672 int SkipChars = 0;
674 if(Current->nText == 0)
676 continue;
679 tx = Current->Text;
680 n = Current->nText;
682 Free(Current->Blocks);
683 Current->Blocks = NULL;
684 bl = NULL;
685 nBlocks = 0;
687 if(Current->Type == slText)
689 SelectObject(hdc, infoPtr->Font);
691 else if(Current->Type == slLink)
693 SelectObject(hdc, infoPtr->LinkFont);
696 while(n > 0)
698 /* skip break characters unless they're the first of the doc item */
699 if(tx != Current->Text || x == SL_LEFTMARGIN)
701 if (n && *tx == '\n')
703 tx++;
704 SkipChars++;
705 n--;
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, x, &LineLen, nFit, &szDim);
726 if(LineLen == 0)
728 /* move one line down, the word didn't fit into the line */
729 x = SL_LEFTMARGIN;
730 y += LineHeight;
731 continue;
734 if(LineLen != n)
736 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
738 if(bl != NULL)
740 Free(bl);
741 bl = NULL;
742 nBlocks = 0;
744 break;
749 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
750 if (nbl != NULL)
752 bl = nbl;
753 nBlocks++;
755 cbl = bl + nBlocks - 1;
757 cbl->nChars = LineLen;
758 cbl->nSkip = SkipChars;
759 cbl->rc.left = x;
760 cbl->rc.top = y;
761 cbl->rc.right = x + szDim.cx;
762 cbl->rc.bottom = y + szDim.cy;
764 if (cbl->rc.right > szDoc.cx)
765 szDoc.cx = cbl->rc.right;
766 if (cbl->rc.bottom > szDoc.cy)
767 szDoc.cy = cbl->rc.bottom;
769 if(LineLen != 0)
771 x += szDim.cx;
772 if(Wrap)
774 x = SL_LEFTMARGIN;
775 y += LineHeight;
779 else
781 Free(bl);
782 bl = NULL;
783 nBlocks = 0;
785 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
786 break;
788 n -= LineLen;
789 tx += LineLen;
790 SkipChars = 0;
792 else
794 n--;
798 if(nBlocks != 0)
800 Current->Blocks = bl;
804 SelectObject(hdc, hOldFont);
806 pRect->right = pRect->left + szDoc.cx;
807 pRect->bottom = pRect->top + szDoc.cy;
810 /***********************************************************************
811 * SYSLINK_Draw
812 * Draws the SysLink control.
814 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
816 RECT rc;
817 PDOC_ITEM Current;
818 HFONT hOldFont;
819 COLORREF OldTextColor, OldBkColor;
820 HBRUSH hBrush;
821 UINT text_flags = ETO_CLIPPED;
822 UINT mode = GetBkMode( hdc );
824 hOldFont = SelectObject(hdc, infoPtr->Font);
825 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
826 OldBkColor = SetBkColor(hdc, comctl32_color.clrWindow);
828 GetClientRect(infoPtr->Self, &rc);
829 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
830 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
832 if(rc.right < 0 || rc.bottom < 0) return 0;
834 hBrush = (HBRUSH)SendMessageW(infoPtr->Notify, WM_CTLCOLORSTATIC,
835 (WPARAM)hdc, (LPARAM)infoPtr->Self);
836 if (!(infoPtr->Style & LWS_TRANSPARENT))
838 FillRect(hdc, &rc, hBrush);
839 if (GetBkMode( hdc ) == OPAQUE) text_flags |= ETO_OPAQUE;
841 else SetBkMode( hdc, TRANSPARENT );
843 DeleteObject(hBrush);
845 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
847 int n;
848 LPWSTR tx;
849 PDOC_TEXTBLOCK bl;
851 bl = Current->Blocks;
852 if(bl != NULL)
854 tx = Current->Text;
855 n = Current->nText;
857 if(Current->Type == slText)
859 SelectObject(hdc, infoPtr->Font);
860 SetTextColor(hdc, infoPtr->TextColor);
862 else
864 SelectObject(hdc, infoPtr->LinkFont);
865 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
868 while(n > 0)
870 tx += bl->nSkip;
871 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, text_flags, &bl->rc, tx, bl->nChars, NULL);
872 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
874 COLORREF PrevTextColor;
875 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
876 DrawFocusRect(hdc, &bl->rc);
877 SetTextColor(hdc, PrevTextColor);
879 tx += bl->nChars;
880 n -= bl->nChars + bl->nSkip;
881 bl++;
886 SetBkColor(hdc, OldBkColor);
887 SetTextColor(hdc, OldTextColor);
888 SelectObject(hdc, hOldFont);
889 SetBkMode(hdc, mode);
890 return 0;
894 /***********************************************************************
895 * SYSLINK_Paint
896 * Handles the WM_PAINT message.
898 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
900 HDC hdc;
901 PAINTSTRUCT ps;
903 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
904 if (hdc)
906 SYSLINK_Draw (infoPtr, hdc);
907 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
909 return 0;
912 /***********************************************************************
913 * SYSLINK_SetFont
914 * Set new Font for the SysLink control.
916 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
918 HDC hdc;
919 LOGFONTW lf;
920 TEXTMETRICW tm;
921 RECT rcClient;
922 HFONT hOldFont = infoPtr->Font;
923 infoPtr->Font = hFont;
925 /* free the underline font */
926 if(infoPtr->LinkFont != NULL)
928 DeleteObject(infoPtr->LinkFont);
929 infoPtr->LinkFont = NULL;
932 /* Render text position and word wrapping in memory */
933 if (GetClientRect(infoPtr->Self, &rcClient))
935 hdc = GetDC(infoPtr->Self);
936 if(hdc != NULL)
938 /* create a new underline font */
939 if(GetTextMetricsW(hdc, &tm) &&
940 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
942 lf.lfUnderline = TRUE;
943 infoPtr->LinkFont = CreateFontIndirectW(&lf);
944 infoPtr->BreakChar = tm.tmBreakChar;
946 else
948 ERR("Failed to create link font!\n");
951 SYSLINK_Render(infoPtr, hdc, &rcClient);
952 ReleaseDC(infoPtr->Self, hdc);
956 if(bRedraw)
958 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
961 return hOldFont;
964 /***********************************************************************
965 * SYSLINK_SetText
966 * Set new text for the SysLink control.
968 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
970 /* clear the document */
971 SYSLINK_ClearDoc(infoPtr);
973 if(Text == NULL || *Text == 0)
975 return TRUE;
978 /* let's parse the string and create a document */
979 if(SYSLINK_ParseText(infoPtr, Text) > 0)
981 RECT rcClient;
983 /* Render text position and word wrapping in memory */
984 if (GetClientRect(infoPtr->Self, &rcClient))
986 HDC hdc = GetDC(infoPtr->Self);
987 if (hdc != NULL)
989 SYSLINK_Render(infoPtr, hdc, &rcClient);
990 ReleaseDC(infoPtr->Self, hdc);
992 InvalidateRect(infoPtr->Self, NULL, TRUE);
997 return TRUE;
1000 /***********************************************************************
1001 * SYSLINK_SetFocusLink
1002 * Updates the focus status bits and focusses the specified link.
1003 * If no document item is specified, the focus bit will be removed from all links.
1004 * Returns the previous focused item.
1006 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
1008 PDOC_ITEM Current, PrevFocus = NULL;
1010 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1012 if(Current->Type == slLink)
1014 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1016 PrevFocus = Current;
1019 if(Current == DocItem)
1021 Current->u.Link.state |= LIS_FOCUSED;
1023 else
1025 Current->u.Link.state &= ~LIS_FOCUSED;
1030 return PrevFocus;
1033 /***********************************************************************
1034 * SYSLINK_SetItem
1035 * Sets the states and attributes of a link item.
1037 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1039 PDOC_ITEM di;
1040 int nc;
1041 PWSTR szId = NULL;
1042 PWSTR szUrl = NULL;
1043 BOOL Repaint = FALSE;
1045 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1047 ERR("Invalid Flags!\n");
1048 return FALSE;
1051 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1052 if(di == NULL)
1054 ERR("Link %d couldn't be found\n", Item->iLink);
1055 return FALSE;
1058 if(Item->mask & LIF_ITEMID)
1060 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1061 szId = Alloc((nc + 1) * sizeof(WCHAR));
1062 if(szId)
1064 lstrcpynW(szId, Item->szID, nc + 1);
1066 else
1068 ERR("Unable to allocate memory for link id\n");
1069 return FALSE;
1073 if(Item->mask & LIF_URL)
1075 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1076 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1077 if(szUrl)
1079 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1081 else
1083 Free(szId);
1085 ERR("Unable to allocate memory for link url\n");
1086 return FALSE;
1090 if(Item->mask & LIF_ITEMID)
1092 Free(di->u.Link.szID);
1093 di->u.Link.szID = szId;
1096 if(Item->mask & LIF_URL)
1098 Free(di->u.Link.szUrl);
1099 di->u.Link.szUrl = szUrl;
1102 if(Item->mask & LIF_STATE)
1104 UINT oldstate = di->u.Link.state;
1105 /* clear the masked bits */
1106 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1107 /* copy the bits */
1108 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1109 Repaint = (oldstate != di->u.Link.state);
1111 /* update the focus */
1112 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1115 if(Repaint)
1117 SYSLINK_RepaintLink(infoPtr, di);
1120 return TRUE;
1123 /***********************************************************************
1124 * SYSLINK_GetItem
1125 * Retrieves the states and attributes of a link item.
1127 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1129 PDOC_ITEM di;
1131 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1133 ERR("Invalid Flags!\n");
1134 return FALSE;
1137 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1138 if(di == NULL)
1140 ERR("Link %d couldn't be found\n", Item->iLink);
1141 return FALSE;
1144 if(Item->mask & LIF_STATE)
1146 Item->state = (di->u.Link.state & Item->stateMask);
1147 if(!infoPtr->HasFocus)
1149 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1150 Item->state &= ~LIS_FOCUSED;
1154 if(Item->mask & LIF_ITEMID)
1156 if(di->u.Link.szID)
1158 lstrcpyW(Item->szID, di->u.Link.szID);
1160 else
1162 Item->szID[0] = 0;
1166 if(Item->mask & LIF_URL)
1168 if(di->u.Link.szUrl)
1170 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1172 else
1174 Item->szUrl[0] = 0;
1178 return TRUE;
1181 /***********************************************************************
1182 * SYSLINK_PtInDocItem
1183 * Determines if a point is in the region of a document item
1185 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1187 PDOC_TEXTBLOCK bl;
1188 int n;
1190 bl = DocItem->Blocks;
1191 if (bl != NULL)
1193 n = DocItem->nText;
1195 while(n > 0)
1197 if (PtInRect(&bl->rc, pt))
1199 return TRUE;
1201 n -= bl->nChars + bl->nSkip;
1202 bl++;
1206 return FALSE;
1209 /***********************************************************************
1210 * SYSLINK_HitTest
1211 * Determines the link the user clicked on.
1213 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1215 PDOC_ITEM Current;
1216 int id = 0;
1218 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1220 if(Current->Type == slLink)
1222 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1224 HitTest->item.mask = 0;
1225 HitTest->item.iLink = id;
1226 HitTest->item.state = 0;
1227 HitTest->item.stateMask = 0;
1228 if(Current->u.Link.szID)
1230 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1232 else
1234 HitTest->item.szID[0] = 0;
1236 if(Current->u.Link.szUrl)
1238 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1240 else
1242 HitTest->item.szUrl[0] = 0;
1244 return TRUE;
1246 id++;
1250 return FALSE;
1253 /***********************************************************************
1254 * SYSLINK_GetIdealHeight
1255 * Returns the preferred height of a link at the current control's width.
1257 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1259 HDC hdc = GetDC(infoPtr->Self);
1260 if(hdc != NULL)
1262 LRESULT height;
1263 TEXTMETRICW tm;
1264 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1266 if(GetTextMetricsW(hdc, &tm))
1268 height = tm.tmHeight;
1270 else
1272 height = 0;
1274 SelectObject(hdc, hOldFont);
1275 ReleaseDC(infoPtr->Self, hdc);
1277 return height;
1279 return 0;
1282 /***********************************************************************
1283 * SYSLINK_SendParentNotify
1284 * Sends a WM_NOTIFY message to the parent window.
1286 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1288 NMLINK nml;
1290 nml.hdr.hwndFrom = infoPtr->Self;
1291 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1292 nml.hdr.code = code;
1294 nml.item.mask = 0;
1295 nml.item.iLink = iLink;
1296 nml.item.state = 0;
1297 nml.item.stateMask = 0;
1298 if(Link->u.Link.szID)
1300 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1302 else
1304 nml.item.szID[0] = 0;
1306 if(Link->u.Link.szUrl)
1308 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1310 else
1312 nml.item.szUrl[0] = 0;
1315 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1318 /***********************************************************************
1319 * SYSLINK_SetFocus
1320 * Handles receiving the input focus.
1322 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1324 PDOC_ITEM Focus;
1326 infoPtr->HasFocus = TRUE;
1328 /* We always select the first link, even if we activated the control using
1329 SHIFT+TAB. This is the default behavior */
1330 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1331 if(Focus != NULL)
1333 SYSLINK_SetFocusLink(infoPtr, Focus);
1334 SYSLINK_RepaintLink(infoPtr, Focus);
1336 return 0;
1339 /***********************************************************************
1340 * SYSLINK_KillFocus
1341 * Handles losing the input focus.
1343 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1345 PDOC_ITEM Focus;
1347 infoPtr->HasFocus = FALSE;
1348 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1350 if(Focus != NULL)
1352 SYSLINK_RepaintLink(infoPtr, Focus);
1355 return 0;
1358 /***********************************************************************
1359 * SYSLINK_LinkAtPt
1360 * Returns a link at the specified position
1362 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1364 PDOC_ITEM Current;
1365 int id = 0;
1367 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1369 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1370 (!MustBeEnabled || (MustBeEnabled && (Current->u.Link.state & LIS_ENABLED))))
1372 if(LinkId != NULL)
1374 *LinkId = id;
1376 return Current;
1378 id++;
1381 return NULL;
1384 /***********************************************************************
1385 * SYSLINK_LButtonDown
1386 * Handles mouse clicks
1388 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1390 PDOC_ITEM Current, Old;
1391 int id;
1393 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1394 if(Current != NULL)
1396 SetFocus(infoPtr->Self);
1398 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1399 if(Old != NULL && Old != Current)
1401 SYSLINK_RepaintLink(infoPtr, Old);
1403 infoPtr->MouseDownID = id;
1404 SYSLINK_RepaintLink(infoPtr, Current);
1407 return 0;
1410 /***********************************************************************
1411 * SYSLINK_LButtonUp
1412 * Handles mouse clicks
1414 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1416 if(infoPtr->MouseDownID > -1)
1418 PDOC_ITEM Current;
1419 int id;
1421 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1422 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1424 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1428 infoPtr->MouseDownID = -1;
1430 return 0;
1433 /***********************************************************************
1434 * SYSLINK_OnEnter
1435 * Handles ENTER key events
1437 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1439 if(infoPtr->HasFocus && !infoPtr->IgnoreReturn)
1441 PDOC_ITEM Focus;
1442 int id;
1444 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1445 if(Focus)
1447 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1448 return TRUE;
1451 return FALSE;
1454 /***********************************************************************
1455 * SYSKEY_SelectNextPrevLink
1456 * Changes the currently focused link
1458 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1460 if(infoPtr->HasFocus)
1462 PDOC_ITEM Focus;
1463 int id;
1465 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1466 if(Focus != NULL)
1468 PDOC_ITEM NewFocus, OldFocus;
1470 if(Prev)
1471 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1472 else
1473 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1475 if(NewFocus != NULL)
1477 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1479 if(OldFocus && OldFocus != NewFocus)
1481 SYSLINK_RepaintLink(infoPtr, OldFocus);
1483 SYSLINK_RepaintLink(infoPtr, NewFocus);
1484 return TRUE;
1488 return FALSE;
1491 /***********************************************************************
1492 * SYSKEY_SelectNextPrevLink
1493 * Determines if there's a next or previous link to decide whether the control
1494 * should capture the tab key message
1496 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1498 PDOC_ITEM Focus, NewFocus;
1500 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1501 if(Prev)
1502 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1503 else
1504 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1506 return NewFocus == NULL;
1509 /***********************************************************************
1510 * SYSLINK_GetIdealSize
1511 * Calculates the ideal size of a link control at a given maximum width.
1513 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1515 RECT rc;
1516 HDC hdc;
1518 rc.left = rc.top = rc.bottom = 0;
1519 rc.right = cxMaxWidth;
1521 hdc = GetDC(infoPtr->Self);
1522 if (hdc != NULL)
1524 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1526 SYSLINK_Render(infoPtr, hdc, &rc);
1528 SelectObject(hdc, hOldFont);
1529 ReleaseDC(infoPtr->Self, hdc);
1531 lpSize->cx = rc.right;
1532 lpSize->cy = rc.bottom;
1536 /***********************************************************************
1537 * SysLinkWindowProc
1539 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1540 WPARAM wParam, LPARAM lParam)
1542 SYSLINK_INFO *infoPtr;
1544 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1546 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1548 if (!infoPtr && message != WM_CREATE)
1549 return DefWindowProcW(hwnd, message, wParam, lParam);
1551 switch(message) {
1552 case WM_PRINTCLIENT:
1553 case WM_PAINT:
1554 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1556 case WM_ERASEBKGND:
1557 if (!(infoPtr->Style & LWS_TRANSPARENT))
1559 HDC hdc = (HDC)wParam;
1560 HBRUSH brush = CreateSolidBrush( comctl32_color.clrWindow );
1561 RECT rect;
1563 GetClipBox( hdc, &rect );
1564 FillRect( hdc, &rect, brush );
1565 DeleteObject( brush );
1566 return 1;
1568 return 0;
1570 case WM_SETCURSOR:
1572 LHITTESTINFO ht;
1573 DWORD mp = GetMessagePos();
1575 ht.pt.x = (short)LOWORD(mp);
1576 ht.pt.y = (short)HIWORD(mp);
1578 ScreenToClient(infoPtr->Self, &ht.pt);
1579 if(SYSLINK_HitTest (infoPtr, &ht))
1581 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1582 return TRUE;
1585 return DefWindowProcW(hwnd, message, wParam, lParam);
1588 case WM_SIZE:
1590 RECT rcClient;
1591 if (GetClientRect(infoPtr->Self, &rcClient))
1593 HDC hdc = GetDC(infoPtr->Self);
1594 if(hdc != NULL)
1596 SYSLINK_Render(infoPtr, hdc, &rcClient);
1597 ReleaseDC(infoPtr->Self, hdc);
1600 return 0;
1603 case WM_GETFONT:
1604 return (LRESULT)infoPtr->Font;
1606 case WM_SETFONT:
1607 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1609 case WM_SETTEXT:
1610 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1611 return DefWindowProcW(hwnd, message, wParam, lParam);
1613 case WM_LBUTTONDOWN:
1615 POINT pt;
1616 pt.x = (short)LOWORD(lParam);
1617 pt.y = (short)HIWORD(lParam);
1618 return SYSLINK_LButtonDown(infoPtr, &pt);
1620 case WM_LBUTTONUP:
1622 POINT pt;
1623 pt.x = (short)LOWORD(lParam);
1624 pt.y = (short)HIWORD(lParam);
1625 return SYSLINK_LButtonUp(infoPtr, &pt);
1628 case WM_KEYDOWN:
1630 switch(wParam)
1632 case VK_RETURN:
1633 SYSLINK_OnEnter(infoPtr);
1634 return 0;
1635 case VK_TAB:
1637 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1638 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1639 return 0;
1641 default:
1642 return DefWindowProcW(hwnd, message, wParam, lParam);
1646 case WM_GETDLGCODE:
1648 LRESULT Ret = DLGC_HASSETSEL;
1649 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1650 switch(vk)
1652 case VK_RETURN:
1653 Ret |= DLGC_WANTMESSAGE;
1654 break;
1655 case VK_TAB:
1657 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1658 if(!SYSLINK_NoNextLink(infoPtr, shift))
1660 Ret |= DLGC_WANTTAB;
1662 else
1664 Ret |= DLGC_WANTCHARS;
1666 break;
1669 return Ret;
1672 case WM_NCHITTEST:
1674 POINT pt;
1675 RECT rc;
1676 pt.x = (short)LOWORD(lParam);
1677 pt.y = (short)HIWORD(lParam);
1679 GetClientRect(infoPtr->Self, &rc);
1680 ScreenToClient(infoPtr->Self, &pt);
1681 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1683 return HTNOWHERE;
1686 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1688 return HTCLIENT;
1691 return HTTRANSPARENT;
1694 case LM_HITTEST:
1695 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1697 case LM_SETITEM:
1698 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1700 case LM_GETITEM:
1701 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1703 case LM_GETIDEALHEIGHT:
1704 if (lParam)
1706 /* LM_GETIDEALSIZE */
1707 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1709 return SYSLINK_GetIdealHeight(infoPtr);
1711 case WM_SETFOCUS:
1712 return SYSLINK_SetFocus(infoPtr);
1714 case WM_KILLFOCUS:
1715 return SYSLINK_KillFocus(infoPtr);
1717 case WM_ENABLE:
1718 infoPtr->Style &= ~WS_DISABLED;
1719 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1720 InvalidateRect (infoPtr->Self, NULL, FALSE);
1721 return 0;
1723 case WM_STYLECHANGED:
1724 if (wParam == GWL_STYLE)
1726 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1728 InvalidateRect(infoPtr->Self, NULL, TRUE);
1730 return 0;
1732 case WM_CREATE:
1733 /* allocate memory for info struct */
1734 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1735 if (!infoPtr) return -1;
1736 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1738 /* initialize the info struct */
1739 infoPtr->Self = hwnd;
1740 infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1741 infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style;
1742 infoPtr->Font = 0;
1743 infoPtr->LinkFont = 0;
1744 infoPtr->Items = NULL;
1745 infoPtr->HasFocus = FALSE;
1746 infoPtr->MouseDownID = -1;
1747 infoPtr->TextColor = comctl32_color.clrWindowText;
1748 infoPtr->LinkColor = comctl32_color.clrHighlight;
1749 infoPtr->VisitedColor = comctl32_color.clrHighlight;
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 return 0;
1769 default:
1770 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1772 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1774 return DefWindowProcW(hwnd, message, wParam, lParam);
1779 /***********************************************************************
1780 * SYSLINK_Register [Internal]
1782 * Registers the SysLink window class.
1784 VOID SYSLINK_Register (void)
1786 WNDCLASSW wndClass;
1788 ZeroMemory (&wndClass, sizeof(wndClass));
1789 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1790 wndClass.lpfnWndProc = SysLinkWindowProc;
1791 wndClass.cbClsExtra = 0;
1792 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1793 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1794 wndClass.lpszClassName = WC_LINK;
1796 RegisterClassW (&wndClass);
1800 /***********************************************************************
1801 * SYSLINK_Unregister [Internal]
1803 * Unregisters the SysLink window class.
1805 VOID SYSLINK_Unregister (void)
1807 UnregisterClassW (WC_LINK, NULL);