comparison os2/dw.c @ 567:81ca08481d49

Added the basics of the color chooser on OS/2. Needs some more logic to be finished. Removed DW_OS2_RGB() since it was no longer used.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 24 Jun 2004 08:54:19 +0000
parents f6de197ecbe9
children 07c100ee783d
comparison
equal deleted inserted replaced
566:f6de197ecbe9 567:81ca08481d49
55 55
56 HWND hwndApp = NULLHANDLE, hwndBubble = NULLHANDLE, hwndBubbleLast = NULLHANDLE, hwndEmph = NULLHANDLE; 56 HWND hwndApp = NULLHANDLE, hwndBubble = NULLHANDLE, hwndBubbleLast = NULLHANDLE, hwndEmph = NULLHANDLE;
57 PRECORDCORE pCoreEmph = NULL; 57 PRECORDCORE pCoreEmph = NULL;
58 ULONG aulBuffer[4], GlobalID = 10000; 58 ULONG aulBuffer[4], GlobalID = 10000;
59 HWND lasthcnr = 0, lastitem = 0, popup = 0, desktop; 59 HWND lasthcnr = 0, lastitem = 0, popup = 0, desktop;
60 HMOD wpconfig = 0;
60 61
61 unsigned long _colors[] = { 62 unsigned long _colors[] = {
62 CLR_BLACK, 63 CLR_BLACK,
63 CLR_DARKRED, 64 CLR_DARKRED,
64 CLR_DARKGREEN, 65 CLR_DARKGREEN,
371 if(ptr) 372 if(ptr)
372 { 373 {
373 WindowData *wd = (WindowData *)ptr; 374 WindowData *wd = (WindowData *)ptr;
374 char tmpbuf[100]; 375 char tmpbuf[100];
375 376
376 /* If this window has an associate bitmap destroy it. */
377 _free_bitmap(handle);
378
379 WinQueryClassName(handle, 99, tmpbuf); 377 WinQueryClassName(handle, 99, tmpbuf);
380 378
381 if(strncmp(tmpbuf, "#1", 3)==0 && !WinWindowFromID(handle, FID_CLIENT)) 379 if(strncmp(tmpbuf, "ColorSelectClass", 17)!=0)
382 { 380 {
383 Box *box = (Box *)ptr; 381 /* If this window has an associate bitmap destroy it. */
384 382 _free_bitmap(handle);
385 if(box->count && box->items) 383
386 free(box->items); 384 if(strncmp(tmpbuf, "#1", 3)==0 && !WinWindowFromID(handle, FID_CLIENT))
387 }
388 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
389 {
390 void *data = dw_window_get_data(handle, "_dw_percent");
391
392 if(data)
393 free(data);
394 }
395 else if(strncmp(tmpbuf, "#37", 4)==0)
396 {
397 dw_container_clear(handle, FALSE);
398 if(wd && dw_window_get_data(handle, "_dw_container"))
399 { 385 {
400 void *oldflags = wd->data; 386 Box *box = (Box *)ptr;
401 387
402 wd->data = NULL; 388 if(box->count && box->items)
403 free(oldflags); 389 free(box->items);
404 } 390 }
405 } 391 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
406 392 {
407 if(wd->oldproc) 393 void *data = dw_window_get_data(handle, "_dw_percent");
408 WinSubclassWindow(handle, wd->oldproc); 394
409 395 if(data)
410 dw_window_set_data(handle, NULL, NULL); 396 free(data);
411 WinSetWindowPtr(handle, QWP_USER, 0); 397 }
412 free(ptr); 398 else if(strncmp(tmpbuf, "#37", 4)==0)
399 {
400 dw_container_clear(handle, FALSE);
401 if(wd && dw_window_get_data(handle, "_dw_container"))
402 {
403 void *oldflags = wd->data;
404
405 wd->data = NULL;
406 free(oldflags);
407 }
408 }
409
410 if(wd->oldproc)
411 WinSubclassWindow(handle, wd->oldproc);
412
413 dw_window_set_data(handle, NULL, NULL);
414 WinSetWindowPtr(handle, QWP_USER, 0);
415 free(ptr);
416 }
413 } 417 }
414 418
415 henum = WinBeginEnumWindows(handle); 419 henum = WinBeginEnumWindows(handle);
416 while((child = WinGetNextWindow(henum)) != NULLHANDLE) 420 while((child = WinGetNextWindow(henum)) != NULLHANDLE)
417 _free_window_memory(child); 421 _free_window_memory(child);
936 unsigned long _internal_color(unsigned long color) 940 unsigned long _internal_color(unsigned long color)
937 { 941 {
938 if(color < 16) 942 if(color < 16)
939 return _colors[color]; 943 return _colors[color];
940 return color; 944 return color;
945 }
946
947 unsigned long _os2_color(unsigned long color)
948 {
949 return DW_RED_VALUE(color) << 16 | DW_GREEN_VALUE(color) << 8 | DW_BLUE_VALUE(color);;
941 } 950 }
942 951
943 BOOL _MySetWindowPos(HWND hwnd, HWND parent, HWND behind, LONG x, LONG y, LONG cx, LONG cy, ULONG fl) 952 BOOL _MySetWindowPos(HWND hwnd, HWND parent, HWND behind, LONG x, LONG y, LONG cx, LONG cy, ULONG fl)
944 { 953 {
945 int height = _get_height(parent); 954 int height = _get_height(parent);
3399 * False if there is already a message loop running. 3408 * False if there is already a message loop running.
3400 */ 3409 */
3401 int API dw_init(int newthread, int argc, char *argv[]) 3410 int API dw_init(int newthread, int argc, char *argv[])
3402 { 3411 {
3403 APIRET rc; 3412 APIRET rc;
3413 char objnamebuf[300] = "";
3404 3414
3405 argc = argc; /* keep compiler happy */ 3415 argc = argc; /* keep compiler happy */
3406 argv = argv; /* keep compiler happy */ 3416 argv = argv; /* keep compiler happy */
3407 if(newthread) 3417 if(newthread)
3408 { 3418 {
3423 3433
3424 /* This is a window that hangs around as long as the 3434 /* This is a window that hangs around as long as the
3425 * application does and handles menu messages. 3435 * application does and handles menu messages.
3426 */ 3436 */
3427 hwndApp = dw_window_new(HWND_OBJECT, "", 0); 3437 hwndApp = dw_window_new(HWND_OBJECT, "", 0);
3438 DosLoadModule(objnamebuf, sizeof(objnamebuf), "WPCONFIG", &wpconfig);
3428 3439
3429 return rc; 3440 return rc;
3430 } 3441 }
3431 3442
3432 /* 3443 /*
7247 * Returns: 7258 * Returns:
7248 * The selected color or the current color if cancelled. 7259 * The selected color or the current color if cancelled.
7249 */ 7260 */
7250 unsigned long API dw_color_choose(unsigned long value) 7261 unsigned long API dw_color_choose(unsigned long value)
7251 { 7262 {
7252 dw_messagebox("Not implemented", DW_MB_OK|DW_MB_INFORMATION, "This feature not yet supported."); 7263 HWND window, hbox, vbox, col, button, text;
7253 return value; 7264 DWDialog *dwwait;
7265 HMTX mtx = dw_mutex_new();
7266
7267 window = dw_window_new( HWND_DESKTOP, "Choose Color", FCF_SHELLPOSITION | FCF_TITLEBAR | FCF_DLGBORDER | FCF_CLOSEBUTTON | FCF_SYSMENU);
7268
7269 vbox = dw_box_new(DW_VERT, 5);
7270
7271 dw_box_pack_start(window, vbox, 0, 0, TRUE, TRUE, 0);
7272
7273 hbox = dw_box_new(DW_HORZ, 0);
7274
7275 dw_box_pack_start(vbox, hbox, 0, 0, FALSE, FALSE, 0);
7276 dw_window_set_style(hbox, 0, WS_CLIPCHILDREN);
7277
7278 col = WinCreateWindow(vbox, "ColorSelectClass", "", WS_VISIBLE | WS_GROUP, 0, 0, 390, 300, vbox, HWND_TOP, 266, NULL,NULL);
7279 dw_box_pack_start(hbox, col, 390, 300, FALSE, FALSE, 0);
7280
7281 dw_window_set_data(window, "_dw_mutex", (void *)mtx);
7282 dw_window_set_data(window, "_dw_col", (void *)col);
7283
7284 hbox = dw_box_new(DW_HORZ, 0);
7285
7286 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0);
7287
7288 text = dw_text_new("Red:", 0);
7289 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3);
7290
7291 button = dw_spinbutton_new("", 1001L);
7292 dw_spinbutton_set_limits(button, 255, 0);
7293 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3);
7294 dw_window_set_data(window, "_dw_red_spin", (void *)button);
7295 dw_spinbutton_set_pos(button, DW_RED_VALUE(value));
7296
7297 text = dw_text_new("Green:", 0);
7298 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3);
7299
7300 button = dw_spinbutton_new("", 1002L);
7301 dw_spinbutton_set_limits(button, 255, 0);
7302 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3);
7303 dw_window_set_data(window, "_dw_green_spin", (void *)button);
7304 dw_spinbutton_set_pos(button, DW_GREEN_VALUE(value));
7305
7306 text = dw_text_new("Blue:", 0);
7307 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3);
7308
7309 button = dw_spinbutton_new("", 1003L);
7310 dw_spinbutton_set_limits(button, 255, 0);
7311 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3);
7312 dw_window_set_data(window, "_dw_blue_spin", (void *)button);
7313 dw_spinbutton_set_pos(button, DW_BLUE_VALUE(value));
7314
7315 hbox = dw_box_new(DW_HORZ, 0);
7316
7317 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0);
7318 dw_box_pack_start(hbox, 0, 100, 1, TRUE, FALSE, 0);
7319
7320 button = dw_button_new("Ok", 1001L);
7321 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3);
7322
7323 button = dw_button_new("Cancel", 1002L);
7324 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3);
7325
7326 dwwait = dw_dialog_new((void *)window);
7327
7328 dw_window_set_size(window, 400, 400);
7329
7330 WinSendMsg(col, 0x0602, MPFROMLONG(_os2_color(value)), 0);
7331 if(!IS_WARP4())
7332 WinSendMsg(col, 0x1384, MPFROMLONG(_os2_color(value)), 0);
7333
7334 dw_window_show(window);
7335
7336 return (unsigned long)dw_dialog_wait(dwwait);
7254 } 7337 }
7255 7338
7256 HPS _set_hps(HPS hps) 7339 HPS _set_hps(HPS hps)
7257 { 7340 {
7258 LONG alTable[2]; 7341 LONG alTable[2];
8196 * try to free memory that could possibly be 8279 * try to free memory that could possibly be
8197 * free()'d by the runtime already. 8280 * free()'d by the runtime already.
8198 */ 8281 */
8199 Root = NULL; 8282 Root = NULL;
8200 8283
8284 DosFreeModule(wpconfig);
8201 exit(exitcode); 8285 exit(exitcode);
8202 } 8286 }
8203 8287
8204 /* 8288 /*
8205 * Creates a splitbar window (widget) with given parameters. 8289 * Creates a splitbar window (widget) with given parameters.