wined3d: Use a separate STATE_VDECL state handler in the GLSL pipeline.
[wine/multimedia.git] / dlls / comctl32 / syslink.c
blobeeb46b98053518c911c9b2d7d782541fe152635d
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 cbl->rc.left = x;
780 cbl->rc.top = y;
781 cbl->rc.right = x + szDim.cx;
782 cbl->rc.bottom = y + szDim.cy;
784 if (cbl->rc.right > szDoc.cx)
785 szDoc.cx = cbl->rc.right;
786 if (cbl->rc.bottom > szDoc.cy)
787 szDoc.cy = cbl->rc.bottom;
789 if(LineLen != 0)
791 x += szDim.cx;
792 if(Wrap)
794 x = SL_LEFTMARGIN;
795 y += LineHeight;
799 else
801 Free(bl);
802 bl = NULL;
803 nBlocks = 0;
805 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
806 break;
808 n -= LineLen;
809 tx += LineLen;
810 SkipChars = 0;
812 else
814 n--;
818 if(nBlocks != 0)
820 Current->Blocks = bl;
824 SelectObject(hdc, hOldFont);
826 pRect->right = pRect->left + szDoc.cx;
827 pRect->bottom = pRect->top + szDoc.cy;
830 /***********************************************************************
831 * SYSLINK_Draw
832 * Draws the SysLink control.
834 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
836 RECT rc;
837 PDOC_ITEM Current;
838 HFONT hOldFont;
839 COLORREF OldTextColor, OldBkColor;
840 HBRUSH hBrush;
841 UINT text_flags = ETO_CLIPPED;
842 UINT mode = GetBkMode( hdc );
844 hOldFont = SelectObject(hdc, infoPtr->Font);
845 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
846 OldBkColor = SetBkColor(hdc, comctl32_color.clrWindow);
848 GetClientRect(infoPtr->Self, &rc);
849 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
850 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
852 if(rc.right < 0 || rc.bottom < 0) return 0;
854 hBrush = (HBRUSH)SendMessageW(infoPtr->Notify, WM_CTLCOLORSTATIC,
855 (WPARAM)hdc, (LPARAM)infoPtr->Self);
856 if (!(infoPtr->Style & LWS_TRANSPARENT))
858 FillRect(hdc, &rc, hBrush);
859 if (GetBkMode( hdc ) == OPAQUE) text_flags |= ETO_OPAQUE;
861 else SetBkMode( hdc, TRANSPARENT );
863 DeleteObject(hBrush);
865 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
867 int n;
868 LPWSTR tx;
869 PDOC_TEXTBLOCK bl;
871 bl = Current->Blocks;
872 if(bl != NULL)
874 tx = Current->Text;
875 n = Current->nText;
877 if(Current->Type == slText)
879 SelectObject(hdc, infoPtr->Font);
880 SetTextColor(hdc, infoPtr->TextColor);
882 else
884 SelectObject(hdc, infoPtr->LinkFont);
885 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
888 while(n > 0)
890 tx += bl->nSkip;
891 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, text_flags, &bl->rc, tx, bl->nChars, NULL);
892 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
894 COLORREF PrevTextColor;
895 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
896 DrawFocusRect(hdc, &bl->rc);
897 SetTextColor(hdc, PrevTextColor);
899 tx += bl->nChars;
900 n -= bl->nChars + bl->nSkip;
901 bl++;
906 SetBkColor(hdc, OldBkColor);
907 SetTextColor(hdc, OldTextColor);
908 SelectObject(hdc, hOldFont);
909 SetBkMode(hdc, mode);
910 return 0;
914 /***********************************************************************
915 * SYSLINK_Paint
916 * Handles the WM_PAINT message.
918 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
920 HDC hdc;
921 PAINTSTRUCT ps;
923 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
924 if (hdc)
926 SYSLINK_Draw (infoPtr, hdc);
927 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
929 return 0;
932 /***********************************************************************
933 * SYSLINK_SetFont
934 * Set new Font for the SysLink control.
936 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
938 HDC hdc;
939 LOGFONTW lf;
940 TEXTMETRICW tm;
941 RECT rcClient;
942 HFONT hOldFont = infoPtr->Font;
943 infoPtr->Font = hFont;
945 /* free the underline font */
946 if(infoPtr->LinkFont != NULL)
948 DeleteObject(infoPtr->LinkFont);
949 infoPtr->LinkFont = NULL;
952 /* Render text position and word wrapping in memory */
953 if (GetClientRect(infoPtr->Self, &rcClient))
955 hdc = GetDC(infoPtr->Self);
956 if(hdc != NULL)
958 /* create a new underline font */
959 if(GetTextMetricsW(hdc, &tm) &&
960 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
962 lf.lfUnderline = TRUE;
963 infoPtr->LinkFont = CreateFontIndirectW(&lf);
964 infoPtr->BreakChar = tm.tmBreakChar;
966 else
968 ERR("Failed to create link font!\n");
971 SYSLINK_Render(infoPtr, hdc, &rcClient);
972 ReleaseDC(infoPtr->Self, hdc);
976 if(bRedraw)
978 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
981 return hOldFont;
984 /***********************************************************************
985 * SYSLINK_SetText
986 * Set new text for the SysLink control.
988 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
990 /* clear the document */
991 SYSLINK_ClearDoc(infoPtr);
993 if(Text == NULL || *Text == 0)
995 return TRUE;
998 /* let's parse the string and create a document */
999 if(SYSLINK_ParseText(infoPtr, Text) > 0)
1001 RECT rcClient;
1003 /* Render text position and word wrapping in memory */
1004 if (GetClientRect(infoPtr->Self, &rcClient))
1006 HDC hdc = GetDC(infoPtr->Self);
1007 if (hdc != NULL)
1009 SYSLINK_Render(infoPtr, hdc, &rcClient);
1010 ReleaseDC(infoPtr->Self, hdc);
1012 InvalidateRect(infoPtr->Self, NULL, TRUE);
1017 return TRUE;
1020 /***********************************************************************
1021 * SYSLINK_SetFocusLink
1022 * Updates the focus status bits and focusses the specified link.
1023 * If no document item is specified, the focus bit will be removed from all links.
1024 * Returns the previous focused item.
1026 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
1028 PDOC_ITEM Current, PrevFocus = NULL;
1030 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1032 if(Current->Type == slLink)
1034 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1036 PrevFocus = Current;
1039 if(Current == DocItem)
1041 Current->u.Link.state |= LIS_FOCUSED;
1043 else
1045 Current->u.Link.state &= ~LIS_FOCUSED;
1050 return PrevFocus;
1053 /***********************************************************************
1054 * SYSLINK_SetItem
1055 * Sets the states and attributes of a link item.
1057 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1059 PDOC_ITEM di;
1060 int nc;
1061 PWSTR szId = NULL;
1062 PWSTR szUrl = NULL;
1063 BOOL Repaint = FALSE;
1065 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1067 ERR("Invalid Flags!\n");
1068 return FALSE;
1071 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1072 if(di == NULL)
1074 ERR("Link %d couldn't be found\n", Item->iLink);
1075 return FALSE;
1078 if(Item->mask & LIF_ITEMID)
1080 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1081 szId = Alloc((nc + 1) * sizeof(WCHAR));
1082 if(szId)
1084 lstrcpynW(szId, Item->szID, nc + 1);
1086 else
1088 ERR("Unable to allocate memory for link id\n");
1089 return FALSE;
1093 if(Item->mask & LIF_URL)
1095 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1096 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1097 if(szUrl)
1099 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1101 else
1103 Free(szId);
1105 ERR("Unable to allocate memory for link url\n");
1106 return FALSE;
1110 if(Item->mask & LIF_ITEMID)
1112 Free(di->u.Link.szID);
1113 di->u.Link.szID = szId;
1116 if(Item->mask & LIF_URL)
1118 Free(di->u.Link.szUrl);
1119 di->u.Link.szUrl = szUrl;
1122 if(Item->mask & LIF_STATE)
1124 UINT oldstate = di->u.Link.state;
1125 /* clear the masked bits */
1126 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1127 /* copy the bits */
1128 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1129 Repaint = (oldstate != di->u.Link.state);
1131 /* update the focus */
1132 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1135 if(Repaint)
1137 SYSLINK_RepaintLink(infoPtr, di);
1140 return TRUE;
1143 /***********************************************************************
1144 * SYSLINK_GetItem
1145 * Retrieves the states and attributes of a link item.
1147 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1149 PDOC_ITEM di;
1151 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1153 ERR("Invalid Flags!\n");
1154 return FALSE;
1157 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1158 if(di == NULL)
1160 ERR("Link %d couldn't be found\n", Item->iLink);
1161 return FALSE;
1164 if(Item->mask & LIF_STATE)
1166 Item->state = (di->u.Link.state & Item->stateMask);
1167 if(!infoPtr->HasFocus)
1169 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1170 Item->state &= ~LIS_FOCUSED;
1174 if(Item->mask & LIF_ITEMID)
1176 if(di->u.Link.szID)
1178 lstrcpyW(Item->szID, di->u.Link.szID);
1180 else
1182 Item->szID[0] = 0;
1186 if(Item->mask & LIF_URL)
1188 if(di->u.Link.szUrl)
1190 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1192 else
1194 Item->szUrl[0] = 0;
1198 return TRUE;
1201 /***********************************************************************
1202 * SYSLINK_PtInDocItem
1203 * Determines if a point is in the region of a document item
1205 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1207 PDOC_TEXTBLOCK bl;
1208 int n;
1210 bl = DocItem->Blocks;
1211 if (bl != NULL)
1213 n = DocItem->nText;
1215 while(n > 0)
1217 if (PtInRect(&bl->rc, pt))
1219 return TRUE;
1221 n -= bl->nChars + bl->nSkip;
1222 bl++;
1226 return FALSE;
1229 /***********************************************************************
1230 * SYSLINK_HitTest
1231 * Determines the link the user clicked on.
1233 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1235 PDOC_ITEM Current;
1236 int id = 0;
1238 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1240 if(Current->Type == slLink)
1242 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1244 HitTest->item.mask = 0;
1245 HitTest->item.iLink = id;
1246 HitTest->item.state = 0;
1247 HitTest->item.stateMask = 0;
1248 if(Current->u.Link.szID)
1250 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1252 else
1254 HitTest->item.szID[0] = 0;
1256 if(Current->u.Link.szUrl)
1258 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1260 else
1262 HitTest->item.szUrl[0] = 0;
1264 return TRUE;
1266 id++;
1270 return FALSE;
1273 /***********************************************************************
1274 * SYSLINK_GetIdealHeight
1275 * Returns the preferred height of a link at the current control's width.
1277 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1279 HDC hdc = GetDC(infoPtr->Self);
1280 if(hdc != NULL)
1282 LRESULT height;
1283 TEXTMETRICW tm;
1284 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1286 if(GetTextMetricsW(hdc, &tm))
1288 height = tm.tmHeight;
1290 else
1292 height = 0;
1294 SelectObject(hdc, hOldFont);
1295 ReleaseDC(infoPtr->Self, hdc);
1297 return height;
1299 return 0;
1302 /***********************************************************************
1303 * SYSLINK_SendParentNotify
1304 * Sends a WM_NOTIFY message to the parent window.
1306 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1308 NMLINK nml;
1310 nml.hdr.hwndFrom = infoPtr->Self;
1311 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1312 nml.hdr.code = code;
1314 nml.item.mask = 0;
1315 nml.item.iLink = iLink;
1316 nml.item.state = 0;
1317 nml.item.stateMask = 0;
1318 if(Link->u.Link.szID)
1320 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1322 else
1324 nml.item.szID[0] = 0;
1326 if(Link->u.Link.szUrl)
1328 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1330 else
1332 nml.item.szUrl[0] = 0;
1335 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1338 /***********************************************************************
1339 * SYSLINK_SetFocus
1340 * Handles receiving the input focus.
1342 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1344 PDOC_ITEM Focus;
1346 infoPtr->HasFocus = TRUE;
1348 /* We always select the first link, even if we activated the control using
1349 SHIFT+TAB. This is the default behavior */
1350 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1351 if(Focus != NULL)
1353 SYSLINK_SetFocusLink(infoPtr, Focus);
1354 SYSLINK_RepaintLink(infoPtr, Focus);
1356 return 0;
1359 /***********************************************************************
1360 * SYSLINK_KillFocus
1361 * Handles losing the input focus.
1363 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1365 PDOC_ITEM Focus;
1367 infoPtr->HasFocus = FALSE;
1368 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1370 if(Focus != NULL)
1372 SYSLINK_RepaintLink(infoPtr, Focus);
1375 return 0;
1378 /***********************************************************************
1379 * SYSLINK_LinkAtPt
1380 * Returns a link at the specified position
1382 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1384 PDOC_ITEM Current;
1385 int id = 0;
1387 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1389 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1390 (!MustBeEnabled || (MustBeEnabled && (Current->u.Link.state & LIS_ENABLED))))
1392 if(LinkId != NULL)
1394 *LinkId = id;
1396 return Current;
1398 id++;
1401 return NULL;
1404 /***********************************************************************
1405 * SYSLINK_LButtonDown
1406 * Handles mouse clicks
1408 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1410 PDOC_ITEM Current, Old;
1411 int id;
1413 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1414 if(Current != NULL)
1416 SetFocus(infoPtr->Self);
1418 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1419 if(Old != NULL && Old != Current)
1421 SYSLINK_RepaintLink(infoPtr, Old);
1423 infoPtr->MouseDownID = id;
1424 SYSLINK_RepaintLink(infoPtr, Current);
1427 return 0;
1430 /***********************************************************************
1431 * SYSLINK_LButtonUp
1432 * Handles mouse clicks
1434 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1436 if(infoPtr->MouseDownID > -1)
1438 PDOC_ITEM Current;
1439 int id;
1441 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1442 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1444 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1448 infoPtr->MouseDownID = -1;
1450 return 0;
1453 /***********************************************************************
1454 * SYSLINK_OnEnter
1455 * Handles ENTER key events
1457 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1459 if(infoPtr->HasFocus && !infoPtr->IgnoreReturn)
1461 PDOC_ITEM Focus;
1462 int id;
1464 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1465 if(Focus)
1467 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1468 return TRUE;
1471 return FALSE;
1474 /***********************************************************************
1475 * SYSKEY_SelectNextPrevLink
1476 * Changes the currently focused link
1478 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1480 if(infoPtr->HasFocus)
1482 PDOC_ITEM Focus;
1483 int id;
1485 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1486 if(Focus != NULL)
1488 PDOC_ITEM NewFocus, OldFocus;
1490 if(Prev)
1491 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1492 else
1493 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1495 if(NewFocus != NULL)
1497 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1499 if(OldFocus && OldFocus != NewFocus)
1501 SYSLINK_RepaintLink(infoPtr, OldFocus);
1503 SYSLINK_RepaintLink(infoPtr, NewFocus);
1504 return TRUE;
1508 return FALSE;
1511 /***********************************************************************
1512 * SYSKEY_SelectNextPrevLink
1513 * Determines if there's a next or previous link to decide whether the control
1514 * should capture the tab key message
1516 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1518 PDOC_ITEM Focus, NewFocus;
1520 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1521 if(Prev)
1522 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1523 else
1524 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1526 return NewFocus == NULL;
1529 /***********************************************************************
1530 * SYSLINK_GetIdealSize
1531 * Calculates the ideal size of a link control at a given maximum width.
1533 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1535 RECT rc;
1536 HDC hdc;
1538 rc.left = rc.top = rc.bottom = 0;
1539 rc.right = cxMaxWidth;
1541 hdc = GetDC(infoPtr->Self);
1542 if (hdc != NULL)
1544 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1546 SYSLINK_Render(infoPtr, hdc, &rc);
1548 SelectObject(hdc, hOldFont);
1549 ReleaseDC(infoPtr->Self, hdc);
1551 lpSize->cx = rc.right;
1552 lpSize->cy = rc.bottom;
1556 /***********************************************************************
1557 * SysLinkWindowProc
1559 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1560 WPARAM wParam, LPARAM lParam)
1562 SYSLINK_INFO *infoPtr;
1564 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1566 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1568 if (!infoPtr && message != WM_CREATE)
1569 return DefWindowProcW(hwnd, message, wParam, lParam);
1571 switch(message) {
1572 case WM_PRINTCLIENT:
1573 case WM_PAINT:
1574 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1576 case WM_ERASEBKGND:
1577 if (!(infoPtr->Style & LWS_TRANSPARENT))
1579 HDC hdc = (HDC)wParam;
1580 HBRUSH brush = CreateSolidBrush( comctl32_color.clrWindow );
1581 RECT rect;
1583 GetClipBox( hdc, &rect );
1584 FillRect( hdc, &rect, brush );
1585 DeleteObject( brush );
1586 return 1;
1588 return 0;
1590 case WM_SETCURSOR:
1592 LHITTESTINFO ht;
1593 DWORD mp = GetMessagePos();
1595 ht.pt.x = (short)LOWORD(mp);
1596 ht.pt.y = (short)HIWORD(mp);
1598 ScreenToClient(infoPtr->Self, &ht.pt);
1599 if(SYSLINK_HitTest (infoPtr, &ht))
1601 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1602 return TRUE;
1605 return DefWindowProcW(hwnd, message, wParam, lParam);
1608 case WM_SIZE:
1610 RECT rcClient;
1611 if (GetClientRect(infoPtr->Self, &rcClient))
1613 HDC hdc = GetDC(infoPtr->Self);
1614 if(hdc != NULL)
1616 SYSLINK_Render(infoPtr, hdc, &rcClient);
1617 ReleaseDC(infoPtr->Self, hdc);
1620 return 0;
1623 case WM_GETFONT:
1624 return (LRESULT)infoPtr->Font;
1626 case WM_SETFONT:
1627 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1629 case WM_SETTEXT:
1630 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1631 return DefWindowProcW(hwnd, message, wParam, lParam);
1633 case WM_LBUTTONDOWN:
1635 POINT pt;
1636 pt.x = (short)LOWORD(lParam);
1637 pt.y = (short)HIWORD(lParam);
1638 return SYSLINK_LButtonDown(infoPtr, &pt);
1640 case WM_LBUTTONUP:
1642 POINT pt;
1643 pt.x = (short)LOWORD(lParam);
1644 pt.y = (short)HIWORD(lParam);
1645 return SYSLINK_LButtonUp(infoPtr, &pt);
1648 case WM_KEYDOWN:
1650 switch(wParam)
1652 case VK_RETURN:
1653 SYSLINK_OnEnter(infoPtr);
1654 return 0;
1655 case VK_TAB:
1657 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1658 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1659 return 0;
1661 default:
1662 return DefWindowProcW(hwnd, message, wParam, lParam);
1666 case WM_GETDLGCODE:
1668 LRESULT Ret = DLGC_HASSETSEL;
1669 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1670 switch(vk)
1672 case VK_RETURN:
1673 Ret |= DLGC_WANTMESSAGE;
1674 break;
1675 case VK_TAB:
1677 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1678 if(!SYSLINK_NoNextLink(infoPtr, shift))
1680 Ret |= DLGC_WANTTAB;
1682 else
1684 Ret |= DLGC_WANTCHARS;
1686 break;
1689 return Ret;
1692 case WM_NCHITTEST:
1694 POINT pt;
1695 RECT rc;
1696 pt.x = (short)LOWORD(lParam);
1697 pt.y = (short)HIWORD(lParam);
1699 GetClientRect(infoPtr->Self, &rc);
1700 ScreenToClient(infoPtr->Self, &pt);
1701 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1703 return HTNOWHERE;
1706 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1708 return HTCLIENT;
1711 return HTTRANSPARENT;
1714 case LM_HITTEST:
1715 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1717 case LM_SETITEM:
1718 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1720 case LM_GETITEM:
1721 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1723 case LM_GETIDEALHEIGHT:
1724 if (lParam)
1726 /* LM_GETIDEALSIZE */
1727 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1729 return SYSLINK_GetIdealHeight(infoPtr);
1731 case WM_SETFOCUS:
1732 return SYSLINK_SetFocus(infoPtr);
1734 case WM_KILLFOCUS:
1735 return SYSLINK_KillFocus(infoPtr);
1737 case WM_ENABLE:
1738 infoPtr->Style &= ~WS_DISABLED;
1739 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1740 InvalidateRect (infoPtr->Self, NULL, FALSE);
1741 return 0;
1743 case WM_STYLECHANGED:
1744 if (wParam == GWL_STYLE)
1746 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1748 InvalidateRect(infoPtr->Self, NULL, TRUE);
1750 return 0;
1752 case WM_CREATE:
1753 /* allocate memory for info struct */
1754 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1755 if (!infoPtr) return -1;
1756 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1758 /* initialize the info struct */
1759 infoPtr->Self = hwnd;
1760 infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1761 infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style;
1762 infoPtr->Font = 0;
1763 infoPtr->LinkFont = 0;
1764 infoPtr->Items = NULL;
1765 infoPtr->HasFocus = FALSE;
1766 infoPtr->MouseDownID = -1;
1767 infoPtr->TextColor = comctl32_color.clrWindowText;
1768 infoPtr->LinkColor = comctl32_color.clrHighlight;
1769 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1770 infoPtr->BreakChar = ' ';
1771 infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN;
1772 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1773 SYSLINK_SetText(infoPtr, ((LPCREATESTRUCTW)lParam)->lpszName);
1774 return 0;
1776 case WM_DESTROY:
1777 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1778 SYSLINK_ClearDoc(infoPtr);
1779 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1780 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1781 SetWindowLongPtrW(hwnd, 0, 0);
1782 Free (infoPtr);
1783 return 0;
1785 case WM_SYSCOLORCHANGE:
1786 COMCTL32_RefreshSysColors();
1787 return 0;
1789 default:
1790 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1792 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1794 return DefWindowProcW(hwnd, message, wParam, lParam);
1799 /***********************************************************************
1800 * SYSLINK_Register [Internal]
1802 * Registers the SysLink window class.
1804 VOID SYSLINK_Register (void)
1806 WNDCLASSW wndClass;
1808 ZeroMemory (&wndClass, sizeof(wndClass));
1809 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1810 wndClass.lpfnWndProc = SysLinkWindowProc;
1811 wndClass.cbClsExtra = 0;
1812 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1813 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1814 wndClass.lpszClassName = WC_LINK;
1816 RegisterClassW (&wndClass);
1820 /***********************************************************************
1821 * SYSLINK_Unregister [Internal]
1823 * Unregisters the SysLink window class.
1825 VOID SYSLINK_Unregister (void)
1827 UnregisterClassW (WC_LINK, NULL);