Develop and Download Open Source Software

Browse Subversion Repository

Contents of /old/listview.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (show annotations) (download)
Thu Mar 13 05:00:28 2008 UTC (16 years, 2 months ago) by tabasa
File MIME type: text/plain
File size: 13119 byte(s)
treemode, change treger to double-click

1
2 #include "defextern.h"
3
4 #ifndef STRICT
5 #define STRICT
6 #endif
7 #include <windows.h>
8 #include <commctrl.h>
9 #include "resource.h"
10 #include "myfilemv.h"
11 #include "initial.h"
12 #include "listview.h"
13 #include "paintflag.h"
14 #include "status.h"
15 #include "file.h"
16 #include "mouseg.h"
17
18
19 int lcx[] ={100,40,70,120,20};//•
20 posi pos(0,2,3,4,-1,1);//ˆĘ’u
21
22 char extpaint[10];
23
24
25 void setExtPaint(char *txt)
26 {
27 if(strlen(txt)<5) strcpy(extpaint, txt);
28 }
29
30 void setExtPaint(HWND list)
31 {
32 int iIndex = ListView_GetNextItem(list, -1, LVNI_SELECTED);
33 ListView_GetItemText(list, iIndex, pos.ext, extpaint, ListItemLen);
34 }
35
36
37
38 int CALLBACK MyCompProc(LPARAM lp1, LPARAM lp2, LPARAM lp3)
39 {
40 static LVFINDINFO lvf;
41 static int nItem1, nItem2;
42 static char buf1[MAX_PATH], buf2[MAX_PATH];
43 SORTDATA *lpsd;
44
45 lpsd = (SORTDATA *)lp3;
46
47 lvf.flags = LVFI_PARAM;
48 lvf.lParam = lp1;
49 nItem1 = ListView_FindItem(lpsd->hwndList, -1, &lvf);
50
51 lvf.lParam = lp2;
52 nItem2 = ListView_FindItem(lpsd->hwndList, -1, &lvf);
53
54 ListView_GetItemText(lpsd->hwndList,
55 nItem1, lpsd->isortSubItem, buf1, sizeof(buf1));
56
57 ListView_GetItemText(lpsd->hwndList,
58 nItem2, lpsd->isortSubItem, buf2, sizeof(buf2));
59 if (lpsd->isortSubItem != pos.size && lpsd->isortSubItem != pos.stat) {
60 if (lpsd->iUPDOWN == UP) {
61 return(stricmp(buf1, buf2));
62 } else {
63 return(stricmp(buf1, buf2) * -1);
64 }
65 } else {
66 if (lpsd->iUPDOWN == UP) {
67 if (atof(buf1) > atof(buf2))//strtod
68 return 1;
69 else if (atof(buf1) == atof(buf2))
70 return 0;
71 else
72 return -1;
73 } else {
74 if (atof(buf1) > atof(buf2))
75 return -1;
76 else if (atof(buf1) == atof(buf2))
77 return 0;
78 else
79 return 1;
80 }
81
82 }
83 }
84
85 void ListSelected(HWND hList, int i, BOOL fl)
86 {
87 if(fl)
88 {
89 ListView_SetItemState( hList, i, LVIS_SELECTED, LVIS_SELECTED);
90 }
91 else
92 {
93 ListView_SetItemState( hList, i, 0, LVIS_SELECTED);
94 }
95 }
96
97 void ListNonSelected( HWND hList )
98 {
99 int i =0;
100 int max =ListView_GetItemCount( hList );
101 while( i< max )
102 {
103 ListView_SetItemState( hList, i, 0, LVIS_SELECTED);
104 i++;
105 }
106 }
107
108 int LGetSelectedCount( HWND hList )
109 {
110 int i =-1;
111 int co=0;
112 int max =ListView_GetItemCount( hList );
113 while( 1 )
114 {
115 i = ListView_GetNextItem( hList, i, LVNI_ALL | LVNI_SELECTED);
116 if ( i ==-1) break;
117 co++;
118 }
119 return co;
120 }
121
122 COLORREF midcolor( DWORD ctxt, DWORD cbk )
123 {
124 static COLORREF cc;
125 BYTE bl=GetGValue(ctxt);//255
126 return RGB( GetRValue(ctxt)/2 + GetRValue(cbk)/2, GetGValue(ctxt)/2 + GetGValue(cbk)/2, bl );
127 }
128
129
130 void initlistcolor()
131 {
132 //listtextcolor =ListView_GetTextColor(hwnd);
133 //listtextbkcolor =ListView_GetTextBkColor(hwnd);
134 //ListView_SetTextBkColor(hwnd,0);
135 //ListView_SetTextColor(hwnd,0xffff);
136 listtextColor =RGB(255,255,255);//GetSysColor(COLOR_WINDOW);
137 listtextBkColor =RGB(0,0,0);//GetSysColor(COLOR_BACKGROUND);
138 listtextSpColor =midcolor(listtextColor,listtextBkColor);
139 //paintf =PAINTFLAG_DEF;
140 }
141
142
143
144 void colorRev(HWND hList)
145 {
146 listtextBkColor =ListView_GetTextBkColor(hList);
147 listtextColor =ListView_GetTextColor(hList);
148 COLORREF cr =listtextColor;
149 listtextColor =listtextBkColor;
150 listtextBkColor =cr;
151 listtextSpColor =midcolor(listtextColor,listtextBkColor);
152 }
153
154 void setlistcolor(HWND hList)
155 {
156 SetBkMode(GetDC(hList), TRANSPARENT);
157 ListView_SetTextBkColor(hList,listtextBkColor);
158 ListView_SetTextColor(hList,listtextColor);
159 }
160
161 void sortlist( HWND hList, int num )
162 {
163 num--;
164 static int sortsubno[NO_OF_SUBITEM] = {UP};
165 if (sortsubno[num] == UP)
166 sortsubno[num] = DOWN;
167 else
168 sortsubno[num] = UP;
169 SORTDATA SortData;
170 SortData.hwndList = hList;
171 SortData.isortSubItem = num;
172 SortData.iUPDOWN = sortsubno[num];
173 ListView_SortItems(hList, MyCompProc, &SortData);
174 }
175
176 void getftime(WIN32_FIND_DATA &wfd, char *txt)
177 {
178 SYSTEMTIME localtm;
179 FILETIME localft;
180 FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localft);
181 FileTimeToSystemTime(&localft, &localtm);
182 wsprintf(txt, "%02d/%02d/%02d %02d:%02d:%02d.%03d",
183 localtm.wYear, localtm.wMonth, localtm.wDay, localtm.wHour, localtm.wMinute, localtm.wSecond, localtm.wMilliseconds);
184 }
185
186
187
188 #define _normal 0
189 #define _clipmode 1
190
191 char blank[]=" ";//""‚É‚ˇ‚é‚ĆŒťóAƒtƒHƒ‹ƒ_‚ɐF‚đ‚Â‚Ż‚Ä‚ľ‚Ü‚¤
192
193
194 // mouse gesture
195
196 void AddListItem(HWND hList, char *szfname, int &iItemNo, int id, WORD key)
197 {
198 LVITEM li;
199 char item[MAX_PATH];
200 wsprintf(item, "%d",id);
201 li.mask = topmask;
202 li.iImage = NO_IMAGE;//FILE_IMAGE;
203 li.pszText = szfname;
204 li.iItem = iItemNo;
205 li.iSubItem = pos.name;
206 li.lParam = iItemNo;
207
208
209 li.iImage = FILE_IMAGE;
210
211 ListView_InsertItem(hList, &li);
212
213 li.mask = LVIF_TEXT;
214 li.iSubItem = pos.size;
215 strcpy(li.pszText, item);
216 ListView_SetItem(hList, &li);
217
218 li.iSubItem = pos.date;
219 strcpy(li.pszText, mgTransRev(item));
220 ListView_SetItem(hList, &li);
221
222 BOOL mg =(strlen(li.pszText)>0) ;
223 // else strcpy(li.pszText, "");
224 strcpy(li.pszText,"");
225 if(key/1000==0)
226 {
227 if(key>='A' && key<='Z') wsprintf(li.pszText, "%c", (char)key);
228 else if(key!=0) wsprintf(li.pszText, "x%02X", key);
229 }
230 else
231 {
232 if(key/7000==1)strcat (li.pszText, "sca+");
233 else if(key/6000==1)strcat (li.pszText, "ca+");
234 else if(key/5000==1)strcat (li.pszText, "sa+");
235 else if(key/4000==1)strcat (li.pszText, "s+");
236 else if(key/3000==1)strcat (li.pszText, "ac+");
237 else if(key/2000==1)strcat (li.pszText, "c+");
238 else if(key/1000==1)strcat (li.pszText, "a+");
239 int a=key%1000;
240 char buf[5];
241 if(a>='A' && a<='Z') wsprintf(buf, "%c", (char)a);
242 else if(a>='0' && a<='9') wsprintf(buf, "%c", (char)a);
243 else if(a!=0) wsprintf(buf, "x%02X", a);
244 strcat(li.pszText, buf);
245 }
246 if(key==0 && mg) strcat(li.pszText, ".");
247
248 li.iSubItem = pos.stat;
249 ListView_SetItem(hList, &li);
250
251 li.iSubItem = pos.ext;
252 ListView_SetItem(hList, &li);
253
254 iItemNo++;
255 }
256
257 void AddListItem(HWND hList, HANDLE hFind, char *szfname, WIN32_FIND_DATA &wfd, LVITEM &li, int &iItemNo, char *item)
258 {
259 char szBuf[MAX_PATH];
260 char ext[MAX_PATH]=defExtPaint;
261 char *p;
262 BOOL dirf;
263 strcpy(szfname, wfd.cFileName);
264 if(item!=NULL) strcpy(szfname, item);
265 li.mask = topmask;
266 li.iImage = NO_IMAGE;//FILE_IMAGE;
267 li.pszText = szfname;
268 li.iItem = iItemNo;
269 li.iSubItem = pos.name;
270 li.lParam = iItemNo;
271
272 dirf =wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
273 p=strrchr(szfname,'.');
274 if(!dirf && p!=NULL) strcpy(ext, p);
275 else strcpy(ext, blank);
276
277 //#ifdef Icon
278 if (dirf) {
279 li.iImage = DIRECTORY_IMAGE;
280 } else {
281 li.iImage = FILE_IMAGE;
282 }
283 //#endif
284
285 ListView_InsertItem(hList, &li);
286
287 li.mask = LVIF_TEXT;
288 li.iSubItem = pos.size;
289 if (!( dirf )) {
290 wsprintf(li.pszText, "%u", wfd.nFileSizeLow);
291 //itoa(wfd.nFileSizeLow, li.pszText, 10);
292 if (wfd.nFileSizeHigh != 0)
293 setstatus("ƒtƒ@ƒCƒ‹ƒTƒCƒY‚Ş‘ĺ‚Ť‚ˇ‚ʂ܂ˇ");
294 } else {
295 strcpy(li.pszText, dirmark);
296 }
297 ListView_SetItem(hList, &li);
298
299 getftime(wfd, li.pszText);
300 li.iSubItem = pos.date;
301 ListView_SetItem(hList, &li);
302
303 wsprintf(li.pszText, "%d", wfd.dwFileAttributes);
304 li.iSubItem = pos.stat;
305 ListView_SetItem(hList, &li);
306
307
308 /*
309 GetShortPathName(wfd.cFileName, szBuf, sizeof(szBuf));
310 strcpy(li.pszText, szBuf);
311 li.iSubItem = pos.dname;
312 ListView_SetItem(hList, &li);
313 */
314 //strcpy(li.pszText, p);
315 li.iSubItem = pos.ext;
316 li.pszText = ext;
317 ListView_SetItem(hList, &li);
318
319 iItemNo++;
320 }
321
322 void InsertMyColumn(HWND hList)
323 {
324 LVCOLUMN lc;//FORWARD_WM_NOTIFY
325
326 lc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
327 lc.fmt = LVCFMT_LEFT;
328 lc.cx = lcx[pos.name];
329 lc.pszText = "ƒtƒ@ƒCƒ‹–ź";
330 lc.iSubItem = pos.name;
331 ListView_InsertColumn(hList, pos.name, &lc);
332
333 lc.fmt = LVCFMT_LEFT;
334 lc.cx = lcx[pos.ext];
335 lc.pszText = "Ží—Ţ"; // Šg’ŁŽq
336 lc.iSubItem = pos.ext;
337 ListView_InsertColumn(hList, pos.ext, &lc);
338
339 lc.fmt = LVCFMT_RIGHT;
340 lc.cx = lcx[pos.size];
341 lc.pszText = "ƒTƒCƒY";
342 lc.iSubItem = pos.size;
343 ListView_InsertColumn(hList, pos.size, &lc);
344
345 lc.fmt = LVCFMT_LEFT;
346 lc.cx = lcx[pos.date];
347 lc.pszText = "XV“úŽž";
348 lc.iSubItem = pos.date;
349 ListView_InsertColumn(hList, pos.date, &lc);
350
351 lc.fmt = LVCFMT_RIGHT;
352 lc.cx = lcx[pos.stat];
353 lc.pszText = "‘ސŤ";
354 lc.iSubItem = pos.stat;
355 ListView_InsertColumn(hList, pos.stat, &lc);
356
357 return;
358 }
359 /*
360 void setlw(HWND list, int id)
361 {
362 LVCOLUMN lc;
363 lc.cx = lcx[id];
364 lc.iSubItem = id;
365 ListView_SetColumn(list, id, &lc);
366 }
367
368 void SetListWidth(HWND list, int wi)
369 {
370 double sum =double(pos.stat +pos.name +pos.date +pos.size +pos.ext)/wi;
371 setlw(list, ((double) pos.stat)/sum);
372 setlw(list, ((double) pos.name)/sum);
373 setlw(list, ((double) pos.date)/sum);
374 setlw(list, ((double) pos.size)/sum);
375 setlw(list, ((double) pos.ext)/sum);
376 }
377 */
378 void AddListDrive(HWND hList, char *szfname, char *fnameback, LVITEM &li, int &iItemNo)
379 {
380 char c='a';
381 while(1)
382 {
383 wsprintf(szfname, "%c:\\",c);
384 SetCurrentDirectory(szfname);
385 GetCurrentDirectory(MAX_PATH, szfname);
386 if((toupper(szfname[0])==toupper(c)) && (toupper(fnameback[0])!=toupper(c)))
387 {
388 li.iSubItem = pos.name;
389 li.pszText =szfname;
390
391 // if (iconf)
392 li.iImage = DRIVE_IMAGE;
393 li.mask = topmask;
394 li.iItem = iItemNo;
395 li.lParam = iItemNo;
396 ListView_InsertItem(hList, &li);
397
398 li.iSubItem = pos.size;
399 li.mask = LVIF_TEXT;
400 strcpy(li.pszText, dirmark);
401 ListView_SetItem(hList, &li);
402
403 }
404 if(c>'z') break;
405 c++;
406 }
407 }
408
409 extern menuMouse menuMg;
410 extern HMENU hMainMenu, hMenuMenu, hTestMenu;
411
412 // ƒ}ƒEƒXƒWƒFƒXƒ`ƒƒEƒŠƒXƒg “ǂݍž‚Ý–{‘Ě
413
414
415 int SetMyMouseGestureList(HWND hWnd, dirw &dir, HWND hDirEdit, HIMAGELIST hImage)
416 {
417 menuMg.init(hMainMenu,hMenuMenu, hTestMenu);
418 SetWindowText(hDirEdit, dir.cd());
419 HWND hList =dir.getList();
420
421 return menuMg.addlist( hList);
422 }
423
424
425 void insertmain(HWND hList, char *szfname, LVITEM &li, int &i)
426 {
427 li.iSubItem = pos.name;
428 li.pszText =szfname;
429
430 // if (iconf)
431 li.iImage = DRIVE_IMAGE;
432 li.mask = topmask;
433 li.iItem = i;
434 li.lParam = i;
435 ListView_InsertItem(hList, &li);
436
437 li.iSubItem = pos.size;
438 li.mask = LVIF_TEXT;
439 strcpy(li.pszText, dirmark);
440 ListView_SetItem(hList, &li);
441 i++;
442 }
443
444 // ƒƒCƒ“EƒŠƒXƒgiƒ‹[ƒg‚Š‚çă‚ÉˆÚ“Ž‚Ĺj “ǂݍž‚Ý–{‘Ě
445
446 int SetMyMainList(HWND hWnd, dirw &dir, HWND hDirEdit, HIMAGELIST hImage)
447 {
448 SetWindowText(hDirEdit, dir.cd());
449 char szfname[MAX_PATH], item[MAX_PATH];
450 char ext[MAX_PATH]=defExtPaint;
451 BOOL dirf =FALSE;
452 HWND hList =dir.getList();
453 LVITEM li;
454 char *p;
455 int i;
456 HANDLE fi;
457 WIN32_FIND_DATA wfd;
458
459 i=0;
460 wsprintf(szfname, "mouse:");
461 insertmain(hList, szfname, li, i);
462 wsprintf(szfname, "his:L");
463 insertmain(hList, szfname, li, i);
464 wsprintf(szfname, "his:R");
465 insertmain(hList, szfname, li, i);
466
467 AddListDrive( hList, szfname, item, li, i);
468 return i;
469 }
470
471 // ƒNƒŠƒbƒvEƒŠƒXƒg “ǂݍž‚Ý–{‘Ě
472
473 int SetMyClipList(HWND hWnd, dirw &dir, HWND hDirEdit, HIMAGELIST hImage)
474 {
475 SetWindowText(hDirEdit, dir.cd());
476 char szfname[MAX_PATH], item[MAX_PATH];
477 char ext[MAX_PATH]=defExtPaint;
478 BOOL dirf =FALSE;
479 HWND hList =dir.getList();
480 LVITEM li;
481 char *p;
482 int i;
483 HANDLE fi;
484 WIN32_FIND_DATA wfd;
485
486 for(i=0; i<dir.getClipMax(); i++) {
487 int ino =i;
488 wsprintf(item,"%s", dir.getClip(i+1));
489 if (strlen(item)==0) continue;
490 fi =getHandle(item);
491 fi = FindFirstFile(dir.getClip(i+1), &wfd);
492 AddListItem( hList, fi, szfname, wfd, li, ino, item);
493 FindClose(fi);
494 }
495 return i;
496 }
497
498 // ƒtƒ@ƒCƒ‹ƒŠƒXƒg “ǂݍž‚Ý–{‘Ě, ƒtƒBƒ‹ƒ^[‚Ífilefilter‚Őݒč
499
500 int SetMyLocalDir(HWND hWnd, dirw &dir, HIMAGELIST hImage)
501 {
502 char szfname[MAX_PATH + 5],szfnameback[MAX_PATH + 5];
503 WIN32_FIND_DATA wfd;
504 HWND hList =dir.getList();
505 HWND hDirEdit =dir.getEdit();
506 HANDLE hFind;
507 int iItemNo = 0;
508 LVITEM li;
509 BOOL rootflag=FALSE;
510
511 ListView_DeleteAllItems(hList);
512 // main “ǂݍž‚Ý
513 if( dir.ismain() )
514 {
515 return SetMyMainList(hWnd, dir, hDirEdit, hImage);
516 }
517 // clip, —š—đ “ǂݍž‚Ý
518 if( dir.isclip() || dir.ishis() )
519 {
520 return SetMyClipList(hWnd, dir, hDirEdit, hImage);
521 }
522 // ƒ}ƒEƒXƒWƒFƒXƒ`ƒƒÝ’č@“ǂݍž‚Ý
523 if( dir.ismouse() )
524 {
525 return SetMyMouseGestureList(hWnd, dir, hDirEdit, hImage);
526 }
527 SetCurrentDirectory( dir.cd() );
528 GetCurrentDirectory(MAX_PATH, szfname);
529 SetWindowText(hDirEdit, szfname);
530 // Mes(szfname);
531 strcpy(szfnameback,szfname);
532 if(strlen(szfname)<4) rootflag=TRUE;//ƒ‹[ƒg‚Šƒ`ƒFƒbƒN@Žč”˛‚Ť
533
534 hFind = FindFirstFile(filefilter, &wfd);
535 if (hFind == INVALID_HANDLE_VALUE) {
536 setstatus("ŒŠ‚Â‚Š‚č‚Ü‚š‚ń");
537 FindClose(hFind);
538 return 0;
539 } else {
540 AddListItem( hList, hFind, szfname, wfd, li, iItemNo);
541 }
542
543 while (FindNextFile(hFind, &wfd)) {
544 AddListItem( hList, hFind, szfname, wfd, li, iItemNo);
545 }
546 FindClose(hFind);
547
548 //ƒhƒ‰ƒCƒu•\ŽŚAŽč”˛‚Ťia-z‚ž‚݁j
549 if(rootflag)
550 {
551 AddListDrive( hList, szfname, szfnameback, li, iItemNo);
552 SetCurrentDirectory(szfnameback);//Œł‚ĚˆĘ’u‚É–ß‚ˇ
553 }
554
555 localitemnum=iItemNo;
556 return iItemNo;
557 }
558
559

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision
svn:mime-type text/plain

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26