OpenMoHAA 0.82.1
Loading...
Searching...
No Matches
uinotepad.h
1/*
2===========================================================================
3Copyright (C) 2024 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23#pragma once
24
25class UINotepad;
26
27class UINotepadEdit : public UIMultiLineEdit
28{
29protected:
30 UINotepad *m_notepad;
31
32public:
33 CLASS_PROTOTYPE(UINotepadEdit);
34
35public:
36 UINotepadEdit();
37
38 void CharEvent(int ch) override;
39 void setNotepad(UINotepad *notepad);
40 bool GotoLine(int line);
41 bool FindText(const char *text, int offsetFromSel);
42 void MousePressed(Event *ev);
43};
44
45typedef enum {
46 STATE_NONE,
47 STATE_GOTO_LINE,
48 STATE_FIND_TEXT,
49 STATE_SAVE_AS,
50 STATE_TIMED_MESSAGE,
51 STATE_CONFIRMCLOSE
52} state_t;
53
54typedef struct textinput_s {
55 str text;
56} textinput_t;
57
58typedef struct timedmessage_s {
59 int die;
60 str text;
61} timedmessage_t;
62
63typedef struct ctrlevent_s {
64 char ch;
65 Event *ev;
66} ctrlevent_t;
67
68class UINotepad : public UIFloatingWindow
69{
70 friend class UINotepadEdit; // UINotepadEdit needs m_state
71
72private:
74
75protected:
76 state_t m_state;
77 textinput_s m_textinput;
78 timedmessage_s m_timedmessage;
79 str m_lastfind;
80 str m_filename;
81 UINotepadEdit *m_edit;
82 UIStatusBar *m_status;
83 class UIPulldownMenu *m_menu;
84
85public:
86 CLASS_PROTOTYPE(UINotepad);
87
88protected:
89 void TimeMessage(const char *message, int howlong);
90
91public:
92 UINotepad();
93 ~UINotepad();
94
95 bool OpenFile(const char *filename);
96 bool Create(UIWidget *parent, UIRect2D& rect, const char *filename);
97 void ChildSizeChanged(Event *ev);
98 void SaveAs(Event *ev);
99 void Save(Event *ev);
100 void Open(Event *ev);
101 void OpenFile(Event *ev);
102 void ClosePressed(Event *ev);
103 void OnFind(Event *ev);
104 void OnGoto(Event *ev);
105 void OnCopy(Event *ev);
106 void OnPaste(Event *ev);
107 void OnCut(Event *ev);
108 bool ProcessControlEvents(int ch);
109 bool ProcessCharEvent(int ch);
110 void Draw(void) override;
111 void setFileName(const char *filename);
112};
113
114bool UI_LoadNotepadFile(const char *filename);
Definition container.h:85
Definition listener.h:246
Definition uinotepad.h:69
Definition uipulldownmenu.h:56
Definition uirect2d.h:29
Definition uistatus.h:64
Definition str.h:77
Definition uinotepad.h:63
Definition uinotepad.h:54
Definition uinotepad.h:58