-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextEdit.cpp
141 lines (112 loc) · 3.11 KB
/
TextEdit.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// TextEdit.cpp
#include "TextEdit.h"
#include "TextView.h"
#include "AccessibleTextView.h"
#include <Windowsx.h>
static inline POINT MakePOINT( LPARAM lParam )
{
POINT point = { GET_X_LPARAM( lParam ), GET_Y_LPARAM( lParam ) };
return point;
}
static LRESULT ProcessWindowMsg( TextView* view, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch ( msg )
{
case WM_CREATE:
return view->OnCreate( reinterpret_cast<LPCREATESTRUCT>( lParam ) );
case WM_PAINT:
view->OnPaint();
return 0;
case WM_SIZE:
view->OnSize( wParam, GET_X_LPARAM( lParam ), GET_Y_LPARAM( lParam ) );
return 0;
case WM_CHAR:
view->OnChar( wParam, LOWORD( lParam ), HIWORD( lParam ) );
return 0;
case WM_KEYDOWN:
view->OnKeyDown( wParam, LOWORD( lParam ), HIWORD( lParam ) );
return 0;
case WM_LBUTTONDBLCLK:
view->OnLButtonDblClk( MakePOINT( lParam ) );
return 0;
case WM_LBUTTONDOWN:
view->OnLButtonDown( MakePOINT( lParam ) );
return 0;
case WM_LBUTTONUP:
view->OnLButtonUp( MakePOINT( lParam ) );
return 0;
case WM_MOUSEMOVE:
view->OnMouseMove( MakePOINT( lParam ) );
return 0;
case WM_CAPTURECHANGED:
view->OnCaptureChanged();
return 0;
case WM_MOUSEACTIVATE:
return view->OnMouseActivate();
case WM_SETCURSOR:
view->OnSetCursor();
return TRUE;
case WM_SETFOCUS:
view->OnSetFocus( reinterpret_cast<HWND>( wParam ) );
return 0;
case WM_KILLFOCUS:
view->OnKillFocus( reinterpret_cast<HWND>( wParam ) );
return 0;
case WM_VSCROLL:
view->OnVScroll( LOWORD( wParam ) );
return 0;
case WM_HSCROLL:
view->OnHScroll( LOWORD( wParam ) );
return 0;
case WM_MOUSEWHEEL:
view->OnMouseWheel( (short) HIWORD( wParam ) );
return 0;
case WM_TIMER:
view->OnTimer( static_cast<UINT_PTR>( wParam ) );
return 0;
case WM_GETOBJECT:
AccessibleTextView* accessibleTextView = new AccessibleTextView( *view );
LRESULT result = LresultFromObject( IID_IAccessible, wParam, static_cast<IUnknown*>( accessibleTextView ) );
accessibleTextView->Release();
return result;
}
return DefWindowProc( hwnd, msg, wParam, lParam );
}
LRESULT CALLBACK TextEditWndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
if ( msg == WM_NCCREATE )
{
try
{
SetWindowLongPtr( hwnd, 0, reinterpret_cast<LONG_PTR>( new TextView( hwnd ) ) );
return TRUE;
}
catch ( std::bad_alloc& )
{
return FALSE;
}
}
TextView* view = reinterpret_cast<TextView*>( GetWindowLongPtr( hwnd, 0 ) );
if ( msg == WM_NCDESTROY )
{
delete view;
SetWindowLongPtr( hwnd, 0, 0 );
return 0;
}
if ( view != 0 )
return ProcessWindowMsg( view, hwnd, msg, wParam, lParam );
return DefWindowProc( hwnd, msg, wParam, lParam );
}
extern "C"
{
BOOL RegisterTextEdit( HINSTANCE hInstance )
{
WNDCLASSEX wcx = { sizeof wcx };
wcx.style = CS_DBLCLKS;
wcx.lpfnWndProc = TextEditWndProc;
wcx.cbWndExtra = sizeof( TextView* );
wcx.hInstance = hInstance;
wcx.lpszClassName = WC_TEXTEDIT;
return RegisterClassEx( &wcx ) ? TRUE : FALSE;
}
}