Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Message boxes |
| 3 | * |
| 4 | * Copyright 1995 Bernd Schmidt |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "windows.h" |
| 9 | #include "dlgs.h" |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame^] | 10 | #include "module.h" |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 11 | #include "win.h" |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 12 | #include "resource.h" |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 13 | #include "task.h" |
| 14 | |
| 15 | typedef struct { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 16 | LPCSTR title; |
| 17 | LPCSTR text; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 18 | WORD type; |
| 19 | } MSGBOX, *LPMSGBOX; |
| 20 | |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 21 | LRESULT SystemMessageBoxProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 22 | { |
| 23 | LPMSGBOX lpmb; |
| 24 | RECT rect, textrect; |
| 25 | HWND hItem; |
| 26 | HDC hdc; |
| 27 | LONG lRet; |
| 28 | int i, buttons, bwidth, bheight, theight, wwidth, bpos; |
| 29 | int borheight, iheight, tiheight; |
| 30 | |
| 31 | switch(message) { |
| 32 | case WM_INITDIALOG: |
| 33 | lpmb = (LPMSGBOX)lParam; |
| 34 | if (lpmb->title != NULL) { |
| 35 | SetWindowText(hwnd, lpmb->title); |
| 36 | } |
| 37 | SetWindowText(GetDlgItem(hwnd, 100), lpmb->text); |
| 38 | /* Hide not selected buttons */ |
| 39 | switch(lpmb->type & MB_TYPEMASK) { |
| 40 | case MB_OK: |
| 41 | ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE); |
| 42 | /* fall through */ |
| 43 | case MB_OKCANCEL: |
| 44 | ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE); |
| 45 | ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE); |
| 46 | ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE); |
| 47 | ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE); |
| 48 | ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE); |
| 49 | break; |
| 50 | case MB_ABORTRETRYIGNORE: |
| 51 | ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE); |
| 52 | ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE); |
| 53 | ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE); |
| 54 | ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE); |
| 55 | break; |
| 56 | case MB_YESNO: |
| 57 | ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE); |
| 58 | /* fall through */ |
| 59 | case MB_YESNOCANCEL: |
| 60 | ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE); |
| 61 | ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE); |
| 62 | ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE); |
| 63 | ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE); |
| 64 | break; |
| 65 | } |
| 66 | /* Set the icon */ |
| 67 | switch(lpmb->type & MB_ICONMASK) { |
| 68 | case MB_ICONEXCLAMATION: |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 69 | SendDlgItemMessage(hwnd, stc1, STM_SETICON, |
| 70 | (WPARAM)LoadIcon(0, IDI_EXCLAMATION), 0); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 71 | break; |
| 72 | case MB_ICONQUESTION: |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 73 | SendDlgItemMessage(hwnd, stc1, STM_SETICON, |
| 74 | (WPARAM)LoadIcon(0, IDI_QUESTION), 0); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 75 | break; |
| 76 | case MB_ICONASTERISK: |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 77 | SendDlgItemMessage(hwnd, stc1, STM_SETICON, |
| 78 | (WPARAM)LoadIcon(0, IDI_ASTERISK), 0); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 79 | break; |
| 80 | case MB_ICONHAND: |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 81 | default: |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 82 | SendDlgItemMessage(hwnd, stc1, STM_SETICON, |
| 83 | (WPARAM)LoadIcon(0, IDI_HAND), 0); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 84 | break; |
| 85 | } |
| 86 | |
| 87 | /* Position everything */ |
| 88 | GetWindowRect(hwnd, &rect); |
| 89 | borheight = rect.bottom - rect.top; |
| 90 | wwidth = rect.right - rect.left; |
| 91 | GetClientRect(hwnd, &rect); |
| 92 | borheight -= rect.bottom - rect.top; |
| 93 | |
| 94 | /* Get the icon height */ |
| 95 | GetWindowRect(GetDlgItem(hwnd, 1088), &rect); |
| 96 | iheight = rect.bottom - rect.top; |
| 97 | |
| 98 | /* Get the number of visible buttons and their width */ |
| 99 | GetWindowRect(GetDlgItem(hwnd, 2), &rect); |
| 100 | bheight = rect.bottom - rect.top; |
| 101 | bwidth = rect.left; |
| 102 | GetWindowRect(GetDlgItem(hwnd, 1), &rect); |
| 103 | bwidth -= rect.left; |
| 104 | for (buttons = 0, i = 1; i < 8; i++) { |
| 105 | hItem = GetDlgItem(hwnd, i); |
| 106 | if (GetWindowLong(hItem, GWL_STYLE) & WS_VISIBLE) { |
| 107 | buttons++; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /* Get the text size */ |
| 112 | hItem = GetDlgItem(hwnd, 100); |
| 113 | GetWindowRect(hItem, &textrect); |
| 114 | MapWindowPoints(0, hwnd, (LPPOINT)&textrect, 2); |
| 115 | |
| 116 | GetClientRect(hItem, &rect); |
| 117 | hdc = GetDC(hItem); |
| 118 | lRet = DrawText(hdc, lpmb->text, -1, &rect, |
| 119 | DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT); |
| 120 | theight = rect.bottom - rect.top; |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 121 | tiheight = 16 + MAX(iheight, theight); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 122 | ReleaseDC(hItem, hdc); |
| 123 | |
| 124 | /* Position the text */ |
| 125 | SetWindowPos(hItem, 0, textrect.left, (tiheight - theight) / 2, |
| 126 | rect.right - rect.left, theight, |
| 127 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); |
| 128 | |
| 129 | /* Position the icon */ |
| 130 | hItem = GetDlgItem(hwnd, 1088); |
| 131 | GetWindowRect(hItem, &rect); |
| 132 | MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2); |
| 133 | SetWindowPos(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0, |
| 134 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); |
| 135 | |
| 136 | /* Resize the window */ |
| 137 | SetWindowPos(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight, |
| 138 | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); |
| 139 | |
| 140 | /* Position the buttons */ |
| 141 | bpos = (wwidth - bwidth * buttons) / 2; |
| 142 | GetWindowRect(GetDlgItem(hwnd, 1), &rect); |
| 143 | for (buttons = i = 0; i < 7; i++) { |
| 144 | /* some arithmetic to get the right order for YesNoCancel windows */ |
| 145 | hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1); |
| 146 | if (GetWindowLong(hItem, GWL_STYLE) & WS_VISIBLE) { |
| 147 | if (buttons++ == ((lpmb->type & MB_DEFMASK) >> 8)) { |
| 148 | SetFocus(hItem); |
| 149 | SendMessage(hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE); |
| 150 | } |
| 151 | SetWindowPos(hItem, 0, bpos, tiheight, 0, 0, |
| 152 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); |
| 153 | bpos += bwidth; |
| 154 | } |
| 155 | } |
| 156 | return 0; |
| 157 | break; |
| 158 | |
| 159 | case WM_COMMAND: |
| 160 | switch (wParam) { |
| 161 | case IDOK: |
| 162 | case IDCANCEL: |
| 163 | case IDABORT: |
| 164 | case IDRETRY: |
| 165 | case IDIGNORE: |
| 166 | case IDYES: |
| 167 | case IDNO: |
| 168 | EndDialog(hwnd, wParam); |
| 169 | break; |
| 170 | } |
| 171 | break; |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /************************************************************************** |
| 177 | * MessageBox [USER.1] |
| 178 | */ |
| 179 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 180 | int MessageBox(HWND hWnd, LPCSTR text, LPCSTR title, WORD type) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 181 | { |
Alexandre Julliard | ff8331e | 1995-09-18 11:19:54 +0000 | [diff] [blame] | 182 | HANDLE handle; |
| 183 | MSGBOX mbox; |
| 184 | int ret; |
| 185 | DWORD WineProc,Win16Proc,Win32Proc; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 186 | |
Alexandre Julliard | ff8331e | 1995-09-18 11:19:54 +0000 | [diff] [blame] | 187 | mbox.title = title; |
| 188 | mbox.text = text; |
| 189 | mbox.type = type; |
| 190 | |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 191 | handle = SYSRES_LoadResource( SYSRES_DIALOG_MSGBOX ); |
Alexandre Julliard | ff8331e | 1995-09-18 11:19:54 +0000 | [diff] [blame] | 192 | if (!handle) return 0; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 193 | ret = DialogBoxIndirectParam( WIN_GetWindowInstance(hWnd), |
Alexandre Julliard | ff8331e | 1995-09-18 11:19:54 +0000 | [diff] [blame] | 194 | handle, hWnd, |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame^] | 195 | MODULE_GetWndProcEntry16("SystemMessageBoxProc"), |
Alexandre Julliard | ff8331e | 1995-09-18 11:19:54 +0000 | [diff] [blame] | 196 | (LONG)&mbox ); |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 197 | SYSRES_FreeResource( handle ); |
Alexandre Julliard | ff8331e | 1995-09-18 11:19:54 +0000 | [diff] [blame] | 198 | return ret; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /************************************************************************** |
| 202 | * FatalAppExit [USER.137] |
| 203 | */ |
| 204 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 205 | void FatalAppExit(UINT fuAction, LPCSTR str) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 206 | { |
| 207 | MessageBox(0, str, NULL, MB_SYSTEMMODAL | MB_OK); |
| 208 | TASK_KillCurrentTask(0); |
| 209 | } |