feeb090df45b58e5127b67c9dab3896a5422a585
[reactos.git] / rosapps / winfile / drivebar.c
1 /*
2 * ReactOS winfile
3 *
4 * drivebar.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include "main.h"
38 #include "settings.h"
39 #include "framewnd.h"
40 #include "childwnd.h"
41
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // Global Variables:
45 //
46
47 void ConfigureDriveBar(HWND hDriveBar)
48 {
49 static DWORD dwLogicalDrivesSaved;
50 DWORD dwLogicalDrives = GetLogicalDrives();
51
52 if (!hDriveBar) return;
53
54 if (dwLogicalDrives != dwLogicalDrivesSaved) {
55 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP};
56 int btn = 1;
57 PTSTR p;
58 int count = SendMessage(hDriveBar, TB_BUTTONCOUNT, 0, 0);
59 while (count) {
60 SendMessage(hDriveBar, TB_DELETEBUTTON, (WPARAM)--count, 0);
61 }
62 count = SendMessage(Globals.hDriveCombo, CB_GETCOUNT, 0, 0);
63 while (count) {
64 // SendMessage(Globals.hDriveCombo, CB_DELETESTRING, (WPARAM)--count, 0);
65 }
66 SendMessage(Globals.hDriveCombo, CB_RESETCONTENT, 0, 0);
67
68 memset(Globals.drives, 0, BUFFER_LEN);
69 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
70 drivebarBtn.fsStyle = TBSTYLE_BUTTON;
71 drivebarBtn.idCommand = ID_DRIVE_FIRST;
72 for (p = Globals.drives; *p;) {
73 // insert drive letter
74 TCHAR b[3] = { tolower(*p) };
75 SendMessage(hDriveBar, TB_ADDSTRING, 0, (LPARAM)b);
76 switch(GetDriveType(p)) {
77 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
78 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
79 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
80 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
81 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
82 }
83 SendMessage(hDriveBar, TB_INSERTBUTTON, btn, (LPARAM)&drivebarBtn);
84 drivebarBtn.idCommand++;
85 drivebarBtn.iString++;
86 while(*p++);
87 //
88 // SendMessage(Globals.hDriveCombo, CB_INSERTSTRING, btn, (LPARAM)b);
89 // SendMessage(Globals.hDriveCombo, CB_ADDSTRING, 0, (LPARAM)b);
90 // SendMessage(Globals.hDriveCombo, WM_SETTEXT, 0, (LPARAM)lpszWord);
91 // SendMessage(Globals.hDriveCombo, CB_ADDSTRING, 0, (LPARAM)&b);
92 //
93 ++btn;
94 }
95 dwLogicalDrivesSaved = dwLogicalDrives;
96
97 // SendMessage(Globals.hDriveCombo, CB_SHOWDROPDOWN, (WPARAM)TRUE, (LPARAM)0);
98 }
99 #ifndef __GNUC__
100
101 {
102 COMBOBOXEXITEM cbei;
103 int iCnt;
104
105 typedef struct {
106 int iImage;
107 int iSelectedImage;
108 int iIndent;
109 LPTSTR pszText;
110 } ITEMINFO, *PITEMINFO;
111
112 #define MAX_ITEMS 15
113
114 ITEMINFO IInf[] = {
115 { 0, 3, 0, _T("first")},
116 { 1, 4, 1, _T("second")},
117 { 2, 5, 2, _T("third")},
118 { 0, 3, 0, _T("fourth")},
119 { 1, 4, 1, _T("fifth")},
120 { 2, 5, 2, _T("sixth")},
121 { 0, 3, 0, _T("seventh")},
122 { 1, 4, 1, _T("eighth")},
123 { 2, 5, 2, _T("ninth")},
124 { 0, 3, 0, _T("tenth")},
125 { 1, 4, 1, _T("eleventh")},
126 { 2, 5, 2, _T("twelfth")},
127 { 0, 3, 0, _T("thirteenth")},
128 { 1, 4, 1, _T("fourteenth")},
129 { 2, 5, 2, _T("fifteenth")}
130 };
131
132 for (iCnt = 0; iCnt < MAX_ITEMS; iCnt++) {
133
134 cbei.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_IMAGE| CBEIF_SELECTEDIMAGE;
135 cbei.iItem = iCnt;
136 cbei.pszText = IInf[iCnt].pszText;
137 cbei.cchTextMax = sizeof(IInf[iCnt].pszText);
138 cbei.iImage = IInf[iCnt].iImage;
139 cbei.iSelectedImage = IInf[iCnt].iSelectedImage;
140 cbei.iIndent = IInf[iCnt].iIndent;
141 }
142
143
144 SendMessage(Globals.hDriveCombo, CBEM_INSERTITEM, 0, (LPARAM)&cbei);
145 }
146 #endif
147 }
148
149 void _GetFreeSpaceEx(void)
150 {
151 BOOL fResult;
152 TCHAR szDrive[MAX_PATH];
153 ULARGE_INTEGER i64FreeBytesToCaller;
154 ULARGE_INTEGER i64TotalBytes;
155 ULARGE_INTEGER i64FreeBytes;
156
157 fResult = GetDiskFreeSpaceEx(szDrive,
158 (PULARGE_INTEGER)&i64FreeBytesToCaller,
159 (PULARGE_INTEGER)&i64TotalBytes,
160 (PULARGE_INTEGER)&i64FreeBytes);
161 }
162