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