1 /*
2  * PROJECT:     PAINT for ReactOS
3  * LICENSE:     LGPL
4  * FILE:        base/applications/mspaint/textedit.cpp
5  * PURPOSE:     Text editor and font chooser for the text tool
6  * PROGRAMMERS: Benedikt Freisen
7  */
8 
9 /* INCLUDES *********************************************************/
10 
11 #include "precomp.h"
12 
13 /* FUNCTIONS ********************************************************/
14 LRESULT CTextEditWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
15 {
16     /* creating the edit control within the editor window */
17     RECT editControlPos = {0, 0, 0 + 100, 0 + 100};
18     editControl.Create(_T("EDIT"), m_hWnd, editControlPos, NULL,
19                        WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
20                        WS_EX_CLIENTEDGE);
21     return 0;
22 }
23 
24 LRESULT CTextEditWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
25 {
26     RECT clientRect;
27     GetClientRect(&clientRect);
28     editControl.MoveWindow(clientRect.left, clientRect.top, RECT_WIDTH(clientRect), RECT_HEIGHT(clientRect), TRUE);
29     return 0;
30 }
31 
32 LRESULT CTextEditWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
33 {
34     ShowWindow(SW_HIDE);
35     return 0;
36 }
37 
38 LRESULT CTextEditWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
39 {
40     switch(HIWORD(wParam))
41     {
42         case EN_UPDATE:
43         {
44             HeapFree(GetProcessHeap(), 0, textToolText);
45             textToolTextMaxLen = editControl.GetWindowTextLength() + 1;
46             textToolText = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(TCHAR) * textToolTextMaxLen);
47             editControl.GetWindowText(textToolText, textToolTextMaxLen);
48             ForceRefreshSelectionContents();
49             break;
50         }
51     }
52     return 0;
53 }
54 
55 LRESULT CTextEditWindow::OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
56 {
57     ShowWindow((wParam == TOOL_TEXT) ? SW_SHOW : SW_HIDE);
58     return 0;
59 }
60