ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/W11/w32/ntutil.c
Revision: 1.1
Committed: Mon Nov 24 17:28:08 2003 UTC (20 years, 7 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-7_0, post_menubar_removal, rel-6_2, rel-6_3, rel-6_0, rel-6_1, rel-2_1_0, rel-5_5, rel-5_4, rel-5_7, rel-5_1, rel-5_0, rel-5_3, rel-5_2, rel-4_4, rel-4_6, rel-4_7, rel-5_9, rel-5_8, rel-4_2, rel-4_3, rel-3_7, rel-3_8, rel-3_5, rel-3_4, rel-3_3, rel-3_2, rel-2_8, rel-3_0, rel-4_0, rel-2_4, rel-2_5, rel-2_2, rel-2_3, rel-2_0, rel-4_1, rel-1-9, rel-1-3, rel-1-2, rxvt-2-0, rel-1_9, rel-3_6, rel-2_7, rel-4_8, rel-4_9
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "ntdef.h"
2
3 static struct NT_window *window_list=NULL;
4
5 void
6 freeMemory(void *p) {
7 if (p!=NULL) free(p);
8 }
9 void *
10 allocateMemory(int s) {
11 void *p=NULL;
12 if (s)
13 {
14 p=(void *)malloc(s);
15 if (p) memset(p,0,s);
16 }
17 return p;
18 }
19
20
21 /*---------------------------------------------------*\
22 | Function: NT_new_window |
23 | Purpose: Add a new window id to the Window table |
24 | Return: Pointer to the new Window structure. |
25 \*---------------------------------------------------*/
26 struct NT_window *
27 NT_new_window()
28 {
29 struct NT_window *new;
30 xtrace("NT_new_window\n");
31 new = (struct NT_window *) allocateMemory (sizeof(struct NT_window));
32 new->next = window_list;
33 new->child=NULL;
34 new->min = 1;
35 new->minx =0;
36 new->miny =0;
37 new->w = INVALID_HANDLE;
38 new->parent= NULL;
39 new->hBitmap = INVALID_HANDLE;
40 new->hDC = INVALID_HANDLE;
41 window_list = new;
42 cjh_printf("NEW window %x\n",window_list);
43 return(window_list);
44 }
45
46 /*---------------------------------------------------*\
47 | Function: NT_delete_window |
48 | Purpose: Remove a window from the window list |
49 | Input: w - pointer to window data |
50 | Return: TRUE if deleted |
51 \*---------------------------------------------------*/
52 int
53 NT_delete_window(struct NT_window *w)
54 {
55 NT_window *f;
56 xtrace("NT_delete_window\n");
57
58 if (w->w != INVALID_HANDLE)
59 {
60 /* ShowWindow(w->w,SW_HIDE);*/
61 DestroyWindow(w->w);
62 w->w=INVALID_HANDLE;
63 }
64 if (w->hBitmap != INVALID_HANDLE)
65 {
66 DeleteObject(w->hBitmap);
67 w->hBitmap = INVALID_HANDLE;
68 }
69 if (w->hDC != INVALID_HANDLE)
70 {
71 DeleteDC(w->hDC);
72 w->hDC=INVALID_HANDLE;
73 }
74
75 if (window_list == w)
76 window_list=w->next;
77 else
78 {
79 for (f=window_list; f!=NULL && f->next!=w; f=f->next);
80 if (f!=NULL)
81 f->next = w->next;
82 }
83 freeMemory(w);
84 return TRUE;
85 }
86
87 /*------------------------------------------------*\
88 | Function: NT_find_window_from_id |
89 | Purpose: Find the window in the window list |
90 | from the HWND id of the window. |
91 | Input: w - Window id (Windows HWND) |
92 | Return: pointer to NT_window structure for w. |
93 \*------------------------------------------------*/
94 struct NT_window *
95 NT_find_window_from_id(HWND w)
96 {
97 struct NT_window *current = window_list;
98 /* xtrace("NT_find_window_from_id\n"); */
99
100 while ( current != NULL &&
101 current->w != w )
102 current = current->next;
103 if(current)
104 return(current);
105 current=window_list;
106 return NULL;
107 }
108
109 /*****************************************************************\
110
111 Function: NT_add_child
112 Inputs: parent and child window IDs.
113 Returned: 1
114
115 Comments: When a child window is created (eg. client canvas) we
116 update our internal list of windows and their children.
117 New children are added to the front of the list.
118
119 \*****************************************************************/
120
121 int
122 NT_add_child(parent,child)
123 NT_window *parent,*child;
124 {
125 struct NT_child *new;
126
127 new=(struct NT_child *) allocateMemory (sizeof(struct NT_child));
128 new->w=child;
129 new->next = parent->child;
130 parent->child=new;
131 return(1);
132 }
133
134 struct NT_window *
135 NT_find_child(NT_window *w,unsigned long mask,
136 unsigned long val)
137 {
138 struct NT_window *ret = NULL;
139 struct NT_child *child = NULL;
140 if (w)
141 {
142 if ((w->mask&mask)==val) ret=w;
143 child = w->child;
144 while(!ret && child) {
145 ret = NT_find_child(child->w, mask, val);
146 child=child->next;
147 }
148 }
149 return ret;
150 }
151
152
153
154 /*****************************************************************\
155
156 Function: NT_del_child
157 Inputs: parent and child window IDs.
158 Returned: TRUE if window is removed, FALSE otherwise.
159
160 Comments: Finds child window if it exits, and it so removes it from
161 the window list.
162
163 \*****************************************************************/
164
165 int
166 NT_del_child(parent,child)
167 struct NT_window *parent;
168 struct NT_window *child;
169 {
170 struct NT_child *current,*last;
171 int status=FALSE;
172
173 if (parent->child==NULL)
174 {
175 }
176 else if (parent->child->w==child)
177 {
178 current = parent->child;
179 parent->child=parent->child->next;
180 freeMemory(current);
181 status=TRUE;
182 }
183 else
184 {
185 last=parent->child;
186 current=parent->child->next;
187 while (current->w!=child && current!=NULL)
188 {
189 last=current;
190 current=current->next;
191 }
192 if (current!=NULL)
193 {
194 last->next=current->next;
195 freeMemory(current);
196 status=TRUE;
197 }
198 }
199 return(status);
200 }
201
202 /*****************************************************************\
203
204 Function: WinMain
205 Inputs: instance, previous instance, command line arguments,
206 default start up.
207
208 Comments: Called instead of main() as the execution entry point.
209
210 \*****************************************************************/
211 #ifdef NOTCYGWIN
212 #define MAX_COMMAND_ARGS 20
213 static HANDLE hInstance,hPrevInstance;
214 int APIENTRY
215 WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nCmdShow)
216 {
217 static char *command_args[MAX_COMMAND_ARGS];
218 static int num_command_args;
219 static char proEng[] = "proe";
220 char *wordPtr,*tempPtr;
221 int i,quote;
222 hInstance=hInst;
223 hPrevInstance=hPrevInst;
224
225 for (i=0;i<MAX_COMMAND_ARGS;i++)
226 command_args[i] = NULL;
227
228 wordPtr = lpCmdLine;
229 quote = 0;
230 num_command_args = 1;
231 command_args[0] = proEng;
232 while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
233 wordPtr++;
234 if (*wordPtr == '\"')
235 {
236 quote = 1;
237 wordPtr++;
238 }
239 if (!*wordPtr)
240 main(0,NULL);
241 else
242 {
243 while (*wordPtr && num_command_args < MAX_COMMAND_ARGS)
244 {
245 tempPtr = wordPtr;
246 if (quote)
247 {
248 while (*tempPtr && *tempPtr != '\"')
249 tempPtr++;
250 quote = 0;
251 }
252 else
253 while (*tempPtr && *tempPtr != ' ')
254 tempPtr++;
255 if (*tempPtr)
256 *(tempPtr++) = '\0';
257 command_args[num_command_args++] = wordPtr;
258 wordPtr = tempPtr;
259 while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
260 wordPtr++;
261 if (*wordPtr == '\"')
262 {
263 quote = 1;
264 wordPtr++;
265 }
266 }
267 main(num_command_args,command_args);
268 }
269
270 }
271 #endif
272
273 static ATOM atom=0;
274 void
275 NT_SetAtom(ATOM class)
276 {
277 atom = class;
278 }
279
280 HWND
281 NT_create_window(char *title,DWORD style,int x,int y,int w, int h,HWND parent)
282 {
283 HMODULE hInst = NULL; /* GetModuleHandleA(NULL); */
284 return CreateWindow((LPCTSTR)MAKELONG(atom,0),title,style,x,y,w,h,
285 parent,NULL,hInst,NULL);
286 }
287 HBITMAP
288 NT_getWallpaper()
289 {
290 HBITMAP hb = NULL;
291 do {
292 HKEY hKey;
293 TCHAR wallpaper[MAX_PATH];
294 DWORD dwBufLen = MAX_PATH;
295 LONG lRet;
296
297 lRet = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, &hKey);
298 if (lRet != ERROR_SUCCESS) break;
299
300 lRet = RegQueryValueEx(hKey, TEXT("Wallpaper"), NULL, NULL, (LPBYTE)wallpaper, &dwBufLen);
301 if (lRet != ERROR_SUCCESS) break;
302
303 RegCloseKey(hKey);
304 hb = LoadImage(NULL, wallpaper, IMAGE_BITMAP, 0, 0,
305 LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
306 } while(0);
307 return hb;
308 }
309
310 void
311 NT_moveWindow(NT_window *ntw, BOOL repaint)
312 {
313 MoveWindow(ntw->w, ntw->x,ntw->y,ntw->wdth,ntw->hght,repaint);
314 NT_configureNotify(ntw,ntw->x,ntw->y);
315 }
316
317 NT_set_origin(NT_window *ntw,int x, int y)
318 {
319 HDC hdc;
320 hdc = GetDC(ntw->w);
321 SetBrushOrgEx(hdc,-x,-y,NULL);
322 ReleaseDC(ntw->w,hdc);
323 }
324
325
326 NT_confChild(NT_window *ntw,int x, int y)
327 {
328 HDC hdc;
329 struct NT_child *child = NULL;
330 if (ntw)
331 {
332 if (ntw->parentRelative) NT_set_origin(ntw,x,y);
333 child = ntw->child;
334 while(child && child->w) {
335 NT_confChild(child->w, child->w->x+x, child->w->y+y);
336 child=child->next;
337 }
338 }
339 }
340
341 NT_configureNotify(NT_window *ntw,int x, int y)
342 {
343 while(ntw && ntw->parent) {
344 ntw=ntw->parent;
345 }
346 NT_confChild(ntw,ntw->x,ntw->y);
347 }
348
349
350
351 /*
352 HBITMAP
353 NT_getWallpaper()
354 {
355 WCHAR wszWallpaper [MAX_PATH];
356 CHAR szWallpaper[MAX_PATH];
357 HRESULT hr;
358 HBITMAP hb = NULL;
359 IActiveDesktop* pIAD = NULL;
360 do {
361 CoInitialize ( NULL );
362 hr = CoCreateInstance ( CLSID_ActiveDesktop,
363 NULL,
364 CLSCTX_INPROC_SERVER,
365 IID_IActiveDesktop,
366 (void**) &pIAD );
367 if (! SUCCEEDED(hr) ) break;
368 hr = pIAD->GetWallpaper ( wszWallpaper, MAX_PATH, 0 );
369
370 if (! SUCCEEDED(hr) ) break;
371 wsprintf(szWallpaper,"%ls",wszWallpaper);
372 hb = LoadImage(NULL, szWallpaper, IMAGE_BITMAP, 0, 0,
373 LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
374 } while(0);
375 if (pIAD) pIAD->Release();
376 CoUninitialize();
377 return hb;
378 }
379 */