Rev 124 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | // dialog_comment.cpp |
| 2 | |||
| 3 | #include "../common.h" |
||
| 4 | |||
| 5 | |||
| 6 | // dialog template |
||
| 7 | #define THIS_DIALOG DIALOG_COMMENT |
||
| 8 | |||
| 9 | |||
| 10 | // prototypes of local functions |
||
| 11 | static void StartThread_ThisDialog (void *thread_parms); |
||
| 12 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
| 13 | |||
| 14 | |||
| 15 | void DialogBox_Comment (void) |
||
| 16 | { |
||
| 17 | // helper function to fire up the modeless dialog box |
||
| 18 | |||
| 140 | pmbaty | 19 | is_dialogbox_displayed = true; |
| 1 | pmbaty | 20 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
| 21 | |||
| 22 | return; // return as soon as the thread is fired up |
||
| 23 | } |
||
| 24 | |||
| 25 | |||
| 26 | void DialogBox_Comment_Validated (void) |
||
| 27 | { |
||
| 28 | // callback function called by the main game thread when the dialog box is validated |
||
| 29 | |||
| 30 | // remember this callback is no longer to be called |
||
| 31 | is_dialogbox_comment_validated = false; |
||
| 32 | |||
| 33 | return; // finished |
||
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | static void StartThread_ThisDialog (void *thread_parms) |
||
| 38 | { |
||
| 39 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
| 40 | // to implement a non-modal message box using the Common Controls library. |
||
| 41 | |||
| 42 | // display the dialog box |
||
| 43 | if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) |
||
| 44 | is_dialogbox_comment_validated = true; |
||
| 140 | pmbaty | 45 | is_dialogbox_displayed = false; |
| 1 | pmbaty | 46 | |
| 124 | pmbaty | 47 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
| 1 | pmbaty | 48 | return; // _endthread() implied |
| 49 | } |
||
| 50 | |||
| 51 | |||
| 52 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
| 53 | { |
||
| 54 | // message handler for the dialog box |
||
| 55 | |||
| 56 | unsigned short wParam_hiword; |
||
| 57 | unsigned short wParam_loword; |
||
| 58 | int new_size; |
||
| 59 | |||
| 60 | // filter out the commonly used message values |
||
| 61 | wParam_hiword = HIWORD (wParam); |
||
| 62 | wParam_loword = LOWORD (wParam); |
||
| 63 | |||
| 64 | // have we just fired up this window ? |
||
| 65 | if (message == WM_INITDIALOG) |
||
| 66 | { |
||
| 67 | // center the window |
||
| 68 | CenterWindow (hWnd, hMainWnd); |
||
| 69 | |||
| 70 | // set dialog icons (small one for title bar & big one for task manager) |
||
| 71 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 72 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 73 | |||
| 74 | // set window title and control texts |
||
| 75 | SetWindowText (hWnd, LOCALIZE (L"Comment_Title")); |
||
| 76 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_COMMENT_QUESTION), LOCALIZE (L"Comment_Question")); |
||
| 77 | SetWindowText (GetDlgItem (hWnd, BUTTON_OK), LOCALIZE (L"Button_OK")); |
||
| 78 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_COMMENT_STATUSBAR), LOCALIZE (L"Comment_StatusBar")); |
||
| 79 | |||
| 80 | // set the edit box comment, select all text and send focus to it |
||
| 81 | if ((the_board.move_count > 1) && (the_board.viewed_move >= 1) && (the_board.viewed_move < the_board.move_count) |
||
| 82 | && (the_board.moves[the_board.viewed_move].comment != NULL) && (the_board.moves[the_board.viewed_move].comment[0] != 0)) |
||
| 83 | { |
||
| 84 | SetWindowText (GetDlgItem (hWnd, EDITBOX_COMMENT), the_board.moves[the_board.viewed_move].comment); |
||
| 85 | SendMessage (GetDlgItem (hWnd, EDITBOX_COMMENT), EM_SETSEL, 0, -1); |
||
| 86 | } |
||
| 87 | SetFocus (GetDlgItem (hWnd, EDITBOX_COMMENT)); |
||
| 88 | |||
| 89 | // convert the status bar message to a hyperlink |
||
| 90 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_COMMENT_STATUSBAR)); |
||
| 91 | } |
||
| 92 | |||
| 93 | // else did we click the close button on the title bar ? |
||
| 94 | else if (message == WM_CLOSE) |
||
| 95 | EndDialog (hWnd, 0); // close the dialog box |
||
| 96 | |||
| 97 | // else did we take action on one of the controls ? |
||
| 98 | else if (message == WM_COMMAND) |
||
| 99 | { |
||
| 100 | // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
| 101 | if (wParam_loword == IDCANCEL) |
||
| 102 | EndDialog (hWnd, 0); // close the dialog box |
||
| 103 | |||
| 104 | // else was it the OK button ? |
||
| 105 | else if (wParam_loword == BUTTON_OK) |
||
| 106 | { |
||
| 107 | // grab the edit box comment |
||
| 108 | if ((the_board.move_count > 1) && (the_board.viewed_move >= 1) && (the_board.viewed_move < the_board.move_count)) |
||
| 109 | { |
||
| 110 | // get comment length |
||
| 111 | new_size = GetWindowTextLength (GetDlgItem (hWnd, EDITBOX_COMMENT)); |
||
| 112 | |||
| 113 | // was there text at all ? |
||
| 114 | if (new_size > 0) |
||
| 115 | { |
||
| 116 | // if so, reallocate (add one for the terminator character) and copy comment |
||
| 117 | the_board.moves[the_board.viewed_move].comment = (wchar_t *) SAFE_realloc (the_board.moves[the_board.viewed_move].comment, the_board.moves[the_board.viewed_move].comment_size, new_size + 1, sizeof (wchar_t), false); |
||
| 118 | GetWindowText (GetDlgItem (hWnd, EDITBOX_COMMENT), the_board.moves[the_board.viewed_move].comment, new_size + 1); |
||
| 119 | the_board.moves[the_board.viewed_move].comment_size = new_size + 1; // remember comment size |
||
| 120 | } |
||
| 121 | else |
||
| 122 | { |
||
| 123 | SAFE_free ((void **) &the_board.moves[the_board.viewed_move].comment); // comment was erased, free the memory space used for it |
||
| 124 | the_board.moves[the_board.viewed_move].comment_size = 0; // and reset its size to zero |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | EndDialog (hWnd, 1); // close the dialog box and return OK |
||
| 129 | } |
||
| 130 | |||
| 131 | // else was it the status bar hyperlink ? |
||
| 132 | else if (wParam_loword == STATICTEXT_COMMENT_STATUSBAR) |
||
| 133 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
| 134 | } |
||
| 135 | |||
| 136 | // call the default dialog message processing function to keep things going |
||
| 137 | return (false); |
||
| 138 | } |