Merge trunk head (r43756)
[reactos.git] / reactos / base / shell / explorer / shell / pane.cpp
1 /*
2 * Copyright 2003, 2004, 2005 Martin Fuchs
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // pane.cpp
24 //
25 // Martin Fuchs, 23.07.2003
26 //
27
28
29 #include <precomp.h>
30
31 #include "../resource.h"
32
33
34 enum IMAGE {
35 IMG_NONE=-1, IMG_FILE=0, IMG_DOCUMENT, IMG_EXECUTABLE,
36 IMG_FOLDER, IMG_OPEN_FOLDER, IMG_FOLDER_PLUS,IMG_OPEN_PLUS, IMG_OPEN_MINUS,
37 IMG_FOLDER_UP, IMG_FOLDER_CUR
38 };
39
40
41 #define IMAGE_WIDTH 16
42 #define IMAGE_HEIGHT 13
43
44
45 static const TCHAR* g_pos_names[COLUMNS] = {
46 TEXT(""), /* symbol */
47 TEXT("Name"),
48 TEXT("Type"),
49 TEXT("Size"),
50 TEXT("CDate"),
51 TEXT("ADate"),
52 TEXT("MDate"),
53 TEXT("Index/Inode"),
54 TEXT("Links"),
55 TEXT("Attributes"),
56 TEXT("Security"),
57 TEXT("Content")
58 };
59
60 static const int g_pos_align[] = {
61 0,
62 HDF_LEFT, /* Name */
63 HDF_LEFT, /* Type */
64 HDF_RIGHT, /* Size */
65 HDF_LEFT, /* CDate */
66 HDF_LEFT, /* ADate */
67 HDF_LEFT, /* MDate */
68 HDF_LEFT, /* Index */
69 HDF_RIGHT, /* Links */
70 HDF_CENTER, /* Attributes */
71 HDF_LEFT, /* Security */
72 HDF_LEFT /* Content / Description */
73 };
74
75
76 Pane::Pane(HWND hparent, int id, int id_header, Entry* root, bool treePane, int visible_cols)
77 : super(CreateWindow(TEXT("ListBox"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
78 LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
79 0, 0, 0, 0, hparent, (HMENU)id, g_Globals._hInstance, 0)),
80 _root(root),
81 _visible_cols(visible_cols),
82 _treePane(treePane)
83 {
84 // insert entries into listbox
85 Entry* entry = _root;
86
87 if (entry)
88 insert_entries(entry);
89
90 init();
91
92 create_header(hparent, id_header);
93 }
94
95 Pane::~Pane()
96 {
97 ImageList_Destroy(_himl);
98 }
99
100
101 LRESULT Pane::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
102 {
103 switch(nmsg) {
104 case WM_HSCROLL:
105 set_header();
106 break;
107
108 case WM_SETFOCUS: {
109 FileChildWindow* child = (FileChildWindow*) SendMessage(GetParent(_hwnd), PM_GET_FILEWND_PTR, 0, 0);
110
111 child->set_focus_pane(this);
112 ListBox_SetSel(_hwnd, TRUE, 1);
113 /*@todo check menu items */
114 break;}
115
116 case WM_KEYDOWN: {
117 FileChildWindow* child = (FileChildWindow*) SendMessage(GetParent(_hwnd), PM_GET_FILEWND_PTR, 0, 0);
118
119 if (wparam == VK_TAB) {
120 /*@todo SetFocus(g_Globals.hdrivebar) */
121 child->switch_focus_pane();
122 }
123 break;}
124 }
125
126 return super::WndProc(nmsg, wparam, lparam);
127 }
128
129
130 bool Pane::create_header(HWND hparent, int id)
131 {
132 HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ/*@todo |HDS_BUTTONS + sort orders*/,
133 0, 0, 0, 0, hparent, (HMENU)id, g_Globals._hInstance, 0);
134 if (!hwnd)
135 return false;
136
137 SetWindowFont(hwnd, GetStockFont(DEFAULT_GUI_FONT), FALSE);
138
139 HD_ITEM hdi;
140
141 hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
142
143 for(int idx=0; idx<COLUMNS; idx++) {
144 hdi.pszText = (TCHAR*)g_pos_names[idx];
145 hdi.fmt = HDF_STRING | g_pos_align[idx];
146 hdi.cxy = _widths[idx];
147 (void)Header_InsertItem(hwnd, idx, &hdi);
148 }
149
150 _hwndHeader = hwnd;
151
152 return true;
153 }
154
155
156 void Pane::init()
157 {
158 _himl = ImageList_LoadBitmap(g_Globals._hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0));
159
160 SetWindowFont(_hwnd, _out_wrkr._hfont, FALSE);
161
162 // read the color for compressed files from registry
163 HKEY hkeyExplorer = 0;
164 DWORD len = sizeof(_clrCompressed);
165
166 if (RegOpenKey(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer"), &hkeyExplorer) ||
167 RegQueryValueEx(hkeyExplorer, TEXT("AltColor"), 0, NULL, (LPBYTE)&_clrCompressed, &len) || len!=sizeof(_clrCompressed))
168 _clrCompressed = RGB(0,0,255);
169
170 if (hkeyExplorer)
171 RegCloseKey(hkeyExplorer);
172
173 // calculate column widths
174 _out_wrkr.init_output(_hwnd);
175 calc_widths(true);
176 }
177
178
179 // calculate prefered width for all visible columns
180
181 bool Pane::calc_widths(bool anyway)
182 {
183 int col, x, cx, spc=3*_out_wrkr._spaceSize.cx;
184 int entries = ListBox_GetCount(_hwnd);
185 int orgWidths[COLUMNS];
186 int orgPositions[COLUMNS+1];
187 HFONT hfontOld;
188 HDC hdc;
189 int cnt;
190
191 if (!anyway) {
192 memcpy(orgWidths, _widths, sizeof(orgWidths));
193 memcpy(orgPositions, _positions, sizeof(orgPositions));
194 }
195
196 for(col=0; col<COLUMNS; col++)
197 _widths[col] = 0;
198
199 hdc = GetDC(_hwnd);
200 hfontOld = SelectFont(hdc, _out_wrkr._hfont);
201
202 for(cnt=0; cnt<entries; cnt++) {
203 Entry* entry = (Entry*) ListBox_GetItemData(_hwnd, cnt);
204
205 DRAWITEMSTRUCT dis;
206
207 dis.CtlType = 0;
208 dis.CtlID = 0;
209 dis.itemID = 0;
210 dis.itemAction = 0;
211 dis.itemState = 0;
212 dis.hwndItem = _hwnd;
213 dis.hDC = hdc;
214 dis.rcItem.left = 0;
215 dis.rcItem.top = 0;
216 dis.rcItem.right = 0;
217 dis.rcItem.bottom = 0;
218 /*dis.itemData = 0; */
219
220 draw_item(&dis, entry, COLUMNS);
221 }
222
223 SelectObject(hdc, hfontOld);
224 ReleaseDC(_hwnd, hdc);
225
226 x = 0;
227 for(col=0; col<COLUMNS; col++) {
228 _positions[col] = x;
229 cx = _widths[col];
230
231 if (cx) {
232 cx += spc;
233
234 if (cx < IMAGE_WIDTH)
235 cx = IMAGE_WIDTH;
236
237 _widths[col] = cx;
238 }
239
240 x += cx;
241 }
242
243 _positions[COLUMNS] = x;
244
245 ListBox_SetHorizontalExtent(_hwnd, x);
246
247 // no change?
248 if (!memcmp(orgWidths, _widths, sizeof(orgWidths)))
249 return FALSE;
250
251 // don't move, if only collapsing an entry
252 if (!anyway && _widths[0]<orgWidths[0] &&
253 !memcmp(orgWidths+1, _widths+1, sizeof(orgWidths)-sizeof(int))) {
254 _widths[0] = orgWidths[0];
255 memcpy(_positions, orgPositions, sizeof(orgPositions));
256
257 return FALSE;
258 }
259
260 InvalidateRect(_hwnd, 0, TRUE);
261
262 return TRUE;
263 }
264
265
266 static void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols)
267 {
268 SYSTEMTIME systime;
269 FILETIME lft;
270 int len = 0;
271
272 *buffer = TEXT('\0');
273
274 if (!ft->dwLowDateTime && !ft->dwHighDateTime)
275 return;
276
277 if (!FileTimeToLocalFileTime(ft, &lft))
278 {err: lstrcpy(buffer,TEXT("???")); return;}
279
280 if (!FileTimeToSystemTime(&lft, &systime))
281 goto err;
282
283 if (visible_cols & COL_DATE) {
284 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
285 if (!len)
286 goto err;
287 }
288
289 if (visible_cols & COL_TIME) {
290 if (len)
291 buffer[len-1] = ' ';
292
293 buffer[len++] = ' ';
294
295 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
296 buffer[len] = TEXT('\0');
297 }
298 }
299
300
301 void Pane::draw_item(LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
302 {
303 TCHAR buffer[BUFFER_LEN];
304 DWORD attrs;
305 int visible_cols = _visible_cols;
306 COLORREF bkcolor, textcolor;
307 RECT focusRect = dis->rcItem;
308 enum IMAGE img;
309 int img_pos, cx;
310 int col = 0;
311
312 if (entry) {
313 attrs = entry->_data.dwFileAttributes;
314
315 if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
316 if (entry->_data.cFileName[0]==TEXT('.') && entry->_data.cFileName[1]==TEXT('.')
317 && entry->_data.cFileName[2]==TEXT('\0'))
318 img = IMG_FOLDER_UP;
319 else if (entry->_data.cFileName[0]==TEXT('.') && entry->_data.cFileName[1]==TEXT('\0'))
320 img = IMG_FOLDER_CUR;
321 else if ((_treePane && (dis->itemState&ODS_FOCUS)))
322 img = IMG_OPEN_FOLDER;
323 else
324 img = IMG_FOLDER;
325 } else {
326 if (attrs & ATTRIBUTE_EXECUTABLE)
327 img = IMG_EXECUTABLE;
328 else if (entry->_type_name)
329 img = IMG_DOCUMENT;
330 else
331 img = IMG_FILE;
332 }
333 } else {
334 attrs = 0;
335 img = IMG_NONE;
336 }
337
338 if (_treePane) {
339 if (entry) {
340 img_pos = dis->rcItem.left + entry->_level*(IMAGE_WIDTH+_out_wrkr._spaceSize.cx);
341
342 if (calcWidthCol == -1) {
343 int x;
344 int y = dis->rcItem.top + IMAGE_HEIGHT/2;
345 Entry* up;
346 RECT rt_clip;
347 HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
348 HRGN hrgn;
349
350 rt_clip.left = dis->rcItem.left;
351 rt_clip.top = dis->rcItem.top;
352 rt_clip.right = dis->rcItem.left+_widths[col];
353 rt_clip.bottom = dis->rcItem.bottom;
354
355 hrgn = CreateRectRgnIndirect(&rt_clip);
356
357 if (!GetClipRgn(dis->hDC, hrgn_org)) {
358 DeleteObject(hrgn_org);
359 hrgn_org = 0;
360 }
361
362 //HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN));
363 ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
364 DeleteObject(hrgn);
365
366 if ((up=entry->_up) != NULL) {
367 MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
368 LineTo(dis->hDC, img_pos-2, y);
369
370 x = img_pos - IMAGE_WIDTH/2;
371
372 do {
373 x -= IMAGE_WIDTH+_out_wrkr._spaceSize.cx;
374
375 if (up->_next) {
376 #ifndef _LEFT_FILES
377 bool following_child = (up->_next->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0; // a directory?
378
379 if (!following_child)
380 {
381 for(Entry*n=up->_next; n; n=n->_next)
382 if (n->_down) { // any file with NTFS sub-streams?
383 following_child = true;
384 break;
385 }
386 }
387 if (following_child)
388 #endif
389 {
390 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
391 LineTo(dis->hDC, x, dis->rcItem.bottom);
392 }
393 }
394 } while((up=up->_up) != NULL);
395 }
396
397 x = img_pos - IMAGE_WIDTH/2;
398
399 MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
400 LineTo(dis->hDC, x, y);
401
402 if (entry->_next) {
403 #ifndef _LEFT_FILES
404 bool following_child = (entry->_next->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0; // a directory?
405
406 if (!following_child)
407 {
408 for(Entry*n=entry->_next; n; n=n->_next)
409 if (n->_down) { // any file with NTFS sub-streams?
410 following_child = true;
411 break;
412 }
413 }
414 if (following_child)
415 #endif
416 LineTo(dis->hDC, x, dis->rcItem.bottom);
417 }
418
419 if (entry->_down && entry->_expanded) {
420 x += IMAGE_WIDTH + _out_wrkr._spaceSize.cx;
421 MoveToEx(dis->hDC, x, dis->rcItem.top+IMAGE_HEIGHT, 0);
422 LineTo(dis->hDC, x, dis->rcItem.bottom);
423 }
424
425 SelectClipRgn(dis->hDC, hrgn_org);
426 if (hrgn_org) DeleteObject(hrgn_org);
427 //SelectObject(dis->hDC, holdPen);
428 } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
429 int right = img_pos + IMAGE_WIDTH - _out_wrkr._spaceSize.cx;
430
431 if (right > _widths[col])
432 _widths[col] = right;
433 }
434 } else {
435 img_pos = dis->rcItem.left;
436 }
437 } else {
438 img_pos = dis->rcItem.left;
439
440 if (calcWidthCol==col || calcWidthCol==COLUMNS)
441 _widths[col] = IMAGE_WIDTH;
442 }
443
444 if (calcWidthCol == -1) {
445 focusRect.left = img_pos -2;
446
447 if (attrs & FILE_ATTRIBUTE_COMPRESSED)
448 textcolor = _clrCompressed;
449 else
450 textcolor = RGB(0,0,0);
451
452 if (dis->itemState & ODS_FOCUS) {
453 textcolor = GetSysColor(COLOR_HIGHLIGHTTEXT);
454 bkcolor = GetSysColor(COLOR_HIGHLIGHT);
455 } else {
456 bkcolor = GetSysColor(COLOR_WINDOW);
457 }
458
459 HBRUSH hbrush = CreateSolidBrush(bkcolor);
460 FillRect(dis->hDC, &focusRect, hbrush);
461 DeleteObject(hbrush);
462
463 SetBkMode(dis->hDC, TRANSPARENT);
464 SetTextColor(dis->hDC, textcolor);
465
466 cx = _widths[col];
467
468 if (cx && img!=IMG_NONE) {
469 if (cx > IMAGE_WIDTH)
470 cx = IMAGE_WIDTH;
471
472 if (entry->_icon_id > ICID_NONE)
473 g_Globals._icon_cache.get_icon(entry->_icon_id).draw(dis->hDC, img_pos, dis->rcItem.top, cx, GetSystemMetrics(SM_CYSMICON), bkcolor, 0);
474 else
475 ImageList_DrawEx(_himl, img, dis->hDC,
476 img_pos, dis->rcItem.top, cx,
477 IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
478 }
479 }
480
481 if (!entry)
482 return;
483
484 ++col;
485
486 // output file name
487 if (calcWidthCol == -1)
488 _out_wrkr.output_text(dis, _positions, col, entry->_display_name, 0);
489 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
490 calc_width(dis, col, entry->_display_name);
491 ++col;
492
493 // output type/class name
494 if (visible_cols & COL_TYPE) {
495 if (calcWidthCol == -1)
496 _out_wrkr.output_text(dis, _positions, col, entry->_type_name? entry->_type_name: TEXT(""), 0);
497 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
498 calc_width(dis, col, entry->_type_name? entry->_type_name: TEXT(""));
499 }
500 ++col;
501
502 // display file size
503 if (visible_cols & COL_SIZE) {
504 ULONGLONG size = ((ULONGLONG)entry->_data.nFileSizeHigh << 32) | entry->_data.nFileSizeLow;
505
506 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("d"), size);
507
508 if (calcWidthCol == -1)
509 _out_wrkr.output_number(dis, _positions, col, buffer);
510 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
511 calc_width(dis, col, buffer); ///@todo not in every case time enough
512 }
513 ++col;
514
515 // display file date
516 if (visible_cols & (COL_DATE|COL_TIME)) {
517 format_date(&entry->_data.ftCreationTime, buffer, visible_cols);
518 if (calcWidthCol == -1)
519 _out_wrkr.output_text(dis, _positions, col, buffer, 0);
520 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
521 calc_width(dis, col, buffer);
522 ++col;
523
524 format_date(&entry->_data.ftLastAccessTime, buffer, visible_cols);
525 if (calcWidthCol == -1)
526 _out_wrkr.output_text(dis,_positions, col, buffer, 0);
527 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
528 calc_width(dis, col, buffer);
529 ++col;
530
531 format_date(&entry->_data.ftLastWriteTime, buffer, visible_cols);
532 if (calcWidthCol == -1)
533 _out_wrkr.output_text(dis, _positions, col, buffer, 0);
534 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
535 calc_width(dis, col, buffer);
536 ++col;
537 } else
538 col += 3;
539
540 if (entry->_bhfi_valid) {
541 ULONGLONG index = ((ULONGLONG)entry->_bhfi.nFileIndexHigh << 32) | entry->_bhfi.nFileIndexLow;
542
543 if (visible_cols & COL_INDEX) {
544 _stprintf(buffer, TEXT("%") LONGLONGARG TEXT("X"), index);
545
546 if (calcWidthCol == -1)
547 _out_wrkr.output_text(dis, _positions, col, buffer, DT_RIGHT);
548 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
549 calc_width(dis, col, buffer);
550
551 ++col;
552 }
553
554 if (visible_cols & COL_LINKS) {
555 wsprintf(buffer, TEXT("%d"), entry->_bhfi.nNumberOfLinks);
556
557 if (calcWidthCol == -1)
558 _out_wrkr.output_text(dis, _positions, col, buffer, DT_RIGHT);
559 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
560 calc_width(dis, col, buffer);
561
562 ++col;
563 }
564 } else
565 col += 2;
566
567 // show file attributes
568 if (visible_cols & COL_ATTRIBUTES) {
569 lstrcpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t \t \t \t "));
570
571 if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
572 else {
573 if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
574 if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
575 if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
576 if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
577 if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
578 if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
579 if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
580 if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
581 if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
582 if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
583 if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
584 if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
585 if (attrs & ATTRIBUTE_EXECUTABLE) buffer[26] = 'x';
586 if (attrs & ATTRIBUTE_SYMBOLIC_LINK) buffer[28] = 'L';
587 }
588
589 if (calcWidthCol == -1)
590 _out_wrkr.output_tabbed_text(dis, _positions, col, buffer);
591 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
592 calc_tabbed_width(dis, col, buffer);
593 }
594 ++col;
595
596 /*TODO
597 if (flags.security) {
598 DWORD rights = get_access_mask();
599
600 tcscpy(buffer, TEXT(" \t \t \t \t \t \t \t \t \t \t \t "));
601
602 if (rights & FILE_READ_DATA) buffer[ 0] = 'R';
603 if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W';
604 if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A';
605 if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';}
606 if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';}
607 if (rights & FILE_EXECUTE) buffer[12] = 'X';
608 if (rights & FILE_DELETE_CHILD) buffer[14] = 'D';
609 if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';}
610 if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';}
611 if (rights & WRITE_DAC) buffer[22] = 'C';
612 if (rights & WRITE_OWNER) buffer[24] = 'O';
613 if (rights & SYNCHRONIZE) buffer[26] = 'S';
614
615 output_text(dis, col++, buffer, DT_LEFT, 3, psize);
616 }
617
618 if (flags.description) {
619 get_description(buffer);
620 output_text(dis, col++, buffer, 0, psize);
621 }
622 */
623 ++col;
624
625 // output content / symbolic link target / comment
626 if (visible_cols & COL_CONTENT) {
627 if (calcWidthCol == -1)
628 _out_wrkr.output_text(dis, _positions, col, entry->_content? entry->_content: TEXT(""), 0);
629 else if (calcWidthCol==col || calcWidthCol==COLUMNS)
630 calc_width(dis, col, entry->_content? entry->_content: TEXT(""));
631 }
632 }
633
634
635 void Pane::calc_width(LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
636 {
637 RECT rt = {0, 0, 0, 0};
638
639 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
640
641 if (rt.right > _widths[col])
642 _widths[col] = rt.right;
643 }
644
645 void Pane::calc_tabbed_width(LPDRAWITEMSTRUCT dis, int col, LPCTSTR str)
646 {
647 RECT rt = {0, 0, 0, 0};
648
649 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
650 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
651
652 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
653
654 if (rt.right > _widths[col])
655 _widths[col] = rt.right;
656 }
657
658
659 // insert listbox entries after index idx
660
661 int Pane::insert_entries(Entry* dir, int idx)
662 {
663 Entry* entry = dir;
664
665 if (!entry)
666 return idx;
667
668 for(; entry; entry=entry->_next) {
669 #ifndef _LEFT_FILES
670 if (_treePane &&
671 !(entry->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) && // not a directory?
672 !entry->_down) // not a file with NTFS sub-streams?
673 continue;
674 #endif
675
676 // don't display entries "." and ".." in the left pane
677 if (_treePane && (entry->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
678 && entry->_data.cFileName[0]==TEXT('.'))
679 if (entry->_data.cFileName[1]==TEXT('\0') ||
680 (entry->_data.cFileName[1]==TEXT('.') && entry->_data.cFileName[2]==TEXT('\0')))
681 continue;
682
683 if (idx != -1)
684 ++idx;
685
686 ListBox_InsertItemData(_hwnd, idx, entry);
687
688 if (_treePane && entry->_expanded)
689 idx = insert_entries(entry->_down, idx);
690 }
691
692 return idx;
693 }
694
695
696 void Pane::set_header()
697 {
698 HD_ITEM item;
699 int scroll_pos = GetScrollPos(_hwnd, SB_HORZ);
700 int i=0, x=0;
701
702 item.mask = HDI_WIDTH;
703 item.cxy = 0;
704
705 for(; x+_widths[i]<scroll_pos && i<COLUMNS; i++) {
706 x += _widths[i];
707 (void)Header_SetItem(_hwndHeader, i, &item);
708 }
709
710 if (i < COLUMNS) {
711 x += _widths[i];
712 item.cxy = x - scroll_pos;
713 (void)Header_SetItem(_hwndHeader, i++, &item);
714
715 for(; i<COLUMNS; i++) {
716 item.cxy = _widths[i];
717 x += _widths[i];
718 (void)Header_SetItem(_hwndHeader, i, &item);
719 }
720 }
721 }
722
723
724 // calculate one prefered column width
725
726 void Pane::calc_single_width(int col)
727 {
728 HFONT hfontOld;
729 int x, cx;
730 int cnt;
731 HDC hdc;
732
733 int entries = ListBox_GetCount(_hwnd);
734
735 _widths[col] = 0;
736
737 hdc = GetDC(_hwnd);
738 hfontOld = SelectFont(hdc, _out_wrkr._hfont);
739
740 for(cnt=0; cnt<entries; cnt++) {
741 Entry* entry = (Entry*) ListBox_GetItemData(_hwnd, cnt);
742
743 DRAWITEMSTRUCT dis;
744
745 dis.CtlType = 0;
746 dis.CtlID = 0;
747 dis.itemID = 0;
748 dis.itemAction = 0;
749 dis.itemState = 0;
750 dis.hwndItem = _hwnd;
751 dis.hDC = hdc;
752 dis.rcItem.left = 0;
753 dis.rcItem.top = 0;
754 dis.rcItem.right = 0;
755 dis.rcItem.bottom = 0;
756 /*dis.itemData = 0; */
757
758 draw_item(&dis, entry, col);
759 }
760
761 SelectObject(hdc, hfontOld);
762 ReleaseDC(_hwnd, hdc);
763
764 cx = _widths[col];
765
766 if (cx) {
767 cx += 3*_out_wrkr._spaceSize.cx;
768
769 if (cx < IMAGE_WIDTH)
770 cx = IMAGE_WIDTH;
771 }
772
773 _widths[col] = cx;
774
775 x = _positions[col] + cx;
776
777 for(; col<COLUMNS; col++) {
778 _positions[col+1] = x;
779 x += _widths[col];
780 }
781
782 (void)ListBox_SetHorizontalExtent(_hwnd, x);
783 }
784
785
786 int Pane::Notify(int id, NMHDR* pnmh)
787 {
788 switch(pnmh->code) {
789 case HDN_TRACK:
790 case HDN_ENDTRACK: {
791 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
792 int idx = phdn->iItem;
793 int dx = phdn->pitem->cxy - _widths[idx];
794 int i;
795
796 ClientRect clnt(_hwnd);
797
798 // move immediate to simulate HDS_FULLDRAG (for now [04/2000] not realy needed with WINELIB)
799 (void)Header_SetItem(_hwndHeader, idx, phdn->pitem);
800
801 _widths[idx] += dx;
802
803 for(i=idx; ++i<=COLUMNS; )
804 _positions[i] += dx;
805
806 {
807 int scroll_pos = GetScrollPos(_hwnd, SB_HORZ);
808 RECT rt_scr;
809 RECT rt_clip;
810
811 rt_scr.left = _positions[idx+1]-scroll_pos;
812 rt_scr.top = 0;
813 rt_scr.right = clnt.right;
814 rt_scr.bottom = clnt.bottom;
815
816 rt_clip.left = _positions[idx]-scroll_pos;
817 rt_clip.top = 0;
818 rt_clip.right = clnt.right;
819 rt_clip.bottom = clnt.bottom;
820
821 if (rt_scr.left < 0) rt_scr.left = 0;
822 if (rt_clip.left < 0) rt_clip.left = 0;
823
824 ScrollWindowEx(_hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
825
826 rt_clip.right = _positions[idx+1];
827 RedrawWindow(_hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
828
829 if (pnmh->code == HDN_ENDTRACK) {
830 ListBox_SetHorizontalExtent(_hwnd, _positions[COLUMNS]);
831
832 if (GetScrollPos(_hwnd, SB_HORZ) != scroll_pos)
833 set_header();
834 }
835 }
836
837 return 0;
838 }
839
840 case HDN_DIVIDERDBLCLICK: {
841 HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh;
842 HD_ITEM item;
843
844 calc_single_width(phdn->iItem);
845 item.mask = HDI_WIDTH;
846 item.cxy = _widths[phdn->iItem];
847
848 (void)Header_SetItem(_hwndHeader, phdn->iItem, &item);
849 InvalidateRect(_hwnd, 0, TRUE);
850 break;}
851
852 default:
853 return super::Notify(id, pnmh);
854 }
855
856 return 0;
857 }
858
859
860 OutputWorker::OutputWorker()
861 {
862 _hfont = CreateFont(-MulDiv(8,GetDeviceCaps(WindowCanvas(0),LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Sans Serif"));
863 }
864
865 void OutputWorker::init_output(HWND hwnd)
866 {
867 TCHAR b[16];
868
869 WindowCanvas canvas(hwnd);
870
871 if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, TEXT("1000"), 0, b, 16) > 4)
872 _num_sep = b[1];
873 else
874 _num_sep = TEXT('.');
875
876 FontSelection font(canvas, _hfont);
877 GetTextExtentPoint32(canvas, TEXT(" "), 1, &_spaceSize);
878 }
879
880
881 void OutputWorker::output_text(LPDRAWITEMSTRUCT dis, int* positions, int col, LPCTSTR str, DWORD flags)
882 {
883 int x = dis->rcItem.left;
884 RECT rt;
885
886 rt.left = x+positions[col]+_spaceSize.cx;
887 rt.top = dis->rcItem.top;
888 rt.right = x+positions[col+1]-_spaceSize.cx;
889 rt.bottom = dis->rcItem.bottom;
890
891 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
892 }
893
894 void OutputWorker::output_tabbed_text(LPDRAWITEMSTRUCT dis, int* positions, int col, LPCTSTR str)
895 {
896 int x = dis->rcItem.left;
897 RECT rt;
898
899 rt.left = x+positions[col]+_spaceSize.cx;
900 rt.top = dis->rcItem.top;
901 rt.right = x+positions[col+1]-_spaceSize.cx;
902 rt.bottom = dis->rcItem.bottom;
903
904 /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2};
905 DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/
906
907 DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
908 }
909
910 void OutputWorker::output_number(LPDRAWITEMSTRUCT dis, int* positions, int col, LPCTSTR str)
911 {
912 int x = dis->rcItem.left;
913 RECT rt;
914 LPCTSTR s = str;
915 TCHAR b[128];
916 LPTSTR d = b;
917 int pos;
918
919 rt.left = x+positions[col]+_spaceSize.cx;
920 rt.top = dis->rcItem.top;
921 rt.right = x+positions[col+1]-_spaceSize.cx;
922 rt.bottom = dis->rcItem.bottom;
923
924 if (*s)
925 *d++ = *s++;
926
927 // insert number separator characters
928 pos = lstrlen(s) % 3;
929
930 while(*s)
931 if (pos--)
932 *d++ = *s++;
933 else {
934 *d++ = _num_sep;
935 pos = 3;
936 }
937
938 DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
939 }
940
941
942 BOOL Pane::command(UINT cmd)
943 {
944 switch(cmd) {
945 case ID_VIEW_NAME:
946 if (_visible_cols) {
947 _visible_cols = 0;
948 calc_widths(true);
949 set_header();
950 InvalidateRect(_hwnd, 0, TRUE);
951 MenuInfo* menu_info = Frame_GetMenuInfo(GetParent(_hwnd));
952 if (menu_info) {
953 CheckMenuItem(menu_info->_hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
954 CheckMenuItem(menu_info->_hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
955 CheckMenuItem(menu_info->_hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
956 }
957 }
958 break;
959
960 case ID_VIEW_ALL_ATTRIBUTES:
961 if (_visible_cols != COL_ALL) {
962 _visible_cols = COL_ALL;
963 calc_widths(true);
964 set_header();
965 InvalidateRect(_hwnd, 0, TRUE);
966 MenuInfo* menu_info = Frame_GetMenuInfo(GetParent(_hwnd));
967 if (menu_info) {
968 CheckMenuItem(menu_info->_hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
969 CheckMenuItem(menu_info->_hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
970 CheckMenuItem(menu_info->_hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND);
971 }
972 }
973 break;
974
975 case ID_PREFERED_SIZES: {
976 calc_widths(true);
977 set_header();
978 InvalidateRect(_hwnd, 0, TRUE);
979 break;}
980
981 /*@todo more command ids... */
982
983 default:
984 return FALSE;
985 }
986
987 return TRUE;
988 }
989
990 MainFrameBase* Pane::get_frame()
991 {
992 HWND owner = GetParent(_hwnd);
993
994 return (MainFrameBase*)owner;
995 }