| 1 | /* $Id: treeview.cpp,v 1.9 2000-04-15 14:22:31 cbratschi Exp $ */
|
|---|
| 2 | /* Treeview control
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
|
|---|
| 5 | * Copyright 1998,1999 Alex Priem <alexp@sci.kun.nl>
|
|---|
| 6 | * Copyright 1999 Sylvain St-Germain
|
|---|
| 7 | * Copyright 1999 Achim Hasenmueller
|
|---|
| 8 | * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
|
|---|
| 9 | *
|
|---|
| 10 | *
|
|---|
| 11 | * TODO:
|
|---|
| 12 | * Using DPA to store the item ptr would be good.
|
|---|
| 13 | * -check custom draw
|
|---|
| 14 | * use separate routine to get item text/image.
|
|---|
| 15 | *
|
|---|
| 16 | * FIXMEs (for personal use)
|
|---|
| 17 | Expand: -ctlmacro expands twice ->toggle.
|
|---|
| 18 | -DblClick: ctlmacro.exe's NM_DBLCLK seems to go wrong (returns FALSE).
|
|---|
| 19 | -treehelper: stack corruption makes big window.
|
|---|
| 20 | *
|
|---|
| 21 | * Status: complete (many things untested)
|
|---|
| 22 | * Version: 5.80
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 | /*
|
|---|
| 26 | Most identical with:
|
|---|
| 27 | - Corel 20000212 level
|
|---|
| 28 | - (WINE 991212 level)
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | /* CB: todo/bugs
|
|---|
| 32 | - startup: missing WM_SIZE messages -> i.e. wrong info tip calculation
|
|---|
| 33 | - bug in SetScrollInfo/ShowScrollBar: WM_SIZE and WM_NCPAINT problems (i.e. RegEdit)
|
|---|
| 34 | - VK_LEFT in WinHlp32 displays expanded icon
|
|---|
| 35 | - expand not finished
|
|---|
| 36 | - WM_ENABLE: draw disabled control
|
|---|
| 37 | */
|
|---|
| 38 |
|
|---|
| 39 | #include <stdlib.h>
|
|---|
| 40 | #include <string.h>
|
|---|
| 41 | #include <math.h>
|
|---|
| 42 | #include "winbase.h"
|
|---|
| 43 | #include "wingdi.h"
|
|---|
| 44 | #include "winnls.h"
|
|---|
| 45 | #include "commctrl.h"
|
|---|
| 46 | #include "comctl32.h"
|
|---|
| 47 | #include "ccbase.h"
|
|---|
| 48 | #include "treeview.h"
|
|---|
| 49 |
|
|---|
| 50 | /* ffs should be in <string.h>. */
|
|---|
| 51 |
|
|---|
| 52 | //#define OS2LINEHACK //CB: too slow, but looks good
|
|---|
| 53 |
|
|---|
| 54 | /* Defines, since they do not need to return previous state, and nr
|
|---|
| 55 | * has no side effects in this file.
|
|---|
| 56 | */
|
|---|
| 57 | #define tv_test_bit(nr,bf) (((LPBYTE)bf)[nr>>3]&(1<<(nr&7)))
|
|---|
| 58 | #define tv_set_bit(nr,bf) ((LPBYTE)bf)[nr>>3]|=(1<<(nr&7))
|
|---|
| 59 | #define tv_clear_bit(nr,bf) ((LPBYTE)bf)[nr>>3]&=~(1<<(nr&7))
|
|---|
| 60 |
|
|---|
| 61 | #define TREEVIEW_GetInfoPtr(hwnd) ((TREEVIEW_INFO *)getInfoPtr(hwnd))
|
|---|
| 62 |
|
|---|
| 63 | static BOOL TREEVIEW_SendTreeviewNotify (HWND hwnd, UINT code, UINT action, HTREEITEM oldItem, HTREEITEM newItem);
|
|---|
| 64 | static BOOL TREEVIEW_SendTreeviewDnDNotify (HWND hwnd, UINT code, HTREEITEM dragItem, POINT pt);
|
|---|
| 65 | static INT TREEVIEW_CallbackChildren(HWND hwnd,TREEVIEW_ITEM *wineItem);
|
|---|
| 66 | static INT TREEVIEW_CallbackImage(HWND hwnd,TREEVIEW_ITEM *wineItem);
|
|---|
| 67 | static INT TREEVIEW_CallbackSelectedImage(HWND hwnd,TREEVIEW_ITEM *wineItem);
|
|---|
| 68 | static WCHAR* TREEVIEW_CallbackText(HWND hwnd,TREEVIEW_ITEM *wineItem,BOOL *mustFree);
|
|---|
| 69 | static BOOL TREEVIEW_SendCustomDrawNotify (HWND hwnd, DWORD dwDrawStage, HDC hdc, RECT rc);
|
|---|
| 70 | static BOOL TREEVIEW_SendCustomDrawItemNotify (HWND hwnd, HDC hdc, TREEVIEW_ITEM *tvItem, UINT uItemDrawState);
|
|---|
| 71 | static LRESULT TREEVIEW_RButtonUp (HWND hwnd, LPPOINT pPt);
|
|---|
| 72 | static LRESULT TREEVIEW_SelectItem (HWND hwnd, WPARAM wParam, LPARAM lParam);
|
|---|
| 73 | static LRESULT TREEVIEW_DoSelectItem(HWND hwnd,INT action,HTREEITEM newSelect,INT cause);
|
|---|
| 74 | static void TREEVIEW_Refresh(HWND hwnd);
|
|---|
| 75 | static void TREEVIEW_RefreshItem(HWND hwnd,TREEVIEW_ITEM *item,BOOL wholeLine);
|
|---|
| 76 | static void TREEVIEW_Draw(HWND hwnd,HDC hdc,RECT *updateRect);
|
|---|
| 77 | static BOOL TREEVIEW_UnqueueRefresh(HWND hwnd,BOOL calc,BOOL refresh);
|
|---|
| 78 | static void TREEVIEW_QueueRefresh(HWND hwnd);
|
|---|
| 79 | static void TREEVIEW_CalcItem(HWND hwnd,HDC hdc,DWORD dwStyle,TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item);
|
|---|
| 80 | static BOOL TREEVIEW_CalcItems(HWND hwnd,HDC hdc,TREEVIEW_INFO *infoPtr);
|
|---|
| 81 | static LRESULT TREEVIEW_EnsureVisible(HWND hwnd,HTREEITEM hItem);
|
|---|
| 82 | static VOID TREEVIEW_ISearch(HWND hwnd,CHAR ch);
|
|---|
| 83 | static VOID TREEVIEW_CheckInfoTip(HWND hwnd);
|
|---|
| 84 | static VOID TREEVIEW_HideInfoTip(HWND hwnd,TREEVIEW_INFO *infoPtr);
|
|---|
| 85 |
|
|---|
| 86 | static LRESULT CALLBACK TREEVIEW_Edit_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|---|
| 87 |
|
|---|
| 88 | LRESULT WINAPI TREEVIEW_EndEditLabelNow (HWND hwnd, BOOL bCancel);
|
|---|
| 89 |
|
|---|
| 90 | HWND TREEVIEW_EditLabel(HWND hwnd, HTREEITEM hItem,BOOL unicode);
|
|---|
| 91 |
|
|---|
| 92 | /* helper functions. Work with the assumption that validity of operands
|
|---|
| 93 | is checked beforehand, and that tree state is valid. */
|
|---|
| 94 |
|
|---|
| 95 | /* FIXME: MS documentation says `GetNextVisibleItem' returns NULL
|
|---|
| 96 | if not succesfull'. Probably only applies to derefencing infoPtr
|
|---|
| 97 | (ie we are offered a valid treeview structure)
|
|---|
| 98 | and not whether there is a next `visible' child.
|
|---|
| 99 | FIXME: check other failures.
|
|---|
| 100 | */
|
|---|
| 101 |
|
|---|
| 102 | /***************************************************************************
|
|---|
| 103 | * This method returns the TREEVIEW_ITEM object given the handle
|
|---|
| 104 | */
|
|---|
| 105 | static TREEVIEW_ITEM* TREEVIEW_ValidItem(
|
|---|
| 106 | TREEVIEW_INFO *infoPtr,
|
|---|
| 107 | HTREEITEM handle)
|
|---|
| 108 | {
|
|---|
| 109 | if ((!handle) || (handle>infoPtr->uMaxHandle))
|
|---|
| 110 | return NULL;
|
|---|
| 111 |
|
|---|
| 112 | if (tv_test_bit ((INT)handle, infoPtr->freeList))
|
|---|
| 113 | return NULL;
|
|---|
| 114 |
|
|---|
| 115 | return &infoPtr->items[(INT)handle];
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /***************************************************************************
|
|---|
| 119 | * This function uses cChildren field to decide whether item has children
|
|---|
| 120 | * or not.
|
|---|
| 121 | * Note: return value doesn't reflect physical presence of children.
|
|---|
| 122 | */
|
|---|
| 123 | static INT TREEVIEW_HasChildren(
|
|---|
| 124 | HWND hwnd,
|
|---|
| 125 | TREEVIEW_ITEM *wineItem)
|
|---|
| 126 | {
|
|---|
| 127 | INT cChildren = 0;
|
|---|
| 128 |
|
|---|
| 129 | if ( wineItem->mask & TVIF_CHILDREN )
|
|---|
| 130 | {
|
|---|
| 131 | if (wineItem->cChildren == I_CHILDRENCALLBACK)
|
|---|
| 132 | cChildren = TREEVIEW_CallbackChildren(hwnd,wineItem);
|
|---|
| 133 | else
|
|---|
| 134 | cChildren = wineItem->cChildren;
|
|---|
| 135 | }
|
|---|
| 136 | else if ( wineItem->firstChild )
|
|---|
| 137 | cChildren = 1;
|
|---|
| 138 |
|
|---|
| 139 | return cChildren;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /***************************************************************************
|
|---|
| 143 | * This method returns the last expanded child item of a tree node
|
|---|
| 144 | */
|
|---|
| 145 | static TREEVIEW_ITEM *TREEVIEW_GetLastListItem(
|
|---|
| 146 | HWND hwnd,
|
|---|
| 147 | TREEVIEW_INFO *infoPtr,
|
|---|
| 148 | TREEVIEW_ITEM *tvItem)
|
|---|
| 149 | {
|
|---|
| 150 | TREEVIEW_ITEM *wineItem = tvItem;
|
|---|
| 151 |
|
|---|
| 152 | /*
|
|---|
| 153 | * Get this item last sibling
|
|---|
| 154 | */
|
|---|
| 155 | while (wineItem->sibling)
|
|---|
| 156 | wineItem=& infoPtr->items [(INT)wineItem->sibling];
|
|---|
| 157 |
|
|---|
| 158 | /*
|
|---|
| 159 | * If the last sibling has expanded children, restart.
|
|---|
| 160 | */
|
|---|
| 161 | if ((wineItem->state & TVIS_EXPANDED) &&
|
|---|
| 162 | TREEVIEW_HasChildren(hwnd, wineItem))
|
|---|
| 163 | {
|
|---|
| 164 | return TREEVIEW_GetLastListItem(
|
|---|
| 165 | hwnd,
|
|---|
| 166 | infoPtr,
|
|---|
| 167 | &(infoPtr->items[(INT)wineItem->firstChild]));
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | return wineItem;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | /***************************************************************************
|
|---|
| 174 | * This method returns the previous physical item in the list not
|
|---|
| 175 | * considering the tree hierarchy.
|
|---|
| 176 | */
|
|---|
| 177 | static TREEVIEW_ITEM *TREEVIEW_GetPrevListItem(
|
|---|
| 178 | HWND hwnd,
|
|---|
| 179 | TREEVIEW_INFO *infoPtr,
|
|---|
| 180 | TREEVIEW_ITEM *tvItem)
|
|---|
| 181 | {
|
|---|
| 182 | if (tvItem->upsibling)
|
|---|
| 183 | {
|
|---|
| 184 | /*
|
|---|
| 185 | * This item has a upsibling, get the last item. Since, GetLastListItem
|
|---|
| 186 | * first looks at siblings, we must feed it with the first child.
|
|---|
| 187 | */
|
|---|
| 188 | TREEVIEW_ITEM *upItem = &infoPtr->items[(INT)tvItem->upsibling];
|
|---|
| 189 |
|
|---|
| 190 | if ( (upItem->state & TVIS_EXPANDED) &&
|
|---|
| 191 | TREEVIEW_HasChildren(hwnd, upItem) )
|
|---|
| 192 | {
|
|---|
| 193 | return TREEVIEW_GetLastListItem(
|
|---|
| 194 | hwnd,
|
|---|
| 195 | infoPtr,
|
|---|
| 196 | &infoPtr->items[(INT)upItem->firstChild]);
|
|---|
| 197 | }
|
|---|
| 198 | else
|
|---|
| 199 | return upItem;
|
|---|
| 200 | }
|
|---|
| 201 | else
|
|---|
| 202 | {
|
|---|
| 203 | /*
|
|---|
| 204 | * this item does not have a upsibling, get the parent
|
|---|
| 205 | */
|
|---|
| 206 | if (tvItem->parent)
|
|---|
| 207 | return &infoPtr->items[(INT)tvItem->parent];
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | return NULL;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 | /***************************************************************************
|
|---|
| 215 | * This method returns the next physical item in the treeview not
|
|---|
| 216 | * considering the tree hierarchy.
|
|---|
| 217 | */
|
|---|
| 218 | static TREEVIEW_ITEM *TREEVIEW_GetNextListItem(
|
|---|
| 219 | HWND hwnd,
|
|---|
| 220 | TREEVIEW_INFO *infoPtr,
|
|---|
| 221 | TREEVIEW_ITEM *tvItem)
|
|---|
| 222 | {
|
|---|
| 223 | TREEVIEW_ITEM *wineItem = NULL;
|
|---|
| 224 |
|
|---|
| 225 | /*
|
|---|
| 226 | * If this item has children and is expanded, return the first child
|
|---|
| 227 | */
|
|---|
| 228 | if ( (tvItem->state & TVIS_EXPANDED) &&
|
|---|
| 229 | TREEVIEW_HasChildren(hwnd, tvItem) )
|
|---|
| 230 | {
|
|---|
| 231 | return (& infoPtr->items[(INT)tvItem->firstChild]);
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 | /*
|
|---|
| 236 | * try to get the sibling
|
|---|
| 237 | */
|
|---|
| 238 | if (tvItem->sibling)
|
|---|
| 239 | return (& infoPtr->items[(INT)tvItem->sibling]);
|
|---|
| 240 |
|
|---|
| 241 | /*
|
|---|
| 242 | * Otherwise, get the parent's sibling.
|
|---|
| 243 | */
|
|---|
| 244 | wineItem=tvItem;
|
|---|
| 245 | while (wineItem->parent) {
|
|---|
| 246 | wineItem=& infoPtr->items [(INT)wineItem->parent];
|
|---|
| 247 | if (wineItem->sibling)
|
|---|
| 248 | return (& infoPtr->items [(INT)wineItem->sibling]);
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | return NULL;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | /***************************************************************************
|
|---|
| 255 | * This method returns the nth item starting at the given item. It returns
|
|---|
| 256 | * the last item (or first) we we run out of items.
|
|---|
| 257 | *
|
|---|
| 258 | * Will scroll backward if count is <0.
|
|---|
| 259 | * forward if count is >0.
|
|---|
| 260 | */
|
|---|
| 261 | static TREEVIEW_ITEM *TREEVIEW_GetListItem(
|
|---|
| 262 | HWND hwnd,
|
|---|
| 263 | TREEVIEW_INFO *infoPtr,
|
|---|
| 264 | TREEVIEW_ITEM *tvItem,
|
|---|
| 265 | LONG count)
|
|---|
| 266 | {
|
|---|
| 267 | TREEVIEW_ITEM *previousItem = NULL;
|
|---|
| 268 | TREEVIEW_ITEM *wineItem = tvItem;
|
|---|
| 269 | LONG iter = 0;
|
|---|
| 270 |
|
|---|
| 271 | if (count > 0)
|
|---|
| 272 | {
|
|---|
| 273 | /* Find count item downward */
|
|---|
| 274 | while ((iter++ < count) && (wineItem != NULL))
|
|---|
| 275 | {
|
|---|
| 276 | /* Keep a pointer to the previous in case we ask for more than we got */
|
|---|
| 277 | previousItem = wineItem;
|
|---|
| 278 | wineItem = TREEVIEW_GetNextListItem(hwnd,infoPtr,wineItem);
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | if (wineItem == NULL)
|
|---|
| 282 | wineItem = previousItem;
|
|---|
| 283 | }
|
|---|
| 284 | else if (count < 0)
|
|---|
| 285 | {
|
|---|
| 286 | /* Find count item upward */
|
|---|
| 287 | while ((iter-- > count) && (wineItem != NULL))
|
|---|
| 288 | {
|
|---|
| 289 | /* Keep a pointer to the previous in case we ask for more than we got */
|
|---|
| 290 | previousItem = wineItem;
|
|---|
| 291 | wineItem = TREEVIEW_GetPrevListItem(hwnd,infoPtr,wineItem);
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | if (wineItem == NULL)
|
|---|
| 295 | wineItem = previousItem;
|
|---|
| 296 | }
|
|---|
| 297 | else
|
|---|
| 298 | wineItem = NULL;
|
|---|
| 299 |
|
|---|
| 300 | return wineItem;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 | /***************************************************************************
|
|---|
| 305 | * This method
|
|---|
| 306 | */
|
|---|
| 307 | static void TREEVIEW_RemoveAllChildren(
|
|---|
| 308 | HWND hwnd,
|
|---|
| 309 | TREEVIEW_ITEM *parentItem)
|
|---|
| 310 | {
|
|---|
| 311 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 312 | TREEVIEW_ITEM *killItem;
|
|---|
| 313 | INT kill;
|
|---|
| 314 |
|
|---|
| 315 | kill=(INT)parentItem->firstChild;
|
|---|
| 316 | while (kill)
|
|---|
| 317 | {
|
|---|
| 318 | tv_set_bit ( kill, infoPtr->freeList);
|
|---|
| 319 | infoPtr->uNumItems--;
|
|---|
| 320 | killItem=& infoPtr->items[kill];
|
|---|
| 321 | if (killItem->pszText != LPSTR_TEXTCALLBACKW)
|
|---|
| 322 | COMCTL32_Free (killItem->pszText);
|
|---|
| 323 | killItem->pszText = NULL;
|
|---|
| 324 | TREEVIEW_SendTreeviewNotify (hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_DELETEITEMW:TVN_DELETEITEMA, 0, (HTREEITEM)kill, 0);
|
|---|
| 325 | if (killItem->firstChild)
|
|---|
| 326 | TREEVIEW_RemoveAllChildren (hwnd, killItem);
|
|---|
| 327 | kill=(INT)killItem->sibling;
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | parentItem->firstChild = 0;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 | static void
|
|---|
| 335 | TREEVIEW_RemoveItem (HWND hwnd, TREEVIEW_ITEM *wineItem)
|
|---|
| 336 |
|
|---|
| 337 | {
|
|---|
| 338 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 339 | TREEVIEW_ITEM *parentItem, *upsiblingItem, *siblingItem;
|
|---|
| 340 | INT iItem;
|
|---|
| 341 |
|
|---|
| 342 | if (infoPtr->hwndEdit) SetFocus(hwnd);
|
|---|
| 343 |
|
|---|
| 344 | iItem=(INT)wineItem->hItem;
|
|---|
| 345 | tv_set_bit(iItem,infoPtr->freeList);
|
|---|
| 346 | infoPtr->uNumItems--;
|
|---|
| 347 | parentItem=NULL;
|
|---|
| 348 | if (wineItem->pszText != LPSTR_TEXTCALLBACKW)
|
|---|
| 349 | COMCTL32_Free (wineItem->pszText);
|
|---|
| 350 | wineItem->pszText = NULL;
|
|---|
| 351 |
|
|---|
| 352 | TREEVIEW_SendTreeviewNotify (hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_DELETEITEMW:TVN_DELETEITEMA, 0, (HTREEITEM)iItem, 0);
|
|---|
| 353 |
|
|---|
| 354 | if (wineItem->firstChild)
|
|---|
| 355 | TREEVIEW_RemoveAllChildren (hwnd,wineItem);
|
|---|
| 356 |
|
|---|
| 357 | if (wineItem->parent) {
|
|---|
| 358 | parentItem=& infoPtr->items [(INT)wineItem->parent];
|
|---|
| 359 | if ((INT)parentItem->firstChild==iItem)
|
|---|
| 360 | parentItem->firstChild=wineItem->sibling;
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | if (iItem==(INT)infoPtr->TopRootItem)
|
|---|
| 364 | infoPtr->TopRootItem=(HTREEITEM)wineItem->sibling;
|
|---|
| 365 | if (wineItem->upsibling) {
|
|---|
| 366 | upsiblingItem=& infoPtr->items [(INT)wineItem->upsibling];
|
|---|
| 367 | upsiblingItem->sibling=wineItem->sibling;
|
|---|
| 368 | }
|
|---|
| 369 | if (wineItem->sibling) {
|
|---|
| 370 | siblingItem=& infoPtr->items [(INT)wineItem->sibling];
|
|---|
| 371 | siblingItem->upsibling=wineItem->upsibling;
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | if (iItem==(INT)infoPtr->selectedItem) {
|
|---|
| 375 | if (!wineItem->upsibling)
|
|---|
| 376 | infoPtr->selectedItem = 0;
|
|---|
| 377 | else
|
|---|
| 378 | TREEVIEW_DoSelectItem(hwnd, TVGN_CARET, wineItem->upsibling, TVC_UNKNOWN);
|
|---|
| 379 | }
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | /* Note:TREEVIEW_RemoveTree doesn't remove infoPtr itself */
|
|---|
| 383 |
|
|---|
| 384 | static void TREEVIEW_RemoveTree (HWND hwnd)
|
|---|
| 385 | {
|
|---|
| 386 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 387 | TREEVIEW_ITEM *killItem;
|
|---|
| 388 | int i;
|
|---|
| 389 |
|
|---|
| 390 | TREEVIEW_EndEditLabelNow(hwnd,TRUE);
|
|---|
| 391 |
|
|---|
| 392 | for (i=1; i<=(INT)infoPtr->uMaxHandle; i++)
|
|---|
| 393 | if (!tv_test_bit (i, infoPtr->freeList)) {
|
|---|
| 394 | killItem=& infoPtr->items [i];
|
|---|
| 395 | if (killItem->pszText != LPSTR_TEXTCALLBACKW)
|
|---|
| 396 | COMCTL32_Free (killItem->pszText);
|
|---|
| 397 | killItem->pszText = NULL;
|
|---|
| 398 |
|
|---|
| 399 | TREEVIEW_SendTreeviewNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_DELETEITEMW:TVN_DELETEITEMA, 0, killItem->hItem, 0);
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | if (infoPtr->uNumPtrsAlloced) {
|
|---|
| 403 | COMCTL32_Free (infoPtr->items);
|
|---|
| 404 | COMCTL32_Free (infoPtr->freeList);
|
|---|
| 405 | infoPtr->uNumItems=0;
|
|---|
| 406 | infoPtr->uNumPtrsAlloced=0;
|
|---|
| 407 | infoPtr->uMaxHandle=0;
|
|---|
| 408 | infoPtr->lefttop.x = infoPtr->lefttop.y = 0;
|
|---|
| 409 | }
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 | static LRESULT
|
|---|
| 414 | TREEVIEW_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 415 | {
|
|---|
| 416 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 417 |
|
|---|
| 418 | if ((INT)wParam == TVSIL_NORMAL)
|
|---|
| 419 | return (LRESULT) infoPtr->himlNormal;
|
|---|
| 420 | if ((INT)wParam == TVSIL_STATE)
|
|---|
| 421 | return (LRESULT) infoPtr->himlState;
|
|---|
| 422 |
|
|---|
| 423 | return 0;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | static LRESULT
|
|---|
| 427 | TREEVIEW_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 428 | {
|
|---|
| 429 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 430 | HIMAGELIST himlTemp;
|
|---|
| 431 |
|
|---|
| 432 | switch ((INT)wParam) {
|
|---|
| 433 | case TVSIL_NORMAL:
|
|---|
| 434 | himlTemp = infoPtr->himlNormal;
|
|---|
| 435 | infoPtr->himlNormal = (HIMAGELIST)lParam;
|
|---|
| 436 | return (LRESULT)himlTemp;
|
|---|
| 437 |
|
|---|
| 438 | case TVSIL_STATE:
|
|---|
| 439 | himlTemp = infoPtr->himlState;
|
|---|
| 440 | infoPtr->himlState = (HIMAGELIST)lParam;
|
|---|
| 441 | return (LRESULT)himlTemp;
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | return (LRESULT)NULL;
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 | static LRESULT
|
|---|
| 450 | TREEVIEW_SetItemHeight (HWND hwnd, WPARAM wParam)
|
|---|
| 451 | {
|
|---|
| 452 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 453 | INT cx,cy,prevHeight = infoPtr->uItemHeight;
|
|---|
| 454 |
|
|---|
| 455 | if (wParam == -1)
|
|---|
| 456 | {
|
|---|
| 457 | infoPtr->uItemHeight = -1;
|
|---|
| 458 |
|
|---|
| 459 | return prevHeight;
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | ImageList_GetIconSize (infoPtr->himlNormal, &cx, &cy);
|
|---|
| 463 |
|
|---|
| 464 | if (wParam > cy) cy = wParam;
|
|---|
| 465 | infoPtr->uItemHeight = cy;
|
|---|
| 466 |
|
|---|
| 467 | if (!(GetWindowLongA(hwnd, GWL_STYLE) & TVS_NONEVENHEIGHT))
|
|---|
| 468 | if (infoPtr->uItemHeight & 0x1) infoPtr->uItemHeight++;
|
|---|
| 469 |
|
|---|
| 470 | if (prevHeight != infoPtr->uItemHeight)
|
|---|
| 471 | {
|
|---|
| 472 | infoPtr->uInternalStatus |= TV_CALCALL;
|
|---|
| 473 | TREEVIEW_QueueRefresh(hwnd);
|
|---|
| 474 | }
|
|---|
| 475 |
|
|---|
| 476 | return prevHeight;
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | static LRESULT
|
|---|
| 480 | TREEVIEW_GetItemHeight (HWND hwnd)
|
|---|
| 481 | {
|
|---|
| 482 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 483 |
|
|---|
| 484 | return infoPtr->uItemHeight;
|
|---|
| 485 | }
|
|---|
| 486 |
|
|---|
| 487 | static LRESULT
|
|---|
| 488 | TREEVIEW_GetLineColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 489 | {
|
|---|
| 490 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 491 |
|
|---|
| 492 | //TRACE("\n");
|
|---|
| 493 | return (LRESULT) infoPtr->clrLine;
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | static LRESULT
|
|---|
| 497 | TREEVIEW_SetLineColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 498 | {
|
|---|
| 499 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 500 | COLORREF prevColor=infoPtr->clrLine;
|
|---|
| 501 |
|
|---|
| 502 | //TRACE("\n");
|
|---|
| 503 | infoPtr->clrLine=(COLORREF) lParam;
|
|---|
| 504 | return (LRESULT) prevColor;
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | static LRESULT
|
|---|
| 508 | TREEVIEW_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 509 | {
|
|---|
| 510 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 511 |
|
|---|
| 512 | //TRACE("\n");
|
|---|
| 513 | return (LRESULT) infoPtr->clrInsertMark;
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 | static LRESULT
|
|---|
| 517 | TREEVIEW_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 518 | {
|
|---|
| 519 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 520 | COLORREF prevColor=infoPtr->clrInsertMark;
|
|---|
| 521 |
|
|---|
| 522 | //TRACE("%d %ld\n",wParam,lParam);
|
|---|
| 523 | infoPtr->clrInsertMark=(COLORREF) lParam;
|
|---|
| 524 | return (LRESULT) prevColor;
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | static LRESULT
|
|---|
| 528 | TREEVIEW_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 529 | {
|
|---|
| 530 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 531 |
|
|---|
| 532 | //FIXME("%d %ld\n",wParam,lParam);
|
|---|
| 533 | if (!TREEVIEW_ValidItem (infoPtr, (HTREEITEM)lParam)) return 0;
|
|---|
| 534 | //FIXME("%d %ld\n",wParam,lParam);
|
|---|
| 535 |
|
|---|
| 536 | infoPtr->insertBeforeorAfter=(BOOL) wParam;
|
|---|
| 537 | infoPtr->insertMarkItem=(HTREEITEM) lParam;
|
|---|
| 538 |
|
|---|
| 539 | TREEVIEW_Refresh(hwnd);
|
|---|
| 540 |
|
|---|
| 541 | return 1;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | static LRESULT
|
|---|
| 545 | TREEVIEW_SetTextColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 546 | {
|
|---|
| 547 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 548 | COLORREF prevColor=infoPtr->clrText;
|
|---|
| 549 |
|
|---|
| 550 | infoPtr->clrText=(COLORREF) lParam;
|
|---|
| 551 | if (infoPtr->clrText != prevColor)
|
|---|
| 552 | TREEVIEW_Refresh(hwnd);
|
|---|
| 553 |
|
|---|
| 554 | return (LRESULT) prevColor;
|
|---|
| 555 | }
|
|---|
| 556 |
|
|---|
| 557 | static LRESULT
|
|---|
| 558 | TREEVIEW_GetBkColor (HWND hwnd)
|
|---|
| 559 | {
|
|---|
| 560 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 561 |
|
|---|
| 562 | return (LRESULT) infoPtr->clrBk;
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | static LRESULT
|
|---|
| 566 | TREEVIEW_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 567 | {
|
|---|
| 568 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 569 | COLORREF prevColor=infoPtr->clrBk;
|
|---|
| 570 |
|
|---|
| 571 | infoPtr->clrBk=(COLORREF) lParam;
|
|---|
| 572 | if (infoPtr->clrBk != prevColor)
|
|---|
| 573 | TREEVIEW_Refresh(hwnd);
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 | return (LRESULT) prevColor;
|
|---|
| 577 | }
|
|---|
| 578 |
|
|---|
| 579 | static LRESULT
|
|---|
| 580 | TREEVIEW_GetTextColor (HWND hwnd)
|
|---|
| 581 | {
|
|---|
| 582 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 583 |
|
|---|
| 584 | return (LRESULT) infoPtr->clrText;
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 | /* cdmode: custom draw mode as received from app. in first NMCUSTOMDRAW
|
|---|
| 589 | notification */
|
|---|
| 590 |
|
|---|
| 591 | #define TREEVIEW_LEFT_MARGIN 8
|
|---|
| 592 |
|
|---|
| 593 | #ifdef OS2LINEHACK
|
|---|
| 594 | //CB: hack for PS_DOT bug in Open32 pen handling
|
|---|
| 595 |
|
|---|
| 596 | BOOL drawPixel;
|
|---|
| 597 | HDC drawDC;
|
|---|
| 598 |
|
|---|
| 599 | VOID CALLBACK TREEVIEW_DDAProc(int x,int y,LPARAM lpData)
|
|---|
| 600 | {
|
|---|
| 601 | if (drawPixel) SetPixel(drawDC,x,y,(COLORREF)lpData);
|
|---|
| 602 | drawPixel = !drawPixel;
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | static void TREEVIEW_Polyline(HDC hdc,const POINT *lppt,int cPoints,COLORREF color)
|
|---|
| 606 | {
|
|---|
| 607 | INT x;
|
|---|
| 608 |
|
|---|
| 609 | drawPixel = TRUE;
|
|---|
| 610 | drawDC = hdc;
|
|---|
| 611 | for (x = 0;x < cPoints-1;x++)
|
|---|
| 612 | LineDDA(lppt[x].x,lppt[x].y,lppt[x+1].x,lppt[x+1].y,TREEVIEW_DDAProc,color);
|
|---|
| 613 | }
|
|---|
| 614 | #endif
|
|---|
| 615 |
|
|---|
| 616 | //pen must be selected!
|
|---|
| 617 |
|
|---|
| 618 | static void TREEVIEW_DrawVLines(HDC hdc,TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item)
|
|---|
| 619 | {
|
|---|
| 620 | POINT points[2];
|
|---|
| 621 | INT center;
|
|---|
| 622 |
|
|---|
| 623 | center = (item->rect.top+item->rect.bottom)/2;
|
|---|
| 624 | //INT cChildren = TREEVIEW_HasChildren(hwnd,wineItem);
|
|---|
| 625 | if ((item->iLevel == 0) && !item->upsibling && item->sibling)
|
|---|
| 626 | {
|
|---|
| 627 | TREEVIEW_ITEM *lastItem = &infoPtr->items[(INT)item->sibling];
|
|---|
| 628 |
|
|---|
| 629 | while (lastItem->sibling) lastItem = &infoPtr->items[(INT)lastItem->sibling];
|
|---|
| 630 |
|
|---|
| 631 | points[0].y = center;
|
|---|
| 632 | points[1].x = points[0].x = 8;
|
|---|
| 633 | points[1].y = (lastItem->rect.top+lastItem->rect.bottom)/2;
|
|---|
| 634 | #ifdef OS2LINEHACK
|
|---|
| 635 | TREEVIEW_Polyline(hdc,points,2,infoPtr->clrLine);
|
|---|
| 636 | #else
|
|---|
| 637 | Polyline(hdc,points,2);
|
|---|
| 638 | #endif
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 | if (item->firstChild && (item->state & TVIS_EXPANDED))
|
|---|
| 642 | {
|
|---|
| 643 | TREEVIEW_ITEM *lastItem = &infoPtr->items[(INT)item->firstChild];
|
|---|
| 644 |
|
|---|
| 645 | while (lastItem->sibling) lastItem = &infoPtr->items[(INT)lastItem->sibling];
|
|---|
| 646 |
|
|---|
| 647 | points[0].y = (lastItem->upsibling != NULL) ?
|
|---|
| 648 | item->rect.bottom-3: /* is linked to an icon */
|
|---|
| 649 | item->rect.bottom+1; /* is linked to a +/- box */
|
|---|
| 650 | points[1].x = points[0].x = 28+20*item->iLevel-infoPtr->lefttop.x;
|
|---|
| 651 | points[1].y = (lastItem->rect.top+lastItem->rect.bottom)/2; /* is linked to a +/- box */
|
|---|
| 652 | #ifdef OS2LINEHACK
|
|---|
| 653 | TREEVIEW_Polyline(hdc,points,2,infoPtr->clrLine);
|
|---|
| 654 | #else
|
|---|
| 655 | Polyline(hdc,points,2);
|
|---|
| 656 | #endif
|
|---|
| 657 | }
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | static VOID TREEVIEW_DrawHottrackLine(HDC hdc,TREEVIEW_ITEM *item)
|
|---|
| 661 | {
|
|---|
| 662 | HPEN hPen,hOldPen;
|
|---|
| 663 | INT rop;
|
|---|
| 664 |
|
|---|
| 665 | if (!item->visible) return;
|
|---|
| 666 |
|
|---|
| 667 | rop = SetROP2(hdc,R2_XORPEN);
|
|---|
| 668 | hPen = CreatePen(PS_SOLID,2,RGB(0,0,0));
|
|---|
| 669 | hOldPen = SelectObject(hdc,hPen);
|
|---|
| 670 |
|
|---|
| 671 | MoveToEx(hdc,item->text.left,item->text.bottom-1,NULL);
|
|---|
| 672 | LineTo(hdc,item->text.right,item->text.bottom-1);
|
|---|
| 673 |
|
|---|
| 674 | DeleteObject(hPen);
|
|---|
| 675 | SelectObject(hdc,hOldPen);
|
|---|
| 676 | SetROP2(hdc,rop);
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | static void
|
|---|
| 680 | TREEVIEW_DrawItem(HWND hwnd,HDC hdc,TREEVIEW_ITEM *item,DWORD dwStyle,TREEVIEW_INFO *infoPtr)
|
|---|
| 681 | {
|
|---|
| 682 | INT center,cditem;
|
|---|
| 683 | HFONT hOldFont;
|
|---|
| 684 |
|
|---|
| 685 | if (!item->calculated) TREEVIEW_CalcItem(hwnd,hdc,dwStyle,infoPtr,item);
|
|---|
| 686 |
|
|---|
| 687 | if (item->state & TVIS_BOLD)
|
|---|
| 688 | hOldFont = SelectObject(hdc,infoPtr->hBoldFont);
|
|---|
| 689 | else
|
|---|
| 690 | hOldFont = SelectObject(hdc,infoPtr->hFont);
|
|---|
| 691 |
|
|---|
| 692 | cditem = 0;
|
|---|
| 693 |
|
|---|
| 694 | if (infoPtr->cdmode & CDRF_NOTIFYITEMDRAW)
|
|---|
| 695 | {
|
|---|
| 696 | cditem = TREEVIEW_SendCustomDrawItemNotify(hwnd, hdc, item, CDDS_ITEMPREPAINT);
|
|---|
| 697 |
|
|---|
| 698 | if (cditem & CDRF_SKIPDEFAULT) return;
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | //CDRF_NEWFONT: CCM_SETVERSION < 5 clips text (what we do now)
|
|---|
| 702 | // > 5 ??? recalc?
|
|---|
| 703 |
|
|---|
| 704 | /*
|
|---|
| 705 | * Set drawing starting points
|
|---|
| 706 | */
|
|---|
| 707 | center = (item->rect.top+item->rect.bottom)/2; /* this item vertical center */
|
|---|
| 708 |
|
|---|
| 709 | /*
|
|---|
| 710 | * Display the tree hierarchy
|
|---|
| 711 | */
|
|---|
| 712 | if (dwStyle & TVS_HASLINES)
|
|---|
| 713 | {
|
|---|
| 714 | /*
|
|---|
| 715 | * Write links to parent node
|
|---|
| 716 | * we draw the L starting from the child to the parent
|
|---|
| 717 | *
|
|---|
| 718 | * points[0] is attached to the current item
|
|---|
| 719 | * points[1] is the L corner
|
|---|
| 720 | * points[2] is attached to the parent or the up sibling
|
|---|
| 721 | */
|
|---|
| 722 | if (dwStyle & TVS_LINESATROOT)
|
|---|
| 723 | {
|
|---|
| 724 | TREEVIEW_ITEM *upNode = NULL;
|
|---|
| 725 | RECT upRect = {0,0,0,0};
|
|---|
| 726 | HPEN hOldPen, hnewPen;
|
|---|
| 727 | POINT points[2];
|
|---|
| 728 |
|
|---|
| 729 | hnewPen = CreatePen(PS_DOT, 0, infoPtr->clrLine);
|
|---|
| 730 | hOldPen = SelectObject(hdc,hnewPen);
|
|---|
| 731 |
|
|---|
| 732 | TREEVIEW_DrawVLines(hdc,infoPtr,item);
|
|---|
| 733 |
|
|---|
| 734 | /*
|
|---|
| 735 | * determine the target location of the line at root, either be linked
|
|---|
| 736 | * to the up sibling or to the parent node.
|
|---|
| 737 | */
|
|---|
| 738 | if (item->upsibling)
|
|---|
| 739 | upNode = TREEVIEW_ValidItem (infoPtr, item->upsibling);
|
|---|
| 740 | else if (item->parent)
|
|---|
| 741 | upNode = TREEVIEW_ValidItem (infoPtr, item->parent);
|
|---|
| 742 |
|
|---|
| 743 | if (upNode) upRect = upNode->rect;
|
|---|
| 744 |
|
|---|
| 745 | if (item->iLevel == 0)
|
|---|
| 746 | {
|
|---|
| 747 | points[1].x = upRect.left+8;
|
|---|
| 748 | points[0].x = points[1].x + 10;
|
|---|
| 749 | points[1].y = points[0].y = center;
|
|---|
| 750 | } else
|
|---|
| 751 | {
|
|---|
| 752 | points[1].x = 8+(20*item->iLevel)-infoPtr->lefttop.x;
|
|---|
| 753 | points[1].y = points[0].y = center;
|
|---|
| 754 | points[0].x = points[1].x + 10;
|
|---|
| 755 | }
|
|---|
| 756 |
|
|---|
| 757 | /*
|
|---|
| 758 | * Get a dotted pen
|
|---|
| 759 | */
|
|---|
| 760 | #ifdef OS2LINEHACK
|
|---|
| 761 | TREEVIEW_Polyline(hdc,points,2,infoPtr->clrLine);
|
|---|
| 762 | #else
|
|---|
| 763 | Polyline(hdc,points,2);
|
|---|
| 764 | #endif
|
|---|
| 765 | DeleteObject(hnewPen);
|
|---|
| 766 | SelectObject(hdc, hOldPen);
|
|---|
| 767 | }
|
|---|
| 768 | }
|
|---|
| 769 |
|
|---|
| 770 | /*
|
|---|
| 771 | * Display the (+/-) signs
|
|---|
| 772 | */
|
|---|
| 773 | if ((dwStyle & TVS_HASBUTTONS) && (dwStyle & TVS_HASLINES))
|
|---|
| 774 | {
|
|---|
| 775 | if (TREEVIEW_HasChildren(hwnd,item))
|
|---|
| 776 | {
|
|---|
| 777 | INT vCenter = (item->expandBox.top+item->expandBox.bottom)/2;
|
|---|
| 778 | INT hCenter = (item->expandBox.right+item->expandBox.left)/2;
|
|---|
| 779 |
|
|---|
| 780 | Rectangle(hdc,item->expandBox.left,item->expandBox.top,item->expandBox.right,item->expandBox.bottom);
|
|---|
| 781 |
|
|---|
| 782 | MoveToEx(hdc,item->expandBox.left+2,vCenter,NULL);
|
|---|
| 783 | LineTo(hdc,item->expandBox.right-2,vCenter);
|
|---|
| 784 |
|
|---|
| 785 | if (!(item->state & TVIS_EXPANDED))
|
|---|
| 786 | {
|
|---|
| 787 | MoveToEx(hdc,hCenter,item->expandBox.top+2,NULL);
|
|---|
| 788 | LineTo(hdc,hCenter,item->expandBox.bottom-2);
|
|---|
| 789 | }
|
|---|
| 790 | }
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | /*
|
|---|
| 794 | * Display the image associated with this item
|
|---|
| 795 | */
|
|---|
| 796 | if ((item->mask & (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) || (dwStyle & TVS_CHECKBOXES))
|
|---|
| 797 | {
|
|---|
| 798 | INT imageIndex;
|
|---|
| 799 | HIMAGELIST *himlp = NULL;
|
|---|
| 800 |
|
|---|
| 801 | /* State images are displayed to the left of the Normal image
|
|---|
| 802 | * image number is in state; zero should be `display no image'.
|
|---|
| 803 | * FIXME: that last sentence looks like it needs some checking.
|
|---|
| 804 | */
|
|---|
| 805 | if (infoPtr->himlState)
|
|---|
| 806 | himlp =& infoPtr->himlState;
|
|---|
| 807 | imageIndex = item->state >> 12;
|
|---|
| 808 |
|
|---|
| 809 | if (himlp && imageIndex)
|
|---|
| 810 | {
|
|---|
| 811 | imageIndex--; /* see FIXME */
|
|---|
| 812 | ImageList_Draw(*himlp,imageIndex,hdc,item->statebitmap.left,item->statebitmap.top,ILD_NORMAL);
|
|---|
| 813 | }
|
|---|
| 814 |
|
|---|
| 815 | /* Now, draw the normal image; can be either selected or
|
|---|
| 816 | * non-selected image.
|
|---|
| 817 | */
|
|---|
| 818 |
|
|---|
| 819 | himlp = NULL;
|
|---|
| 820 | if (infoPtr->himlNormal)
|
|---|
| 821 | himlp = &infoPtr->himlNormal; /* get the image list */
|
|---|
| 822 |
|
|---|
| 823 | imageIndex = item->iImage;
|
|---|
| 824 | if ((item->state & TVIS_SELECTED) && item->iSelectedImage)
|
|---|
| 825 | {
|
|---|
| 826 | /* The item is curently selected */
|
|---|
| 827 | if (item->iSelectedImage == I_IMAGECALLBACK)
|
|---|
| 828 | imageIndex = TREEVIEW_CallbackSelectedImage(hwnd,item);
|
|---|
| 829 | else
|
|---|
| 830 | imageIndex = item->iSelectedImage;
|
|---|
| 831 | } else
|
|---|
| 832 | {
|
|---|
| 833 | /* The item is not selected */
|
|---|
| 834 | if (item->iImage == I_IMAGECALLBACK)
|
|---|
| 835 | imageIndex = TREEVIEW_CallbackImage(hwnd,item);
|
|---|
| 836 | else
|
|---|
| 837 | imageIndex = item->iImage;
|
|---|
| 838 | }
|
|---|
| 839 |
|
|---|
| 840 | if (himlp && (imageIndex != I_IMAGENONE))
|
|---|
| 841 | {
|
|---|
| 842 | int ovlIdx = 0;
|
|---|
| 843 |
|
|---|
| 844 | if(item->stateMask & TVIS_OVERLAYMASK)
|
|---|
| 845 | ovlIdx = item->state & TVIS_OVERLAYMASK;
|
|---|
| 846 |
|
|---|
| 847 | ImageList_Draw(*himlp,imageIndex,hdc,item->bitmap.left,item->bitmap.top,ILD_NORMAL | ovlIdx);
|
|---|
| 848 | }
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | /*
|
|---|
| 852 | * Display the text associated with this item
|
|---|
| 853 | */
|
|---|
| 854 | /* Don't paint item's text if it's being edited */
|
|---|
| 855 | if (!infoPtr->hwndEdit || (infoPtr->editItem != item->hItem))
|
|---|
| 856 | {
|
|---|
| 857 | if ((item->mask & TVIF_TEXT) && (item->pszText))
|
|---|
| 858 | {
|
|---|
| 859 | UINT uTextJustify = DT_LEFT;
|
|---|
| 860 | COLORREF oldTextColor = 0;
|
|---|
| 861 | INT oldBkMode;
|
|---|
| 862 | HBRUSH hbrBk = 0;
|
|---|
| 863 | BOOL inFocus = GetFocus() == hwnd;
|
|---|
| 864 | WCHAR* text;
|
|---|
| 865 | BOOL mustFree = FALSE;
|
|---|
| 866 |
|
|---|
| 867 | oldBkMode = SetBkMode(hdc, TRANSPARENT);
|
|---|
| 868 |
|
|---|
| 869 | /* - If item is drop target or it is selected and window is in focus -
|
|---|
| 870 | * use blue background (COLOR_HIGHLIGHT).
|
|---|
| 871 | * - If item is selected, window is not in focus, but it has style
|
|---|
| 872 | * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
|
|---|
| 873 | * - Otherwise - don't fill background
|
|---|
| 874 | */
|
|---|
| 875 | if ((item->state & TVIS_DROPHILITED) ||
|
|---|
| 876 | ((item->state & TVIS_SELECTED) &&
|
|---|
| 877 | (inFocus || (GetWindowLongA( hwnd, GWL_STYLE) & TVS_SHOWSELALWAYS))))
|
|---|
| 878 | {
|
|---|
| 879 | if ((item->state & TVIS_DROPHILITED) || inFocus)
|
|---|
| 880 | {
|
|---|
| 881 | hbrBk = CreateSolidBrush(GetSysColor( COLOR_HIGHLIGHT));
|
|---|
| 882 | oldTextColor = SetTextColor(hdc, GetSysColor( COLOR_HIGHLIGHTTEXT));
|
|---|
| 883 | } else
|
|---|
| 884 | {
|
|---|
| 885 | hbrBk = CreateSolidBrush(GetSysColor( COLOR_BTNFACE));
|
|---|
| 886 |
|
|---|
| 887 | if (infoPtr->clrText == -1)
|
|---|
| 888 | oldTextColor = SetTextColor(hdc, GetSysColor( COLOR_WINDOWTEXT));
|
|---|
| 889 | else
|
|---|
| 890 | oldTextColor = SetTextColor(hdc, infoPtr->clrText);
|
|---|
| 891 | }
|
|---|
| 892 | } else
|
|---|
| 893 | {
|
|---|
| 894 | if (infoPtr->clrText == -1)
|
|---|
| 895 | oldTextColor = SetTextColor(hdc, GetSysColor( COLOR_WINDOWTEXT));
|
|---|
| 896 | else
|
|---|
| 897 | oldTextColor = SetTextColor(hdc, infoPtr->clrText);
|
|---|
| 898 | }
|
|---|
| 899 |
|
|---|
| 900 | if (item->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 901 | text = TREEVIEW_CallbackText(hwnd,item,&mustFree);
|
|---|
| 902 | else
|
|---|
| 903 | text = item->pszText;
|
|---|
| 904 |
|
|---|
| 905 | if (hbrBk)
|
|---|
| 906 | {
|
|---|
| 907 | FillRect(hdc, &item->text, hbrBk);
|
|---|
| 908 | DeleteObject(hbrBk);
|
|---|
| 909 | }
|
|---|
| 910 |
|
|---|
| 911 | item->text.left += 2;
|
|---|
| 912 |
|
|---|
| 913 | /* Draw it */
|
|---|
| 914 | DrawTextW(hdc,text,lstrlenW(text),&item->text,uTextJustify | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
|
|---|
| 915 | if (mustFree) COMCTL32_Free(text);
|
|---|
| 916 |
|
|---|
| 917 | item->text.left -= 2;
|
|---|
| 918 |
|
|---|
| 919 | /* Restore the hdc state */
|
|---|
| 920 | SetTextColor( hdc, oldTextColor);
|
|---|
| 921 |
|
|---|
| 922 | /* Draw the box arround the selected item */
|
|---|
| 923 | if (item->state & TVIS_SELECTED)
|
|---|
| 924 | {
|
|---|
| 925 | HPEN hNewPen = CreatePen(PS_DOT, 0, GetSysColor(COLOR_WINDOWTEXT) );
|
|---|
| 926 | HPEN hOldPen = SelectObject( hdc, hNewPen );
|
|---|
| 927 | INT rop = SetROP2(hdc, R2_XORPEN);
|
|---|
| 928 | POINT points[5];
|
|---|
| 929 |
|
|---|
| 930 | points[4].x = points[0].x = item->text.left;
|
|---|
| 931 | points[4].y = points[0].y = item->text.top;
|
|---|
| 932 | points[1].x = item->text.right-1 ;
|
|---|
| 933 | points[1].y = item->text.top;
|
|---|
| 934 | points[2].x = item->text.right-1;
|
|---|
| 935 | points[2].y = item->text.bottom-1;
|
|---|
| 936 | points[3].x = item->text.left;
|
|---|
| 937 | points[3].y = item->text.bottom-1;
|
|---|
| 938 |
|
|---|
| 939 | Polyline (hdc,points,5);
|
|---|
| 940 |
|
|---|
| 941 | SetROP2(hdc, rop);
|
|---|
| 942 | DeleteObject(hNewPen);
|
|---|
| 943 | SelectObject(hdc, hOldPen);
|
|---|
| 944 | }
|
|---|
| 945 |
|
|---|
| 946 | if (oldBkMode != TRANSPARENT)
|
|---|
| 947 | SetBkMode(hdc, oldBkMode);
|
|---|
| 948 | }
|
|---|
| 949 | }
|
|---|
| 950 |
|
|---|
| 951 | /* Draw insertion mark if necessary */
|
|---|
| 952 |
|
|---|
| 953 | if (item->hItem == infoPtr->insertMarkItem)
|
|---|
| 954 | {
|
|---|
| 955 | HPEN hNewPen, hOldPen;
|
|---|
| 956 | int offset;
|
|---|
| 957 |
|
|---|
| 958 | hNewPen = CreatePen(PS_SOLID, 2, infoPtr->clrInsertMark);
|
|---|
| 959 | hOldPen = SelectObject( hdc, hNewPen );
|
|---|
| 960 |
|
|---|
| 961 | if (infoPtr->insertBeforeorAfter)
|
|---|
| 962 | offset = item->text.top+1;
|
|---|
| 963 | else
|
|---|
| 964 | offset = item->text.bottom-1;
|
|---|
| 965 |
|
|---|
| 966 | MoveToEx(hdc,item->text.left, offset-3, NULL);
|
|---|
| 967 | LineTo(hdc,item->text.left, offset+3);
|
|---|
| 968 |
|
|---|
| 969 | MoveToEx(hdc,item->text.left,offset,NULL);
|
|---|
| 970 | LineTo(hdc,item->text.right-2,offset);
|
|---|
| 971 |
|
|---|
| 972 | MoveToEx(hdc,item->text.right-2, offset+3, NULL);
|
|---|
| 973 | LineTo(hdc,item->text.right-2, offset-3);
|
|---|
| 974 |
|
|---|
| 975 | DeleteObject(hNewPen);
|
|---|
| 976 |
|
|---|
| 977 | SelectObject(hdc, hOldPen);
|
|---|
| 978 | }
|
|---|
| 979 |
|
|---|
| 980 | //draw hot item if necessary
|
|---|
| 981 | if (item->hItem == infoPtr->hotItem)
|
|---|
| 982 | TREEVIEW_DrawHottrackLine(hdc,item);
|
|---|
| 983 |
|
|---|
| 984 | if (cditem & CDRF_NOTIFYPOSTPAINT)
|
|---|
| 985 | cditem = TREEVIEW_SendCustomDrawItemNotify(hwnd, hdc, item, CDDS_ITEMPOSTPAINT);
|
|---|
| 986 |
|
|---|
| 987 | SelectObject (hdc, hOldFont);
|
|---|
| 988 | }
|
|---|
| 989 |
|
|---|
| 990 | static LRESULT
|
|---|
| 991 | TREEVIEW_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 992 | {
|
|---|
| 993 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 994 | TREEVIEW_ITEM *wineItem;
|
|---|
| 995 | HTREEITEM *iItem;
|
|---|
| 996 | LPRECT lpRect = (LPRECT)lParam;
|
|---|
| 997 |
|
|---|
| 998 | /*
|
|---|
| 999 | * validate parameters
|
|---|
| 1000 | */
|
|---|
| 1001 | if ((infoPtr == NULL) || (lpRect == NULL))
|
|---|
| 1002 | return FALSE;
|
|---|
| 1003 |
|
|---|
| 1004 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
|
|---|
| 1005 |
|
|---|
| 1006 | /*
|
|---|
| 1007 | * retrieve the item ptr
|
|---|
| 1008 | */
|
|---|
| 1009 | iItem = (HTREEITEM *) lParam;
|
|---|
| 1010 | wineItem = TREEVIEW_ValidItem (infoPtr, *iItem);
|
|---|
| 1011 | if (!wineItem || !wineItem->visible)
|
|---|
| 1012 | return FALSE;
|
|---|
| 1013 |
|
|---|
| 1014 | /*
|
|---|
| 1015 | * If wParam is TRUE return the text size otherwise return
|
|---|
| 1016 | * the whole item size
|
|---|
| 1017 | */
|
|---|
| 1018 | if (wParam)
|
|---|
| 1019 | {
|
|---|
| 1020 | lpRect->left = wineItem->text.left;
|
|---|
| 1021 | lpRect->right = wineItem->text.right;
|
|---|
| 1022 | lpRect->bottom = wineItem->text.bottom;
|
|---|
| 1023 | lpRect->top = wineItem->text.top;
|
|---|
| 1024 | } else
|
|---|
| 1025 | {
|
|---|
| 1026 | lpRect->left = wineItem->rect.left;
|
|---|
| 1027 | lpRect->right = wineItem->rect.right;
|
|---|
| 1028 | lpRect->bottom = wineItem->rect.bottom;
|
|---|
| 1029 | lpRect->top = wineItem->rect.top;
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | return TRUE;
|
|---|
| 1033 | }
|
|---|
| 1034 |
|
|---|
| 1035 | static LRESULT
|
|---|
| 1036 | TREEVIEW_GetVisibleCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 1037 |
|
|---|
| 1038 | {
|
|---|
| 1039 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1040 |
|
|---|
| 1041 | return (LRESULT)infoPtr->uVisibleHeight/infoPtr->uRealItemHeight;
|
|---|
| 1042 | }
|
|---|
| 1043 |
|
|---|
| 1044 | static LRESULT TREEVIEW_SetItem(HWND hwnd,WPARAM wParam,LPARAM lParam,BOOL unicode)
|
|---|
| 1045 | {
|
|---|
| 1046 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1047 | TREEVIEW_ITEM *wineItem;
|
|---|
| 1048 | TVITEMEXW *tvItem;
|
|---|
| 1049 | INT iItem,len;
|
|---|
| 1050 | BOOL mustRefresh = FALSE;
|
|---|
| 1051 | BOOL mustRepaintItem = FALSE;
|
|---|
| 1052 | BOOL refreshFullLine = FALSE;
|
|---|
| 1053 |
|
|---|
| 1054 | if (infoPtr->hwndEdit) SetFocus(hwnd);
|
|---|
| 1055 |
|
|---|
| 1056 | tvItem = (LPTVITEMEXW)lParam;
|
|---|
| 1057 | iItem = (INT)tvItem->hItem;
|
|---|
| 1058 |
|
|---|
| 1059 | wineItem = TREEVIEW_ValidItem(infoPtr,(HTREEITEM)iItem);
|
|---|
| 1060 | if (!wineItem) return FALSE;
|
|---|
| 1061 |
|
|---|
| 1062 | if ((tvItem->mask & TVIF_CHILDREN) && (wineItem->cChildren != tvItem->cChildren))
|
|---|
| 1063 | {
|
|---|
| 1064 | wineItem->cChildren = tvItem->cChildren;
|
|---|
| 1065 | mustRefresh = TRUE;
|
|---|
| 1066 | }
|
|---|
| 1067 |
|
|---|
| 1068 | if ((tvItem->mask & TVIF_IMAGE) && (wineItem->iImage != tvItem->iImage))
|
|---|
| 1069 | {
|
|---|
| 1070 | wineItem->iImage = tvItem->iImage;
|
|---|
| 1071 | mustRepaintItem = TRUE;
|
|---|
| 1072 | }
|
|---|
| 1073 |
|
|---|
| 1074 | if ((tvItem->mask & TVIF_INTEGRAL) && (wineItem->iIntegral != tvItem->iIntegral))
|
|---|
| 1075 | {
|
|---|
| 1076 | wineItem->iIntegral = tvItem->iIntegral;
|
|---|
| 1077 | mustRefresh = TRUE;
|
|---|
| 1078 | }
|
|---|
| 1079 |
|
|---|
| 1080 | if (tvItem->mask & TVIF_PARAM)
|
|---|
| 1081 | wineItem->lParam = tvItem->lParam;
|
|---|
| 1082 |
|
|---|
| 1083 | if ((tvItem->mask & TVIF_SELECTEDIMAGE) && (wineItem->iSelectedImage != tvItem->iSelectedImage))
|
|---|
| 1084 | {
|
|---|
| 1085 | wineItem->iSelectedImage = tvItem->iSelectedImage;
|
|---|
| 1086 | mustRepaintItem = TRUE;
|
|---|
| 1087 | }
|
|---|
| 1088 |
|
|---|
| 1089 | if (tvItem->mask & TVIF_STATE)
|
|---|
| 1090 | {
|
|---|
| 1091 | DWORD oldState = wineItem->state,oldMask = wineItem->stateMask;
|
|---|
| 1092 |
|
|---|
| 1093 | wineItem->state &= ~tvItem->stateMask;
|
|---|
| 1094 | wineItem->state |= (tvItem->state & tvItem->stateMask);
|
|---|
| 1095 | wineItem->stateMask |= tvItem->stateMask;
|
|---|
| 1096 | mustRepaintItem = (oldState != wineItem->state) || (oldMask != wineItem->stateMask);
|
|---|
| 1097 | }
|
|---|
| 1098 |
|
|---|
| 1099 | if (tvItem->mask & TVIF_TEXT)
|
|---|
| 1100 | {
|
|---|
| 1101 | if (unicode)
|
|---|
| 1102 | {
|
|---|
| 1103 | if (tvItem->pszText != LPSTR_TEXTCALLBACKW)
|
|---|
| 1104 | {
|
|---|
| 1105 | len = lstrlenW(tvItem->pszText)+1;
|
|---|
| 1106 |
|
|---|
| 1107 | mustRepaintItem = ((wineItem->pszText == LPSTR_TEXTCALLBACKW) || (lstrcmpW(wineItem->pszText,tvItem->pszText) != 0));
|
|---|
| 1108 | if (len > wineItem->cchTextMax)
|
|---|
| 1109 | {
|
|---|
| 1110 | if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free(wineItem->pszText);
|
|---|
| 1111 | wineItem->pszText= (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
|---|
| 1112 | wineItem->cchTextMax = len;
|
|---|
| 1113 | }
|
|---|
| 1114 | lstrcpyW(wineItem->pszText,tvItem->pszText);
|
|---|
| 1115 | } else
|
|---|
| 1116 | {
|
|---|
| 1117 | if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free(wineItem->pszText);
|
|---|
| 1118 | wineItem->cchTextMax = 0;
|
|---|
| 1119 | wineItem->pszText = LPSTR_TEXTCALLBACKW;
|
|---|
| 1120 | mustRepaintItem = TRUE;
|
|---|
| 1121 | }
|
|---|
| 1122 | } else
|
|---|
| 1123 | {
|
|---|
| 1124 | if ((LPSTR)tvItem->pszText != LPSTR_TEXTCALLBACKA)
|
|---|
| 1125 | {
|
|---|
| 1126 | mustRepaintItem = ((wineItem->pszText == LPSTR_TEXTCALLBACKW) || (lstrcmpAtoW((CHAR*)tvItem->pszText,wineItem->pszText) != 0));
|
|---|
| 1127 | len = lstrlenA((LPSTR)tvItem->pszText)+1;
|
|---|
| 1128 | if (len > wineItem->cchTextMax)
|
|---|
| 1129 | {
|
|---|
| 1130 | if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free(wineItem->pszText);
|
|---|
| 1131 | wineItem->pszText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
|---|
| 1132 | wineItem->cchTextMax = len;
|
|---|
| 1133 | }
|
|---|
| 1134 | lstrcpyAtoW(wineItem->pszText,(LPSTR)tvItem->pszText);
|
|---|
| 1135 | } else
|
|---|
| 1136 | {
|
|---|
| 1137 | if (wineItem->pszText != LPSTR_TEXTCALLBACKW) COMCTL32_Free(wineItem->pszText);
|
|---|
| 1138 | wineItem->cchTextMax = 0;
|
|---|
| 1139 | wineItem->pszText = LPSTR_TEXTCALLBACKW;
|
|---|
| 1140 | mustRepaintItem = TRUE;
|
|---|
| 1141 | }
|
|---|
| 1142 | }
|
|---|
| 1143 | refreshFullLine = TRUE;
|
|---|
| 1144 | }
|
|---|
| 1145 |
|
|---|
| 1146 | if (wineItem->mask != (wineItem->mask | tvItem->mask))
|
|---|
| 1147 | {
|
|---|
| 1148 | wineItem->mask |= tvItem->mask;
|
|---|
| 1149 | mustRepaintItem = TRUE;
|
|---|
| 1150 | }
|
|---|
| 1151 |
|
|---|
| 1152 | if (mustRepaintItem || mustRefresh)
|
|---|
| 1153 | {
|
|---|
| 1154 | wineItem->calculated = FALSE;
|
|---|
| 1155 | if (mustRefresh)
|
|---|
| 1156 | TREEVIEW_QueueRefresh(hwnd);
|
|---|
| 1157 | else
|
|---|
| 1158 | TREEVIEW_RefreshItem(hwnd,wineItem,refreshFullLine);
|
|---|
| 1159 | }
|
|---|
| 1160 |
|
|---|
| 1161 | return TRUE;
|
|---|
| 1162 | }
|
|---|
| 1163 |
|
|---|
| 1164 | static LRESULT
|
|---|
| 1165 | TREEVIEW_GetItemState (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 1166 |
|
|---|
| 1167 | {
|
|---|
| 1168 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1169 | TREEVIEW_ITEM *wineItem;
|
|---|
| 1170 |
|
|---|
| 1171 | wineItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM)wParam);
|
|---|
| 1172 | if (!wineItem) return 0;
|
|---|
| 1173 |
|
|---|
| 1174 | return (wineItem->state & lParam);
|
|---|
| 1175 | }
|
|---|
| 1176 |
|
|---|
| 1177 | static void TREEVIEW_Refresh(HWND hwnd)
|
|---|
| 1178 | {
|
|---|
| 1179 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,FALSE);
|
|---|
| 1180 |
|
|---|
| 1181 | InvalidateRect(hwnd,NULL,TRUE);
|
|---|
| 1182 | }
|
|---|
| 1183 |
|
|---|
| 1184 | static void TREEVIEW_RefreshItem(HWND hwnd,TREEVIEW_ITEM *item,BOOL wholeLine)
|
|---|
| 1185 | {
|
|---|
| 1186 | if (item && item->visible)
|
|---|
| 1187 | {
|
|---|
| 1188 | RECT rect = item->rect;
|
|---|
| 1189 |
|
|---|
| 1190 | if (wholeLine)
|
|---|
| 1191 | {
|
|---|
| 1192 | RECT client;
|
|---|
| 1193 |
|
|---|
| 1194 | GetClientRect(hwnd,&client);
|
|---|
| 1195 | rect.left = 0;
|
|---|
| 1196 | rect.right = client.right;
|
|---|
| 1197 | } else
|
|---|
| 1198 | {
|
|---|
| 1199 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 1200 |
|
|---|
| 1201 | //redraw text and image
|
|---|
| 1202 | if ((((item->mask & (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) == (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) || (dwStyle & TVS_CHECKBOXES)) && (item->iSelectedImage != item->iImage))
|
|---|
| 1203 | {
|
|---|
| 1204 | rect.left += TREEVIEW_LEFT_MARGIN;
|
|---|
| 1205 | if (item->iLevel != 0) rect.left += (5*item->iLevel);
|
|---|
| 1206 | rect.left += 15;
|
|---|
| 1207 | } else rect = item->text;
|
|---|
| 1208 | }
|
|---|
| 1209 |
|
|---|
| 1210 | InvalidateRect(hwnd,&rect,TRUE);
|
|---|
| 1211 | }
|
|---|
| 1212 | }
|
|---|
| 1213 |
|
|---|
| 1214 | //HDC parameter is optional
|
|---|
| 1215 |
|
|---|
| 1216 | static void TREEVIEW_CalcItem(HWND hwnd,HDC hdc,DWORD dwStyle,TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item)
|
|---|
| 1217 | {
|
|---|
| 1218 | RECT r;
|
|---|
| 1219 | INT center,xpos;
|
|---|
| 1220 | BOOL ownDC = FALSE;
|
|---|
| 1221 |
|
|---|
| 1222 | item->calculated = TRUE;
|
|---|
| 1223 |
|
|---|
| 1224 | r = item->rect; /* this item rectangle */
|
|---|
| 1225 | center = (r.top+r.bottom)/2; /* this item vertical center */
|
|---|
| 1226 | xpos = r.left + TREEVIEW_LEFT_MARGIN;/* horizontal starting point */
|
|---|
| 1227 |
|
|---|
| 1228 | if (item->iLevel != 0)/* update position only for non root node */
|
|---|
| 1229 | xpos += 5*item->iLevel;
|
|---|
| 1230 |
|
|---|
| 1231 | if ((dwStyle & TVS_HASBUTTONS) && (dwStyle & TVS_HASLINES))
|
|---|
| 1232 | {
|
|---|
| 1233 | if (TREEVIEW_HasChildren(hwnd,item))
|
|---|
| 1234 | {
|
|---|
| 1235 | /* Setup expand box coordinate to facilitate the LMBClick handling */
|
|---|
| 1236 | item->expandBox.left = xpos-4;
|
|---|
| 1237 | item->expandBox.top = center-4;
|
|---|
| 1238 | item->expandBox.right = xpos+5;
|
|---|
| 1239 | item->expandBox.bottom = center+5;
|
|---|
| 1240 | } else SetRectEmpty(&item->expandBox);
|
|---|
| 1241 | } else SetRectEmpty(&item->expandBox);
|
|---|
| 1242 |
|
|---|
| 1243 | xpos += 13; /* update position */
|
|---|
| 1244 |
|
|---|
| 1245 | if ((item->mask & (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) || (dwStyle & TVS_CHECKBOXES))
|
|---|
| 1246 | {
|
|---|
| 1247 | INT imageIndex,cx,cy;
|
|---|
| 1248 | HIMAGELIST *himlp = NULL;
|
|---|
| 1249 |
|
|---|
| 1250 | /* State images are displayed to the left of the Normal image
|
|---|
| 1251 | * image number is in state; zero should be `display no image'.
|
|---|
| 1252 | * FIXME: that last sentence looks like it needs some checking.
|
|---|
| 1253 | */
|
|---|
| 1254 | if (infoPtr->himlState)
|
|---|
| 1255 | himlp = &infoPtr->himlState;
|
|---|
| 1256 | imageIndex = item->state >> 12;
|
|---|
| 1257 |
|
|---|
| 1258 | if (himlp && imageIndex)
|
|---|
| 1259 | {
|
|---|
| 1260 | if (!hdc)
|
|---|
| 1261 | {
|
|---|
| 1262 | ownDC = TRUE;
|
|---|
| 1263 | hdc = GetDC(hwnd);
|
|---|
| 1264 | }
|
|---|
| 1265 |
|
|---|
| 1266 | imageIndex--; /* see FIXME */
|
|---|
| 1267 | ImageList_GetIconSize(*himlp,&cx,&cy);
|
|---|
| 1268 | item->statebitmap.left = xpos-2;
|
|---|
| 1269 | item->statebitmap.right = xpos-2+cx;
|
|---|
| 1270 | item->statebitmap.top = r.top+1;
|
|---|
| 1271 | item->statebitmap.bottom = r.top+1+cy;
|
|---|
| 1272 | xpos += cx;
|
|---|
| 1273 | } else SetRectEmpty(&item->statebitmap);
|
|---|
| 1274 |
|
|---|
| 1275 | /* Now, draw the normal image; can be either selected or
|
|---|
| 1276 | * non-selected image.
|
|---|
| 1277 | */
|
|---|
| 1278 |
|
|---|
| 1279 | himlp = NULL;
|
|---|
| 1280 | if (infoPtr->himlNormal)
|
|---|
| 1281 | himlp = &infoPtr->himlNormal; /* get the image list */
|
|---|
| 1282 |
|
|---|
| 1283 | if (himlp)
|
|---|
| 1284 | {
|
|---|
| 1285 | int ovlIdx = 0;
|
|---|
| 1286 |
|
|---|
| 1287 | if(item->stateMask & TVIS_OVERLAYMASK)
|
|---|
| 1288 | ovlIdx = item->state & TVIS_OVERLAYMASK;
|
|---|
| 1289 |
|
|---|
| 1290 | if (!hdc)
|
|---|
| 1291 | {
|
|---|
| 1292 | ownDC = TRUE;
|
|---|
| 1293 | hdc = GetDC(hwnd);
|
|---|
| 1294 | }
|
|---|
| 1295 |
|
|---|
| 1296 | ImageList_GetIconSize(*himlp,&cx,&cy);
|
|---|
| 1297 | item->bitmap.left = xpos-2;
|
|---|
| 1298 | item->bitmap.right = xpos-2+cx;
|
|---|
| 1299 | item->bitmap.top = r.top+1;
|
|---|
| 1300 | item->bitmap.bottom = r.top+1+cy;
|
|---|
| 1301 | xpos += cx;
|
|---|
| 1302 | } else SetRectEmpty(&item->bitmap);
|
|---|
| 1303 | } else
|
|---|
| 1304 | {
|
|---|
| 1305 | SetRectEmpty(&item->statebitmap);
|
|---|
| 1306 | SetRectEmpty(&item->bitmap);
|
|---|
| 1307 | }
|
|---|
| 1308 |
|
|---|
| 1309 | r.left = xpos;
|
|---|
| 1310 | if ((item->mask & TVIF_TEXT) && item->pszText)
|
|---|
| 1311 | {
|
|---|
| 1312 | UINT uTextJustify = DT_LEFT;
|
|---|
| 1313 | HFONT hOldFont;
|
|---|
| 1314 | WCHAR* text;
|
|---|
| 1315 | BOOL mustFree = FALSE;
|
|---|
| 1316 |
|
|---|
| 1317 | r.left += 3;
|
|---|
| 1318 | r.right -= 3;
|
|---|
| 1319 |
|
|---|
| 1320 | item->text.left = r.left;
|
|---|
| 1321 | item->text.right = r.right;
|
|---|
| 1322 | item->text.top = r.top;
|
|---|
| 1323 | item->text.bottom= r.bottom;
|
|---|
| 1324 |
|
|---|
| 1325 | if (item->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 1326 | text = TREEVIEW_CallbackText(hwnd,item,&mustFree);
|
|---|
| 1327 | else
|
|---|
| 1328 | text = item->pszText;
|
|---|
| 1329 |
|
|---|
| 1330 | if (!hdc)
|
|---|
| 1331 | {
|
|---|
| 1332 | ownDC = TRUE;
|
|---|
| 1333 | hdc = GetDC(hwnd);
|
|---|
| 1334 | }
|
|---|
| 1335 |
|
|---|
| 1336 | if (item->state & TVIS_BOLD)
|
|---|
| 1337 | hOldFont = SelectObject (hdc, infoPtr->hBoldFont);
|
|---|
| 1338 | else
|
|---|
| 1339 | hOldFont = SelectObject (hdc, infoPtr->hFont);
|
|---|
| 1340 |
|
|---|
| 1341 | /* Obtain the text coordinate */
|
|---|
| 1342 | DrawTextW (hdc,text,lstrlenW(text),&item->text,uTextJustify | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX);
|
|---|
| 1343 | if (mustFree) COMCTL32_Free(text);
|
|---|
| 1344 |
|
|---|
| 1345 | SelectObject(hdc,hOldFont);
|
|---|
| 1346 |
|
|---|
| 1347 | /* We need to reset it to items height */
|
|---|
| 1348 | item->text.top = r.top;
|
|---|
| 1349 | item->text.bottom = r.bottom;
|
|---|
| 1350 | item->text.right += 4; /* This is extra for focus rectangle */
|
|---|
| 1351 |
|
|---|
| 1352 | xpos = item->text.right;
|
|---|
| 1353 | } else SetRectEmpty(&item->text);
|
|---|
| 1354 |
|
|---|
| 1355 | item->rect.right = xpos;
|
|---|
| 1356 |
|
|---|
| 1357 | if (ownDC) ReleaseDC(hwnd,hdc);
|
|---|
| 1358 | }
|
|---|
| 1359 |
|
|---|
| 1360 | //HDC parameter is optional
|
|---|
| 1361 |
|
|---|
| 1362 | static BOOL TREEVIEW_CalcItems(HWND hwnd,HDC hdc,TREEVIEW_INFO *infoPtr)
|
|---|
| 1363 | {
|
|---|
| 1364 | TREEVIEW_ITEM *item;
|
|---|
| 1365 | INT iItem, indent,x,y,height,itemHeight;
|
|---|
| 1366 | TEXTMETRICA tm;
|
|---|
| 1367 | RECT rect,view;
|
|---|
| 1368 | BOOL ownDC = FALSE,changedLeftTop = FALSE;
|
|---|
| 1369 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 1370 | INT maxXScroll,maxYScroll;
|
|---|
| 1371 | INT xDiff,yDiff;
|
|---|
| 1372 | HFONT oldFont;
|
|---|
| 1373 |
|
|---|
| 1374 | GetClientRect(hwnd,&rect);
|
|---|
| 1375 | infoPtr->uVisibleHeight = rect.bottom-rect.top;
|
|---|
| 1376 | infoPtr->uVisibleWidth = rect.right-rect.left;
|
|---|
| 1377 |
|
|---|
| 1378 | if (infoPtr->uInternalStatus & TV_CALCALL)
|
|---|
| 1379 | {
|
|---|
| 1380 | TREEVIEW_HideInfoTip(hwnd,infoPtr);
|
|---|
| 1381 | itemHeight = 0;
|
|---|
| 1382 | ImageList_GetIconSize (infoPtr->himlNormal, &x, &itemHeight);
|
|---|
| 1383 | itemHeight = MAX(infoPtr->uItemHeight,itemHeight);
|
|---|
| 1384 |
|
|---|
| 1385 | if (!hdc)
|
|---|
| 1386 | {
|
|---|
| 1387 | ownDC = TRUE;
|
|---|
| 1388 | hdc = GetDC(hwnd);
|
|---|
| 1389 | }
|
|---|
| 1390 |
|
|---|
| 1391 | oldFont = SelectObject(hdc,infoPtr->hFont);
|
|---|
| 1392 | GetTextMetricsA(hdc,&tm);
|
|---|
| 1393 | itemHeight = MAX(tm.tmHeight+tm.tmExternalLeading,itemHeight);
|
|---|
| 1394 | SelectObject(hdc,infoPtr->hBoldFont);
|
|---|
| 1395 | GetTextMetricsA(hdc,&tm);
|
|---|
| 1396 | itemHeight = MAX(tm.tmHeight+tm.tmExternalLeading,itemHeight);
|
|---|
| 1397 | SelectObject(hdc,oldFont);
|
|---|
| 1398 | if (!(dwStyle & TVS_NONEVENHEIGHT))
|
|---|
| 1399 | if (itemHeight & 0x1) itemHeight++; //important for PS_DOT pen!
|
|---|
| 1400 | infoPtr->uRealItemHeight = itemHeight;
|
|---|
| 1401 | infoPtr->uVScrollStep = itemHeight+ITEM_VSPACE;
|
|---|
| 1402 | } else
|
|---|
| 1403 | {
|
|---|
| 1404 | itemHeight = infoPtr->uRealItemHeight;
|
|---|
| 1405 | }
|
|---|
| 1406 | infoPtr->uTotalWidth = 0;
|
|---|
| 1407 |
|
|---|
| 1408 | view = rect;
|
|---|
| 1409 | OffsetRect(&view,infoPtr->lefttop.x,infoPtr->lefttop.y);
|
|---|
| 1410 |
|
|---|
| 1411 | iItem = (INT)infoPtr->TopRootItem;
|
|---|
| 1412 | infoPtr->firstVisible = 0;
|
|---|
| 1413 | item = NULL;
|
|---|
| 1414 | indent = x = y = 0;
|
|---|
| 1415 |
|
|---|
| 1416 | while (iItem)
|
|---|
| 1417 | {
|
|---|
| 1418 | item = &infoPtr->items[iItem];
|
|---|
| 1419 | item->iLevel = indent;
|
|---|
| 1420 |
|
|---|
| 1421 | height = itemHeight*item->iIntegral+ITEM_VSPACE;
|
|---|
| 1422 |
|
|---|
| 1423 | //calculate size and fill rects
|
|---|
| 1424 | if ((infoPtr->uInternalStatus & TV_CALCALL) || !item->calculated)
|
|---|
| 1425 | {
|
|---|
| 1426 | item->rect.top = y-view.top;
|
|---|
| 1427 | item->rect.bottom = item->rect.top+height;
|
|---|
| 1428 | item->rect.left = x-view.left;
|
|---|
| 1429 | item->rect.right = rect.right; //dummy
|
|---|
| 1430 | if (!hdc)
|
|---|
| 1431 | {
|
|---|
| 1432 | ownDC = TRUE;
|
|---|
| 1433 | hdc = GetDC(hwnd);
|
|---|
| 1434 | }
|
|---|
| 1435 | TREEVIEW_CalcItem(hwnd,hdc,dwStyle,infoPtr,item);
|
|---|
| 1436 | } else
|
|---|
| 1437 | {
|
|---|
| 1438 | INT xOffset,yOffset;
|
|---|
| 1439 |
|
|---|
| 1440 | xOffset = (x-view.left)-item->rect.left;
|
|---|
| 1441 | yOffset = (y-view.top)-item->rect.top;
|
|---|
| 1442 | OffsetRect(&item->rect,xOffset,yOffset);
|
|---|
| 1443 | OffsetRect(&item->text,xOffset,yOffset);
|
|---|
| 1444 | OffsetRect(&item->expandBox,xOffset,yOffset);
|
|---|
| 1445 | OffsetRect(&item->bitmap,xOffset,yOffset);
|
|---|
| 1446 | OffsetRect(&item->statebitmap,xOffset,yOffset);
|
|---|
| 1447 | }
|
|---|
| 1448 | infoPtr->uTotalWidth = MAX(infoPtr->uTotalWidth,item->rect.right+infoPtr->lefttop.x);
|
|---|
| 1449 |
|
|---|
| 1450 | if (((y >= view.top) && (y < view.bottom)) || ((y+height > view.top) && (y+height <= view.bottom)))
|
|---|
| 1451 | {
|
|---|
| 1452 | item->visible = TRUE;
|
|---|
| 1453 | if (!infoPtr->firstVisible)
|
|---|
| 1454 | infoPtr->firstVisible = item->hItem;
|
|---|
| 1455 | } else item->visible = FALSE;
|
|---|
| 1456 |
|
|---|
| 1457 | /* look up next item */
|
|---|
| 1458 |
|
|---|
| 1459 | if ((item->firstChild) && (item->state & TVIS_EXPANDED))
|
|---|
| 1460 | {
|
|---|
| 1461 | iItem = (INT)item->firstChild;
|
|---|
| 1462 | indent++;
|
|---|
| 1463 | x += infoPtr->uIndent;
|
|---|
| 1464 | } else
|
|---|
| 1465 | {
|
|---|
| 1466 | iItem = (INT)item->sibling;
|
|---|
| 1467 | while ((!iItem) && (indent > 0))
|
|---|
| 1468 | {
|
|---|
| 1469 | indent--;
|
|---|
| 1470 | x -= infoPtr->uIndent;
|
|---|
| 1471 | item = &infoPtr->items[(INT)item->parent];
|
|---|
| 1472 | iItem = (INT)item->sibling;
|
|---|
| 1473 | }
|
|---|
| 1474 | }
|
|---|
| 1475 | y += height;
|
|---|
| 1476 | } /* while */
|
|---|
| 1477 |
|
|---|
| 1478 | if (ownDC) ReleaseDC(hwnd,hdc);
|
|---|
| 1479 |
|
|---|
| 1480 | infoPtr->uInternalStatus &= ~TV_CALCALL;
|
|---|
| 1481 | infoPtr->uTotalHeight = y;
|
|---|
| 1482 |
|
|---|
| 1483 | //check cx and cy
|
|---|
| 1484 | yDiff = xDiff = 0;
|
|---|
| 1485 |
|
|---|
| 1486 | maxYScroll = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
|
|---|
| 1487 | if (maxYScroll < 0) maxYScroll = 0;
|
|---|
| 1488 | if (infoPtr->lefttop.y > maxYScroll)
|
|---|
| 1489 | {
|
|---|
| 1490 | INT mod = maxYScroll % infoPtr->uVScrollStep;
|
|---|
| 1491 |
|
|---|
| 1492 | if (mod > 0) maxYScroll += infoPtr->uVScrollStep-mod;
|
|---|
| 1493 | yDiff = infoPtr->lefttop.y-maxYScroll;
|
|---|
| 1494 | infoPtr->lefttop.y = maxYScroll;
|
|---|
| 1495 | }
|
|---|
| 1496 |
|
|---|
| 1497 | maxXScroll = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
|
|---|
| 1498 | if (maxXScroll < 0) maxXScroll = 0;
|
|---|
| 1499 | if (infoPtr->lefttop.x > maxXScroll)
|
|---|
| 1500 | {
|
|---|
| 1501 | xDiff = infoPtr->lefttop.x-maxXScroll;
|
|---|
| 1502 | infoPtr->lefttop.x = maxXScroll;
|
|---|
| 1503 | }
|
|---|
| 1504 |
|
|---|
| 1505 | changedLeftTop = xDiff || yDiff;
|
|---|
| 1506 | if (changedLeftTop)
|
|---|
| 1507 | {
|
|---|
| 1508 | iItem = (INT)infoPtr->TopRootItem;
|
|---|
| 1509 | item = NULL;
|
|---|
| 1510 | indent = 0;
|
|---|
| 1511 | infoPtr->firstVisible = 0;
|
|---|
| 1512 |
|
|---|
| 1513 | while (iItem)
|
|---|
| 1514 | {
|
|---|
| 1515 | item = &infoPtr->items[iItem];
|
|---|
| 1516 | OffsetRect(&item->rect,xDiff,yDiff);
|
|---|
| 1517 | OffsetRect(&item->text,xDiff,yDiff);
|
|---|
| 1518 | OffsetRect(&item->expandBox,xDiff,yDiff);
|
|---|
| 1519 | OffsetRect(&item->bitmap,xDiff,yDiff);
|
|---|
| 1520 | OffsetRect(&item->statebitmap,xDiff,yDiff);
|
|---|
| 1521 |
|
|---|
| 1522 | y = view.top+item->rect.top;
|
|---|
| 1523 | if (((y >= view.top) && (y < view.bottom)) || ((y+height > view.top) && (y+height <= view.bottom)))
|
|---|
| 1524 | {
|
|---|
| 1525 | item->visible = TRUE;
|
|---|
| 1526 | if (!infoPtr->firstVisible)
|
|---|
| 1527 | infoPtr->firstVisible = item->hItem;
|
|---|
| 1528 | } else item->visible = FALSE;
|
|---|
| 1529 |
|
|---|
| 1530 | if ((item->firstChild) && (item->state & TVIS_EXPANDED))
|
|---|
| 1531 | {
|
|---|
| 1532 | iItem = (INT)item->firstChild;
|
|---|
| 1533 | indent++;
|
|---|
| 1534 | } else
|
|---|
| 1535 | {
|
|---|
| 1536 | iItem = (INT)item->sibling;
|
|---|
| 1537 | while ((!iItem) && (indent > 0))
|
|---|
| 1538 | {
|
|---|
| 1539 | indent--;
|
|---|
| 1540 | item = &infoPtr->items[(INT)item->parent];
|
|---|
| 1541 | iItem = (INT)item->sibling;
|
|---|
| 1542 | }
|
|---|
| 1543 | }
|
|---|
| 1544 | } /* while */
|
|---|
| 1545 | }
|
|---|
| 1546 |
|
|---|
| 1547 | if (!(dwStyle & TVS_NOSCROLL) && (infoPtr->uVisibleHeight > 0) && (infoPtr->uVisibleWidth > 0))
|
|---|
| 1548 | {
|
|---|
| 1549 | if (infoPtr->uTotalHeight > infoPtr->uVisibleHeight)
|
|---|
| 1550 | {
|
|---|
| 1551 | SCROLLINFO info;
|
|---|
| 1552 | INT visH = ((INT)(infoPtr->uVisibleHeight/infoPtr->uVScrollStep))*infoPtr->uVScrollStep;
|
|---|
| 1553 |
|
|---|
| 1554 | info.cbSize = sizeof(info);
|
|---|
| 1555 | info.nMin = 0;
|
|---|
| 1556 | info.nMax = infoPtr->uTotalHeight-1;
|
|---|
| 1557 | info.nPos = infoPtr->lefttop.y;
|
|---|
| 1558 | info.nPage = visH;
|
|---|
| 1559 | info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
|
|---|
| 1560 | infoPtr->uInternalStatus |= TV_VSCROLL;
|
|---|
| 1561 | SetScrollInfo(hwnd,SB_VERT,&info,TRUE);
|
|---|
| 1562 | } else
|
|---|
| 1563 | {
|
|---|
| 1564 | if (infoPtr->uInternalStatus & TV_VSCROLL)
|
|---|
| 1565 | ShowScrollBar(hwnd,SB_VERT,FALSE);
|
|---|
| 1566 | infoPtr->uInternalStatus &= ~TV_VSCROLL;
|
|---|
| 1567 | }
|
|---|
| 1568 | if (!(dwStyle & TVS_NOHSCROLL) && (infoPtr->uTotalWidth > infoPtr->uVisibleWidth))
|
|---|
| 1569 | {
|
|---|
| 1570 | SCROLLINFO info;
|
|---|
| 1571 |
|
|---|
| 1572 | info.cbSize = sizeof(info);
|
|---|
| 1573 | info.nMin = 0;
|
|---|
| 1574 | info.nMax = infoPtr->uTotalWidth-1;
|
|---|
| 1575 | info.nPos = infoPtr->lefttop.x;
|
|---|
| 1576 | info.nPage = MAX(infoPtr->uVisibleWidth,1);
|
|---|
| 1577 | info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
|
|---|
| 1578 | infoPtr->uInternalStatus |= TV_HSCROLL;
|
|---|
| 1579 | SetScrollInfo(hwnd,SB_HORZ,&info,TRUE);
|
|---|
| 1580 | } else
|
|---|
| 1581 | {
|
|---|
| 1582 | if (infoPtr->uInternalStatus & TV_HSCROLL)
|
|---|
| 1583 | ShowScrollBar(hwnd,SB_HORZ,FALSE);
|
|---|
| 1584 | infoPtr->uInternalStatus &= ~TV_HSCROLL;
|
|---|
| 1585 | }
|
|---|
| 1586 | } else
|
|---|
| 1587 | {
|
|---|
| 1588 | if (infoPtr->uInternalStatus & (TV_VSCROLL | TV_HSCROLL))
|
|---|
| 1589 | ShowScrollBar(hwnd,SB_BOTH,FALSE);
|
|---|
| 1590 | infoPtr->uInternalStatus &= ~(TV_VSCROLL | TV_HSCROLL);
|
|---|
| 1591 | }
|
|---|
| 1592 |
|
|---|
| 1593 | return changedLeftTop;
|
|---|
| 1594 | }
|
|---|
| 1595 |
|
|---|
| 1596 | static void
|
|---|
| 1597 | TREEVIEW_Draw(HWND hwnd,HDC hdc,RECT *updateRect)
|
|---|
| 1598 | {
|
|---|
| 1599 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1600 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 1601 | HBRUSH hbrBk;
|
|---|
| 1602 | RECT rect;
|
|---|
| 1603 | TREEVIEW_ITEM *item;
|
|---|
| 1604 | INT iItem,indent;
|
|---|
| 1605 | BOOL visFound = FALSE;
|
|---|
| 1606 | HPEN hNewPen,hOldPen;
|
|---|
| 1607 |
|
|---|
| 1608 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,FALSE);
|
|---|
| 1609 |
|
|---|
| 1610 | GetClientRect (hwnd, &rect);
|
|---|
| 1611 | if ((rect.left == rect.right) || (rect.top == rect.bottom)) return;
|
|---|
| 1612 |
|
|---|
| 1613 | infoPtr->cdmode = TREEVIEW_SendCustomDrawNotify(hwnd, CDDS_PREPAINT, hdc, rect);
|
|---|
| 1614 |
|
|---|
| 1615 | if (infoPtr->cdmode == CDRF_SKIPDEFAULT) return;
|
|---|
| 1616 |
|
|---|
| 1617 | //draw items
|
|---|
| 1618 |
|
|---|
| 1619 | hNewPen = CreatePen(PS_DOT,0,infoPtr->clrLine);
|
|---|
| 1620 |
|
|---|
| 1621 | iItem = (INT)infoPtr->TopRootItem;
|
|---|
| 1622 | indent = 0;
|
|---|
| 1623 |
|
|---|
| 1624 | while (iItem)
|
|---|
| 1625 | {
|
|---|
| 1626 | item = &infoPtr->items[iItem];
|
|---|
| 1627 | if (item->visible)
|
|---|
| 1628 | {
|
|---|
| 1629 | if (updateRect && IntersectRect(NULL,&item->rect,updateRect))
|
|---|
| 1630 | {
|
|---|
| 1631 | TREEVIEW_DrawItem(hwnd,hdc,item,dwStyle,infoPtr);
|
|---|
| 1632 | visFound = TRUE;
|
|---|
| 1633 | } else if (updateRect && (item->rect.top >= updateRect->bottom)) break;
|
|---|
| 1634 | } else if (visFound) break;
|
|---|
| 1635 | if (!visFound && (dwStyle & TVS_HASLINES) && (dwStyle & TVS_LINESATROOT))
|
|---|
| 1636 | {
|
|---|
| 1637 | //draw vertical connections
|
|---|
| 1638 | hOldPen = SelectObject(hdc,hNewPen);
|
|---|
| 1639 | TREEVIEW_DrawVLines(hdc,infoPtr,item);
|
|---|
| 1640 | SelectObject(hdc,hOldPen);
|
|---|
| 1641 | }
|
|---|
| 1642 | if (item->firstChild && (item->state & TVIS_EXPANDED))
|
|---|
| 1643 | {
|
|---|
| 1644 | iItem = (INT)item->firstChild;
|
|---|
| 1645 | indent++;
|
|---|
| 1646 | } else
|
|---|
| 1647 | {
|
|---|
| 1648 | iItem = (INT)item->sibling;
|
|---|
| 1649 | while (!iItem && (indent > 0))
|
|---|
| 1650 | {
|
|---|
| 1651 | item = &infoPtr->items[(INT)item->parent];
|
|---|
| 1652 | iItem = (INT)item->sibling;
|
|---|
| 1653 | indent--;
|
|---|
| 1654 | }
|
|---|
| 1655 | }
|
|---|
| 1656 | }
|
|---|
| 1657 |
|
|---|
| 1658 | DeleteObject(hNewPen);
|
|---|
| 1659 |
|
|---|
| 1660 | if (infoPtr->cdmode & CDRF_NOTIFYPOSTPAINT)
|
|---|
| 1661 | infoPtr->cdmode = TREEVIEW_SendCustomDrawNotify(hwnd, CDDS_POSTPAINT, hdc, rect);
|
|---|
| 1662 | }
|
|---|
| 1663 |
|
|---|
| 1664 | static LRESULT TREEVIEW_SetRedraw(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 1665 | {
|
|---|
| 1666 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1667 |
|
|---|
| 1668 | if (wParam)
|
|---|
| 1669 | {
|
|---|
| 1670 | if (!(infoPtr->uInternalStatus & TV_NOREDRAW)) return 0;
|
|---|
| 1671 | infoPtr->uInternalStatus &= ~TV_NOREDRAW;
|
|---|
| 1672 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 1673 | TREEVIEW_Refresh(hwnd);
|
|---|
| 1674 | } else
|
|---|
| 1675 | {
|
|---|
| 1676 | infoPtr->uInternalStatus |= TV_NOREDRAW;
|
|---|
| 1677 | }
|
|---|
| 1678 |
|
|---|
| 1679 | return 0;
|
|---|
| 1680 | }
|
|---|
| 1681 |
|
|---|
| 1682 |
|
|---|
| 1683 | static LRESULT
|
|---|
| 1684 | TREEVIEW_HandleTimer (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 1685 | {
|
|---|
| 1686 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1687 |
|
|---|
| 1688 | switch (wParam)
|
|---|
| 1689 | {
|
|---|
| 1690 | case TV_REFRESH_TIMER:
|
|---|
| 1691 | KillTimer (hwnd, TV_REFRESH_TIMER);
|
|---|
| 1692 | infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
|
|---|
| 1693 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 1694 | TREEVIEW_Refresh(hwnd);
|
|---|
| 1695 | return 0;
|
|---|
| 1696 |
|
|---|
| 1697 | case TV_EDIT_TIMER:
|
|---|
| 1698 | KillTimer (hwnd, TV_EDIT_TIMER);
|
|---|
| 1699 | infoPtr->Timer &= ~TV_EDIT_TIMER_SET;
|
|---|
| 1700 | if (infoPtr->editItem)
|
|---|
| 1701 | TREEVIEW_EditLabel(hwnd,infoPtr->editItem,TRUE);
|
|---|
| 1702 | return 0;
|
|---|
| 1703 |
|
|---|
| 1704 | case TV_ISEARCH_TIMER:
|
|---|
| 1705 | KillTimer(hwnd,TV_ISEARCH_TIMER);
|
|---|
| 1706 | infoPtr->Timer &= ~TV_ISEARCH_TIMER_SET;
|
|---|
| 1707 | return 0;
|
|---|
| 1708 |
|
|---|
| 1709 | case TV_INFOTIP_TIMER:
|
|---|
| 1710 | TREEVIEW_CheckInfoTip(hwnd);
|
|---|
| 1711 | return 0;
|
|---|
| 1712 | }
|
|---|
| 1713 |
|
|---|
| 1714 | return 1;
|
|---|
| 1715 | }
|
|---|
| 1716 |
|
|---|
| 1717 | static void TREEVIEW_QueueRefresh(HWND hwnd)
|
|---|
| 1718 |
|
|---|
| 1719 | {
|
|---|
| 1720 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1721 |
|
|---|
| 1722 | if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
|
|---|
| 1723 | KillTimer (hwnd, TV_REFRESH_TIMER);
|
|---|
| 1724 |
|
|---|
| 1725 | if (infoPtr->uInternalStatus & TV_NOREDRAW)
|
|---|
| 1726 | {
|
|---|
| 1727 | infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
|
|---|
| 1728 |
|
|---|
| 1729 | return;
|
|---|
| 1730 | }
|
|---|
| 1731 |
|
|---|
| 1732 | SetTimer (hwnd, TV_REFRESH_TIMER, TV_REFRESH_DELAY, 0);
|
|---|
| 1733 | infoPtr->Timer |= TV_REFRESH_TIMER_SET;
|
|---|
| 1734 | }
|
|---|
| 1735 |
|
|---|
| 1736 | static BOOL TREEVIEW_UnqueueRefresh(HWND hwnd,BOOL calc,BOOL refresh)
|
|---|
| 1737 | {
|
|---|
| 1738 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1739 |
|
|---|
| 1740 | if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
|
|---|
| 1741 | {
|
|---|
| 1742 | KillTimer (hwnd, TV_REFRESH_TIMER);
|
|---|
| 1743 | infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
|
|---|
| 1744 | if (calc) TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 1745 | if (refresh)
|
|---|
| 1746 | {
|
|---|
| 1747 | TREEVIEW_Refresh(hwnd);
|
|---|
| 1748 | UpdateWindow(hwnd);
|
|---|
| 1749 | }
|
|---|
| 1750 |
|
|---|
| 1751 | return TRUE;
|
|---|
| 1752 | }
|
|---|
| 1753 |
|
|---|
| 1754 | return FALSE;
|
|---|
| 1755 | }
|
|---|
| 1756 |
|
|---|
| 1757 | static LRESULT
|
|---|
| 1758 | TREEVIEW_GetItem(HWND hwnd,WPARAM wParam,LPARAM lParam,BOOL unicode)
|
|---|
| 1759 | {
|
|---|
| 1760 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1761 | LPTVITEMEXW tvItem;
|
|---|
| 1762 | TREEVIEW_ITEM *wineItem;
|
|---|
| 1763 | INT iItem;
|
|---|
| 1764 |
|
|---|
| 1765 | tvItem = (LPTVITEMEXW)lParam;
|
|---|
| 1766 | iItem = (INT)tvItem->hItem;
|
|---|
| 1767 |
|
|---|
| 1768 | wineItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM)iItem);
|
|---|
| 1769 | if (!wineItem) return FALSE;
|
|---|
| 1770 |
|
|---|
| 1771 | if (tvItem->mask & TVIF_CHILDREN)
|
|---|
| 1772 | tvItem->cChildren = TREEVIEW_HasChildren(hwnd, wineItem);
|
|---|
| 1773 |
|
|---|
| 1774 | if (tvItem->mask & TVIF_HANDLE)
|
|---|
| 1775 | tvItem->hItem = wineItem->hItem;
|
|---|
| 1776 |
|
|---|
| 1777 | if (tvItem->mask & TVIF_IMAGE)
|
|---|
| 1778 | {
|
|---|
| 1779 | if (wineItem->iImage == I_IMAGECALLBACK)
|
|---|
| 1780 | tvItem->iImage = TREEVIEW_CallbackImage(hwnd,wineItem);
|
|---|
| 1781 | else
|
|---|
| 1782 | tvItem->iImage = wineItem->iImage;
|
|---|
| 1783 | }
|
|---|
| 1784 |
|
|---|
| 1785 | if (tvItem->mask & TVIF_INTEGRAL)
|
|---|
| 1786 | tvItem->iIntegral = wineItem->iIntegral;
|
|---|
| 1787 |
|
|---|
| 1788 | // undocumented: windows ignores TVIF_PARAM and
|
|---|
| 1789 | // always sets lParam
|
|---|
| 1790 | tvItem->lParam = wineItem->lParam;
|
|---|
| 1791 |
|
|---|
| 1792 | if (tvItem->mask & TVIF_SELECTEDIMAGE)
|
|---|
| 1793 | {
|
|---|
| 1794 | if (wineItem->iSelectedImage == I_IMAGECALLBACK)
|
|---|
| 1795 | tvItem->iSelectedImage = TREEVIEW_CallbackSelectedImage(hwnd,wineItem);
|
|---|
| 1796 | else
|
|---|
| 1797 | tvItem->iSelectedImage = wineItem->iSelectedImage;
|
|---|
| 1798 | }
|
|---|
| 1799 |
|
|---|
| 1800 | if (tvItem->mask & TVIF_STATE)
|
|---|
| 1801 | tvItem->state = wineItem->state & tvItem->stateMask;
|
|---|
| 1802 |
|
|---|
| 1803 | if (tvItem->mask & TVIF_TEXT)
|
|---|
| 1804 | {
|
|---|
| 1805 | WCHAR* text;
|
|---|
| 1806 | BOOL mustFree = FALSE;
|
|---|
| 1807 |
|
|---|
| 1808 | if (wineItem->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 1809 | text = TREEVIEW_CallbackText(hwnd,wineItem,&mustFree);
|
|---|
| 1810 | else
|
|---|
| 1811 | text = wineItem->pszText;
|
|---|
| 1812 |
|
|---|
| 1813 | if (unicode)
|
|---|
| 1814 | lstrcpynW(tvItem->pszText,text,tvItem->cchTextMax);
|
|---|
| 1815 | else
|
|---|
| 1816 | lstrcpynWtoA((LPSTR)tvItem->pszText,text,tvItem->cchTextMax);
|
|---|
| 1817 | if (mustFree) COMCTL32_Free(text);
|
|---|
| 1818 | }
|
|---|
| 1819 |
|
|---|
| 1820 | return TRUE;
|
|---|
| 1821 | }
|
|---|
| 1822 |
|
|---|
| 1823 |
|
|---|
| 1824 |
|
|---|
| 1825 | /* FIXME: check implementation of TVGN_NEXT/TVGN_NEXTVISIBLE */
|
|---|
| 1826 |
|
|---|
| 1827 | static LRESULT
|
|---|
| 1828 | TREEVIEW_GetNextItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 1829 |
|
|---|
| 1830 | {
|
|---|
| 1831 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1832 | TREEVIEW_ITEM *wineItem, *returnItem;
|
|---|
| 1833 | INT iItem, retval, flag;
|
|---|
| 1834 |
|
|---|
| 1835 | flag = (INT) wParam;
|
|---|
| 1836 | iItem = (INT) lParam;
|
|---|
| 1837 | retval = 0;
|
|---|
| 1838 | switch (flag)
|
|---|
| 1839 | {
|
|---|
| 1840 | case TVGN_CHILD: /* Special case: child of 0 is root */
|
|---|
| 1841 | if (iItem) break;
|
|---|
| 1842 |
|
|---|
| 1843 | case TVGN_ROOT:
|
|---|
| 1844 | retval = (INT)infoPtr->TopRootItem;
|
|---|
| 1845 | break;
|
|---|
| 1846 |
|
|---|
| 1847 | case TVGN_CARET:
|
|---|
| 1848 | retval = (INT)infoPtr->selectedItem;
|
|---|
| 1849 | break;
|
|---|
| 1850 |
|
|---|
| 1851 | case TVGN_FIRSTVISIBLE:
|
|---|
| 1852 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
|
|---|
| 1853 | retval = (INT)infoPtr->firstVisible;
|
|---|
| 1854 | break;
|
|---|
| 1855 |
|
|---|
| 1856 | case TVGN_DROPHILITE:
|
|---|
| 1857 | retval = (INT)infoPtr->dropItem;
|
|---|
| 1858 | break;
|
|---|
| 1859 | }
|
|---|
| 1860 |
|
|---|
| 1861 | if (retval) return retval;
|
|---|
| 1862 |
|
|---|
| 1863 | wineItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM)iItem);
|
|---|
| 1864 | returnItem = NULL;
|
|---|
| 1865 | if (!wineItem) return FALSE;
|
|---|
| 1866 |
|
|---|
| 1867 | switch (flag)
|
|---|
| 1868 | {
|
|---|
| 1869 | case TVGN_NEXT:
|
|---|
| 1870 | retval = (INT)wineItem->sibling;
|
|---|
| 1871 | break;
|
|---|
| 1872 |
|
|---|
| 1873 | case TVGN_PREVIOUS:
|
|---|
| 1874 | retval = (INT)wineItem->upsibling;
|
|---|
| 1875 | break;
|
|---|
| 1876 |
|
|---|
| 1877 | case TVGN_PARENT:
|
|---|
| 1878 | retval = (INT)wineItem->parent;
|
|---|
| 1879 | break;
|
|---|
| 1880 |
|
|---|
| 1881 | case TVGN_CHILD:
|
|---|
| 1882 | retval = (INT)wineItem->firstChild;
|
|---|
| 1883 | break;
|
|---|
| 1884 |
|
|---|
| 1885 | case TVGN_LASTVISIBLE:
|
|---|
| 1886 | returnItem = TREEVIEW_GetLastListItem (hwnd,infoPtr,wineItem);
|
|---|
| 1887 | break;
|
|---|
| 1888 |
|
|---|
| 1889 | case TVGN_NEXTVISIBLE:
|
|---|
| 1890 | returnItem = TREEVIEW_GetNextListItem (hwnd,infoPtr,wineItem);
|
|---|
| 1891 | break;
|
|---|
| 1892 |
|
|---|
| 1893 | case TVGN_PREVIOUSVISIBLE:
|
|---|
| 1894 | returnItem = TREEVIEW_GetPrevListItem (hwnd,infoPtr, wineItem);
|
|---|
| 1895 | break;
|
|---|
| 1896 |
|
|---|
| 1897 | default:
|
|---|
| 1898 | break;
|
|---|
| 1899 | }
|
|---|
| 1900 |
|
|---|
| 1901 | if (returnItem) return (INT)returnItem->hItem;
|
|---|
| 1902 |
|
|---|
| 1903 | return retval;
|
|---|
| 1904 | }
|
|---|
| 1905 |
|
|---|
| 1906 |
|
|---|
| 1907 | static LRESULT
|
|---|
| 1908 | TREEVIEW_GetCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 1909 | {
|
|---|
| 1910 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 1911 |
|
|---|
| 1912 | return (LRESULT) infoPtr->uNumItems;
|
|---|
| 1913 | }
|
|---|
| 1914 |
|
|---|
| 1915 | /***************************************************************************
|
|---|
| 1916 | * This method does the chaining of the insertion of a treeview item
|
|---|
| 1917 | * before an item.
|
|---|
| 1918 | * If parent is NULL, we're inserting at the root of the list.
|
|---|
| 1919 | */
|
|---|
| 1920 | static void TREEVIEW_InsertBefore(
|
|---|
| 1921 | TREEVIEW_INFO *infoPtr,
|
|---|
| 1922 | TREEVIEW_ITEM *newItem,
|
|---|
| 1923 | TREEVIEW_ITEM *sibling,
|
|---|
| 1924 | TREEVIEW_ITEM *parent)
|
|---|
| 1925 | {
|
|---|
| 1926 | HTREEITEM siblingHandle = 0;
|
|---|
| 1927 | HTREEITEM upSiblingHandle = 0;
|
|---|
| 1928 | TREEVIEW_ITEM *upSibling = NULL;
|
|---|
| 1929 |
|
|---|
| 1930 | // if (newItem == NULL)
|
|---|
| 1931 | // ERR(treeview, "NULL newItem, impossible condition\n");
|
|---|
| 1932 |
|
|---|
| 1933 | // if (parent == NULL)
|
|---|
| 1934 | // ERR(treeview, "NULL parent, impossible condition\n");
|
|---|
| 1935 |
|
|---|
| 1936 | if (sibling != NULL) /* Insert before this sibling for this parent */
|
|---|
| 1937 | {
|
|---|
| 1938 | /* Store the new item sibling up sibling and sibling tem handle */
|
|---|
| 1939 | siblingHandle = sibling->hItem;
|
|---|
| 1940 | upSiblingHandle = sibling->upsibling;
|
|---|
| 1941 | /* As well as a pointer to the upsibling sibling object */
|
|---|
| 1942 | if ( (INT)sibling->upsibling != 0 )
|
|---|
| 1943 | upSibling = &infoPtr->items[(INT)sibling->upsibling];
|
|---|
| 1944 |
|
|---|
| 1945 | /* Adjust the sibling pointer */
|
|---|
| 1946 | sibling->upsibling = newItem->hItem;
|
|---|
| 1947 |
|
|---|
| 1948 | /* Adjust the new item pointers */
|
|---|
| 1949 | newItem->upsibling = upSiblingHandle;
|
|---|
| 1950 | newItem->sibling = siblingHandle;
|
|---|
| 1951 |
|
|---|
| 1952 | /* Adjust the up sibling pointer */
|
|---|
| 1953 | if ( upSibling != NULL )
|
|---|
| 1954 | upSibling->sibling = newItem->hItem;
|
|---|
| 1955 | else
|
|---|
| 1956 | if (parent)
|
|---|
| 1957 | /* this item is the first child of this parent, adjust parent pointers */
|
|---|
| 1958 | parent->firstChild = newItem->hItem;
|
|---|
| 1959 | else infoPtr->TopRootItem = newItem->hItem;
|
|---|
| 1960 | }
|
|---|
| 1961 | else /* Insert as first child of this parent */
|
|---|
| 1962 | if (parent)
|
|---|
| 1963 | parent->firstChild = newItem->hItem;
|
|---|
| 1964 | }
|
|---|
| 1965 |
|
|---|
| 1966 | /***************************************************************************
|
|---|
| 1967 | * This method does the chaining of the insertion of a treeview item
|
|---|
| 1968 | * If parent is NULL, we're inserting at the root of the list.
|
|---|
| 1969 | * after an item.
|
|---|
| 1970 | */
|
|---|
| 1971 | static void TREEVIEW_InsertAfter(
|
|---|
| 1972 | TREEVIEW_INFO *infoPtr,
|
|---|
| 1973 | TREEVIEW_ITEM *newItem,
|
|---|
| 1974 | TREEVIEW_ITEM *upSibling,
|
|---|
| 1975 | TREEVIEW_ITEM *parent)
|
|---|
| 1976 | {
|
|---|
| 1977 | HTREEITEM upSiblingHandle = 0;
|
|---|
| 1978 | HTREEITEM siblingHandle = 0;
|
|---|
| 1979 | TREEVIEW_ITEM *sibling = NULL;
|
|---|
| 1980 |
|
|---|
| 1981 | // if (newItem == NULL)
|
|---|
| 1982 | // ERR(treeview, "NULL newItem, impossible condition\n");
|
|---|
| 1983 |
|
|---|
| 1984 | // if (parent == NULL)
|
|---|
| 1985 | // ERR(treeview, "NULL parent, impossible condition\n");
|
|---|
| 1986 |
|
|---|
| 1987 | if (upSibling != NULL) /* Insert after this upsibling for this parent */
|
|---|
| 1988 | {
|
|---|
| 1989 | /* Store the new item up sibling and sibling item handle */
|
|---|
| 1990 | upSiblingHandle = upSibling->hItem;
|
|---|
| 1991 | siblingHandle = upSibling->sibling;
|
|---|
| 1992 | /* As well as a pointer to the upsibling sibling object */
|
|---|
| 1993 | if ( (INT)upSibling->sibling != 0 )
|
|---|
| 1994 | sibling = &infoPtr->items[(INT)upSibling->sibling];
|
|---|
| 1995 |
|
|---|
| 1996 | /* Adjust the up sibling pointer */
|
|---|
| 1997 | upSibling->sibling = newItem->hItem;
|
|---|
| 1998 |
|
|---|
| 1999 | /* Adjust the new item pointers */
|
|---|
| 2000 | newItem->upsibling = upSiblingHandle;
|
|---|
| 2001 | newItem->sibling = siblingHandle;
|
|---|
| 2002 |
|
|---|
| 2003 | /* Adjust the sibling pointer */
|
|---|
| 2004 | if ( sibling != NULL )
|
|---|
| 2005 | sibling->upsibling = newItem->hItem;
|
|---|
| 2006 | /*
|
|---|
| 2007 | else
|
|---|
| 2008 | newItem is the last of the level, nothing else to do
|
|---|
| 2009 | */
|
|---|
| 2010 | }
|
|---|
| 2011 | else /* Insert as first child of this parent */
|
|---|
| 2012 | if (parent)
|
|---|
| 2013 | parent->firstChild = newItem->hItem;
|
|---|
| 2014 | }
|
|---|
| 2015 |
|
|---|
| 2016 | /***************************************************************************
|
|---|
| 2017 | * Forward the DPA local callback to the treeview owner callback
|
|---|
| 2018 | */
|
|---|
| 2019 | static INT WINAPI TREEVIEW_CallBackCompare(LPVOID first,LPVOID second,LPARAM tvInfoPtr)
|
|---|
| 2020 | {
|
|---|
| 2021 | /* Forward the call to the client define callback */
|
|---|
| 2022 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr((HWND)tvInfoPtr);
|
|---|
| 2023 |
|
|---|
| 2024 | return (infoPtr->pCallBackSort->lpfnCompare)(
|
|---|
| 2025 | ((TREEVIEW_ITEM*)first)->lParam,
|
|---|
| 2026 | ((TREEVIEW_ITEM*)second)->lParam,
|
|---|
| 2027 | infoPtr->pCallBackSort->lParam);
|
|---|
| 2028 | }
|
|---|
| 2029 |
|
|---|
| 2030 | /***************************************************************************
|
|---|
| 2031 | * Treeview native sort routine: sort on item text.
|
|---|
| 2032 | */
|
|---|
| 2033 | static INT WINAPI TREEVIEW_SortOnName(LPVOID first,LPVOID second,LPARAM tvInfoPtr)
|
|---|
| 2034 | {
|
|---|
| 2035 | HWND hwnd = (HWND)tvInfoPtr;
|
|---|
| 2036 | WCHAR *txt1,*txt2;
|
|---|
| 2037 | TREEVIEW_ITEM *item;
|
|---|
| 2038 | INT res;
|
|---|
| 2039 | BOOL mustFree1 = FALSE,mustFree2 = FALSE;
|
|---|
| 2040 |
|
|---|
| 2041 | item = (TREEVIEW_ITEM*)first;
|
|---|
| 2042 | if (item->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 2043 | txt1 = TREEVIEW_CallbackText(hwnd,item,&mustFree1);
|
|---|
| 2044 | else
|
|---|
| 2045 | txt1 = item->pszText;
|
|---|
| 2046 |
|
|---|
| 2047 | item = (TREEVIEW_ITEM*)second;
|
|---|
| 2048 | if (item->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 2049 | txt2 = TREEVIEW_CallbackText(hwnd,item,&mustFree2);
|
|---|
| 2050 | else
|
|---|
| 2051 | txt2 = item->pszText;
|
|---|
| 2052 |
|
|---|
| 2053 | res = lstrcmpiW(txt1,txt2); //CB: or lstrcmpW?
|
|---|
| 2054 | if (mustFree1) COMCTL32_Free(txt1);
|
|---|
| 2055 | if (mustFree2) COMCTL32_Free(txt2);
|
|---|
| 2056 |
|
|---|
| 2057 | return res;
|
|---|
| 2058 | }
|
|---|
| 2059 |
|
|---|
| 2060 | /***************************************************************************
|
|---|
| 2061 | * Setup the treeview structure with regards of the sort method
|
|---|
| 2062 | * and sort the children of the TV item specified in lParam
|
|---|
| 2063 | * fRecurse: currently unused. Should be zero.
|
|---|
| 2064 | * parent: if pSort!=NULL, should equal pSort->hParent.
|
|---|
| 2065 | * otherwise, item which child items are to be sorted.
|
|---|
| 2066 | * pSort: sort method info. if NULL, sort on item text.
|
|---|
| 2067 | * if non-NULL, sort on item's lParam content, and let the
|
|---|
| 2068 | * application decide what that means. See also TVM_SORTCHILDRENCB.
|
|---|
| 2069 | */
|
|---|
| 2070 |
|
|---|
| 2071 | static LRESULT WINAPI TREEVIEW_Sort(HWND hwnd,BOOL fRecurse,HTREEITEM parent,LPTVSORTCB pSort)
|
|---|
| 2072 | {
|
|---|
| 2073 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2074 | TREEVIEW_ITEM *sortMe = NULL; /* Node for which we sort the children */
|
|---|
| 2075 | INT cChildren;
|
|---|
| 2076 | HTREEITEM hti;
|
|---|
| 2077 | BOOL root = FALSE;
|
|---|
| 2078 |
|
|---|
| 2079 | /* Obtain the TVSORTBC struct */
|
|---|
| 2080 | infoPtr->pCallBackSort = pSort;
|
|---|
| 2081 |
|
|---|
| 2082 | /* undocumented feature: TVI_ROOT means `sort the whole tree' */
|
|---|
| 2083 |
|
|---|
| 2084 | if ((parent == TVI_ROOT) || (parent == 0))
|
|---|
| 2085 | {
|
|---|
| 2086 | root = TRUE;
|
|---|
| 2087 | parent = infoPtr->TopRootItem;
|
|---|
| 2088 | }
|
|---|
| 2089 |
|
|---|
| 2090 | /* Check for a valid handle to the parent item */
|
|---|
| 2091 | sortMe = TREEVIEW_ValidItem(infoPtr,parent);
|
|---|
| 2092 | if (!sortMe)
|
|---|
| 2093 | return FALSE;
|
|---|
| 2094 |
|
|---|
| 2095 | cChildren = 0;
|
|---|
| 2096 | for(hti = root ? sortMe->hItem:sortMe->firstChild; hti; hti = infoPtr->items[(INT)hti].sibling)
|
|---|
| 2097 | cChildren++;
|
|---|
| 2098 |
|
|---|
| 2099 | /* Make sure there is something to sort */
|
|---|
| 2100 | if (cChildren > 1)
|
|---|
| 2101 | {
|
|---|
| 2102 | /* pointer organization */
|
|---|
| 2103 | HDPA sortList = DPA_Create(cChildren);
|
|---|
| 2104 | HTREEITEM itemHandle = root ? sortMe->hItem:sortMe->firstChild;
|
|---|
| 2105 | TREEVIEW_ITEM *itemPtr = &infoPtr->items[(INT)itemHandle];
|
|---|
| 2106 |
|
|---|
| 2107 | /* TREEVIEW_ITEM rechaining */
|
|---|
| 2108 | INT count = 0;
|
|---|
| 2109 | VOID *item = 0;
|
|---|
| 2110 | VOID *nextItem = 0;
|
|---|
| 2111 | VOID *prevItem = 0;
|
|---|
| 2112 |
|
|---|
| 2113 | /* Build the list of item to sort */
|
|---|
| 2114 | do
|
|---|
| 2115 | {
|
|---|
| 2116 | itemPtr = &infoPtr->items[(INT)itemHandle];
|
|---|
| 2117 | DPA_InsertPtr(
|
|---|
| 2118 | sortList, /* the list */
|
|---|
| 2119 | cChildren+1, /* force the insertion to be an append */
|
|---|
| 2120 | itemPtr); /* the ptr to store */
|
|---|
| 2121 |
|
|---|
| 2122 | /* Get the next sibling */
|
|---|
| 2123 | itemHandle = itemPtr->sibling;
|
|---|
| 2124 | } while (itemHandle != NULL);
|
|---|
| 2125 |
|
|---|
| 2126 | /* let DPA perform the sort activity */
|
|---|
| 2127 | if (pSort)
|
|---|
| 2128 | DPA_Sort(
|
|---|
| 2129 | sortList, /* what */
|
|---|
| 2130 | TREEVIEW_CallBackCompare, /* how */
|
|---|
| 2131 | hwnd); /* owner */
|
|---|
| 2132 | else
|
|---|
| 2133 | DPA_Sort (
|
|---|
| 2134 | sortList, /* what */
|
|---|
| 2135 | TREEVIEW_SortOnName, /* how */
|
|---|
| 2136 | hwnd); /* owner */
|
|---|
| 2137 |
|
|---|
| 2138 | /*
|
|---|
| 2139 | * Reorganized TREEVIEW_ITEM structures.
|
|---|
| 2140 | * Note that we know we have at least two elements.
|
|---|
| 2141 | */
|
|---|
| 2142 |
|
|---|
| 2143 | /* Get the first item and get ready to start... */
|
|---|
| 2144 | item = DPA_GetPtr(sortList, count++);
|
|---|
| 2145 | while ((nextItem = DPA_GetPtr(sortList, count++)) != NULL)
|
|---|
| 2146 | {
|
|---|
| 2147 | /* link the two current item toghether */
|
|---|
| 2148 | ((TREEVIEW_ITEM*)item)->sibling = ((TREEVIEW_ITEM*)nextItem)->hItem;
|
|---|
| 2149 | ((TREEVIEW_ITEM*)nextItem)->upsibling = ((TREEVIEW_ITEM*)item)->hItem;
|
|---|
| 2150 |
|
|---|
| 2151 | if (prevItem == NULL) /* this is the first item, update the parent */
|
|---|
| 2152 | {
|
|---|
| 2153 | if (root)
|
|---|
| 2154 | infoPtr->TopRootItem = ((TREEVIEW_ITEM*)item)->hItem;
|
|---|
| 2155 | else
|
|---|
| 2156 | sortMe->firstChild = ((TREEVIEW_ITEM*)item)->hItem;
|
|---|
| 2157 | ((TREEVIEW_ITEM*)item)->upsibling = NULL;
|
|---|
| 2158 | }
|
|---|
| 2159 | else /* fix the back chaining */
|
|---|
| 2160 | {
|
|---|
| 2161 | ((TREEVIEW_ITEM*)item)->upsibling = ((TREEVIEW_ITEM*)prevItem)->hItem;
|
|---|
| 2162 | }
|
|---|
| 2163 |
|
|---|
| 2164 | /* get ready for the next one */
|
|---|
| 2165 | prevItem = item;
|
|---|
| 2166 | item = nextItem;
|
|---|
| 2167 | }
|
|---|
| 2168 |
|
|---|
| 2169 | /* the last item is pointed to by item and never has a sibling */
|
|---|
| 2170 | ((TREEVIEW_ITEM*)item)->sibling = NULL;
|
|---|
| 2171 |
|
|---|
| 2172 | DPA_Destroy(sortList);
|
|---|
| 2173 | TREEVIEW_QueueRefresh(hwnd);
|
|---|
| 2174 |
|
|---|
| 2175 | return TRUE;
|
|---|
| 2176 | }
|
|---|
| 2177 | return FALSE;
|
|---|
| 2178 | }
|
|---|
| 2179 |
|
|---|
| 2180 | /***************************************************************************
|
|---|
| 2181 | * Setup the treeview structure with regards of the sort method
|
|---|
| 2182 | * and sort the children of the TV item specified in lParam
|
|---|
| 2183 | */
|
|---|
| 2184 | static LRESULT WINAPI TREEVIEW_SortChildrenCB(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 2185 | {
|
|---|
| 2186 | LPTVSORTCB pSort = (LPTVSORTCB) lParam;
|
|---|
| 2187 |
|
|---|
| 2188 | return TREEVIEW_Sort (hwnd, wParam, pSort->hParent, pSort);
|
|---|
| 2189 | }
|
|---|
| 2190 |
|
|---|
| 2191 |
|
|---|
| 2192 | /***************************************************************************
|
|---|
| 2193 | * Sort the children of the TV item specified in lParam.
|
|---|
| 2194 | */
|
|---|
| 2195 | static LRESULT WINAPI TREEVIEW_SortChildren(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 2196 | {
|
|---|
| 2197 | return TREEVIEW_Sort (hwnd, (BOOL) wParam, (HTREEITEM) lParam, NULL);
|
|---|
| 2198 | }
|
|---|
| 2199 |
|
|---|
| 2200 |
|
|---|
| 2201 | int ffs(int mask)
|
|---|
| 2202 | {
|
|---|
| 2203 | int bit;
|
|---|
| 2204 |
|
|---|
| 2205 | if (mask == 0)
|
|---|
| 2206 | return(0);
|
|---|
| 2207 | for (bit = 1; !(mask & 1); bit++)
|
|---|
| 2208 | mask >>= 1;
|
|---|
| 2209 | return(bit);
|
|---|
| 2210 | }
|
|---|
| 2211 |
|
|---|
| 2212 | /* the method used below isn't the most memory-friendly, but it avoids
|
|---|
| 2213 | a lot of memory reallocations */
|
|---|
| 2214 |
|
|---|
| 2215 | /* BTW: we waste handle 0; 0 is not an allowed handle. */
|
|---|
| 2216 |
|
|---|
| 2217 | static LRESULT
|
|---|
| 2218 | TREEVIEW_InsertItem(HWND hwnd,WPARAM wParam,LPARAM lParam,BOOL unicode)
|
|---|
| 2219 | {
|
|---|
| 2220 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2221 | TVINSERTSTRUCTW *ptdi;
|
|---|
| 2222 | TVITEMEXW *tvItem;
|
|---|
| 2223 | TREEVIEW_ITEM *wineItem, *parentItem, *prevsib, *sibItem;
|
|---|
| 2224 | INT iItem,i,len;
|
|---|
| 2225 |
|
|---|
| 2226 | if (infoPtr->hwndEdit) SetFocus(hwnd);
|
|---|
| 2227 |
|
|---|
| 2228 | /* Item to insert */
|
|---|
| 2229 | ptdi = (LPTVINSERTSTRUCTW)lParam;
|
|---|
| 2230 |
|
|---|
| 2231 | /* check if memory is available */
|
|---|
| 2232 |
|
|---|
| 2233 | if (infoPtr->uNumPtrsAlloced==0) {
|
|---|
| 2234 | infoPtr->items = (TREEVIEW_ITEM*)COMCTL32_Alloc (TVITEM_ALLOC*sizeof (TREEVIEW_ITEM));
|
|---|
| 2235 | infoPtr->freeList= (INT*)COMCTL32_Alloc (((TVITEM_ALLOC>>5)) * sizeof (INT));
|
|---|
| 2236 | infoPtr->uNumPtrsAlloced=TVITEM_ALLOC;
|
|---|
| 2237 | infoPtr->TopRootItem=(HTREEITEM)1;
|
|---|
| 2238 | }
|
|---|
| 2239 |
|
|---|
| 2240 | /*
|
|---|
| 2241 | * Reallocate contiguous space for items
|
|---|
| 2242 | */
|
|---|
| 2243 | if (infoPtr->uNumItems == (infoPtr->uNumPtrsAlloced-1) ) {
|
|---|
| 2244 | TREEVIEW_ITEM *oldItems = infoPtr->items;
|
|---|
| 2245 | INT *oldfreeList = infoPtr->freeList;
|
|---|
| 2246 |
|
|---|
| 2247 | infoPtr->uNumPtrsAlloced*=2;
|
|---|
| 2248 | infoPtr->items = (TREEVIEW_ITEM*)COMCTL32_Alloc (infoPtr->uNumPtrsAlloced*sizeof (TREEVIEW_ITEM));
|
|---|
| 2249 | infoPtr->freeList= (INT*)COMCTL32_Alloc (((infoPtr->uNumPtrsAlloced>>5))*sizeof (INT));
|
|---|
| 2250 |
|
|---|
| 2251 | memcpy (&infoPtr->items[0], &oldItems[0],
|
|---|
| 2252 | infoPtr->uNumPtrsAlloced/2 * sizeof(TREEVIEW_ITEM));
|
|---|
| 2253 | memcpy (&infoPtr->freeList[0], &oldfreeList[0],
|
|---|
| 2254 | (infoPtr->uNumPtrsAlloced>>6) * sizeof(INT));
|
|---|
| 2255 |
|
|---|
| 2256 | COMCTL32_Free (oldItems);
|
|---|
| 2257 | COMCTL32_Free (oldfreeList);
|
|---|
| 2258 | }
|
|---|
| 2259 |
|
|---|
| 2260 | /*
|
|---|
| 2261 | * Reset infoPtr structure with new stat according to current TV picture
|
|---|
| 2262 | */
|
|---|
| 2263 | iItem=0;
|
|---|
| 2264 | infoPtr->uNumItems++;
|
|---|
| 2265 | if ((INT)infoPtr->uMaxHandle==(infoPtr->uNumItems-1)) {
|
|---|
| 2266 | iItem=infoPtr->uNumItems;
|
|---|
| 2267 | infoPtr->uMaxHandle = (HTREEITEM)((INT)infoPtr->uMaxHandle + 1);
|
|---|
| 2268 | } else { /* check freelist */
|
|---|
| 2269 | for (i=0; i<infoPtr->uNumPtrsAlloced>>5; i++) {
|
|---|
| 2270 | if (infoPtr->freeList[i]) {
|
|---|
| 2271 | for(iItem = 0; iItem < 32; iItem++)
|
|---|
| 2272 | {
|
|---|
| 2273 | if(tv_test_bit(iItem, &infoPtr->freeList[i]))
|
|---|
| 2274 | break;
|
|---|
| 2275 | }
|
|---|
| 2276 | tv_clear_bit(iItem,&infoPtr->freeList[i]);
|
|---|
| 2277 | iItem+=i<<5;
|
|---|
| 2278 | break;
|
|---|
| 2279 | }
|
|---|
| 2280 | }
|
|---|
| 2281 | }
|
|---|
| 2282 |
|
|---|
| 2283 | /*
|
|---|
| 2284 | * Find the parent item of the new item
|
|---|
| 2285 | */
|
|---|
| 2286 | tvItem = &ptdi->itemex;
|
|---|
| 2287 | wineItem = &infoPtr->items[iItem];
|
|---|
| 2288 |
|
|---|
| 2289 | if ((ptdi->hParent==TVI_ROOT) || (ptdi->hParent==0)) {
|
|---|
| 2290 | parentItem = NULL;
|
|---|
| 2291 | wineItem->parent = 0;
|
|---|
| 2292 | sibItem = &infoPtr->items [(INT)infoPtr->TopRootItem];
|
|---|
| 2293 | }
|
|---|
| 2294 | else {
|
|---|
| 2295 | parentItem = &infoPtr->items[(INT)ptdi->hParent];
|
|---|
| 2296 |
|
|---|
| 2297 | /* Do the insertion here it if it's the only item of this parent */
|
|---|
| 2298 | if (!parentItem->firstChild)
|
|---|
| 2299 | parentItem->firstChild=(HTREEITEM)iItem;
|
|---|
| 2300 |
|
|---|
| 2301 | wineItem->parent = ptdi->hParent;
|
|---|
| 2302 | sibItem = &infoPtr->items [(INT)parentItem->firstChild];
|
|---|
| 2303 | }
|
|---|
| 2304 |
|
|---|
| 2305 |
|
|---|
| 2306 | /* NOTE: I am moving some setup of the wineItem object that was initialy
|
|---|
| 2307 | * done at the end of the function since some of the values are
|
|---|
| 2308 | * required by the Callback sorting
|
|---|
| 2309 | */
|
|---|
| 2310 |
|
|---|
| 2311 | if (tvItem->mask & TVIF_TEXT)
|
|---|
| 2312 | {
|
|---|
| 2313 | /*
|
|---|
| 2314 | * Setup the item text stuff here since it's required by the Sort method
|
|---|
| 2315 | * when the insertion are ordered
|
|---|
| 2316 | */
|
|---|
| 2317 | if (unicode)
|
|---|
| 2318 | {
|
|---|
| 2319 | if (tvItem->pszText != LPSTR_TEXTCALLBACKW)
|
|---|
| 2320 | {
|
|---|
| 2321 | len = lstrlenW(tvItem->pszText)+1;
|
|---|
| 2322 | wineItem->pszText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
|---|
| 2323 | lstrcpyW (wineItem->pszText, tvItem->pszText);
|
|---|
| 2324 | wineItem->cchTextMax = len;
|
|---|
| 2325 | } else
|
|---|
| 2326 | {
|
|---|
| 2327 | wineItem->pszText = LPSTR_TEXTCALLBACKW;
|
|---|
| 2328 | wineItem->cchTextMax = 0;
|
|---|
| 2329 | }
|
|---|
| 2330 | } else
|
|---|
| 2331 | {
|
|---|
| 2332 | if ((LPSTR)tvItem->pszText != LPSTR_TEXTCALLBACKA)
|
|---|
| 2333 | {
|
|---|
| 2334 | len = lstrlenA((LPSTR)tvItem->pszText)+1;
|
|---|
| 2335 | wineItem->pszText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
|---|
| 2336 | lstrcpyAtoW (wineItem->pszText,(LPSTR)tvItem->pszText);
|
|---|
| 2337 | wineItem->cchTextMax = len;
|
|---|
| 2338 | } else
|
|---|
| 2339 | {
|
|---|
| 2340 | wineItem->pszText = LPSTR_TEXTCALLBACKW;
|
|---|
| 2341 | wineItem->cchTextMax = 0;
|
|---|
| 2342 | }
|
|---|
| 2343 | }
|
|---|
| 2344 | }
|
|---|
| 2345 |
|
|---|
| 2346 | if (tvItem->mask & TVIF_PARAM)
|
|---|
| 2347 | wineItem->lParam=tvItem->lParam;
|
|---|
| 2348 |
|
|---|
| 2349 |
|
|---|
| 2350 | wineItem->upsibling=0; /* needed in case we're the first item in a list */
|
|---|
| 2351 | wineItem->sibling=0;
|
|---|
| 2352 | wineItem->firstChild=0;
|
|---|
| 2353 | wineItem->hItem=(HTREEITEM)iItem;
|
|---|
| 2354 |
|
|---|
| 2355 | if (sibItem != wineItem)
|
|---|
| 2356 | {
|
|---|
| 2357 | prevsib=NULL;
|
|---|
| 2358 |
|
|---|
| 2359 | if (ptdi->hInsertAfter == TVI_FIRST)
|
|---|
| 2360 | {
|
|---|
| 2361 | if (wineItem->parent) {
|
|---|
| 2362 | wineItem->sibling=parentItem->firstChild;
|
|---|
| 2363 | parentItem->firstChild=(HTREEITEM)iItem;
|
|---|
| 2364 | } else {
|
|---|
| 2365 | wineItem->sibling=infoPtr->TopRootItem;
|
|---|
| 2366 | infoPtr->TopRootItem=(HTREEITEM)iItem;
|
|---|
| 2367 | }
|
|---|
| 2368 | sibItem->upsibling=(HTREEITEM)iItem;
|
|---|
| 2369 | } else if (ptdi->hInsertAfter == TVI_SORT)
|
|---|
| 2370 | {
|
|---|
| 2371 | TREEVIEW_ITEM *aChild;
|
|---|
| 2372 | TREEVIEW_ITEM *previousChild = NULL;
|
|---|
| 2373 | BOOL bItemInserted = FALSE;
|
|---|
| 2374 | WCHAR* text;
|
|---|
| 2375 | BOOL mustFree = FALSE;
|
|---|
| 2376 |
|
|---|
| 2377 | if (parentItem)
|
|---|
| 2378 | aChild = &infoPtr->items[(INT)parentItem->firstChild];
|
|---|
| 2379 | else
|
|---|
| 2380 | aChild = &infoPtr->items[(INT)infoPtr->TopRootItem];
|
|---|
| 2381 |
|
|---|
| 2382 | /* lookup the text if using LPSTR_TEXTCALLBACKs */
|
|---|
| 2383 | if (wineItem->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 2384 | text = TREEVIEW_CallbackText(hwnd,wineItem,&mustFree);
|
|---|
| 2385 | else
|
|---|
| 2386 | text = wineItem->pszText;
|
|---|
| 2387 |
|
|---|
| 2388 | /* Iterate the parent children to see where we fit in */
|
|---|
| 2389 | while ( aChild != NULL )
|
|---|
| 2390 | {
|
|---|
| 2391 | INT comp;
|
|---|
| 2392 | WCHAR* text2;
|
|---|
| 2393 | BOOL mustFree2 = FALSE;
|
|---|
| 2394 |
|
|---|
| 2395 | /* lookup the text if using LPSTR_TEXTCALLBACKs */
|
|---|
| 2396 | if (aChild->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 2397 | text2 = TREEVIEW_CallbackText(hwnd,aChild,&mustFree2);
|
|---|
| 2398 | else
|
|---|
| 2399 | text2 = aChild->pszText;
|
|---|
| 2400 |
|
|---|
| 2401 | comp = lstrcmpW(text,text2);
|
|---|
| 2402 | if (mustFree2) COMCTL32_Free(text2);
|
|---|
| 2403 | if ( comp < 0 ) /* we are smaller than the current one */
|
|---|
| 2404 | {
|
|---|
| 2405 | TREEVIEW_InsertBefore(infoPtr, wineItem, aChild, parentItem);
|
|---|
| 2406 | bItemInserted = TRUE;
|
|---|
| 2407 | break;
|
|---|
| 2408 | }
|
|---|
| 2409 | else if ( comp > 0 ) /* we are bigger than the current one */
|
|---|
| 2410 | {
|
|---|
| 2411 | previousChild = aChild;
|
|---|
| 2412 | aChild = (aChild->sibling == 0) /* This will help us to exit */
|
|---|
| 2413 | ? NULL /* if there is no more sibling */
|
|---|
| 2414 | : &infoPtr->items[(INT)aChild->sibling];
|
|---|
| 2415 |
|
|---|
| 2416 | /* Look at the next item */
|
|---|
| 2417 | continue;
|
|---|
| 2418 | }
|
|---|
| 2419 | else if ( comp == 0 )
|
|---|
| 2420 | {
|
|---|
| 2421 | /*
|
|---|
| 2422 | * An item with this name is already existing, therefore,
|
|---|
| 2423 | * we add after the one we found
|
|---|
| 2424 | */
|
|---|
| 2425 | TREEVIEW_InsertAfter(infoPtr, wineItem, aChild, parentItem);
|
|---|
| 2426 | bItemInserted = TRUE;
|
|---|
| 2427 | break;
|
|---|
| 2428 | }
|
|---|
| 2429 | }
|
|---|
| 2430 | if (mustFree) COMCTL32_Free(text);
|
|---|
| 2431 |
|
|---|
| 2432 | /*
|
|---|
| 2433 | * we reach the end of the child list and the item as not
|
|---|
| 2434 | * yet been inserted, therefore, insert it after the last child.
|
|---|
| 2435 | */
|
|---|
| 2436 | if ( (! bItemInserted ) && (aChild == NULL) )
|
|---|
| 2437 | TREEVIEW_InsertAfter(infoPtr, wineItem, previousChild, parentItem);
|
|---|
| 2438 | } else if (ptdi->hInsertAfter == TVI_LAST)
|
|---|
| 2439 | {
|
|---|
| 2440 | TVI_LAST_CASE:
|
|---|
| 2441 | while (sibItem->sibling) {
|
|---|
| 2442 | prevsib=sibItem;
|
|---|
| 2443 | sibItem=&infoPtr->items [(INT)sibItem->sibling];
|
|---|
| 2444 | }
|
|---|
| 2445 | sibItem->sibling=(HTREEITEM)iItem;
|
|---|
| 2446 | wineItem->upsibling=sibItem->hItem;
|
|---|
| 2447 | } else
|
|---|
| 2448 | {
|
|---|
| 2449 | while ((sibItem->sibling) && (sibItem->hItem!=ptdi->hInsertAfter))
|
|---|
| 2450 | {
|
|---|
| 2451 | prevsib=sibItem;
|
|---|
| 2452 | sibItem=&infoPtr->items [(INT)sibItem->sibling];
|
|---|
| 2453 | }
|
|---|
| 2454 | if (sibItem->hItem!=ptdi->hInsertAfter) {
|
|---|
| 2455 | goto TVI_LAST_CASE;
|
|---|
| 2456 | }
|
|---|
| 2457 | prevsib=sibItem;
|
|---|
| 2458 | if (sibItem->sibling) {
|
|---|
| 2459 | sibItem=&infoPtr->items [(INT)sibItem->sibling];
|
|---|
| 2460 | sibItem->upsibling=(HTREEITEM)iItem;
|
|---|
| 2461 | wineItem->sibling=sibItem->hItem;
|
|---|
| 2462 | }
|
|---|
| 2463 | prevsib->sibling=(HTREEITEM)iItem;
|
|---|
| 2464 | wineItem->upsibling=prevsib->hItem;
|
|---|
| 2465 | }
|
|---|
| 2466 | }
|
|---|
| 2467 |
|
|---|
| 2468 | /* Fill in info structure */
|
|---|
| 2469 |
|
|---|
| 2470 | wineItem->mask = tvItem->mask;
|
|---|
| 2471 | wineItem->iIntegral = 1;
|
|---|
| 2472 |
|
|---|
| 2473 | if (tvItem->mask & TVIF_CHILDREN)
|
|---|
| 2474 | wineItem->cChildren=tvItem->cChildren;
|
|---|
| 2475 |
|
|---|
| 2476 | wineItem->expandBox.left = 0; /* Initialize the expandBox */
|
|---|
| 2477 | wineItem->expandBox.top = 0;
|
|---|
| 2478 | wineItem->expandBox.right = 0;
|
|---|
| 2479 | wineItem->expandBox.bottom = 0;
|
|---|
| 2480 |
|
|---|
| 2481 | if (tvItem->mask & TVIF_IMAGE)
|
|---|
| 2482 | wineItem->iImage = tvItem->iImage;
|
|---|
| 2483 |
|
|---|
| 2484 | /* If the application sets TVIF_INTEGRAL without
|
|---|
| 2485 | supplying a TVITEMEX structure, it's toast */
|
|---|
| 2486 |
|
|---|
| 2487 | if (tvItem->mask & TVIF_INTEGRAL)
|
|---|
| 2488 | wineItem->iIntegral = tvItem->iIntegral;
|
|---|
| 2489 |
|
|---|
| 2490 | if (tvItem->mask & TVIF_SELECTEDIMAGE)
|
|---|
| 2491 | wineItem->iSelectedImage = tvItem->iSelectedImage;
|
|---|
| 2492 |
|
|---|
| 2493 | if (tvItem->mask & TVIF_STATE)
|
|---|
| 2494 | {
|
|---|
| 2495 | wineItem->state = tvItem->state;
|
|---|
| 2496 | wineItem->stateMask = tvItem->stateMask;
|
|---|
| 2497 | }
|
|---|
| 2498 |
|
|---|
| 2499 | wineItem->calculated = FALSE;
|
|---|
| 2500 | //TREEVIEW_Sort(hwnd,0,NULL,NULL); //CB: the Corel people do this, I think it's wrong
|
|---|
| 2501 | TREEVIEW_QueueRefresh(hwnd);
|
|---|
| 2502 |
|
|---|
| 2503 | return (LRESULT) iItem;
|
|---|
| 2504 | }
|
|---|
| 2505 |
|
|---|
| 2506 |
|
|---|
| 2507 | static LRESULT
|
|---|
| 2508 | TREEVIEW_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2509 | {
|
|---|
| 2510 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2511 | INT iItem;
|
|---|
| 2512 | TREEVIEW_ITEM *wineItem;
|
|---|
| 2513 |
|
|---|
| 2514 | if (lParam == (INT)TVI_ROOT)
|
|---|
| 2515 | {
|
|---|
| 2516 | TREEVIEW_RemoveTree (hwnd);
|
|---|
| 2517 | } else
|
|---|
| 2518 | {
|
|---|
| 2519 | iItem = (INT)lParam;
|
|---|
| 2520 | wineItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM)iItem);
|
|---|
| 2521 | if (!wineItem) return FALSE;
|
|---|
| 2522 |
|
|---|
| 2523 | TREEVIEW_RemoveItem (hwnd, wineItem);
|
|---|
| 2524 | }
|
|---|
| 2525 |
|
|---|
| 2526 | TREEVIEW_QueueRefresh(hwnd);
|
|---|
| 2527 |
|
|---|
| 2528 | return TRUE;
|
|---|
| 2529 | }
|
|---|
| 2530 |
|
|---|
| 2531 |
|
|---|
| 2532 |
|
|---|
| 2533 | static LRESULT
|
|---|
| 2534 | TREEVIEW_GetIndent (HWND hwnd)
|
|---|
| 2535 | {
|
|---|
| 2536 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2537 |
|
|---|
| 2538 | return infoPtr->uIndent;
|
|---|
| 2539 | }
|
|---|
| 2540 |
|
|---|
| 2541 | static LRESULT
|
|---|
| 2542 | TREEVIEW_SetIndent (HWND hwnd, WPARAM wParam)
|
|---|
| 2543 | {
|
|---|
| 2544 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2545 | INT newIndent;
|
|---|
| 2546 |
|
|---|
| 2547 | newIndent = (INT)wParam;
|
|---|
| 2548 | if (newIndent < MINIMUM_INDENT) newIndent = MINIMUM_INDENT;
|
|---|
| 2549 | if (newIndent != infoPtr->uIndent)
|
|---|
| 2550 | {
|
|---|
| 2551 | infoPtr->uIndent = newIndent;
|
|---|
| 2552 | infoPtr->uInternalStatus |= TV_CALCALL;
|
|---|
| 2553 | TREEVIEW_QueueRefresh(hwnd);
|
|---|
| 2554 | }
|
|---|
| 2555 |
|
|---|
| 2556 | return 0;
|
|---|
| 2557 | }
|
|---|
| 2558 |
|
|---|
| 2559 | static LRESULT
|
|---|
| 2560 | TREEVIEW_GetToolTips (HWND hwnd)
|
|---|
| 2561 | {
|
|---|
| 2562 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2563 |
|
|---|
| 2564 | return infoPtr->hwndToolTip;
|
|---|
| 2565 | }
|
|---|
| 2566 |
|
|---|
| 2567 |
|
|---|
| 2568 | static LRESULT
|
|---|
| 2569 | TREEVIEW_SetToolTips (HWND hwnd, WPARAM wParam)
|
|---|
| 2570 | {
|
|---|
| 2571 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2572 | HWND prevToolTip;
|
|---|
| 2573 |
|
|---|
| 2574 | prevToolTip = infoPtr->hwndToolTip;
|
|---|
| 2575 | infoPtr->hwndToolTip = (HWND)wParam;
|
|---|
| 2576 |
|
|---|
| 2577 | return prevToolTip;
|
|---|
| 2578 | }
|
|---|
| 2579 |
|
|---|
| 2580 |
|
|---|
| 2581 | static LRESULT CALLBACK
|
|---|
| 2582 | TREEVIEW_GetEditControl (HWND hwnd)
|
|---|
| 2583 | {
|
|---|
| 2584 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2585 |
|
|---|
| 2586 | return infoPtr->hwndEdit;
|
|---|
| 2587 | }
|
|---|
| 2588 |
|
|---|
| 2589 |
|
|---|
| 2590 | //@@@PH: Note - this SubclassProc is sometimes called with the
|
|---|
| 2591 | // wrong window handle. Therefore, infoPtr points to anything
|
|---|
| 2592 | // but the expected structure.
|
|---|
| 2593 | LRESULT CALLBACK
|
|---|
| 2594 | TREEVIEW_Edit_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam,
|
|---|
| 2595 | LPARAM lParam)
|
|---|
| 2596 | {
|
|---|
| 2597 | BOOL bCancel = FALSE;
|
|---|
| 2598 | static BOOL bIgnoreKillFocus = FALSE;
|
|---|
| 2599 |
|
|---|
| 2600 | switch (uMsg)
|
|---|
| 2601 | {
|
|---|
| 2602 | case WM_PAINT:
|
|---|
| 2603 | {
|
|---|
| 2604 | LRESULT rc;
|
|---|
| 2605 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
|
|---|
| 2606 | //TRACE("WM_PAINT start\n");
|
|---|
| 2607 | rc = CallWindowProcA( infoPtr->wpEditOrig, hwnd, uMsg, wParam, lParam);
|
|---|
| 2608 | //TRACE("WM_PAINT done\n");
|
|---|
| 2609 | return rc;
|
|---|
| 2610 | }
|
|---|
| 2611 |
|
|---|
| 2612 | case WM_KILLFOCUS:
|
|---|
| 2613 | if(bIgnoreKillFocus)
|
|---|
| 2614 | {
|
|---|
| 2615 | return TRUE;
|
|---|
| 2616 | }
|
|---|
| 2617 | break;
|
|---|
| 2618 |
|
|---|
| 2619 | case WM_GETDLGCODE:
|
|---|
| 2620 | return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
|
|---|
| 2621 |
|
|---|
| 2622 | case WM_KEYDOWN:
|
|---|
| 2623 | if (VK_ESCAPE == (INT)wParam)
|
|---|
| 2624 | {
|
|---|
| 2625 | bCancel = TRUE;
|
|---|
| 2626 | break;
|
|---|
| 2627 | }
|
|---|
| 2628 | else if (VK_RETURN == (INT)wParam)
|
|---|
| 2629 | {
|
|---|
| 2630 | break;
|
|---|
| 2631 | }
|
|---|
| 2632 |
|
|---|
| 2633 | default:
|
|---|
| 2634 | {
|
|---|
| 2635 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
|
|---|
| 2636 |
|
|---|
| 2637 | //@@@PH 1999/11/05 method called with freed infoPtr memory object
|
|---|
| 2638 | if (infoPtr != NULL)
|
|---|
| 2639 | return CallWindowProcA( infoPtr->wpEditOrig, hwnd, uMsg, wParam, lParam);
|
|---|
| 2640 | else
|
|---|
| 2641 | break;
|
|---|
| 2642 | }
|
|---|
| 2643 | }
|
|---|
| 2644 |
|
|---|
| 2645 | /* Processing LVN_ENDLABELEDIT message could kill the focus */
|
|---|
| 2646 | /* eg. Using a messagebox */
|
|---|
| 2647 | bIgnoreKillFocus = TRUE;
|
|---|
| 2648 | TREEVIEW_EndEditLabelNow(GetParent(hwnd), bCancel);
|
|---|
| 2649 | bIgnoreKillFocus = FALSE;
|
|---|
| 2650 |
|
|---|
| 2651 | return 0;
|
|---|
| 2652 | }
|
|---|
| 2653 |
|
|---|
| 2654 | /* should handle edit control messages here */
|
|---|
| 2655 |
|
|---|
| 2656 | static LRESULT
|
|---|
| 2657 | TREEVIEW_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2658 |
|
|---|
| 2659 | {
|
|---|
| 2660 | switch (HIWORD(wParam))
|
|---|
| 2661 | {
|
|---|
| 2662 | case EN_UPDATE:
|
|---|
| 2663 | {
|
|---|
| 2664 | /*
|
|---|
| 2665 | * Adjust the edit window size
|
|---|
| 2666 | */
|
|---|
| 2667 | char buffer[1024];
|
|---|
| 2668 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2669 | TREEVIEW_ITEM *editItem = TREEVIEW_ValidItem(infoPtr, infoPtr->editItem);
|
|---|
| 2670 | HDC hdc = GetDC(infoPtr->hwndEdit);
|
|---|
| 2671 | SIZE sz;
|
|---|
| 2672 | int len;
|
|---|
| 2673 | HFONT hFont, hOldFont=0;
|
|---|
| 2674 |
|
|---|
| 2675 | len = GetWindowTextA(infoPtr->hwndEdit, buffer, 1024);
|
|---|
| 2676 |
|
|---|
| 2677 | /* Select font to get the right dimension of the string */
|
|---|
| 2678 | hFont = SendMessageA(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
|
|---|
| 2679 | if(hFont != 0)
|
|---|
| 2680 | {
|
|---|
| 2681 | hOldFont = SelectObject(hdc, hFont);
|
|---|
| 2682 | }
|
|---|
| 2683 |
|
|---|
| 2684 | if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz))
|
|---|
| 2685 | {
|
|---|
| 2686 | TEXTMETRICA textMetric;
|
|---|
| 2687 | /* Add Extra spacing for the next character */
|
|---|
| 2688 | GetTextMetricsA(hdc, &textMetric);
|
|---|
| 2689 | sz.cx += (textMetric.tmMaxCharWidth * 2);
|
|---|
| 2690 |
|
|---|
| 2691 | SetWindowPos (
|
|---|
| 2692 | infoPtr->hwndEdit,
|
|---|
| 2693 | HWND_TOP,
|
|---|
| 2694 | 0,
|
|---|
| 2695 | 0,
|
|---|
| 2696 | sz.cx,
|
|---|
| 2697 | editItem->text.bottom - editItem->text.top + 3,
|
|---|
| 2698 | SWP_NOMOVE|SWP_DRAWFRAME);
|
|---|
| 2699 | }
|
|---|
| 2700 |
|
|---|
| 2701 | if(hFont != 0)
|
|---|
| 2702 | {
|
|---|
| 2703 | SelectObject(hdc, hOldFont);
|
|---|
| 2704 | }
|
|---|
| 2705 |
|
|---|
| 2706 | ReleaseDC(hwnd, hdc);
|
|---|
| 2707 | break;
|
|---|
| 2708 | }
|
|---|
| 2709 |
|
|---|
| 2710 | default:
|
|---|
| 2711 | return SendMessageA (GetParent (hwnd), WM_COMMAND, wParam, lParam);
|
|---|
| 2712 | }
|
|---|
| 2713 |
|
|---|
| 2714 | return 0;
|
|---|
| 2715 | }
|
|---|
| 2716 |
|
|---|
| 2717 | static LRESULT TREEVIEW_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2718 | {
|
|---|
| 2719 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2720 |
|
|---|
| 2721 | if (wParam == SIZE_RESTORED)
|
|---|
| 2722 | if (TREEVIEW_CalcItems(hwnd,0,infoPtr))
|
|---|
| 2723 | TREEVIEW_Refresh(hwnd);
|
|---|
| 2724 |
|
|---|
| 2725 | return TRUE;
|
|---|
| 2726 | }
|
|---|
| 2727 |
|
|---|
| 2728 | static LRESULT
|
|---|
| 2729 | TREEVIEW_StyleChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2730 | {
|
|---|
| 2731 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2732 |
|
|---|
| 2733 | if (infoPtr->hwndEdit) SetFocus(hwnd);
|
|---|
| 2734 |
|
|---|
| 2735 | infoPtr->uInternalStatus |= TV_CALCALL;
|
|---|
| 2736 | TREEVIEW_QueueRefresh(hwnd);
|
|---|
| 2737 |
|
|---|
| 2738 | return 0;
|
|---|
| 2739 | }
|
|---|
| 2740 |
|
|---|
| 2741 | static LRESULT
|
|---|
| 2742 | TREEVIEW_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 2743 | {
|
|---|
| 2744 | TREEVIEW_Refresh(hwnd);
|
|---|
| 2745 |
|
|---|
| 2746 | return DefWindowProcA(hwnd,WM_SYSCOLORCHANGE,wParam,lParam);
|
|---|
| 2747 | }
|
|---|
| 2748 |
|
|---|
| 2749 | static LRESULT
|
|---|
| 2750 | TREEVIEW_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2751 | {
|
|---|
| 2752 | LPCREATESTRUCTA lpcs = (LPCREATESTRUCTA)lParam;
|
|---|
| 2753 | TREEVIEW_INFO *infoPtr;
|
|---|
| 2754 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
|---|
| 2755 | LOGFONTA logFont;
|
|---|
| 2756 | TEXTMETRICA tm;
|
|---|
| 2757 | HDC hdc;
|
|---|
| 2758 |
|
|---|
| 2759 | /* allocate memory for info structure */
|
|---|
| 2760 | infoPtr = (TREEVIEW_INFO*)initControl(hwnd,sizeof(TREEVIEW_INFO));
|
|---|
| 2761 |
|
|---|
| 2762 | if (infoPtr == NULL) return 0;
|
|---|
| 2763 |
|
|---|
| 2764 | hdc = GetDC(hwnd);
|
|---|
| 2765 |
|
|---|
| 2766 | /* set default settings */
|
|---|
| 2767 | infoPtr->uInternalStatus = TV_CALCALL;
|
|---|
| 2768 | infoPtr->uNumItems = 0;
|
|---|
| 2769 | infoPtr->clrBk = GetSysColor (COLOR_WINDOW);
|
|---|
| 2770 | infoPtr->clrLine = GetSysColor (COLOR_WINDOWTEXT);
|
|---|
| 2771 | infoPtr->clrInsertMark = GetSysColor (COLOR_BTNTEXT);
|
|---|
| 2772 | infoPtr->lefttop.y = 0;
|
|---|
| 2773 | infoPtr->lefttop.x = 0;
|
|---|
| 2774 | infoPtr->uIndent = 15;
|
|---|
| 2775 | infoPtr->himlNormal = NULL;
|
|---|
| 2776 | infoPtr->himlState = NULL;
|
|---|
| 2777 | infoPtr->uItemHeight = -1;
|
|---|
| 2778 | infoPtr->uRealItemHeight = 0;
|
|---|
| 2779 | infoPtr->uVScrollStep = 1;
|
|---|
| 2780 | infoPtr->uVisibleHeight = lpcs->cy;
|
|---|
| 2781 | infoPtr->uTotalHeight = 0;
|
|---|
| 2782 | infoPtr->uVisibleWidth = lpcs->cx;
|
|---|
| 2783 | infoPtr->uTotalWidth = 0;
|
|---|
| 2784 |
|
|---|
| 2785 | GetTextMetricsA (hdc, &tm);
|
|---|
| 2786 | infoPtr->hFont = GetStockObject (DEFAULT_GUI_FONT);
|
|---|
| 2787 | GetObjectA (infoPtr->hFont, sizeof (LOGFONTA), &logFont);
|
|---|
| 2788 | logFont.lfWeight = FW_BOLD;
|
|---|
| 2789 | infoPtr->hBoldFont = CreateFontIndirectA (&logFont);
|
|---|
| 2790 |
|
|---|
| 2791 | infoPtr->items = NULL;
|
|---|
| 2792 | infoPtr->selectedItem = 0;
|
|---|
| 2793 | infoPtr->clrText = -1; /* use system color */
|
|---|
| 2794 | infoPtr->dropItem = 0;
|
|---|
| 2795 | infoPtr->insertMarkItem = 0;
|
|---|
| 2796 | infoPtr->insertBeforeorAfter = 0;
|
|---|
| 2797 | infoPtr->pCallBackSort = NULL;
|
|---|
| 2798 | infoPtr->uScrollTime = 300; /* milliseconds */
|
|---|
| 2799 | infoPtr->hwndEdit = 0;
|
|---|
| 2800 | infoPtr->pszISearch = NULL;
|
|---|
| 2801 | infoPtr->uISearchLen = 0;
|
|---|
| 2802 |
|
|---|
| 2803 | infoPtr->tipItem = 0;
|
|---|
| 2804 | infoPtr->hwndToolTip = 0;
|
|---|
| 2805 | if (!(dwStyle & TVS_NOTOOLTIPS))
|
|---|
| 2806 | {
|
|---|
| 2807 | infoPtr->hwndToolTip = createToolTip(hwnd,TTF_TRACK | TTF_ABSOLUTE | TTF_TRANSPARENT,TRUE);
|
|---|
| 2808 | SendMessageA(infoPtr->hwndToolTip,WM_SETFONT,infoPtr->hFont,0);
|
|---|
| 2809 | }
|
|---|
| 2810 |
|
|---|
| 2811 | if (dwStyle & TVS_CHECKBOXES)
|
|---|
| 2812 | {
|
|---|
| 2813 | HBITMAP hbmLoad;
|
|---|
| 2814 | int nIndex;
|
|---|
| 2815 |
|
|---|
| 2816 | infoPtr->himlState = ImageList_Create (16, 16,ILC_COLOR | ILC_MASK, 15, 1);
|
|---|
| 2817 |
|
|---|
| 2818 | //MSDN docu says: uses DrawFrameControl but never believe what they write
|
|---|
| 2819 | hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDT_CHECK));
|
|---|
| 2820 | nIndex = ImageList_AddMasked (infoPtr->himlState, hbmLoad, CLR_DEFAULT);
|
|---|
| 2821 | DeleteObject (hbmLoad);
|
|---|
| 2822 | }
|
|---|
| 2823 | ReleaseDC (hwnd, hdc);
|
|---|
| 2824 |
|
|---|
| 2825 | return 0;
|
|---|
| 2826 | }
|
|---|
| 2827 |
|
|---|
| 2828 | static LRESULT
|
|---|
| 2829 | TREEVIEW_Destroy (HWND hwnd)
|
|---|
| 2830 | {
|
|---|
| 2831 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2832 |
|
|---|
| 2833 | TREEVIEW_RemoveTree (hwnd);
|
|---|
| 2834 | if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
|
|---|
| 2835 | KillTimer (hwnd, TV_REFRESH_TIMER);
|
|---|
| 2836 | destroyToolTip(infoPtr->hwndToolTip);
|
|---|
| 2837 |
|
|---|
| 2838 | /* Restore original windproc so that we can free infoPtr */
|
|---|
| 2839 | if (infoPtr->hwndEdit)
|
|---|
| 2840 | SetWindowLongA (infoPtr->hwndEdit, GWL_WNDPROC, (DWORD)infoPtr->wpEditOrig);
|
|---|
| 2841 |
|
|---|
| 2842 | DeleteObject(infoPtr->hBoldFont);
|
|---|
| 2843 | COMCTL32_Free(infoPtr->pszISearch);
|
|---|
| 2844 | doneControl(hwnd);
|
|---|
| 2845 |
|
|---|
| 2846 | return 0;
|
|---|
| 2847 | }
|
|---|
| 2848 |
|
|---|
| 2849 |
|
|---|
| 2850 | static LRESULT
|
|---|
| 2851 | TREEVIEW_Paint (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2852 | {
|
|---|
| 2853 | HDC hdc = (HDC)wParam;
|
|---|
| 2854 |
|
|---|
| 2855 | if (!hdc)
|
|---|
| 2856 | {
|
|---|
| 2857 | PAINTSTRUCT ps;
|
|---|
| 2858 |
|
|---|
| 2859 | hdc = BeginPaint(hwnd,&ps);
|
|---|
| 2860 | TREEVIEW_Draw(hwnd, hdc,&ps.rcPaint);
|
|---|
| 2861 | EndPaint(hwnd,&ps);
|
|---|
| 2862 | } else
|
|---|
| 2863 | TREEVIEW_Draw(hwnd,hdc,NULL);
|
|---|
| 2864 |
|
|---|
| 2865 | return 0;
|
|---|
| 2866 | }
|
|---|
| 2867 |
|
|---|
| 2868 | static LRESULT
|
|---|
| 2869 | TREEVIEW_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2870 | {
|
|---|
| 2871 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2872 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 2873 |
|
|---|
| 2874 | sendNotify(hwnd,NM_SETFOCUS);
|
|---|
| 2875 |
|
|---|
| 2876 | if (!(dwStyle & TVS_SHOWSELALWAYS))
|
|---|
| 2877 | {
|
|---|
| 2878 | if (infoPtr->selectedItem)
|
|---|
| 2879 | TREEVIEW_RefreshItem(hwnd,TREEVIEW_ValidItem(infoPtr,infoPtr->selectedItem),FALSE);
|
|---|
| 2880 | else if (infoPtr->firstVisible)
|
|---|
| 2881 | TREEVIEW_DoSelectItem(hwnd,TVGN_CARET,infoPtr->firstVisible,TVC_UNKNOWN);
|
|---|
| 2882 | }
|
|---|
| 2883 |
|
|---|
| 2884 | return 0;
|
|---|
| 2885 | }
|
|---|
| 2886 |
|
|---|
| 2887 | static LRESULT
|
|---|
| 2888 | TREEVIEW_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2889 | {
|
|---|
| 2890 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2891 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 2892 |
|
|---|
| 2893 | sendNotify(hwnd,NM_KILLFOCUS);
|
|---|
| 2894 |
|
|---|
| 2895 | if (!(dwStyle & TVS_SHOWSELALWAYS) && infoPtr->selectedItem)
|
|---|
| 2896 | TREEVIEW_RefreshItem(hwnd,TREEVIEW_ValidItem(infoPtr,infoPtr->selectedItem),FALSE);
|
|---|
| 2897 |
|
|---|
| 2898 | return 0;
|
|---|
| 2899 | }
|
|---|
| 2900 |
|
|---|
| 2901 | static LRESULT TREEVIEW_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 2902 | {
|
|---|
| 2903 | TREEVIEW_Refresh(hwnd);
|
|---|
| 2904 |
|
|---|
| 2905 | return DefWindowProcA(hwnd,WM_ENABLE,wParam,lParam);
|
|---|
| 2906 | }
|
|---|
| 2907 |
|
|---|
| 2908 | static LRESULT
|
|---|
| 2909 | TREEVIEW_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 2910 | {
|
|---|
| 2911 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2912 | HBRUSH hBrush = CreateSolidBrush (infoPtr->clrBk);
|
|---|
| 2913 | RECT rect;
|
|---|
| 2914 |
|
|---|
| 2915 | GetClientRect (hwnd, &rect);
|
|---|
| 2916 | FillRect ((HDC)wParam, &rect, hBrush);
|
|---|
| 2917 | DeleteObject (hBrush);
|
|---|
| 2918 |
|
|---|
| 2919 | return TRUE;
|
|---|
| 2920 | }
|
|---|
| 2921 |
|
|---|
| 2922 | static LRESULT TREEVIEW_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 2923 | {
|
|---|
| 2924 | return DLGC_WANTARROWS | DLGC_WANTCHARS;
|
|---|
| 2925 | }
|
|---|
| 2926 |
|
|---|
| 2927 | /* Notifications */
|
|---|
| 2928 |
|
|---|
| 2929 | static BOOL
|
|---|
| 2930 | TREEVIEW_SendTreeviewNotify (HWND hwnd,UINT code,UINT action,HTREEITEM oldItem,HTREEITEM newItem)
|
|---|
| 2931 | {
|
|---|
| 2932 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 2933 | NMTREEVIEWW nmhdr;
|
|---|
| 2934 | TREEVIEW_ITEM *wineItem;
|
|---|
| 2935 | CHAR *oldText = NULL,*newText = NULL;
|
|---|
| 2936 | BOOL rc;
|
|---|
| 2937 |
|
|---|
| 2938 | ZeroMemory(&nmhdr,sizeof(NMTREEVIEWW));
|
|---|
| 2939 |
|
|---|
| 2940 | nmhdr.action = action;
|
|---|
| 2941 | if (oldItem)
|
|---|
| 2942 | {
|
|---|
| 2943 | wineItem = &infoPtr->items[(INT)oldItem];
|
|---|
| 2944 | nmhdr.itemOld.mask = wineItem->mask;
|
|---|
| 2945 | nmhdr.itemOld.hItem = wineItem->hItem;
|
|---|
| 2946 | nmhdr.itemOld.state = wineItem->state;
|
|---|
| 2947 | nmhdr.itemOld.stateMask = wineItem->stateMask;
|
|---|
| 2948 | nmhdr.itemOld.iImage = wineItem->iImage;
|
|---|
| 2949 | if (!isUnicodeNotify(&infoPtr->header))
|
|---|
| 2950 | {
|
|---|
| 2951 | if (!wineItem->pszText || (wineItem->pszText == LPSTR_TEXTCALLBACKW)) nmhdr.itemOld.pszText = NULL; else
|
|---|
| 2952 | {
|
|---|
| 2953 | INT len = lstrlenW(wineItem->pszText)+1;
|
|---|
| 2954 |
|
|---|
| 2955 | oldText = (CHAR*)COMCTL32_Alloc(len);
|
|---|
| 2956 | lstrcpyWtoA(oldText,wineItem->pszText);
|
|---|
| 2957 | nmhdr.itemOld.pszText = (WCHAR*)oldText;
|
|---|
| 2958 | }
|
|---|
| 2959 | } else nmhdr.itemOld.pszText = wineItem->pszText;
|
|---|
| 2960 | nmhdr.itemOld.cchTextMax= wineItem->cchTextMax;
|
|---|
| 2961 | nmhdr.itemOld.iImage = wineItem->iImage;
|
|---|
| 2962 | nmhdr.itemOld.iSelectedImage = wineItem->iSelectedImage;
|
|---|
| 2963 | nmhdr.itemOld.cChildren = wineItem->cChildren;
|
|---|
| 2964 | nmhdr.itemOld.lParam = wineItem->lParam;
|
|---|
| 2965 | }
|
|---|
| 2966 |
|
|---|
| 2967 | if (newItem)
|
|---|
| 2968 | {
|
|---|
| 2969 | wineItem = &infoPtr->items[(INT)newItem];
|
|---|
| 2970 | nmhdr.itemNew.mask = wineItem->mask;
|
|---|
| 2971 | nmhdr.itemNew.hItem = wineItem->hItem;
|
|---|
| 2972 | nmhdr.itemNew.state = wineItem->state;
|
|---|
| 2973 | nmhdr.itemNew.stateMask = wineItem->stateMask;
|
|---|
| 2974 | nmhdr.itemNew.iImage = wineItem->iImage;
|
|---|
| 2975 | if (!isUnicodeNotify(&infoPtr->header))
|
|---|
| 2976 | {
|
|---|
| 2977 | if (!wineItem->pszText || (wineItem->pszText == LPSTR_TEXTCALLBACKW)) nmhdr.itemNew.pszText = NULL; else
|
|---|
| 2978 | {
|
|---|
| 2979 | INT len = lstrlenW(wineItem->pszText)+1;
|
|---|
| 2980 |
|
|---|
| 2981 | newText = (CHAR*)COMCTL32_Alloc(len);
|
|---|
| 2982 | lstrcpyWtoA(newText,wineItem->pszText);
|
|---|
| 2983 | nmhdr.itemNew.pszText = (WCHAR*)newText;
|
|---|
| 2984 | }
|
|---|
| 2985 | } else nmhdr.itemNew.pszText = wineItem->pszText;
|
|---|
| 2986 | nmhdr.itemNew.cchTextMax= wineItem->cchTextMax;
|
|---|
| 2987 | nmhdr.itemNew.iImage = wineItem->iImage;
|
|---|
| 2988 | nmhdr.itemNew.iSelectedImage = wineItem->iSelectedImage;
|
|---|
| 2989 | nmhdr.itemNew.cChildren = wineItem->cChildren;
|
|---|
| 2990 | nmhdr.itemNew.lParam = wineItem->lParam;
|
|---|
| 2991 | }
|
|---|
| 2992 |
|
|---|
| 2993 | nmhdr.ptDrag.x = 0;
|
|---|
| 2994 | nmhdr.ptDrag.y = 0;
|
|---|
| 2995 |
|
|---|
| 2996 | rc = (BOOL)sendNotify(hwnd,code,&nmhdr.hdr);
|
|---|
| 2997 |
|
|---|
| 2998 | if (oldText) COMCTL32_Free(oldText);
|
|---|
| 2999 | if (newText) COMCTL32_Free(newText);
|
|---|
| 3000 |
|
|---|
| 3001 | return rc;
|
|---|
| 3002 | }
|
|---|
| 3003 |
|
|---|
| 3004 | static BOOL
|
|---|
| 3005 | TREEVIEW_SendTreeviewDnDNotify (HWND hwnd, UINT code, HTREEITEM dragItem,
|
|---|
| 3006 | POINT pt)
|
|---|
| 3007 | {
|
|---|
| 3008 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3009 | NMTREEVIEWA nmhdr;
|
|---|
| 3010 | TREEVIEW_ITEM *wineItem;
|
|---|
| 3011 |
|
|---|
| 3012 | nmhdr.action = 0;
|
|---|
| 3013 | wineItem=& infoPtr->items[(INT)dragItem];
|
|---|
| 3014 | nmhdr.itemNew.mask = wineItem->mask;
|
|---|
| 3015 | nmhdr.itemNew.hItem = wineItem->hItem;
|
|---|
| 3016 | nmhdr.itemNew.state = wineItem->state;
|
|---|
| 3017 | nmhdr.itemNew.lParam = wineItem->lParam;
|
|---|
| 3018 |
|
|---|
| 3019 | nmhdr.ptDrag.x = pt.x;
|
|---|
| 3020 | nmhdr.ptDrag.y = pt.y;
|
|---|
| 3021 |
|
|---|
| 3022 | return (BOOL)sendNotify(hwnd,code,&nmhdr.hdr);
|
|---|
| 3023 |
|
|---|
| 3024 | }
|
|---|
| 3025 |
|
|---|
| 3026 | static INT TREEVIEW_CallbackImage(HWND hwnd,TREEVIEW_ITEM *wineItem)
|
|---|
| 3027 | {
|
|---|
| 3028 | NMTVDISPINFOW tvdi;
|
|---|
| 3029 | BOOL retval;
|
|---|
| 3030 |
|
|---|
| 3031 | tvdi.item.mask = TVIF_IMAGE;
|
|---|
| 3032 | tvdi.item.hItem = wineItem->hItem;
|
|---|
| 3033 | tvdi.item.state = wineItem->state;
|
|---|
| 3034 | tvdi.item.lParam = wineItem->lParam;
|
|---|
| 3035 | tvdi.item.iImage = 0;
|
|---|
| 3036 |
|
|---|
| 3037 | retval = (BOOL)sendNotify(hwnd,isUnicodeNotify(hwnd) ? TVN_GETDISPINFOW:TVN_GETDISPINFOA,&tvdi.hdr);
|
|---|
| 3038 |
|
|---|
| 3039 | if (tvdi.item.mask & TVIF_DI_SETITEM)
|
|---|
| 3040 | wineItem->iImage = tvdi.item.iImage;
|
|---|
| 3041 |
|
|---|
| 3042 | return tvdi.item.iImage;
|
|---|
| 3043 | }
|
|---|
| 3044 |
|
|---|
| 3045 | static INT TREEVIEW_CallbackSelectedImage(HWND hwnd,TREEVIEW_ITEM *wineItem)
|
|---|
| 3046 | {
|
|---|
| 3047 | NMTVDISPINFOW tvdi;
|
|---|
| 3048 | BOOL retval;
|
|---|
| 3049 |
|
|---|
| 3050 | tvdi.item.mask = TVIF_SELECTEDIMAGE;
|
|---|
| 3051 | tvdi.item.hItem = wineItem->hItem;
|
|---|
| 3052 | tvdi.item.state = wineItem->state;
|
|---|
| 3053 | tvdi.item.lParam = wineItem->lParam;
|
|---|
| 3054 | tvdi.item.iSelectedImage = 0;
|
|---|
| 3055 |
|
|---|
| 3056 | retval = (BOOL)sendNotify(hwnd,isUnicodeNotify(hwnd) ? TVN_GETDISPINFOW:TVN_GETDISPINFOA,&tvdi.hdr);
|
|---|
| 3057 |
|
|---|
| 3058 | if (tvdi.item.mask & TVIF_DI_SETITEM)
|
|---|
| 3059 | wineItem->iSelectedImage = tvdi.item.iSelectedImage;
|
|---|
| 3060 |
|
|---|
| 3061 | return tvdi.item.iSelectedImage;
|
|---|
| 3062 | }
|
|---|
| 3063 |
|
|---|
| 3064 | static WCHAR* TREEVIEW_CallbackText(HWND hwnd,TREEVIEW_ITEM *wineItem,BOOL *mustFree)
|
|---|
| 3065 | {
|
|---|
| 3066 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3067 | NMTVDISPINFOW tvdi;
|
|---|
| 3068 | BOOL retval;
|
|---|
| 3069 | WCHAR *buf;
|
|---|
| 3070 |
|
|---|
| 3071 | tvdi.item.mask = TVIF_TEXT;
|
|---|
| 3072 | tvdi.item.hItem = wineItem->hItem;
|
|---|
| 3073 | tvdi.item.state = wineItem->state;
|
|---|
| 3074 | tvdi.item.lParam = wineItem->lParam;
|
|---|
| 3075 | tvdi.item.pszText = (WCHAR*)COMCTL32_Alloc(128*(isUnicodeNotify(&infoPtr->header) ? sizeof(WCHAR):sizeof(CHAR)));
|
|---|
| 3076 | tvdi.item.cchTextMax = 128;
|
|---|
| 3077 | buf = tvdi.item.pszText;
|
|---|
| 3078 |
|
|---|
| 3079 | retval = (BOOL)sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_GETDISPINFOW:TVN_GETDISPINFOA,&tvdi.hdr);
|
|---|
| 3080 |
|
|---|
| 3081 | if (tvdi.item.pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 3082 | {
|
|---|
| 3083 | *mustFree = FALSE;
|
|---|
| 3084 | return NULL;
|
|---|
| 3085 | }
|
|---|
| 3086 |
|
|---|
| 3087 | if (isUnicodeNotify(&infoPtr->header))
|
|---|
| 3088 | {
|
|---|
| 3089 | if (tvdi.item.mask & TVIF_DI_SETITEM)
|
|---|
| 3090 | {
|
|---|
| 3091 | if (buf == tvdi.item.pszText)
|
|---|
| 3092 | {
|
|---|
| 3093 | wineItem->pszText = tvdi.item.pszText;
|
|---|
| 3094 | wineItem->cchTextMax = 128;
|
|---|
| 3095 | } else
|
|---|
| 3096 | { //user-supplied buffer
|
|---|
| 3097 | INT len = lstrlenW(tvdi.item.pszText);
|
|---|
| 3098 |
|
|---|
| 3099 | COMCTL32_Free(buf);
|
|---|
| 3100 | if (len > 0)
|
|---|
| 3101 | {
|
|---|
| 3102 | len++;
|
|---|
| 3103 | wineItem->pszText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
|---|
| 3104 | lstrcpyW(wineItem->pszText,tvdi.item.pszText);
|
|---|
| 3105 | wineItem->cchTextMax = len;
|
|---|
| 3106 | } else
|
|---|
| 3107 | {
|
|---|
| 3108 | wineItem->pszText = NULL;
|
|---|
| 3109 | wineItem->cchTextMax = len;
|
|---|
| 3110 | }
|
|---|
| 3111 | }
|
|---|
| 3112 | *mustFree = FALSE;
|
|---|
| 3113 | return wineItem->pszText;
|
|---|
| 3114 | } else
|
|---|
| 3115 | {
|
|---|
| 3116 | if (buf != tvdi.item.pszText)
|
|---|
| 3117 | {
|
|---|
| 3118 | COMCTL32_Free(buf);
|
|---|
| 3119 | *mustFree = FALSE;
|
|---|
| 3120 | } else *mustFree = TRUE;
|
|---|
| 3121 | return tvdi.item.pszText;
|
|---|
| 3122 | }
|
|---|
| 3123 | } else
|
|---|
| 3124 | {
|
|---|
| 3125 | if (tvdi.item.mask & TVIF_DI_SETITEM)
|
|---|
| 3126 | {
|
|---|
| 3127 | if (buf == tvdi.item.pszText)
|
|---|
| 3128 | {
|
|---|
| 3129 | wineItem->cchTextMax = 128;
|
|---|
| 3130 | wineItem->pszText = (WCHAR*)COMCTL32_Alloc(128*sizeof(WCHAR));
|
|---|
| 3131 | lstrcpynAtoW(wineItem->pszText,(CHAR*)tvdi.item.pszText,wineItem->cchTextMax);
|
|---|
| 3132 | COMCTL32_Free(buf);
|
|---|
| 3133 | } else
|
|---|
| 3134 | { //user-supplied buffer
|
|---|
| 3135 | INT len = lstrlenA((CHAR*)tvdi.item.pszText);
|
|---|
| 3136 |
|
|---|
| 3137 | COMCTL32_Free(buf);
|
|---|
| 3138 | if (len > 0)
|
|---|
| 3139 | {
|
|---|
| 3140 | len++;
|
|---|
| 3141 | wineItem->pszText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
|---|
| 3142 | lstrcpyAtoW(wineItem->pszText,(CHAR*)tvdi.item.pszText);
|
|---|
| 3143 | wineItem->cchTextMax = len;
|
|---|
| 3144 | } else
|
|---|
| 3145 | {
|
|---|
| 3146 | wineItem->pszText = NULL;
|
|---|
| 3147 | wineItem->cchTextMax = len;
|
|---|
| 3148 | }
|
|---|
| 3149 | }
|
|---|
| 3150 | *mustFree = FALSE;
|
|---|
| 3151 | return wineItem->pszText;
|
|---|
| 3152 | } else
|
|---|
| 3153 | {
|
|---|
| 3154 | INT len = lstrlenA((LPSTR)tvdi.item.pszText);
|
|---|
| 3155 | WCHAR* textW = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR));
|
|---|
| 3156 |
|
|---|
| 3157 | lstrcpyAtoW(textW,(LPSTR)tvdi.item.pszText);
|
|---|
| 3158 | COMCTL32_Free(buf);
|
|---|
| 3159 | *mustFree = TRUE;
|
|---|
| 3160 | return textW;
|
|---|
| 3161 | }
|
|---|
| 3162 | }
|
|---|
| 3163 | }
|
|---|
| 3164 |
|
|---|
| 3165 | static INT TREEVIEW_CallbackChildren(HWND hwnd,TREEVIEW_ITEM *wineItem)
|
|---|
| 3166 | {
|
|---|
| 3167 | NMTVDISPINFOW tvdi;
|
|---|
| 3168 | BOOL retval;
|
|---|
| 3169 |
|
|---|
| 3170 | tvdi.item.mask = TVIF_CHILDREN;
|
|---|
| 3171 | tvdi.item.hItem = wineItem->hItem;
|
|---|
| 3172 | tvdi.item.state = wineItem->state;
|
|---|
| 3173 | tvdi.item.lParam = wineItem->lParam;
|
|---|
| 3174 | tvdi.item.cChildren = 0;
|
|---|
| 3175 |
|
|---|
| 3176 | retval = (BOOL)sendNotify(hwnd,isUnicodeNotify(hwnd) ? TVN_GETDISPINFOW:TVN_GETDISPINFOA,&tvdi.hdr);
|
|---|
| 3177 |
|
|---|
| 3178 | if (tvdi.item.mask & TVIF_DI_SETITEM)
|
|---|
| 3179 | wineItem->cChildren = tvdi.item.cChildren;
|
|---|
| 3180 |
|
|---|
| 3181 | return tvdi.item.cChildren;
|
|---|
| 3182 | }
|
|---|
| 3183 |
|
|---|
| 3184 | static BOOL
|
|---|
| 3185 | TREEVIEW_SendCustomDrawNotify (HWND hwnd, DWORD dwDrawStage, HDC hdc,
|
|---|
| 3186 | RECT rc)
|
|---|
| 3187 | {
|
|---|
| 3188 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3189 | NMTVCUSTOMDRAW nmcdhdr;
|
|---|
| 3190 | LPNMCUSTOMDRAW nmcd;
|
|---|
| 3191 |
|
|---|
| 3192 | nmcd = &nmcdhdr.nmcd;
|
|---|
| 3193 | nmcd->dwDrawStage= dwDrawStage;
|
|---|
| 3194 | nmcd->hdc = hdc;
|
|---|
| 3195 | nmcd->rc.left = rc.left;
|
|---|
| 3196 | nmcd->rc.right = rc.right;
|
|---|
| 3197 | nmcd->rc.bottom = rc.bottom;
|
|---|
| 3198 | nmcd->rc.top = rc.top;
|
|---|
| 3199 | nmcd->dwItemSpec = 0;
|
|---|
| 3200 | nmcd->uItemState = 0;
|
|---|
| 3201 | nmcd->lItemlParam= 0;
|
|---|
| 3202 | nmcdhdr.clrText = infoPtr->clrText;
|
|---|
| 3203 | nmcdhdr.clrTextBk= infoPtr->clrBk;
|
|---|
| 3204 | nmcdhdr.iLevel = 0;
|
|---|
| 3205 |
|
|---|
| 3206 | return (BOOL)sendNotify(hwnd,NM_CUSTOMDRAW,&nmcdhdr.nmcd.hdr);
|
|---|
| 3207 | }
|
|---|
| 3208 |
|
|---|
| 3209 | /* FIXME: need to find out when the flags in uItemState need to be set */
|
|---|
| 3210 |
|
|---|
| 3211 | static BOOL
|
|---|
| 3212 | TREEVIEW_SendCustomDrawItemNotify (HWND hwnd, HDC hdc,
|
|---|
| 3213 | TREEVIEW_ITEM *wineItem, UINT uItemDrawState)
|
|---|
| 3214 | {
|
|---|
| 3215 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3216 | NMTVCUSTOMDRAW nmcdhdr;
|
|---|
| 3217 | LPNMCUSTOMDRAW nmcd;
|
|---|
| 3218 | DWORD dwDrawStage,dwItemSpec;
|
|---|
| 3219 | UINT uItemState;
|
|---|
| 3220 | INT retval;
|
|---|
| 3221 |
|
|---|
| 3222 | dwDrawStage=CDDS_ITEM | uItemDrawState;
|
|---|
| 3223 | dwItemSpec=(DWORD)wineItem->hItem;
|
|---|
| 3224 | uItemState=0;
|
|---|
| 3225 | if (wineItem->hItem == infoPtr->selectedItem)
|
|---|
| 3226 | {
|
|---|
| 3227 | uItemState|=CDIS_SELECTED;
|
|---|
| 3228 | if (GetFocus() == hwnd) uItemState |= CDIS_FOCUS;
|
|---|
| 3229 | }
|
|---|
| 3230 | if (wineItem->hItem==infoPtr->hotItem) uItemState|=CDIS_HOT;
|
|---|
| 3231 |
|
|---|
| 3232 | nmcd= & nmcdhdr.nmcd;
|
|---|
| 3233 | nmcd->dwDrawStage= dwDrawStage;
|
|---|
| 3234 | nmcd->hdc = hdc;
|
|---|
| 3235 | nmcd->rc.left = wineItem->rect.left;
|
|---|
| 3236 | nmcd->rc.right = wineItem->rect.right;
|
|---|
| 3237 | nmcd->rc.bottom = wineItem->rect.bottom;
|
|---|
| 3238 | nmcd->rc.top = wineItem->rect.top;
|
|---|
| 3239 | nmcd->dwItemSpec = dwItemSpec;
|
|---|
| 3240 | nmcd->uItemState = uItemState;
|
|---|
| 3241 | nmcd->lItemlParam= wineItem->lParam;
|
|---|
| 3242 |
|
|---|
| 3243 | nmcdhdr.clrText = infoPtr->clrText;
|
|---|
| 3244 | nmcdhdr.clrTextBk= infoPtr->clrBk;
|
|---|
| 3245 | nmcdhdr.iLevel = wineItem->iLevel;
|
|---|
| 3246 |
|
|---|
| 3247 | //TRACE (treeview,"drawstage:%lx hdc:%x item:%lx, itemstate:%x\n",
|
|---|
| 3248 | // dwDrawStage, hdc, dwItemSpec, uItemState);
|
|---|
| 3249 |
|
|---|
| 3250 | retval = sendNotify(hwnd,NM_CUSTOMDRAW,&nmcdhdr.nmcd.hdr);
|
|---|
| 3251 |
|
|---|
| 3252 | infoPtr->clrText=nmcdhdr.clrText;
|
|---|
| 3253 | infoPtr->clrBk =nmcdhdr.clrTextBk;
|
|---|
| 3254 |
|
|---|
| 3255 | return (BOOL) retval;
|
|---|
| 3256 | }
|
|---|
| 3257 |
|
|---|
| 3258 | static VOID TREEVIEW_SendKeyDownNotify(HWND hwnd,UINT code,WORD wVKey)
|
|---|
| 3259 | {
|
|---|
| 3260 | NMTVKEYDOWN nmkdhdr;
|
|---|
| 3261 |
|
|---|
| 3262 | nmkdhdr.wVKey = wVKey;
|
|---|
| 3263 | nmkdhdr.flags = 0;
|
|---|
| 3264 |
|
|---|
| 3265 | sendNotify(hwnd,code,&nmkdhdr.hdr);
|
|---|
| 3266 | }
|
|---|
| 3267 |
|
|---|
| 3268 | /* Note:If the specified item is the child of a collapsed parent item,
|
|---|
| 3269 | the parent's list of child items is (recursively) expanded to reveal the
|
|---|
| 3270 | specified item. This is mentioned for TREEVIEW_SelectItem; don't
|
|---|
| 3271 | know if it also applies here.
|
|---|
| 3272 | */
|
|---|
| 3273 |
|
|---|
| 3274 | static LRESULT
|
|---|
| 3275 | TREEVIEW_Expand (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 3276 | {
|
|---|
| 3277 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3278 | TREEVIEW_ITEM *wineItem;
|
|---|
| 3279 | UINT flag;
|
|---|
| 3280 | INT expand;
|
|---|
| 3281 |
|
|---|
| 3282 | flag = (UINT)wParam;
|
|---|
| 3283 | expand = (INT)lParam;
|
|---|
| 3284 |
|
|---|
| 3285 | wineItem = TREEVIEW_ValidItem (infoPtr,(HTREEITEM)expand);
|
|---|
| 3286 |
|
|---|
| 3287 | if (!wineItem)
|
|---|
| 3288 | return 0;
|
|---|
| 3289 |
|
|---|
| 3290 | if (!TREEVIEW_HasChildren(hwnd, wineItem))
|
|---|
| 3291 | return 0;
|
|---|
| 3292 |
|
|---|
| 3293 | if ((flag & 0xF) == TVE_TOGGLE)
|
|---|
| 3294 | {
|
|---|
| 3295 | if (wineItem->state & TVIS_EXPANDED)
|
|---|
| 3296 | flag = (flag & ~0xF)+TVE_COLLAPSE;
|
|---|
| 3297 | else
|
|---|
| 3298 | flag = (flag & ~0xF)+TVE_EXPAND;
|
|---|
| 3299 | }
|
|---|
| 3300 |
|
|---|
| 3301 | switch (flag & 0xF)
|
|---|
| 3302 | {
|
|---|
| 3303 | case TVE_COLLAPSE:
|
|---|
| 3304 | {
|
|---|
| 3305 | POINT oldLeftTop = infoPtr->lefttop;
|
|---|
| 3306 |
|
|---|
| 3307 | if (!wineItem->state & TVIS_EXPANDED)
|
|---|
| 3308 | return 0;
|
|---|
| 3309 |
|
|---|
| 3310 | if (flag & TVE_COLLAPSERESET)
|
|---|
| 3311 | {
|
|---|
| 3312 | wineItem->state &= ~(TVIS_EXPANDEDONCE | TVIS_EXPANDED);
|
|---|
| 3313 | TREEVIEW_RemoveAllChildren (hwnd, wineItem);
|
|---|
| 3314 | } else wineItem->state &= ~TVIS_EXPANDED;
|
|---|
| 3315 |
|
|---|
| 3316 | //update window
|
|---|
| 3317 | //CB: todo: optimize!
|
|---|
| 3318 | TREEVIEW_UnqueueRefresh(hwnd,FALSE,FALSE);
|
|---|
| 3319 | //CB: todo: precalc expanded items here
|
|---|
| 3320 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 3321 | TREEVIEW_Refresh(hwnd);
|
|---|
| 3322 | //CB: todo: check cx and cy to fit ranges!
|
|---|
| 3323 |
|
|---|
| 3324 | //check selection
|
|---|
| 3325 | HTREEITEM hItem = infoPtr->selectedItem;
|
|---|
| 3326 |
|
|---|
| 3327 | if (!TREEVIEW_ValidItem (infoPtr, hItem))
|
|---|
| 3328 | hItem = wineItem->hItem;
|
|---|
| 3329 | else
|
|---|
| 3330 | {
|
|---|
| 3331 | while (hItem)
|
|---|
| 3332 | {
|
|---|
| 3333 | hItem = infoPtr->items[(INT)hItem].parent;
|
|---|
| 3334 |
|
|---|
| 3335 | if (hItem == wineItem->hItem)
|
|---|
| 3336 | break;
|
|---|
| 3337 | }
|
|---|
| 3338 | }
|
|---|
| 3339 |
|
|---|
| 3340 | if (hItem)
|
|---|
| 3341 | TREEVIEW_DoSelectItem(hwnd,TVGN_CARET,hItem,TVC_UNKNOWN);
|
|---|
| 3342 |
|
|---|
| 3343 | break;
|
|---|
| 3344 | }
|
|---|
| 3345 |
|
|---|
| 3346 | case TVE_EXPAND:
|
|---|
| 3347 | {
|
|---|
| 3348 | POINT oldLeftTop = infoPtr->lefttop;
|
|---|
| 3349 |
|
|---|
| 3350 | if (wineItem->state & TVIS_EXPANDED)
|
|---|
| 3351 | return 0;
|
|---|
| 3352 |
|
|---|
| 3353 | if (flag & TVE_EXPANDPARTIAL)
|
|---|
| 3354 | {
|
|---|
| 3355 | return FALSE; //CB: how does this work??? (only display one level? nonsense in MSDN docu)
|
|---|
| 3356 | wineItem->state ^=TVIS_EXPANDED;
|
|---|
| 3357 | wineItem->state |=TVIS_EXPANDEDONCE;
|
|---|
| 3358 | break;
|
|---|
| 3359 | }
|
|---|
| 3360 |
|
|---|
| 3361 | if (!(wineItem->state & TVIS_EXPANDEDONCE))
|
|---|
| 3362 | {
|
|---|
| 3363 | //TRACE(treeview, " and has never been expanded...\n");
|
|---|
| 3364 | wineItem->state |= TVIS_EXPANDED;
|
|---|
| 3365 |
|
|---|
| 3366 | /* this item has never been expanded */
|
|---|
| 3367 | if (TREEVIEW_SendTreeviewNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_ITEMEXPANDINGW:TVN_ITEMEXPANDINGA,TVE_EXPAND,0,(HTREEITEM)expand))
|
|---|
| 3368 | return FALSE;
|
|---|
| 3369 |
|
|---|
| 3370 |
|
|---|
| 3371 | /* FIXME
|
|---|
| 3372 | * Since the TVN_ITEMEXPANDING message may has caused the parent to
|
|---|
| 3373 | * insert new items which in turn may have cause items placeholder
|
|---|
| 3374 | * reallocation, I reassign the current item pointer so we have
|
|---|
| 3375 | * something valid to work with...
|
|---|
| 3376 | * However, this should not be necessary,
|
|---|
| 3377 | * investigation required in TREEVIEW_InsertItemA
|
|---|
| 3378 | */
|
|---|
| 3379 | wineItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM)expand);
|
|---|
| 3380 | if (!wineItem)
|
|---|
| 3381 | {
|
|---|
| 3382 | //ERR(treeview,
|
|---|
| 3383 | // "Catastropic situation, cannot retreive item #%d\n",
|
|---|
| 3384 | // expand);
|
|---|
| 3385 | return FALSE;
|
|---|
| 3386 | }
|
|---|
| 3387 |
|
|---|
| 3388 | wineItem->state |= TVIS_EXPANDEDONCE;
|
|---|
| 3389 |
|
|---|
| 3390 | TREEVIEW_SendTreeviewNotify (hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_ITEMEXPANDEDW:TVN_ITEMEXPANDEDA,TVE_EXPAND,0,(HTREEITEM)expand);
|
|---|
| 3391 | } else
|
|---|
| 3392 | {
|
|---|
| 3393 | /* this item has already been expanded */
|
|---|
| 3394 | wineItem->state |= TVIS_EXPANDED;
|
|---|
| 3395 | }
|
|---|
| 3396 |
|
|---|
| 3397 | //update window
|
|---|
| 3398 | //CB: todo: optimize!
|
|---|
| 3399 | TREEVIEW_UnqueueRefresh(hwnd,FALSE,FALSE);
|
|---|
| 3400 | //CB: todo: precalc expanded items here
|
|---|
| 3401 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 3402 | TREEVIEW_Refresh(hwnd);
|
|---|
| 3403 | //CB: todo: check cx and cy to fit ranges!
|
|---|
| 3404 |
|
|---|
| 3405 | break;
|
|---|
| 3406 | }
|
|---|
| 3407 |
|
|---|
| 3408 | default:
|
|---|
| 3409 | return FALSE;
|
|---|
| 3410 | }
|
|---|
| 3411 |
|
|---|
| 3412 | return TRUE;
|
|---|
| 3413 | }
|
|---|
| 3414 |
|
|---|
| 3415 | static LRESULT TREEVIEW_HitTest(HWND hwnd,LPTVHITTESTINFO lpht,BOOL ignoreClientRect)
|
|---|
| 3416 | {
|
|---|
| 3417 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3418 | TREEVIEW_ITEM *wineItem;
|
|---|
| 3419 | RECT rect;
|
|---|
| 3420 | UINT status;
|
|---|
| 3421 | INT x,y;
|
|---|
| 3422 |
|
|---|
| 3423 | if (!lpht) return 0;
|
|---|
| 3424 |
|
|---|
| 3425 | status = 0;
|
|---|
| 3426 | x = lpht->pt.x;
|
|---|
| 3427 | y = lpht->pt.y;
|
|---|
| 3428 |
|
|---|
| 3429 | if (!ignoreClientRect)
|
|---|
| 3430 | {
|
|---|
| 3431 | GetClientRect (hwnd, &rect);
|
|---|
| 3432 |
|
|---|
| 3433 | if (x < rect.left) status |= TVHT_TOLEFT;
|
|---|
| 3434 | if (x > rect.right) status |= TVHT_TORIGHT;
|
|---|
| 3435 | if (y < rect.top ) status |= TVHT_ABOVE;
|
|---|
| 3436 | if (y > rect.bottom) status |= TVHT_BELOW;
|
|---|
| 3437 |
|
|---|
| 3438 | if (status)
|
|---|
| 3439 | {
|
|---|
| 3440 | lpht->flags = status;
|
|---|
| 3441 | lpht->hItem = 0;
|
|---|
| 3442 |
|
|---|
| 3443 | return 0;
|
|---|
| 3444 | }
|
|---|
| 3445 | }
|
|---|
| 3446 |
|
|---|
| 3447 | if (infoPtr->firstVisible)
|
|---|
| 3448 | {
|
|---|
| 3449 | wineItem = &infoPtr->items [(INT)infoPtr->firstVisible];
|
|---|
| 3450 |
|
|---|
| 3451 | while ((wineItem != NULL) && (y > wineItem->rect.bottom))
|
|---|
| 3452 | wineItem = TREEVIEW_GetNextListItem(hwnd,infoPtr,wineItem);
|
|---|
| 3453 | } else wineItem = NULL;
|
|---|
| 3454 |
|
|---|
| 3455 | if (!wineItem)
|
|---|
| 3456 | {
|
|---|
| 3457 | lpht->flags = TVHT_NOWHERE;
|
|---|
| 3458 | lpht->hItem = 0;
|
|---|
| 3459 |
|
|---|
| 3460 | return 0;
|
|---|
| 3461 | }
|
|---|
| 3462 |
|
|---|
| 3463 | lpht->flags = 0;
|
|---|
| 3464 |
|
|---|
| 3465 | if (x < wineItem->expandBox.left) {
|
|---|
| 3466 | lpht->flags |= TVHT_ONITEMINDENT;
|
|---|
| 3467 | goto done;
|
|---|
| 3468 | }
|
|---|
| 3469 | if ( PtInRect ( &wineItem->expandBox, lpht->pt)) {
|
|---|
| 3470 | lpht->flags |= TVHT_ONITEMBUTTON;
|
|---|
| 3471 | goto done;
|
|---|
| 3472 | }
|
|---|
| 3473 | if ( PtInRect ( &wineItem->bitmap, lpht->pt)) {
|
|---|
| 3474 | lpht->flags |= TVHT_ONITEMICON;
|
|---|
| 3475 | goto done;
|
|---|
| 3476 | }
|
|---|
| 3477 | if ( PtInRect ( &wineItem->statebitmap, lpht->pt)) {
|
|---|
| 3478 | lpht->flags |= TVHT_ONITEMSTATEICON;
|
|---|
| 3479 | goto done;
|
|---|
| 3480 | }
|
|---|
| 3481 | if ( PtInRect ( &wineItem->text, lpht->pt)) {
|
|---|
| 3482 | lpht->flags |= TVHT_ONITEMLABEL;
|
|---|
| 3483 | goto done;
|
|---|
| 3484 | }
|
|---|
| 3485 |
|
|---|
| 3486 | lpht->flags |= TVHT_ONITEMRIGHT;
|
|---|
| 3487 |
|
|---|
| 3488 | done:
|
|---|
| 3489 | lpht->hItem = wineItem->hItem;
|
|---|
| 3490 |
|
|---|
| 3491 | return (LRESULT) wineItem->hItem;
|
|---|
| 3492 | }
|
|---|
| 3493 |
|
|---|
| 3494 | HWND TREEVIEW_EditLabel(HWND hwnd,HTREEITEM hItem,BOOL unicode)
|
|---|
| 3495 | {
|
|---|
| 3496 | SIZE sz;
|
|---|
| 3497 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3498 | TREEVIEW_ITEM *editItem = TREEVIEW_ValidItem(infoPtr, (HTREEITEM)hItem);
|
|---|
| 3499 | HINSTANCE hinst = GetWindowLongA(hwnd, GWL_HINSTANCE);
|
|---|
| 3500 | HDC hdc;
|
|---|
| 3501 | HFONT hOldFont = 0;
|
|---|
| 3502 | TEXTMETRICA textMetric;
|
|---|
| 3503 | WCHAR* textW;
|
|---|
| 3504 | CHAR* textA = NULL;
|
|---|
| 3505 | BOOL mustFree = FALSE;
|
|---|
| 3506 | NMTVDISPINFOW tvdi;
|
|---|
| 3507 |
|
|---|
| 3508 | if (!editItem)
|
|---|
| 3509 | return FALSE;
|
|---|
| 3510 |
|
|---|
| 3511 | if(infoPtr->hwndEdit)
|
|---|
| 3512 | return infoPtr->hwndEdit;
|
|---|
| 3513 |
|
|---|
| 3514 | /* Make shure that edit item is selected */
|
|---|
| 3515 |
|
|---|
| 3516 | TREEVIEW_DoSelectItem ( hwnd, TVGN_CARET, hItem, TVC_UNKNOWN);
|
|---|
| 3517 |
|
|---|
| 3518 | if (editItem->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 3519 | textW = TREEVIEW_CallbackText(hwnd,editItem,&mustFree);
|
|---|
| 3520 | else
|
|---|
| 3521 | textW = editItem->pszText;
|
|---|
| 3522 |
|
|---|
| 3523 | hdc = GetDC(hwnd);
|
|---|
| 3524 | /* Select the font to get appropriate metric dimensions */
|
|---|
| 3525 | if(infoPtr->hFont != 0)
|
|---|
| 3526 | {
|
|---|
| 3527 | hOldFont = SelectObject(hdc, infoPtr->hFont);
|
|---|
| 3528 | }
|
|---|
| 3529 |
|
|---|
| 3530 | /*Get String Lenght in pixels */
|
|---|
| 3531 | GetTextExtentPoint32W(hdc,textW,lstrlenW(textW),&sz);
|
|---|
| 3532 |
|
|---|
| 3533 | /*Add Extra spacing for the next character */
|
|---|
| 3534 | GetTextMetricsA(hdc, &textMetric);
|
|---|
| 3535 | sz.cx += (textMetric.tmMaxCharWidth * 2);
|
|---|
| 3536 |
|
|---|
| 3537 | if(infoPtr->hFont != 0)
|
|---|
| 3538 | {
|
|---|
| 3539 | SelectObject(hdc, hOldFont);
|
|---|
| 3540 | }
|
|---|
| 3541 |
|
|---|
| 3542 | ReleaseDC(hwnd, hdc);
|
|---|
| 3543 | infoPtr->hwndEdit = CreateWindowExA (
|
|---|
| 3544 | WS_EX_LEFT,
|
|---|
| 3545 | "EDIT",
|
|---|
| 3546 | 0,
|
|---|
| 3547 | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | WS_CLIPSIBLINGS |
|
|---|
| 3548 | ES_WANTRETURN | ES_LEFT,
|
|---|
| 3549 | editItem->text.left - 2, editItem->text.top - 1,
|
|---|
| 3550 | sz.cx+3, editItem->text.bottom - editItem->text.top + 3,
|
|---|
| 3551 | hwnd,
|
|---|
| 3552 | 0,hinst,0); /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0);*/
|
|---|
| 3553 |
|
|---|
| 3554 | SendMessageA ( infoPtr->hwndEdit, WM_SETFONT, infoPtr->hFont, FALSE);
|
|---|
| 3555 | infoPtr->wpEditOrig = (WNDPROC)SetWindowLongA (
|
|---|
| 3556 | infoPtr->hwndEdit,
|
|---|
| 3557 | GWL_WNDPROC,
|
|---|
| 3558 | (DWORD) TREEVIEW_Edit_SubclassProc);
|
|---|
| 3559 |
|
|---|
| 3560 | tvdi.item.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
|
|---|
| 3561 | tvdi.item.hItem = editItem->hItem;
|
|---|
| 3562 | tvdi.item.state = editItem->state;
|
|---|
| 3563 | tvdi.item.lParam = editItem->lParam;
|
|---|
| 3564 | if (isUnicodeNotify(&infoPtr->header))
|
|---|
| 3565 | {
|
|---|
| 3566 | tvdi.item.pszText = textW;
|
|---|
| 3567 | } else
|
|---|
| 3568 | {
|
|---|
| 3569 | textA = HEAP_strdupWtoA(GetProcessHeap(),0,textW);
|
|---|
| 3570 | tvdi.item.pszText = (LPWSTR)textA;
|
|---|
| 3571 | }
|
|---|
| 3572 |
|
|---|
| 3573 | if (sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_BEGINLABELEDITW:TVN_BEGINLABELEDITA,&tvdi.hdr))
|
|---|
| 3574 | {
|
|---|
| 3575 | DestroyWindow(infoPtr->hwndEdit);
|
|---|
| 3576 | infoPtr->hwndEdit = 0;
|
|---|
| 3577 | if (mustFree) COMCTL32_Free(textW);
|
|---|
| 3578 | if (textA) COMCTL32_Free(textA);
|
|---|
| 3579 |
|
|---|
| 3580 | return (HWND)0;
|
|---|
| 3581 | }
|
|---|
| 3582 | if (textA) HeapFree(GetProcessHeap(),0,textA);
|
|---|
| 3583 |
|
|---|
| 3584 | infoPtr->editItem = hItem;
|
|---|
| 3585 | SetWindowTextW(infoPtr->hwndEdit,textW);
|
|---|
| 3586 | SetFocus(infoPtr->hwndEdit);
|
|---|
| 3587 | SendMessageA(infoPtr->hwndEdit, EM_SETSEL, 0, -1);
|
|---|
| 3588 | ShowWindow(infoPtr->hwndEdit, SW_SHOW);
|
|---|
| 3589 | if (mustFree) COMCTL32_Free(textW);
|
|---|
| 3590 |
|
|---|
| 3591 | return infoPtr->hwndEdit;
|
|---|
| 3592 | }
|
|---|
| 3593 |
|
|---|
| 3594 |
|
|---|
| 3595 | LRESULT WINAPI
|
|---|
| 3596 | TREEVIEW_EndEditLabelNow(HWND hwnd,BOOL bCancel)
|
|---|
| 3597 | {
|
|---|
| 3598 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3599 | TREEVIEW_ITEM *editedItem = TREEVIEW_ValidItem (infoPtr, infoPtr->editItem);
|
|---|
| 3600 | NMTVDISPINFOW tvdi;
|
|---|
| 3601 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 3602 | BOOL bCommit;
|
|---|
| 3603 | WCHAR *textW = NULL;
|
|---|
| 3604 | CHAR *textA = NULL;
|
|---|
| 3605 | int iLength = 0;
|
|---|
| 3606 |
|
|---|
| 3607 | if (!infoPtr->hwndEdit)
|
|---|
| 3608 | return FALSE;
|
|---|
| 3609 |
|
|---|
| 3610 | tvdi.item.mask = 0;
|
|---|
| 3611 | tvdi.item.hItem = editedItem->hItem;
|
|---|
| 3612 | tvdi.item.state = editedItem->state;
|
|---|
| 3613 | tvdi.item.lParam = editedItem->lParam;
|
|---|
| 3614 |
|
|---|
| 3615 | if (!bCancel)
|
|---|
| 3616 | {
|
|---|
| 3617 | textW = (WCHAR*)COMCTL32_Alloc(1024*sizeof(WCHAR));
|
|---|
| 3618 | iLength = GetWindowTextW(infoPtr->hwndEdit,textW,1023);
|
|---|
| 3619 |
|
|---|
| 3620 | if (isUnicodeNotify(&infoPtr->header)) tvdi.item.pszText = textW; else
|
|---|
| 3621 | {
|
|---|
| 3622 | INT len = iLength+1;
|
|---|
| 3623 |
|
|---|
| 3624 | textA = (CHAR*)COMCTL32_Alloc(len*sizeof(CHAR));
|
|---|
| 3625 | lstrcpynWtoA(textA,textW,len);
|
|---|
| 3626 | tvdi.item.pszText = (WCHAR*)textA;
|
|---|
| 3627 | }
|
|---|
| 3628 | tvdi.item.cchTextMax = iLength + 1;
|
|---|
| 3629 | } else
|
|---|
| 3630 | {
|
|---|
| 3631 | tvdi.item.pszText = NULL;
|
|---|
| 3632 | tvdi.item.cchTextMax = 0;
|
|---|
| 3633 | }
|
|---|
| 3634 |
|
|---|
| 3635 | bCommit = (BOOL)sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_ENDLABELEDITW:TVN_ENDLABELEDITA,&tvdi.hdr);
|
|---|
| 3636 |
|
|---|
| 3637 | if (!bCancel && bCommit) /* Apply the changes */
|
|---|
| 3638 | {
|
|---|
| 3639 | WCHAR* text;
|
|---|
| 3640 | BOOL mustFree = FALSE;
|
|---|
| 3641 |
|
|---|
| 3642 | if (!isUnicodeNotify(&infoPtr->header))
|
|---|
| 3643 | lstrcpynAtoW(textW,textA,iLength+1);
|
|---|
| 3644 |
|
|---|
| 3645 | if (editedItem->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 3646 | text = TREEVIEW_CallbackText(hwnd,editedItem,&mustFree);
|
|---|
| 3647 | else
|
|---|
| 3648 | text = editedItem->pszText;
|
|---|
| 3649 |
|
|---|
| 3650 | if (lstrcmpW(textW,text) != 0)
|
|---|
| 3651 | {
|
|---|
| 3652 | if (editedItem->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 3653 | {
|
|---|
| 3654 | NMTVDISPINFOW tvdi;
|
|---|
| 3655 | BOOL retval;
|
|---|
| 3656 |
|
|---|
| 3657 | tvdi.item.mask = TVIF_TEXT;
|
|---|
| 3658 | tvdi.item.hItem = editedItem->hItem;
|
|---|
| 3659 | tvdi.item.state = editedItem->state;
|
|---|
| 3660 | tvdi.item.lParam = editedItem->lParam;
|
|---|
| 3661 | if (isUnicodeNotify(&infoPtr->header))
|
|---|
| 3662 | {
|
|---|
| 3663 | tvdi.item.pszText = textW;
|
|---|
| 3664 | tvdi.item.cchTextMax = lstrlenW(textW)+1;
|
|---|
| 3665 | } else
|
|---|
| 3666 | {
|
|---|
| 3667 | tvdi.item.pszText = (LPWSTR)textA;
|
|---|
| 3668 | tvdi.item.cchTextMax = lstrlenA(textA)+1;
|
|---|
| 3669 | }
|
|---|
| 3670 |
|
|---|
| 3671 | retval = (BOOL)sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_SETDISPINFOW:TVN_SETDISPINFOA,&tvdi.hdr);
|
|---|
| 3672 | } else
|
|---|
| 3673 | {
|
|---|
| 3674 | if (!COMCTL32_ReAlloc(text,(iLength+1)*sizeof(WCHAR)))
|
|---|
| 3675 | {
|
|---|
| 3676 | //ERR("OutOfMemory, cannot allocate space for label");
|
|---|
| 3677 | DestroyWindow(infoPtr->hwndEdit);
|
|---|
| 3678 | infoPtr->hwndEdit = 0;
|
|---|
| 3679 | if (textA) COMCTL32_Free(textA);
|
|---|
| 3680 | if (textW) COMCTL32_Free(textW);
|
|---|
| 3681 | if (mustFree) COMCTL32_Free(text);
|
|---|
| 3682 |
|
|---|
| 3683 | return FALSE;
|
|---|
| 3684 | } else
|
|---|
| 3685 | {
|
|---|
| 3686 | editedItem->cchTextMax = iLength + 1;
|
|---|
| 3687 | lstrcpyW(editedItem->pszText,textW);
|
|---|
| 3688 | }
|
|---|
| 3689 | }
|
|---|
| 3690 | }
|
|---|
| 3691 | if (mustFree) COMCTL32_Free(text);
|
|---|
| 3692 | }
|
|---|
| 3693 |
|
|---|
| 3694 | ShowWindow(infoPtr->hwndEdit, SW_HIDE);
|
|---|
| 3695 | DestroyWindow(infoPtr->hwndEdit);
|
|---|
| 3696 | infoPtr->hwndEdit = 0;
|
|---|
| 3697 | infoPtr->editItem = 0;
|
|---|
| 3698 | if (textA) COMCTL32_Free(textA);
|
|---|
| 3699 | if (textW) COMCTL32_Free(textW);
|
|---|
| 3700 |
|
|---|
| 3701 | editedItem->calculated = FALSE;
|
|---|
| 3702 | TREEVIEW_CalcItem(hwnd,0,dwStyle,infoPtr,editedItem);
|
|---|
| 3703 | TREEVIEW_RefreshItem(hwnd,editedItem,TRUE);
|
|---|
| 3704 |
|
|---|
| 3705 | return TRUE;
|
|---|
| 3706 | }
|
|---|
| 3707 |
|
|---|
| 3708 |
|
|---|
| 3709 | /***************************************************************************
|
|---|
| 3710 | * This is quite unusual piece of code, but that's how it's implemented in
|
|---|
| 3711 | * Windows.
|
|---|
| 3712 | */
|
|---|
| 3713 | static LRESULT TREEVIEW_TrackMouse(HWND hwnd, POINT pt)
|
|---|
| 3714 | {
|
|---|
| 3715 | INT cxDrag = GetSystemMetrics(SM_CXDRAG);
|
|---|
| 3716 | INT cyDrag = GetSystemMetrics(SM_CYDRAG);
|
|---|
| 3717 | RECT r;
|
|---|
| 3718 | MSG msg;
|
|---|
| 3719 |
|
|---|
| 3720 | r.top = pt.y - cyDrag;
|
|---|
| 3721 | r.left = pt.x - cxDrag;
|
|---|
| 3722 | r.bottom = pt.y + cyDrag;
|
|---|
| 3723 | r.right = pt.x + cxDrag;
|
|---|
| 3724 |
|
|---|
| 3725 | SetCapture(hwnd);
|
|---|
| 3726 |
|
|---|
| 3727 | while(1)
|
|---|
| 3728 | {
|
|---|
| 3729 | if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD))
|
|---|
| 3730 | {
|
|---|
| 3731 | if (msg.message == WM_MOUSEMOVE)
|
|---|
| 3732 | {
|
|---|
| 3733 | pt.x = (INT)LOWORD(msg.lParam);
|
|---|
| 3734 | pt.y = (INT)HIWORD(msg.lParam);
|
|---|
| 3735 | if (PtInRect(&r, pt))
|
|---|
| 3736 | continue;
|
|---|
| 3737 | else
|
|---|
| 3738 | {
|
|---|
| 3739 | ReleaseCapture();
|
|---|
| 3740 | return 1;
|
|---|
| 3741 | }
|
|---|
| 3742 | }
|
|---|
| 3743 | else if (msg.message >= WM_LBUTTONDOWN &&
|
|---|
| 3744 | msg.message <= WM_RBUTTONDBLCLK)
|
|---|
| 3745 | {
|
|---|
| 3746 | if (msg.message == WM_RBUTTONUP)
|
|---|
| 3747 | TREEVIEW_RButtonUp (hwnd, &pt);
|
|---|
| 3748 | break;
|
|---|
| 3749 | }
|
|---|
| 3750 |
|
|---|
| 3751 | DispatchMessageA( &msg );
|
|---|
| 3752 | }
|
|---|
| 3753 |
|
|---|
| 3754 | if (GetCapture() != hwnd)
|
|---|
| 3755 | return 0;
|
|---|
| 3756 | }
|
|---|
| 3757 |
|
|---|
| 3758 | ReleaseCapture();
|
|---|
| 3759 | return 0;
|
|---|
| 3760 | }
|
|---|
| 3761 |
|
|---|
| 3762 | static LRESULT
|
|---|
| 3763 | TREEVIEW_LButtonDoubleClick (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 3764 | {
|
|---|
| 3765 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3766 | TREEVIEW_ITEM *wineItem;
|
|---|
| 3767 | TV_HITTESTINFO hitinfo;
|
|---|
| 3768 |
|
|---|
| 3769 | hitinfo.pt.x = (INT)LOWORD(lParam);
|
|---|
| 3770 | hitinfo.pt.y = (INT)HIWORD(lParam);
|
|---|
| 3771 | SetFocus (hwnd);
|
|---|
| 3772 |
|
|---|
| 3773 | if (infoPtr->Timer & TV_EDIT_TIMER_SET)
|
|---|
| 3774 | {
|
|---|
| 3775 | /* If there is pending 'edit label' event - kill it now */
|
|---|
| 3776 | infoPtr->editItem = 0;
|
|---|
| 3777 | KillTimer (hwnd, TV_EDIT_TIMER);
|
|---|
| 3778 | }
|
|---|
| 3779 |
|
|---|
| 3780 | if (!TREEVIEW_HitTest(hwnd,&hitinfo,FALSE) || !(hitinfo.flags & TVHT_ONITEM)) return FALSE;
|
|---|
| 3781 | wineItem = &infoPtr->items [(INT)hitinfo.hItem];
|
|---|
| 3782 |
|
|---|
| 3783 | //MSDN documentation says: stop on non zero. but this isn't true in this case
|
|---|
| 3784 | if (!sendNotify(hwnd,NM_DBLCLK))
|
|---|
| 3785 | TREEVIEW_Expand (hwnd, (WPARAM) TVE_TOGGLE, (LPARAM) wineItem->hItem);
|
|---|
| 3786 |
|
|---|
| 3787 | return TRUE;
|
|---|
| 3788 | }
|
|---|
| 3789 |
|
|---|
| 3790 | HTREEITEM TREEVIEW_GetInfoTipItem(HWND hwnd,TREEVIEW_INFO *infoPtr,POINT pt)
|
|---|
| 3791 | {
|
|---|
| 3792 | TVHITTESTINFO ht;
|
|---|
| 3793 |
|
|---|
| 3794 | ht.pt = pt;
|
|---|
| 3795 | TREEVIEW_HitTest(hwnd,&ht,FALSE);
|
|---|
| 3796 |
|
|---|
| 3797 | if (ht.hItem && (ht.flags & TVHT_ONITEM))
|
|---|
| 3798 | {
|
|---|
| 3799 | TREEVIEW_ITEM *item;
|
|---|
| 3800 |
|
|---|
| 3801 | item = &infoPtr->items[(INT)ht.hItem];
|
|---|
| 3802 | if (item->visible && ((item->text.left < 0) || (item->text.right > infoPtr->uVisibleWidth)))
|
|---|
| 3803 | return ht.hItem;
|
|---|
| 3804 | }
|
|---|
| 3805 |
|
|---|
| 3806 | //check tool rect -> no flickering on tip frame
|
|---|
| 3807 | if (infoPtr->tipItem)
|
|---|
| 3808 | {
|
|---|
| 3809 | POINT pt2 = pt;
|
|---|
| 3810 | RECT rect;
|
|---|
| 3811 |
|
|---|
| 3812 | GetWindowRect(infoPtr->hwndToolTip,&rect);
|
|---|
| 3813 | ClientToScreen(hwnd,&pt2);
|
|---|
| 3814 | return PtInRect(&rect,pt2) ? infoPtr->tipItem:0;
|
|---|
| 3815 | }
|
|---|
| 3816 |
|
|---|
| 3817 | return 0;
|
|---|
| 3818 | }
|
|---|
| 3819 |
|
|---|
| 3820 | VOID TREEVIEW_ShowInfoTip(HWND hwnd,TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item)
|
|---|
| 3821 | {
|
|---|
| 3822 | LPWSTR text;
|
|---|
| 3823 | BOOL mustFree = FALSE;
|
|---|
| 3824 | TTTOOLINFOW ti;
|
|---|
| 3825 | POINT pt;
|
|---|
| 3826 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 3827 |
|
|---|
| 3828 | if (dwStyle & TVS_INFOTIP)
|
|---|
| 3829 | {
|
|---|
| 3830 | NMTVGETINFOTIPW tvgit;
|
|---|
| 3831 | WCHAR* buf = (WCHAR*)COMCTL32_Alloc(isUnicodeNotify(&infoPtr->header) ? INFOTIPSIZE*sizeof(WCHAR):INFOTIPSIZE*sizeof(CHAR));
|
|---|
| 3832 |
|
|---|
| 3833 | tvgit.pszText = buf;
|
|---|
| 3834 | tvgit.cchTextMax = INFOTIPSIZE;
|
|---|
| 3835 | tvgit.hItem = item->hItem;
|
|---|
| 3836 | tvgit.lParam = item->lParam;
|
|---|
| 3837 |
|
|---|
| 3838 | sendNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_GETINFOTIPW:TVN_GETINFOTIPA,&tvgit.hdr);
|
|---|
| 3839 | if (isUnicodeNotify(&infoPtr->header))
|
|---|
| 3840 | {
|
|---|
| 3841 | if (buf != tvgit.pszText) COMCTL32_Free(buf); else mustFree = TRUE;
|
|---|
| 3842 | text = tvgit.pszText;
|
|---|
| 3843 | } else
|
|---|
| 3844 | {
|
|---|
| 3845 | text = (WCHAR*)COMCTL32_Alloc(tvgit.cchTextMax*sizeof(WCHAR));
|
|---|
| 3846 | lstrcpyAtoW(text,(LPSTR)tvgit.pszText);
|
|---|
| 3847 | COMCTL32_Free(buf);
|
|---|
| 3848 | }
|
|---|
| 3849 | } else
|
|---|
| 3850 | {
|
|---|
| 3851 | if (item->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 3852 | text = TREEVIEW_CallbackText(hwnd,item,&mustFree);
|
|---|
| 3853 | else
|
|---|
| 3854 | text = item->pszText;
|
|---|
| 3855 | }
|
|---|
| 3856 |
|
|---|
| 3857 | infoPtr->tipItem = item->hItem;
|
|---|
| 3858 | SetTimer(hwnd,TV_INFOTIP_TIMER,TV_INFOTIP_DELAY,0);
|
|---|
| 3859 | infoPtr->Timer |= TV_INFOTIP_TIMER_SET;
|
|---|
| 3860 |
|
|---|
| 3861 | ti.cbSize = sizeof(ti);
|
|---|
| 3862 | ti.uId = 0;
|
|---|
| 3863 | ti.hwnd = hwnd;
|
|---|
| 3864 | ti.hinst = 0;
|
|---|
| 3865 | ti.lpszText = text;
|
|---|
| 3866 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)FALSE,(LPARAM)&ti);
|
|---|
| 3867 | pt.x = item->text.left;
|
|---|
| 3868 | pt.y = item->text.top;
|
|---|
| 3869 | ClientToScreen(hwnd,&pt);
|
|---|
| 3870 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(pt.x,pt.y));
|
|---|
| 3871 | SendMessageA(infoPtr->hwndToolTip,TTM_UPDATETIPTEXTW,0,(LPARAM)&ti);
|
|---|
| 3872 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&ti);
|
|---|
| 3873 |
|
|---|
| 3874 | if (mustFree) COMCTL32_Free(text);
|
|---|
| 3875 | }
|
|---|
| 3876 |
|
|---|
| 3877 | VOID TREEVIEW_HideInfoTip(HWND hwnd,TREEVIEW_INFO *infoPtr)
|
|---|
| 3878 | {
|
|---|
| 3879 | if (infoPtr->tipItem)
|
|---|
| 3880 | {
|
|---|
| 3881 | TTTOOLINFOA ti;
|
|---|
| 3882 |
|
|---|
| 3883 | infoPtr->tipItem = 0;
|
|---|
| 3884 | KillTimer(hwnd,TV_INFOTIP_TIMER);
|
|---|
| 3885 | infoPtr->Timer &= ~TV_INFOTIP_TIMER_SET;
|
|---|
| 3886 |
|
|---|
| 3887 | ti.cbSize = sizeof(TTTOOLINFOA);
|
|---|
| 3888 | ti.uId = 0;
|
|---|
| 3889 | ti.hwnd = (UINT)hwnd;
|
|---|
| 3890 |
|
|---|
| 3891 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)FALSE,(LPARAM)&ti);
|
|---|
| 3892 | }
|
|---|
| 3893 | }
|
|---|
| 3894 |
|
|---|
| 3895 | static VOID TREEVIEW_CheckInfoTip(HWND hwnd)
|
|---|
| 3896 | {
|
|---|
| 3897 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3898 | HTREEITEM hItem;
|
|---|
| 3899 | POINT pt;
|
|---|
| 3900 |
|
|---|
| 3901 | GetCursorPos(&pt);
|
|---|
| 3902 | ScreenToClient(hwnd,&pt);
|
|---|
| 3903 | hItem = TREEVIEW_GetInfoTipItem(hwnd,infoPtr,pt);
|
|---|
| 3904 |
|
|---|
| 3905 | if (hItem != infoPtr->tipItem)
|
|---|
| 3906 | TREEVIEW_HideInfoTip(hwnd,infoPtr);
|
|---|
| 3907 | }
|
|---|
| 3908 |
|
|---|
| 3909 | HTREEITEM TREEVIEW_GetHottrackItem(HWND hwnd,TREEVIEW_INFO *infoPtr,POINT pt)
|
|---|
| 3910 | {
|
|---|
| 3911 | TVHITTESTINFO ht;
|
|---|
| 3912 |
|
|---|
| 3913 | ht.pt = pt;
|
|---|
| 3914 | TREEVIEW_HitTest(hwnd,&ht,FALSE);
|
|---|
| 3915 |
|
|---|
| 3916 | return (ht.hItem && (ht.flags & TVHT_ONITEM)) ? ht.hItem:0;
|
|---|
| 3917 | }
|
|---|
| 3918 |
|
|---|
| 3919 | static LRESULT TREEVIEW_MouseMove(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 3920 | {
|
|---|
| 3921 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3922 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 3923 | POINT pt;
|
|---|
| 3924 |
|
|---|
| 3925 | pt.x = (INT)LOWORD(lParam);
|
|---|
| 3926 | pt.y = (INT)HIWORD(lParam);
|
|---|
| 3927 |
|
|---|
| 3928 | if (infoPtr->hwndToolTip)
|
|---|
| 3929 | {
|
|---|
| 3930 | HTREEITEM hItem = TREEVIEW_GetInfoTipItem(hwnd,infoPtr,pt);
|
|---|
| 3931 |
|
|---|
| 3932 | if (infoPtr->tipItem != hItem)
|
|---|
| 3933 | {
|
|---|
| 3934 | if (hItem)
|
|---|
| 3935 | {
|
|---|
| 3936 | TREEVIEW_ITEM *item;
|
|---|
| 3937 |
|
|---|
| 3938 | item = &infoPtr->items[(INT)hItem];
|
|---|
| 3939 | TREEVIEW_ShowInfoTip(hwnd,infoPtr,item);
|
|---|
| 3940 | } else TREEVIEW_HideInfoTip(hwnd,infoPtr);
|
|---|
| 3941 | }
|
|---|
| 3942 | }
|
|---|
| 3943 |
|
|---|
| 3944 | if (dwStyle & TVS_TRACKSELECT)
|
|---|
| 3945 | {
|
|---|
| 3946 | HTREEITEM hItem = TREEVIEW_GetHottrackItem(hwnd,infoPtr,pt);
|
|---|
| 3947 |
|
|---|
| 3948 | if (infoPtr->hotItem != hItem)
|
|---|
| 3949 | {
|
|---|
| 3950 | TREEVIEW_ITEM *item;
|
|---|
| 3951 | HDC hdc = 0;
|
|---|
| 3952 |
|
|---|
| 3953 | item = TREEVIEW_ValidItem(infoPtr,infoPtr->hotItem);
|
|---|
| 3954 | if (item)
|
|---|
| 3955 | {
|
|---|
| 3956 | if (!hdc) hdc = GetDC(hwnd);
|
|---|
| 3957 | TREEVIEW_DrawHottrackLine(hdc,item);
|
|---|
| 3958 | }
|
|---|
| 3959 | if (hItem)
|
|---|
| 3960 | {
|
|---|
| 3961 | item = &infoPtr->items[(INT)hItem];
|
|---|
| 3962 | if (item)
|
|---|
| 3963 | {
|
|---|
| 3964 | if (!hdc) hdc = GetDC(hwnd);
|
|---|
| 3965 | TREEVIEW_DrawHottrackLine(hdc,item);
|
|---|
| 3966 | }
|
|---|
| 3967 | }
|
|---|
| 3968 | if (hdc) ReleaseDC(hwnd,hdc);
|
|---|
| 3969 | }
|
|---|
| 3970 | }
|
|---|
| 3971 |
|
|---|
| 3972 | return 0;
|
|---|
| 3973 | }
|
|---|
| 3974 |
|
|---|
| 3975 | static LRESULT
|
|---|
| 3976 | TREEVIEW_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 3977 | {
|
|---|
| 3978 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 3979 | TVHITTESTINFO ht;
|
|---|
| 3980 | BOOL bTrack;
|
|---|
| 3981 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
|---|
| 3982 |
|
|---|
| 3983 | /* If Edit control is active - kill it and return.
|
|---|
| 3984 | * The best way to do it is to set focus to itself.
|
|---|
| 3985 | * Edit control subclassed procedure will automatically call
|
|---|
| 3986 | * EndEditLabelNow.
|
|---|
| 3987 | */
|
|---|
| 3988 | if (infoPtr->hwndEdit)
|
|---|
| 3989 | {
|
|---|
| 3990 | SetFocus (hwnd);
|
|---|
| 3991 | return 0;
|
|---|
| 3992 | }
|
|---|
| 3993 |
|
|---|
| 3994 | ht.pt.x = (INT)LOWORD(lParam);
|
|---|
| 3995 | ht.pt.y = (INT)HIWORD(lParam);
|
|---|
| 3996 |
|
|---|
| 3997 | TREEVIEW_HitTest (hwnd,&ht,FALSE);
|
|---|
| 3998 |
|
|---|
| 3999 | bTrack = (ht.flags & TVHT_ONITEM) && !(dwStyle & TVS_DISABLEDRAGDROP);
|
|---|
| 4000 |
|
|---|
| 4001 | /* Send NM_CLICK right away */
|
|---|
| 4002 | if (!bTrack)
|
|---|
| 4003 | if (sendNotify(hwnd,NM_CLICK))
|
|---|
| 4004 | goto setfocus;
|
|---|
| 4005 |
|
|---|
| 4006 | if (ht.flags & TVHT_ONITEMBUTTON)
|
|---|
| 4007 | {
|
|---|
| 4008 | TREEVIEW_Expand (hwnd, (WPARAM) TVE_TOGGLE, (LPARAM) ht.hItem);
|
|---|
| 4009 | goto setfocus;
|
|---|
| 4010 | } else if (bTrack)
|
|---|
| 4011 | {
|
|---|
| 4012 | if (TREEVIEW_TrackMouse(hwnd, ht.pt))
|
|---|
| 4013 | {
|
|---|
| 4014 | TREEVIEW_SendTreeviewDnDNotify (hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_BEGINDRAGW:TVN_BEGINDRAGA, ht.hItem, ht.pt);
|
|---|
| 4015 | infoPtr->dropItem = ht.hItem;
|
|---|
| 4016 | return 0;
|
|---|
| 4017 | }
|
|---|
| 4018 | }
|
|---|
| 4019 |
|
|---|
| 4020 | if (sendNotify(hwnd,NM_CLICK))
|
|---|
| 4021 | goto setfocus;
|
|---|
| 4022 |
|
|---|
| 4023 | /*
|
|---|
| 4024 | * If the style allow editing and the node is already selected
|
|---|
| 4025 | * and the click occured on the item label...
|
|---|
| 4026 | */
|
|---|
| 4027 | if ((dwStyle & TVS_EDITLABELS) && (ht.flags & TVHT_ONITEMLABEL) && (infoPtr->selectedItem == ht.hItem))
|
|---|
| 4028 | {
|
|---|
| 4029 | if (infoPtr->Timer & TV_EDIT_TIMER_SET)
|
|---|
| 4030 | KillTimer (hwnd, TV_EDIT_TIMER);
|
|---|
| 4031 |
|
|---|
| 4032 | infoPtr->editItem = ht.hItem;
|
|---|
| 4033 | SetTimer (hwnd, TV_EDIT_TIMER, GetDoubleClickTime(), 0);
|
|---|
| 4034 | infoPtr->Timer|=TV_EDIT_TIMER_SET;
|
|---|
| 4035 | } else if (ht.flags & (TVHT_ONITEMLABEL | TVHT_ONITEMICON))
|
|---|
| 4036 | {
|
|---|
| 4037 | TREEVIEW_DoSelectItem(hwnd,TVGN_CARET,ht.hItem,TVC_BYMOUSE);
|
|---|
| 4038 | } else if (ht.flags & TVHT_ONITEMSTATEICON)
|
|---|
| 4039 | {
|
|---|
| 4040 | if (dwStyle & TVS_CHECKBOXES) /* TVS_CHECKBOXES requires _us_ */
|
|---|
| 4041 | { /* to toggle the current state */
|
|---|
| 4042 | int state;
|
|---|
| 4043 | TREEVIEW_ITEM *wineItem;
|
|---|
| 4044 |
|
|---|
| 4045 | wineItem = TREEVIEW_ValidItem(infoPtr, ht.hItem);
|
|---|
| 4046 |
|
|---|
| 4047 | state = 1-(wineItem->state>>12);
|
|---|
| 4048 | wineItem->state &= ~TVIS_STATEIMAGEMASK;
|
|---|
| 4049 | wineItem->state |= state<<12;
|
|---|
| 4050 | if (wineItem->visible)
|
|---|
| 4051 | {
|
|---|
| 4052 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
|
|---|
| 4053 | InvalidateRect(hwnd,&wineItem->statebitmap,TRUE);
|
|---|
| 4054 | }
|
|---|
| 4055 | }
|
|---|
| 4056 | }
|
|---|
| 4057 |
|
|---|
| 4058 | setfocus:
|
|---|
| 4059 | SetFocus (hwnd);
|
|---|
| 4060 |
|
|---|
| 4061 | return 0;
|
|---|
| 4062 | }
|
|---|
| 4063 |
|
|---|
| 4064 |
|
|---|
| 4065 | static LRESULT
|
|---|
| 4066 | TREEVIEW_RButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4067 | {
|
|---|
| 4068 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4069 | TVHITTESTINFO ht;
|
|---|
| 4070 |
|
|---|
| 4071 | if (infoPtr->hwndEdit)
|
|---|
| 4072 | {
|
|---|
| 4073 | SetFocus(hwnd);
|
|---|
| 4074 | return 0;
|
|---|
| 4075 | }
|
|---|
| 4076 |
|
|---|
| 4077 | ht.pt.x = (INT)LOWORD(lParam);
|
|---|
| 4078 | ht.pt.y = (INT)HIWORD(lParam);
|
|---|
| 4079 |
|
|---|
| 4080 | TREEVIEW_HitTest(hwnd,&ht,FALSE);
|
|---|
| 4081 |
|
|---|
| 4082 | if (TREEVIEW_TrackMouse(hwnd, ht.pt))
|
|---|
| 4083 | {
|
|---|
| 4084 | if (ht.hItem)
|
|---|
| 4085 | {
|
|---|
| 4086 | TREEVIEW_SendTreeviewDnDNotify (hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_BEGINRDRAGW:TVN_BEGINDRAGA, ht.hItem, ht.pt);
|
|---|
| 4087 | infoPtr->dropItem = ht.hItem;
|
|---|
| 4088 | }
|
|---|
| 4089 | }
|
|---|
| 4090 | else
|
|---|
| 4091 | {
|
|---|
| 4092 | SetFocus(hwnd);
|
|---|
| 4093 | sendNotify(hwnd,NM_RCLICK);
|
|---|
| 4094 | }
|
|---|
| 4095 |
|
|---|
| 4096 | return 0;
|
|---|
| 4097 | }
|
|---|
| 4098 |
|
|---|
| 4099 | static LRESULT TREEVIEW_RButtonDoubleClick(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 4100 | {
|
|---|
| 4101 | sendNotify(hwnd,NM_RDBLCLK);
|
|---|
| 4102 |
|
|---|
| 4103 | return DefWindowProcA(hwnd,WM_RBUTTONDBLCLK,wParam,lParam);
|
|---|
| 4104 | }
|
|---|
| 4105 |
|
|---|
| 4106 | static LRESULT
|
|---|
| 4107 | TREEVIEW_RButtonUp (HWND hwnd, LPPOINT pPt)
|
|---|
| 4108 | {
|
|---|
| 4109 | POINT pt;
|
|---|
| 4110 |
|
|---|
| 4111 | pt.x = pPt->x;
|
|---|
| 4112 | pt.y = pPt->y;
|
|---|
| 4113 |
|
|---|
| 4114 | /* Change to screen coordinate for WM_CONTEXTMENU */
|
|---|
| 4115 | ClientToScreen(hwnd, &pt);
|
|---|
| 4116 |
|
|---|
| 4117 | /* Send the WM_CONTEXTMENU on a right click */
|
|---|
| 4118 | SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
|
|---|
| 4119 | return 0;
|
|---|
| 4120 | }
|
|---|
| 4121 |
|
|---|
| 4122 | static LRESULT TREEVIEW_CreateDragImage (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4123 | {
|
|---|
| 4124 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4125 | TREEVIEW_ITEM *dragItem;
|
|---|
| 4126 | INT cx,cy;
|
|---|
| 4127 | HDC hdc,htopdc;
|
|---|
| 4128 | HWND hwtop;
|
|---|
| 4129 | HBITMAP hbmp,hOldbmp;
|
|---|
| 4130 | SIZE size;
|
|---|
| 4131 | RECT rc;
|
|---|
| 4132 | HFONT hOldFont;
|
|---|
| 4133 | WCHAR *itemtxt;
|
|---|
| 4134 | BOOL mustFree = FALSE;
|
|---|
| 4135 |
|
|---|
| 4136 | if (!(infoPtr->himlNormal)) return 0;
|
|---|
| 4137 | dragItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM) lParam);
|
|---|
| 4138 |
|
|---|
| 4139 | if (!dragItem) return 0;
|
|---|
| 4140 |
|
|---|
| 4141 | if (dragItem->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 4142 | itemtxt = TREEVIEW_CallbackText(hwnd,dragItem,&mustFree);
|
|---|
| 4143 | else
|
|---|
| 4144 | itemtxt = dragItem->pszText;
|
|---|
| 4145 |
|
|---|
| 4146 | hwtop = GetDesktopWindow();
|
|---|
| 4147 | htopdc = GetDC(hwtop);
|
|---|
| 4148 | hdc = CreateCompatibleDC(htopdc);
|
|---|
| 4149 |
|
|---|
| 4150 | hOldFont = SelectObject (hdc, infoPtr->hFont);
|
|---|
| 4151 | GetTextExtentPoint32W (hdc, itemtxt, lstrlenW (itemtxt), &size);
|
|---|
| 4152 |
|
|---|
| 4153 | hbmp = CreateCompatibleBitmap (htopdc, size.cx, size.cy);
|
|---|
| 4154 | hOldbmp = SelectObject (hdc, hbmp);
|
|---|
| 4155 |
|
|---|
| 4156 | ImageList_GetIconSize (infoPtr->himlNormal, &cx, &cy);
|
|---|
| 4157 | size.cx += cx;
|
|---|
| 4158 | if (cy > size.cy) size.cy = cy;
|
|---|
| 4159 |
|
|---|
| 4160 | infoPtr->dragList = ImageList_Create (size.cx, size.cy, ILC_COLOR, 10, 10);
|
|---|
| 4161 | ImageList_Draw (infoPtr->himlNormal, dragItem->iImage, hdc, 0, 0, ILD_NORMAL);
|
|---|
| 4162 |
|
|---|
| 4163 | /*
|
|---|
| 4164 | ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
|
|---|
| 4165 | ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
|
|---|
| 4166 | */
|
|---|
| 4167 |
|
|---|
| 4168 | /* draw item text */
|
|---|
| 4169 |
|
|---|
| 4170 | SetRect (&rc, cx, 0, size.cx,size.cy);
|
|---|
| 4171 | DrawTextW (hdc, itemtxt, lstrlenW (itemtxt), &rc, DT_LEFT);
|
|---|
| 4172 | SelectObject (hdc, hOldFont);
|
|---|
| 4173 | SelectObject (hdc, hOldbmp);
|
|---|
| 4174 |
|
|---|
| 4175 | ImageList_Add (infoPtr->dragList, hbmp, 0);
|
|---|
| 4176 |
|
|---|
| 4177 | DeleteDC (hdc);
|
|---|
| 4178 | DeleteObject (hbmp);
|
|---|
| 4179 | ReleaseDC (hwtop, htopdc);
|
|---|
| 4180 | if (mustFree) COMCTL32_Free(itemtxt);
|
|---|
| 4181 |
|
|---|
| 4182 | return (LRESULT)infoPtr->dragList;
|
|---|
| 4183 | }
|
|---|
| 4184 |
|
|---|
| 4185 |
|
|---|
| 4186 | static LRESULT
|
|---|
| 4187 | TREEVIEW_DoSelectItem (HWND hwnd, INT action, HTREEITEM newSelect, INT cause)
|
|---|
| 4188 | {
|
|---|
| 4189 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4190 | TREEVIEW_ITEM *prevItem,*wineItem;
|
|---|
| 4191 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
|---|
| 4192 | INT prevSelect;
|
|---|
| 4193 | BOOL refreshPrev = FALSE,refreshNew = FALSE;
|
|---|
| 4194 |
|
|---|
| 4195 | wineItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM)newSelect);
|
|---|
| 4196 |
|
|---|
| 4197 | if (wineItem && wineItem->parent)
|
|---|
| 4198 | {
|
|---|
| 4199 | TREEVIEW_ITEM *parent = TREEVIEW_ValidItem(infoPtr,wineItem->parent);
|
|---|
| 4200 |
|
|---|
| 4201 | /*
|
|---|
| 4202 | * If the item has a collapse parent expand the parent so he
|
|---|
| 4203 | * can expose the item
|
|---|
| 4204 | */
|
|---|
| 4205 | while (parent && !(parent->state & TVIS_EXPANDED))
|
|---|
| 4206 | {
|
|---|
| 4207 | TREEVIEW_Expand(hwnd,TVE_EXPAND,(LPARAM)parent->hItem);
|
|---|
| 4208 | parent = TREEVIEW_ValidItem(infoPtr,parent->parent);
|
|---|
| 4209 | }
|
|---|
| 4210 | }
|
|---|
| 4211 |
|
|---|
| 4212 | switch (action)
|
|---|
| 4213 | {
|
|---|
| 4214 | case TVGN_CARET:
|
|---|
| 4215 | prevSelect = (INT)infoPtr->selectedItem;
|
|---|
| 4216 |
|
|---|
| 4217 | if ((HTREEITEM)prevSelect == newSelect)
|
|---|
| 4218 | return FALSE;
|
|---|
| 4219 |
|
|---|
| 4220 | prevItem = TREEVIEW_ValidItem (infoPtr, (HTREEITEM)prevSelect);
|
|---|
| 4221 |
|
|---|
| 4222 | if (newSelect)
|
|---|
| 4223 | if (TREEVIEW_SendTreeviewNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_SELCHANGINGW:TVN_SELCHANGINGA,cause,(HTREEITEM)prevSelect,(HTREEITEM)newSelect))
|
|---|
| 4224 | return FALSE; /* FIXME: OK? */
|
|---|
| 4225 |
|
|---|
| 4226 | if (prevItem)
|
|---|
| 4227 | {
|
|---|
| 4228 | refreshPrev = prevItem->state & TVIS_SELECTED;
|
|---|
| 4229 | prevItem->state &= ~TVIS_SELECTED;
|
|---|
| 4230 | }
|
|---|
| 4231 | if (wineItem)
|
|---|
| 4232 | {
|
|---|
| 4233 | refreshNew = !(wineItem->state & TVIS_SELECTED);
|
|---|
| 4234 | wineItem->state |= TVIS_SELECTED;
|
|---|
| 4235 | }
|
|---|
| 4236 |
|
|---|
| 4237 | infoPtr->selectedItem = (HTREEITEM)newSelect;
|
|---|
| 4238 |
|
|---|
| 4239 | if ((cause == TVC_BYMOUSE) && (dwStyle & TVS_SINGLEEXPAND))
|
|---|
| 4240 | {
|
|---|
| 4241 | BOOL control = GetKeyState(VK_CONTROL) & 0x8000;
|
|---|
| 4242 | UINT rc = TREEVIEW_SendTreeviewNotify(hwnd,TVN_SINGLEEXPAND,0,prevItem->hItem,wineItem->hItem);
|
|---|
| 4243 |
|
|---|
| 4244 | if (!(rc & TVNRET_SKIPOLD) && !control && prevItem->state & TVIS_EXPANDED)
|
|---|
| 4245 | TREEVIEW_Expand(hwnd,TVE_COLLAPSE,(LPARAM)prevItem->hItem);
|
|---|
| 4246 | if (!(rc & TVNRET_SKIPNEW) && TREEVIEW_HasChildren(hwnd,wineItem))
|
|---|
| 4247 | TREEVIEW_Expand(hwnd,TVE_TOGGLE,(LPARAM)wineItem->hItem);
|
|---|
| 4248 | }
|
|---|
| 4249 |
|
|---|
| 4250 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
|
|---|
| 4251 | if (dwStyle & TVS_FULLROWSELECT)
|
|---|
| 4252 | {
|
|---|
| 4253 | TREEVIEW_ITEM *item;
|
|---|
| 4254 |
|
|---|
| 4255 | //deselect last selected row
|
|---|
| 4256 | if (prevItem)
|
|---|
| 4257 | {
|
|---|
| 4258 | if (refreshPrev) TREEVIEW_RefreshItem(hwnd,prevItem,FALSE);
|
|---|
| 4259 | if (prevItem->upsibling)
|
|---|
| 4260 | {
|
|---|
| 4261 | item = &infoPtr->items[(INT)prevItem->upsibling];
|
|---|
| 4262 | while (item)
|
|---|
| 4263 | {
|
|---|
| 4264 | if (item->state & TVIS_SELECTED)
|
|---|
| 4265 | {
|
|---|
| 4266 | item->state &= ~TVIS_SELECTED;
|
|---|
| 4267 | TREEVIEW_RefreshItem(hwnd,item,FALSE);
|
|---|
| 4268 | }
|
|---|
| 4269 | item = &infoPtr->items[(INT)item->upsibling];
|
|---|
| 4270 | }
|
|---|
| 4271 | }
|
|---|
| 4272 | if (prevItem->sibling)
|
|---|
| 4273 | {
|
|---|
| 4274 | item = &infoPtr->items[(INT)prevItem->sibling];
|
|---|
| 4275 | while (item)
|
|---|
| 4276 | {
|
|---|
| 4277 | if (item->state & TVIS_SELECTED)
|
|---|
| 4278 | {
|
|---|
| 4279 | item->state &= ~TVIS_SELECTED;
|
|---|
| 4280 | TREEVIEW_RefreshItem(hwnd,item,FALSE);
|
|---|
| 4281 | }
|
|---|
| 4282 | item = &infoPtr->items[(INT)item->sibling];
|
|---|
| 4283 | }
|
|---|
| 4284 | }
|
|---|
| 4285 | }
|
|---|
| 4286 |
|
|---|
| 4287 | //select new row
|
|---|
| 4288 | if (wineItem)
|
|---|
| 4289 | {
|
|---|
| 4290 | if (refreshNew) TREEVIEW_RefreshItem(hwnd,wineItem,FALSE);
|
|---|
| 4291 | if (wineItem->upsibling)
|
|---|
| 4292 | {
|
|---|
| 4293 | item = &infoPtr->items[(INT)wineItem->upsibling];
|
|---|
| 4294 | while (item)
|
|---|
| 4295 | {
|
|---|
| 4296 | if (!(item->state & TVIS_SELECTED))
|
|---|
| 4297 | {
|
|---|
| 4298 | item->state |= TVIS_SELECTED;
|
|---|
| 4299 | TREEVIEW_RefreshItem(hwnd,item,FALSE);
|
|---|
| 4300 | }
|
|---|
| 4301 | item = &infoPtr->items[(INT)item->upsibling];
|
|---|
| 4302 | }
|
|---|
| 4303 | }
|
|---|
| 4304 | if (wineItem->sibling)
|
|---|
| 4305 | {
|
|---|
| 4306 | item = &infoPtr->items[(INT)wineItem->sibling];
|
|---|
| 4307 | while (item)
|
|---|
| 4308 | {
|
|---|
| 4309 | if (!(item->state & TVIS_SELECTED))
|
|---|
| 4310 | {
|
|---|
| 4311 | item->state |= TVIS_SELECTED;
|
|---|
| 4312 | TREEVIEW_RefreshItem(hwnd,item,FALSE);
|
|---|
| 4313 | }
|
|---|
| 4314 | item = &infoPtr->items[(INT)item->sibling];
|
|---|
| 4315 | }
|
|---|
| 4316 | }
|
|---|
| 4317 | }
|
|---|
| 4318 | } else
|
|---|
| 4319 | {
|
|---|
| 4320 | if (refreshPrev) TREEVIEW_RefreshItem(hwnd,prevItem,FALSE);
|
|---|
| 4321 | if (refreshNew) TREEVIEW_RefreshItem(hwnd,wineItem,FALSE);
|
|---|
| 4322 | }
|
|---|
| 4323 |
|
|---|
| 4324 | TREEVIEW_SendTreeviewNotify(hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_SELCHANGEDW:TVN_SELCHANGEDA,cause,(HTREEITEM)prevSelect,(HTREEITEM)newSelect);
|
|---|
| 4325 |
|
|---|
| 4326 | break;
|
|---|
| 4327 |
|
|---|
| 4328 | case TVGN_DROPHILITE:
|
|---|
| 4329 | prevItem = TREEVIEW_ValidItem (infoPtr, infoPtr->dropItem);
|
|---|
| 4330 |
|
|---|
| 4331 | if (prevItem)
|
|---|
| 4332 | {
|
|---|
| 4333 | refreshPrev = prevItem->state & TVIS_DROPHILITED;
|
|---|
| 4334 | prevItem->state &= ~TVIS_DROPHILITED;
|
|---|
| 4335 | }
|
|---|
| 4336 |
|
|---|
| 4337 | infoPtr->dropItem = (HTREEITEM)newSelect;
|
|---|
| 4338 |
|
|---|
| 4339 | if (wineItem)
|
|---|
| 4340 | {
|
|---|
| 4341 | refreshNew = !(wineItem->state & TVIS_DROPHILITED);
|
|---|
| 4342 | wineItem->state |=TVIS_DROPHILITED;
|
|---|
| 4343 | }
|
|---|
| 4344 |
|
|---|
| 4345 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
|
|---|
| 4346 | if (refreshPrev) TREEVIEW_RefreshItem(hwnd,prevItem,FALSE);
|
|---|
| 4347 | if (refreshNew) TREEVIEW_RefreshItem(hwnd,wineItem,FALSE);
|
|---|
| 4348 |
|
|---|
| 4349 | break;
|
|---|
| 4350 |
|
|---|
| 4351 | case TVGN_FIRSTVISIBLE:
|
|---|
| 4352 | {
|
|---|
| 4353 | TREEVIEW_ITEM *firstVis;
|
|---|
| 4354 | INT scrollY;
|
|---|
| 4355 |
|
|---|
| 4356 | if (!infoPtr->firstVisible) return FALSE;
|
|---|
| 4357 |
|
|---|
| 4358 | firstVis = &infoPtr->items[(INT)infoPtr->firstVisible];
|
|---|
| 4359 |
|
|---|
| 4360 | if (wineItem->rect.top < 0)
|
|---|
| 4361 | scrollY = wineItem->rect.top;
|
|---|
| 4362 | else
|
|---|
| 4363 | {
|
|---|
| 4364 | scrollY = MIN(wineItem->rect.top,(infoPtr->uTotalHeight-infoPtr->uVisibleHeight)-infoPtr->lefttop.y);
|
|---|
| 4365 | scrollY -= scrollY % infoPtr->uVScrollStep;
|
|---|
| 4366 | }
|
|---|
| 4367 |
|
|---|
| 4368 | if (scrollY != 0)
|
|---|
| 4369 | {
|
|---|
| 4370 | infoPtr->lefttop.y += scrollY;
|
|---|
| 4371 | if (!TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE))
|
|---|
| 4372 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 4373 |
|
|---|
| 4374 | ScrollWindowEx(hwnd,0,-scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
|---|
| 4375 | }
|
|---|
| 4376 |
|
|---|
| 4377 | break;
|
|---|
| 4378 | }
|
|---|
| 4379 | }
|
|---|
| 4380 |
|
|---|
| 4381 | return TRUE;
|
|---|
| 4382 | }
|
|---|
| 4383 |
|
|---|
| 4384 | static LRESULT
|
|---|
| 4385 | TREEVIEW_SelectItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4386 | {
|
|---|
| 4387 | return TREEVIEW_DoSelectItem (hwnd, wParam, (HTREEITEM) lParam, TVC_UNKNOWN);
|
|---|
| 4388 | }
|
|---|
| 4389 |
|
|---|
| 4390 | static LRESULT
|
|---|
| 4391 | TREEVIEW_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4392 | {
|
|---|
| 4393 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4394 |
|
|---|
| 4395 | return infoPtr->hFont;
|
|---|
| 4396 | }
|
|---|
| 4397 |
|
|---|
| 4398 | static LRESULT
|
|---|
| 4399 | TREEVIEW_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4400 | {
|
|---|
| 4401 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4402 | TEXTMETRICA tm;
|
|---|
| 4403 | LOGFONTA logFont;
|
|---|
| 4404 | HFONT hFont, hOldFont;
|
|---|
| 4405 | INT height;
|
|---|
| 4406 | HDC hdc;
|
|---|
| 4407 |
|
|---|
| 4408 | infoPtr->hFont = (HFONT)wParam;
|
|---|
| 4409 |
|
|---|
| 4410 | hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
|
|---|
| 4411 |
|
|---|
| 4412 | GetObjectA (infoPtr->hFont, sizeof (LOGFONTA), &logFont);
|
|---|
| 4413 | logFont.lfWeight = FW_BOLD;
|
|---|
| 4414 | DeleteObject(infoPtr->hBoldFont);
|
|---|
| 4415 | infoPtr->hBoldFont = CreateFontIndirectA (&logFont);
|
|---|
| 4416 |
|
|---|
| 4417 | SendMessageA(infoPtr->hwndToolTip,WM_SETFONT,infoPtr->hFont,1);
|
|---|
| 4418 | infoPtr->uInternalStatus |= TV_CALCALL;
|
|---|
| 4419 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 4420 |
|
|---|
| 4421 | if (lParam)
|
|---|
| 4422 | {
|
|---|
| 4423 | TREEVIEW_UnqueueRefresh(hwnd,FALSE,FALSE);
|
|---|
| 4424 | TREEVIEW_Refresh(hwnd);
|
|---|
| 4425 | }
|
|---|
| 4426 |
|
|---|
| 4427 | return 0;
|
|---|
| 4428 | }
|
|---|
| 4429 |
|
|---|
| 4430 | static LRESULT
|
|---|
| 4431 | TREEVIEW_VScroll(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 4432 | {
|
|---|
| 4433 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4434 | INT newY,mod;
|
|---|
| 4435 | INT maxY = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
|
|---|
| 4436 |
|
|---|
| 4437 | if (!(infoPtr->uInternalStatus & TV_VSCROLL)) return FALSE;
|
|---|
| 4438 |
|
|---|
| 4439 | mod = maxY % infoPtr->uVScrollStep;
|
|---|
| 4440 | if (mod > 0) maxY += infoPtr->uVScrollStep-mod;
|
|---|
| 4441 |
|
|---|
| 4442 | switch (LOWORD (wParam))
|
|---|
| 4443 | {
|
|---|
| 4444 | case SB_LINEUP:
|
|---|
| 4445 | newY = infoPtr->lefttop.y-infoPtr->uVScrollStep;
|
|---|
| 4446 | if (newY < 0) newY = 0;
|
|---|
| 4447 | break;
|
|---|
| 4448 |
|
|---|
| 4449 | case SB_LINEDOWN:
|
|---|
| 4450 | newY = infoPtr->lefttop.y+infoPtr->uVScrollStep;
|
|---|
| 4451 | if (newY > maxY) newY = maxY;
|
|---|
| 4452 | break;
|
|---|
| 4453 |
|
|---|
| 4454 | case SB_PAGEUP:
|
|---|
| 4455 | newY = infoPtr->lefttop.y-MAX(((INT)(infoPtr->uVisibleHeight/infoPtr->uVScrollStep))*infoPtr->uVScrollStep,infoPtr->uVScrollStep);
|
|---|
| 4456 | if (newY < 0) newY = 0;
|
|---|
| 4457 | break;
|
|---|
| 4458 |
|
|---|
| 4459 | case SB_PAGEDOWN:
|
|---|
| 4460 | newY = infoPtr->lefttop.y+MAX(((INT)(infoPtr->uVisibleHeight/infoPtr->uVScrollStep))*infoPtr->uVScrollStep,infoPtr->uVScrollStep);
|
|---|
| 4461 | if (newY > maxY) newY = maxY;
|
|---|
| 4462 | break;
|
|---|
| 4463 |
|
|---|
| 4464 | case SB_THUMBTRACK:
|
|---|
| 4465 | newY = HIWORD(wParam);
|
|---|
| 4466 | mod = newY % infoPtr->uVScrollStep;
|
|---|
| 4467 | if (mod > 0) newY -= mod;
|
|---|
| 4468 | break;
|
|---|
| 4469 |
|
|---|
| 4470 | default:
|
|---|
| 4471 | return FALSE;
|
|---|
| 4472 | }
|
|---|
| 4473 |
|
|---|
| 4474 | if (newY != infoPtr->lefttop.y)
|
|---|
| 4475 | {
|
|---|
| 4476 | INT scrollY = infoPtr->lefttop.y-newY;
|
|---|
| 4477 |
|
|---|
| 4478 | TREEVIEW_HideInfoTip(hwnd,infoPtr);
|
|---|
| 4479 | infoPtr->lefttop.y = newY;
|
|---|
| 4480 | if (!TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE))
|
|---|
| 4481 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 4482 | ScrollWindowEx(hwnd,0,scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
|---|
| 4483 |
|
|---|
| 4484 | return TRUE;
|
|---|
| 4485 | }
|
|---|
| 4486 |
|
|---|
| 4487 | return FALSE;
|
|---|
| 4488 | }
|
|---|
| 4489 |
|
|---|
| 4490 | static LRESULT
|
|---|
| 4491 | TREEVIEW_HScroll (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4492 | {
|
|---|
| 4493 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4494 | int maxWidth;
|
|---|
| 4495 | int lastPos = infoPtr->lefttop.x;
|
|---|
| 4496 |
|
|---|
| 4497 | if (!(infoPtr->uInternalStatus & TV_HSCROLL)) return FALSE;
|
|---|
| 4498 |
|
|---|
| 4499 | switch (LOWORD (wParam))
|
|---|
| 4500 | {
|
|---|
| 4501 | case SB_LINEUP:
|
|---|
| 4502 | if (!infoPtr->lefttop.x) return FALSE;
|
|---|
| 4503 | infoPtr->lefttop.x -= infoPtr->uRealItemHeight;
|
|---|
| 4504 | if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
|
|---|
| 4505 | break;
|
|---|
| 4506 |
|
|---|
| 4507 | case SB_LINEDOWN:
|
|---|
| 4508 | maxWidth = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
|
|---|
| 4509 | if (maxWidth <= 0) return FALSE;
|
|---|
| 4510 | if (infoPtr->lefttop.x == maxWidth) return FALSE;
|
|---|
| 4511 | infoPtr->lefttop.x += infoPtr->uRealItemHeight; /*FIXME */
|
|---|
| 4512 | if (infoPtr->lefttop.x > maxWidth)
|
|---|
| 4513 | infoPtr->lefttop.x = maxWidth;
|
|---|
| 4514 | break;
|
|---|
| 4515 |
|
|---|
| 4516 | case SB_PAGEUP:
|
|---|
| 4517 | if (!infoPtr->lefttop.x) return FALSE;
|
|---|
| 4518 | infoPtr->lefttop.x -= infoPtr->uVisibleWidth;
|
|---|
| 4519 | if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
|
|---|
| 4520 | break;
|
|---|
| 4521 |
|
|---|
| 4522 | case SB_PAGEDOWN:
|
|---|
| 4523 | maxWidth = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
|
|---|
| 4524 | if (maxWidth <= 0) return FALSE;
|
|---|
| 4525 | if (infoPtr->lefttop.x == maxWidth) return FALSE;
|
|---|
| 4526 | infoPtr->lefttop.x += infoPtr->uVisibleWidth;
|
|---|
| 4527 | if (infoPtr->lefttop.x > maxWidth)
|
|---|
| 4528 | infoPtr->lefttop.x = maxWidth;
|
|---|
| 4529 | break;
|
|---|
| 4530 |
|
|---|
| 4531 | case SB_THUMBTRACK:
|
|---|
| 4532 | maxWidth = infoPtr->uTotalWidth-infoPtr->uVisibleWidth;
|
|---|
| 4533 | if (maxWidth <= 0) return FALSE;
|
|---|
| 4534 | infoPtr->lefttop.x = HIWORD(wParam);
|
|---|
| 4535 | if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
|
|---|
| 4536 | if (infoPtr->lefttop.x > maxWidth) infoPtr->lefttop.x = maxWidth;
|
|---|
| 4537 | break;
|
|---|
| 4538 |
|
|---|
| 4539 | default:
|
|---|
| 4540 | return FALSE;
|
|---|
| 4541 | }
|
|---|
| 4542 |
|
|---|
| 4543 | if (lastPos != infoPtr->lefttop.x)
|
|---|
| 4544 | {
|
|---|
| 4545 | TREEVIEW_HideInfoTip(hwnd,infoPtr);
|
|---|
| 4546 | if (!TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE))
|
|---|
| 4547 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 4548 | ScrollWindowEx(hwnd,lastPos-infoPtr->lefttop.x,0,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
|---|
| 4549 |
|
|---|
| 4550 | return TRUE;
|
|---|
| 4551 | }
|
|---|
| 4552 |
|
|---|
| 4553 | return FALSE;
|
|---|
| 4554 | }
|
|---|
| 4555 |
|
|---|
| 4556 | static LRESULT TREEVIEW_MouseWheel (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4557 | {
|
|---|
| 4558 |
|
|---|
| 4559 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4560 | short gcWheelDelta = 0;
|
|---|
| 4561 | UINT pulScrollLines = 3;
|
|---|
| 4562 |
|
|---|
| 4563 | if (wParam & (MK_SHIFT | MK_CONTROL))
|
|---|
| 4564 | return DefWindowProcA( hwnd, WM_MOUSEWHEEL, wParam, lParam );
|
|---|
| 4565 |
|
|---|
| 4566 |
|
|---|
| 4567 | SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
|
|---|
| 4568 |
|
|---|
| 4569 | gcWheelDelta -= (short) HIWORD(wParam);
|
|---|
| 4570 | pulScrollLines *= (gcWheelDelta / WHEEL_DELTA);
|
|---|
| 4571 |
|
|---|
| 4572 | if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
|
|---|
| 4573 | {
|
|---|
| 4574 | int wheelDy = pulScrollLines * infoPtr->uRealItemHeight;
|
|---|
| 4575 | int newDy = infoPtr->lefttop.y + wheelDy;
|
|---|
| 4576 | int maxDy = infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
|
|---|
| 4577 |
|
|---|
| 4578 | if (newDy > maxDy) newDy = maxDy;
|
|---|
| 4579 | if (newDy < 0) newDy = 0;
|
|---|
| 4580 |
|
|---|
| 4581 | if (newDy == infoPtr->lefttop.y) return TRUE;
|
|---|
| 4582 |
|
|---|
| 4583 | TREEVIEW_VScroll(hwnd, MAKEWPARAM(SB_THUMBTRACK,newDy),0);
|
|---|
| 4584 | }
|
|---|
| 4585 | return TRUE;
|
|---|
| 4586 | }
|
|---|
| 4587 |
|
|---|
| 4588 | static LRESULT
|
|---|
| 4589 | TREEVIEW_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 4590 | {
|
|---|
| 4591 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4592 | HTREEITEM hNewSelection = 0;
|
|---|
| 4593 | INT prevSelect = (INT)infoPtr->selectedItem;
|
|---|
| 4594 | TREEVIEW_ITEM *prevItem =
|
|---|
| 4595 | (prevSelect != 0 ) ?
|
|---|
| 4596 | TREEVIEW_ValidItem (infoPtr, (HTREEITEM)prevSelect) :
|
|---|
| 4597 | NULL;
|
|---|
| 4598 | TREEVIEW_ITEM *newItem = NULL;
|
|---|
| 4599 | BOOL control;
|
|---|
| 4600 |
|
|---|
| 4601 | TREEVIEW_SendKeyDownNotify(hwnd,TVN_KEYDOWN,wParam);
|
|---|
| 4602 |
|
|---|
| 4603 | control = GetKeyState(VK_CONTROL) & 0x8000;
|
|---|
| 4604 |
|
|---|
| 4605 | if (control)
|
|---|
| 4606 | {
|
|---|
| 4607 | INT scrollMsg = -1;
|
|---|
| 4608 | BOOL horz = FALSE;
|
|---|
| 4609 |
|
|---|
| 4610 | switch (wParam)
|
|---|
| 4611 | {
|
|---|
| 4612 | case VK_UP:
|
|---|
| 4613 | scrollMsg = SB_LINELEFT;
|
|---|
| 4614 | break;
|
|---|
| 4615 |
|
|---|
| 4616 | case VK_DOWN:
|
|---|
| 4617 | scrollMsg = SB_LINERIGHT;
|
|---|
| 4618 | break;
|
|---|
| 4619 |
|
|---|
| 4620 | case VK_LEFT:
|
|---|
| 4621 | scrollMsg = SB_LINELEFT;
|
|---|
| 4622 | horz = TRUE;
|
|---|
| 4623 | break;
|
|---|
| 4624 |
|
|---|
| 4625 | case VK_RIGHT:
|
|---|
| 4626 | scrollMsg = SB_LINERIGHT;
|
|---|
| 4627 | horz = TRUE;
|
|---|
| 4628 | break;
|
|---|
| 4629 |
|
|---|
| 4630 | case VK_PRIOR:
|
|---|
| 4631 | scrollMsg = SB_PAGELEFT;
|
|---|
| 4632 | break;
|
|---|
| 4633 |
|
|---|
| 4634 | case VK_NEXT:
|
|---|
| 4635 | scrollMsg = SB_PAGERIGHT;
|
|---|
| 4636 | break;
|
|---|
| 4637 | }
|
|---|
| 4638 | if (scrollMsg != -1)
|
|---|
| 4639 | {
|
|---|
| 4640 | SendMessageA(hwnd,horz ? WM_HSCROLL:WM_VSCROLL,MAKELONG(scrollMsg,0),0);
|
|---|
| 4641 | return TRUE;
|
|---|
| 4642 | }
|
|---|
| 4643 | }
|
|---|
| 4644 |
|
|---|
| 4645 | if (prevSelect == 0)
|
|---|
| 4646 | return FALSE;
|
|---|
| 4647 |
|
|---|
| 4648 | switch (wParam)
|
|---|
| 4649 | {
|
|---|
| 4650 | case VK_UP:
|
|---|
| 4651 | newItem = TREEVIEW_GetPrevListItem(hwnd,infoPtr, prevItem);
|
|---|
| 4652 |
|
|---|
| 4653 | if (!newItem)
|
|---|
| 4654 | newItem = &infoPtr->items[(INT)infoPtr->TopRootItem];
|
|---|
| 4655 |
|
|---|
| 4656 | hNewSelection = newItem->hItem;
|
|---|
| 4657 |
|
|---|
| 4658 | break;
|
|---|
| 4659 |
|
|---|
| 4660 | case VK_DOWN:
|
|---|
| 4661 | newItem = TREEVIEW_GetNextListItem (hwnd,infoPtr, prevItem);
|
|---|
| 4662 |
|
|---|
| 4663 | if (!newItem)
|
|---|
| 4664 | newItem = prevItem;
|
|---|
| 4665 |
|
|---|
| 4666 | hNewSelection = newItem->hItem;
|
|---|
| 4667 |
|
|---|
| 4668 | break;
|
|---|
| 4669 |
|
|---|
| 4670 | case VK_HOME:
|
|---|
| 4671 | newItem = &infoPtr->items[(INT)infoPtr->TopRootItem];
|
|---|
| 4672 | hNewSelection = newItem->hItem;
|
|---|
| 4673 |
|
|---|
| 4674 | break;
|
|---|
| 4675 |
|
|---|
| 4676 | case VK_END:
|
|---|
| 4677 | newItem = &infoPtr->items[(INT)infoPtr->TopRootItem];
|
|---|
| 4678 | newItem = TREEVIEW_GetLastListItem (hwnd,infoPtr, newItem);
|
|---|
| 4679 | hNewSelection = newItem->hItem;
|
|---|
| 4680 |
|
|---|
| 4681 | break;
|
|---|
| 4682 |
|
|---|
| 4683 | case VK_LEFT:
|
|---|
| 4684 | if ( (prevItem->state & TVIS_EXPANDED) &&
|
|---|
| 4685 | TREEVIEW_HasChildren(hwnd, prevItem))
|
|---|
| 4686 | {
|
|---|
| 4687 | TREEVIEW_Expand(hwnd, TVE_COLLAPSE, prevSelect );
|
|---|
| 4688 | } else if ((INT)prevItem->parent)
|
|---|
| 4689 | {
|
|---|
| 4690 | newItem = (& infoPtr->items[(INT)prevItem->parent]);
|
|---|
| 4691 |
|
|---|
| 4692 | hNewSelection = newItem->hItem; //CB: what does Win32??? Please not the Corel hack!!!
|
|---|
| 4693 | }
|
|---|
| 4694 |
|
|---|
| 4695 | break;
|
|---|
| 4696 |
|
|---|
| 4697 | case VK_RIGHT:
|
|---|
| 4698 | if (TREEVIEW_HasChildren(hwnd, prevItem))
|
|---|
| 4699 | {
|
|---|
| 4700 | if (!(prevItem->state & TVIS_EXPANDED))
|
|---|
| 4701 | TREEVIEW_Expand(hwnd, TVE_EXPAND, prevSelect );
|
|---|
| 4702 | else
|
|---|
| 4703 | {
|
|---|
| 4704 | newItem = (& infoPtr->items[(INT)prevItem->firstChild]);
|
|---|
| 4705 | hNewSelection = newItem->hItem;
|
|---|
| 4706 | }
|
|---|
| 4707 | }
|
|---|
| 4708 |
|
|---|
| 4709 | break;
|
|---|
| 4710 |
|
|---|
| 4711 | case VK_ADD:
|
|---|
| 4712 | if (!(prevItem->state & TVIS_EXPANDED))
|
|---|
| 4713 | TREEVIEW_Expand(hwnd, TVE_EXPAND, prevSelect );
|
|---|
| 4714 | break;
|
|---|
| 4715 |
|
|---|
| 4716 | case VK_SUBTRACT:
|
|---|
| 4717 | if (prevItem->state & TVIS_EXPANDED)
|
|---|
| 4718 | TREEVIEW_Expand(hwnd, TVE_COLLAPSE, prevSelect );
|
|---|
| 4719 | break;
|
|---|
| 4720 |
|
|---|
| 4721 | case VK_PRIOR:
|
|---|
| 4722 | newItem=TREEVIEW_GetListItem(
|
|---|
| 4723 | hwnd,
|
|---|
| 4724 | infoPtr,
|
|---|
| 4725 | prevItem,
|
|---|
| 4726 | -1*(TREEVIEW_GetVisibleCount(hwnd,0,0)-3));
|
|---|
| 4727 | if (!newItem)
|
|---|
| 4728 | newItem = prevItem;
|
|---|
| 4729 |
|
|---|
| 4730 | hNewSelection = newItem->hItem;
|
|---|
| 4731 |
|
|---|
| 4732 | break;
|
|---|
| 4733 |
|
|---|
| 4734 | case VK_NEXT:
|
|---|
| 4735 | newItem=TREEVIEW_GetListItem(
|
|---|
| 4736 | hwnd,
|
|---|
| 4737 | infoPtr,
|
|---|
| 4738 | prevItem,
|
|---|
| 4739 | TREEVIEW_GetVisibleCount(hwnd,0,0)-3);
|
|---|
| 4740 |
|
|---|
| 4741 | if (!newItem)
|
|---|
| 4742 | newItem = prevItem;
|
|---|
| 4743 |
|
|---|
| 4744 | hNewSelection = newItem->hItem;
|
|---|
| 4745 |
|
|---|
| 4746 | break;
|
|---|
| 4747 |
|
|---|
| 4748 | case VK_RETURN:
|
|---|
| 4749 | sendNotify(hwnd,NM_RETURN);
|
|---|
| 4750 | break;
|
|---|
| 4751 |
|
|---|
| 4752 | case VK_BACK:
|
|---|
| 4753 |
|
|---|
| 4754 | default:
|
|---|
| 4755 | break;
|
|---|
| 4756 | }
|
|---|
| 4757 |
|
|---|
| 4758 | if (hNewSelection)
|
|---|
| 4759 | {
|
|---|
| 4760 | if (TREEVIEW_DoSelectItem(hwnd,TVGN_CARET,(HTREEITEM)hNewSelection,TVC_BYKEYBOARD))
|
|---|
| 4761 | {
|
|---|
| 4762 | TREEVIEW_EnsureVisible(hwnd,hNewSelection);
|
|---|
| 4763 | }
|
|---|
| 4764 | }
|
|---|
| 4765 |
|
|---|
| 4766 | return FALSE;
|
|---|
| 4767 | }
|
|---|
| 4768 |
|
|---|
| 4769 | static LRESULT TREEVIEW_Char(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 4770 | {
|
|---|
| 4771 | CHAR ch = (CHAR)wParam;
|
|---|
| 4772 |
|
|---|
| 4773 | TREEVIEW_ISearch(hwnd,ch);
|
|---|
| 4774 |
|
|---|
| 4775 | return 0;
|
|---|
| 4776 | }
|
|---|
| 4777 |
|
|---|
| 4778 | static LRESULT
|
|---|
| 4779 | TREEVIEW_GetScrollTime (HWND hwnd)
|
|---|
| 4780 | {
|
|---|
| 4781 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4782 |
|
|---|
| 4783 | return infoPtr->uScrollTime;
|
|---|
| 4784 | }
|
|---|
| 4785 |
|
|---|
| 4786 | static LRESULT
|
|---|
| 4787 | TREEVIEW_SetScrollTime (HWND hwnd, UINT uScrollTime)
|
|---|
| 4788 | {
|
|---|
| 4789 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4790 | UINT uOldScrollTime = infoPtr->uScrollTime;
|
|---|
| 4791 |
|
|---|
| 4792 | infoPtr->uScrollTime = min (uScrollTime, 100);
|
|---|
| 4793 |
|
|---|
| 4794 | return uOldScrollTime;
|
|---|
| 4795 | }
|
|---|
| 4796 |
|
|---|
| 4797 | static LRESULT TREEVIEW_EnsureVisible(HWND hwnd,HTREEITEM hItem)
|
|---|
| 4798 | {
|
|---|
| 4799 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4800 | TREEVIEW_ITEM *item;
|
|---|
| 4801 | RECT rect;
|
|---|
| 4802 | INT scrollY;
|
|---|
| 4803 |
|
|---|
| 4804 | item = TREEVIEW_ValidItem(infoPtr,hItem);
|
|---|
| 4805 |
|
|---|
| 4806 | if (!item) return FALSE;
|
|---|
| 4807 |
|
|---|
| 4808 | if (item && item->parent)
|
|---|
| 4809 | {
|
|---|
| 4810 | TREEVIEW_ITEM *parent = TREEVIEW_ValidItem(infoPtr,item->parent);
|
|---|
| 4811 |
|
|---|
| 4812 | while (parent && !(parent->state & TVIS_EXPANDED))
|
|---|
| 4813 | {
|
|---|
| 4814 | TREEVIEW_Expand(hwnd,TVE_EXPAND,(LPARAM)parent->hItem);
|
|---|
| 4815 | parent = TREEVIEW_ValidItem(infoPtr,parent->parent);
|
|---|
| 4816 | }
|
|---|
| 4817 | }
|
|---|
| 4818 |
|
|---|
| 4819 | TREEVIEW_UnqueueRefresh(hwnd,TRUE,TRUE);
|
|---|
| 4820 | GetClientRect(hwnd,&rect);
|
|---|
| 4821 | if (item->rect.top < 0)
|
|---|
| 4822 | scrollY = item->rect.top;
|
|---|
| 4823 | else if (item->rect.bottom > rect.bottom)
|
|---|
| 4824 | {
|
|---|
| 4825 | INT mod;
|
|---|
| 4826 |
|
|---|
| 4827 | scrollY = item->rect.bottom-rect.bottom;
|
|---|
| 4828 | mod = scrollY % infoPtr->uVScrollStep;
|
|---|
| 4829 | if (mod) scrollY += infoPtr->uVScrollStep-mod;
|
|---|
| 4830 | } else return FALSE;
|
|---|
| 4831 |
|
|---|
| 4832 | if (scrollY != 0)
|
|---|
| 4833 | {
|
|---|
| 4834 | infoPtr->lefttop.y += scrollY;
|
|---|
| 4835 | TREEVIEW_CalcItems(hwnd,0,infoPtr);
|
|---|
| 4836 | ScrollWindowEx(hwnd,0,-scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
|---|
| 4837 |
|
|---|
| 4838 | return TRUE;
|
|---|
| 4839 | }
|
|---|
| 4840 |
|
|---|
| 4841 | return FALSE;
|
|---|
| 4842 | }
|
|---|
| 4843 |
|
|---|
| 4844 | static BOOL TREEVIEW_Compare(HWND hwnd,TREEVIEW_ITEM *item,LPWSTR text,INT textlen)
|
|---|
| 4845 | {
|
|---|
| 4846 | WCHAR* itemtext;
|
|---|
| 4847 | BOOL mustFree = FALSE,res;
|
|---|
| 4848 |
|
|---|
| 4849 | if (item->pszText == LPSTR_TEXTCALLBACKW)
|
|---|
| 4850 | itemtext = TREEVIEW_CallbackText(hwnd,item,&mustFree);
|
|---|
| 4851 | else
|
|---|
| 4852 | itemtext = item->pszText;
|
|---|
| 4853 |
|
|---|
| 4854 | //simulate lstrcmpniW
|
|---|
| 4855 | res = (CompareStringW(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE,itemtext,MIN(lstrlenW(itemtext),textlen),text,textlen) == 2);
|
|---|
| 4856 | if (mustFree) COMCTL32_Free(itemtext);
|
|---|
| 4857 |
|
|---|
| 4858 | return res;
|
|---|
| 4859 | }
|
|---|
| 4860 |
|
|---|
| 4861 | static TREEVIEW_ITEM* TREEVIEW_Search(HWND hwnd,TREEVIEW_INFO *infoPtr,INT iItem,LPWSTR text,INT textlen)
|
|---|
| 4862 | {
|
|---|
| 4863 | TREEVIEW_ITEM *item,*start;
|
|---|
| 4864 | BOOL found = FALSE;
|
|---|
| 4865 |
|
|---|
| 4866 | item = start = &infoPtr->items[iItem];
|
|---|
| 4867 |
|
|---|
| 4868 | //search start to end
|
|---|
| 4869 | while (item)
|
|---|
| 4870 | {
|
|---|
| 4871 | if (TREEVIEW_Compare(hwnd,item,text,textlen)) return item;
|
|---|
| 4872 | item = TREEVIEW_GetNextListItem(hwnd,infoPtr,item);
|
|---|
| 4873 | }
|
|---|
| 4874 | if (!found)
|
|---|
| 4875 | {
|
|---|
| 4876 | iItem = (INT)infoPtr->TopRootItem;
|
|---|
| 4877 | item = &infoPtr->items[iItem];
|
|---|
| 4878 |
|
|---|
| 4879 | //search first to start
|
|---|
| 4880 | while (item != start)
|
|---|
| 4881 | {
|
|---|
| 4882 | if (TREEVIEW_Compare(hwnd,item,text,textlen)) return item;
|
|---|
| 4883 | item = TREEVIEW_GetNextListItem(hwnd,infoPtr,item);
|
|---|
| 4884 | }
|
|---|
| 4885 | }
|
|---|
| 4886 |
|
|---|
| 4887 | return NULL;
|
|---|
| 4888 | }
|
|---|
| 4889 |
|
|---|
| 4890 | //CB: this method is CPU intense: optimize it and use a secondary thread
|
|---|
| 4891 |
|
|---|
| 4892 | static VOID TREEVIEW_ISearch(HWND hwnd,CHAR ch)
|
|---|
| 4893 | {
|
|---|
| 4894 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4895 | LPWSTR newString;
|
|---|
| 4896 | INT len,iItem;
|
|---|
| 4897 | CHAR ch2[2];
|
|---|
| 4898 | TREEVIEW_ITEM *item;
|
|---|
| 4899 |
|
|---|
| 4900 | //check timer
|
|---|
| 4901 | if (infoPtr->Timer & TV_ISEARCH_TIMER_SET)
|
|---|
| 4902 | {
|
|---|
| 4903 | KillTimer(hwnd,TV_ISEARCH_TIMER);
|
|---|
| 4904 | infoPtr->Timer &= ~TV_ISEARCH_TIMER_SET;
|
|---|
| 4905 | } else if (infoPtr->uISearchLen > 0)
|
|---|
| 4906 | {
|
|---|
| 4907 | COMCTL32_Free(infoPtr->pszISearch);
|
|---|
| 4908 | infoPtr->pszISearch = NULL;
|
|---|
| 4909 | infoPtr->uISearchLen = 0;
|
|---|
| 4910 | }
|
|---|
| 4911 |
|
|---|
| 4912 | //prepare new search string
|
|---|
| 4913 | len = infoPtr->uISearchLen+1;
|
|---|
| 4914 | newString = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR));
|
|---|
| 4915 |
|
|---|
| 4916 | if (infoPtr->uISearchLen > 0) lstrcpyW(newString,infoPtr->pszISearch);
|
|---|
| 4917 |
|
|---|
| 4918 | ch2[0] = ch;
|
|---|
| 4919 | ch2[1] = 0;
|
|---|
| 4920 | lstrcpyAtoW((LPWSTR)&newString[len-1],(LPSTR)&ch2);
|
|---|
| 4921 |
|
|---|
| 4922 | //search
|
|---|
| 4923 |
|
|---|
| 4924 | iItem = infoPtr->selectedItem ? (INT)infoPtr->selectedItem:(INT)infoPtr->TopRootItem;
|
|---|
| 4925 |
|
|---|
| 4926 | if (infoPtr->selectedItem)
|
|---|
| 4927 | {
|
|---|
| 4928 | item = &infoPtr->items[iItem];
|
|---|
| 4929 | item = TREEVIEW_GetNextListItem(hwnd,infoPtr,item);
|
|---|
| 4930 | if (!item) item = &infoPtr->items[(INT)infoPtr->TopRootItem];
|
|---|
| 4931 | iItem = (INT)item->hItem;
|
|---|
| 4932 | } else iItem = (INT)infoPtr->TopRootItem;
|
|---|
| 4933 |
|
|---|
| 4934 | item = TREEVIEW_Search(hwnd,infoPtr,iItem,newString,len);
|
|---|
| 4935 | if (!item && infoPtr->selectedItem && infoPtr->pszISearch)
|
|---|
| 4936 | {
|
|---|
| 4937 | TREEVIEW_ITEM *next;
|
|---|
| 4938 |
|
|---|
| 4939 | item = &infoPtr->items[iItem];
|
|---|
| 4940 | next = TREEVIEW_Search(hwnd,infoPtr,(INT)item->hItem,infoPtr->pszISearch,infoPtr->uISearchLen);
|
|---|
| 4941 | if (next)
|
|---|
| 4942 | {
|
|---|
| 4943 | TREEVIEW_SelectItem(hwnd,(WPARAM)TVGN_CARET,(LPARAM)next->hItem);
|
|---|
| 4944 | TREEVIEW_EnsureVisible(hwnd,next->hItem);
|
|---|
| 4945 | }
|
|---|
| 4946 | COMCTL32_Free(newString);
|
|---|
| 4947 | return;
|
|---|
| 4948 | }
|
|---|
| 4949 |
|
|---|
| 4950 | //done
|
|---|
| 4951 | if (item)
|
|---|
| 4952 | {
|
|---|
| 4953 | COMCTL32_Free(infoPtr->pszISearch);
|
|---|
| 4954 | infoPtr->pszISearch = newString;
|
|---|
| 4955 | infoPtr->uISearchLen = len;
|
|---|
| 4956 | TREEVIEW_SelectItem(hwnd,(WPARAM)TVGN_CARET,(LPARAM)item->hItem);
|
|---|
| 4957 | TREEVIEW_EnsureVisible(hwnd,item->hItem);
|
|---|
| 4958 | SetTimer(hwnd,TV_ISEARCH_TIMER,TV_ISEARCH_DELAY,0);
|
|---|
| 4959 | infoPtr->Timer |= TV_ISEARCH_TIMER_SET;
|
|---|
| 4960 | } else
|
|---|
| 4961 | {
|
|---|
| 4962 | COMCTL32_Free(newString);
|
|---|
| 4963 | MessageBeep(0xFFFFFFFF);
|
|---|
| 4964 | }
|
|---|
| 4965 | }
|
|---|
| 4966 |
|
|---|
| 4967 | static LRESULT TREEVIEW_GetISearchString(HWND hwnd,LPWSTR lpsz,BOOL unicode)
|
|---|
| 4968 | {
|
|---|
| 4969 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
|---|
| 4970 |
|
|---|
| 4971 | if (infoPtr->uISearchLen == 0) return 0;
|
|---|
| 4972 |
|
|---|
| 4973 | if (unicode)
|
|---|
| 4974 | lstrcpyW(lpsz,infoPtr->pszISearch);
|
|---|
| 4975 | else
|
|---|
| 4976 | lstrcpyWtoA((LPSTR)lpsz,infoPtr->pszISearch);
|
|---|
| 4977 |
|
|---|
| 4978 | return infoPtr->uISearchLen;
|
|---|
| 4979 | }
|
|---|
| 4980 |
|
|---|
| 4981 | static LRESULT TREEVIEW_SetCursor(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
|---|
| 4982 | {
|
|---|
| 4983 | sendNotify(hwnd,NM_SETCURSOR); //CB: todo: result
|
|---|
| 4984 |
|
|---|
| 4985 | return DefWindowProcA(hwnd,WM_SETCURSOR,wParam,lParam);
|
|---|
| 4986 | }
|
|---|
| 4987 |
|
|---|
| 4988 | static LRESULT WINAPI
|
|---|
| 4989 | TREEVIEW_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|---|
| 4990 | {
|
|---|
| 4991 | if (uMsg == WM_CREATE)
|
|---|
| 4992 | return TREEVIEW_Create (hwnd, wParam, lParam);
|
|---|
| 4993 |
|
|---|
| 4994 | if (!TREEVIEW_GetInfoPtr(hwnd))
|
|---|
| 4995 | return DefWindowProcA (hwnd, uMsg, wParam, lParam);
|
|---|
| 4996 |
|
|---|
| 4997 | switch (uMsg)
|
|---|
| 4998 | {
|
|---|
| 4999 | case TVM_INSERTITEMA:
|
|---|
| 5000 | return TREEVIEW_InsertItem(hwnd,wParam,lParam,FALSE);
|
|---|
| 5001 |
|
|---|
| 5002 | case TVM_INSERTITEMW:
|
|---|
| 5003 | return TREEVIEW_InsertItem(hwnd,wParam,lParam,TRUE);
|
|---|
| 5004 |
|
|---|
| 5005 | case TVM_DELETEITEM:
|
|---|
| 5006 | return TREEVIEW_DeleteItem (hwnd, wParam, lParam);
|
|---|
| 5007 |
|
|---|
| 5008 | case TVM_EXPAND:
|
|---|
| 5009 | return TREEVIEW_Expand (hwnd, wParam, lParam);
|
|---|
| 5010 |
|
|---|
| 5011 | case TVM_GETITEMRECT:
|
|---|
| 5012 | return TREEVIEW_GetItemRect (hwnd, wParam, lParam);
|
|---|
| 5013 |
|
|---|
| 5014 | case TVM_GETCOUNT:
|
|---|
| 5015 | return TREEVIEW_GetCount (hwnd, wParam, lParam);
|
|---|
| 5016 |
|
|---|
| 5017 | case TVM_GETINDENT:
|
|---|
| 5018 | return TREEVIEW_GetIndent (hwnd);
|
|---|
| 5019 |
|
|---|
| 5020 | case TVM_SETINDENT:
|
|---|
| 5021 | return TREEVIEW_SetIndent (hwnd, wParam);
|
|---|
| 5022 |
|
|---|
| 5023 | case TVM_GETIMAGELIST:
|
|---|
| 5024 | return TREEVIEW_GetImageList (hwnd, wParam, lParam);
|
|---|
| 5025 |
|
|---|
| 5026 | case TVM_SETIMAGELIST:
|
|---|
| 5027 | return TREEVIEW_SetImageList (hwnd, wParam, lParam);
|
|---|
| 5028 |
|
|---|
| 5029 | case TVM_GETNEXTITEM:
|
|---|
| 5030 | return TREEVIEW_GetNextItem (hwnd, wParam, lParam);
|
|---|
| 5031 |
|
|---|
| 5032 | case TVM_SELECTITEM:
|
|---|
| 5033 | return TREEVIEW_SelectItem (hwnd, wParam, lParam);
|
|---|
| 5034 |
|
|---|
| 5035 | case TVM_GETITEMA:
|
|---|
| 5036 | return TREEVIEW_GetItem(hwnd,wParam,lParam,FALSE);
|
|---|
| 5037 |
|
|---|
| 5038 | case TVM_GETITEMW:
|
|---|
| 5039 | return TREEVIEW_GetItem(hwnd,wParam,lParam,TRUE);
|
|---|
| 5040 |
|
|---|
| 5041 | case TVM_SETITEMA:
|
|---|
| 5042 | return TREEVIEW_SetItem(hwnd,wParam,lParam,FALSE);
|
|---|
| 5043 |
|
|---|
| 5044 | case TVM_SETITEMW:
|
|---|
| 5045 | return TREEVIEW_SetItem(hwnd,wParam,lParam,TRUE);
|
|---|
| 5046 |
|
|---|
| 5047 | case TVM_EDITLABELA:
|
|---|
| 5048 | return TREEVIEW_EditLabel(hwnd,(HTREEITEM)lParam,FALSE);
|
|---|
| 5049 |
|
|---|
| 5050 | case TVM_EDITLABELW:
|
|---|
| 5051 | return TREEVIEW_EditLabel(hwnd,(HTREEITEM)lParam,TRUE);
|
|---|
| 5052 |
|
|---|
| 5053 | case TVM_GETEDITCONTROL:
|
|---|
| 5054 | return TREEVIEW_GetEditControl (hwnd);
|
|---|
| 5055 |
|
|---|
| 5056 | case TVM_GETVISIBLECOUNT:
|
|---|
| 5057 | return TREEVIEW_GetVisibleCount (hwnd, wParam, lParam);
|
|---|
| 5058 |
|
|---|
| 5059 | case TVM_HITTEST:
|
|---|
| 5060 | return TREEVIEW_HitTest(hwnd,(LPTVHITTESTINFO)lParam,FALSE);
|
|---|
| 5061 |
|
|---|
| 5062 | case TVM_CREATEDRAGIMAGE:
|
|---|
| 5063 | return TREEVIEW_CreateDragImage (hwnd, wParam, lParam);
|
|---|
| 5064 |
|
|---|
| 5065 | case TVM_SORTCHILDREN:
|
|---|
| 5066 | return TREEVIEW_SortChildren(hwnd, wParam, lParam);
|
|---|
| 5067 |
|
|---|
| 5068 | case TVM_ENSUREVISIBLE:
|
|---|
| 5069 | return TREEVIEW_EnsureVisible(hwnd,(HTREEITEM)lParam);
|
|---|
| 5070 |
|
|---|
| 5071 | case TVM_SORTCHILDRENCB:
|
|---|
| 5072 | return TREEVIEW_SortChildrenCB(hwnd, wParam, lParam);
|
|---|
| 5073 |
|
|---|
| 5074 | case TVM_ENDEDITLABELNOW:
|
|---|
| 5075 | return TREEVIEW_EndEditLabelNow (hwnd,(BOOL)wParam);
|
|---|
| 5076 |
|
|---|
| 5077 | case TVM_GETISEARCHSTRINGA:
|
|---|
| 5078 | return TREEVIEW_GetISearchString(hwnd,(LPWSTR)lParam,FALSE);
|
|---|
| 5079 |
|
|---|
| 5080 | case TVM_GETISEARCHSTRINGW:
|
|---|
| 5081 | return TREEVIEW_GetISearchString(hwnd,(LPWSTR)lParam,TRUE);
|
|---|
| 5082 |
|
|---|
| 5083 | case TVM_GETTOOLTIPS:
|
|---|
| 5084 | return TREEVIEW_GetToolTips (hwnd);
|
|---|
| 5085 |
|
|---|
| 5086 | case TVM_SETTOOLTIPS:
|
|---|
| 5087 | return TREEVIEW_SetToolTips (hwnd, wParam);
|
|---|
| 5088 |
|
|---|
| 5089 | case TVM_SETINSERTMARK:
|
|---|
| 5090 | return TREEVIEW_SetInsertMark (hwnd,wParam, lParam);
|
|---|
| 5091 |
|
|---|
| 5092 | case TVM_SETITEMHEIGHT:
|
|---|
| 5093 | return TREEVIEW_SetItemHeight (hwnd, wParam);
|
|---|
| 5094 |
|
|---|
| 5095 | case TVM_GETITEMHEIGHT:
|
|---|
| 5096 | return TREEVIEW_GetItemHeight (hwnd);
|
|---|
| 5097 |
|
|---|
| 5098 | case TVM_SETBKCOLOR:
|
|---|
| 5099 | return TREEVIEW_SetBkColor (hwnd, wParam, lParam);
|
|---|
| 5100 |
|
|---|
| 5101 | case TVM_SETTEXTCOLOR:
|
|---|
| 5102 | return TREEVIEW_SetTextColor (hwnd, wParam, lParam);
|
|---|
| 5103 |
|
|---|
| 5104 | case TVM_GETBKCOLOR:
|
|---|
| 5105 | return TREEVIEW_GetBkColor (hwnd);
|
|---|
| 5106 |
|
|---|
| 5107 | case TVM_GETTEXTCOLOR:
|
|---|
| 5108 | return TREEVIEW_GetTextColor (hwnd);
|
|---|
| 5109 |
|
|---|
| 5110 | case TVM_SETSCROLLTIME:
|
|---|
| 5111 | return TREEVIEW_SetScrollTime (hwnd, (UINT)wParam);
|
|---|
| 5112 |
|
|---|
| 5113 | case TVM_GETSCROLLTIME:
|
|---|
| 5114 | return TREEVIEW_GetScrollTime (hwnd);
|
|---|
| 5115 |
|
|---|
| 5116 | case TVM_GETITEMSTATE:
|
|---|
| 5117 | return TREEVIEW_GetItemState (hwnd,wParam, lParam);
|
|---|
| 5118 |
|
|---|
| 5119 | case TVM_GETLINECOLOR:
|
|---|
| 5120 | return TREEVIEW_GetLineColor (hwnd,wParam, lParam);
|
|---|
| 5121 |
|
|---|
| 5122 | case TVM_SETLINECOLOR:
|
|---|
| 5123 | return TREEVIEW_SetLineColor (hwnd,wParam, lParam);
|
|---|
| 5124 |
|
|---|
| 5125 | case TVM_SETINSERTMARKCOLOR:
|
|---|
| 5126 | return TREEVIEW_SetInsertMarkColor (hwnd,wParam, lParam);
|
|---|
| 5127 |
|
|---|
| 5128 | case TVM_GETINSERTMARKCOLOR:
|
|---|
| 5129 | return TREEVIEW_GetInsertMarkColor (hwnd,wParam, lParam);
|
|---|
| 5130 |
|
|---|
| 5131 | case WM_COMMAND:
|
|---|
| 5132 | return TREEVIEW_Command (hwnd, wParam, lParam);
|
|---|
| 5133 |
|
|---|
| 5134 | case WM_DESTROY:
|
|---|
| 5135 | return TREEVIEW_Destroy (hwnd);
|
|---|
| 5136 |
|
|---|
| 5137 | case WM_ENABLE:
|
|---|
| 5138 | return TREEVIEW_Enable(hwnd,wParam,lParam);
|
|---|
| 5139 |
|
|---|
| 5140 | case WM_ERASEBKGND:
|
|---|
| 5141 | return TREEVIEW_EraseBackground (hwnd, wParam, lParam);
|
|---|
| 5142 |
|
|---|
| 5143 | case WM_GETDLGCODE:
|
|---|
| 5144 | return TREEVIEW_GetDlgCode(hwnd,wParam,lParam);
|
|---|
| 5145 |
|
|---|
| 5146 | case WM_PAINT:
|
|---|
| 5147 | return TREEVIEW_Paint (hwnd, wParam, lParam);
|
|---|
| 5148 |
|
|---|
| 5149 | case WM_GETFONT:
|
|---|
| 5150 | return TREEVIEW_GetFont (hwnd, wParam, lParam);
|
|---|
| 5151 |
|
|---|
| 5152 | case WM_SETFONT:
|
|---|
| 5153 | return TREEVIEW_SetFont (hwnd, wParam, lParam);
|
|---|
| 5154 |
|
|---|
| 5155 | case WM_KEYDOWN:
|
|---|
| 5156 | return TREEVIEW_KeyDown (hwnd, wParam, lParam);
|
|---|
| 5157 |
|
|---|
| 5158 | case WM_CHAR:
|
|---|
| 5159 | return TREEVIEW_Char(hwnd,wParam,lParam);
|
|---|
| 5160 |
|
|---|
| 5161 | case WM_SETFOCUS:
|
|---|
| 5162 | return TREEVIEW_SetFocus (hwnd, wParam, lParam);
|
|---|
| 5163 |
|
|---|
| 5164 | case WM_KILLFOCUS:
|
|---|
| 5165 | return TREEVIEW_KillFocus (hwnd, wParam, lParam);
|
|---|
| 5166 |
|
|---|
| 5167 | case WM_MOUSEMOVE:
|
|---|
| 5168 | return TREEVIEW_MouseMove(hwnd,wParam,lParam);
|
|---|
| 5169 |
|
|---|
| 5170 | case WM_LBUTTONDOWN:
|
|---|
| 5171 | return TREEVIEW_LButtonDown (hwnd, wParam, lParam);
|
|---|
| 5172 |
|
|---|
| 5173 | case WM_LBUTTONDBLCLK:
|
|---|
| 5174 | return TREEVIEW_LButtonDoubleClick (hwnd, wParam, lParam);
|
|---|
| 5175 |
|
|---|
| 5176 | case WM_RBUTTONDOWN:
|
|---|
| 5177 | return TREEVIEW_RButtonDown (hwnd, wParam, lParam);
|
|---|
| 5178 |
|
|---|
| 5179 | case WM_RBUTTONDBLCLK:
|
|---|
| 5180 | return TREEVIEW_RButtonDoubleClick(hwnd,wParam,lParam);
|
|---|
| 5181 |
|
|---|
| 5182 | case WM_STYLECHANGED:
|
|---|
| 5183 | return TREEVIEW_StyleChanged (hwnd, wParam, lParam);
|
|---|
| 5184 |
|
|---|
| 5185 | case WM_SYSCOLORCHANGE:
|
|---|
| 5186 | return TREEVIEW_SysColorChange(hwnd,wParam,lParam);
|
|---|
| 5187 |
|
|---|
| 5188 | case WM_SETCURSOR:
|
|---|
| 5189 | return TREEVIEW_SetCursor(hwnd,wParam,lParam);
|
|---|
| 5190 |
|
|---|
| 5191 | case WM_SETREDRAW:
|
|---|
| 5192 | return TREEVIEW_SetRedraw(hwnd,wParam,lParam);
|
|---|
| 5193 |
|
|---|
| 5194 | case WM_TIMER:
|
|---|
| 5195 | return TREEVIEW_HandleTimer (hwnd, wParam, lParam);
|
|---|
| 5196 |
|
|---|
| 5197 | case WM_SIZE:
|
|---|
| 5198 | return TREEVIEW_Size (hwnd, wParam,lParam);
|
|---|
| 5199 |
|
|---|
| 5200 | case WM_HSCROLL:
|
|---|
| 5201 | return TREEVIEW_HScroll (hwnd, wParam, lParam);
|
|---|
| 5202 |
|
|---|
| 5203 | case WM_VSCROLL:
|
|---|
| 5204 | return TREEVIEW_VScroll (hwnd, wParam, lParam);
|
|---|
| 5205 |
|
|---|
| 5206 | case WM_MOUSEWHEEL:
|
|---|
| 5207 | return TREEVIEW_MouseWheel (hwnd, wParam, lParam);
|
|---|
| 5208 |
|
|---|
| 5209 | case WM_DRAWITEM:
|
|---|
| 5210 | //printf ("drawItem\n");
|
|---|
| 5211 | return DefWindowProcA (hwnd, uMsg, wParam, lParam);
|
|---|
| 5212 |
|
|---|
| 5213 | default:
|
|---|
| 5214 | return defComCtl32ProcA(hwnd,uMsg,wParam,lParam);
|
|---|
| 5215 | }
|
|---|
| 5216 | return 0;
|
|---|
| 5217 | }
|
|---|
| 5218 |
|
|---|
| 5219 |
|
|---|
| 5220 | VOID TREEVIEW_Register (VOID)
|
|---|
| 5221 | {
|
|---|
| 5222 | WNDCLASSA wndClass;
|
|---|
| 5223 |
|
|---|
| 5224 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
|---|
| 5225 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
|---|
| 5226 | wndClass.lpfnWndProc = (WNDPROC)TREEVIEW_WindowProc;
|
|---|
| 5227 | wndClass.cbClsExtra = 0;
|
|---|
| 5228 | wndClass.cbWndExtra = sizeof(TREEVIEW_INFO *);
|
|---|
| 5229 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
|---|
| 5230 | wndClass.hbrBackground = 0;
|
|---|
| 5231 | wndClass.lpszClassName = WC_TREEVIEWA;
|
|---|
| 5232 |
|
|---|
| 5233 | RegisterClassA (&wndClass);
|
|---|
| 5234 | }
|
|---|
| 5235 |
|
|---|
| 5236 |
|
|---|
| 5237 | VOID TREEVIEW_Unregister (VOID)
|
|---|
| 5238 | {
|
|---|
| 5239 | UnregisterClassA (WC_TREEVIEWA, (HINSTANCE)NULL);
|
|---|
| 5240 | }
|
|---|
| 5241 |
|
|---|