Revert, thx Thomas, wasnt sure.
[reactos.git] / reactos / subsys / system / cmd / window.c
1 /* $Id$
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 * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
15 * Remove all hardcode string to En.rc
16 */
17
18
19 #include <precomp.h>
20 #include "resource.h"
21
22 #if ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) )
23
24
25 #define A_MIN 0x01
26 #define A_MAX 0x02
27 #define A_RESTORE 0x04
28 #define A_POS 0x08
29 #define A_SIZE 0x10
30 #define A_CLOSE 0x20
31
32
33 /*service funciton to perform actions on windows
34
35 param is a string to parse for options/actions
36 hWnd is the handle of window on wich perform actions
37
38 */
39
40 static INT ServiceActivate (LPTSTR param, HWND hWnd)
41 {
42 LPTSTR *p = 0, p_tmp;
43 INT argc = 0, i;
44 INT iAction = 0;
45 LPTSTR title = 0;
46 WINDOWPLACEMENT wp;
47 RECT pos;
48 LPTSTR tmp;
49
50
51 if (*param)
52 p = split(param, &argc, FALSE);
53
54 for (i = 0; i < argc; i++)
55 {
56 p_tmp = p[i];
57 if (*p_tmp == _T('/'))
58 p_tmp++;
59
60 if (_tcsicmp(p_tmp, _T("min")) == 0)
61 {
62 iAction |= A_MIN;
63 continue;
64 }
65
66 if (_tcsicmp(p_tmp, _T("max")) == 0)
67 {
68 iAction |= A_MAX;
69 continue;
70 }
71
72 if (_tcsicmp(p_tmp, _T("restore")) == 0)
73 {
74 iAction |= A_RESTORE;
75 continue;
76 }
77
78 if (_tcsicmp(p_tmp, _T("close")) == 0)
79 {
80 iAction |= A_CLOSE;
81 continue;
82 }
83
84 if (_tcsnicmp(p_tmp, _T("pos"), 3) == 0)
85 {
86 iAction |= A_POS;
87 tmp = p_tmp+3;
88 if (*tmp == _T('='))
89 tmp++;
90
91 pos.left= _ttoi(tmp);
92 if(!(tmp=_tcschr(tmp, _T(','))))
93 {
94 error_invalid_parameter_format(p[i]);
95 freep(p);
96 return 1;
97 }
98
99 pos.top = _ttoi (++tmp);
100 if(!(tmp=_tcschr(tmp, _T(','))))
101 {
102 error_invalid_parameter_format(p[i]);
103 freep(p);
104 return 1;
105 }
106
107 pos.right = _ttoi(++tmp) + pos.left;
108 if (!(tmp = _tcschr(tmp, _T(','))))
109 {
110 error_invalid_parameter_format(p[i]);
111 freep(p);
112 return 1;
113 }
114 pos.bottom = _ttoi(++tmp) + pos.top;
115 continue;
116 }
117
118 if (_tcsnicmp(p_tmp, _T("size"), 4)==0)
119 {
120 iAction |=A_SIZE;
121 continue;
122 }
123
124 /* none of them=window title */
125 if (title)
126 {
127 error_invalid_parameter_format(p[i]);
128 freep(p);
129 return 1;
130 }
131
132 if (p_tmp[0] == _T('"'))
133 {
134 title = (p_tmp + 1);
135 *_tcschr(p_tmp + 1, _T('"')) = 0;
136 continue;
137 }
138 title = p_tmp;
139 }
140
141 if (title)
142 SetWindowText(hWnd, title);
143
144 wp.length = sizeof(WINDOWPLACEMENT);
145 GetWindowPlacement(hWnd, &wp);
146
147 if (iAction & A_POS)
148 wp.rcNormalPosition = pos;
149
150 if (iAction & A_MIN)
151 wp.showCmd = SW_MINIMIZE;
152
153 if (iAction & A_MAX)
154 wp.showCmd = SW_SHOWMAXIMIZED;
155
156 /*if no actions are specified default is SW_RESTORE*/
157 if ((iAction & A_RESTORE) || (!iAction))
158 wp.showCmd = SW_RESTORE;
159
160 if (iAction & A_CLOSE)
161 {
162 #ifdef _DEBUG
163 ConErrPrintf(_T("!!!FIXME: CLOSE Not implemented!!!\n"));
164 #endif
165 }
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 hwnd;
182
183 if (_tcsncmp (param, _T("/?"), 2) == 0)
184 {
185 ConOutResPaging(TRUE,STRING_WINDOW_HELP1);
186 return 0;
187 }
188
189 hwnd = GetConsoleWindow();
190 Sleep(0);
191 return ServiceActivate(param, hwnd);
192 }
193
194
195 INT CommandActivate (LPTSTR cmd, LPTSTR param)
196 {
197 HWND hwnd;
198 LPTSTR *arg;
199 INT argc;
200
201 if (_tcsncmp (param, _T("/?"), 2) == 0)
202 {
203 ConOutResPaging(TRUE,STRING_WINDOW_HELP2);
204 return 0;
205 }
206
207 if(!(*param))
208 return 1;
209
210 /*Split the user input into array*/
211 arg = split (param, &argc, FALSE);
212 if(argc < 2)
213 {
214 if(arg != NULL)
215 freep(arg);
216 }
217 hwnd = FindWindow(NULL, arg[0]);
218 if (hwnd == NULL)
219 {
220 if(arg != NULL)
221 freep(arg);
222 ConErrResPuts(STRING_WINDOW_ERROR1);
223 return 1;
224 }
225 if(arg != NULL)
226 freep(arg);
227
228 return ServiceActivate(param, hwnd);
229 }
230
231 #endif /* ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) ) */