Commit 986306cd authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

comctl32/syslink: Use wine list to keep items.

parent f4640b04
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "comctl32.h" #include "comctl32.h"
#include "wine/unicode.h" #include "wine/unicode.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/list.h"
WINE_DEFAULT_DEBUG_CHANNEL(syslink); WINE_DEFAULT_DEBUG_CHANNEL(syslink);
...@@ -61,7 +62,7 @@ typedef enum ...@@ -61,7 +62,7 @@ typedef enum
typedef struct _DOC_ITEM typedef struct _DOC_ITEM
{ {
struct _DOC_ITEM *Next; /* Address to the next item */ struct list entry;
UINT nText; /* Number of characters of the text */ UINT nText; /* Number of characters of the text */
SL_ITEM_TYPE Type; /* type of the item */ SL_ITEM_TYPE Type; /* type of the item */
PDOC_TEXTBLOCK Blocks; /* Array of text blocks */ PDOC_TEXTBLOCK Blocks; /* Array of text blocks */
...@@ -86,7 +87,7 @@ typedef struct ...@@ -86,7 +87,7 @@ typedef struct
HWND Self; /* The window handle for this control */ HWND Self; /* The window handle for this control */
HWND Notify; /* The parent handle to receive notifications */ HWND Notify; /* The parent handle to receive notifications */
DWORD Style; /* Styles for this control */ DWORD Style; /* Styles for this control */
PDOC_ITEM Items; /* Address to the first document item */ struct list Items; /* Document items list */
BOOL HasFocus; /* Whether the control has the input focus */ BOOL HasFocus; /* Whether the control has the input focus */
int MouseDownID; /* ID of the link that the mouse button first selected */ int MouseDownID; /* ID of the link that the mouse button first selected */
HFONT Font; /* Handle to the font for text */ HFONT Font; /* Handle to the font for text */
...@@ -147,22 +148,15 @@ static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UIN ...@@ -147,22 +148,15 @@ static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UIN
return NULL; return NULL;
} }
Item->Next = NULL;
Item->nText = textlen; Item->nText = textlen;
Item->Type = type; Item->Type = type;
Item->Blocks = NULL; Item->Blocks = NULL;
if(LastItem != NULL)
{
LastItem->Next = Item;
}
else
{
infoPtr->Items = Item;
}
lstrcpynW(Item->Text, Text, textlen + 1); lstrcpynW(Item->Text, Text, textlen + 1);
if (LastItem)
list_add_after(&LastItem->entry, &Item->entry);
else
list_add_tail(&infoPtr->Items, &Item->entry);
return Item; return Item;
} }
...@@ -172,17 +166,13 @@ static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UIN ...@@ -172,17 +166,13 @@ static PDOC_ITEM SYSLINK_AppendDocItem (SYSLINK_INFO *infoPtr, LPCWSTR Text, UIN
*/ */
static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr) static VOID SYSLINK_ClearDoc (SYSLINK_INFO *infoPtr)
{ {
PDOC_ITEM Item, Next; DOC_ITEM *Item, *Item2;
Item = infoPtr->Items; LIST_FOR_EACH_ENTRY_SAFE(Item, Item2, &infoPtr->Items, DOC_ITEM, entry)
while(Item != NULL)
{ {
Next = Item->Next; list_remove(&Item->entry);
SYSLINK_FreeDocItem(Item); SYSLINK_FreeDocItem(Item);
Item = Next;
} }
infoPtr->Items = NULL;
} }
/*********************************************************************** /***********************************************************************
...@@ -526,15 +516,12 @@ static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *Do ...@@ -526,15 +516,12 @@ static VOID SYSLINK_RepaintLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *Do
*/ */
static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink) static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iLink)
{ {
PDOC_ITEM Current = infoPtr->Items; DOC_ITEM *Current;
while(Current != NULL) LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
{ {
if((Current->Type == slLink) && (iLink-- <= 0)) if ((Current->Type == slLink) && (iLink-- <= 0))
{
return Current; return Current;
}
Current = Current->Next;
} }
return NULL; return NULL;
} }
...@@ -545,10 +532,10 @@ static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iL ...@@ -545,10 +532,10 @@ static PDOC_ITEM SYSLINK_GetLinkItemByIndex (const SYSLINK_INFO *infoPtr, int iL
*/ */
static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId) static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
{ {
PDOC_ITEM Current = infoPtr->Items; DOC_ITEM *Current;
int id = 0; int id = 0;
while(Current != NULL) LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
{ {
if(Current->Type == slLink) if(Current->Type == slLink)
{ {
...@@ -560,8 +547,8 @@ static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId) ...@@ -560,8 +547,8 @@ static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
} }
id++; id++;
} }
Current = Current->Next;
} }
return NULL; return NULL;
} }
...@@ -571,13 +558,13 @@ static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId) ...@@ -571,13 +558,13 @@ static PDOC_ITEM SYSLINK_GetFocusLink (const SYSLINK_INFO *infoPtr, int *LinkId)
*/ */
static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current) static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
{ {
for(Current = (Current != NULL ? Current->Next : infoPtr->Items); DOC_ITEM *Next;
Current != NULL;
Current = Current->Next) LIST_FOR_EACH_ENTRY(Next, Current ? &Current->entry : &infoPtr->Items, DOC_ITEM, entry)
{ {
if(Current->Type == slLink) if (Next->Type == slLink)
{ {
return Current; return Next;
} }
} }
return NULL; return NULL;
...@@ -589,38 +576,17 @@ static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Cur ...@@ -589,38 +576,17 @@ static PDOC_ITEM SYSLINK_GetNextLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Cur
*/ */
static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current) static PDOC_ITEM SYSLINK_GetPrevLink (const SYSLINK_INFO *infoPtr, PDOC_ITEM Current)
{ {
if(Current == NULL) DOC_ITEM *Prev;
{
/* returns the last link */ LIST_FOR_EACH_ENTRY_REV(Prev, Current ? &Current->entry : list_tail(&infoPtr->Items), DOC_ITEM, entry)
PDOC_ITEM Last = NULL;
for(Current = infoPtr->Items; Current != NULL; Current = Current->Next)
{
if(Current->Type == slLink)
{
Last = Current;
}
}
return Last;
}
else
{ {
/* returns the previous link */ if (Prev->Type == slLink)
PDOC_ITEM Cur, Prev = NULL;
for(Cur = infoPtr->Items; Cur != NULL; Cur = Cur->Next)
{ {
if(Cur == Current) return Prev;
{
break;
}
if(Cur->Type == slLink)
{
Prev = Cur;
}
} }
return Prev;
} }
return NULL;
} }
/*********************************************************************** /***********************************************************************
...@@ -684,7 +650,7 @@ static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect) ...@@ -684,7 +650,7 @@ static VOID SYSLINK_Render (const SYSLINK_INFO *infoPtr, HDC hdc, PRECT pRect)
GetTextMetricsW( hdc, &tm ); GetTextMetricsW( hdc, &tm );
LineHeight = tm.tmHeight + tm.tmExternalLeading; LineHeight = tm.tmHeight + tm.tmExternalLeading;
for(Current = infoPtr->Items; Current != NULL; Current = Current->Next) LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
{ {
int n, nBlocks; int n, nBlocks;
LPWSTR tx; LPWSTR tx;
...@@ -861,7 +827,7 @@ static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc) ...@@ -861,7 +827,7 @@ static LRESULT SYSLINK_Draw (const SYSLINK_INFO *infoPtr, HDC hdc)
DeleteObject(hBrush); DeleteObject(hBrush);
for(Current = infoPtr->Items; Current != NULL; Current = Current->Next) LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
{ {
int n; int n;
LPWSTR tx; LPWSTR tx;
...@@ -1025,8 +991,8 @@ static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text) ...@@ -1025,8 +991,8 @@ static LRESULT SYSLINK_SetText (SYSLINK_INFO *infoPtr, LPCWSTR Text)
static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem) static PDOC_ITEM SYSLINK_SetFocusLink (const SYSLINK_INFO *infoPtr, const DOC_ITEM *DocItem)
{ {
PDOC_ITEM Current, PrevFocus = NULL; PDOC_ITEM Current, PrevFocus = NULL;
for(Current = infoPtr->Items; Current != NULL; Current = Current->Next) LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
{ {
if(Current->Type == slLink) if(Current->Type == slLink)
{ {
...@@ -1234,7 +1200,7 @@ static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTe ...@@ -1234,7 +1200,7 @@ static LRESULT SYSLINK_HitTest (const SYSLINK_INFO *infoPtr, PLHITTESTINFO HitTe
PDOC_ITEM Current; PDOC_ITEM Current;
int id = 0; int id = 0;
for(Current = infoPtr->Items; Current != NULL; Current = Current->Next) LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
{ {
if(Current->Type == slLink) if(Current->Type == slLink)
{ {
...@@ -1383,7 +1349,7 @@ static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt, ...@@ -1383,7 +1349,7 @@ static PDOC_ITEM SYSLINK_LinkAtPt (const SYSLINK_INFO *infoPtr, const POINT *pt,
PDOC_ITEM Current; PDOC_ITEM Current;
int id = 0; int id = 0;
for(Current = infoPtr->Items; Current != NULL; Current = Current->Next) LIST_FOR_EACH_ENTRY(Current, &infoPtr->Items, DOC_ITEM, entry)
{ {
if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) && if((Current->Type == slLink) && SYSLINK_PtInDocItem(Current, *pt) &&
(!MustBeEnabled || (Current->u.Link.state & LIS_ENABLED))) (!MustBeEnabled || (Current->u.Link.state & LIS_ENABLED)))
...@@ -1749,6 +1715,9 @@ static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message, ...@@ -1749,6 +1715,9 @@ static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
return 0; return 0;
case WM_CREATE: case WM_CREATE:
{
CREATESTRUCTW *cs = (CREATESTRUCTW*)lParam;
/* allocate memory for info struct */ /* allocate memory for info struct */
infoPtr = Alloc (sizeof(SYSLINK_INFO)); infoPtr = Alloc (sizeof(SYSLINK_INFO));
if (!infoPtr) return -1; if (!infoPtr) return -1;
...@@ -1756,11 +1725,11 @@ static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message, ...@@ -1756,11 +1725,11 @@ static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
/* initialize the info struct */ /* initialize the info struct */
infoPtr->Self = hwnd; infoPtr->Self = hwnd;
infoPtr->Notify = ((LPCREATESTRUCTW)lParam)->hwndParent; infoPtr->Notify = cs->hwndParent;
infoPtr->Style = ((LPCREATESTRUCTW)lParam)->style; infoPtr->Style = cs->style;
infoPtr->Font = 0; infoPtr->Font = 0;
infoPtr->LinkFont = 0; infoPtr->LinkFont = 0;
infoPtr->Items = NULL; list_init(&infoPtr->Items);
infoPtr->HasFocus = FALSE; infoPtr->HasFocus = FALSE;
infoPtr->MouseDownID = -1; infoPtr->MouseDownID = -1;
infoPtr->TextColor = comctl32_color.clrWindowText; infoPtr->TextColor = comctl32_color.clrWindowText;
...@@ -1769,9 +1738,9 @@ static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message, ...@@ -1769,9 +1738,9 @@ static LRESULT WINAPI SysLinkWindowProc(HWND hwnd, UINT message,
infoPtr->BreakChar = ' '; infoPtr->BreakChar = ' ';
infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN; infoPtr->IgnoreReturn = infoPtr->Style & LWS_IGNORERETURN;
TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd); TRACE("SysLink Ctrl creation, hwnd=%p\n", hwnd);
SYSLINK_SetText(infoPtr, ((LPCREATESTRUCTW)lParam)->lpszName); SYSLINK_SetText(infoPtr, cs->lpszName);
return 0; return 0;
}
case WM_DESTROY: case WM_DESTROY:
TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd); TRACE("SysLink Ctrl destruction, hwnd=%p\n", hwnd);
SYSLINK_ClearDoc(infoPtr); SYSLINK_ClearDoc(infoPtr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment