push 4e98c31ec75caed2ea3040ac2e710b58ba1ca0e1
[wine/hacks.git] / dlls / comctl32 / syslink.c
blob7f74b36dccc7ddeb33810df6d7d98b6ec1ae8bdf
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(progress);
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 } SYSLINK_INFO;
100 static const WCHAR SL_LINKOPEN[] = { '<','a', 0 };
101 static const WCHAR SL_HREF[] = { 'h','r','e','f','=','\"',0 };
102 static const WCHAR SL_ID[] = { 'i','d','=','\"',0 };
103 static const WCHAR SL_LINKCLOSE[] = { '<','/','a','>',0 };
105 /* Control configuration constants */
107 #define SL_LEFTMARGIN (0)
108 #define SL_TOPMARGIN (0)
109 #define SL_RIGHTMARGIN (0)
110 #define SL_BOTTOMMARGIN (0)
112 /***********************************************************************
113 * SYSLINK_FreeDocItem
114 * Frees all data and gdi objects associated with a document item
116 static VOID SYSLINK_FreeDocItem (PDOC_ITEM DocItem)
118 if(DocItem->Type == slLink)
120 Free(DocItem->u.Link.szID);
121 Free(DocItem->u.Link.szUrl);
124 /* we don't free Text because it's just a pointer to a character in the
125 entire window text string */
127 Free(DocItem);
130 /***********************************************************************
131 * SYSLINK_AppendDocItem
132 * Create and append a new document item.
134 static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UINT textlen,
135 SL_ITEM_TYPE type, PDOC_ITEM LastItem)
137 PDOC_ITEM Item;
139 textlen = min(textlen, strlenW(Text));
140 Item = Alloc(FIELD_OFFSET(DOC_ITEM, Text[textlen + 1]));
141 if(Item == NULL)
143 ERR("Failed to alloc DOC_ITEM structure!\n");
144 return NULL;
147 Item->Next = NULL;
148 Item->nText = textlen;
149 Item->Type = type;
150 Item->Blocks = NULL;
152 if(LastItem != NULL)
154 LastItem->Next = Item;
156 else
158 infoPtr->Items = Item;
161 lstrcpynW(Item->Text, Text, textlen + 1);
163 return Item;
166 /***********************************************************************
167 * SYSLINK_ClearDoc
168 * Clears the document tree
170 static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
172 PDOC_ITEM Item, Next;
174 Item = infoPtr->Items;
175 while(Item != NULL)
177 Next = Item->Next;
178 SYSLINK_FreeDocItem(Item);
179 Item = Next;
182 infoPtr->Items = NULL;
185 /***********************************************************************
186 * SYSLINK_ParseText
187 * Parses the window text string and creates a document. Returns the
188 * number of document items created.
190 static UINT SYSLINK_ParseText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
192 LPCWSTR current, textstart = NULL, linktext = NULL, firsttag = NULL;
193 int taglen = 0, textlen = 0, linklen = 0, docitems = 0;
194 PDOC_ITEM Last = NULL;
195 SL_ITEM_TYPE CurrentType = slText;
196 LPCWSTR lpID, lpUrl;
197 UINT lenId, lenUrl;
199 for(current = Text; *current != 0;)
201 if(*current == '<')
203 if(!StrCmpNIW(current, SL_LINKOPEN, 2) && (CurrentType == slText))
205 BOOL ValidParam = FALSE, ValidLink = FALSE;
207 if(*(current + 2) == '>')
209 /* we just have to deal with a <a> tag */
210 taglen = 3;
211 ValidLink = TRUE;
212 ValidParam = TRUE;
213 firsttag = current;
214 linklen = 0;
215 lpID = NULL;
216 lpUrl = NULL;
218 else if(*(current + 2) == infoPtr->BreakChar)
220 /* we expect parameters, parse them */
221 LPCWSTR *CurrentParameter = NULL, tmp;
222 UINT *CurrentParameterLen = NULL;
224 taglen = 3;
225 tmp = current + taglen;
226 lpID = NULL;
227 lpUrl = NULL;
229 CheckParameter:
230 /* compare the current position with all known parameters */
231 if(!StrCmpNIW(tmp, SL_HREF, 6))
233 taglen += 6;
234 ValidParam = TRUE;
235 CurrentParameter = &lpUrl;
236 CurrentParameterLen = &lenUrl;
238 else if(!StrCmpNIW(tmp, SL_ID, 4))
240 taglen += 4;
241 ValidParam = TRUE;
242 CurrentParameter = &lpID;
243 CurrentParameterLen = &lenId;
245 else
247 ValidParam = FALSE;
250 if(ValidParam)
252 /* we got a known parameter, now search until the next " character.
253 If we can't find a " character, there's a syntax error and we just assume it's text */
254 ValidParam = FALSE;
255 *CurrentParameter = current + taglen;
256 *CurrentParameterLen = 0;
258 for(tmp = *CurrentParameter; *tmp != 0; tmp++)
260 taglen++;
261 if(*tmp == '\"')
263 ValidParam = TRUE;
264 tmp++;
265 break;
267 (*CurrentParameterLen)++;
270 if(ValidParam)
272 /* we're done with this parameter, now there are only 2 possibilities:
273 * 1. another parameter is coming, so expect a ' ' (space) character
274 * 2. the tag is being closed, so expect a '<' character
276 if(*tmp == infoPtr->BreakChar)
278 /* we expect another parameter, do the whole thing again */
279 taglen++;
280 tmp++;
281 goto CheckParameter;
283 else if(*tmp == '>')
285 /* the tag is being closed, we're done */
286 ValidLink = TRUE;
287 taglen++;
289 else
290 tmp++;
294 if(ValidLink && ValidParam)
296 /* the <a ...> tag appears to be valid. save all information
297 so we can add the link if we find a valid </a> tag later */
298 CurrentType = slLink;
299 linktext = current + taglen;
300 linklen = 0;
301 firsttag = current;
303 else
305 taglen = 1;
306 lpID = NULL;
307 lpUrl = NULL;
308 if(textstart == NULL)
310 textstart = current;
314 else if(!StrCmpNIW(current, SL_LINKCLOSE, 4) && (CurrentType == slLink) && firsttag)
316 /* there's a <a...> tag opened, first add the previous text, if present */
317 if(textstart != NULL && textlen > 0 && firsttag > textstart)
319 Last = SYSLINK_AppendDocItem(infoPtr, textstart, firsttag - textstart, slText, Last);
320 if(Last == NULL)
322 ERR("Unable to create new document item!\n");
323 return docitems;
325 docitems++;
326 textstart = NULL;
327 textlen = 0;
330 /* now it's time to add the link to the document */
331 current += 4;
332 if(linktext != NULL && linklen > 0)
334 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slLink, Last);
335 if(Last == NULL)
337 ERR("Unable to create new document item!\n");
338 return docitems;
340 docitems++;
341 if(CurrentType == slLink)
343 int nc;
345 if(!(infoPtr->Style & WS_DISABLED))
347 Last->u.Link.state |= LIS_ENABLED;
349 /* Copy the tag parameters */
350 if(lpID != NULL)
352 nc = min(lenId, strlenW(lpID));
353 nc = min(nc, MAX_LINKID_TEXT - 1);
354 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
355 if(Last->u.Link.szID != NULL)
357 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
360 else
361 Last->u.Link.szID = NULL;
362 if(lpUrl != NULL)
364 nc = min(lenUrl, strlenW(lpUrl));
365 nc = min(nc, L_MAX_URL_LENGTH - 1);
366 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
367 if(Last->u.Link.szUrl != NULL)
369 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
372 else
373 Last->u.Link.szUrl = NULL;
375 linktext = NULL;
377 CurrentType = slText;
378 firsttag = NULL;
379 textstart = NULL;
380 continue;
382 else
384 /* we don't know what tag it is, so just continue */
385 taglen = 1;
386 linklen++;
387 if(CurrentType == slText && textstart == NULL)
389 textstart = current;
393 textlen += taglen;
394 current += taglen;
396 else
398 textlen++;
399 linklen++;
401 /* save the pointer of the current text item if we couldn't find a tag */
402 if(textstart == NULL && CurrentType == slText)
404 textstart = current;
407 current++;
411 if(textstart != NULL && textlen > 0)
413 Last = SYSLINK_AppendDocItem(infoPtr, textstart, textlen, CurrentType, Last);
414 if(Last == NULL)
416 ERR("Unable to create new document item!\n");
417 return docitems;
419 if(CurrentType == slLink)
421 int nc;
423 if(!(infoPtr->Style & WS_DISABLED))
425 Last->u.Link.state |= LIS_ENABLED;
427 /* Copy the tag parameters */
428 if(lpID != NULL)
430 nc = min(lenId, strlenW(lpID));
431 nc = min(nc, MAX_LINKID_TEXT - 1);
432 Last->u.Link.szID = Alloc((nc + 1) * sizeof(WCHAR));
433 if(Last->u.Link.szID != NULL)
435 lstrcpynW(Last->u.Link.szID, lpID, nc + 1);
438 else
439 Last->u.Link.szID = NULL;
440 if(lpUrl != NULL)
442 nc = min(lenUrl, strlenW(lpUrl));
443 nc = min(nc, L_MAX_URL_LENGTH - 1);
444 Last->u.Link.szUrl = Alloc((nc + 1) * sizeof(WCHAR));
445 if(Last->u.Link.szUrl != NULL)
447 lstrcpynW(Last->u.Link.szUrl, lpUrl, nc + 1);
450 else
451 Last->u.Link.szUrl = NULL;
453 docitems++;
456 if(linktext != NULL && linklen > 0)
458 /* we got an unclosed link, just display the text */
459 Last = SYSLINK_AppendDocItem(infoPtr, linktext, linklen, slText, Last);
460 if(Last == NULL)
462 ERR("Unable to create new document item!\n");
463 return docitems;
465 docitems++;
468 return docitems;
471 /***********************************************************************
472 * SYSLINK_RepaintLink
473 * Repaints a link.
475 static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
477 PDOC_TEXTBLOCK bl;
478 int n;
480 if(DocItem->Type != slLink)
482 ERR("DocItem not a link!\n");
483 return;
486 bl = DocItem->Blocks;
487 if (bl != NULL)
489 n = DocItem->nText;
491 while(n > 0)
493 InvalidateRect(infoPtr->Self, &bl->rc, TRUE);
494 n -= bl->nChars + bl->nSkip;
495 bl++;
500 /***********************************************************************
501 * SYSLINK_GetLinkItemByIndex
502 * Retrieves a document link by its index
504 static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
506 PDOC_ITEM Current = infoPtr->Items;
508 while(Current != NULL)
510 if((Current->Type == slLink) && (iLink-- <= 0))
512 return Current;
514 Current = Current->Next;
516 return NULL;
519 /***********************************************************************
520 * SYSLINK_GetFocusLink
521 * Retrieves the link that has the LIS_FOCUSED bit
523 static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
525 PDOC_ITEM Current = infoPtr->Items;
526 int id = 0;
528 while(Current != NULL)
530 if((Current->Type == slLink))
532 if(Current->u.Link.state & LIS_FOCUSED)
534 if(LinkId != NULL)
535 *LinkId = id;
536 return Current;
538 id++;
540 Current = Current->Next;
542 return NULL;
545 /***********************************************************************
546 * SYSLINK_GetNextLink
547 * Gets the next link
549 static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
551 for(Current = (Current != NULL ? Current->Next : infoPtr->Items);
552 Current != NULL;
553 Current = Current->Next)
555 if(Current->Type == slLink)
557 return Current;
560 return NULL;
563 /***********************************************************************
564 * SYSLINK_GetPrevLink
565 * Gets the previous link
567 static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
569 if(Current == NULL)
571 /* returns the last link */
572 PDOC_ITEM Last = NULL;
574 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
576 if(Current->Type == slLink)
578 Last = Current;
581 return Last;
583 else
585 /* returns the previous link */
586 PDOC_ITEM Cur, Prev = NULL;
588 for(Cur = infoPtr->Items; Cur != NULL; Cur = Cur->Next)
590 if(Cur == Current)
592 break;
594 if(Cur->Type == slLink)
596 Prev = Cur;
599 return Prev;
603 /***********************************************************************
604 * SYSLINK_WrapLine
605 * Tries to wrap a line.
607 static BOOL SYSLINK_WrapLine (HDC hdc, LPWSTR Text, WCHAR BreakChar, int *LineLen,
608 int nFit, LPSIZE Extent, int Width)
610 WCHAR *Current;
612 if(nFit == *LineLen)
614 return FALSE;
617 *LineLen = nFit;
619 Current = Text + nFit;
621 /* check if we're in the middle of a word */
622 if((*Current) != BreakChar)
624 /* search for the beginning of the word */
625 while(Current > Text && (*(Current - 1)) != BreakChar)
627 Current--;
628 (*LineLen)--;
631 if((*LineLen) == 0)
633 Extent->cx = 0;
634 Extent->cy = 0;
636 return TRUE;
639 return TRUE;
642 /***********************************************************************
643 * SYSLINK_Render
644 * Renders the document in memory
646 static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
648 RECT rc;
649 PDOC_ITEM Current;
650 HGDIOBJ hOldFont;
651 int x, y, LineHeight;
652 SIZE szDoc;
654 szDoc.cx = szDoc.cy = 0;
656 rc = *pRect;
657 rc.right -= SL_RIGHTMARGIN;
658 rc.bottom -= SL_BOTTOMMARGIN;
660 if(rc.right - SL_LEFTMARGIN < 0)
661 rc.right = MAXLONG;
662 if (rc.bottom - SL_TOPMARGIN < 0)
663 rc.bottom = MAXLONG;
665 hOldFont = SelectObject(hdc, infoPtr->Font);
667 x = SL_LEFTMARGIN;
668 y = SL_TOPMARGIN;
669 LineHeight = 0;
671 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
673 int n, nBlocks;
674 LPWSTR tx;
675 PDOC_TEXTBLOCK bl, cbl;
676 INT nFit;
677 SIZE szDim;
679 if(Current->nText == 0)
681 continue;
684 tx = Current->Text;
685 n = Current->nText;
687 Free(Current->Blocks);
688 Current->Blocks = NULL;
689 bl = NULL;
690 nBlocks = 0;
692 if(Current->Type == slText)
694 SelectObject(hdc, infoPtr->Font);
696 else if(Current->Type == slLink)
698 SelectObject(hdc, infoPtr->LinkFont);
701 while(n > 0)
703 int SkipChars = 0;
705 /* skip break characters unless they're the first of the doc item */
706 if(tx != Current->Text || x == SL_LEFTMARGIN)
708 while(n > 0 && (*tx) == infoPtr->BreakChar)
710 tx++;
711 SkipChars++;
712 n--;
716 if((n == 0 && SkipChars != 0) ||
717 GetTextExtentExPointW(hdc, tx, n, rc.right - x, &nFit, NULL, &szDim))
719 int LineLen = n;
720 BOOL Wrap = FALSE;
721 PDOC_TEXTBLOCK nbl;
723 if(n != 0)
725 Wrap = SYSLINK_WrapLine(hdc, tx, infoPtr->BreakChar, &LineLen, nFit, &szDim, rc.right - x);
727 if(LineLen == 0)
729 if(x > SL_LEFTMARGIN)
731 /* move one line down, the word didn't fit into the line */
732 x = SL_LEFTMARGIN;
733 y += LineHeight;
734 LineHeight = 0;
735 continue;
737 else
739 /* the word starts at the beginning of the line and doesn't
740 fit into the line, so break it at the last character that fits */
741 LineLen = max(nFit, 1);
745 if(LineLen != n)
747 if(!GetTextExtentExPointW(hdc, tx, LineLen, rc.right - x, NULL, NULL, &szDim))
749 if(bl != NULL)
751 Free(bl);
752 bl = NULL;
753 nBlocks = 0;
755 break;
760 nbl = ReAlloc(bl, (nBlocks + 1) * sizeof(DOC_TEXTBLOCK));
761 if (nbl != NULL)
763 bl = nbl;
764 nBlocks++;
766 cbl = bl + nBlocks - 1;
768 cbl->nChars = LineLen;
769 cbl->nSkip = SkipChars;
770 cbl->rc.left = x;
771 cbl->rc.top = y;
772 cbl->rc.right = x + szDim.cx;
773 cbl->rc.bottom = y + szDim.cy;
775 if (cbl->rc.right > szDoc.cx)
776 szDoc.cx = cbl->rc.right;
777 if (cbl->rc.bottom > szDoc.cy)
778 szDoc.cy = cbl->rc.bottom;
780 if(LineLen != 0)
782 x += szDim.cx;
783 LineHeight = max(LineHeight, szDim.cy);
785 if(Wrap)
787 x = SL_LEFTMARGIN;
788 y += LineHeight;
789 LineHeight = 0;
793 else
795 Free(bl);
796 bl = NULL;
797 nBlocks = 0;
799 ERR("Failed to alloc DOC_TEXTBLOCK structure!\n");
800 break;
802 n -= LineLen;
803 tx += LineLen;
805 else
807 n--;
811 if(nBlocks != 0)
813 Current->Blocks = bl;
817 SelectObject(hdc, hOldFont);
819 pRect->right = pRect->left + szDoc.cx;
820 pRect->bottom = pRect->top + szDoc.cy;
823 /***********************************************************************
824 * SYSLINK_Draw
825 * Draws the SysLink control.
827 static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
829 RECT rc;
830 PDOC_ITEM Current;
831 HFONT hOldFont;
832 COLORREF OldTextColor, OldBkColor;
834 hOldFont = SelectObject(hdc, infoPtr->Font);
835 OldTextColor = SetTextColor(hdc, infoPtr->TextColor);
836 OldBkColor = SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
838 GetClientRect(infoPtr->Self, &rc);
839 rc.right -= SL_RIGHTMARGIN + SL_LEFTMARGIN;
840 rc.bottom -= SL_BOTTOMMARGIN + SL_TOPMARGIN;
842 if(rc.right < 0 || rc.bottom < 0) return 0;
844 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
846 int n;
847 LPWSTR tx;
848 PDOC_TEXTBLOCK bl;
850 bl = Current->Blocks;
851 if(bl != NULL)
853 tx = Current->Text;
854 n = Current->nText;
856 if(Current->Type == slText)
858 SelectObject(hdc, infoPtr->Font);
859 SetTextColor(hdc, infoPtr->TextColor);
861 else
863 SelectObject(hdc, infoPtr->LinkFont);
864 SetTextColor(hdc, (!(Current->u.Link.state & LIS_VISITED) ? infoPtr->LinkColor : infoPtr->VisitedColor));
867 while(n > 0)
869 tx += bl->nSkip;
870 ExtTextOutW(hdc, bl->rc.left, bl->rc.top, ETO_OPAQUE | ETO_CLIPPED, &bl->rc, tx, bl->nChars, NULL);
871 if((Current->Type == slLink) && (Current->u.Link.state & LIS_FOCUSED) && infoPtr->HasFocus)
873 COLORREF PrevTextColor;
874 PrevTextColor = SetTextColor(hdc, infoPtr->TextColor);
875 DrawFocusRect(hdc, &bl->rc);
876 SetTextColor(hdc, PrevTextColor);
878 tx += bl->nChars;
879 n -= bl->nChars + bl->nSkip;
880 bl++;
885 SetBkColor(hdc, OldBkColor);
886 SetTextColor(hdc, OldTextColor);
887 SelectObject(hdc, hOldFont);
889 return 0;
893 /***********************************************************************
894 * SYSLINK_Paint
895 * Handles the WM_PAINT message.
897 static LRESULT SYSLINK_Paint (const SYSLINK_INFO *infoPtr, HDC hdcParam)
899 HDC hdc;
900 PAINTSTRUCT ps;
902 hdc = hdcParam ? hdcParam : BeginPaint (infoPtr->Self, &ps);
903 if (hdc)
905 SYSLINK_Draw (infoPtr, hdc);
906 if (!hdcParam) EndPaint (infoPtr->Self, &ps);
908 return 0;
912 /***********************************************************************
913 * SYSLINK_SetFont
914 * Set new Font for the SysLink control.
916 static HFONT SYSLINK_SetFont (SYSLINK_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
918 HDC hdc;
919 LOGFONTW lf;
920 TEXTMETRICW tm;
921 RECT rcClient;
922 HFONT hOldFont = infoPtr->Font;
923 infoPtr->Font = hFont;
925 /* free the underline font */
926 if(infoPtr->LinkFont != NULL)
928 DeleteObject(infoPtr->LinkFont);
929 infoPtr->LinkFont = NULL;
932 /* Render text position and word wrapping in memory */
933 if (GetClientRect(infoPtr->Self, &rcClient))
935 hdc = GetDC(infoPtr->Self);
936 if(hdc != NULL)
938 /* create a new underline font */
939 if(GetTextMetricsW(hdc, &tm) &&
940 GetObjectW(infoPtr->Font, sizeof(LOGFONTW), &lf))
942 lf.lfUnderline = TRUE;
943 infoPtr->LinkFont = CreateFontIndirectW(&lf);
944 infoPtr->BreakChar = tm.tmBreakChar;
946 else
948 ERR("Failed to create link font!\n");
951 SYSLINK_Render(infoPtr, hdc, &rcClient);
952 ReleaseDC(infoPtr->Self, hdc);
956 if(bRedraw)
958 RedrawWindow(infoPtr->Self, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
961 return hOldFont;
964 /***********************************************************************
965 * SYSLINK_SetText
966 * Set new text for the SysLink control.
968 static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
970 /* clear the document */
971 SYSLINK_ClearDoc(infoPtr);
973 if(Text == NULL || *Text == 0)
975 return TRUE;
978 /* let's parse the string and create a document */
979 if(SYSLINK_ParseText(infoPtr, Text) > 0)
981 RECT rcClient;
983 /* Render text position and word wrapping in memory */
984 if (GetClientRect(infoPtr->Self, &rcClient))
986 HDC hdc = GetDC(infoPtr->Self);
987 if (hdc != NULL)
989 SYSLINK_Render(infoPtr, hdc, &rcClient);
990 ReleaseDC(infoPtr->Self, hdc);
992 InvalidateRect(infoPtr->Self, NULL, TRUE);
997 return TRUE;
1000 /***********************************************************************
1001 * SYSLINK_SetFocusLink
1002 * Updates the focus status bits and focusses the specified link.
1003 * If no document item is specified, the focus bit will be removed from all links.
1004 * Returns the previous focused item.
1006 static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
1008 PDOC_ITEM Current, PrevFocus = NULL;
1010 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1012 if(Current->Type == slLink)
1014 if((PrevFocus == NULL) && (Current->u.Link.state & LIS_FOCUSED))
1016 PrevFocus = Current;
1019 if(Current == DocItem)
1021 Current->u.Link.state |= LIS_FOCUSED;
1023 else
1025 Current->u.Link.state &= ~LIS_FOCUSED;
1030 return PrevFocus;
1033 /***********************************************************************
1034 * SYSLINK_SetItem
1035 * Sets the states and attributes of a link item.
1037 static LRESULT SYSLINK_SetItem (const SYSLINK_INFO *infoPtr, const LITEM *Item)
1039 PDOC_ITEM di;
1040 int nc;
1041 PWSTR szId = NULL;
1042 PWSTR szUrl = NULL;
1043 BOOL Repaint = FALSE;
1045 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1047 ERR("Invalid Flags!\n");
1048 return FALSE;
1051 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1052 if(di == NULL)
1054 ERR("Link %d couldn't be found\n", Item->iLink);
1055 return FALSE;
1058 if(Item->mask & LIF_ITEMID)
1060 nc = min(lstrlenW(Item->szID), MAX_LINKID_TEXT - 1);
1061 szId = Alloc((nc + 1) * sizeof(WCHAR));
1062 if(szId)
1064 lstrcpynW(szId, Item->szID, nc + 1);
1066 else
1068 ERR("Unable to allocate memory for link id\n");
1069 return FALSE;
1073 if(Item->mask & LIF_URL)
1075 nc = min(lstrlenW(Item->szUrl), L_MAX_URL_LENGTH - 1);
1076 szUrl = Alloc((nc + 1) * sizeof(WCHAR));
1077 if(szUrl)
1079 lstrcpynW(szUrl, Item->szUrl, nc + 1);
1081 else
1083 Free(szId);
1085 ERR("Unable to allocate memory for link url\n");
1086 return FALSE;
1090 if(Item->mask & LIF_ITEMID)
1092 Free(di->u.Link.szID);
1093 di->u.Link.szID = szId;
1096 if(Item->mask & LIF_URL)
1098 Free(di->u.Link.szUrl);
1099 di->u.Link.szUrl = szUrl;
1102 if(Item->mask & LIF_STATE)
1104 UINT oldstate = di->u.Link.state;
1105 /* clear the masked bits */
1106 di->u.Link.state &= ~(Item->stateMask & LIS_MASK);
1107 /* copy the bits */
1108 di->u.Link.state |= (Item->state & Item->stateMask) & LIS_MASK;
1109 Repaint = (oldstate != di->u.Link.state);
1111 /* update the focus */
1112 SYSLINK_SetFocusLink(infoPtr, ((di->u.Link.state & LIS_FOCUSED) ? di : NULL));
1115 if(Repaint)
1117 SYSLINK_RepaintLink(infoPtr, di);
1120 return TRUE;
1123 /***********************************************************************
1124 * SYSLINK_GetItem
1125 * Retrieves the states and attributes of a link item.
1127 static LRESULT SYSLINK_GetItem (const SYSLINK_INFO *infoPtr, PLITEM Item)
1129 PDOC_ITEM di;
1131 if(!(Item->mask & LIF_ITEMINDEX) || !(Item->mask & (LIF_FLAGSMASK)))
1133 ERR("Invalid Flags!\n");
1134 return FALSE;
1137 di = SYSLINK_GetLinkItemByIndex(infoPtr, Item->iLink);
1138 if(di == NULL)
1140 ERR("Link %d couldn't be found\n", Item->iLink);
1141 return FALSE;
1144 if(Item->mask & LIF_STATE)
1146 Item->state = (di->u.Link.state & Item->stateMask);
1147 if(!infoPtr->HasFocus)
1149 /* remove the LIS_FOCUSED bit if the control doesn't have focus */
1150 Item->state &= ~LIS_FOCUSED;
1154 if(Item->mask & LIF_ITEMID)
1156 if(di->u.Link.szID)
1158 lstrcpyW(Item->szID, di->u.Link.szID);
1160 else
1162 Item->szID[0] = 0;
1166 if(Item->mask & LIF_URL)
1168 if(di->u.Link.szUrl)
1170 lstrcpyW(Item->szUrl, di->u.Link.szUrl);
1172 else
1174 Item->szUrl[0] = 0;
1178 return TRUE;
1181 /***********************************************************************
1182 * SYSLINK_PtInDocItem
1183 * Determines if a point is in the region of a document item
1185 static BOOL SYSLINK_PtInDocItem (const DOC_ITEM *DocItem, POINT pt)
1187 PDOC_TEXTBLOCK bl;
1188 int n;
1190 bl = DocItem->Blocks;
1191 if (bl != NULL)
1193 n = DocItem->nText;
1195 while(n > 0)
1197 if (PtInRect(&bl->rc, pt))
1199 return TRUE;
1201 n -= bl->nChars + bl->nSkip;
1202 bl++;
1206 return FALSE;
1209 /***********************************************************************
1210 * SYSLINK_HitTest
1211 * Determines the link the user clicked on.
1213 static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTest)
1215 PDOC_ITEM Current;
1216 int id = 0;
1218 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1220 if(Current->Type == slLink)
1222 if(SYSLINK_PtInDocItem(Current, HitTest->pt))
1224 HitTest->item.mask = 0;
1225 HitTest->item.iLink = id;
1226 HitTest->item.state = 0;
1227 HitTest->item.stateMask = 0;
1228 if(Current->u.Link.szID)
1230 lstrcpyW(HitTest->item.szID, Current->u.Link.szID);
1232 else
1234 HitTest->item.szID[0] = 0;
1236 if(Current->u.Link.szUrl)
1238 lstrcpyW(HitTest->item.szUrl, Current->u.Link.szUrl);
1240 else
1242 HitTest->item.szUrl[0] = 0;
1244 return TRUE;
1246 id++;
1250 return FALSE;
1253 /***********************************************************************
1254 * SYSLINK_GetIdealHeight
1255 * Returns the preferred height of a link at the current control's width.
1257 static LRESULT SYSLINK_GetIdealHeight (const SYSLINK_INFO *infoPtr)
1259 HDC hdc = GetDC(infoPtr->Self);
1260 if(hdc != NULL)
1262 LRESULT height;
1263 TEXTMETRICW tm;
1264 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1266 if(GetTextMetricsW(hdc, &tm))
1268 height = tm.tmHeight;
1270 else
1272 height = 0;
1274 SelectObject(hdc, hOldFont);
1275 ReleaseDC(infoPtr->Self, hdc);
1277 return height;
1279 return 0;
1282 /***********************************************************************
1283 * SYSLINK_SendParentNotify
1284 * Sends a WM_NOTIFY message to the parent window.
1286 static LRESULT SYSLINK_SendParentNotify (const SYSLINK_INFO *infoPtr, UINT code, const DOC_ITEM *Link, int iLink)
1288 NMLINK nml;
1290 nml.hdr.hwndFrom = infoPtr->Self;
1291 nml.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1292 nml.hdr.code = code;
1294 nml.item.mask = 0;
1295 nml.item.iLink = iLink;
1296 nml.item.state = 0;
1297 nml.item.stateMask = 0;
1298 if(Link->u.Link.szID)
1300 lstrcpyW(nml.item.szID, Link->u.Link.szID);
1302 else
1304 nml.item.szID[0] = 0;
1306 if(Link->u.Link.szUrl)
1308 lstrcpyW(nml.item.szUrl, Link->u.Link.szUrl);
1310 else
1312 nml.item.szUrl[0] = 0;
1315 return SendMessageW(infoPtr->Notify, WM_NOTIFY, nml.hdr.idFrom, (LPARAM)&nml);
1318 /***********************************************************************
1319 * SYSLINK_SetFocus
1320 * Handles receiving the input focus.
1322 static LRESULT SYSLINK_SetFocus (SYSLINK_INFO *infoPtr, HWND PrevFocusWindow)
1324 PDOC_ITEM Focus;
1326 infoPtr->HasFocus = TRUE;
1328 /* We always select the first link, even if we activated the control using
1329 SHIFT+TAB. This is the default behavior */
1330 Focus = SYSLINK_GetNextLink(infoPtr, NULL);
1331 if(Focus != NULL)
1333 SYSLINK_SetFocusLink(infoPtr, Focus);
1336 SYSLINK_RepaintLink(infoPtr, Focus);
1338 return 0;
1341 /***********************************************************************
1342 * SYSLINK_KillFocus
1343 * Handles losing the input focus.
1345 static LRESULT SYSLINK_KillFocus (SYSLINK_INFO *infoPtr, HWND NewFocusWindow)
1347 PDOC_ITEM Focus;
1349 infoPtr->HasFocus = FALSE;
1350 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1352 if(Focus != NULL)
1354 SYSLINK_RepaintLink(infoPtr, Focus);
1357 return 0;
1360 /***********************************************************************
1361 * SYSLINK_LinkAtPt
1362 * Returns a link at the specified position
1364 static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, int *LinkId, BOOL MustBeEnabled)
1366 PDOC_ITEM Current;
1367 int id = 0;
1369 for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
1371 if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
1372 (!MustBeEnabled || (MustBeEnabled && (Current->u.Link.state & LIS_ENABLED))))
1374 if(LinkId != NULL)
1376 *LinkId = id;
1378 return Current;
1380 id++;
1383 return NULL;
1386 /***********************************************************************
1387 * SYSLINK_LButtonDown
1388 * Handles mouse clicks
1390 static LRESULT SYSLINK_LButtonDown (SYSLINK_INFO *infoPtr, DWORD Buttons, const POINT *pt)
1392 PDOC_ITEM Current, Old;
1393 int id;
1395 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1396 if(Current != NULL)
1398 SetFocus(infoPtr->Self);
1400 Old = SYSLINK_SetFocusLink(infoPtr, Current);
1401 if(Old != NULL && Old != Current)
1403 SYSLINK_RepaintLink(infoPtr, Old);
1405 infoPtr->MouseDownID = id;
1406 SYSLINK_RepaintLink(infoPtr, Current);
1409 return 0;
1412 /***********************************************************************
1413 * SYSLINK_LButtonUp
1414 * Handles mouse clicks
1416 static LRESULT SYSLINK_LButtonUp (SYSLINK_INFO *infoPtr, DWORD Buttons, const POINT *pt)
1418 if(infoPtr->MouseDownID > -1)
1420 PDOC_ITEM Current;
1421 int id;
1423 Current = SYSLINK_LinkAtPt(infoPtr, pt, &id, TRUE);
1424 if((Current != NULL) && (Current->u.Link.state & LIS_FOCUSED) && (infoPtr->MouseDownID == id))
1426 SYSLINK_SendParentNotify(infoPtr, NM_CLICK, Current, id);
1430 infoPtr->MouseDownID = -1;
1432 return 0;
1435 /***********************************************************************
1436 * SYSLINK_OnEnter
1437 * Handles ENTER key events
1439 static BOOL SYSLINK_OnEnter (const SYSLINK_INFO *infoPtr)
1441 if(infoPtr->HasFocus)
1443 PDOC_ITEM Focus;
1444 int id;
1446 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1447 if(Focus != NULL)
1449 SYSLINK_SendParentNotify(infoPtr, NM_RETURN, Focus, id);
1450 return TRUE;
1453 return FALSE;
1456 /***********************************************************************
1457 * SYSKEY_SelectNextPrevLink
1458 * Changes the currently focused link
1460 static BOOL SYSKEY_SelectNextPrevLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1462 if(infoPtr->HasFocus)
1464 PDOC_ITEM Focus;
1465 int id;
1467 Focus = SYSLINK_GetFocusLink(infoPtr, &id);
1468 if(Focus != NULL)
1470 PDOC_ITEM NewFocus, OldFocus;
1472 if(Prev)
1473 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1474 else
1475 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1477 if(NewFocus != NULL)
1479 OldFocus = SYSLINK_SetFocusLink(infoPtr, NewFocus);
1481 if(OldFocus != NewFocus)
1483 SYSLINK_RepaintLink(infoPtr, OldFocus);
1485 SYSLINK_RepaintLink(infoPtr, NewFocus);
1486 return TRUE;
1490 return FALSE;
1493 /***********************************************************************
1494 * SYSKEY_SelectNextPrevLink
1495 * Determines if there's a next or previous link to decide whether the control
1496 * should capture the tab key message
1498 static BOOL SYSLINK_NoNextLink (const SYSLINK_INFO *infoPtr, BOOL Prev)
1500 PDOC_ITEM Focus, NewFocus;
1502 Focus = SYSLINK_GetFocusLink(infoPtr, NULL);
1503 if(Prev)
1504 NewFocus = SYSLINK_GetPrevLink(infoPtr, Focus);
1505 else
1506 NewFocus = SYSLINK_GetNextLink(infoPtr, Focus);
1508 return NewFocus == NULL;
1511 /***********************************************************************
1512 * SYSLINK_GetIdealSize
1513 * Calculates the ideal size of a link control at a given maximum width.
1515 static VOID SYSLINK_GetIdealSize (const SYSLINK_INFO *infoPtr, int cxMaxWidth, LPSIZE lpSize)
1517 RECT rc;
1518 HDC hdc;
1520 rc.left = rc.top = rc.bottom = 0;
1521 rc.right = cxMaxWidth;
1523 hdc = GetDC(infoPtr->Self);
1524 if (hdc != NULL)
1526 HGDIOBJ hOldFont = SelectObject(hdc, infoPtr->Font);
1528 SYSLINK_Render(infoPtr, hdc, &rc);
1530 SelectObject(hdc, hOldFont);
1531 ReleaseDC(infoPtr->Self, hdc);
1533 lpSize->cx = rc.right;
1534 lpSize->cy = rc.bottom;
1538 /***********************************************************************
1539 * SysLinkWindowProc
1541 static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
1542 WPARAM wParam, LPARAM lParam)
1544 SYSLINK_INFO *infoPtr;
1546 TRACE("hwnd=%p msg=%04x wparam=%lx lParam=%lx\n", hwnd, message, wParam, lParam);
1548 infoPtr = (SYSLINK_INFO *)GetWindowLongPtrW(hwnd, 0);
1550 if (!infoPtr && message != WM_CREATE)
1551 goto HandleDefaultMessage;
1553 switch(message) {
1554 case WM_PRINTCLIENT:
1555 case WM_PAINT:
1556 return SYSLINK_Paint (infoPtr, (HDC)wParam);
1558 case WM_SETCURSOR:
1560 LHITTESTINFO ht;
1561 DWORD mp = GetMessagePos();
1563 ht.pt.x = (short)LOWORD(mp);
1564 ht.pt.y = (short)HIWORD(mp);
1566 ScreenToClient(infoPtr->Self, &ht.pt);
1567 if(SYSLINK_HitTest (infoPtr, &ht))
1569 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_HAND));
1570 return TRUE;
1572 /* let the default window proc handle this message */
1573 goto HandleDefaultMessage;
1576 case WM_SIZE:
1578 RECT rcClient;
1579 if (GetClientRect(infoPtr->Self, &rcClient))
1581 HDC hdc = GetDC(infoPtr->Self);
1582 if(hdc != NULL)
1584 SYSLINK_Render(infoPtr, hdc, &rcClient);
1585 ReleaseDC(infoPtr->Self, hdc);
1588 return 0;
1591 case WM_GETFONT:
1592 return (LRESULT)infoPtr->Font;
1594 case WM_SETFONT:
1595 return (LRESULT)SYSLINK_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
1597 case WM_SETTEXT:
1598 SYSLINK_SetText(infoPtr, (LPWSTR)lParam);
1599 goto HandleDefaultMessage;
1601 case WM_LBUTTONDOWN:
1603 POINT pt;
1604 pt.x = (short)LOWORD(lParam);
1605 pt.y = (short)HIWORD(lParam);
1606 return SYSLINK_LButtonDown(infoPtr, wParam, &pt);
1608 case WM_LBUTTONUP:
1610 POINT pt;
1611 pt.x = (short)LOWORD(lParam);
1612 pt.y = (short)HIWORD(lParam);
1613 return SYSLINK_LButtonUp(infoPtr, wParam, &pt);
1616 case WM_KEYDOWN:
1618 switch(wParam)
1620 case VK_RETURN:
1621 SYSLINK_OnEnter(infoPtr);
1622 return 0;
1623 case VK_TAB:
1625 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1626 SYSKEY_SelectNextPrevLink(infoPtr, shift);
1627 return 0;
1630 goto HandleDefaultMessage;
1633 case WM_GETDLGCODE:
1635 LRESULT Ret = DLGC_HASSETSEL;
1636 int vk = (lParam != 0 ? (int)((LPMSG)lParam)->wParam : 0);
1637 switch(vk)
1639 case VK_RETURN:
1640 Ret |= DLGC_WANTMESSAGE;
1641 break;
1642 case VK_TAB:
1644 BOOL shift = GetKeyState(VK_SHIFT) & 0x8000;
1645 if(!SYSLINK_NoNextLink(infoPtr, shift))
1647 Ret |= DLGC_WANTTAB;
1649 else
1651 Ret |= DLGC_WANTCHARS;
1653 break;
1656 return Ret;
1659 case WM_NCHITTEST:
1661 POINT pt;
1662 RECT rc;
1663 pt.x = (short)LOWORD(lParam);
1664 pt.y = (short)HIWORD(lParam);
1666 GetClientRect(infoPtr->Self, &rc);
1667 ScreenToClient(infoPtr->Self, &pt);
1668 if(pt.x < 0 || pt.y < 0 || pt.x > rc.right || pt.y > rc.bottom)
1670 return HTNOWHERE;
1673 if(SYSLINK_LinkAtPt(infoPtr, &pt, NULL, FALSE))
1675 return HTCLIENT;
1678 return HTTRANSPARENT;
1681 case LM_HITTEST:
1682 return SYSLINK_HitTest(infoPtr, (PLHITTESTINFO)lParam);
1684 case LM_SETITEM:
1685 return SYSLINK_SetItem(infoPtr, (PLITEM)lParam);
1687 case LM_GETITEM:
1688 return SYSLINK_GetItem(infoPtr, (PLITEM)lParam);
1690 case LM_GETIDEALHEIGHT:
1691 if (lParam)
1693 /* LM_GETIDEALSIZE */
1694 SYSLINK_GetIdealSize(infoPtr, (int)wParam, (LPSIZE)lParam);
1696 return SYSLINK_GetIdealHeight(infoPtr);
1698 case WM_SETFOCUS:
1699 return SYSLINK_SetFocus(infoPtr, (HWND)wParam);
1701 case WM_KILLFOCUS:
1702 return SYSLINK_KillFocus(infoPtr, (HWND)wParam);
1704 case WM_ENABLE:
1705 infoPtr->Style &= ~WS_DISABLED;
1706 infoPtr->Style |= (wParam ? 0 : WS_DISABLED);
1707 InvalidateRect (infoPtr->Self, NULL, FALSE);
1708 return 0;
1710 case WM_STYLECHANGED:
1711 if (wParam == GWL_STYLE)
1713 infoPtr->Style = ((LPSTYLESTRUCT)lParam)->styleNew;
1715 InvalidateRect(infoPtr->Self, NULL, TRUE);
1717 return 0;
1719 case WM_CREATE:
1720 /* allocate memory for info struct */
1721 infoPtr = Alloc (sizeof(SYSLINK_INFO));
1722 if (!infoPtr) return -1;
1723 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1725 /* initialize the info struct */
1726 infoPtr->Self = hwnd;
1727 infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent;
1728 infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style;
1729 infoPtr->Font = 0;
1730 infoPtr->LinkFont = 0;
1731 infoPtr->Items = NULL;
1732 infoPtr->HasFocus = FALSE;
1733 infoPtr->MouseDownID = -1;
1734 infoPtr->TextColor = GetSysColor(COLOR_WINDOWTEXT);
1735 infoPtr->LinkColor = GetSysColor(COLOR_HIGHLIGHT);
1736 infoPtr->VisitedColor = GetSysColor(COLOR_HIGHLIGHT);
1737 infoPtr->BreakChar = ' ';
1738 TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
1739 SYSLINK_SetText(infoPtr, ((LPCREATESTRUCTW)lParam)->lpszName);
1740 return 0;
1742 case WM_DESTROY:
1743 TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
1744 SYSLINK_ClearDoc(infoPtr);
1745 if(infoPtr->Font != 0) DeleteObject(infoPtr->Font);
1746 if(infoPtr->LinkFont != 0) DeleteObject(infoPtr->LinkFont);
1747 SetWindowLongPtrW(hwnd, 0, 0);
1748 Free (infoPtr);
1749 return 0;
1751 default:
1752 HandleDefaultMessage:
1753 if ((message >= WM_USER) && (message < WM_APP) && !COMCTL32_IsReflectedMessage(message))
1755 ERR("unknown msg %04x wp=%04lx lp=%08lx\n", message, wParam, lParam );
1757 return DefWindowProcW(hwnd, message, wParam, lParam);
1762 /***********************************************************************
1763 * SYSLINK_Register [Internal]
1765 * Registers the SysLink window class.
1767 VOID SYSLINK_Register (void)
1769 WNDCLASSW wndClass;
1771 ZeroMemory (&wndClass, sizeof(wndClass));
1772 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
1773 wndClass.lpfnWndProc = SysLinkWindowProc;
1774 wndClass.cbClsExtra = 0;
1775 wndClass.cbWndExtra = sizeof (SYSLINK_INFO *);
1776 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1777 wndClass.lpszClassName = WC_LINK;
1779 RegisterClassW (&wndClass);
1783 /***********************************************************************
1784 * SYSLINK_Unregister [Internal]
1786 * Unregisters the SysLink window class.
1788 VOID SYSLINK_Unregister (void)
1790 UnregisterClassW (WC_LINK, NULL);