source: trunk/dll/attribs.c@ 1570

Last change on this file since 1570 was 1498, checked in by Gregg Young, 16 years ago

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: attribs.c 1498 2010-01-18 00:57:01Z gyoung $
5
6 attributes editor
7
8 Copyright (c) 1993, 1998 M. Kimes
9 Copyright (c) 2006, 2010 Steven H.Levine
10
11 14 Jul 06 SHL Use Runtime_Error
12 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
13 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
14 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
15
16***********************************************************************/
17
18#include <ctype.h>
19#include <time.h>
20
21#define INCL_DOS
22#define INCL_WIN
23
24#include "fm3dll.h"
25#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
26#include "notebook.h" // Data declaration(s)
27#include "info.h" // Data declaration(s)
28#include "init.h" // Data declaration(s)
29#include "fm3dlg.h"
30#include "fm3str.h"
31#include "makelist.h" // LISTINFO
32#include "errutil.h" // Runtime_Error
33#include "strutil.h" // GetPString
34#include "defview.h" // QuickView
35#include "attribs.h"
36#include "misc.h" // PaintRecessedWindow
37#include "wrappers.h" // xDosSetPathInfo
38
39static PSZ pszSrcFile = __FILE__;
40
41MRESULT EXPENTRY AttrListDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
42{
43 LISTINFO *li;
44
45 switch (msg) {
46 case WM_INITDLG:
47 if (!mp2)
48 WinDismissDlg(hwnd, 0);
49 else {
50 WinSetWindowPtr(hwnd, QWL_USER, mp2);
51 li = (LISTINFO *) mp2;
52 if (!li->list || !li->list[0]) {
53 WinSendMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
54 break;
55 }
56 }
57 WinSendDlgItemMsg(hwnd, ATR_YEAR, SPBM_SETTEXTLIMIT, MPFROMSHORT(4L),
58 MPVOID);
59 WinSendDlgItemMsg(hwnd, ATR_MONTH, SPBM_SETTEXTLIMIT, MPFROMSHORT(2L),
60 MPVOID);
61 WinSendDlgItemMsg(hwnd, ATR_DAY, SPBM_SETTEXTLIMIT, MPFROMSHORT(2L),
62 MPVOID);
63 WinSendDlgItemMsg(hwnd, ATR_HOUR, SPBM_SETTEXTLIMIT, MPFROMSHORT(2L),
64 MPVOID);
65 WinSendDlgItemMsg(hwnd, ATR_MINUTES, SPBM_SETTEXTLIMIT, MPFROMSHORT(2L),
66 MPVOID);
67 WinSendDlgItemMsg(hwnd, ATR_SECONDS, SPBM_SETTEXTLIMIT, MPFROMSHORT(2L),
68 MPVOID);
69 WinSendDlgItemMsg(hwnd, ATR_YEAR, SPBM_OVERRIDESETLIMITS,
70 MPFROMLONG(2200L), MPFROMLONG(1980L));
71 WinSendDlgItemMsg(hwnd, ATR_MONTH, SPBM_OVERRIDESETLIMITS,
72 MPFROMLONG(12L), MPFROMLONG(1L));
73 WinSendDlgItemMsg(hwnd, ATR_DAY, SPBM_OVERRIDESETLIMITS, MPFROMLONG(31L),
74 MPFROMLONG(1L));
75 WinSendDlgItemMsg(hwnd, ATR_HOUR, SPBM_OVERRIDESETLIMITS, MPFROMLONG(23L),
76 MPFROMLONG(0L));
77 WinSendDlgItemMsg(hwnd, ATR_MINUTES, SPBM_OVERRIDESETLIMITS,
78 MPFROMLONG(59L), MPFROMLONG(0L));
79 WinSendDlgItemMsg(hwnd, ATR_SECONDS, SPBM_OVERRIDESETLIMITS,
80 MPFROMLONG(59L), MPFROMLONG(0L));
81 WinCheckButton(hwnd, ATR_USEDATETIME, FALSE);
82 {
83 INT x;
84
85 for (x = 0; li->list[x]; x++) {
86 WinSendDlgItemMsg(hwnd, ATR_LISTBOX, LM_INSERTITEM,
87 MPFROM2SHORT(LIT_END, 0), MPFROMP(li->list[x]));
88 WinSendDlgItemMsg(hwnd, ATR_LISTBOX, LM_SELECTITEM,
89 MPFROM2SHORT(x, 0), MPFROMSHORT(TRUE));
90 }
91 }
92 PostMsg(hwnd, UM_UNDO, MPFROMLONG(((!li->list[1]) ? 1L : 0L)), MPVOID);
93 if (li->list[1])
94 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(ATR_NOW, 0), MPVOID);
95 break;
96
97 case UM_UNDO:
98 {
99 FILESTATUS3 fi;
100 long ro = 2, hi = 2, sy = 2, ar = 2;
101 BOOL allgrey;
102
103 allgrey = ((long)WinQueryButtonCheckstate(hwnd, ATR_READONLY) == 2 &&
104 (long)WinQueryButtonCheckstate(hwnd, ATR_SYSTEM) == 2 &&
105 (long)WinQueryButtonCheckstate(hwnd, ATR_HIDDEN) == 2 &&
106 (long)WinQueryButtonCheckstate(hwnd, ATR_ARCHIVED) == 2);
107 li = INSTDATA(hwnd);
108 if (li && li->list[0] && (allgrey || mp1) &&
109 !DosQueryPathInfo(li->list[0], FIL_STANDARD, &fi,
110 (ULONG) sizeof(fi))) {
111 ro = ((fi.attrFile & FILE_READONLY) != 0);
112 hi = ((fi.attrFile & FILE_HIDDEN) != 0);
113 sy = ((fi.attrFile & FILE_SYSTEM) != 0);
114 ar = ((fi.attrFile & FILE_ARCHIVED) != 0);
115 WinSendDlgItemMsg(hwnd, ATR_YEAR, SPBM_SETCURRENTVALUE,
116 MPFROMSHORT(fi.fdateLastWrite.year + 1980), MPVOID);
117 WinSendDlgItemMsg(hwnd, ATR_MONTH, SPBM_SETCURRENTVALUE,
118 MPFROMSHORT(fi.fdateLastWrite.month), MPVOID);
119 WinSendDlgItemMsg(hwnd, ATR_DAY, SPBM_SETCURRENTVALUE,
120 MPFROMSHORT(fi.fdateLastWrite.day), MPVOID);
121 WinSendDlgItemMsg(hwnd, ATR_HOUR, SPBM_SETCURRENTVALUE,
122 MPFROMSHORT(fi.ftimeLastWrite.hours), MPVOID);
123 WinSendDlgItemMsg(hwnd, ATR_MINUTES, SPBM_SETCURRENTVALUE,
124 MPFROMSHORT(fi.ftimeLastWrite.minutes), MPVOID);
125 WinSendDlgItemMsg(hwnd, ATR_SECONDS, SPBM_SETCURRENTVALUE,
126 MPFROMSHORT(fi.ftimeLastWrite.twosecs * 2), MPVOID);
127 }
128 WinCheckButton(hwnd, ATR_READONLY, ro);
129 WinCheckButton(hwnd, ATR_HIDDEN, hi);
130 WinCheckButton(hwnd, ATR_SYSTEM, sy);
131 WinCheckButton(hwnd, ATR_ARCHIVED, ar);
132 PostMsg(hwnd, UM_CONTROL, MPFROM2SHORT(ATR_READONLY, BN_CLICKED),
133 MPVOID);
134 PostMsg(hwnd, UM_CONTROL, MPFROM2SHORT(ATR_HIDDEN, BN_CLICKED), MPVOID);
135 PostMsg(hwnd, UM_CONTROL, MPFROM2SHORT(ATR_SYSTEM, BN_CLICKED), MPVOID);
136 PostMsg(hwnd, UM_CONTROL, MPFROM2SHORT(ATR_ARCHIVED, BN_CLICKED),
137 MPVOID);
138 }
139 return 0;
140
141 case WM_ADJUSTWINDOWPOS:
142 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
143 break;
144
145 case UM_SETDIR:
146 PaintRecessedWindow(WinWindowFromID(hwnd, ATR_HELP), (HPS) 0, FALSE,
147 TRUE);
148 return 0;
149
150 case WM_CONTROL:
151 switch (SHORT1FROMMP(mp1)) {
152 case ATR_LISTBOX:
153 if (SHORT2FROMMP(mp1) == LN_ENTER) {
154
155 SHORT x;
156 CHAR szBuffer[CCHMAXPATH];
157
158 x = (SHORT) WinSendDlgItemMsg(hwnd, ATR_LISTBOX, LM_QUERYSELECTION,
159 MPFROMSHORT(LIT_FIRST), MPVOID);
160 if (x >= 0) {
161 *szBuffer = 0;
162 WinSendDlgItemMsg(hwnd, ATR_LISTBOX, LM_QUERYITEMTEXT,
163 MPFROM2SHORT(x, CCHMAXPATH), MPFROMP(szBuffer));
164 if (*szBuffer)
165 QuickView(hwnd, szBuffer);
166 }
167 }
168 else if (SHORT2FROMMP(mp1) == LN_KILLFOCUS)
169 WinSetDlgItemText(hwnd, ATR_HELP, NullStr);
170 else if (SHORT2FROMMP(mp1) == LN_SETFOCUS)
171 WinSetDlgItemText(hwnd, ATR_HELP,
172 (CHAR *) GetPString(IDS_ATTRLISTBOXHELPTEXT));
173 break;
174 case ATR_YEAR:
175 if (SHORT2FROMMP(mp1) == SPBN_KILLFOCUS)
176 WinSetDlgItemText(hwnd, ATR_HELP, NullStr);
177 if (SHORT2FROMMP(mp1) == SPBN_SETFOCUS)
178 WinSetDlgItemText(hwnd, ATR_HELP, (CHAR *) GetPString(IDS_ATTRYEARHELPTEXT));
179 break;
180 case ATR_MONTH:
181 if (SHORT2FROMMP(mp1) == SPBN_KILLFOCUS)
182 WinSetDlgItemText(hwnd, ATR_HELP, NullStr);
183 if (SHORT2FROMMP(mp1) == SPBN_SETFOCUS)
184 WinSetDlgItemText(hwnd, ATR_HELP, (CHAR *) GetPString(IDS_ATTRMONTHHELPTEXT));
185 break;
186 case ATR_DAY:
187 if (SHORT2FROMMP(mp1) == SPBN_KILLFOCUS)
188 WinSetDlgItemText(hwnd, ATR_HELP, NullStr);
189 if (SHORT2FROMMP(mp1) == SPBN_SETFOCUS)
190 WinSetDlgItemText(hwnd, ATR_HELP, (CHAR *) GetPString(IDS_ATTRDAYHELPTEXT));
191 break;
192 case ATR_HOUR:
193 if (SHORT2FROMMP(mp1) == SPBN_KILLFOCUS)
194 WinSetDlgItemText(hwnd, ATR_HELP, NullStr);
195 if (SHORT2FROMMP(mp1) == SPBN_SETFOCUS)
196 WinSetDlgItemText(hwnd, ATR_HELP, (CHAR *) GetPString(IDS_ATTRHOURHELPTEXT));
197 break;
198 case ATR_MINUTES:
199 if (SHORT2FROMMP(mp1) == SPBN_KILLFOCUS)
200 WinSetDlgItemText(hwnd, ATR_HELP, NullStr);
201 if (SHORT2FROMMP(mp1) == SPBN_SETFOCUS)
202 WinSetDlgItemText(hwnd, ATR_HELP, (CHAR *) GetPString(IDS_ATTRMINHELPTEXT));
203 break;
204 case ATR_SECONDS:
205 if (SHORT2FROMMP(mp1) == SPBN_KILLFOCUS)
206 WinSetDlgItemText(hwnd, ATR_HELP, NullStr);
207 if (SHORT2FROMMP(mp1) == SPBN_SETFOCUS)
208 WinSetDlgItemText(hwnd, ATR_HELP, (CHAR *) GetPString(IDS_ATTRSECHELPTEXT));
209 break;
210 case ATR_READONLY:
211 case ATR_SYSTEM:
212 case ATR_HIDDEN:
213 case ATR_ARCHIVED:
214 WinSendMsg(hwnd, UM_CONTROL, mp1, mp2);
215 break;
216 }
217 return 0;
218
219 case UM_CONTROL:
220 switch (SHORT1FROMMP(mp1)) {
221 case ATR_READONLY:
222 case ATR_SYSTEM:
223 case ATR_HIDDEN:
224 case ATR_ARCHIVED:
225 {
226
227 LONG check = WinQueryButtonCheckstate(hwnd, SHORT1FROMMP(mp1));
228 CHAR s[80];
229
230 sprintf(s, "%s %s",
231 (SHORT1FROMMP(mp1) == ATR_READONLY) ?
232 GetPString(IDS_ATTRREADONLYBTEXT) :
233 (SHORT1FROMMP(mp1) == ATR_SYSTEM) ?
234 GetPString(IDS_ATTRSYSTEMBTEXT) :
235 (SHORT1FROMMP(mp1) == ATR_HIDDEN) ?
236 GetPString(IDS_ATTRHIDDENBTEXT) :
237 GetPString(IDS_ATTRARCHIVEDBTEXT),
238 (check == 1) ?
239 GetPString(IDS_ONTEXT) :
240 (check == 0) ?
241 GetPString(IDS_OFFTEXT) : GetPString(IDS_UNCHANGEDTEXT));
242 WinSetDlgItemText(hwnd, SHORT1FROMMP(mp1), s);
243 }
244 break;
245 }
246 return 0;
247
248 case WM_COMMAND:
249 switch (SHORT1FROMMP(mp1)) {
250 case ATR_LEAVEALL:
251 PostMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
252 break;
253
254 case ATR_NOW:
255 {
256 time_t t;
257 struct tm *tm;
258
259 t = time(NULL);
260 tm = localtime(&t);
261 WinSendDlgItemMsg(hwnd, ATR_YEAR, SPBM_SETCURRENTVALUE,
262 MPFROMSHORT(tm->tm_year + 1900), MPVOID);
263 WinSendDlgItemMsg(hwnd, ATR_MONTH, SPBM_SETCURRENTVALUE,
264 MPFROMSHORT(tm->tm_mon + 1), MPVOID);
265 WinSendDlgItemMsg(hwnd, ATR_DAY, SPBM_SETCURRENTVALUE,
266 MPFROMSHORT(tm->tm_mday), MPVOID);
267 WinSendDlgItemMsg(hwnd, ATR_HOUR, SPBM_SETCURRENTVALUE,
268 MPFROMSHORT(tm->tm_hour), MPVOID);
269 WinSendDlgItemMsg(hwnd, ATR_MINUTES, SPBM_SETCURRENTVALUE,
270 MPFROMSHORT(tm->tm_min), MPVOID);
271 WinSendDlgItemMsg(hwnd, ATR_SECONDS, SPBM_SETCURRENTVALUE,
272 MPFROMSHORT(tm->tm_sec), MPVOID);
273 }
274 break;
275
276 case DID_OK:
277 if (!WinQueryButtonCheckstate(hwnd, ATR_USEDATETIME) &&
278 WinQueryButtonCheckstate(hwnd, ATR_HIDDEN) == 2 &&
279 WinQueryButtonCheckstate(hwnd, ATR_SYSTEM) == 2 &&
280 WinQueryButtonCheckstate(hwnd, ATR_READONLY) == 2 &&
281 WinQueryButtonCheckstate(hwnd, ATR_ARCHIVED) == 2) {
282 saymsg(MB_ENTER,
283 hwnd,
284 GetPString(IDS_UHYOTEXT), GetPString(IDS_ATTRADVANTAGETEXT));
285 break;
286 }
287 {
288 ULONG temp = 0;
289 FILESTATUS3 fi;
290 SHORT x;
291 APIRET rc;
292 USHORT state;
293
294 li = INSTDATA(hwnd);
295 if (!li) {
296 Runtime_Error(pszSrcFile, __LINE__, NULL);
297 break;
298 }
299 {
300 CHAR szBuffer[CCHMAXPATH + 1];
301 UINT numfiles = 0, numalloc = 0;
302 INT error;
303
304 if (li->list)
305 FreeList(li->list);
306 li->list = NULL;
307 x = (SHORT) WinSendDlgItemMsg(hwnd, ATR_LISTBOX, LM_QUERYSELECTION,
308 MPFROMSHORT(LIT_FIRST), MPVOID);
309 if (x >= 0) {
310 do {
311 *szBuffer = 0;
312 WinSendDlgItemMsg(hwnd, ATR_LISTBOX, LM_QUERYITEMTEXT,
313 MPFROM2SHORT(x, CCHMAXPATH),
314 MPFROMP(szBuffer));
315 if (*szBuffer && isalpha(*szBuffer) &&
316 !(driveflags[toupper(*szBuffer) - 'A'] &
317 DRIVE_NOTWRITEABLE)) {
318 error = AddToList(szBuffer, &li->list, &numfiles, &numalloc);
319 if (error) {
320 Runtime_Error(pszSrcFile, __LINE__, "AddToList");
321 break;
322 }
323 }
324 x = (SHORT) WinSendDlgItemMsg(hwnd, ATR_LISTBOX,
325 LM_QUERYSELECTION,
326 MPFROMSHORT(x), MPVOID);
327 } while (x >= 0);
328 }
329 }
330 if (!li->list || !li->list[0]) {
331 Runtime_Error(pszSrcFile, __LINE__, "list build failed");
332 break;
333 }
334 for (x = 0; li->list[x]; x++) {
335 DosError(FERR_DISABLEHARDERR);
336 rc = DosQueryPathInfo(li->list[x], FIL_STANDARD, &fi,
337 (ULONG) sizeof(fi));
338 if (rc)
339 continue;
340 if (WinQueryButtonCheckstate(hwnd, ATR_USEDATETIME)) {
341 WinSendDlgItemMsg(hwnd, ATR_YEAR, SPBM_QUERYVALUE, MPFROMP(&temp),
342 MPFROM2SHORT(0, SPBQ_DONOTUPDATE));
343 fi.fdateLastWrite.year = temp - 1980;
344 WinSendDlgItemMsg(hwnd, ATR_MONTH, SPBM_QUERYVALUE,
345 MPFROMP(&temp), MPFROM2SHORT(0,
346 SPBQ_DONOTUPDATE));
347 fi.fdateLastWrite.month = temp;
348 WinSendDlgItemMsg(hwnd, ATR_DAY, SPBM_QUERYVALUE, MPFROMP(&temp),
349 MPFROM2SHORT(0, SPBQ_DONOTUPDATE));
350 fi.fdateLastWrite.day = temp;
351 WinSendDlgItemMsg(hwnd, ATR_HOUR, SPBM_QUERYVALUE, MPFROMP(&temp),
352 MPFROM2SHORT(0, SPBQ_DONOTUPDATE));
353 fi.ftimeLastWrite.hours = temp;
354 WinSendDlgItemMsg(hwnd, ATR_MINUTES, SPBM_QUERYVALUE,
355 MPFROMP(&temp), MPFROM2SHORT(0,
356 SPBQ_DONOTUPDATE));
357 fi.ftimeLastWrite.minutes = temp;
358 WinSendDlgItemMsg(hwnd, ATR_SECONDS, SPBM_QUERYVALUE,
359 MPFROMP(&temp), MPFROM2SHORT(0,
360 SPBQ_DONOTUPDATE));
361 fi.ftimeLastWrite.twosecs = (temp / 2L);
362 }
363 fi.attrFile &= (~FILE_DIRECTORY);
364 state = (USHORT) WinSendDlgItemMsg(hwnd, ATR_READONLY,
365 BM_QUERYCHECK, MPVOID, MPVOID);
366 if (!state)
367 fi.attrFile &= (~FILE_READONLY);
368 else if (state == 1)
369 fi.attrFile |= FILE_READONLY;
370 state = (USHORT) WinSendDlgItemMsg(hwnd, ATR_HIDDEN, BM_QUERYCHECK,
371 MPVOID, MPVOID);
372 if (!state)
373 fi.attrFile &= (~FILE_HIDDEN);
374 else if (state == 1)
375 fi.attrFile |= FILE_HIDDEN;
376 state = (USHORT) WinSendDlgItemMsg(hwnd, ATR_SYSTEM, BM_QUERYCHECK,
377 MPVOID, MPVOID);
378 if (!state)
379 fi.attrFile &= (~FILE_SYSTEM);
380 else if (state == 1)
381 fi.attrFile |= FILE_SYSTEM;
382 state = (USHORT) WinSendDlgItemMsg(hwnd, ATR_ARCHIVED,
383 BM_QUERYCHECK, MPVOID, MPVOID);
384 if (!state)
385 fi.attrFile &= (~FILE_ARCHIVED);
386 else if (state == 1)
387 fi.attrFile |= FILE_ARCHIVED;
388 xDosSetPathInfo(li->list[x], FIL_STANDARD, &fi, sizeof(fi), 0);
389 }
390 WinDismissDlg(hwnd, 1);
391 }
392 break;
393
394 case IDM_HELP:
395 if (hwndHelp)
396 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
397 MPFROM2SHORT(HELP_ATTRIBSLIST, 0),
398 MPFROMSHORT(HM_RESOURCEID));
399 break;
400
401 case DID_CANCEL:
402 WinDismissDlg(hwnd, 0);
403 break;
404 }
405 return 0;
406 }
407 return WinDefDlgProc(hwnd, msg, mp1, mp2);
408}
409
410#pragma alloc_text(ATTRIBS,AttrListDlgProc)
Note: See TracBrowser for help on using the repository browser.