comparison win/dw.c @ 37:360bc6a5f1c9

Sync with latest Dynamic Windows code.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 14 Oct 2001 23:27:37 +0000
parents b03b24bb95f8
children 3aa9ef0b3996
comparison
equal deleted inserted replaced
36:cddb02f847e1 37:360bc6a5f1c9
12 #include <commctrl.h> 12 #include <commctrl.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <string.h> 14 #include <string.h>
15 #include <stdio.h> 15 #include <stdio.h>
16 #include <process.h> 16 #include <process.h>
17 #include <time.h>
17 #include "dw.h" 18 #include "dw.h"
18 19
19 /* this is the callback handle for the window procedure */ 20 /* this is the callback handle for the window procedure */
20 /* make sure you always match the calling convention! */ 21 /* make sure you always match the calling convention! */
21 int (*filterfunc)(HWND, UINT, WPARAM, LPARAM) = 0L; 22 int (*filterfunc)(HWND, UINT, WPARAM, LPARAM) = 0L;
1348 break; 1349 break;
1349 case WM_COMMAND: 1350 case WM_COMMAND:
1350 case WM_NOTIFY: 1351 case WM_NOTIFY:
1351 _wndproc(hWnd, msg, mp1, mp2); 1352 _wndproc(hWnd, msg, mp1, mp2);
1352 break; 1353 break;
1354 #if 0
1355 case WM_ERASEBKGND:
1356 {
1357 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLong(hWnd, GWL_USERDATA);
1358
1359 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1)
1360 return FALSE;
1361 }
1362 break;
1363 #endif
1364 case WM_PAINT:
1365 {
1366 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLong(hWnd, GWL_USERDATA);
1367
1368 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1)
1369 {
1370 PAINTSTRUCT ps;
1371 HDC hdcPaint = BeginPaint(hWnd, &ps);
1372 int success = FALSE;
1373
1374 if(thiscinfo->fore > -1 && thiscinfo->back > -1 &&
1375 thiscinfo->fore < 18 && thiscinfo->back < 18)
1376 {
1377 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore],
1378 _green[thiscinfo->fore],
1379 _blue[thiscinfo->fore]));
1380 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back],
1381 _green[thiscinfo->back],
1382 _blue[thiscinfo->back]));
1383 DeleteObject(thiscinfo->hbrush);
1384 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back],
1385 _green[thiscinfo->back],
1386 _blue[thiscinfo->back]));
1387 SelectObject(hdcPaint, thiscinfo->hbrush);
1388 Rectangle(hdcPaint, ps.rcPaint.left - 1, ps.rcPaint.top - 1, ps.rcPaint.right + 1, ps.rcPaint.bottom + 1);
1389 success = TRUE;
1390 }
1391 if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR && (thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR)
1392 {
1393 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore),
1394 DW_GREEN_VALUE(thiscinfo->fore),
1395 DW_BLUE_VALUE(thiscinfo->fore)));
1396 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back),
1397 DW_GREEN_VALUE(thiscinfo->back),
1398 DW_BLUE_VALUE(thiscinfo->back)));
1399 DeleteObject(thiscinfo->hbrush);
1400 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back),
1401 DW_GREEN_VALUE(thiscinfo->back),
1402 DW_BLUE_VALUE(thiscinfo->back)));
1403 SelectObject(hdcPaint, thiscinfo->hbrush);
1404 Rectangle(hdcPaint, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
1405 success = TRUE;
1406 }
1407
1408 EndPaint(hWnd, &ps);
1409 if(success)
1410 return FALSE;
1411 }
1412
1413 }
1414 break;
1353 } 1415 }
1354 return DefWindowProc(hWnd, msg, mp1, mp2); 1416 return DefWindowProc(hWnd, msg, mp1, mp2);
1355 } 1417 }
1356 1418
1357 BOOL CALLBACK _rendwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) 1419 BOOL CALLBACK _rendwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2)
1446 1508
1447 if(cinfo) 1509 if(cinfo)
1448 { 1510 {
1449 switch( msg ) 1511 switch( msg )
1450 { 1512 {
1513 case WM_SETFOCUS:
1514 _wndproc(hWnd, msg, mp1, mp2);
1515 break;
1451 case WM_CHAR: 1516 case WM_CHAR:
1452 if(LOWORD(mp1) == '\t') 1517 if(LOWORD(mp1) == '\t')
1453 { 1518 {
1454 if(cinfo->buddy) 1519 if(cinfo->buddy)
1455 _shift_focus(cinfo->buddy); 1520 _shift_focus(cinfo->buddy);
1967 return DefWindowProc(hwnd, msg, mp1, mp2); 2032 return DefWindowProc(hwnd, msg, mp1, mp2);
1968 2033
1969 switch(msg) 2034 switch(msg)
1970 { 2035 {
1971 #ifndef NO_SIGNALS 2036 #ifndef NO_SIGNALS
2037 case WM_SETFOCUS:
2038 _wndproc(hwnd, msg, mp1, mp2);
2039 break;
1972 case WM_LBUTTONUP: 2040 case WM_LBUTTONUP:
1973 { 2041 {
1974 SignalHandler *tmp = Root; 2042 SignalHandler *tmp = Root;
1975 2043
1976 /* Find any callbacks for this function */ 2044 /* Find any callbacks for this function */
2307 MSG msg; 2375 MSG msg;
2308 2376
2309 /* Setup the filter function */ 2377 /* Setup the filter function */
2310 filterfunc = func; 2378 filterfunc = func;
2311 2379
2312 while (GetMessage(&msg,NULL,0,0)) { 2380 while (GetMessage(&msg, NULL, 0, 0))
2381 {
2313 TranslateMessage(&msg); 2382 TranslateMessage(&msg);
2314 DispatchMessage(&msg); 2383 DispatchMessage(&msg);
2315 } 2384 }
2316 2385
2317 #ifdef DWDEBUG 2386 #ifdef DWDEBUG
2318 fclose(f); 2387 fclose(f);
2319 #endif 2388 #endif
2389 }
2390
2391 /*
2392 * Runs a message loop for Dynamic Windows, for a period of seconds.
2393 * Parameters:
2394 * seconds: Number of seconds to run the loop for.
2395 */
2396 void dw_main_sleep(int seconds)
2397 {
2398 MSG msg;
2399 time_t start = time(NULL);
2400
2401 while(time(NULL) - start <= seconds)
2402 {
2403 if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
2404 {
2405 GetMessage(&msg, NULL, 0, 0);
2406 TranslateMessage(&msg);
2407 DispatchMessage(&msg);
2408 }
2409 else
2410 Sleep(1);
2411 }
2320 } 2412 }
2321 2413
2322 /* 2414 /*
2323 * Free's memory allocated by dynamic windows. 2415 * Free's memory allocated by dynamic windows.
2324 * Parameters: 2416 * Parameters:
2562 char tmpbuf[100]; 2654 char tmpbuf[100];
2563 2655
2564 cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); 2656 cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA);
2565 2657
2566 GetClassName(handle, tmpbuf, 99); 2658 GetClassName(handle, tmpbuf, 99);
2567
2568 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME))==0)
2569 return FALSE;
2570 2659
2571 if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))==0) 2660 if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))==0)
2572 { 2661 {
2573 ListView_SetTextColor(handle, RGB(DW_RED_VALUE(fore), 2662 ListView_SetTextColor(handle, RGB(DW_RED_VALUE(fore),
2574 DW_GREEN_VALUE(fore), 2663 DW_GREEN_VALUE(fore),
4160 * buffer: Text buffer to be imported. 4249 * buffer: Text buffer to be imported.
4161 * startpoint: Point to start entering text. 4250 * startpoint: Point to start entering text.
4162 */ 4251 */
4163 unsigned int dw_mle_import(HWND handle, char *buffer, int startpoint) 4252 unsigned int dw_mle_import(HWND handle, char *buffer, int startpoint)
4164 { 4253 {
4165 char *tmpbuf = malloc(MLE_MAX+1); 4254 char *tmpbuf = calloc(1, MLE_MAX+1);
4166 int len; 4255 int len;
4256
4257 if(strlen(buffer) < 1)
4258 return startpoint;
4259
4260 startpoint++;
4167 4261
4168 if(startpoint < 0) 4262 if(startpoint < 0)
4169 startpoint = 0; 4263 startpoint = 0;
4170 4264
4171 GetWindowText(handle, tmpbuf, MLE_MAX); 4265 GetWindowText(handle, tmpbuf, MLE_MAX);
4172 tmpbuf[MLE_MAX] = 0;
4173 4266
4174 len = strlen(tmpbuf); 4267 len = strlen(tmpbuf);
4175 if(len) 4268 if(len)
4176 memcpy(&tmpbuf[startpoint+strlen(buffer)], &tmpbuf[startpoint], (len-startpoint)); 4269 {
4270 char *dest = &tmpbuf[startpoint+strlen(buffer)-1], *start = &tmpbuf[startpoint];
4271 int copylen = len - startpoint;
4272
4273 if(copylen > 0)
4274 memcpy(dest, start, copylen);
4275 }
4177 memcpy(&tmpbuf[startpoint], buffer, strlen(buffer)); 4276 memcpy(&tmpbuf[startpoint], buffer, strlen(buffer));
4178
4179 tmpbuf[len+strlen(buffer)] = 0;
4180 4277
4181 SetWindowText(handle, tmpbuf); 4278 SetWindowText(handle, tmpbuf);
4182 4279
4183 free(tmpbuf); 4280 free(tmpbuf);
4184 return startpoint+strlen(buffer); 4281 return startpoint+strlen(buffer);
5828 { 5925 {
5829 ULONG message = 0L; 5926 ULONG message = 0L;
5830 5927
5831 if(window && signame && sigfunc) 5928 if(window && signame && sigfunc)
5832 { 5929 {
5930 if(stricmp(signame, "set-focus") == 0)
5931 window = _normalize_handle(window);
5932
5833 if((message = _findsigmessage(signame)) != 0) 5933 if((message = _findsigmessage(signame)) != 0)
5834 _new_signal(message, window, sigfunc, data); 5934 _new_signal(message, window, sigfunc, data);
5835 } 5935 }
5836 } 5936 }
5837 5937