mirrored from git://source.winehq.org/git/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
listview.c
12026 lines (10190 loc) · 346 KB
/
listview.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Listview control
*
* Copyright 1998, 1999 Eric Kohl
* Copyright 1999 Luc Tourangeau
* Copyright 2000 Jason Mawdsley
* Copyright 2001 CodeWeavers Inc.
* Copyright 2002 Dimitrie O. Paun
* Copyright 2009-2015 Nikolay Sivov
* Copyright 2009 Owen Rudge for CodeWeavers
* Copyright 2012-2013 Daniel Jelinski
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* TODO:
*
* Default Message Processing
* -- WM_CREATE: create the icon and small icon image lists at this point only if
* the LVS_SHAREIMAGELISTS style is not specified.
* -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
* or small icon and the LVS_AUTOARRANGE style is specified.
* -- WM_TIMER
* -- WM_WININICHANGE
*
* Features
* -- Hot item handling, mouse hovering
* -- Workareas support
* -- Tilemode support
* -- Groups support
*
* Bugs
* -- Expand large item in ICON mode when the cursor is flying over the icon or text.
* -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
* -- LVA_SNAPTOGRID not implemented
* -- LISTVIEW_ApproximateViewRect partially implemented
* -- LISTVIEW_StyleChanged doesn't handle some changes too well
*
* Speedups
* -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
* linear in the number of items in the list, and this is
* unacceptable for large lists.
* -- if list is sorted by item text LISTVIEW_InsertItemT could use
* binary search to calculate item index (e.g. DPA_Search()).
* This requires sorted state to be reliably tracked in item modifiers.
* -- we should keep an ordered array of coordinates in iconic mode.
* This would allow framing items (iterator_frameditems),
* and finding the nearest item (LVFI_NEARESTXY) a lot more efficiently.
*
* Flags
* -- LVIF_COLUMNS
* -- LVIF_GROUPID
*
* States
* -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
* -- LVIS_DROPHILITED
*
* Styles
* -- LVS_NOLABELWRAP
* -- LVS_NOSCROLL (see Q137520)
* -- LVS_ALIGNTOP
*
* Extended Styles
* -- LVS_EX_BORDERSELECT
* -- LVS_EX_FLATSB
* -- LVS_EX_INFOTIP
* -- LVS_EX_LABELTIP
* -- LVS_EX_MULTIWORKAREAS
* -- LVS_EX_REGIONAL
* -- LVS_EX_SIMPLESELECT
* -- LVS_EX_TWOCLICKACTIVATE
* -- LVS_EX_UNDERLINECOLD
* -- LVS_EX_UNDERLINEHOT
*
* Notifications:
* -- LVN_BEGINSCROLL, LVN_ENDSCROLL
* -- LVN_GETINFOTIP
* -- LVN_HOTTRACK
* -- LVN_SETDISPINFO
*
* Messages:
* -- LVM_ENABLEGROUPVIEW
* -- LVM_GETBKIMAGE
* -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
* -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
* -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
* -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
* -- LVM_GETINSERTMARKRECT
* -- LVM_GETNUMBEROFWORKAREAS
* -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
* -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
* -- LVM_GETTILEINFO, LVM_SETTILEINFO
* -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
* -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
* -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
* -- LVM_INSERTGROUPSORTED
* -- LVM_INSERTMARKHITTEST
* -- LVM_ISGROUPVIEWENABLED
* -- LVM_MOVEGROUP
* -- LVM_MOVEITEMTOGROUP
* -- LVM_SETINFOTIP
* -- LVM_SETTILEWIDTH
* -- LVM_SORTGROUPS
*
* Macros:
* -- ListView_GetHoverTime, ListView_SetHoverTime
* -- ListView_GetISearchString
* -- ListView_GetNumberOfWorkAreas
* -- ListView_GetWorkAreas, ListView_SetWorkAreas
*
* Functions:
* -- LVGroupComparE
*/
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winnt.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "commctrl.h"
#include "comctl32.h"
#include "uxtheme.h"
#include "vsstyle.h"
#include "shlwapi.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(listview);
typedef struct tagCOLUMN_INFO
{
RECT rcHeader; /* tracks the header's rectangle */
INT fmt; /* same as LVCOLUMN.fmt */
INT cxMin;
} COLUMN_INFO;
typedef struct tagITEMHDR
{
LPWSTR pszText;
INT iImage;
} ITEMHDR, *LPITEMHDR;
typedef struct tagSUBITEM_INFO
{
ITEMHDR hdr;
INT iSubItem;
} SUBITEM_INFO;
typedef struct tagITEM_ID ITEM_ID;
typedef struct tagITEM_INFO
{
ITEMHDR hdr;
UINT state;
LPARAM lParam;
INT iIndent;
ITEM_ID *id;
} ITEM_INFO;
struct tagITEM_ID
{
UINT id; /* item id */
HDPA item; /* link to item data */
};
typedef struct tagRANGE
{
INT lower;
INT upper;
} RANGE;
typedef struct tagRANGES
{
HDPA hdpa;
} *RANGES;
typedef struct tagITERATOR
{
INT nItem;
INT nSpecial;
RANGE range;
RANGES ranges;
INT index;
} ITERATOR;
typedef struct tagDELAYED_ITEM_EDIT
{
BOOL fEnabled;
INT iItem;
} DELAYED_ITEM_EDIT;
enum notification_mask
{
NOTIFY_MASK_ITEM_CHANGE = 0x1,
NOTIFY_MASK_END_LABEL_EDIT = 0x2,
NOTIFY_MASK_UNMASK_ALL = 0xffffffff
};
typedef struct tagLISTVIEW_INFO
{
/* control window */
HWND hwndSelf;
RECT rcList; /* This rectangle is really the window
* client rectangle possibly reduced by the
* horizontal scroll bar and/or header - see
* LISTVIEW_UpdateSize. This rectangle offset
* by the LISTVIEW_GetOrigin value is in
* client coordinates */
/* notification window */
SHORT notifyFormat;
HWND hwndNotify;
DWORD notify_mask;
UINT uCallbackMask;
/* tooltips */
HWND hwndToolTip;
/* items */
INT nItemCount; /* the number of items in the list */
HDPA hdpaItems; /* array ITEM_INFO pointers */
HDPA hdpaItemIds; /* array of ITEM_ID pointers */
HDPA hdpaPosX; /* maintains the (X, Y) coordinates of the */
HDPA hdpaPosY; /* items in LVS_ICON, and LVS_SMALLICON modes */
RANGES selectionRanges;
INT nSelectionMark; /* item to start next multiselection from */
INT nHotItem;
/* columns */
HDPA hdpaColumns; /* array of COLUMN_INFO pointers */
BOOL colRectsDirty; /* trigger column rectangles requery from header */
INT selected_column; /* index for LVM_SETSELECTEDCOLUMN/LVM_GETSELECTEDCOLUMN */
/* item metrics */
BOOL bNoItemMetrics; /* flags if item metrics are not yet computed */
INT nItemHeight;
INT nItemWidth;
/* style */
DWORD dwStyle; /* the cached window GWL_STYLE */
DWORD dwLvExStyle; /* extended listview style */
DWORD uView; /* current view available through LVM_[G,S]ETVIEW */
/* edit item */
HWND hwndEdit;
WNDPROC EditWndProc;
INT nEditLabelItem;
DELAYED_ITEM_EDIT itemEdit; /* Pointer to this structure will be the timer ID */
/* icons */
HIMAGELIST himlNormal;
HIMAGELIST himlSmall;
HIMAGELIST himlState;
SIZE iconSize;
BOOL autoSpacing;
SIZE iconSpacing;
SIZE iconStateSize;
POINT currIconPos; /* this is the position next icon will be placed */
/* header */
HWND hwndHeader;
INT xTrackLine; /* The x coefficient of the track line or -1 if none */
/* marquee selection */
BOOL bMarqueeSelect; /* marquee selection/highlight underway */
BOOL bScrolling;
RECT marqueeRect; /* absolute coordinates of marquee selection */
RECT marqueeDrawRect; /* relative coordinates for drawing marquee */
POINT marqueeOrigin; /* absolute coordinates of marquee click origin */
/* focus drawing */
BOOL bFocus; /* control has focus */
INT nFocusedItem;
RECT rcFocus; /* focus bounds */
/* colors */
HBRUSH hBkBrush;
COLORREF clrBk;
COLORREF clrText;
COLORREF clrTextBk;
HBITMAP hBkBitmap;
/* font */
HFONT hDefaultFont;
HFONT hFont;
INT ntmHeight; /* Some cached metrics of the font used */
INT ntmMaxCharWidth; /* by the listview to draw items */
INT nEllipsisWidth;
/* mouse operation */
BOOL bLButtonDown;
BOOL bDragging;
POINT ptClickPos; /* point where the user clicked */
INT nLButtonDownItem; /* tracks item to reset multiselection on WM_LBUTTONUP */
DWORD dwHoverTime;
HCURSOR hHotCursor;
INT cWheelRemainder;
/* keyboard operation */
DWORD lastKeyPressTimestamp;
WPARAM charCode;
INT nSearchParamLength;
WCHAR szSearchParam[ MAX_PATH ];
/* painting */
BOOL bIsDrawing; /* Drawing in progress */
INT nMeasureItemHeight; /* WM_MEASUREITEM result */
BOOL redraw; /* WM_SETREDRAW switch */
/* misc */
DWORD iVersion; /* CCM_[G,S]ETVERSION */
} LISTVIEW_INFO;
/*
* constants
*/
/* How many we debug buffer to allocate */
#define DEBUG_BUFFERS 20
/* The size of a single debug buffer */
#define DEBUG_BUFFER_SIZE 256
/* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
#define SB_INTERNAL -1
/* maximum size of a label */
#define DISP_TEXT_SIZE 260
/* padding for items in list and small icon display modes */
#define WIDTH_PADDING 12
/* padding for items in list, report and small icon display modes */
#define HEIGHT_PADDING 1
/* offset of items in report display mode */
#define REPORT_MARGINX 2
/* padding for icon in large icon display mode
* ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
* that HITTEST will see.
* ICON_TOP_PADDING_HITABLE - spacing between above and icon.
* ICON_TOP_PADDING - sum of the two above.
* ICON_BOTTOM_PADDING - between bottom of icon and top of text
* LABEL_HOR_PADDING - between text and sides of box
* LABEL_VERT_PADDING - between bottom of text and end of box
*
* ICON_LR_PADDING - additional width above icon size.
* ICON_LR_HALF - half of the above value
*/
#define ICON_TOP_PADDING_NOTHITABLE 2
#define ICON_TOP_PADDING_HITABLE 2
#define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
#define ICON_BOTTOM_PADDING 4
#define LABEL_HOR_PADDING 5
#define LABEL_VERT_PADDING 7
#define ICON_LR_PADDING 16
#define ICON_LR_HALF (ICON_LR_PADDING/2)
/* default label width for items in list and small icon display modes */
#define DEFAULT_LABEL_WIDTH 40
/* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
#define MAX_EMPTYTEXT_SELECT_WIDTH 80
/* default column width for items in list display mode */
#define DEFAULT_COLUMN_WIDTH 128
/* Size of "line" scroll for V & H scrolls */
#define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
/* Padding between image and label */
#define IMAGE_PADDING 2
/* Padding behind the label */
#define TRAILING_LABEL_PADDING 12
#define TRAILING_HEADER_PADDING 11
/* Border for the icon caption */
#define CAPTION_BORDER 2
/* Standard DrawText flags */
#define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
#define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
#define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
/* Image index from state */
#define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
/* The time in milliseconds to reset the search in the list */
#define KEY_DELAY 450
/* Dump the LISTVIEW_INFO structure to the debug channel */
#define LISTVIEW_DUMP(iP) do { \
TRACE("hwndSelf=%p, clrBk=%#lx, clrText=%#lx, clrTextBk=%#lx, ItemHeight=%d, ItemWidth=%d, Style=%#lx\n", \
iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=%#lx, Focus=%d\n", \
iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
} while(0)
static const WCHAR themeClass[] = L"ListView";
/*
* forward declarations
*/
static BOOL LISTVIEW_GetItemT(const LISTVIEW_INFO *, LPLVITEMW, BOOL);
static void LISTVIEW_GetItemBox(const LISTVIEW_INFO *, INT, LPRECT);
static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO *, INT, LPPOINT);
static BOOL LISTVIEW_GetItemPosition(const LISTVIEW_INFO *, INT, LPPOINT);
static BOOL LISTVIEW_GetItemRect(const LISTVIEW_INFO *, INT, LPRECT);
static void LISTVIEW_GetOrigin(const LISTVIEW_INFO *, LPPOINT);
static BOOL LISTVIEW_GetViewRect(const LISTVIEW_INFO *, LPRECT);
static void LISTVIEW_UpdateSize(LISTVIEW_INFO *);
static LRESULT LISTVIEW_Command(LISTVIEW_INFO *, WPARAM, LPARAM);
static INT LISTVIEW_GetStringWidthT(const LISTVIEW_INFO *, LPCWSTR, BOOL);
static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *, INT, BOOL);
static UINT LISTVIEW_GetItemState(const LISTVIEW_INFO *, INT, UINT);
static BOOL LISTVIEW_SetItemState(LISTVIEW_INFO *, INT, const LVITEMW *);
static VOID LISTVIEW_SetOwnerDataState(LISTVIEW_INFO *, INT, INT, const LVITEMW *);
static LRESULT LISTVIEW_VScroll(LISTVIEW_INFO *, INT, INT);
static LRESULT LISTVIEW_HScroll(LISTVIEW_INFO *, INT, INT);
static BOOL LISTVIEW_EnsureVisible(LISTVIEW_INFO *, INT, BOOL);
static HIMAGELIST LISTVIEW_SetImageList(LISTVIEW_INFO *, INT, HIMAGELIST);
static INT LISTVIEW_HitTest(const LISTVIEW_INFO *, LPLVHITTESTINFO, BOOL, BOOL);
static BOOL LISTVIEW_EndEditLabelT(LISTVIEW_INFO *, BOOL, BOOL);
static BOOL LISTVIEW_Scroll(LISTVIEW_INFO *, INT, INT);
/******** Text handling functions *************************************/
/* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
* text string. The string may be ANSI or Unicode, in which case
* the boolean isW tells us the type of the string.
*
* The name of the function tell what type of strings it expects:
* W: Unicode, T: ANSI/Unicode - function of isW
*/
static inline BOOL is_text(LPCWSTR text)
{
return text != NULL && text != LPSTR_TEXTCALLBACKW;
}
static inline int textlenT(LPCWSTR text, BOOL isW)
{
return !is_text(text) ? 0 :
isW ? lstrlenW(text) : lstrlenA((LPCSTR)text);
}
static inline void textcpynT(LPWSTR dest, BOOL isDestW, LPCWSTR src, BOOL isSrcW, INT max)
{
if (isDestW)
if (isSrcW) lstrcpynW(dest, src, max);
else MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1, dest, max);
else
if (isSrcW) WideCharToMultiByte(CP_ACP, 0, src, -1, (LPSTR)dest, max, NULL, NULL);
else lstrcpynA((LPSTR)dest, (LPCSTR)src, max);
}
static inline LPWSTR textdupTtoW(LPCWSTR text, BOOL isW)
{
LPWSTR wstr = (LPWSTR)text;
if (!isW && is_text(text))
{
INT len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)text, -1, NULL, 0);
wstr = Alloc(len * sizeof(WCHAR));
if (wstr) MultiByteToWideChar(CP_ACP, 0, (LPCSTR)text, -1, wstr, len);
}
TRACE(" wstr=%s\n", text == LPSTR_TEXTCALLBACKW ? "(callback)" : debugstr_w(wstr));
return wstr;
}
static inline void textfreeT(LPWSTR wstr, BOOL isW)
{
if (!isW && is_text(wstr)) Free (wstr);
}
/*
* dest is a pointer to a Unicode string
* src is a pointer to a string (Unicode if isW, ANSI if !isW)
*/
static BOOL textsetptrT(LPWSTR *dest, LPCWSTR src, BOOL isW)
{
BOOL bResult = TRUE;
if (src == LPSTR_TEXTCALLBACKW)
{
if (is_text(*dest)) Free(*dest);
*dest = LPSTR_TEXTCALLBACKW;
}
else
{
LPWSTR pszText = textdupTtoW(src, isW);
if (*dest == LPSTR_TEXTCALLBACKW) *dest = NULL;
bResult = Str_SetPtrW(dest, pszText);
textfreeT(pszText, isW);
}
return bResult;
}
/*
* compares a Unicode to a Unicode/ANSI text string
*/
static inline int textcmpWT(LPCWSTR aw, LPCWSTR bt, BOOL isW)
{
if (!aw) return bt ? -1 : 0;
if (!bt) return 1;
if (aw == LPSTR_TEXTCALLBACKW)
return bt == LPSTR_TEXTCALLBACKW ? 1 : -1;
if (bt != LPSTR_TEXTCALLBACKW)
{
LPWSTR bw = textdupTtoW(bt, isW);
int r = bw ? lstrcmpW(aw, bw) : 1;
textfreeT(bw, isW);
return r;
}
return 1;
}
/******** Debugging functions *****************************************/
static inline LPCSTR debugtext_t(LPCWSTR text, BOOL isW)
{
if (text == LPSTR_TEXTCALLBACKW) return "(callback)";
return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
}
static inline LPCSTR debugtext_tn(LPCWSTR text, BOOL isW, INT n)
{
if (text == LPSTR_TEXTCALLBACKW) return "(callback)";
n = min(textlenT(text, isW), n);
return isW ? debugstr_wn(text, n) : debugstr_an((LPCSTR)text, n);
}
static char* debug_getbuf(void)
{
static int index = 0;
static char buffers[DEBUG_BUFFERS][DEBUG_BUFFER_SIZE];
return buffers[index++ % DEBUG_BUFFERS];
}
static inline const char* debugrange(const RANGE *lprng)
{
if (!lprng) return "(null)";
return wine_dbg_sprintf("[%d, %d]", lprng->lower, lprng->upper);
}
static const char* debugscrollinfo(const SCROLLINFO *pScrollInfo)
{
char* buf = debug_getbuf(), *text = buf;
int len, size = DEBUG_BUFFER_SIZE;
if (pScrollInfo == NULL) return "(null)";
len = snprintf(buf, size, "{cbSize=%u, ", pScrollInfo->cbSize);
if (len == -1) goto end;
buf += len; size -= len;
if (pScrollInfo->fMask & SIF_RANGE)
len = snprintf(buf, size, "nMin=%d, nMax=%d, ", pScrollInfo->nMin, pScrollInfo->nMax);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (pScrollInfo->fMask & SIF_PAGE)
len = snprintf(buf, size, "nPage=%u, ", pScrollInfo->nPage);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (pScrollInfo->fMask & SIF_POS)
len = snprintf(buf, size, "nPos=%d, ", pScrollInfo->nPos);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (pScrollInfo->fMask & SIF_TRACKPOS)
len = snprintf(buf, size, "nTrackPos=%d, ", pScrollInfo->nTrackPos);
else len = 0;
if (len == -1) goto end;
buf += len;
goto undo;
end:
buf = text + strlen(text);
undo:
if (buf - text > 2) { buf[-2] = '}'; buf[-1] = 0; }
return text;
}
static const char* debugnmlistview(const NMLISTVIEW *plvnm)
{
if (!plvnm) return "(null)";
return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
" uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%Id",
plvnm->iItem, plvnm->iSubItem, plvnm->uNewState, plvnm->uOldState,
plvnm->uChanged, wine_dbgstr_point(&plvnm->ptAction), plvnm->lParam);
}
static const char* debuglvitem_t(const LVITEMW *lpLVItem, BOOL isW)
{
char* buf = debug_getbuf(), *text = buf;
int len, size = DEBUG_BUFFER_SIZE;
if (lpLVItem == NULL) return "(null)";
len = snprintf(buf, size, "{iItem=%d, iSubItem=%d, ", lpLVItem->iItem, lpLVItem->iSubItem);
if (len == -1) goto end;
buf += len; size -= len;
if (lpLVItem->mask & LVIF_STATE)
len = snprintf(buf, size, "state=%x, stateMask=%x, ", lpLVItem->state, lpLVItem->stateMask);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpLVItem->mask & LVIF_TEXT)
len = snprintf(buf, size, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem->pszText, isW, 80), lpLVItem->cchTextMax);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpLVItem->mask & LVIF_IMAGE)
len = snprintf(buf, size, "iImage=%d, ", lpLVItem->iImage);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpLVItem->mask & LVIF_PARAM)
len = snprintf(buf, size, "lParam=%Ix, ", lpLVItem->lParam);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpLVItem->mask & LVIF_INDENT)
len = snprintf(buf, size, "iIndent=%d, ", lpLVItem->iIndent);
else len = 0;
if (len == -1) goto end;
buf += len;
goto undo;
end:
buf = text + strlen(text);
undo:
if (buf - text > 2) { buf[-2] = '}'; buf[-1] = 0; }
return text;
}
static const char* debuglvcolumn_t(const LVCOLUMNW *lpColumn, BOOL isW)
{
char* buf = debug_getbuf(), *text = buf;
int len, size = DEBUG_BUFFER_SIZE;
if (lpColumn == NULL) return "(null)";
len = snprintf(buf, size, "{");
if (len == -1) goto end;
buf += len; size -= len;
if (lpColumn->mask & LVCF_SUBITEM)
len = snprintf(buf, size, "iSubItem=%d, ", lpColumn->iSubItem);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpColumn->mask & LVCF_FMT)
len = snprintf(buf, size, "fmt=%x, ", lpColumn->fmt);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpColumn->mask & LVCF_WIDTH)
len = snprintf(buf, size, "cx=%d, ", lpColumn->cx);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpColumn->mask & LVCF_TEXT)
len = snprintf(buf, size, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn->pszText, isW, 80), lpColumn->cchTextMax);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpColumn->mask & LVCF_IMAGE)
len = snprintf(buf, size, "iImage=%d, ", lpColumn->iImage);
else len = 0;
if (len == -1) goto end;
buf += len; size -= len;
if (lpColumn->mask & LVCF_ORDER)
len = snprintf(buf, size, "iOrder=%d, ", lpColumn->iOrder);
else len = 0;
if (len == -1) goto end;
buf += len;
goto undo;
end:
buf = text + strlen(text);
undo:
if (buf - text > 2) { buf[-2] = '}'; buf[-1] = 0; }
return text;
}
static const char* debuglvhittestinfo(const LVHITTESTINFO *lpht)
{
if (!lpht) return "(null)";
return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
wine_dbgstr_point(&lpht->pt), lpht->flags, lpht->iItem, lpht->iSubItem);
}
/* Return the corresponding text for a given scroll value */
static inline LPCSTR debugscrollcode(int nScrollCode)
{
switch(nScrollCode)
{
case SB_LINELEFT: return "SB_LINELEFT";
case SB_LINERIGHT: return "SB_LINERIGHT";
case SB_PAGELEFT: return "SB_PAGELEFT";
case SB_PAGERIGHT: return "SB_PAGERIGHT";
case SB_THUMBPOSITION: return "SB_THUMBPOSITION";
case SB_THUMBTRACK: return "SB_THUMBTRACK";
case SB_ENDSCROLL: return "SB_ENDSCROLL";
case SB_INTERNAL: return "SB_INTERNAL";
default: return "unknown";
}
}
/******** Notification functions ************************************/
static int get_ansi_notification(UINT unicodeNotificationCode)
{
switch (unicodeNotificationCode)
{
case LVN_BEGINLABELEDITA:
case LVN_BEGINLABELEDITW: return LVN_BEGINLABELEDITA;
case LVN_ENDLABELEDITA:
case LVN_ENDLABELEDITW: return LVN_ENDLABELEDITA;
case LVN_GETDISPINFOA:
case LVN_GETDISPINFOW: return LVN_GETDISPINFOA;
case LVN_SETDISPINFOA:
case LVN_SETDISPINFOW: return LVN_SETDISPINFOA;
case LVN_ODFINDITEMA:
case LVN_ODFINDITEMW: return LVN_ODFINDITEMA;
case LVN_GETINFOTIPA:
case LVN_GETINFOTIPW: return LVN_GETINFOTIPA;
/* header forwards */
case HDN_TRACKA:
case HDN_TRACKW: return HDN_TRACKA;
case HDN_ENDTRACKA:
case HDN_ENDTRACKW: return HDN_ENDTRACKA;
case HDN_BEGINDRAG: return HDN_BEGINDRAG;
case HDN_ENDDRAG: return HDN_ENDDRAG;
case HDN_ITEMCHANGINGA:
case HDN_ITEMCHANGINGW: return HDN_ITEMCHANGINGA;
case HDN_ITEMCHANGEDA:
case HDN_ITEMCHANGEDW: return HDN_ITEMCHANGEDA;
case HDN_ITEMCLICKA:
case HDN_ITEMCLICKW: return HDN_ITEMCLICKA;
case HDN_DIVIDERDBLCLICKA:
case HDN_DIVIDERDBLCLICKW: return HDN_DIVIDERDBLCLICKA;
default: break;
}
FIXME("unknown notification %x\n", unicodeNotificationCode);
return unicodeNotificationCode;
}
/* forwards header notifications to listview parent */
static LRESULT notify_forward_header(const LISTVIEW_INFO *infoPtr, NMHEADERW *lpnmhW)
{
LPCWSTR text = NULL, filter = NULL;
LRESULT ret;
NMHEADERA *lpnmh = (NMHEADERA*) lpnmhW;
/* on unicode format exit earlier */
if (infoPtr->notifyFormat == NFR_UNICODE)
return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmh->hdr.idFrom,
(LPARAM)lpnmh);
/* header always supplies unicode notifications,
all we have to do is to convert strings to ANSI */
if (lpnmh->pitem)
{
/* convert item text */
if (lpnmh->pitem->mask & HDI_TEXT)
{
text = (LPCWSTR)lpnmh->pitem->pszText;
lpnmh->pitem->pszText = NULL;
Str_SetPtrWtoA(&lpnmh->pitem->pszText, text);
}
/* convert filter text */
if ((lpnmh->pitem->mask & HDI_FILTER) && (lpnmh->pitem->type == HDFT_ISSTRING) &&
lpnmh->pitem->pvFilter)
{
filter = (LPCWSTR)((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText;
((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText = NULL;
Str_SetPtrWtoA(&((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText, filter);
}
}
lpnmh->hdr.code = get_ansi_notification(lpnmh->hdr.code);
ret = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmh->hdr.idFrom,
(LPARAM)lpnmh);
/* cleanup */
if(text)
{
Free(lpnmh->pitem->pszText);
lpnmh->pitem->pszText = (LPSTR)text;
}
if(filter)
{
Free(((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText);
((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText = (LPSTR)filter;
}
return ret;
}
static LRESULT notify_hdr(const LISTVIEW_INFO *infoPtr, INT code, LPNMHDR pnmh)
{
LRESULT result;
TRACE("(code=%d)\n", code);
pnmh->hwndFrom = infoPtr->hwndSelf;
pnmh->idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
pnmh->code = code;
result = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, pnmh->idFrom, (LPARAM)pnmh);
TRACE(" <= %Id\n", result);
return result;
}
static inline BOOL notify(const LISTVIEW_INFO *infoPtr, INT code)
{
NMHDR nmh;
HWND hwnd = infoPtr->hwndSelf;
notify_hdr(infoPtr, code, &nmh);
return IsWindow(hwnd);
}
static inline void notify_itemactivate(const LISTVIEW_INFO *infoPtr, const LVHITTESTINFO *htInfo)
{
NMITEMACTIVATE nmia;
LVITEMW item;
nmia.uNewState = 0;
nmia.uOldState = 0;
nmia.uChanged = 0;
nmia.uKeyFlags = 0;
item.mask = LVIF_PARAM|LVIF_STATE;
item.iItem = htInfo->iItem;
item.iSubItem = 0;
item.stateMask = (UINT)-1;
if (LISTVIEW_GetItemT(infoPtr, &item, TRUE)) {
nmia.lParam = item.lParam;
nmia.uOldState = item.state;
nmia.uNewState = item.state | LVIS_ACTIVATING;
nmia.uChanged = LVIF_STATE;
}
nmia.iItem = htInfo->iItem;
nmia.iSubItem = htInfo->iSubItem;
nmia.ptAction = htInfo->pt;
if (GetKeyState(VK_SHIFT) & 0x8000) nmia.uKeyFlags |= LVKF_SHIFT;
if (GetKeyState(VK_CONTROL) & 0x8000) nmia.uKeyFlags |= LVKF_CONTROL;
if (GetKeyState(VK_MENU) & 0x8000) nmia.uKeyFlags |= LVKF_ALT;
notify_hdr(infoPtr, LVN_ITEMACTIVATE, (LPNMHDR)&nmia);
}
static inline LRESULT notify_listview(const LISTVIEW_INFO *infoPtr, INT code, LPNMLISTVIEW plvnm)
{
TRACE("(code=%d, plvnm=%s)\n", code, debugnmlistview(plvnm));
return notify_hdr(infoPtr, code, (LPNMHDR)plvnm);
}
/* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
static BOOL notify_click(const LISTVIEW_INFO *infoPtr, INT code, const LVHITTESTINFO *lvht)
{
NMITEMACTIVATE nmia;
LVITEMW item;
HWND hwnd = infoPtr->hwndSelf;
LRESULT ret;
TRACE("code=%d, lvht=%s\n", code, debuglvhittestinfo(lvht));
ZeroMemory(&nmia, sizeof(nmia));
nmia.iItem = lvht->iItem;
nmia.iSubItem = lvht->iSubItem;
nmia.ptAction = lvht->pt;
item.mask = LVIF_PARAM;
item.iItem = lvht->iItem;
item.iSubItem = 0;
if (LISTVIEW_GetItemT(infoPtr, &item, TRUE)) nmia.lParam = item.lParam;
ret = notify_hdr(infoPtr, code, (NMHDR*)&nmia);
return IsWindow(hwnd) && (code == NM_RCLICK ? !ret : TRUE);
}
static BOOL notify_deleteitem(const LISTVIEW_INFO *infoPtr, INT nItem)
{
NMLISTVIEW nmlv;
LVITEMW item;
HWND hwnd = infoPtr->hwndSelf;
ZeroMemory(&nmlv, sizeof (NMLISTVIEW));
nmlv.iItem = nItem;
item.mask = LVIF_PARAM;
item.iItem = nItem;
item.iSubItem = 0;
if (LISTVIEW_GetItemT(infoPtr, &item, TRUE)) nmlv.lParam = item.lParam;
notify_listview(infoPtr, LVN_DELETEITEM, &nmlv);
return IsWindow(hwnd);
}
/*
Send notification. depends on dispinfoW having same
structure as dispinfoA.
infoPtr : listview struct
code : *Unicode* notification code
pdi : dispinfo structure (can be unicode or ansi)
isW : TRUE if dispinfo is Unicode
*/
static BOOL notify_dispinfoT(const LISTVIEW_INFO *infoPtr, UINT code, LPNMLVDISPINFOW pdi, BOOL isW)
{
INT length = 0, ret_length;
LPWSTR buffer = NULL, ret_text;
BOOL return_ansi = FALSE;
BOOL return_unicode = FALSE;
BOOL ret;
if ((pdi->item.mask & LVIF_TEXT) && is_text(pdi->item.pszText))
{
return_unicode = ( isW && infoPtr->notifyFormat == NFR_ANSI);
return_ansi = (!isW && infoPtr->notifyFormat == NFR_UNICODE);
}
ret_length = pdi->item.cchTextMax;
ret_text = pdi->item.pszText;
if (return_unicode || return_ansi)
{
if (code != LVN_GETDISPINFOW)
{
length = return_ansi ?
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1, NULL, 0):
WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, NULL, 0, NULL, NULL);
}
else
{
length = pdi->item.cchTextMax;
*pdi->item.pszText = 0; /* make sure we don't process garbage */
}
buffer = Alloc( length * (return_ansi ? sizeof(WCHAR) : sizeof(CHAR)) );
if (!buffer) return FALSE;
if (return_ansi)
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1,
buffer, length);
else
WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR) buffer,
length, NULL, NULL);
pdi->item.pszText = buffer;
pdi->item.cchTextMax = length;
}
if (infoPtr->notifyFormat == NFR_ANSI)
code = get_ansi_notification(code);
TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi->item, infoPtr->notifyFormat != NFR_ANSI));
ret = notify_hdr(infoPtr, code, &pdi->hdr);
TRACE(" resulting code=%d\n", pdi->hdr.code);
if (return_ansi || return_unicode)
{
if (return_ansi && (pdi->hdr.code == LVN_GETDISPINFOA))
{
strcpy((char*)ret_text, (char*)pdi->item.pszText);
}
else if (return_unicode && (pdi->hdr.code == LVN_GETDISPINFOW))
{
lstrcpyW(ret_text, pdi->item.pszText);
}
else if (return_ansi) /* note : pointer can be changed by app ! */
{
WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR) ret_text,
ret_length, NULL, NULL);
}
else
MultiByteToWideChar(CP_ACP, 0, (LPSTR) pdi->item.pszText, -1,
ret_text, ret_length);