1 /* Ch-Drive command for OS/2 operating system
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #error This file is for the OS/2 operating systems.
24 #define INCL_DOSDEVICES /* Device values */
25 #define INCL_DOSERRORS /* Error values */
37 #include "dialog.h" /* For do_refresh() */
40 #include "panel.h" /* Needed for the externs */
45 struct Dlg_head
*drive_dlg
;
48 static int drive_dlg_callback (Dlg_head
*h
, int Par
, int Msg
);
49 static void drive_dlg_refresh (void);
50 static void drive_cmd();
52 #define B_DRIVE_BASE 100
54 void drive_cmd_a(WPanel
*p
)
56 this_panel
= left_panel
;
57 /* .ado: Drive change can only be done within view_listing */
58 if (p
== this_panel
) {
59 if (get_current_type() != view_listing
) {
63 if (get_other_type() != view_listing
) {
71 void drive_cmd_b(WPanel
*p
)
73 this_panel
= right_panel
;
74 /* .ado: Drive change can only be done within view_listing */
75 if (p
== this_panel
) {
76 if (get_current_type() != view_listing
) {
80 if (get_other_type() != view_listing
) {
88 void drive_chg(WPanel
*panel
)
96 static void drive_cmd()
100 int nDrivesAvail
= 0; /* Available drives */
101 int nNewDrive
; /* New drive */
103 ULONG uDriveNum
= 0; /* Drive number (A=1, B=2 ...) */
104 ULONG uDriveMap
= 0; /* Mapping */
105 char sDrvs
[26]; /* Char-Mapping */
108 // Dialogbox position
109 int x_pos
; /* X-Position for the dialog */
110 int y_pos
= (LINES
-6)/2-3; /* Center on y */
117 APIRET rc
= NO_ERROR
; /* Return code */
119 memset(sDrvs
, (char) 0, 26);
120 rc
= DosQueryCurrentDisk(&uDriveNum
, &uDriveMap
);
122 if (rc
!= NO_ERROR
) {
123 message(0, " ERROR ", " Internal Error with drive_cmd ");
128 for (i
=0; i
< 26; i
++) {
129 if ( (uDriveMap
<<(31-i
)) >> 31) {
130 sDrvs
[j
++] = (char) ((int) 'A' + i
);
138 m_drv
= ((nDrivesAvail
> MAX_LGH
) ? MAX_LGH
: nDrivesAvail
);
139 x_pos
= this_panel
->widget
.x
+ (this_panel
->widget
.cols
- m_drv
*3)/2 + 2; /* Center on x, relative to panel */
141 if (nDrivesAvail
> MAX_LGH
) {
146 x_width
= (nDrivesAvail
- 1) * 2 + 9;
149 drive_dlg
= create_dlg (y_pos
, x_pos
,
158 x_set_dialog_title (drive_dlg
, "Change Drive");
160 if (nDrivesAvail
>MAX_LGH
) {
161 for (i
= 0; i
< nDrivesAvail
- MAX_LGH
; i
++) {
162 sprintf(szTempBuf
, "%c", sDrvs
[nDrivesAvail
-i
-1]);
163 add_widgetl (drive_dlg
,
164 button_new (5, (m_drv
-i
-1)*2+4 - (MAX_LGH
*2 - nDrivesAvail
) * 2,
165 B_DRIVE_BASE
+((int) szTempBuf
[0] - (int) 'A'),
172 /* Add a button for each drive */
173 for (i
= 0; i
< m_drv
; i
++) {
174 sprintf (szTempBuf
, "%c", sDrvs
[m_drv
-i
-1]);
175 add_widgetl(drive_dlg
,
178 B_DRIVE_BASE
+((int)szTempBuf
[0] - (int) 'A'),
190 if (drive_dlg
->ret_value
!= B_CANCEL
) {
191 nNewDrive
= drive_dlg
->ret_value
- B_DRIVE_BASE
;
192 curDisk
= (char) (nNewDrive
+ (int) 'A');
193 rc
= DosSetDefaultDisk(nNewDrive
+ 1);
194 if (rc
!= NO_ERROR
) {
195 message(1, " Error ", " Invalid Drive %c: \n", curDisk
);
197 getcwd(this_panel
->cwd
, sizeof(this_panel
->cwd
) - 2);
198 // if getcwd returns NULL --> error!
199 // rc = DosQueryCurrentDisk(&uDriveNum, &uDriveMap);
200 if (toupper(curDisk
) == toupper(*(this_panel
->cwd
))) {
201 clean_dir (&this_panel
->dir
, this_panel
->count
);
202 this_panel
->count
= do_load_dir (&this_panel
->dir
,
203 this_panel
->sort_type
,
205 this_panel
->case_sensitive
,
207 this_panel
->top_file
= 0;
208 this_panel
->selected
= 0;
209 this_panel
->marked
= 0;
210 this_panel
->total
= 0;
211 show_dir(this_panel
);
214 // rc = DosSetDefaultDisk(uDriveNum);
217 destroy_dlg (drive_dlg
);
221 static int drive_dlg_callback (Dlg_head
*h
, int Par
, int Msg
)
228 drive_dlg_refresh ();
235 static void drive_dlg_refresh (void)
237 attrset (dialog_colors
[0]);
238 dlg_erase (drive_dlg
);
239 draw_box (drive_dlg
, 1, 1, drive_dlg
->lines
-2, drive_dlg
->cols
-2);
241 attrset (dialog_colors
[2]);
242 dlg_move (drive_dlg
, 1, drive_dlg
->cols
/2 - 7);
243 addstr (" Change Drive ");