d3d9: Return D3D_OK from UnlockRect() for not locked textures.
[wine.git] / dlls / comctl32 / syslink.c
blob08e5230c55d8ac2447e99ab730f76e67d9c6c06a
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 INT WINAPI StrCmpNIW(LPCWSTR,LPCWSTR,INT);
47 typedef struct
49 int nChars;
50 int nSkip;
51 RECT rc;
52 } DOC_TEXTBLOCK, *PDOC_TEXTBLOCK;
54 #define LIF_FLAGSMASK (LIF_STATE | LIF_ITEMID | LIF_URL)
55 #define LIS_MASK (LIS_FOCUSED | LIS_ENABLED | LIS_VISITED)
57 typedef enum
59 slText = 0,
60 slLink
61 } SL_ITEM_TYPE;
63 typedef struct _DOC_ITEM
65 struct list entry;
66 UINT nText; /* Number of characters of the text */
67 SL_ITEM_TYPE Type; /* type of the item */
68 PDOC_TEXTBLOCK Blocks; /* Array of text blocks */
69 union
71 struct
73 UINT state; /* Link state */
74 WCHAR *szID; /* Link ID string */
75 WCHAR *szUrl; /* Link URL string */
76 } Link;
77 struct
79 UINT Dummy;
80 } Text;
81 } u;
82 WCHAR Text[1]; /* Text of the document item */
83 } DOC_ITEM, *PDOC_ITEM;
85 typedef struct
87 HWND Self; /* The window handle for this control */
88 HWND Notify; /* The parent handle to receive notifications */
89 DWORD Style; /* Styles for this control */
90 struct list Items; /* Document items list */
91 BOOL HasFocus; /* Whether the control has the input focus */
92 int MouseDownID; /* ID of the link that the mouse button first selected */
93 HFONT Font; /* Handle to the font for text */
94 HFONT LinkFont; /* Handle to the font for links */
95 COLORREF TextColor; /* Color of the text */
96 COLORREF LinkColor; /* Color of links */
97 COLORREF VisitedColor; /* Color of visited links */
98 WCHAR BreakChar; /* Break Character for the current font */
99 BOOL IgnoreReturn; /* (infoPtr->Style & LWS_IGNORERETURN) on creation */
100 } SYSLINK_INFO;
102 static const WCHAR SL_LINKOPEN[] = { '<','a', 0 };
103 static const WCHAR SL_HREF[] = { 'h','r','e','f','=','\"',0 };
104 static const WCHAR SL_ID[] = { 'i','d','=','\"',0 };
105 static const WCHAR SL_LINKCLOSE[] = { '<','/','a','>',0 };
107 /* Control configuration constants */
109 #define SL_LEFTMARGIN (0)
110 #define SL_TOPMARGIN (0)
111 #define SL_RIGHTMARGIN (0)
112 #define SL_BOTTOMMARGIN (0)
114 /***********************************************************************
115 * SYSLINK_FreeDocItem
116 * Frees all data and gdi objects associated with a document item
118 static VOID SYSLINK_FreeDocItem (PDOC_ITEM DocItem)
120 if(DocItem->Type == slLink)
122 Free(DocItem->u.Link.szID);
123 Free(DocItem->u.Link.szUrl);
126 Free(DocItem->Blocks);
128 /* we don't free Text because it's just a pointer to a character in the
129 entire window text string */
131 Free(DocItem);
134 /***********************************************************************
135 * SYSLINK_AppendDocItem
136 * Create and append a new document item.
138 static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UINT textlen,
139 SL_ITEM_TYPE type, PDOC_ITEM LastItem)
141 PDOC_ITEM Item;
143 textlen = min(textlen, strlenW(Text));
144 Item = Alloc(FIELD_OFFSET(DOC_ITEM, Text[textlen + 1]));
145 if(Item == NULL)
147 ERR("Failed to alloc DOC_ITEM structure!\n");
148 return NULL;
151 Item->nText = textlen;
152 Item->Type = type;
153 Item->Blocks = NULL;
154 lstrcpynW(Item->Text, Text, textlen + 1);
155 if (LastItem)
156 list_add_after(&LastItem->entry, &Item->entry);
157 else
158 list_add_tail(&infoPtr->Items, &Item->entry);
160 return Item;
163 /***********************************************************************
164 * SYSLINK_ClearDoc
165 * Clears the document tree
167 static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
169 DOC_ITEM *Item, *Item2;
171 LIST_FOR_EACH_ENTRY_SAFE(Item, Item2, &infoPtr->Items, DOC_ITEM, entry)
173 list_remove(&Item->entry);
174 SYSLINK_FreeDocItem(Item);
178 /***********************************************************************
179 * SYSLINK_StrCmpNIW
180 * Wrapper for StrCmpNIW to ensure 'len' is not too big.
182 static INT SYSLINK_StrCmpNIW (LPCWSTR str, LPCWSTR comp, INT len)
184 INT i;
186 for(i = 0; i < len; i++)
188 if(!str[i])
190 len = i + 1;
191 break;
195 return StrCmpNIW(str, comp, len);
198 /***********************************************************************
199 * SYSLINK_ParseText
200 * Parses the window text string and creates a document. Returns the
201 * number of document items created.
203 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
205 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
206 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
207 PDOC_ITEM Last = NULL;
208 SL_ITEM_TYPE CurrentType = slText;
209 LPCWSTR lpID, lpUrl;
210 UINT lenId, lenUrl;
212 TRACE("(%p %s)\n", infoPtr, debugstr_w(Text));
214 for(current = Text; *current != 0;)
216 if(*current == '<')
218 if(!SYSLINK_StrCmpNIW(current, SL_LINKOPEN, 2) && (CurrentType == slText))
220 BOOL ValidParam = FALSE, ValidLink = FALSE;
222 if(*(current + 2) == '>')
224 /* we just have to deal with a <a> tag */
225 taglen = 3;
226 ValidLink = TRUE;
227 ValidParam = TRUE;
228 firsttag = current;
229 linklen = 0;
230 lpID = NULL;
231 lpUrl = NULL;
233 else if(*(current + 2) == infoPtr->BreakChar)
235 /* we expect parameters, parse them */
236 LPCWSTR *CurrentParameter = NULL, tmp;
237 UINT *CurrentParameterLen = NULL;
239 taglen = 3;
240 tmp = current + taglen;
241 lpID = NULL;
242 lpUrl = NULL;
244 CheckParameter:
245 /* compare the current position with all known parameters */
246 if(!SYSLINK_StrCmpNIW(tmp, SL_HREF, 6))
248 taglen += 6;
249 ValidParam = TRUE;
250 CurrentParameter = &lpUrl;
251 CurrentParameterLen = &lenUrl;
253 else if(!SYSLINK_StrCmpNIW(tmp, SL_ID, 4))
255 taglen += 4;
256 ValidParam = TRUE;
257 CurrentParameter = &lpID;
258 CurrentParameterLen = &lenId;
260 else
262 ValidParam = FALSE;
265 if(ValidParam)
267 /* we got a known parameter, now search until the next " character.
268 If we can't find a " character, there's a syntax error and we just assume it's text */
269 ValidParam = FALSE;
270 *CurrentParameter = current + taglen;
271 *CurrentParameterLen = 0;
273 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
275 taglen++;
276 if(*tmp == '\"')
278 ValidParam = TRUE;
279 tmp++;
280 break;
282 (*CurrentParameterLen)++;
285 if(ValidParam)
287 /* we're done with this parameter, now there are only 2 possibilities:
288 * 1. another parameter is coming, so expect a ' ' (space) character
289 * 2. the tag is being closed, so expect a '<' character
291 if(*tmp == infoPtr->BreakChar)
293 /* we expect another parameter, do the whole thing again */
294 taglen++;
295 tmp++;
296 goto CheckParameter;
298 else if(*tmp == '>')
300 /* the tag is being closed, we're done */
301 ValidLink = TRUE;
302 taglen++;
307 if(ValidLink && ValidParam)
309 /* the <a ...> tag appears to be valid. save all information
310 so we can add the link if we find a valid </a> tag later */
311 CurrentType = slLink;
312 linktext = current + taglen;
313 linklen = 0;
314 firsttag = current;
316 else
318 taglen = 1;
319 lpID = NULL;
320 lpUrl = NULL;
321 if(textstart == NULL)
323 textstart = current;
327 else if(!SYSLINK_StrCmpNIW(current, SL_LINKCLOSE, 4) && (CurrentType == slLink) && firsttag)
329 /* there's a <a...> tag opened, first add the previous text, if present */
330 if(textstart != NULL && textlen > 0 && firsttag > textstart)
332 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
333 if(Last == NULL)
335 ERR("Unable to create new document item!\n");
336 return docitems;
338 docitems++;
339 textstart = NULL;
340 textlen = 0;
343 /* now it's time to add the link to the document */
344 current += 4;
345 if(linktext != NULL && linklen > 0)
347 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
348 if(Last == NULL)
350 ERR("Unable to create new document item!\n");
351 return docitems;
353 docitems++;
354 if(CurrentType == slLink)
356 int nc;
358 if(!(infoPtr->Style & WS_DISABLED))
360 Last->u.Link.state |= LIS_ENABLED;
362 /* Copy the tag parameters */
363 if(lpID != NULL)
365 nc = min(lenId, strlenW(lpID));
366 nc = min(nc, MAX_LINKID_TEXT - 1);
367 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
368 if(Last->u.Link.szID != NULL)
370 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
373 else
374 Last->u.Link.szID = NULL;
375 if(lpUrl != NULL)
377 nc = min(lenUrl, strlenW(lpUrl));
378 nc = min(nc, L_MAX_URL_LENGTH - 1);
379 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
380 if(Last->u.Link.szUrl != NULL)
382 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
385 else
386 Last->u.Link.szUrl = NULL;
388 linktext = NULL;
390 CurrentType = slText;
391 firsttag = NULL;
392 textstart = NULL;
393 continue;
395 else
397 /* we don't know what tag it is, so just continue */
398 taglen = 1;
399 linklen++;
400 if(CurrentType == slText && textstart == NULL)
402 textstart = current;
406 textlen += taglen;
407 current += taglen;
409 else
411 textlen++;
412 linklen++;
414 /* save the pointer of the current text item if we couldn't find a tag */
415 if(textstart == NULL && CurrentType == slText)
417 textstart = current;
420 current++;
424 if(textstart != NULL && textlen > 0)
426 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
427 if(Last == NULL)
429 ERR("Unable to create new document item!\n");
430 return docitems;
432 if(CurrentType == slLink)
434 int nc;
436 if(!(infoPtr->Style & WS_DISABLED))
438 Last->u.Link.state |= LIS_ENABLED;
440 /* Copy the tag parameters */
441 if(lpID != NULL)
443 nc = min(lenId, strlenW(lpID));
444 nc = min(nc, MAX_LINKID_TEXT - 1);
445 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
446 if(Last->u.Link.szID != NULL)
448 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
451 else
452 Last->u.Link.szID = NULL;
453 if(lpUrl != NULL)
455 nc = min(lenUrl, strlenW(lpUrl));
456 nc = min(nc, L_MAX_URL_LENGTH - 1);
457 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
458 if(Last->u.Link.szUrl != NULL)
460 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
463 else
464 Last->u.Link.szUrl = NULL;
466 docitems++;
469 if(linktext != NULL && linklen > 0)
471 /* we got an unclosed link, just display the text */
472 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
473 if(Last == NULL)
475 ERR("Unable to create new document item!\n");
476 return docitems;
478 docitems++;
481 return docitems;
484 /***********************************************************************
485 * SYSLINK_RepaintLink
486 * Repaints a link.
488 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
490 PDOC_TEXTBLOCK bl;
491 int n;
493 if(DocItem->Type != slLink)
495 ERR("DocItem not a link!\n");
496 return;
499 bl = DocItem->Blocks;
500 if (bl != NULL)
502 n = DocItem->nText;
504 while(n > 0)
506 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
507 n -= bl->nChars + bl->nSkip;
508 bl++;
513 /***********************************************************************
514 * SYSLINK_GetLinkItemByIndex
515 * Retrieves a document link by its index
517 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
519 DOC_ITEM *Current;
521 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
523 if ((Current->Type == slLink) && (iLink-- <= 0))
524 return Current;
526 return NULL;
529 /***********************************************************************
530 * SYSLINK_GetFocusLink
531 * Retrieves the link that has the LIS_FOCUSED bit
533 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
535 DOC_ITEM *Current;
536 int id = 0;
538 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
540 if(Current->Type == slLink)
542 if(Current->u.Link.state & LIS_FOCUSED)
544 if(LinkId != NULL)
545 *LinkId = id;
546 return Current;
548 id++;
552 return NULL;
555 /***********************************************************************
556 * SYSLINK_GetNextLink
557 * Gets the next link
559 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
561 DOC_ITEM *Next;
563 LIST_FOR_EACH_ENTRY(Next, Current ? &Current->entry : &infoPtr->Items, DOC_ITEM, entry)
565 if (Next->Type == slLink)
567 return Next;
570 return NULL;
573 /***********************************************************************
574 * SYSLINK_GetPrevLink
575 * Gets the previous link
577 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
579 DOC_ITEM *Prev;
581 LIST_FOR_EACH_ENTRY_REV(Prev, Current ? &Current->entry : list_tail(&infoPtr->Items), DOC_ITEM, entry)
583 if (Prev->Type == slLink)
585 return Prev;
589 return NULL;
592 /***********************************************************************
593 * SYSLINK_WrapLine
594 * Tries to wrap a line.
596 static BOOL SYSLINK_WrapLine (LPWSTR Text, WCHAR BreakChar, int x, int *LineLen,
597 int nFit, LPSIZE Extent)
599 int i;
601 for (i = 0; i < nFit; i++) if (Text[i] == '\n') break;
603 if (i == *LineLen) return FALSE;
605 /* check if we're in the middle of a word */
606 if (Text[i] != '\n' && Text[i] != BreakChar)
608 /* search for the beginning of the word */
609 while (i && Text[i - 1] != BreakChar) i--;
611 if (i == 0)
613 Extent->cx = 0;
614 Extent->cy = 0;
615 if (x == SL_LEFTMARGIN) i = max( nFit, 1 );
618 *LineLen = i;
619 return TRUE;
622 /***********************************************************************
623 * SYSLINK_Render
624 * Renders the document in memory
626 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
628 RECT rc;
629 PDOC_ITEM Current;
630 HGDIOBJ hOldFont;
631 int x, y, LineHeight;
632 SIZE szDoc;
633 TEXTMETRICW tm;
635 szDoc.cx = szDoc.cy = 0;
637 rc = *pRect;
638 rc.right -= SL_RIGHTMARGIN;
639 rc.bottom -= SL_BOTTOMMARGIN;
641 if(rc.right - SL_LEFTMARGIN < 0)
642 rc.right = MAXLONG;
643 if (rc.bottom - SL_TOPMARGIN < 0)
644 rc.bottom = MAXLONG;
646 hOldFont = SelectObject(hdc, infoPtr->Font);
648 x = SL_LEFTMARGIN;
649 y = SL_TOPMARGIN;
650 GetTextMetricsW( hdc, &tm );
651 LineHeight = tm.tmHeight + tm.tmExternalLeading;
653 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
655 int n, nBlocks;
656 LPWSTR tx;
657 PDOC_TEXTBLOCK bl, cbl;
658 INT nFit;
659 SIZE szDim;
660 int SkipChars = 0;
662 if(Current->nText == 0)
664 continue;
667 tx = Current->Text;
668 n = Current->nText;
670 Free(Current->Blocks);
671 Current->Blocks = NULL;
672 bl = NULL;
673 nBlocks = 0;
675 if(Current->Type == slText)
677 SelectObject(hdc, infoPtr->Font);
679 else if(Current->Type == slLink)
681 SelectObject(hdc, infoPtr->LinkFont);
684 while(n > 0)
686 /* skip break characters unless they're the first of the doc item */
687 if(tx != Current->Text || x == SL_LEFTMARGIN)
689 if (n && *tx == '\n')
691 tx++;
692 SkipChars++;
693 n--;
695 while(n > 0 && (*tx) == infoPtr->BreakChar)
697 tx++;
698 SkipChars++;
699 n--;
703 if((n == 0 && SkipChars != 0) ||
704 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
706 int LineLen = n;
707 BOOL Wrap = FALSE;
708 PDOC_TEXTBLOCK nbl;
710 if(n != 0)
712 Wrap = SYSLINK_WrapLine(tx, infoPtr->BreakChar, x, &LineLen, nFit, &szDim);
714 if(LineLen == 0)
716 /* move one line down, the word didn't fit into the line */
717 x = SL_LEFTMARGIN;
718 y += LineHeight;
719 continue;
722 if(LineLen != n)
724 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
726 if(bl != NULL)
728 Free(bl);
729 bl = NULL;
730 nBlocks = 0;
732 break;
737 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
738 if (nbl != NULL)
740 bl = nbl;
741 nBlocks++;
743 cbl = bl + nBlocks - 1;
745 cbl->nChars = LineLen;
746 cbl->nSkip = SkipChars;
747 SetRect(&cbl->rc, x, y, x + szDim.cx, y + szDim.cy);
749 if (cbl->rc.right > szDoc.cx)
750 szDoc.cx = cbl->rc.right;
751 if (cbl->rc.bottom > szDoc.cy)
752 szDoc.cy = cbl->rc.bottom;
754 if(LineLen != 0)
756 x += szDim.cx;
757 if(Wrap)
759 x = SL_LEFTMARGIN;
760 y += LineHeight;
764 else
766 Free(bl);
767 bl = NULL;
768 nBlocks = 0;
770 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
771 break;
773 n -= LineLen;
774 tx += LineLen;
775 SkipChars = 0;
777 else
779 n--;
783 if(nBlocks != 0)
785 Current->Blocks = bl;
789 SelectObject(hdc, hOldFont);
791 pRect->right = pRect->left + szDoc.cx;
792 pRect->bottom = pRect->top + szDoc.cy;
795 /***********************************************************************
796 * SYSLINK_Draw
797 * Draws the SysLink control.
799 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
801 RECT rc;
802 PDOC_ITEM Current;
803 HFONT hOldFont;
804 COLORREF OldTextColor, OldBkColor;
805 HBRUSH hBrush;
806 UINT text_flags = ETO_CLIPPED;
807 UINT mode = GetBkMode( hdc );
809 hOldFont = SelectObject(hdc, infoPtr->Font);
810 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
811 OldBkColor = SetBkColor(hdc, comctl32_color.clrWindow);
813 GetClientRect(infoPtr->Self, &rc);
814 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
815 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
817 if(rc.right < 0 || rc.bottom < 0) return 0;
819 hBrush = (HBRUSH)SendMessageW(infoPtr->Notify, WM_CTLCOLORSTATIC,
820 (WPARAM)hdc, (LPARAM)infoPtr->Self);
821 if (!(infoPtr->Style & LWS_TRANSPARENT))
823 FillRect(hdc, &rc, hBrush);
824 if (GetBkMode( hdc ) == OPAQUE) text_flags |= ETO_OPAQUE;
826 else SetBkMode( hdc, TRANSPARENT );
828 DeleteObject(hBrush);
830 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
832 int n;
833 LPWSTR tx;
834 PDOC_TEXTBLOCK bl;
836 bl = Current->Blocks;
837 if(bl != NULL)
839 tx = Current->Text;
840 n = Current->nText;
842 if(Current->Type == slText)
844 SelectObject(hdc, infoPtr->Font);
845 SetTextColor(hdc, infoPtr->TextColor);
847 else
849 SelectObject(hdc, infoPtr->LinkFont);
850 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
853 while(n > 0)
855 tx += bl->nSkip;
856 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, text_flags, &bl->rc, tx, bl->nChars, NULL);
857 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
859 COLORREF PrevTextColor;
860 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
861 DrawFocusRect(hdc, &bl->rc);
862 SetTextColor(hdc, PrevTextColor);
864 tx += bl->nChars;
865 n -= bl->nChars + bl->nSkip;
866 bl++;
871 SetBkColor(hdc, OldBkColor);
872 SetTextColor(hdc, OldTextColor);
873 SelectObject(hdc, hOldFont);
874 SetBkMode(hdc, mode);
875 return 0;
879 /***********************************************************************
880 * SYSLINK_Paint
881 * Handles the WM_PAINT message.
883 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
885 HDC hdc;
886 PAINTSTRUCT ps;
888 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
889 if (hdc)
891 SYSLINK_Draw (infoPtr, hdc);
892 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
894 return 0;
897 /***********************************************************************
898 * SYSLINK_SetFont
899 * Set new Font for the SysLink control.
901 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
903 HDC hdc;
904 LOGFONTW lf;
905 TEXTMETRICW tm;
906 RECT rcClient;
907 HFONT hOldFont = infoPtr->Font;
908 infoPtr->Font = hFont;
910 /* free the underline font */
911 if(infoPtr->LinkFont != NULL)
913 DeleteObject(infoPtr->LinkFont);
914 infoPtr->LinkFont = NULL;
917 /* Render text position and word wrapping in memory */
918 if (GetClientRect(infoPtr->Self, &rcClient))
920 hdc = GetDC(infoPtr->Self);
921 if(hdc != NULL)
923 /* create a new underline font */
924 if(GetTextMetricsW(hdc, &tm) &&
925 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
927 lf.lfUnderline = TRUE;
928 infoPtr->LinkFont = CreateFontIndirectW(&lf);
929 infoPtr->BreakChar = tm.tmBreakChar;
931 else
933 ERR("Failed to create link font!\n");
936 SYSLINK_Render(infoPtr, hdc, &rcClient);
937 ReleaseDC(infoPtr->Self, hdc);
941 if(bRedraw)
943 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
946 return hOldFont;
949 /***********************************************************************
950 * SYSLINK_SetText
951 * Set new text for the SysLink control.
953 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
955 /* clear the document */
956 SYSLINK_ClearDoc(infoPtr);
958 if(Text == NULL || *Text == 0)
960 return TRUE;
963 /* let's parse the string and create a document */
964 if(SYSLINK_ParseText(infoPtr, Text) > 0)
966 RECT rcClient;
968 /* Render text position and word wrapping in memory */
969 if (GetClientRect(infoPtr->Self, &rcClient))
971 HDC hdc = GetDC(infoPtr->Self);
972 if (hdc != NULL)
974 SYSLINK_Render(infoPtr, hdc, &rcClient);
975 ReleaseDC(infoPtr->Self, hdc);
977 InvalidateRect(infoPtr->Self, NULL, TRUE);
982 return TRUE;
985 /***********************************************************************
986 * SYSLINK_SetFocusLink
987 * Updates the focus status bits and focusses the specified link.
988 * If no document item is specified, the focus bit will be removed from all links.
989 * Returns the previous focused item.
991 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
993 PDOC_ITEM Current, PrevFocus = NULL;
995 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
997 if(Current->Type == slLink)
999 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1001 PrevFocus = Current;
1004 if(Current == DocItem)
1006 Current->u.Link.state |= LIS_FOCUSED;
1008 else
1010 Current->u.Link.state &= ~LIS_FOCUSED;
1015 return PrevFocus;
1018 /***********************************************************************
1019 * SYSLINK_SetItem
1020 * Sets the states and attributes of a link item.
1022 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1024 PDOC_ITEM di;
1025 int nc;
1026 PWSTR szId = NULL;
1027 PWSTR szUrl = NULL;
1028 BOOL Repaint = FALSE;
1030 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1032 ERR("Invalid Flags!\n");
1033 return FALSE;
1036 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1037 if(di == NULL)
1039 ERR("Link %d couldn't be found\n", Item->iLink);
1040 return FALSE;
1043 if(Item->mask & LIF_ITEMID)
1045 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1046 szId = Alloc((nc + 1) * sizeof(WCHAR));
1047 if(szId)
1049 lstrcpynW(szId, Item->szID, nc + 1);
1051 else
1053 ERR("Unable to allocate memory for link id\n");
1054 return FALSE;
1058 if(Item->mask & LIF_URL)
1060 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1061 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1062 if(szUrl)
1064 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1066 else
1068 Free(szId);
1070 ERR("Unable to allocate memory for link url\n");
1071 return FALSE;
1075 if(Item->mask & LIF_ITEMID)
1077 Free(di->u.Link.szID);
1078 di->u.Link.szID = szId;
1081 if(Item->mask & LIF_URL)
1083 Free(di->u.Link.szUrl);
1084 di->u.Link.szUrl = szUrl;
1087 if(Item->mask & LIF_STATE)
1089 UINT oldstate = di->u.Link.state;
1090 /* clear the masked bits */
1091 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1092 /* copy the bits */
1093 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1094 Repaint = (oldstate != di->u.Link.state);
1096 /* update the focus */
1097 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1100 if(Repaint)
1102 SYSLINK_RepaintLink(infoPtr, di);
1105 return TRUE;
1108 /***********************************************************************
1109 * SYSLINK_GetItem
1110 * Retrieves the states and attributes of a link item.
1112 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1114 PDOC_ITEM di;
1116 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1118 ERR("Invalid Flags!\n");
1119 return FALSE;
1122 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1123 if(di == NULL)
1125 ERR("Link %d couldn't be found\n", Item->iLink);
1126 return FALSE;
1129 if(Item->mask & LIF_STATE)
1131 Item->state = (di->u.Link.state & Item->stateMask);
1132 if(!infoPtr->HasFocus)
1134 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1135 Item->state &= ~LIS_FOCUSED;
1139 if(Item->mask & LIF_ITEMID)
1141 if(di->u.Link.szID)
1143 lstrcpyW(Item->szID, di->u.Link.szID);
1145 else
1147 Item->szID[0] = 0;
1151 if(Item->mask & LIF_URL)
1153 if(di->u.Link.szUrl)
1155 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1157 else
1159 Item->szUrl[0] = 0;
1163 return TRUE;
1166 /***********************************************************************
1167 * SYSLINK_PtInDocItem
1168 * Determines if a point is in the region of a document item
1170 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1172 PDOC_TEXTBLOCK bl;
1173 int n;
1175 bl = DocItem->Blocks;
1176 if (bl != NULL)
1178 n = DocItem->nText;
1180 while(n > 0)
1182 if (PtInRect(&bl->rc, pt))
1184 return TRUE;
1186 n -= bl->nChars + bl->nSkip;
1187 bl++;
1191 return FALSE;
1194 /***********************************************************************
1195 * SYSLINK_HitTest
1196 * Determines the link the user clicked on.
1198 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1200 PDOC_ITEM Current;
1201 int id = 0;
1203 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
1205 if(Current->Type == slLink)
1207 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1209 HitTest->item.mask = 0;
1210 HitTest->item.iLink = id;
1211 HitTest->item.state = 0;
1212 HitTest->item.stateMask = 0;
1213 if(Current->u.Link.szID)
1215 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1217 else
1219 HitTest->item.szID[0] = 0;
1221 if(Current->u.Link.szUrl)
1223 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1225 else
1227 HitTest->item.szUrl[0] = 0;
1229 return TRUE;
1231 id++;
1235 return FALSE;
1238 /***********************************************************************
1239 * SYSLINK_GetIdealHeight
1240 * Returns the preferred height of a link at the current control's width.
1242 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1244 HDC hdc = GetDC(infoPtr->Self);
1245 if(hdc != NULL)
1247 LRESULT height;
1248 TEXTMETRICW tm;
1249 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1251 if(GetTextMetricsW(hdc, &tm))
1253 height = tm.tmHeight;
1255 else
1257 height = 0;
1259 SelectObject(hdc, hOldFont);
1260 ReleaseDC(infoPtr->Self, hdc);
1262 return height;
1264 return 0;
1267 /***********************************************************************
1268 * SYSLINK_SendParentNotify
1269 * Sends a WM_NOTIFY message to the parent window.
1271 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1273 NMLINK nml;
1275 nml.hdr.hwndFrom = infoPtr->Self;
1276 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1277 nml.hdr.code = code;
1279 nml.item.mask = 0;
1280 nml.item.iLink = iLink;
1281 nml.item.state = 0;
1282 nml.item.stateMask = 0;
1283 if(Link->u.Link.szID)
1285 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1287 else
1289 nml.item.szID[0] = 0;
1291 if(Link->u.Link.szUrl)
1293 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1295 else
1297 nml.item.szUrl[0] = 0;
1300 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1303 /***********************************************************************
1304 * SYSLINK_SetFocus
1305 * Handles receiving the input focus.
1307 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr)
1309 PDOC_ITEM Focus;
1311 infoPtr->HasFocus = TRUE;
1313 /* We always select the first link, even if we activated the control using
1314 SHIFT+TAB. This is the default behavior */
1315 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1316 if(Focus != NULL)
1318 SYSLINK_SetFocusLink(infoPtr, Focus);
1319 SYSLINK_RepaintLink(infoPtr, Focus);
1321 return 0;
1324 /***********************************************************************
1325 * SYSLINK_KillFocus
1326 * Handles losing the input focus.
1328 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr)
1330 PDOC_ITEM Focus;
1332 infoPtr->HasFocus = FALSE;
1333 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1335 if(Focus != NULL)
1337 SYSLINK_RepaintLink(infoPtr, Focus);
1340 return 0;
1343 /***********************************************************************
1344 * SYSLINK_LinkAtPt
1345 * Returns a link at the specified position
1347 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1349 PDOC_ITEM Current;
1350 int id = 0;
1352 LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
1354 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1355 (!MustBeEnabled || (Current->u.Link.state & LIS_ENABLED)))
1357 if(LinkId != NULL)
1359 *LinkId = id;
1361 return Current;
1363 id++;
1366 return NULL;
1369 /***********************************************************************
1370 * SYSLINK_LButtonDown
1371 * Handles mouse clicks
1373 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, const POINT *pt)
1375 PDOC_ITEM Current, Old;
1376 int id;
1378 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1379 if(Current != NULL)
1381 SetFocus(infoPtr->Self);
1383 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1384 if(Old != NULL && Old != Current)
1386 SYSLINK_RepaintLink(infoPtr, Old);
1388 infoPtr->MouseDownID = id;
1389 SYSLINK_RepaintLink(infoPtr, Current);
1392 return 0;
1395 /***********************************************************************
1396 * SYSLINK_LButtonUp
1397 * Handles mouse clicks
1399 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, const POINT *pt)
1401 if(infoPtr->MouseDownID > -1)
1403 PDOC_ITEM Current;
1404 int id;
1406 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1407 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1409 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1413 infoPtr->MouseDownID = -1;
1415 return 0;
1418 /***********************************************************************
1419 * SYSLINK_OnEnter
1420 * Handles ENTER key events
1422 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1424 if(infoPtr->HasFocus && !infoPtr->IgnoreReturn)
1426 PDOC_ITEM Focus;
1427 int id;
1429 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1430 if(Focus)
1432 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1433 return TRUE;
1436 return FALSE;
1439 /***********************************************************************
1440 * SYSKEY_SelectNextPrevLink
1441 * Changes the currently focused link
1443 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1445 if(infoPtr->HasFocus)
1447 PDOC_ITEM Focus;
1448 int id;
1450 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1451 if(Focus != NULL)
1453 PDOC_ITEM NewFocus, OldFocus;
1455 if(Prev)
1456 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1457 else
1458 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1460 if(NewFocus != NULL)
1462 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1464 if(OldFocus && OldFocus != NewFocus)
1466 SYSLINK_RepaintLink(infoPtr, OldFocus);
1468 SYSLINK_RepaintLink(infoPtr, NewFocus);
1469 return TRUE;
1473 return FALSE;
1476 /***********************************************************************
1477 * SYSKEY_SelectNextPrevLink
1478 * Determines if there's a next or previous link to decide whether the control
1479 * should capture the tab key message
1481 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1483 PDOC_ITEM Focus, NewFocus;
1485 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1486 if(Prev)
1487 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1488 else
1489 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1491 return NewFocus == NULL;
1494 /***********************************************************************
1495 * SYSLINK_GetIdealSize
1496 * Calculates the ideal size of a link control at a given maximum width.
1498 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1500 RECT rc;
1501 HDC hdc;
1503 rc.left = rc.top = rc.bottom = 0;
1504 rc.right = cxMaxWidth;
1506 hdc = GetDC(infoPtr->Self);
1507 if (hdc != NULL)
1509 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1511 SYSLINK_Render(infoPtr, hdc, &rc);
1513 SelectObject(hdc, hOldFont);
1514 ReleaseDC(infoPtr->Self, hdc);
1516 lpSize->cx = rc.right;
1517 lpSize->cy = rc.bottom;
1521 /***********************************************************************
1522 * SysLinkWindowProc
1524 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1525 WPARAM wParam, LPARAM lParam)
1527 SYSLINK_INFO *infoPtr;
1529 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1531 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1533 if (!infoPtr && message != WM_CREATE)
1534 return DefWindowProcW(hwnd, message, wParam, lParam);
1536 switch(message) {
1537 case WM_PRINTCLIENT:
1538 case WM_PAINT:
1539 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1541 case WM_ERASEBKGND:
1542 if (!(infoPtr->Style & LWS_TRANSPARENT))
1544 HDC hdc = (HDC)wParam;
1545 HBRUSH brush = CreateSolidBrush( comctl32_color.clrWindow );
1546 RECT rect;
1548 GetClipBox( hdc, &rect );
1549 FillRect( hdc, &rect, brush );
1550 DeleteObject( brush );
1551 return 1;
1553 return 0;
1555 case WM_SETCURSOR:
1557 LHITTESTINFO ht;
1558 DWORD mp = GetMessagePos();
1560 ht.pt.x = (short)LOWORD(mp);
1561 ht.pt.y = (short)HIWORD(mp);
1563 ScreenToClient(infoPtr->Self, &ht.pt);
1564 if(SYSLINK_HitTest (infoPtr, &ht))
1566 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1567 return TRUE;
1570 return DefWindowProcW(hwnd, message, wParam, lParam);
1573 case WM_SIZE:
1575 RECT rcClient;
1576 if (GetClientRect(infoPtr->Self, &rcClient))
1578 HDC hdc = GetDC(infoPtr->Self);
1579 if(hdc != NULL)
1581 SYSLINK_Render(infoPtr, hdc, &rcClient);
1582 ReleaseDC(infoPtr->Self, hdc);
1585 return 0;
1588 case WM_GETFONT:
1589 return (LRESULT)infoPtr->Font;
1591 case WM_SETFONT:
1592 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1594 case WM_SETTEXT:
1595 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1596 return DefWindowProcW(hwnd, message, wParam, lParam);
1598 case WM_LBUTTONDOWN:
1600 POINT pt;
1601 pt.x = (short)LOWORD(lParam);
1602 pt.y = (short)HIWORD(lParam);
1603 return SYSLINK_LButtonDown(infoPtr, &pt);
1605 case WM_LBUTTONUP:
1607 POINT pt;
1608 pt.x = (short)LOWORD(lParam);
1609 pt.y = (short)HIWORD(lParam);
1610 return SYSLINK_LButtonUp(infoPtr, &pt);
1613 case WM_KEYDOWN:
1615 switch(wParam)
1617 case VK_RETURN:
1618 SYSLINK_OnEnter(infoPtr);
1619 return 0;
1620 case VK_TAB:
1622 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1623 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1624 return 0;
1626 default:
1627 return DefWindowProcW(hwnd, message, wParam, lParam);
1631 case WM_GETDLGCODE:
1633 LRESULT Ret = DLGC_HASSETSEL;
1634 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1635 switch(vk)
1637 case VK_RETURN:
1638 Ret |= DLGC_WANTMESSAGE;
1639 break;
1640 case VK_TAB:
1642 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1643 if(!SYSLINK_NoNextLink(infoPtr, shift))
1645 Ret |= DLGC_WANTTAB;
1647 else
1649 Ret |= DLGC_WANTCHARS;
1651 break;
1654 return Ret;
1657 case WM_NCHITTEST:
1659 POINT pt;
1660 RECT rc;
1661 pt.x = (short)LOWORD(lParam);
1662 pt.y = (short)HIWORD(lParam);
1664 GetClientRect(infoPtr->Self, &rc);
1665 ScreenToClient(infoPtr->Self, &pt);
1666 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1668 return HTNOWHERE;
1671 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1673 return HTCLIENT;
1676 return HTTRANSPARENT;
1679 case LM_HITTEST:
1680 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1682 case LM_SETITEM:
1683 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1685 case LM_GETITEM:
1686 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1688 case LM_GETIDEALHEIGHT:
1689 if (lParam)
1691 /* LM_GETIDEALSIZE */
1692 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1694 return SYSLINK_GetIdealHeight(infoPtr);
1696 case WM_SETFOCUS:
1697 return SYSLINK_SetFocus(infoPtr);
1699 case WM_KILLFOCUS:
1700 return SYSLINK_KillFocus(infoPtr);
1702 case WM_ENABLE:
1703 infoPtr->Style &= ~WS_DISABLED;
1704 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1705 InvalidateRect (infoPtr->Self, NULL, FALSE);
1706 return 0;
1708 case WM_STYLECHANGED:
1709 if (wParam == GWL_STYLE)
1711 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1713 InvalidateRect(infoPtr->Self, NULL, TRUE);
1715 return 0;
1717 case WM_CREATE:
1719 CREATESTRUCTW *cs = (CREATESTRUCTW*)lParam;
1721 /* allocate memory for info struct */
1722 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1723 if (!infoPtr) return -1;
1724 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1726 /* initialize the info struct */
1727 infoPtr->Self = hwnd;
1728 infoPtr->Notify = cs->hwndParent;
1729 infoPtr->Style = cs->style;
1730 infoPtr->Font = 0;
1731 infoPtr->LinkFont = 0;
1732 list_init(&infoPtr->Items);
1733 infoPtr->HasFocus = FALSE;
1734 infoPtr->MouseDownID = -1;
1735 infoPtr->TextColor = comctl32_color.clrWindowText;
1736 infoPtr->LinkColor = comctl32_color.clrHighlight;
1737 infoPtr->VisitedColor = comctl32_color.clrHighlight;
1738 infoPtr->BreakChar = ' ';
1739 infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN;
1740 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1741 SYSLINK_SetText(infoPtr, cs->lpszName);
1742 return 0;
1744 case WM_DESTROY:
1745 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1746 SYSLINK_ClearDoc(infoPtr);
1747 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1748 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1749 SetWindowLongPtrW(hwnd, 0, 0);
1750 Free (infoPtr);
1751 return 0;
1753 case WM_SYSCOLORCHANGE:
1754 COMCTL32_RefreshSysColors();
1755 return 0;
1757 default:
1758 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1760 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1762 return DefWindowProcW(hwnd, message, wParam, lParam);
1767 /***********************************************************************
1768 * SYSLINK_Register [Internal]
1770 * Registers the SysLink window class.
1772 VOID SYSLINK_Register (void)
1774 WNDCLASSW wndClass;
1776 ZeroMemory (&wndClass, sizeof(wndClass));
1777 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1778 wndClass.lpfnWndProc = SysLinkWindowProc;
1779 wndClass.cbClsExtra = 0;
1780 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1781 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1782 wndClass.lpszClassName = WC_LINK;
1784 RegisterClassW (&wndClass);
1788 /***********************************************************************
1789 * SYSLINK_Unregister [Internal]
1791 * Unregisters the SysLink window class.
1793 VOID SYSLINK_Unregister (void)
1795 UnregisterClassW (WC_LINK, NULL);