include: Use the hard-float calling convention for Windows APIs on ARM
[wine.git] / dlls / comctl32 / syslink.c
blob339c7282477673a0ee34f3b17d623cb4dbdfd3b0
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"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(syslink);
45 typedef struct
47 int nChars;
48 int nSkip;
49 RECT rc;
50 } DOC_TEXTBLOCK, *PDOC_TEXTBLOCK;
52 #define LIF_FLAGSMASK (LIF_STATE | LIF_ITEMID | LIF_URL)
53 #define LIS_MASK (LIS_FOCUSED | LIS_ENABLED | LIS_VISITED)
55 typedef enum
57 slText = 0,
58 slLink
59 } SL_ITEM_TYPE;
61 typedef struct _DOC_ITEM
63 struct list entry;
64 UINT nText; /* Number of characters of the text */
65 SL_ITEM_TYPE Type; /* type of the item */
66 PDOC_TEXTBLOCK Blocks; /* Array of text blocks */
67 union
69 struct
71 UINT state; /* Link state */
72 WCHAR *szID; /* Link ID string */
73 WCHAR *szUrl; /* Link URL string */
74 } Link;
75 struct
77 UINT Dummy;
78 } Text;
79 } u;
80 WCHAR Text[1]; /* Text of the document item */
81 } DOC_ITEM, *PDOC_ITEM;
83 typedef struct
85 HWND Self; /* The window handle for this control */
86 HWND Notify; /* The parent handle to receive notifications */
87 DWORD Style; /* Styles for this control */
88 struct list Items; /* Document items list */
89 BOOL HasFocus; /* Whether the control has the input focus */
90 int MouseDownID; /* ID of the link that the mouse button first selected */
91 HFONT Font; /* Handle to the font for text */
92 HFONT LinkFont; /* Handle to the font for links */
93 COLORREF TextColor; /* Color of the text */
94 COLORREF LinkColor; /* Color of links */
95 COLORREF VisitedColor; /* Color of visited links */
96 WCHAR BreakChar; /* Break Character for the current font */
97 BOOL IgnoreReturn; /* (infoPtr->Style & LWS_IGNORERETURN) on creation */
98 } SYSLINK_INFO;
100 /* Control configuration constants */
102 #define SL_LEFTMARGIN (0)
103 #define SL_TOPMARGIN (0)
104 #define SL_RIGHTMARGIN (0)
105 #define SL_BOTTOMMARGIN (0)
107 /***********************************************************************
108 * SYSLINK_FreeDocItem
109 * Frees all data and gdi objects associated with a document item
111 static VOID SYSLINK_FreeDocItem (PDOC_ITEM DocItem)
113 if(DocItem->Type == slLink)
115 Free(DocItem->u.Link.szID);
116 Free(DocItem->u.Link.szUrl);
119 Free(DocItem->Blocks);
121 /* we don't free Text because it's just a pointer to a character in the
122 entire window text string */
124 Free(DocItem);
127 /***********************************************************************
128 * SYSLINK_AppendDocItem
129 * Create and append a new document item.
131 static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UINT textlen,
132 SL_ITEM_TYPE type, PDOC_ITEM LastItem)
134 PDOC_ITEM Item;
136 textlen = min(textlen, strlenW(Text));
137 Item = Alloc(FIELD_OFFSET(DOC_ITEM, Text[textlen + 1]));
138 if(Item == NULL)
140 ERR("Failed to alloc DOC_ITEM structure!\n");
141 return NULL;
144 Item->nText = textlen;
145 Item->Type = type;
146 Item->Blocks = NULL;
147 lstrcpynW(Item->Text, Text, textlen + 1);
148 if (LastItem)
149 list_add_after(&LastItem->entry, &Item->entry);
150 else
151 list_add_tail(&infoPtr->Items, &Item->entry);
153 return Item;
156 /***********************************************************************
157 * SYSLINK_ClearDoc
158 * Clears the document tree
160 static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
162 DOC_ITEM *Item, *Item2;
164 LIST_FOR_EACH_ENTRY_SAFE(Item, Item2, &infoPtr->Items, DOC_ITEM, entry)
166 list_remove(&Item->entry);
167 SYSLINK_FreeDocItem(Item);
171 /***********************************************************************
172 * SYSLINK_ParseText
173 * Parses the window text string and creates a document. Returns the
174 * number of document items created.
176 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
178 static const WCHAR SL_LINKOPEN[] = { '<','a' };
179 static const WCHAR SL_HREF[] = { 'h','r','e','f','=','\"' };
180 static const WCHAR SL_ID[] = { 'i','d','=','\"' };
181 static const WCHAR SL_LINKCLOSE[] = { '<','/','a','>' };
182 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
183 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
184 PDOC_ITEM Last = NULL;
185 SL_ITEM_TYPE CurrentType = slText;
186 LPCWSTR lpID, lpUrl;
187 UINT lenId, lenUrl;
189 TRACE("(%p %s)\n", infoPtr, debugstr_w(Text));
191 for(current = Text; *current != 0;)
193 if(*current == '<')
195 if(!strncmpiW(current, SL_LINKOPEN, sizeof(SL_LINKOPEN)/sizeof(SL_LINKOPEN[0])) && (CurrentType == slText))
197 BOOL ValidParam = FALSE, ValidLink = FALSE;
199 if(*(current + 2) == '>')
201 /* we just have to deal with a <a> tag */
202 taglen = 3;
203 ValidLink = TRUE;
204 ValidParam = TRUE;
205 firsttag = current;
206 linklen = 0;
207 lpID = NULL;
208 lpUrl = NULL;
210 else if(*(current + 2) == infoPtr->BreakChar)
212 /* we expect parameters, parse them */
213 LPCWSTR *CurrentParameter = NULL, tmp;
214 UINT *CurrentParameterLen = NULL;
216 taglen = 3;
217 tmp = current + taglen;
218 lpID = NULL;
219 lpUrl = NULL;
221 CheckParameter:
222 /* compare the current position with all known parameters */
223 if(!strncmpiW(tmp, SL_HREF, sizeof(SL_HREF)/sizeof(SL_HREF[0])))
225 taglen += 6;
226 ValidParam = TRUE;
227 CurrentParameter = &lpUrl;
228 CurrentParameterLen = &lenUrl;
230 else if(!strncmpiW(tmp, SL_ID, sizeof(SL_ID)/sizeof(SL_ID[0])))
232 taglen += 4;
233 ValidParam = TRUE;
234 CurrentParameter = &lpID;
235 CurrentParameterLen = &lenId;
237 else
239 ValidParam = FALSE;
242 if(ValidParam)
244 /* we got a known parameter, now search until the next " character.
245 If we can't find a " character, there's a syntax error and we just assume it's text */
246 ValidParam = FALSE;
247 *CurrentParameter = current + taglen;
248 *CurrentParameterLen = 0;
250 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
252 taglen++;
253 if(*tmp == '\"')
255 ValidParam = TRUE;
256 tmp++;
257 break;
259 (*CurrentParameterLen)++;
262 if(ValidParam)
264 /* we're done with this parameter, now there are only 2 possibilities:
265 * 1. another parameter is coming, so expect a ' ' (space) character
266 * 2. the tag is being closed, so expect a '<' character
268 if(*tmp == infoPtr->BreakChar)
270 /* we expect another parameter, do the whole thing again */
271 taglen++;
272 tmp++;
273 goto CheckParameter;
275 else if(*tmp == '>')
277 /* the tag is being closed, we're done */
278 ValidLink = TRUE;
279 taglen++;
284 if(ValidLink && ValidParam)
286 /* the <a ...> tag appears to be valid. save all information
287 so we can add the link if we find a valid </a> tag later */
288 CurrentType = slLink;
289 linktext = current + taglen;
290 linklen = 0;
291 firsttag = current;
293 else
295 taglen = 1;
296 lpID = NULL;
297 lpUrl = NULL;
298 if(textstart == NULL)
300 textstart = current;
304 else if(!strncmpiW(current, SL_LINKCLOSE, sizeof(SL_LINKCLOSE)/sizeof(SL_LINKCLOSE[0])) && (CurrentType == slLink) && firsttag)
306 /* there's a <a...> tag opened, first add the previous text, if present */
307 if(textstart != NULL && textlen > 0 && firsttag > textstart)
309 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
310 if(Last == NULL)
312 ERR("Unable to create new document item!\n");
313 return docitems;
315 docitems++;
316 textstart = NULL;
317 textlen = 0;
320 /* now it's time to add the link to the document */
321 current += 4;
322 if(linktext != NULL && linklen > 0)
324 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
325 if(Last == NULL)
327 ERR("Unable to create new document item!\n");
328 return docitems;
330 docitems++;
331 if(CurrentType == slLink)
333 int nc;
335 if(!(infoPtr->Style & WS_DISABLED))
337 Last->u.Link.state |= LIS_ENABLED;
339 /* Copy the tag parameters */
340 if(lpID != NULL)
342 nc = min(lenId, strlenW(lpID));
343 nc = min(nc, MAX_LINKID_TEXT - 1);
344 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
345 if(Last->u.Link.szID != NULL)
347 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
350 else
351 Last->u.Link.szID = NULL;
352 if(lpUrl != NULL)
354 nc = min(lenUrl, strlenW(lpUrl));
355 nc = min(nc, L_MAX_URL_LENGTH - 1);
356 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
357 if(Last->u.Link.szUrl != NULL)
359 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
362 else
363 Last->u.Link.szUrl = NULL;
365 linktext = NULL;
367 CurrentType = slText;
368 firsttag = NULL;
369 textstart = NULL;
370 continue;
372 else
374 /* we don't know what tag it is, so just continue */
375 taglen = 1;
376 linklen++;
377 if(CurrentType == slText && textstart == NULL)
379 textstart = current;
383 textlen += taglen;
384 current += taglen;
386 else
388 textlen++;
389 linklen++;
391 /* save the pointer of the current text item if we couldn't find a tag */
392 if(textstart == NULL && CurrentType == slText)
394 textstart = current;
397 current++;
401 if(textstart != NULL && textlen > 0)
403 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
404 if(Last == NULL)
406 ERR("Unable to create new document item!\n");
407 return docitems;
409 if(CurrentType == slLink)
411 int nc;
413 if(!(infoPtr->Style & WS_DISABLED))
415 Last->u.Link.state |= LIS_ENABLED;
417 /* Copy the tag parameters */
418 if(lpID != NULL)
420 nc = min(lenId, strlenW(lpID));
421 nc = min(nc, MAX_LINKID_TEXT - 1);
422 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
423 if(Last->u.Link.szID != NULL)
425 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
428 else
429 Last->u.Link.szID = NULL;
430 if(lpUrl != NULL)
432 nc = min(lenUrl, strlenW(lpUrl));
433 nc = min(nc, L_MAX_URL_LENGTH - 1);
434 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
435 if(Last->u.Link.szUrl != NULL)
437 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
440 else
441 Last->u.Link.szUrl = NULL;
443 docitems++;
446 if(linktext != NULL && linklen > 0)
448 /* we got an unclosed link, just display the text */
449 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
450 if(Last == NULL)
452 ERR("Unable to create new document item!\n");
453 return docitems;
455 docitems++;
458 return docitems;
461 /***********************************************************************
462 * SYSLINK_RepaintLink
463 * Repaints a link.
465 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
467 PDOC_TEXTBLOCK bl;
468 int n;
470 if(DocItem->Type != slLink)
472 ERR("DocItem not a link!\n");
473 return;
476 bl = DocItem->Blocks;
477 if (bl != NULL)
479 n = DocItem->nText;
481 while(n > 0)
483 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
484 n -= bl->nChars + bl->nSkip;
485 bl++;
490 /***********************************************************************
491 * SYSLINK_GetLinkItemByIndex
492 * Retrieves a document link by its index
494 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
496 DOC_ITEM *Current;
498 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
500 if ((Current->Type == slLink) && (iLink-- <= 0))
501 return Current;
503 return NULL;
506 /***********************************************************************
507 * SYSLINK_GetFocusLink
508 * Retrieves the link that has the LIS_FOCUSED bit
510 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
512 DOC_ITEM *Current;
513 int id = 0;
515 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
517 if(Current->Type == slLink)
519 if(Current->u.Link.state & LIS_FOCUSED)
521 if(LinkId != NULL)
522 *LinkId = id;
523 return Current;
525 id++;
529 return NULL;
532 /***********************************************************************
533 * SYSLINK_GetNextLink
534 * Gets the next link
536 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
538 DOC_ITEM *Next;
540 LIST_FOR_EACH_ENTRY(Next, Current ? &Current->entry : &infoPtr->Items, DOC_ITEM, entry)
542 if (Next->Type == slLink)
544 return Next;
547 return NULL;
550 /***********************************************************************
551 * SYSLINK_GetPrevLink
552 * Gets the previous link
554 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
556 DOC_ITEM *Prev;
558 LIST_FOR_EACH_ENTRY_REV(Prev, Current ? &Current->entry : list_tail(&infoPtr->Items), DOC_ITEM, entry)
560 if (Prev->Type == slLink)
562 return Prev;
566 return NULL;
569 /***********************************************************************
570 * SYSLINK_WrapLine
571 * Tries to wrap a line.
573 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int x, int *LineLen,
574 int nFit, LPSIZE Extent)
576 int i;
578 for (i = 0; i < nFit; i++) if (Text[i] == '\n') break;
580 if (i == *LineLen) return FALSE;
582 /* check if we're in the middle of a word */
583 if (Text[i] != '\n' && Text[i] != BreakChar)
585 /* search for the beginning of the word */
586 while (i && Text[i - 1] != BreakChar) i--;
588 if (i == 0)
590 Extent->cx = 0;
591 Extent->cy = 0;
592 if (x == SL_LEFTMARGIN) i = max( nFit, 1 );
595 *LineLen = i;
596 return TRUE;
599 /***********************************************************************
600 * SYSLINK_Render
601 * Renders the document in memory
603 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
605 RECT rc;
606 PDOC_ITEM Current;
607 HGDIOBJ hOldFont;
608 int x, y, LineHeight;
609 SIZE szDoc;
610 TEXTMETRICW tm;
612 szDoc.cx = szDoc.cy = 0;
614 rc = *pRect;
615 rc.right -= SL_RIGHTMARGIN;
616 rc.bottom -= SL_BOTTOMMARGIN;
618 if(rc.right - SL_LEFTMARGIN < 0)
619 rc.right = MAXLONG;
620 if (rc.bottom - SL_TOPMARGIN < 0)
621 rc.bottom = MAXLONG;
623 hOldFont = SelectObject(hdc, infoPtr->Font);
625 x = SL_LEFTMARGIN;
626 y = SL_TOPMARGIN;
627 GetTextMetricsW( hdc, &tm );
628 LineHeight = tm.tmHeight + tm.tmExternalLeading;
630 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
632 int n, nBlocks;
633 LPWSTR tx;
634 PDOC_TEXTBLOCK bl, cbl;
635 INT nFit;
636 SIZE szDim;
637 int SkipChars = 0;
639 if(Current->nText == 0)
641 continue;
644 tx = Current->Text;
645 n = Current->nText;
647 Free(Current->Blocks);
648 Current->Blocks = NULL;
649 bl = NULL;
650 nBlocks = 0;
652 if(Current->Type == slText)
654 SelectObject(hdc, infoPtr->Font);
656 else if(Current->Type == slLink)
658 SelectObject(hdc, infoPtr->LinkFont);
661 while(n > 0)
663 /* skip break characters unless they're the first of the doc item */
664 if(tx != Current->Text || x == SL_LEFTMARGIN)
666 if (n && *tx == '\n')
668 tx++;
669 SkipChars++;
670 n--;
672 while(n > 0 && (*tx) == infoPtr->BreakChar)
674 tx++;
675 SkipChars++;
676 n--;
680 if((n == 0 && SkipChars != 0) ||
681 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
683 int LineLen = n;
684 BOOL Wrap = FALSE;
685 PDOC_TEXTBLOCK nbl;
687 if(n != 0)
689 Wrap = SYSLINK_WrapLine(tx, infoPtr->BreakChar, x, &LineLen, nFit, &szDim);
691 if(LineLen == 0)
693 /* move one line down, the word didn't fit into the line */
694 x = SL_LEFTMARGIN;
695 y += LineHeight;
696 continue;
699 if(LineLen != n)
701 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
703 if(bl != NULL)
705 Free(bl);
706 bl = NULL;
707 nBlocks = 0;
709 break;
714 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
715 if (nbl != NULL)
717 bl = nbl;
718 nBlocks++;
720 cbl = bl + nBlocks - 1;
722 cbl->nChars = LineLen;
723 cbl->nSkip = SkipChars;
724 SetRect(&cbl->rc, x, y, x + szDim.cx, y + szDim.cy);
726 if (cbl->rc.right > szDoc.cx)
727 szDoc.cx = cbl->rc.right;
728 if (cbl->rc.bottom > szDoc.cy)
729 szDoc.cy = cbl->rc.bottom;
731 if(LineLen != 0)
733 x += szDim.cx;
734 if(Wrap)
736 x = SL_LEFTMARGIN;
737 y += LineHeight;
741 else
743 Free(bl);
744 bl = NULL;
745 nBlocks = 0;
747 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
748 break;
750 n -= LineLen;
751 tx += LineLen;
752 SkipChars = 0;
754 else
756 n--;
760 if(nBlocks != 0)
762 Current->Blocks = bl;
766 SelectObject(hdc, hOldFont);
768 pRect->right = pRect->left + szDoc.cx;
769 pRect->bottom = pRect->top + szDoc.cy;
772 /***********************************************************************
773 * SYSLINK_Draw
774 * Draws the SysLink control.
776 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
778 RECT rc;
779 PDOC_ITEM Current;
780 HFONT hOldFont;
781 COLORREF OldTextColor, OldBkColor;
782 HBRUSH hBrush;
783 UINT text_flags = ETO_CLIPPED;
784 UINT mode = GetBkMode( hdc );
786 hOldFont = SelectObject(hdc, infoPtr->Font);
787 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
788 OldBkColor = SetBkColor(hdc, comctl32_color.clrWindow);
790 GetClientRect(infoPtr->Self, &rc);
791 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
792 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
794 if(rc.right < 0 || rc.bottom < 0) return 0;
796 hBrush = (HBRUSH)SendMessageW(infoPtr->Notify, WM_CTLCOLORSTATIC,
797 (WPARAM)hdc, (LPARAM)infoPtr->Self);
798 if (!(infoPtr->Style & LWS_TRANSPARENT))
800 FillRect(hdc, &rc, hBrush);
801 if (GetBkMode( hdc ) == OPAQUE) text_flags |= ETO_OPAQUE;
803 else SetBkMode( hdc, TRANSPARENT );
805 DeleteObject(hBrush);
807 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
809 int n;
810 LPWSTR tx;
811 PDOC_TEXTBLOCK bl;
813 bl = Current->Blocks;
814 if(bl != NULL)
816 tx = Current->Text;
817 n = Current->nText;
819 if(Current->Type == slText)
821 SelectObject(hdc, infoPtr->Font);
822 SetTextColor(hdc, infoPtr->TextColor);
824 else
826 SelectObject(hdc, infoPtr->LinkFont);
827 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
830 while(n > 0)
832 tx += bl->nSkip;
833 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, text_flags, &bl->rc, tx, bl->nChars, NULL);
834 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
836 COLORREF PrevTextColor;
837 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
838 DrawFocusRect(hdc, &bl->rc);
839 SetTextColor(hdc, PrevTextColor);
841 tx += bl->nChars;
842 n -= bl->nChars + bl->nSkip;
843 bl++;
848 SetBkColor(hdc, OldBkColor);
849 SetTextColor(hdc, OldTextColor);
850 SelectObject(hdc, hOldFont);
851 SetBkMode(hdc, mode);
852 return 0;
856 /***********************************************************************
857 * SYSLINK_Paint
858 * Handles the WM_PAINT message.
860 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
862 HDC hdc;
863 PAINTSTRUCT ps;
865 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
866 if (hdc)
868 SYSLINK_Draw (infoPtr, hdc);
869 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
871 return 0;
874 /***********************************************************************
875 * SYSLINK_SetFont
876 * Set new Font for the SysLink control.
878 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
880 HDC hdc;
881 LOGFONTW lf;
882 TEXTMETRICW tm;
883 RECT rcClient;
884 HFONT hOldFont = infoPtr->Font;
885 infoPtr->Font = hFont;
887 /* free the underline font */
888 if(infoPtr->LinkFont != NULL)
890 DeleteObject(infoPtr->LinkFont);
891 infoPtr->LinkFont = NULL;
894 /* Render text position and word wrapping in memory */
895 if (GetClientRect(infoPtr->Self, &rcClient))
897 hdc = GetDC(infoPtr->Self);
898 if(hdc != NULL)
900 /* create a new underline font */
901 if(GetTextMetricsW(hdc, &tm) &&
902 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
904 lf.lfUnderline = TRUE;
905 infoPtr->LinkFont = CreateFontIndirectW(&lf);
906 infoPtr->BreakChar = tm.tmBreakChar;
908 else
910 ERR("Failed to create link font!\n");
913 SYSLINK_Render(infoPtr, hdc, &rcClient);
914 ReleaseDC(infoPtr->Self, hdc);
918 if(bRedraw)
920 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
923 return hOldFont;
926 /***********************************************************************
927 * SYSLINK_SetText
928 * Set new text for the SysLink control.
930 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
932 /* clear the document */
933 SYSLINK_ClearDoc(infoPtr);
935 if(Text == NULL || *Text == 0)
937 return TRUE;
940 /* let's parse the string and create a document */
941 if(SYSLINK_ParseText(infoPtr, Text) > 0)
943 RECT rcClient;
945 /* Render text position and word wrapping in memory */
946 if (GetClientRect(infoPtr->Self, &rcClient))
948 HDC hdc = GetDC(infoPtr->Self);
949 if (hdc != NULL)
951 SYSLINK_Render(infoPtr, hdc, &rcClient);
952 ReleaseDC(infoPtr->Self, hdc);
954 InvalidateRect(infoPtr->Self, NULL, TRUE);
959 return TRUE;
962 /***********************************************************************
963 * SYSLINK_SetFocusLink
964 * Updates the focus status bits and focusses the specified link.
965 * If no document item is specified, the focus bit will be removed from all links.
966 * Returns the previous focused item.
968 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
970 PDOC_ITEM Current, PrevFocus = NULL;
972 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
974 if(Current->Type == slLink)
976 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
978 PrevFocus = Current;
981 if(Current == DocItem)
983 Current->u.Link.state |= LIS_FOCUSED;
985 else
987 Current->u.Link.state &= ~LIS_FOCUSED;
992 return PrevFocus;
995 /***********************************************************************
996 * SYSLINK_SetItem
997 * Sets the states and attributes of a link item.
999 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1001 PDOC_ITEM di;
1002 int nc;
1003 PWSTR szId = NULL;
1004 PWSTR szUrl = NULL;
1005 BOOL Repaint = FALSE;
1007 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1009 ERR("Invalid Flags!\n");
1010 return FALSE;
1013 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1014 if(di == NULL)
1016 ERR("Link %d couldn't be found\n", Item->iLink);
1017 return FALSE;
1020 if(Item->mask & LIF_ITEMID)
1022 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1023 szId = Alloc((nc + 1) * sizeof(WCHAR));
1024 if(szId)
1026 lstrcpynW(szId, Item->szID, nc + 1);
1028 else
1030 ERR("Unable to allocate memory for link id\n");
1031 return FALSE;
1035 if(Item->mask & LIF_URL)
1037 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1038 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1039 if(szUrl)
1041 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1043 else
1045 Free(szId);
1047 ERR("Unable to allocate memory for link url\n");
1048 return FALSE;
1052 if(Item->mask & LIF_ITEMID)
1054 Free(di->u.Link.szID);
1055 di->u.Link.szID = szId;
1058 if(Item->mask & LIF_URL)
1060 Free(di->u.Link.szUrl);
1061 di->u.Link.szUrl = szUrl;
1064 if(Item->mask & LIF_STATE)
1066 UINT oldstate = di->u.Link.state;
1067 /* clear the masked bits */
1068 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1069 /* copy the bits */
1070 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1071 Repaint = (oldstate != di->u.Link.state);
1073 /* update the focus */
1074 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1077 if(Repaint)
1079 SYSLINK_RepaintLink(infoPtr, di);
1082 return TRUE;
1085 /***********************************************************************
1086 * SYSLINK_GetItem
1087 * Retrieves the states and attributes of a link item.
1089 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1091 PDOC_ITEM di;
1093 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1095 ERR("Invalid Flags!\n");
1096 return FALSE;
1099 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1100 if(di == NULL)
1102 ERR("Link %d couldn't be found\n", Item->iLink);
1103 return FALSE;
1106 if(Item->mask & LIF_STATE)
1108 Item->state = (di->u.Link.state & Item->stateMask);
1109 if(!infoPtr->HasFocus)
1111 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1112 Item->state &= ~LIS_FOCUSED;
1116 if(Item->mask & LIF_ITEMID)
1118 if(di->u.Link.szID)
1120 lstrcpyW(Item->szID, di->u.Link.szID);
1122 else
1124 Item->szID[0] = 0;
1128 if(Item->mask & LIF_URL)
1130 if(di->u.Link.szUrl)
1132 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1134 else
1136 Item->szUrl[0] = 0;
1140 return TRUE;
1143 /***********************************************************************
1144 * SYSLINK_PtInDocItem
1145 * Determines if a point is in the region of a document item
1147 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1149 PDOC_TEXTBLOCK bl;
1150 int n;
1152 bl = DocItem->Blocks;
1153 if (bl != NULL)
1155 n = DocItem->nText;
1157 while(n > 0)
1159 if (PtInRect(&bl->rc, pt))
1161 return TRUE;
1163 n -= bl->nChars + bl->nSkip;
1164 bl++;
1168 return FALSE;
1171 /***********************************************************************
1172 * SYSLINK_HitTest
1173 * Determines the link the user clicked on.
1175 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1177 PDOC_ITEM Current;
1178 int id = 0;
1180 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
1182 if(Current->Type == slLink)
1184 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1186 HitTest->item.mask = 0;
1187 HitTest->item.iLink = id;
1188 HitTest->item.state = 0;
1189 HitTest->item.stateMask = 0;
1190 if(Current->u.Link.szID)
1192 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1194 else
1196 HitTest->item.szID[0] = 0;
1198 if(Current->u.Link.szUrl)
1200 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1202 else
1204 HitTest->item.szUrl[0] = 0;
1206 return TRUE;
1208 id++;
1212 return FALSE;
1215 /***********************************************************************
1216 * SYSLINK_GetIdealHeight
1217 * Returns the preferred height of a link at the current control's width.
1219 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1221 HDC hdc = GetDC(infoPtr->Self);
1222 if(hdc != NULL)
1224 LRESULT height;
1225 TEXTMETRICW tm;
1226 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1228 if(GetTextMetricsW(hdc, &tm))
1230 height = tm.tmHeight;
1232 else
1234 height = 0;
1236 SelectObject(hdc, hOldFont);
1237 ReleaseDC(infoPtr->Self, hdc);
1239 return height;
1241 return 0;
1244 /***********************************************************************
1245 * SYSLINK_SendParentNotify
1246 * Sends a WM_NOTIFY message to the parent window.
1248 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1250 NMLINK nml;
1252 nml.hdr.hwndFrom = infoPtr->Self;
1253 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1254 nml.hdr.code = code;
1256 nml.item.mask = 0;
1257 nml.item.iLink = iLink;
1258 nml.item.state = 0;
1259 nml.item.stateMask = 0;
1260 if(Link->u.Link.szID)
1262 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1264 else
1266 nml.item.szID[0] = 0;
1268 if(Link->u.Link.szUrl)
1270 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1272 else
1274 nml.item.szUrl[0] = 0;
1277 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1280 /***********************************************************************
1281 * SYSLINK_SetFocus
1282 * Handles receiving the input focus.
1284 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1286 PDOC_ITEM Focus;
1288 infoPtr->HasFocus = TRUE;
1290 /* We always select the first link, even if we activated the control using
1291 SHIFT+TAB. This is the default behavior */
1292 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1293 if(Focus != NULL)
1295 SYSLINK_SetFocusLink(infoPtr, Focus);
1296 SYSLINK_RepaintLink(infoPtr, Focus);
1298 return 0;
1301 /***********************************************************************
1302 * SYSLINK_KillFocus
1303 * Handles losing the input focus.
1305 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1307 PDOC_ITEM Focus;
1309 infoPtr->HasFocus = FALSE;
1310 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1312 if(Focus != NULL)
1314 SYSLINK_RepaintLink(infoPtr, Focus);
1317 return 0;
1320 /***********************************************************************
1321 * SYSLINK_LinkAtPt
1322 * Returns a link at the specified position
1324 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1326 PDOC_ITEM Current;
1327 int id = 0;
1329 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
1331 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1332 (!MustBeEnabled || (Current->u.Link.state & LIS_ENABLED)))
1334 if(LinkId != NULL)
1336 *LinkId = id;
1338 return Current;
1340 id++;
1343 return NULL;
1346 /***********************************************************************
1347 * SYSLINK_LButtonDown
1348 * Handles mouse clicks
1350 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1352 PDOC_ITEM Current, Old;
1353 int id;
1355 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1356 if(Current != NULL)
1358 SetFocus(infoPtr->Self);
1360 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1361 if(Old != NULL && Old != Current)
1363 SYSLINK_RepaintLink(infoPtr, Old);
1365 infoPtr->MouseDownID = id;
1366 SYSLINK_RepaintLink(infoPtr, Current);
1369 return 0;
1372 /***********************************************************************
1373 * SYSLINK_LButtonUp
1374 * Handles mouse clicks
1376 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1378 if(infoPtr->MouseDownID > -1)
1380 PDOC_ITEM Current;
1381 int id;
1383 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1384 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1386 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1390 infoPtr->MouseDownID = -1;
1392 return 0;
1395 /***********************************************************************
1396 * SYSLINK_OnEnter
1397 * Handles ENTER key events
1399 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1401 if(infoPtr->HasFocus && !infoPtr->IgnoreReturn)
1403 PDOC_ITEM Focus;
1404 int id;
1406 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1407 if(Focus)
1409 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1410 return TRUE;
1413 return FALSE;
1416 /***********************************************************************
1417 * SYSKEY_SelectNextPrevLink
1418 * Changes the currently focused link
1420 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1422 if(infoPtr->HasFocus)
1424 PDOC_ITEM Focus;
1425 int id;
1427 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1428 if(Focus != NULL)
1430 PDOC_ITEM NewFocus, OldFocus;
1432 if(Prev)
1433 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1434 else
1435 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1437 if(NewFocus != NULL)
1439 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1441 if(OldFocus && OldFocus != NewFocus)
1443 SYSLINK_RepaintLink(infoPtr, OldFocus);
1445 SYSLINK_RepaintLink(infoPtr, NewFocus);
1446 return TRUE;
1450 return FALSE;
1453 /***********************************************************************
1454 * SYSKEY_SelectNextPrevLink
1455 * Determines if there's a next or previous link to decide whether the control
1456 * should capture the tab key message
1458 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1460 PDOC_ITEM Focus, NewFocus;
1462 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1463 if(Prev)
1464 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1465 else
1466 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1468 return NewFocus == NULL;
1471 /***********************************************************************
1472 * SYSLINK_GetIdealSize
1473 * Calculates the ideal size of a link control at a given maximum width.
1475 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1477 RECT rc;
1478 HDC hdc;
1480 rc.left = rc.top = rc.bottom = 0;
1481 rc.right = cxMaxWidth;
1483 hdc = GetDC(infoPtr->Self);
1484 if (hdc != NULL)
1486 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1488 SYSLINK_Render(infoPtr, hdc, &rc);
1490 SelectObject(hdc, hOldFont);
1491 ReleaseDC(infoPtr->Self, hdc);
1493 lpSize->cx = rc.right;
1494 lpSize->cy = rc.bottom;
1498 /***********************************************************************
1499 * SysLinkWindowProc
1501 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1502 WPARAM wParam, LPARAM lParam)
1504 SYSLINK_INFO *infoPtr;
1506 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1508 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1510 if (!infoPtr && message != WM_CREATE)
1511 return DefWindowProcW(hwnd, message, wParam, lParam);
1513 switch(message) {
1514 case WM_PRINTCLIENT:
1515 case WM_PAINT:
1516 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1518 case WM_ERASEBKGND:
1519 if (!(infoPtr->Style & LWS_TRANSPARENT))
1521 HDC hdc = (HDC)wParam;
1522 HBRUSH brush = CreateSolidBrush( comctl32_color.clrWindow );
1523 RECT rect;
1525 GetClipBox( hdc, &rect );
1526 FillRect( hdc, &rect, brush );
1527 DeleteObject( brush );
1528 return 1;
1530 return 0;
1532 case WM_SETCURSOR:
1534 LHITTESTINFO ht;
1535 DWORD mp = GetMessagePos();
1537 ht.pt.x = (short)LOWORD(mp);
1538 ht.pt.y = (short)HIWORD(mp);
1540 ScreenToClient(infoPtr->Self, &ht.pt);
1541 if(SYSLINK_HitTest (infoPtr, &ht))
1543 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1544 return TRUE;
1547 return DefWindowProcW(hwnd, message, wParam, lParam);
1550 case WM_SIZE:
1552 RECT rcClient;
1553 if (GetClientRect(infoPtr->Self, &rcClient))
1555 HDC hdc = GetDC(infoPtr->Self);
1556 if(hdc != NULL)
1558 SYSLINK_Render(infoPtr, hdc, &rcClient);
1559 ReleaseDC(infoPtr->Self, hdc);
1562 return 0;
1565 case WM_GETFONT:
1566 return (LRESULT)infoPtr->Font;
1568 case WM_SETFONT:
1569 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1571 case WM_SETTEXT:
1572 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1573 return DefWindowProcW(hwnd, message, wParam, lParam);
1575 case WM_LBUTTONDOWN:
1577 POINT pt;
1578 pt.x = (short)LOWORD(lParam);
1579 pt.y = (short)HIWORD(lParam);
1580 return SYSLINK_LButtonDown(infoPtr, &pt);
1582 case WM_LBUTTONUP:
1584 POINT pt;
1585 pt.x = (short)LOWORD(lParam);
1586 pt.y = (short)HIWORD(lParam);
1587 return SYSLINK_LButtonUp(infoPtr, &pt);
1590 case WM_KEYDOWN:
1592 switch(wParam)
1594 case VK_RETURN:
1595 SYSLINK_OnEnter(infoPtr);
1596 return 0;
1597 case VK_TAB:
1599 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1600 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1601 return 0;
1603 default:
1604 return DefWindowProcW(hwnd, message, wParam, lParam);
1608 case WM_GETDLGCODE:
1610 LRESULT Ret = DLGC_HASSETSEL;
1611 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1612 switch(vk)
1614 case VK_RETURN:
1615 Ret |= DLGC_WANTMESSAGE;
1616 break;
1617 case VK_TAB:
1619 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1620 if(!SYSLINK_NoNextLink(infoPtr, shift))
1622 Ret |= DLGC_WANTTAB;
1624 else
1626 Ret |= DLGC_WANTCHARS;
1628 break;
1631 return Ret;
1634 case WM_NCHITTEST:
1636 POINT pt;
1637 RECT rc;
1638 pt.x = (short)LOWORD(lParam);
1639 pt.y = (short)HIWORD(lParam);
1641 GetClientRect(infoPtr->Self, &rc);
1642 ScreenToClient(infoPtr->Self, &pt);
1643 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1645 return HTNOWHERE;
1648 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1650 return HTCLIENT;
1653 return HTTRANSPARENT;
1656 case LM_HITTEST:
1657 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1659 case LM_SETITEM:
1660 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1662 case LM_GETITEM:
1663 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1665 case LM_GETIDEALHEIGHT:
1666 if (lParam)
1668 /* LM_GETIDEALSIZE */
1669 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1671 return SYSLINK_GetIdealHeight(infoPtr);
1673 case WM_SETFOCUS:
1674 return SYSLINK_SetFocus(infoPtr);
1676 case WM_KILLFOCUS:
1677 return SYSLINK_KillFocus(infoPtr);
1679 case WM_ENABLE:
1680 infoPtr->Style &= ~WS_DISABLED;
1681 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1682 InvalidateRect (infoPtr->Self, NULL, FALSE);
1683 return 0;
1685 case WM_STYLECHANGED:
1686 if (wParam == GWL_STYLE)
1688 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1690 InvalidateRect(infoPtr->Self, NULL, TRUE);
1692 return 0;
1694 case WM_CREATE:
1696 CREATESTRUCTW *cs = (CREATESTRUCTW*)lParam;
1698 /* allocate memory for info struct */
1699 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1700 if (!infoPtr) return -1;
1701 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1703 /* initialize the info struct */
1704 infoPtr->Self = hwnd;
1705 infoPtr->Notify = cs->hwndParent;
1706 infoPtr->Style = cs->style;
1707 infoPtr->Font = 0;
1708 infoPtr->LinkFont = 0;
1709 list_init(&infoPtr->Items);
1710 infoPtr->HasFocus = FALSE;
1711 infoPtr->MouseDownID = -1;
1712 infoPtr->TextColor = comctl32_color.clrWindowText;
1713 infoPtr->LinkColor = comctl32_color.clrHighlight;
1714 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1715 infoPtr->BreakChar = ' ';
1716 infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN;
1717 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1718 SYSLINK_SetText(infoPtr, cs->lpszName);
1719 return 0;
1721 case WM_DESTROY:
1722 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1723 SYSLINK_ClearDoc(infoPtr);
1724 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1725 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1726 SetWindowLongPtrW(hwnd, 0, 0);
1727 Free (infoPtr);
1728 return 0;
1730 case WM_SYSCOLORCHANGE:
1731 COMCTL32_RefreshSysColors();
1732 return 0;
1734 default:
1735 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1737 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1739 return DefWindowProcW(hwnd, message, wParam, lParam);
1744 /***********************************************************************
1745 * SYSLINK_Register [Internal]
1747 * Registers the SysLink window class.
1749 VOID SYSLINK_Register (void)
1751 WNDCLASSW wndClass;
1753 ZeroMemory (&wndClass, sizeof(wndClass));
1754 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1755 wndClass.lpfnWndProc = SysLinkWindowProc;
1756 wndClass.cbClsExtra = 0;
1757 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1758 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1759 wndClass.lpszClassName = WC_LINK;
1761 RegisterClassW (&wndClass);
1765 /***********************************************************************
1766 * SYSLINK_Unregister [Internal]
1768 * Unregisters the SysLink window class.
1770 VOID SYSLINK_Unregister (void)
1772 UnregisterClassW (WC_LINK, NULL);