Mercurial > dwindows
comparison os2/dw.c @ 568:07c100ee783d
The color selection dialog is now functional under OS/2 but it does not
yet accept the predefined system colors. Only RGB colors.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 24 Jun 2004 18:31:55 +0000 |
parents | 81ca08481d49 |
children | 828e6a66c5c5 |
comparison
equal
deleted
inserted
replaced
567:81ca08481d49 | 568:07c100ee783d |
---|---|
1 /* | |
1 /* | 2 /* |
2 * Dynamic Windows: | 3 * Dynamic Windows: |
3 * A GTK like implementation of the PM GUI | 4 * A GTK like implementation of the PM GUI |
4 * | 5 * |
5 * (C) 2000-2004 Brian Smith <dbsoft@technologist.com> | 6 * (C) 2000-2004 Brian Smith <dbsoft@technologist.com> |
450 char tmpbuf[100]; | 451 char tmpbuf[100]; |
451 | 452 |
452 if(!handle) | 453 if(!handle) |
453 return 0; | 454 return 0; |
454 | 455 |
455 if(!WinIsWindowEnabled(handle) || dw_window_get_data(handle, "_dw_disabled")) | 456 WinQueryClassName(handle, 99, tmpbuf); |
457 | |
458 if(!WinIsWindowEnabled(handle) || | |
459 (strncmp(tmpbuf, "ColorSelectClass", 17) && dw_window_get_data(handle, "_dw_disabled"))) | |
456 return 0; | 460 return 0; |
457 | |
458 WinQueryClassName(handle, 99, tmpbuf); | |
459 | 461 |
460 /* These are the window classes which can | 462 /* These are the window classes which can |
461 * obtain input focus. | 463 * obtain input focus. |
462 */ | 464 */ |
463 if(strncmp(tmpbuf, "#2", 3)==0 || /* Combobox */ | 465 if(strncmp(tmpbuf, "#2", 3)==0 || /* Combobox */ |
2549 | 2551 |
2550 } | 2552 } |
2551 return (MRESULT)result; | 2553 return (MRESULT)result; |
2552 } | 2554 } |
2553 | 2555 |
2556 /* Gets a DW_RGB value from the three spinbuttons */ | |
2557 unsigned long _dw_color_spin_get(HWND window) | |
2558 { | |
2559 HWND button = (HWND)dw_window_get_data(window, "_dw_red_spin"); | |
2560 long red, green, blue; | |
2561 | |
2562 red = dw_spinbutton_get_pos(button); | |
2563 button = (HWND)dw_window_get_data(window, "_dw_green_spin"); | |
2564 green = dw_spinbutton_get_pos(button); | |
2565 button = (HWND)dw_window_get_data(window, "_dw_blue_spin"); | |
2566 blue = dw_spinbutton_get_pos(button); | |
2567 | |
2568 return DW_RGB(red, green, blue); | |
2569 } | |
2570 | |
2571 /* Set the three spinbuttons from a DW_RGB value */ | |
2572 void _dw_color_spin_set(HWND window, unsigned long value) | |
2573 { | |
2574 HWND button = (HWND)dw_window_get_data(window, "_dw_red_spin"); | |
2575 dw_window_set_data(window, "_dw_updating", (void *)1); | |
2576 dw_spinbutton_set_pos(button, DW_RED_VALUE(value)); | |
2577 button = (HWND)dw_window_get_data(window, "_dw_green_spin"); | |
2578 dw_spinbutton_set_pos(button, DW_GREEN_VALUE(value)); | |
2579 button = (HWND)dw_window_get_data(window, "_dw_blue_spin"); | |
2580 dw_spinbutton_set_pos(button, DW_BLUE_VALUE(value)); | |
2581 dw_window_set_data(window, "_dw_updating", NULL); | |
2582 } | |
2583 | |
2584 /* Sets the color selection control to be a DW_RGB value */ | |
2585 void _dw_col_set(HWND col, unsigned long value) | |
2586 { | |
2587 WinSendMsg(col, 0x0602, MPFROMLONG(_os2_color(value)), 0); | |
2588 if(!IS_WARP4()) | |
2589 WinSendMsg(col, 0x1384, MPFROMLONG(_os2_color(value)), 0); | |
2590 } | |
2591 | |
2554 /* Handles control messages sent to the box (owner). */ | 2592 /* Handles control messages sent to the box (owner). */ |
2555 MRESULT EXPENTRY _controlproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 2593 MRESULT EXPENTRY _controlproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) |
2556 { | 2594 { |
2557 Box *blah = WinQueryWindowPtr(hWnd, QWP_USER); | 2595 Box *blah = WinQueryWindowPtr(hWnd, QWP_USER); |
2558 | 2596 |
2568 { | 2606 { |
2569 HWND window = WinWindowFromID(hWnd, (ULONG)mp1); | 2607 HWND window = WinWindowFromID(hWnd, (ULONG)mp1); |
2570 _HandleScroller(window, (int)SHORT1FROMMP(mp2), (int)SHORT2FROMMP(mp2)); | 2608 _HandleScroller(window, (int)SHORT1FROMMP(mp2), (int)SHORT2FROMMP(mp2)); |
2571 } | 2609 } |
2572 break; | 2610 break; |
2611 /* Handles Color Selection control messages */ | |
2612 case 0x0601: | |
2613 case 0x130C: | |
2614 { | |
2615 HWND window = (HWND)dw_window_get_data(hWnd, "_dw_window"); | |
2616 unsigned long val = (unsigned long)mp1; | |
2617 | |
2618 if(window) | |
2619 _dw_color_spin_set(window, DW_RGB((val & 0xFF0000) >> 16, (val & 0xFF00) >> 8, val & 0xFF)); | |
2620 } | |
2621 break; | |
2573 case WM_CONTROL: | 2622 case WM_CONTROL: |
2623 if((SHORT2FROMMP(mp1) == SPBN_CHANGE || SHORT2FROMMP(mp1) == SPBN_ENDSPIN)) | |
2624 { | |
2625 HWND window = (HWND)dw_window_get_data(hWnd, "_dw_window"); | |
2626 | |
2627 if(window && !dw_window_get_data(window, "_dw_updating")) | |
2628 { | |
2629 unsigned long val = _dw_color_spin_get(window); | |
2630 HWND col = (HWND)dw_window_get_data(window, "_dw_col"); | |
2631 | |
2632 _dw_col_set(col, val); | |
2633 } | |
2634 } | |
2574 _run_event(hWnd, msg, mp1, mp2); | 2635 _run_event(hWnd, msg, mp1, mp2); |
2575 break; | 2636 break; |
2576 } | 2637 } |
2577 | 2638 |
2578 if(blah && blah->oldproc) | 2639 if(blah && blah->oldproc) |
7250 void API dw_color_background_set(unsigned long value) | 7311 void API dw_color_background_set(unsigned long value) |
7251 { | 7312 { |
7252 _background = value; | 7313 _background = value; |
7253 } | 7314 } |
7254 | 7315 |
7316 int DWSIGNAL _dw_color_cancel_func(HWND window, void *data) | |
7317 { | |
7318 DWDialog *dwwait = (DWDialog *)data; | |
7319 HMTX mtx = (HMTX)dw_window_get_data((HWND)dwwait->data, "_dw_mutex"); | |
7320 void *val; | |
7321 | |
7322 window = (HWND)dwwait->data; | |
7323 val = dw_window_get_data(window, "_dw_val"); | |
7324 | |
7325 dw_mutex_lock(mtx); | |
7326 dw_mutex_close(mtx); | |
7327 dw_window_destroy(window); | |
7328 dw_dialog_dismiss((DWDialog *)data, val); | |
7329 return FALSE; | |
7330 } | |
7331 | |
7332 int DWSIGNAL _dw_color_ok_func(HWND window, void *data) | |
7333 { | |
7334 DWDialog *dwwait = (DWDialog *)data; | |
7335 HMTX mtx = (HMTX)dw_window_get_data((HWND)dwwait->data, "_dw_mutex"); | |
7336 unsigned long val; | |
7337 | |
7338 window = (HWND)dwwait->data; | |
7339 val = _dw_color_spin_get(window); | |
7340 | |
7341 dw_mutex_lock(mtx); | |
7342 dw_mutex_close(mtx); | |
7343 dw_window_destroy(window); | |
7344 dw_dialog_dismiss((DWDialog *)data, (void *)val); | |
7345 return FALSE; | |
7346 } | |
7347 | |
7255 /* Allows the user to choose a color using the system's color chooser dialog. | 7348 /* Allows the user to choose a color using the system's color chooser dialog. |
7256 * Parameters: | 7349 * Parameters: |
7257 * value: current color | 7350 * value: current color |
7258 * Returns: | 7351 * Returns: |
7259 * The selected color or the current color if cancelled. | 7352 * The selected color or the current color if cancelled. |
7276 dw_window_set_style(hbox, 0, WS_CLIPCHILDREN); | 7369 dw_window_set_style(hbox, 0, WS_CLIPCHILDREN); |
7277 | 7370 |
7278 col = WinCreateWindow(vbox, "ColorSelectClass", "", WS_VISIBLE | WS_GROUP, 0, 0, 390, 300, vbox, HWND_TOP, 266, NULL,NULL); | 7371 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); | 7372 dw_box_pack_start(hbox, col, 390, 300, FALSE, FALSE, 0); |
7280 | 7373 |
7374 dw_window_set_data(hbox, "_dw_window", (void *)window); | |
7281 dw_window_set_data(window, "_dw_mutex", (void *)mtx); | 7375 dw_window_set_data(window, "_dw_mutex", (void *)mtx); |
7282 dw_window_set_data(window, "_dw_col", (void *)col); | 7376 dw_window_set_data(window, "_dw_col", (void *)col); |
7377 dw_window_set_data(window, "_dw_val", (void *)value); | |
7283 | 7378 |
7284 hbox = dw_box_new(DW_HORZ, 0); | 7379 hbox = dw_box_new(DW_HORZ, 0); |
7380 dw_window_set_data(hbox, "_dw_window", (void *)window); | |
7285 | 7381 |
7286 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0); | 7382 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0); |
7287 | 7383 |
7288 text = dw_text_new("Red:", 0); | 7384 text = dw_text_new("Red:", 0); |
7385 dw_window_set_style(text, DW_DT_VCENTER, DW_DT_VCENTER); | |
7289 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3); | 7386 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3); |
7290 | 7387 |
7291 button = dw_spinbutton_new("", 1001L); | 7388 button = dw_spinbutton_new("", 1001L); |
7292 dw_spinbutton_set_limits(button, 255, 0); | 7389 dw_spinbutton_set_limits(button, 255, 0); |
7293 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3); | 7390 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3); |
7391 WinSetOwner(button, hbox); | |
7294 dw_window_set_data(window, "_dw_red_spin", (void *)button); | 7392 dw_window_set_data(window, "_dw_red_spin", (void *)button); |
7295 dw_spinbutton_set_pos(button, DW_RED_VALUE(value)); | |
7296 | 7393 |
7297 text = dw_text_new("Green:", 0); | 7394 text = dw_text_new("Green:", 0); |
7395 dw_window_set_style(text, DW_DT_VCENTER, DW_DT_VCENTER); | |
7298 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3); | 7396 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3); |
7299 | 7397 |
7300 button = dw_spinbutton_new("", 1002L); | 7398 button = dw_spinbutton_new("", 1002L); |
7301 dw_spinbutton_set_limits(button, 255, 0); | 7399 dw_spinbutton_set_limits(button, 255, 0); |
7302 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3); | 7400 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3); |
7401 WinSetOwner(button, hbox); | |
7303 dw_window_set_data(window, "_dw_green_spin", (void *)button); | 7402 dw_window_set_data(window, "_dw_green_spin", (void *)button); |
7304 dw_spinbutton_set_pos(button, DW_GREEN_VALUE(value)); | |
7305 | 7403 |
7306 text = dw_text_new("Blue:", 0); | 7404 text = dw_text_new("Blue:", 0); |
7405 dw_window_set_style(text, DW_DT_VCENTER, DW_DT_VCENTER); | |
7307 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3); | 7406 dw_box_pack_start(hbox, text, 30, 20, FALSE, FALSE, 3); |
7308 | 7407 |
7309 button = dw_spinbutton_new("", 1003L); | 7408 button = dw_spinbutton_new("", 1003L); |
7310 dw_spinbutton_set_limits(button, 255, 0); | 7409 dw_spinbutton_set_limits(button, 255, 0); |
7311 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3); | 7410 dw_box_pack_start(hbox, button, 20, 20, TRUE, FALSE, 3); |
7411 WinSetOwner(button, hbox); | |
7312 dw_window_set_data(window, "_dw_blue_spin", (void *)button); | 7412 dw_window_set_data(window, "_dw_blue_spin", (void *)button); |
7313 dw_spinbutton_set_pos(button, DW_BLUE_VALUE(value)); | |
7314 | 7413 |
7315 hbox = dw_box_new(DW_HORZ, 0); | 7414 hbox = dw_box_new(DW_HORZ, 0); |
7316 | 7415 |
7317 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0); | 7416 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0); |
7318 dw_box_pack_start(hbox, 0, 100, 1, TRUE, FALSE, 0); | 7417 dw_box_pack_start(hbox, 0, 100, 1, TRUE, FALSE, 0); |
7319 | 7418 |
7320 button = dw_button_new("Ok", 1001L); | 7419 button = dw_button_new("Ok", 1001L); |
7321 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3); | 7420 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3); |
7322 | 7421 |
7422 dwwait = dw_dialog_new((void *)window); | |
7423 | |
7424 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_color_ok_func), (void *)dwwait); | |
7425 | |
7323 button = dw_button_new("Cancel", 1002L); | 7426 button = dw_button_new("Cancel", 1002L); |
7324 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3); | 7427 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3); |
7325 | 7428 |
7326 dwwait = dw_dialog_new((void *)window); | 7429 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_color_cancel_func), (void *)dwwait); |
7430 dw_signal_connect(window, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_dw_color_cancel_func), (void *)dwwait); | |
7327 | 7431 |
7328 dw_window_set_size(window, 400, 400); | 7432 dw_window_set_size(window, 400, 400); |
7329 | 7433 |
7330 WinSendMsg(col, 0x0602, MPFROMLONG(_os2_color(value)), 0); | 7434 _dw_col_set(col, value); |
7331 if(!IS_WARP4()) | 7435 _dw_color_spin_set(window, value); |
7332 WinSendMsg(col, 0x1384, MPFROMLONG(_os2_color(value)), 0); | |
7333 | 7436 |
7334 dw_window_show(window); | 7437 dw_window_show(window); |
7335 | 7438 |
7336 return (unsigned long)dw_dialog_wait(dwwait); | 7439 return (unsigned long)dw_dialog_wait(dwwait); |
7337 } | 7440 } |
8825 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); | 8928 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); |
8826 | 8929 |
8827 button = dw_button_new("Cancel", 1002L); | 8930 button = dw_button_new("Cancel", 1002L); |
8828 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3); | 8931 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3); |
8829 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); | 8932 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); |
8933 dw_signal_connect(window, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); | |
8830 | 8934 |
8831 dw_window_set_size(window, 225, 300); | 8935 dw_window_set_size(window, 225, 300); |
8832 dw_window_show(window); | 8936 dw_window_show(window); |
8833 | 8937 |
8834 dw_thread_new((void *)_populate_tree_thread, (void *)window, 0xff); | 8938 dw_thread_new((void *)_populate_tree_thread, (void *)window, 0xff); |