-
Notifications
You must be signed in to change notification settings - Fork 37
/
ImeWindow.cpp
103 lines (88 loc) · 2.44 KB
/
ImeWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Copyright (C) 2013 Hong Jen Yee (PCMan) <[email protected]>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA 02110-1301, USA.
//
#include "ImeWindow.h"
namespace Ime {
ImeWindow::ImeWindow(TextService* service):
textService_(service) {
if(service->isImmersive()) { // windows 8 app mode
margin_ = 10;
}
else { // desktop mode
margin_ = 5;
}
font_ = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
/*
LOGFONT lf;
GetObject(font_, sizeof(lf), &lf);
lf.lfHeight = fontSize_;
lf.lfWeight = FW_NORMAL;
font_ = CreateFontIndirect(&lf);
*/
}
ImeWindow::~ImeWindow(void) {
}
void ImeWindow::onLButtonDown(WPARAM wp, LPARAM lp) {
oldPos = MAKEPOINTS(lp);
SetCapture(hwnd_);
}
void ImeWindow::onLButtonUp(WPARAM wp, LPARAM lp) {
ReleaseCapture();
}
void ImeWindow::onMouseMove(WPARAM wp, LPARAM lp) {
if(GetCapture() != hwnd_)
return;
POINTS pt = MAKEPOINTS(lp);
RECT rc;
GetWindowRect(hwnd_, &rc);
OffsetRect( &rc, (pt.x - oldPos.x), (pt.y - oldPos.y) );
move(rc.left, rc.top);
}
void ImeWindow::move(int x, int y) {
int w, h;
size(&w, &h);
// ensure that the window does not fall outside of the screen.
RECT rc = {x, y, x + w, y + h}; // current window rect
// get the nearest monitor
HMONITOR monitor = ::MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof(mi);
if(GetMonitorInfo(monitor, &mi))
rc = mi.rcWork;
if(x < rc.left)
x = rc.left;
else if((x + w) > rc.right)
x = rc.right - w;
if(y < rc.top)
y = rc.top;
else if((y + h) > rc.bottom)
y = rc.bottom - h;
::MoveWindow(hwnd_, x, y, w, h, TRUE);
}
void ImeWindow::setFont(HFONT f) {
if(font_)
::DeleteObject(font_);
font_ = f;
recalculateSize();
if(isVisible())
::InvalidateRect(hwnd_, NULL, TRUE);
}
// virtual
void ImeWindow::recalculateSize() {
}
} // namespace Ime