| 1 | #include <PrecompiledHeaders.h>
|
|---|
| 2 | #include "Mediator.h"
|
|---|
| 3 | #include "InputWindowPlatform.h"
|
|---|
| 4 | #include "InputWindow.h"
|
|---|
| 5 |
|
|---|
| 6 | const int ICON_SIZE = 16;
|
|---|
| 7 | //const int ICON_SIZE = 32;
|
|---|
| 8 |
|
|---|
| 9 | namespace i3 {
|
|---|
| 10 | using namespace mil;
|
|---|
| 11 |
|
|---|
| 12 | struct ExecuteEvent {
|
|---|
| 13 | };
|
|---|
| 14 |
|
|---|
| 15 | template <>
|
|---|
| 16 | void Delegate::execute(ExecuteEvent& e) {
|
|---|
| 17 | TCHAR prog[200] = {};
|
|---|
| 18 | //GetWindowText(e.hEdit, prog, _countof(prog));
|
|---|
| 19 | // if (_tcscmp(prog, _T("hello")) == 0) {
|
|---|
| 20 | // alert(_("Hello, world!"));
|
|---|
| 21 | // return;
|
|---|
| 22 | // } else if (_tcscmp(prog, _T("exit")) == 0) {
|
|---|
| 23 | // ExitEvent e;
|
|---|
| 24 | // mediator.getInputWindow().post(e, *this);
|
|---|
| 25 | // return;
|
|---|
| 26 | // }
|
|---|
| 27 |
|
|---|
| 28 | /*
|
|---|
| 29 | TCHAR cwd_buf[MAX_PATH] = {};
|
|---|
| 30 | TCHAR* cwd = cwd_buf;
|
|---|
| 31 | DWORD required = GetCurrentDirectory(_countof(cwd_buf), cwd_buf);
|
|---|
| 32 | if (!required) {
|
|---|
| 33 | return; // error
|
|---|
| 34 | } else if (required > _countof(cwd_buf)) {
|
|---|
| 35 | const size_t BUFFER_CHARS = 33000;
|
|---|
| 36 | cwd = (TCHAR*)malloc(BUFFER_CHARS * sizeof(TCHAR));
|
|---|
| 37 | if (!cwd) {
|
|---|
| 38 | return; // error
|
|---|
| 39 | }
|
|---|
| 40 | if (!GetCurrentDirectory(BUFFER_CHARS, cwd)) {
|
|---|
| 41 | free(cwd);
|
|---|
| 42 | return; // error
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | HINSTANCE ins = ShellExecute(
|
|---|
| 48 | NULL, // �e�E�B���h�E�̃n���h��
|
|---|
| 49 | _T("open"), // ���� prog, // �����ۂ̃t�@�C��
|
|---|
| 50 | NULL, // �����p�����[�^
|
|---|
| 51 | cwd, // ���f�B���N�g��
|
|---|
| 52 | SW_SHOW // �\���� |
|---|
| 53 | );
|
|---|
| 54 |
|
|---|
| 55 | if (cwd != cwd_buf) {
|
|---|
| 56 | free(cwd);
|
|---|
| 57 | }
|
|---|
| 58 | if ((INT)ins <= 32) {
|
|---|
| 59 | alert(_T("failure"));
|
|---|
| 60 | }
|
|---|
| 61 | */
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | struct LazyEditFocusEvent {};
|
|---|
| 65 |
|
|---|
| 66 | template <>
|
|---|
| 67 | void InputWindow::execute(LazyEditFocusEvent&) {
|
|---|
| 68 | SetFocus(hEdit);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | struct EditChangedEvent {
|
|---|
| 72 | HWND hEdit;
|
|---|
| 73 | };
|
|---|
| 74 |
|
|---|
| 75 | template <>
|
|---|
| 76 | void Delegate::execute(EditChangedEvent& e) {
|
|---|
| 77 | //MessageBox(NULL, data, data, MB_OK);
|
|---|
| 78 | HICON new_icon = NULL;
|
|---|
| 79 |
|
|---|
| 80 | //TCHAR data[STACKABLE_MAX_PATH] = {};
|
|---|
| 81 | ///int result = GetWindowText(e.hEdit, data, _countof(data));
|
|---|
| 82 | std::vector<TCHAR> data;
|
|---|
| 83 | getChild().mediator.getInputWindow().input_cache.read(data);
|
|---|
| 84 |
|
|---|
| 85 | if (data[0]) {
|
|---|
| 86 | SHFILEINFO sfi = {};
|
|---|
| 87 | DWORD_PTR dwptr = SHGetFileInfo(&data[0], 0, &sfi,
|
|---|
| 88 | sizeof(sfi), SHGFI_ICON | SHGFI_SMALLICON /* | SHGFI_ADDOVERLAYS */ );
|
|---|
| 89 |
|
|---|
| 90 | if (dwptr) { // ok
|
|---|
| 91 | new_icon = sfi.hIcon;
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | BOOST_STATIC_ASSERT(sizeof(HICON) == sizeof(DWORD_PTR));
|
|---|
| 96 | HICON old = getChild().mediator.getInputWindow().hSharedIcon.exchange(new_icon);
|
|---|
| 97 | if (old) {
|
|---|
| 98 | DestroyIcon(old);
|
|---|
| 99 | }
|
|---|
| 100 | HWND hWnd = getChild().mediator.getInputWindow().getWindow();
|
|---|
| 101 | RECT r = {0, 0, 20, 20};
|
|---|
| 102 | InvalidateRect(hWnd, &r, TRUE);
|
|---|
| 103 | UpdateWindow(hWnd);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | template <>
|
|---|
| 107 | InputWindowPlatform<InputWindow>::InputWindowPlatform() :
|
|---|
| 108 | //hSharedEdit(NULL),
|
|---|
| 109 | hSharedIcon(NULL),
|
|---|
| 110 | hEdit(NULL),
|
|---|
| 111 | riched20_dll(NULL) {
|
|---|
| 112 | memset((void*)&layout, 0, sizeof(layout));
|
|---|
| 113 | memset((void*)&ce, 0, sizeof(ce));
|
|---|
| 114 | is_dwm_extend_frame_into_client_area = 0;
|
|---|
| 115 | layout.icon_edit_space = 1;
|
|---|
| 116 | layout.margin_right = 5;
|
|---|
| 117 | layout.nc_width = 200;
|
|---|
| 118 | #ifdef _WIN32_WCE
|
|---|
| 119 | layout.margin_top = 1;
|
|---|
| 120 | layout.margin_bottom = 1;
|
|---|
| 121 | layout.margin_left = 1;
|
|---|
| 122 | #endif
|
|---|
| 123 | icon = LoadIcon(i3::hInstance, _T("IDI_ICON1"));
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | template <>
|
|---|
| 127 | UINT InputWindowPlatform<InputWindow>::OnNCHitTest(HWND hWnd, int x, int y) {
|
|---|
| 128 | POINT p = POINT();
|
|---|
| 129 | p.x = x;
|
|---|
| 130 | p.y = y;
|
|---|
| 131 | if (!ScreenToClient(hWnd, &p)) {
|
|---|
| 132 | return HTCAPTION;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | if (p.x >= layout.width - layout.margin_right - (layout.width - layout.nc_width) / 2) {
|
|---|
| 136 | return HTRIGHT;
|
|---|
| 137 | }
|
|---|
| 138 | return HTCAPTION;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | #ifdef _WIN32_WCE
|
|---|
| 142 | template <>
|
|---|
| 143 | void InputWindowPlatform<InputWindow>::OnLButtonDown(HWND hWnd, BOOL fDoubleClick, int x, int y, UINT keyFlags) {
|
|---|
| 144 | SetCapture(hwnd);
|
|---|
| 145 | RECT rect;
|
|---|
| 146 | GetWindowRect(hwnd, &rect);
|
|---|
| 147 | ce.is_capturing = 1;
|
|---|
| 148 | POINT point;
|
|---|
| 149 | point.x = x;
|
|---|
| 150 | point.y = y;
|
|---|
| 151 | ClientToScreen(hwnd, &point);
|
|---|
| 152 | ce.capture_x = point.x - rect.left;
|
|---|
| 153 | ce.capture_y = point.y - rect.top;
|
|---|
| 154 | SetMsgHandled(false);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | template <>
|
|---|
| 158 | void InputWindowPlatform<InputWindow>::OnMouseMove(HWND hWnd, int x, int y, UINT keyFlags) {
|
|---|
| 159 | if (ce.is_capturing) {
|
|---|
| 160 | POINT point;
|
|---|
| 161 | point.x = x;
|
|---|
| 162 | point.y = y;
|
|---|
| 163 | ClientToScreen(hwnd, &point);
|
|---|
| 164 | SetWindowPos(hwnd, 0,
|
|---|
| 165 | point.x - ce.capture_x, point.y - ce.capture_y,
|
|---|
| 166 | 0, 0,
|
|---|
| 167 | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSIZE);
|
|---|
| 168 | SetMsgHandled(true);
|
|---|
| 169 | }
|
|---|
| 170 | SetMsgHandled(false);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | template <>
|
|---|
| 174 | void InputWindowPlatform<InputWindow>::OnLButtonUp(HWND hWnd, int x, int y, UINT keyFlags) {
|
|---|
| 175 | ReleaseCapture();
|
|---|
| 176 | ce.is_capturing = 0;
|
|---|
| 177 | SetFocus(hEdit);
|
|---|
| 178 | SetMsgHandled(false);
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | #else
|
|---|
| 182 |
|
|---|
| 183 | template <>
|
|---|
| 184 | void InputWindowPlatform<InputWindow>::OnLButtonDown(HWND hWnd, BOOL fDoubleClick, int x, int y, UINT keyFlags) {
|
|---|
| 185 | SetMsgHandled(false);
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | template <>
|
|---|
| 189 | void InputWindowPlatform<InputWindow>::OnMouseMove(HWND hWnd, int x, int y, UINT keyFlags) {
|
|---|
| 190 | SetMsgHandled(false);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | template <>
|
|---|
| 194 | void InputWindowPlatform<InputWindow>::OnLButtonUp(HWND hWnd, int x, int y, UINT keyFlags) {
|
|---|
| 195 | SetFocus(hEdit);
|
|---|
| 196 | SetMsgHandled(false);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | #endif
|
|---|
| 200 |
|
|---|
| 201 | template <>
|
|---|
| 202 | HBRUSH InputWindowPlatform<InputWindow>::OnCtlColorEdit(HWND hWnd, HDC hdc, HWND hWndChild, int type) {
|
|---|
| 203 | SetMsgHandled(false);
|
|---|
| 204 | return 0;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | template <>
|
|---|
| 208 | void InputWindowPlatform<InputWindow>::OnActivate(HWND hWnd, UINT state, HWND hWndActDeact, BOOL fMinimized) {
|
|---|
| 209 | if (state == WA_INACTIVE) {
|
|---|
| 210 | } else {
|
|---|
| 211 | post(LazyEditFocusEvent(), *this);
|
|---|
| 212 | }
|
|---|
| 213 | SetMsgHandled(false);
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | template <>
|
|---|
| 217 | void InputWindowPlatform<InputWindow>::OnActivateApp(HWND hWnd, BOOL fActivate, DWORD dwThreadId) {
|
|---|
| 218 | SetMsgHandled(false);
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | template <>
|
|---|
| 222 | void InputWindowPlatform<InputWindow>::OnSize(HWND hWnd, UINT state, int cx, int cy) {
|
|---|
| 223 | layout.width = layout.width + cx - layout.nc_width;
|
|---|
| 224 | layout.nc_width = cx;
|
|---|
| 225 | int w = layout.nc_width - layout.edit_left - layout.margin_right - layout.margin_left;
|
|---|
| 226 | int h = layout.edit_height;
|
|---|
| 227 | SetWindowPos(hEdit, 0, 0, 0, w, h, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOREDRAW | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
|---|
| 228 | SetMsgHandled(false);
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | template <>
|
|---|
| 232 | InputWindowPlatform<InputWindow>::~InputWindowPlatform() {
|
|---|
| 233 | using namespace std;
|
|---|
| 234 |
|
|---|
| 235 | if (!riched20_dll) {
|
|---|
| 236 | return;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | if (!hEdit || !IsWindow(hEdit)) {
|
|---|
| 240 | return;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | DestroyWindow(hEdit);
|
|---|
| 244 | FreeLibrary(riched20_dll);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | template <>
|
|---|
| 248 | void InputWindowPlatform<InputWindow>::OnClose(HWND hWnd) {
|
|---|
| 249 | if (hEdit && IsWindow(hEdit)) {
|
|---|
| 250 | //TCHAR data[100] = {};
|
|---|
| 251 | //GetWindowText(hEdit, data, _countof(data));
|
|---|
| 252 | //MessageBox(NULL, data, data, MB_OK);
|
|---|
| 253 | DestroyWindow(hEdit);
|
|---|
| 254 | hEdit = NULL;
|
|---|
| 255 | }
|
|---|
| 256 | destroy();
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | template <>
|
|---|
| 260 | void InputWindowPlatform<InputWindow>::OnDestroy(HWND hWnd) {
|
|---|
| 261 | if (IsWindow(hEdit)) {
|
|---|
| 262 | DebugBreak();
|
|---|
| 263 | DestroyWindow(hEdit);
|
|---|
| 264 | hEdit = NULL;
|
|---|
| 265 | }
|
|---|
| 266 | PostQuitMessage(0);
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | template <>
|
|---|
| 270 | void InputWindowPlatform<InputWindow>::OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) {
|
|---|
| 271 | if (hWndCtl == hEdit) {
|
|---|
| 272 | switch (codeNotify) {
|
|---|
| 273 | case EN_CHANGE: {
|
|---|
| 274 | //GetWindowText(e.hEdit, prog, _countof(prog));
|
|---|
| 275 | size_t size_to_copy = 0;
|
|---|
| 276 | std::vector<TCHAR>& local_input_cache = getChild().local_input_cache;
|
|---|
| 277 | local_input_cache[0] = 0;
|
|---|
| 278 | for (;;) {
|
|---|
| 279 | /*
|
|---|
| 280 | http://msdn.microsoft.com/en-us/library/ms633520(VS.85).aspx
|
|---|
| 281 |
|
|---|
| 282 | int GetWindowText(
|
|---|
| 283 | HWND hWnd,
|
|---|
| 284 | LPTSTR lpString,
|
|---|
| 285 | int nMaxCount
|
|---|
| 286 | );
|
|---|
| 287 |
|
|---|
| 288 | Parameters
|
|---|
| 289 | hWnd
|
|---|
| 290 | [in] Handle to the window or control containing the text.
|
|---|
| 291 | lpString
|
|---|
| 292 | [out] Pointer to the buffer that will receive the text.
|
|---|
| 293 | If the string is as long or longer than the buffer,
|
|---|
| 294 | the string is truncated and terminated with
|
|---|
| 295 | a NULL character.
|
|---|
| 296 | nMaxCount
|
|---|
| 297 | [in] Specifies the maximum number of characters to copy
|
|---|
| 298 | to the buffer, including the NULL character.
|
|---|
| 299 | If the text exceeds this limit, it is truncated.
|
|---|
| 300 | */
|
|---|
| 301 |
|
|---|
| 302 | // ex) WindowText[] = "foo";
|
|---|
| 303 | // nMaxCount == 4;
|
|---|
| 304 | // GetWindowText() == 3;
|
|---|
| 305 | //
|
|---|
| 306 | local_input_cache.resize(local_input_cache.capacity());
|
|---|
| 307 | int result = GetWindowText(hEdit, &local_input_cache[0], local_input_cache.size());
|
|---|
| 308 | if (!result) {
|
|---|
| 309 | size_to_copy = 1;
|
|---|
| 310 | break;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | if (static_cast<size_t>((result + 1))
|
|---|
| 314 | < local_input_cache.size()) {
|
|---|
| 315 | size_to_copy = result + 1;
|
|---|
| 316 | local_input_cache[result] = 0;
|
|---|
| 317 | break;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | int length = GetWindowTextLength(hEdit);
|
|---|
| 321 | size_t new_length = static_cast<size_t>(length * 1.2 + 10);
|
|---|
| 322 | if (!length || new_length < local_input_cache.size()) {
|
|---|
| 323 | size_to_copy = 1;
|
|---|
| 324 | break;
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | try {
|
|---|
| 328 | local_input_cache.reserve(new_length);
|
|---|
| 329 | } catch (std::exception& e) {
|
|---|
| 330 | halt << "local_input_cache.reserve()";
|
|---|
| 331 | }
|
|---|
| 332 | }
|
|---|
| 333 | local_input_cache.back() = 0;
|
|---|
| 334 | local_input_cache.resize(size_to_copy);
|
|---|
| 335 | getChild().input_cache.write(local_input_cache);
|
|---|
| 336 |
|
|---|
| 337 | EditChangedEvent e = {};
|
|---|
| 338 | getChild().mediator.getDelegate().post(e, *this);
|
|---|
| 339 | }
|
|---|
| 340 | break;
|
|---|
| 341 | }
|
|---|
| 342 | }
|
|---|
| 343 | SetMsgHandled(false);
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 | template <>
|
|---|
| 348 | void InputWindowPlatform<InputWindow>::OnKeyDown(HWND hWnd, UINT vk, BOOL fDown, int cRepeat, UINT flags) {
|
|---|
| 349 | if (vk == VK_ESCAPE) {
|
|---|
| 350 | PostMessage(hWnd, WM_CLOSE, 0, 0);
|
|---|
| 351 | }
|
|---|
| 352 | }
|
|---|
| 353 |
|
|---|
| 354 | template <>
|
|---|
| 355 | void InputWindowPlatform<InputWindow>::OnNotify(HWND hWnd, int idCtrl, LPNMHDR pnmh) {
|
|---|
| 356 | if (pnmh->hwndFrom != hEdit) {
|
|---|
| 357 | SetMsgHandled(false);
|
|---|
| 358 | return;
|
|---|
| 359 | }
|
|---|
| 360 | switch (pnmh->code) {
|
|---|
| 361 | #ifndef _WIN32_WCE
|
|---|
| 362 | case EN_MSGFILTER: {
|
|---|
| 363 | MSGFILTER* filter = reinterpret_cast<MSGFILTER*>(pnmh);
|
|---|
| 364 | if (filter->msg == WM_KEYDOWN) {
|
|---|
| 365 | if (filter->wParam == VK_ESCAPE) {
|
|---|
| 366 | PostMessage(hWnd, WM_CLOSE, 0, 0);
|
|---|
| 367 | } else if (filter->wParam == VK_RETURN) {
|
|---|
| 368 | ExecuteEvent e;
|
|---|
| 369 | getChild().mediator.getDelegate().post(e, *this);
|
|---|
| 370 | }
|
|---|
| 371 | }
|
|---|
| 372 | }
|
|---|
| 373 | break;
|
|---|
| 374 | #endif
|
|---|
| 375 | default:
|
|---|
| 376 | SetMsgHandled(false);
|
|---|
| 377 | break;
|
|---|
| 378 | }
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | template <>
|
|---|
| 382 | void InputWindowPlatform<InputWindow>::OnPaint(HWND hWnd) {
|
|---|
| 383 | PAINTSTRUCT ps = {};
|
|---|
| 384 | HDC hdc = BeginPaint(hWnd , &ps);
|
|---|
| 385 |
|
|---|
| 386 | if (is_dwm_extend_frame_into_client_area) {
|
|---|
| 387 | FillRect(ps.hdc, &ps.rcPaint, (HBRUSH)GetStockObject(BLACK_BRUSH));
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | //HBRUSH hBrushYellow = NULL;
|
|---|
| 391 | //HBRUSH hOldBrush = NULL;
|
|---|
| 392 | //hBrushYellow= CreateSolidBrush(RGB(255,255,0));
|
|---|
| 393 | //hOldBrush= (HBRUSH)SelectObject(hdc,hBrushYellow); // �u���V��� //Rectangle(hdc, 2, 2, 18, 18);
|
|---|
| 394 | //SelectObject(hdc,hOldBrush); // �u���V���
|
|---|
| 395 | //DeleteObject(hBrushYellow); // �u���V���
|
|---|
| 396 |
|
|---|
| 397 | HICON hMyIcon = hSharedIcon.load();
|
|---|
| 398 | if (!hMyIcon) {
|
|---|
| 399 | TCHAR data[MAX_PATH] = {};
|
|---|
| 400 | //int result = GetWindowText(hEdit, data, _countof(data));
|
|---|
| 401 | //if (!result) {
|
|---|
| 402 | // hMyIcon = icon;
|
|---|
| 403 | //}
|
|---|
| 404 | }
|
|---|
| 405 | //DrawIcon(hdc , 2 , 2 , hMyIcon);
|
|---|
| 406 | //DrawIconEx (hdc, 2, 2, hMyIcon, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT | DI_DEFAULTSIZE);
|
|---|
| 407 | if (hMyIcon) {
|
|---|
| 408 | int left = ((layout.edit_left - layout.icon_edit_space) - ICON_SIZE) / 2 + layout.margin_left;
|
|---|
| 409 | int top = (layout.nc_height - ICON_SIZE) / 2 + layout.margin_top - /* XXX margin ?? */ 1;
|
|---|
| 410 | DrawIconEx(hdc, left, top, hMyIcon, ICON_SIZE, ICON_SIZE, 0, NULL, DI_NORMAL /*| DI_COMPAT*/);
|
|---|
| 411 | }
|
|---|
| 412 | EndPaint(hWnd, &ps);
|
|---|
| 413 | SetMsgHandled(false);
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | template <>
|
|---|
| 417 | size_t InputWindowPlatform<InputWindow>::getEditVerticalMargin() {
|
|---|
| 418 | NONCLIENTMETRICS NCMetrics = {};
|
|---|
| 419 | NCMetrics.cbSize = sizeof(NCMetrics);
|
|---|
| 420 | SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NCMetrics, 0);
|
|---|
| 421 |
|
|---|
| 422 | DWORD dwStyle = (DWORD)GetWindowLongPtr(hEdit, GWL_STYLE);
|
|---|
| 423 | DWORD dwExStyle = (DWORD)GetWindowLongPtr(hEdit, GWL_EXSTYLE);
|
|---|
| 424 |
|
|---|
| 425 | int cyborder = GetSystemMetrics(SM_CYBORDER);
|
|---|
| 426 | int cysizeframe = GetSystemMetrics(SM_CYSIZEFRAME);
|
|---|
| 427 | int cyfixedframe = GetSystemMetrics(SM_CYFIXEDFRAME);
|
|---|
| 428 | int cyedge = GetSystemMetrics(SM_CYEDGE);
|
|---|
| 429 |
|
|---|
| 430 | // debug << boost::basic_format<char>(
|
|---|
| 431 | // "SM_CYBORDER: %d\n"
|
|---|
| 432 | // "SM_CYSIZEFRAME: %d\n"
|
|---|
| 433 | // "SM_CYFIXEDFRAME: %d\n"
|
|---|
| 434 | // "SM_CYEDGE: %d\n"
|
|---|
| 435 | // "NONCLIENTMETRICS::iBorderWidth: %d\n"
|
|---|
| 436 | // //"NONCLIENTMETRICS::iPaddedBorderWidth: %d\n"
|
|---|
| 437 | // //"TEXTMETRIC::tmHeight: %d\n"
|
|---|
| 438 | // //"TEXTMETRIC::tmExternalLeading: %d\n"
|
|---|
| 439 | // )
|
|---|
| 440 | // % cyborder % cysizeframe % cyfixedframe % cyedge % NCMetrics.iBorderWidth
|
|---|
| 441 | // //% NCMetrics.iPaddedBorderWidth
|
|---|
| 442 | // ;
|
|---|
| 443 |
|
|---|
| 444 | //if (richedit_style & WS_BORDER)
|
|---|
| 445 | //{
|
|---|
| 446 | // layout.edit_height += cyedge * 2;
|
|---|
| 447 | // layout.edit_height += 3; // top, bottom padding
|
|---|
| 448 | // layout.edit_height += 1; // user bottom padding
|
|---|
| 449 | //}
|
|---|
| 450 | #ifdef _WIN32_WCE
|
|---|
| 451 | return 2;
|
|---|
| 452 | #endif
|
|---|
| 453 | if (is_dwm_extend_frame_into_client_area) {
|
|---|
| 454 | return 0;
|
|---|
| 455 | } else {
|
|---|
| 456 | return 8;
|
|---|
| 457 | }
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | template <>
|
|---|
| 461 | void InputWindowPlatform<InputWindow>::createGui() {
|
|---|
| 462 | if (getWindow()) {
|
|---|
| 463 | return;
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | // -------------------------------------------------------------
|
|---|
| 467 | // �N���C�A���g�̈��Ńt���[��������邩
|
|---|
| 468 | //
|
|---|
| 469 | if (dll.have_dwmapi_dll) {
|
|---|
| 470 | BOOL enabled = FALSE;
|
|---|
| 471 | HRESULT hr = dll.dll_DwmIsCompositionEnabled(&enabled);
|
|---|
| 472 | if (SUCCEEDED(hr) && enabled) {
|
|---|
| 473 | is_dwm_extend_frame_into_client_area = true;
|
|---|
| 474 | }
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | // -------------------------------------------------------------
|
|---|
| 478 | // �E�B���h�E�쐬
|
|---|
| 479 | //
|
|---|
| 480 |
|
|---|
| 481 | const int DEFAULT_WINDOW_WIDTH = 200;
|
|---|
| 482 | const int DEFAULT_WINDOW_HEIGHT = 200;
|
|---|
| 483 |
|
|---|
| 484 | TCHAR ClassName[] = _T("i3.WNDCLASS::lpszClassName.InputWindow"); // <- rule required
|
|---|
| 485 | int nCmdShow = SW_SHOW;
|
|---|
| 486 |
|
|---|
| 487 | WNDCLASS wc = {};
|
|---|
| 488 | wc.style = CS_HREDRAW | CS_VREDRAW;
|
|---|
| 489 | wc.lpfnWndProc = DefWindowProc;
|
|---|
| 490 | wc.cbClsExtra = 0;
|
|---|
| 491 | wc.cbWndExtra = 0;
|
|---|
| 492 | wc.hInstance = i3::hInstance;
|
|---|
| 493 | wc.hIcon = NULL;//LoadIcon(hCrtInst, MAKEINTRESOURCE(IDI_ICON1));
|
|---|
| 494 | wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|---|
| 495 | wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
|
|---|
| 496 | wc.lpszMenuName = NULL;
|
|---|
| 497 | wc.lpszClassName = ClassName;
|
|---|
| 498 |
|
|---|
| 499 | if (!RegisterClass(&wc)) {
|
|---|
| 500 | // what ..?
|
|---|
| 501 | halt << "lpszClassName: [" << wc.lpszClassName << "], "
|
|---|
| 502 | << "LastError: [" << GetLastError() << "]";
|
|---|
| 503 | //return;
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|
| 506 | DWORD dwDefaultStyle = WS_POPUP;
|
|---|
| 507 | DWORD dwDefaultExStyle = 0;
|
|---|
| 508 | // DWORD dwDefaultExStyle = WS_EX_DLGMODALFRAME;
|
|---|
| 509 | #ifdef _WIN32_WCE
|
|---|
| 510 | dwDefaultStyle |= WS_BORDER;
|
|---|
| 511 | #else
|
|---|
| 512 | dwDefaultStyle |= WS_THICKFRAME;
|
|---|
| 513 | // dwDefaultStyle |= WS_DLGFRAME;
|
|---|
| 514 | // dwDefaultStyle |= WS_BORDER;
|
|---|
| 515 | #endif
|
|---|
| 516 | dwDefaultStyle &= ~WS_CAPTION;
|
|---|
| 517 |
|
|---|
| 518 | HWND hWnd = CreateWindowEx(
|
|---|
| 519 | dwDefaultExStyle,
|
|---|
| 520 | ClassName,
|
|---|
| 521 | _T("i3 Title: InputWindow"), // <- need rule
|
|---|
| 522 | dwDefaultStyle,
|
|---|
| 523 | 30, //CW_USEDEFAULT,
|
|---|
| 524 | 30, //CW_USEDEFAULT,
|
|---|
| 525 | DEFAULT_WINDOW_WIDTH,
|
|---|
| 526 | DEFAULT_WINDOW_HEIGHT,
|
|---|
| 527 | NULL,
|
|---|
| 528 | NULL,
|
|---|
| 529 | i3::hInstance,
|
|---|
| 530 | NULL
|
|---|
| 531 | );
|
|---|
| 532 |
|
|---|
| 533 | if (!IsWindow(hWnd)) {
|
|---|
| 534 | // what ..?
|
|---|
| 535 | halt << hWnd;
|
|---|
| 536 | return;
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | // -------------------------------------------------------------
|
|---|
| 540 | // �G�f�B�b�g�R���g���[���I�� //
|
|---|
| 541 | int richedit_style = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
|
|---|
| 542 | int richedit_exstyle = 0;
|
|---|
| 543 | //richedit_exstyle |= WS_EX_CLIENTEDGE;
|
|---|
| 544 | if (!is_dwm_extend_frame_into_client_area) {
|
|---|
| 545 | //richedit_style |= WS_BORDER;
|
|---|
| 546 | richedit_exstyle |= WS_EX_CLIENTEDGE;
|
|---|
| 547 | }
|
|---|
| 548 | #ifndef _WIN32_WCE
|
|---|
| 549 | TCHAR name[100] = MSFTEDIT_CLASS;
|
|---|
| 550 | HMODULE module = LoadLibrary(_T("Msftedit.dll"));
|
|---|
| 551 | if (!module) {
|
|---|
| 552 | module = LoadLibrary(_T("Riched20.dll"));
|
|---|
| 553 | if (module) {
|
|---|
| 554 | _tcscpy_s(name, RICHEDIT_CLASS);
|
|---|
| 555 | } else {
|
|---|
| 556 | _tcscpy_s(name, _T("EDIT"));
|
|---|
| 557 | }
|
|---|
| 558 | }
|
|---|
| 559 | #else
|
|---|
| 560 | TCHAR name[100] = _T("EDIT");
|
|---|
| 561 | #endif
|
|---|
| 562 |
|
|---|
| 563 | // -------------------------------------------------------------
|
|---|
| 564 | // �t�H���g�ݒ� //
|
|---|
| 565 | HFONT font = NULL;
|
|---|
| 566 | #ifndef _WIN32_WCE
|
|---|
| 567 | NONCLIENTMETRICS NCMetrics = {};
|
|---|
| 568 | NCMetrics.cbSize = sizeof(NCMetrics);
|
|---|
| 569 | if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NCMetrics, 0 )) {
|
|---|
| 570 | font = CreateFontIndirect(&NCMetrics.lfMessageFont);
|
|---|
| 571 | }
|
|---|
| 572 | if (!font) {
|
|---|
| 573 | font = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
|
|---|
| 574 | }
|
|---|
| 575 |
|
|---|
| 576 | #else
|
|---|
| 577 | font = (HFONT)SendMessage(hEdit, WM_GETFONT, NULL, NULL);
|
|---|
| 578 | if (!font) {
|
|---|
| 579 | font = (HFONT)GetStockObject(SYSTEM_FONT);
|
|---|
| 580 | }
|
|---|
| 581 | #endif
|
|---|
| 582 | // -------------------------------------------------------------
|
|---|
| 583 | // �t�H���g���擾
|
|---|
| 584 | //
|
|---|
| 585 | TEXTMETRIC tm = {};
|
|---|
| 586 | {
|
|---|
| 587 | HDC dc = GetDC(hWnd);
|
|---|
| 588 | HFONT old_font = (HFONT)SelectObject(dc, font);
|
|---|
| 589 | GetTextMetrics(dc, &tm);
|
|---|
| 590 | SelectObject(dc, old_font);
|
|---|
| 591 | int result = ReleaseDC(hWnd, dc);
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | // -------------------------------------------------------------
|
|---|
| 595 | // �E�B���h�E�T�C�Y�̍Đݒ� //
|
|---|
| 596 | {
|
|---|
| 597 | layout.edit_height += tm.tmHeight + tm.tmExternalLeading + getEditVerticalMargin();
|
|---|
| 598 | if (layout.edit_height > ICON_SIZE) {
|
|---|
| 599 | layout.nc_height = layout.edit_height;
|
|---|
| 600 | layout.edit_left = layout.icon_edit_space + layout.edit_height;
|
|---|
| 601 | } else {
|
|---|
| 602 | layout.nc_height = ICON_SIZE;
|
|---|
| 603 | layout.edit_left = layout.icon_edit_space + ICON_SIZE;
|
|---|
| 604 | }
|
|---|
| 605 | layout.nc_height += layout.margin_top;
|
|---|
| 606 | layout.nc_height += layout.margin_bottom;
|
|---|
| 607 |
|
|---|
| 608 | layout.nc_width += layout.margin_left;
|
|---|
| 609 | layout.nc_width += layout.margin_right;
|
|---|
| 610 |
|
|---|
| 611 | DWORD dwStyle = (DWORD)GetWindowLongPtr(hWnd, GWL_STYLE);
|
|---|
| 612 | DWORD dwExStyle = (DWORD)GetWindowLongPtr(hWnd, GWL_EXSTYLE);
|
|---|
| 613 | RECT r;
|
|---|
| 614 | r.top = 0;
|
|---|
| 615 | r.left = 0;
|
|---|
| 616 | r.right = layout.nc_width;
|
|---|
| 617 | r.bottom = layout.nc_height;
|
|---|
| 618 | //r.right = 200;
|
|---|
| 619 | //r.bottom = 200;
|
|---|
| 620 | BOOL b = AdjustWindowRectEx(&r, dwStyle, FALSE, dwExStyle);
|
|---|
| 621 | if (!b) {
|
|---|
| 622 | halt << "AdjustWindowRectEx() failed";
|
|---|
| 623 | }
|
|---|
| 624 | {
|
|---|
| 625 | layout.width = r.right - r.left;
|
|---|
| 626 | layout.height = r.bottom - r.top;
|
|---|
| 627 | SetWindowPos(hWnd, 0, 0, 0, layout.width, layout.height, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE);
|
|---|
| 628 | }
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 | // -------------------------------------------------------------
|
|---|
| 632 | // �E�B���h�E���� //
|
|---|
| 633 |
|
|---|
| 634 | //SetLayeredWindowAttributes(hWnd, 0, 200, LWA_ALPHA);
|
|---|
| 635 | if (is_dwm_extend_frame_into_client_area) {
|
|---|
| 636 | HRESULT hr = S_OK;
|
|---|
| 637 | int t = (layout.nc_height - layout.edit_height) / 2;
|
|---|
| 638 | int b = layout.edit_height;
|
|---|
| 639 | MARGINS margins = {
|
|---|
| 640 | layout.margin_left + layout.edit_left, // left
|
|---|
| 641 | layout.margin_right, // right
|
|---|
| 642 | (layout.nc_height - layout.edit_height) / 2, //layout.margin_top, // top
|
|---|
| 643 | (layout.nc_height - layout.edit_height) / 2 //layout.margin_bottom, // bottom
|
|---|
| 644 |
|
|---|
| 645 | };
|
|---|
| 646 | hr = dll.dll_DwmExtendFrameIntoClientArea(hWnd,&margins);
|
|---|
| 647 |
|
|---|
| 648 | /*
|
|---|
| 649 | DWM_BLURBEHIND bb = {};
|
|---|
| 650 | bb.dwFlags = DWM_BB_ENABLE;
|
|---|
| 651 | bb.fEnable = true;
|
|---|
| 652 | hr = dll.dll_DwmEnableBlurBehindWindow(hWnd, &bb);
|
|---|
| 653 |
|
|---|
| 654 | DWORD color = 0;
|
|---|
| 655 | BOOL blend = FALSE;
|
|---|
| 656 | if (SUCCEEDED(hr))
|
|---|
| 657 | {
|
|---|
| 658 | hr = dll.dll_DwmGetColorizationColor(&color, &blend);
|
|---|
| 659 | if (SUCCEEDED(hr))
|
|---|
| 660 | {
|
|---|
| 661 | BYTE a = (color & 0xFF000000) >> 24;
|
|---|
| 662 | BYTE r = (color & 0x00FF0000) >> 16;
|
|---|
| 663 | BYTE g = (color & 0x0000FF00) >> 8;
|
|---|
| 664 | BYTE b = (color & 0x000000FF);
|
|---|
| 665 |
|
|---|
| 666 | //a = 255 - ((255 - a) * 0.3);
|
|---|
| 667 | a = 0x80;
|
|---|
| 668 | r = 255;
|
|---|
| 669 | g = 255;
|
|---|
| 670 | b = 0;
|
|---|
| 671 | //r = 255 - ((255 - r) * 0.5);
|
|---|
| 672 | //g = 255 - ((255 - g) * 0.5);
|
|---|
| 673 | //b = 255 - ((255 - b) * 0.5);
|
|---|
| 674 |
|
|---|
| 675 | DWORD color2 = (a << 24) | (b << 16) | (g << 8) | r ;
|
|---|
| 676 | //SendMessage(hEdit, EM_SETBKGNDCOLOR, (WPARAM)0, (LPARAM)(color2));
|
|---|
| 677 | //printf("");
|
|---|
| 678 | }
|
|---|
| 679 | }
|
|---|
| 680 | */
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 | // -------------------------------------------------------------
|
|---|
| 685 | // �G�f�B�b�g�R���g���[���쐬
|
|---|
| 686 | //
|
|---|
| 687 | int x = layout.margin_left + layout.edit_left;
|
|---|
| 688 | int y = (layout.nc_height - layout.edit_height) / 2;
|
|---|
| 689 | hEdit = CreateWindowEx(
|
|---|
| 690 | richedit_exstyle,
|
|---|
| 691 | name,
|
|---|
| 692 | //_T("RICHEDIT"),
|
|---|
| 693 | //_T("EDIT"),
|
|---|
| 694 | _T(""),
|
|---|
| 695 | richedit_style,
|
|---|
| 696 | x,
|
|---|
| 697 | y,
|
|---|
| 698 | 100,
|
|---|
| 699 | 100,
|
|---|
| 700 | hWnd,
|
|---|
| 701 | NULL,//reinterpret_cast<HMENU>(IDC_EDIT),
|
|---|
| 702 | i3::hInstance,
|
|---|
| 703 | NULL
|
|---|
| 704 | );
|
|---|
| 705 | SendMessage(hEdit, WM_SETFONT, (WPARAM)font, (LPARAM)FALSE);
|
|---|
| 706 | #ifndef _WIN32_WCE
|
|---|
| 707 | LRESULT dwEvent = SendMessage(hEdit, EM_GETEVENTMASK, 0, 0);
|
|---|
| 708 | dwEvent |= ENM_MOUSEEVENTS | ENM_KEYEVENTS | ENM_CHANGE;
|
|---|
| 709 | SendMessage(hEdit, EM_SETEVENTMASK, 0, (LPARAM)dwEvent);
|
|---|
| 710 | #endif
|
|---|
| 711 |
|
|---|
| 712 | OnSize(hWnd, SIZE_RESTORED, layout.nc_width, layout.nc_height);
|
|---|
| 713 |
|
|---|
| 714 | // -------------------------------------------------------------
|
|---|
| 715 | // �^�X�N�g���C�p�̃A�C�R���̍쐬
|
|---|
| 716 | //
|
|---|
| 717 | NOTIFYICONDATA connectingIcon = {};
|
|---|
| 718 | connectingIcon.cbSize = sizeof(connectingIcon);
|
|---|
| 719 | connectingIcon.hIcon = icon;
|
|---|
| 720 | connectingIcon.hWnd = hWnd;
|
|---|
| 721 | connectingIcon.uCallbackMessage = WM_USER + 10;
|
|---|
| 722 | connectingIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
|
|---|
| 723 | _tcscpy_s(connectingIcon.szTip, _T(""));
|
|---|
| 724 | Shell_NotifyIcon(NIM_ADD, &connectingIcon);
|
|---|
| 725 |
|
|---|
| 726 | // -------------------------------------------------------------
|
|---|
| 727 | // �E�B���h�E����ƗL�� //
|
|---|
| 728 | //UpdateWindow(hEdit);
|
|---|
| 729 | SetFocus(hEdit);
|
|---|
| 730 | setWindow(hWnd);
|
|---|
| 731 | //hSharedEdit.store(hEdit);
|
|---|
| 732 | //InvalidateRect(hWnd, NULL, FALSE);
|
|---|
| 733 | UpdateWindow(hWnd);
|
|---|
| 734 | //ShowWindow(hEdit, SW_HIDE);
|
|---|
| 735 | ShowWindow(hWnd, nCmdShow);
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | }
|
|---|