comctl32: Use SetRect() instead of open coding it.
[wine.git] / dlls / comctl32 / syslink.c
blob7e0b49b11944684732171c13e66e10c65ed04642
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_StrCmpNIW
188 * Wrapper for StrCmpNIW to ensure 'len' is not too big.
190 static INT SYSLINK_StrCmpNIW (LPCWSTR str, LPCWSTR comp, INT len)
192 INT i;
194 for(i = 0; i < len; i++)
196 if(!str[i])
198 len = i + 1;
199 break;
203 return StrCmpNIW(str, comp, len);
206 /***********************************************************************
207 * SYSLINK_ParseText
208 * Parses the window text string and creates a document. Returns the
209 * number of document items created.
211 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
213 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
214 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
215 PDOC_ITEM Last = NULL;
216 SL_ITEM_TYPE CurrentType = slText;
217 LPCWSTR lpID, lpUrl;
218 UINT lenId, lenUrl;
220 TRACE("(%p %s)\n", infoPtr, debugstr_w(Text));
222 for(current = Text; *current != 0;)
224 if(*current == '<')
226 if(!SYSLINK_StrCmpNIW(current, SL_LINKOPEN, 2) && (CurrentType == slText))
228 BOOL ValidParam = FALSE, ValidLink = FALSE;
230 if(*(current + 2) == '>')
232 /* we just have to deal with a <a> tag */
233 taglen = 3;
234 ValidLink = TRUE;
235 ValidParam = TRUE;
236 firsttag = current;
237 linklen = 0;
238 lpID = NULL;
239 lpUrl = NULL;
241 else if(*(current + 2) == infoPtr->BreakChar)
243 /* we expect parameters, parse them */
244 LPCWSTR *CurrentParameter = NULL, tmp;
245 UINT *CurrentParameterLen = NULL;
247 taglen = 3;
248 tmp = current + taglen;
249 lpID = NULL;
250 lpUrl = NULL;
252 CheckParameter:
253 /* compare the current position with all known parameters */
254 if(!SYSLINK_StrCmpNIW(tmp, SL_HREF, 6))
256 taglen += 6;
257 ValidParam = TRUE;
258 CurrentParameter = &lpUrl;
259 CurrentParameterLen = &lenUrl;
261 else if(!SYSLINK_StrCmpNIW(tmp, SL_ID, 4))
263 taglen += 4;
264 ValidParam = TRUE;
265 CurrentParameter = &lpID;
266 CurrentParameterLen = &lenId;
268 else
270 ValidParam = FALSE;
273 if(ValidParam)
275 /* we got a known parameter, now search until the next " character.
276 If we can't find a " character, there's a syntax error and we just assume it's text */
277 ValidParam = FALSE;
278 *CurrentParameter = current + taglen;
279 *CurrentParameterLen = 0;
281 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
283 taglen++;
284 if(*tmp == '\"')
286 ValidParam = TRUE;
287 tmp++;
288 break;
290 (*CurrentParameterLen)++;
293 if(ValidParam)
295 /* we're done with this parameter, now there are only 2 possibilities:
296 * 1. another parameter is coming, so expect a ' ' (space) character
297 * 2. the tag is being closed, so expect a '<' character
299 if(*tmp == infoPtr->BreakChar)
301 /* we expect another parameter, do the whole thing again */
302 taglen++;
303 tmp++;
304 goto CheckParameter;
306 else if(*tmp == '>')
308 /* the tag is being closed, we're done */
309 ValidLink = TRUE;
310 taglen++;
315 if(ValidLink && ValidParam)
317 /* the <a ...> tag appears to be valid. save all information
318 so we can add the link if we find a valid </a> tag later */
319 CurrentType = slLink;
320 linktext = current + taglen;
321 linklen = 0;
322 firsttag = current;
324 else
326 taglen = 1;
327 lpID = NULL;
328 lpUrl = NULL;
329 if(textstart == NULL)
331 textstart = current;
335 else if(!SYSLINK_StrCmpNIW(current, SL_LINKCLOSE, 4) && (CurrentType == slLink) && firsttag)
337 /* there's a <a...> tag opened, first add the previous text, if present */
338 if(textstart != NULL && textlen > 0 && firsttag > textstart)
340 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
341 if(Last == NULL)
343 ERR("Unable to create new document item!\n");
344 return docitems;
346 docitems++;
347 textstart = NULL;
348 textlen = 0;
351 /* now it's time to add the link to the document */
352 current += 4;
353 if(linktext != NULL && linklen > 0)
355 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
356 if(Last == NULL)
358 ERR("Unable to create new document item!\n");
359 return docitems;
361 docitems++;
362 if(CurrentType == slLink)
364 int nc;
366 if(!(infoPtr->Style & WS_DISABLED))
368 Last->u.Link.state |= LIS_ENABLED;
370 /* Copy the tag parameters */
371 if(lpID != NULL)
373 nc = min(lenId, strlenW(lpID));
374 nc = min(nc, MAX_LINKID_TEXT - 1);
375 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
376 if(Last->u.Link.szID != NULL)
378 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
381 else
382 Last->u.Link.szID = NULL;
383 if(lpUrl != NULL)
385 nc = min(lenUrl, strlenW(lpUrl));
386 nc = min(nc, L_MAX_URL_LENGTH - 1);
387 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
388 if(Last->u.Link.szUrl != NULL)
390 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
393 else
394 Last->u.Link.szUrl = NULL;
396 linktext = NULL;
398 CurrentType = slText;
399 firsttag = NULL;
400 textstart = NULL;
401 continue;
403 else
405 /* we don't know what tag it is, so just continue */
406 taglen = 1;
407 linklen++;
408 if(CurrentType == slText && textstart == NULL)
410 textstart = current;
414 textlen += taglen;
415 current += taglen;
417 else
419 textlen++;
420 linklen++;
422 /* save the pointer of the current text item if we couldn't find a tag */
423 if(textstart == NULL && CurrentType == slText)
425 textstart = current;
428 current++;
432 if(textstart != NULL && textlen > 0)
434 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
435 if(Last == NULL)
437 ERR("Unable to create new document item!\n");
438 return docitems;
440 if(CurrentType == slLink)
442 int nc;
444 if(!(infoPtr->Style & WS_DISABLED))
446 Last->u.Link.state |= LIS_ENABLED;
448 /* Copy the tag parameters */
449 if(lpID != NULL)
451 nc = min(lenId, strlenW(lpID));
452 nc = min(nc, MAX_LINKID_TEXT - 1);
453 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
454 if(Last->u.Link.szID != NULL)
456 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
459 else
460 Last->u.Link.szID = NULL;
461 if(lpUrl != NULL)
463 nc = min(lenUrl, strlenW(lpUrl));
464 nc = min(nc, L_MAX_URL_LENGTH - 1);
465 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
466 if(Last->u.Link.szUrl != NULL)
468 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
471 else
472 Last->u.Link.szUrl = NULL;
474 docitems++;
477 if(linktext != NULL && linklen > 0)
479 /* we got an unclosed link, just display the text */
480 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
481 if(Last == NULL)
483 ERR("Unable to create new document item!\n");
484 return docitems;
486 docitems++;
489 return docitems;
492 /***********************************************************************
493 * SYSLINK_RepaintLink
494 * Repaints a link.
496 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
498 PDOC_TEXTBLOCK bl;
499 int n;
501 if(DocItem->Type != slLink)
503 ERR("DocItem not a link!\n");
504 return;
507 bl = DocItem->Blocks;
508 if (bl != NULL)
510 n = DocItem->nText;
512 while(n > 0)
514 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
515 n -= bl->nChars + bl->nSkip;
516 bl++;
521 /***********************************************************************
522 * SYSLINK_GetLinkItemByIndex
523 * Retrieves a document link by its index
525 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
527 PDOC_ITEM Current = infoPtr->Items;
529 while(Current != NULL)
531 if((Current->Type == slLink) && (iLink-- <= 0))
533 return Current;
535 Current = Current->Next;
537 return NULL;
540 /***********************************************************************
541 * SYSLINK_GetFocusLink
542 * Retrieves the link that has the LIS_FOCUSED bit
544 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
546 PDOC_ITEM Current = infoPtr->Items;
547 int id = 0;
549 while(Current != NULL)
551 if(Current->Type == slLink)
553 if(Current->u.Link.state & LIS_FOCUSED)
555 if(LinkId != NULL)
556 *LinkId = id;
557 return Current;
559 id++;
561 Current = Current->Next;
563 return NULL;
566 /***********************************************************************
567 * SYSLINK_GetNextLink
568 * Gets the next link
570 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
572 for(Current = (Current != NULL ? Current->Next : infoPtr->Items);
573 Current != NULL;
574 Current = Current->Next)
576 if(Current->Type == slLink)
578 return Current;
581 return NULL;
584 /***********************************************************************
585 * SYSLINK_GetPrevLink
586 * Gets the previous link
588 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
590 if(Current == NULL)
592 /* returns the last link */
593 PDOC_ITEM Last = NULL;
595 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
597 if(Current->Type == slLink)
599 Last = Current;
602 return Last;
604 else
606 /* returns the previous link */
607 PDOC_ITEM Cur, Prev = NULL;
609 for(Cur = infoPtr->Items; Cur != NULL; Cur = Cur->Next)
611 if(Cur == Current)
613 break;
615 if(Cur->Type == slLink)
617 Prev = Cur;
620 return Prev;
624 /***********************************************************************
625 * SYSLINK_WrapLine
626 * Tries to wrap a line.
628 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int x, int *LineLen,
629 int nFit, LPSIZE Extent)
631 int i;
633 for (i = 0; i < nFit; i++) if (Text[i] == '\n') break;
635 if (i == *LineLen) return FALSE;
637 /* check if we're in the middle of a word */
638 if (Text[i] != '\n' && Text[i] != BreakChar)
640 /* search for the beginning of the word */
641 while (i && Text[i - 1] != BreakChar) i--;
643 if (i == 0)
645 Extent->cx = 0;
646 Extent->cy = 0;
647 if (x == SL_LEFTMARGIN) i = max( nFit, 1 );
650 *LineLen = i;
651 return TRUE;
654 /***********************************************************************
655 * SYSLINK_Render
656 * Renders the document in memory
658 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
660 RECT rc;
661 PDOC_ITEM Current;
662 HGDIOBJ hOldFont;
663 int x, y, LineHeight;
664 SIZE szDoc;
665 TEXTMETRICW tm;
667 szDoc.cx = szDoc.cy = 0;
669 rc = *pRect;
670 rc.right -= SL_RIGHTMARGIN;
671 rc.bottom -= SL_BOTTOMMARGIN;
673 if(rc.right - SL_LEFTMARGIN < 0)
674 rc.right = MAXLONG;
675 if (rc.bottom - SL_TOPMARGIN < 0)
676 rc.bottom = MAXLONG;
678 hOldFont = SelectObject(hdc, infoPtr->Font);
680 x = SL_LEFTMARGIN;
681 y = SL_TOPMARGIN;
682 GetTextMetricsW( hdc, &tm );
683 LineHeight = tm.tmHeight + tm.tmExternalLeading;
685 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
687 int n, nBlocks;
688 LPWSTR tx;
689 PDOC_TEXTBLOCK bl, cbl;
690 INT nFit;
691 SIZE szDim;
692 int SkipChars = 0;
694 if(Current->nText == 0)
696 continue;
699 tx = Current->Text;
700 n = Current->nText;
702 Free(Current->Blocks);
703 Current->Blocks = NULL;
704 bl = NULL;
705 nBlocks = 0;
707 if(Current->Type == slText)
709 SelectObject(hdc, infoPtr->Font);
711 else if(Current->Type == slLink)
713 SelectObject(hdc, infoPtr->LinkFont);
716 while(n > 0)
718 /* skip break characters unless they're the first of the doc item */
719 if(tx != Current->Text || x == SL_LEFTMARGIN)
721 if (n && *tx == '\n')
723 tx++;
724 SkipChars++;
725 n--;
727 while(n > 0 && (*tx) == infoPtr->BreakChar)
729 tx++;
730 SkipChars++;
731 n--;
735 if((n == 0 && SkipChars != 0) ||
736 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
738 int LineLen = n;
739 BOOL Wrap = FALSE;
740 PDOC_TEXTBLOCK nbl;
742 if(n != 0)
744 Wrap = SYSLINK_WrapLine(tx, infoPtr->BreakChar, x, &LineLen, nFit, &szDim);
746 if(LineLen == 0)
748 /* move one line down, the word didn't fit into the line */
749 x = SL_LEFTMARGIN;
750 y += LineHeight;
751 continue;
754 if(LineLen != n)
756 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
758 if(bl != NULL)
760 Free(bl);
761 bl = NULL;
762 nBlocks = 0;
764 break;
769 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
770 if (nbl != NULL)
772 bl = nbl;
773 nBlocks++;
775 cbl = bl + nBlocks - 1;
777 cbl->nChars = LineLen;
778 cbl->nSkip = SkipChars;
779 SetRect(&cbl->rc, x, y, x + szDim.cx, y + szDim.cy);
781 if (cbl->rc.right > szDoc.cx)
782 szDoc.cx = cbl->rc.right;
783 if (cbl->rc.bottom > szDoc.cy)
784 szDoc.cy = cbl->rc.bottom;
786 if(LineLen != 0)
788 x += szDim.cx;
789 if(Wrap)
791 x = SL_LEFTMARGIN;
792 y += LineHeight;
796 else
798 Free(bl);
799 bl = NULL;
800 nBlocks = 0;
802 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
803 break;
805 n -= LineLen;
806 tx += LineLen;
807 SkipChars = 0;
809 else
811 n--;
815 if(nBlocks != 0)
817 Current->Blocks = bl;
821 SelectObject(hdc, hOldFont);
823 pRect->right = pRect->left + szDoc.cx;
824 pRect->bottom = pRect->top + szDoc.cy;
827 /***********************************************************************
828 * SYSLINK_Draw
829 * Draws the SysLink control.
831 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
833 RECT rc;
834 PDOC_ITEM Current;
835 HFONT hOldFont;
836 COLORREF OldTextColor, OldBkColor;
837 HBRUSH hBrush;
838 UINT text_flags = ETO_CLIPPED;
839 UINT mode = GetBkMode( hdc );
841 hOldFont = SelectObject(hdc, infoPtr->Font);
842 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
843 OldBkColor = SetBkColor(hdc, comctl32_color.clrWindow);
845 GetClientRect(infoPtr->Self, &rc);
846 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
847 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
849 if(rc.right < 0 || rc.bottom < 0) return 0;
851 hBrush = (HBRUSH)SendMessageW(infoPtr->Notify, WM_CTLCOLORSTATIC,
852 (WPARAM)hdc, (LPARAM)infoPtr->Self);
853 if (!(infoPtr->Style & LWS_TRANSPARENT))
855 FillRect(hdc, &rc, hBrush);
856 if (GetBkMode( hdc ) == OPAQUE) text_flags |= ETO_OPAQUE;
858 else SetBkMode( hdc, TRANSPARENT );
860 DeleteObject(hBrush);
862 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
864 int n;
865 LPWSTR tx;
866 PDOC_TEXTBLOCK bl;
868 bl = Current->Blocks;
869 if(bl != NULL)
871 tx = Current->Text;
872 n = Current->nText;
874 if(Current->Type == slText)
876 SelectObject(hdc, infoPtr->Font);
877 SetTextColor(hdc, infoPtr->TextColor);
879 else
881 SelectObject(hdc, infoPtr->LinkFont);
882 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
885 while(n > 0)
887 tx += bl->nSkip;
888 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, text_flags, &bl->rc, tx, bl->nChars, NULL);
889 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
891 COLORREF PrevTextColor;
892 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
893 DrawFocusRect(hdc, &bl->rc);
894 SetTextColor(hdc, PrevTextColor);
896 tx += bl->nChars;
897 n -= bl->nChars + bl->nSkip;
898 bl++;
903 SetBkColor(hdc, OldBkColor);
904 SetTextColor(hdc, OldTextColor);
905 SelectObject(hdc, hOldFont);
906 SetBkMode(hdc, mode);
907 return 0;
911 /***********************************************************************
912 * SYSLINK_Paint
913 * Handles the WM_PAINT message.
915 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
917 HDC hdc;
918 PAINTSTRUCT ps;
920 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
921 if (hdc)
923 SYSLINK_Draw (infoPtr, hdc);
924 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
926 return 0;
929 /***********************************************************************
930 * SYSLINK_SetFont
931 * Set new Font for the SysLink control.
933 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
935 HDC hdc;
936 LOGFONTW lf;
937 TEXTMETRICW tm;
938 RECT rcClient;
939 HFONT hOldFont = infoPtr->Font;
940 infoPtr->Font = hFont;
942 /* free the underline font */
943 if(infoPtr->LinkFont != NULL)
945 DeleteObject(infoPtr->LinkFont);
946 infoPtr->LinkFont = NULL;
949 /* Render text position and word wrapping in memory */
950 if (GetClientRect(infoPtr->Self, &rcClient))
952 hdc = GetDC(infoPtr->Self);
953 if(hdc != NULL)
955 /* create a new underline font */
956 if(GetTextMetricsW(hdc, &tm) &&
957 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
959 lf.lfUnderline = TRUE;
960 infoPtr->LinkFont = CreateFontIndirectW(&lf);
961 infoPtr->BreakChar = tm.tmBreakChar;
963 else
965 ERR("Failed to create link font!\n");
968 SYSLINK_Render(infoPtr, hdc, &rcClient);
969 ReleaseDC(infoPtr->Self, hdc);
973 if(bRedraw)
975 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
978 return hOldFont;
981 /***********************************************************************
982 * SYSLINK_SetText
983 * Set new text for the SysLink control.
985 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
987 /* clear the document */
988 SYSLINK_ClearDoc(infoPtr);
990 if(Text == NULL || *Text == 0)
992 return TRUE;
995 /* let's parse the string and create a document */
996 if(SYSLINK_ParseText(infoPtr, Text) > 0)
998 RECT rcClient;
1000 /* Render text position and word wrapping in memory */
1001 if (GetClientRect(infoPtr->Self, &rcClient))
1003 HDC hdc = GetDC(infoPtr->Self);
1004 if (hdc != NULL)
1006 SYSLINK_Render(infoPtr, hdc, &rcClient);
1007 ReleaseDC(infoPtr->Self, hdc);
1009 InvalidateRect(infoPtr->Self, NULL, TRUE);
1014 return TRUE;
1017 /***********************************************************************
1018 * SYSLINK_SetFocusLink
1019 * Updates the focus status bits and focusses the specified link.
1020 * If no document item is specified, the focus bit will be removed from all links.
1021 * Returns the previous focused item.
1023 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
1025 PDOC_ITEM Current, PrevFocus = NULL;
1027 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1029 if(Current->Type == slLink)
1031 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1033 PrevFocus = Current;
1036 if(Current == DocItem)
1038 Current->u.Link.state |= LIS_FOCUSED;
1040 else
1042 Current->u.Link.state &= ~LIS_FOCUSED;
1047 return PrevFocus;
1050 /***********************************************************************
1051 * SYSLINK_SetItem
1052 * Sets the states and attributes of a link item.
1054 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1056 PDOC_ITEM di;
1057 int nc;
1058 PWSTR szId = NULL;
1059 PWSTR szUrl = NULL;
1060 BOOL Repaint = FALSE;
1062 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1064 ERR("Invalid Flags!\n");
1065 return FALSE;
1068 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1069 if(di == NULL)
1071 ERR("Link %d couldn't be found\n", Item->iLink);
1072 return FALSE;
1075 if(Item->mask & LIF_ITEMID)
1077 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1078 szId = Alloc((nc + 1) * sizeof(WCHAR));
1079 if(szId)
1081 lstrcpynW(szId, Item->szID, nc + 1);
1083 else
1085 ERR("Unable to allocate memory for link id\n");
1086 return FALSE;
1090 if(Item->mask & LIF_URL)
1092 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1093 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1094 if(szUrl)
1096 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1098 else
1100 Free(szId);
1102 ERR("Unable to allocate memory for link url\n");
1103 return FALSE;
1107 if(Item->mask & LIF_ITEMID)
1109 Free(di->u.Link.szID);
1110 di->u.Link.szID = szId;
1113 if(Item->mask & LIF_URL)
1115 Free(di->u.Link.szUrl);
1116 di->u.Link.szUrl = szUrl;
1119 if(Item->mask & LIF_STATE)
1121 UINT oldstate = di->u.Link.state;
1122 /* clear the masked bits */
1123 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1124 /* copy the bits */
1125 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1126 Repaint = (oldstate != di->u.Link.state);
1128 /* update the focus */
1129 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1132 if(Repaint)
1134 SYSLINK_RepaintLink(infoPtr, di);
1137 return TRUE;
1140 /***********************************************************************
1141 * SYSLINK_GetItem
1142 * Retrieves the states and attributes of a link item.
1144 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1146 PDOC_ITEM di;
1148 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1150 ERR("Invalid Flags!\n");
1151 return FALSE;
1154 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1155 if(di == NULL)
1157 ERR("Link %d couldn't be found\n", Item->iLink);
1158 return FALSE;
1161 if(Item->mask & LIF_STATE)
1163 Item->state = (di->u.Link.state & Item->stateMask);
1164 if(!infoPtr->HasFocus)
1166 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1167 Item->state &= ~LIS_FOCUSED;
1171 if(Item->mask & LIF_ITEMID)
1173 if(di->u.Link.szID)
1175 lstrcpyW(Item->szID, di->u.Link.szID);
1177 else
1179 Item->szID[0] = 0;
1183 if(Item->mask & LIF_URL)
1185 if(di->u.Link.szUrl)
1187 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1189 else
1191 Item->szUrl[0] = 0;
1195 return TRUE;
1198 /***********************************************************************
1199 * SYSLINK_PtInDocItem
1200 * Determines if a point is in the region of a document item
1202 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1204 PDOC_TEXTBLOCK bl;
1205 int n;
1207 bl = DocItem->Blocks;
1208 if (bl != NULL)
1210 n = DocItem->nText;
1212 while(n > 0)
1214 if (PtInRect(&bl->rc, pt))
1216 return TRUE;
1218 n -= bl->nChars + bl->nSkip;
1219 bl++;
1223 return FALSE;
1226 /***********************************************************************
1227 * SYSLINK_HitTest
1228 * Determines the link the user clicked on.
1230 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1232 PDOC_ITEM Current;
1233 int id = 0;
1235 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1237 if(Current->Type == slLink)
1239 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1241 HitTest->item.mask = 0;
1242 HitTest->item.iLink = id;
1243 HitTest->item.state = 0;
1244 HitTest->item.stateMask = 0;
1245 if(Current->u.Link.szID)
1247 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1249 else
1251 HitTest->item.szID[0] = 0;
1253 if(Current->u.Link.szUrl)
1255 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1257 else
1259 HitTest->item.szUrl[0] = 0;
1261 return TRUE;
1263 id++;
1267 return FALSE;
1270 /***********************************************************************
1271 * SYSLINK_GetIdealHeight
1272 * Returns the preferred height of a link at the current control's width.
1274 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1276 HDC hdc = GetDC(infoPtr->Self);
1277 if(hdc != NULL)
1279 LRESULT height;
1280 TEXTMETRICW tm;
1281 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1283 if(GetTextMetricsW(hdc, &tm))
1285 height = tm.tmHeight;
1287 else
1289 height = 0;
1291 SelectObject(hdc, hOldFont);
1292 ReleaseDC(infoPtr->Self, hdc);
1294 return height;
1296 return 0;
1299 /***********************************************************************
1300 * SYSLINK_SendParentNotify
1301 * Sends a WM_NOTIFY message to the parent window.
1303 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1305 NMLINK nml;
1307 nml.hdr.hwndFrom = infoPtr->Self;
1308 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1309 nml.hdr.code = code;
1311 nml.item.mask = 0;
1312 nml.item.iLink = iLink;
1313 nml.item.state = 0;
1314 nml.item.stateMask = 0;
1315 if(Link->u.Link.szID)
1317 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1319 else
1321 nml.item.szID[0] = 0;
1323 if(Link->u.Link.szUrl)
1325 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1327 else
1329 nml.item.szUrl[0] = 0;
1332 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1335 /***********************************************************************
1336 * SYSLINK_SetFocus
1337 * Handles receiving the input focus.
1339 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1341 PDOC_ITEM Focus;
1343 infoPtr->HasFocus = TRUE;
1345 /* We always select the first link, even if we activated the control using
1346 SHIFT+TAB. This is the default behavior */
1347 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1348 if(Focus != NULL)
1350 SYSLINK_SetFocusLink(infoPtr, Focus);
1351 SYSLINK_RepaintLink(infoPtr, Focus);
1353 return 0;
1356 /***********************************************************************
1357 * SYSLINK_KillFocus
1358 * Handles losing the input focus.
1360 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1362 PDOC_ITEM Focus;
1364 infoPtr->HasFocus = FALSE;
1365 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1367 if(Focus != NULL)
1369 SYSLINK_RepaintLink(infoPtr, Focus);
1372 return 0;
1375 /***********************************************************************
1376 * SYSLINK_LinkAtPt
1377 * Returns a link at the specified position
1379 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1381 PDOC_ITEM Current;
1382 int id = 0;
1384 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1386 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1387 (!MustBeEnabled || (Current->u.Link.state & LIS_ENABLED)))
1389 if(LinkId != NULL)
1391 *LinkId = id;
1393 return Current;
1395 id++;
1398 return NULL;
1401 /***********************************************************************
1402 * SYSLINK_LButtonDown
1403 * Handles mouse clicks
1405 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1407 PDOC_ITEM Current, Old;
1408 int id;
1410 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1411 if(Current != NULL)
1413 SetFocus(infoPtr->Self);
1415 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1416 if(Old != NULL && Old != Current)
1418 SYSLINK_RepaintLink(infoPtr, Old);
1420 infoPtr->MouseDownID = id;
1421 SYSLINK_RepaintLink(infoPtr, Current);
1424 return 0;
1427 /***********************************************************************
1428 * SYSLINK_LButtonUp
1429 * Handles mouse clicks
1431 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1433 if(infoPtr->MouseDownID > -1)
1435 PDOC_ITEM Current;
1436 int id;
1438 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1439 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1441 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1445 infoPtr->MouseDownID = -1;
1447 return 0;
1450 /***********************************************************************
1451 * SYSLINK_OnEnter
1452 * Handles ENTER key events
1454 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1456 if(infoPtr->HasFocus && !infoPtr->IgnoreReturn)
1458 PDOC_ITEM Focus;
1459 int id;
1461 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1462 if(Focus)
1464 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1465 return TRUE;
1468 return FALSE;
1471 /***********************************************************************
1472 * SYSKEY_SelectNextPrevLink
1473 * Changes the currently focused link
1475 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1477 if(infoPtr->HasFocus)
1479 PDOC_ITEM Focus;
1480 int id;
1482 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1483 if(Focus != NULL)
1485 PDOC_ITEM NewFocus, OldFocus;
1487 if(Prev)
1488 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1489 else
1490 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1492 if(NewFocus != NULL)
1494 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1496 if(OldFocus && OldFocus != NewFocus)
1498 SYSLINK_RepaintLink(infoPtr, OldFocus);
1500 SYSLINK_RepaintLink(infoPtr, NewFocus);
1501 return TRUE;
1505 return FALSE;
1508 /***********************************************************************
1509 * SYSKEY_SelectNextPrevLink
1510 * Determines if there's a next or previous link to decide whether the control
1511 * should capture the tab key message
1513 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1515 PDOC_ITEM Focus, NewFocus;
1517 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1518 if(Prev)
1519 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1520 else
1521 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1523 return NewFocus == NULL;
1526 /***********************************************************************
1527 * SYSLINK_GetIdealSize
1528 * Calculates the ideal size of a link control at a given maximum width.
1530 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1532 RECT rc;
1533 HDC hdc;
1535 rc.left = rc.top = rc.bottom = 0;
1536 rc.right = cxMaxWidth;
1538 hdc = GetDC(infoPtr->Self);
1539 if (hdc != NULL)
1541 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1543 SYSLINK_Render(infoPtr, hdc, &rc);
1545 SelectObject(hdc, hOldFont);
1546 ReleaseDC(infoPtr->Self, hdc);
1548 lpSize->cx = rc.right;
1549 lpSize->cy = rc.bottom;
1553 /***********************************************************************
1554 * SysLinkWindowProc
1556 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1557 WPARAM wParam, LPARAM lParam)
1559 SYSLINK_INFO *infoPtr;
1561 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1563 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1565 if (!infoPtr && message != WM_CREATE)
1566 return DefWindowProcW(hwnd, message, wParam, lParam);
1568 switch(message) {
1569 case WM_PRINTCLIENT:
1570 case WM_PAINT:
1571 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1573 case WM_ERASEBKGND:
1574 if (!(infoPtr->Style & LWS_TRANSPARENT))
1576 HDC hdc = (HDC)wParam;
1577 HBRUSH brush = CreateSolidBrush( comctl32_color.clrWindow );
1578 RECT rect;
1580 GetClipBox( hdc, &rect );
1581 FillRect( hdc, &rect, brush );
1582 DeleteObject( brush );
1583 return 1;
1585 return 0;
1587 case WM_SETCURSOR:
1589 LHITTESTINFO ht;
1590 DWORD mp = GetMessagePos();
1592 ht.pt.x = (short)LOWORD(mp);
1593 ht.pt.y = (short)HIWORD(mp);
1595 ScreenToClient(infoPtr->Self, &ht.pt);
1596 if(SYSLINK_HitTest (infoPtr, &ht))
1598 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1599 return TRUE;
1602 return DefWindowProcW(hwnd, message, wParam, lParam);
1605 case WM_SIZE:
1607 RECT rcClient;
1608 if (GetClientRect(infoPtr->Self, &rcClient))
1610 HDC hdc = GetDC(infoPtr->Self);
1611 if(hdc != NULL)
1613 SYSLINK_Render(infoPtr, hdc, &rcClient);
1614 ReleaseDC(infoPtr->Self, hdc);
1617 return 0;
1620 case WM_GETFONT:
1621 return (LRESULT)infoPtr->Font;
1623 case WM_SETFONT:
1624 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1626 case WM_SETTEXT:
1627 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1628 return DefWindowProcW(hwnd, message, wParam, lParam);
1630 case WM_LBUTTONDOWN:
1632 POINT pt;
1633 pt.x = (short)LOWORD(lParam);
1634 pt.y = (short)HIWORD(lParam);
1635 return SYSLINK_LButtonDown(infoPtr, &pt);
1637 case WM_LBUTTONUP:
1639 POINT pt;
1640 pt.x = (short)LOWORD(lParam);
1641 pt.y = (short)HIWORD(lParam);
1642 return SYSLINK_LButtonUp(infoPtr, &pt);
1645 case WM_KEYDOWN:
1647 switch(wParam)
1649 case VK_RETURN:
1650 SYSLINK_OnEnter(infoPtr);
1651 return 0;
1652 case VK_TAB:
1654 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1655 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1656 return 0;
1658 default:
1659 return DefWindowProcW(hwnd, message, wParam, lParam);
1663 case WM_GETDLGCODE:
1665 LRESULT Ret = DLGC_HASSETSEL;
1666 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1667 switch(vk)
1669 case VK_RETURN:
1670 Ret |= DLGC_WANTMESSAGE;
1671 break;
1672 case VK_TAB:
1674 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1675 if(!SYSLINK_NoNextLink(infoPtr, shift))
1677 Ret |= DLGC_WANTTAB;
1679 else
1681 Ret |= DLGC_WANTCHARS;
1683 break;
1686 return Ret;
1689 case WM_NCHITTEST:
1691 POINT pt;
1692 RECT rc;
1693 pt.x = (short)LOWORD(lParam);
1694 pt.y = (short)HIWORD(lParam);
1696 GetClientRect(infoPtr->Self, &rc);
1697 ScreenToClient(infoPtr->Self, &pt);
1698 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1700 return HTNOWHERE;
1703 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1705 return HTCLIENT;
1708 return HTTRANSPARENT;
1711 case LM_HITTEST:
1712 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1714 case LM_SETITEM:
1715 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1717 case LM_GETITEM:
1718 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1720 case LM_GETIDEALHEIGHT:
1721 if (lParam)
1723 /* LM_GETIDEALSIZE */
1724 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1726 return SYSLINK_GetIdealHeight(infoPtr);
1728 case WM_SETFOCUS:
1729 return SYSLINK_SetFocus(infoPtr);
1731 case WM_KILLFOCUS:
1732 return SYSLINK_KillFocus(infoPtr);
1734 case WM_ENABLE:
1735 infoPtr->Style &= ~WS_DISABLED;
1736 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1737 InvalidateRect (infoPtr->Self, NULL, FALSE);
1738 return 0;
1740 case WM_STYLECHANGED:
1741 if (wParam == GWL_STYLE)
1743 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1745 InvalidateRect(infoPtr->Self, NULL, TRUE);
1747 return 0;
1749 case WM_CREATE:
1750 /* allocate memory for info struct */
1751 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1752 if (!infoPtr) return -1;
1753 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1755 /* initialize the info struct */
1756 infoPtr->Self = hwnd;
1757 infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1758 infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style;
1759 infoPtr->Font = 0;
1760 infoPtr->LinkFont = 0;
1761 infoPtr->Items = NULL;
1762 infoPtr->HasFocus = FALSE;
1763 infoPtr->MouseDownID = -1;
1764 infoPtr->TextColor = comctl32_color.clrWindowText;
1765 infoPtr->LinkColor = comctl32_color.clrHighlight;
1766 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1767 infoPtr->BreakChar = ' ';
1768 infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN;
1769 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1770 SYSLINK_SetText(infoPtr, ((LPCREATESTRUCTW)lParam)->lpszName);
1771 return 0;
1773 case WM_DESTROY:
1774 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1775 SYSLINK_ClearDoc(infoPtr);
1776 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1777 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1778 SetWindowLongPtrW(hwnd, 0, 0);
1779 Free (infoPtr);
1780 return 0;
1782 case WM_SYSCOLORCHANGE:
1783 COMCTL32_RefreshSysColors();
1784 return 0;
1786 default:
1787 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1789 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1791 return DefWindowProcW(hwnd, message, wParam, lParam);
1796 /***********************************************************************
1797 * SYSLINK_Register [Internal]
1799 * Registers the SysLink window class.
1801 VOID SYSLINK_Register (void)
1803 WNDCLASSW wndClass;
1805 ZeroMemory (&wndClass, sizeof(wndClass));
1806 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1807 wndClass.lpfnWndProc = SysLinkWindowProc;
1808 wndClass.cbClsExtra = 0;
1809 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1810 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1811 wndClass.lpszClassName = WC_LINK;
1813 RegisterClassW (&wndClass);
1817 /***********************************************************************
1818 * SYSLINK_Unregister [Internal]
1820 * Unregisters the SysLink window class.
1822 VOID SYSLINK_Unregister (void)
1824 UnregisterClassW (WC_LINK, NULL);