End of line fix for gcc 3.x
[reactos.git] / rosapps / cmd / window.c
1 /* $Id: window.c,v 1.4 2002/09/24 03:43:25 sedwards Exp $
2 *
3 * WINDOW.C - activate & window internal commands.
4 *
5 * clone from 4nt activate command
6 *
7 * 10 Sep 1999 (Paolo Pantaleo)
8 * started (window command in WINDOW.c)
9 *
10 * 29 Sep 1999 (Paolo Pantaleo)
11 * activate and window in a single file using mainly the same code
12 * (nice size optimization :)
13 */
14
15
16 #include "config.h"
17
18 #if ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) )
19
20 #include "cmd.h"
21 #include <windows.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <tchar.h>
25
26
27 #define A_MIN 0x01
28 #define A_MAX 0x02
29 #define A_RESTORE 0x04
30 #define A_POS 0x08
31 #define A_SIZE 0x10
32 #define A_CLOSE 0x20
33
34
35 /*service funciton to perform actions on windows
36
37 param is a string to parse for options/actions
38 hWnd is the handle of window on wich perform actions
39
40 */
41
42 static
43 INT ServiceActivate (LPTSTR param, HWND hWnd)
44 {
45 LPTSTR *p=0,p_tmp;
46 INT argc=0,i;
47 INT iAction=0;
48 LPTSTR title=0;
49 WINDOWPLACEMENT wp;
50 RECT pos;
51 LPTSTR tmp;
52
53
54 if(*param)
55 p=split(param,&argc);
56
57
58 for(i = 0; i < argc; i++)
59 {
60 p_tmp=p[i];
61 if (*p_tmp == _T('/'))
62 p_tmp++;
63
64 if (_tcsicmp(p_tmp,_T("min"))==0)
65 {
66 iAction |= A_MIN;
67 continue;
68 }
69
70 if (_tcsicmp(p_tmp,_T("max"))==0)
71 {
72 iAction |= A_MAX;
73 continue;
74 }
75
76 if (_tcsicmp(p_tmp,_T("restore"))==0)
77 {
78 iAction |= A_RESTORE;
79 continue;
80 }
81
82 if (_tcsicmp(p_tmp,_T("close"))==0)
83 {
84 iAction |= A_CLOSE;
85 continue;
86 }
87
88 if (_tcsnicmp(p_tmp,_T("pos"),3)==0)
89 {
90 iAction |= A_POS;
91 tmp = p_tmp+3;
92 if (*tmp == _T('='))
93 tmp++;
94
95 pos.left= _ttoi(tmp);
96 if(!(tmp=_tcschr(tmp,_T(','))))
97 {
98 error_invalid_parameter_format(p[i]);
99 freep(p);
100 return 1;
101 }
102
103 pos.top = _ttoi (++tmp);
104 if(!(tmp=_tcschr(tmp,_T(','))))
105 {
106 error_invalid_parameter_format(p[i]);
107 freep(p);
108 return 1;
109 }
110
111 pos.right = _ttoi(++tmp)+pos.left;
112 if(!(tmp=_tcschr(tmp,_T(','))))
113 {
114 error_invalid_parameter_format(p[i]);
115 freep(p);
116 return 1;
117 }
118 pos.bottom = _ttoi(++tmp) + pos.top;
119 continue;
120 }
121
122 if (_tcsnicmp(p_tmp,_T("size"),4)==0)
123 {
124 iAction |=A_SIZE;
125 continue;
126 }
127
128 /*none of them=window title*/
129 if (title)
130 {
131 error_invalid_parameter_format(p[i]);
132 freep(p);
133 return 1;
134 }
135
136 if (p_tmp[0] == _T('"'))
137 {
138 title = (p_tmp+1);
139 *_tcschr(p_tmp+1,_T('"'))=0;
140 continue;
141 }
142 title = p_tmp;
143 }
144
145 if(title)
146 SetWindowText(hWnd,title);
147
148 wp.length=sizeof(WINDOWPLACEMENT);
149 GetWindowPlacement(hWnd,&wp);
150
151 if(iAction & A_POS)
152 wp.rcNormalPosition = pos;
153
154 if(iAction & A_MIN)
155 wp.showCmd=SW_MINIMIZE;
156
157 if(iAction & A_MAX)
158 wp.showCmd=SW_SHOWMAXIMIZED;
159
160 /*if no actions are specified default is SW_RESTORE*/
161 if( (iAction & A_RESTORE) || (!iAction) )
162 wp.showCmd=SW_RESTORE;
163
164 if(iAction & A_CLOSE)
165 ConErrPrintf(_T("!!!FIXME: CLOSE Not implemented!!!\n"));
166
167 wp.length=sizeof(WINDOWPLACEMENT);
168 SetWindowPlacement(hWnd,&wp);
169
170 if(p)
171 freep(p);
172
173 return 0;
174 }
175
176
177
178
179 INT CommandWindow (LPTSTR cmd, LPTSTR param)
180 {
181 HWND h;
182
183 if (_tcsncmp (param, _T("/?"), 2) == 0)
184 {
185 ConOutPuts(_T("change console window aspect\n"
186 "\n"
187 "WINDOW [/POS[=]left,top,width,heigth]\n"
188 " [MIN|MAX|RESTORE] [\"title\"]\n"
189 "\n"
190 "/POS specify window placement and dimensions\n"
191 "MIN minimize the window\n"
192 "MAX maximize the window\n"
193 "RESTORE restore the window"));
194 return 0;
195 }
196
197 h = GetConsoleWindow();
198 Sleep(0);
199 return ServiceActivate(param,h);
200 }
201
202
203 INT CommandActivate (LPTSTR cmd, LPTSTR param)
204 {
205 LPTSTR str;
206 HWND h;
207
208 if (_tcsncmp (param, _T("/?"), 2) == 0)
209 {
210 ConOutPuts(_T("change console window aspect\n"
211 "\n"
212 "ACTIAVTE \"window\" [/POS[=]left,top,width,heigth]\n"
213 " [MIN|MAX|RESTORE] [\"title\"]\n"
214 "\n"
215 "window tile of window on wich perform actions\n"
216 "/POS specify window placement and dimensions\n"
217 "MIN minimize the window\n"
218 "MAX maximize the window\n"
219 "RESTORE restore the window\n"
220 "title new title"));
221 return 0;
222 }
223
224 if(!(*param))
225 return 1;
226
227 str=_tcschr(param,_T(' '));
228
229 if (str)
230 {
231 *str=_T('\0');
232 str++;
233 }
234 else
235 str = "";
236
237 h=FindWindow(NULL, param);
238 if (!h)
239 {
240 ConErrPuts("window not found");
241 return 1;
242 }
243
244 return ServiceActivate(str,h);
245 }
246
247 #endif /* ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) ) */