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