-
Notifications
You must be signed in to change notification settings - Fork 4
/
LayoutWidget.h
261 lines (199 loc) · 6.78 KB
/
LayoutWidget.h
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/******************************************************************************
LayoutWidget.h
Copyright (C) 2023 by John Lindal.
******************************************************************************/
#ifndef _H_LayoutWidget
#define _H_LayoutWidget
#include <jx-af/jx/JXWidget.h>
class JStringManager;
class LayoutContainer;
class WidgetParametersDialog;
class LayoutWidget : public JXWidget
{
public:
LayoutWidget(const bool wantsInput, LayoutContainer* layout,
const HSizingOption hSizing, const VSizingOption vSizing,
const JCoordinate x, const JCoordinate y,
const JCoordinate w, const JCoordinate h);
LayoutWidget(std::istream& input, const JFileVersion vers, LayoutContainer* layout,
const HSizingOption hSizing, const VSizingOption vSizing,
const JCoordinate x, const JCoordinate y,
const JCoordinate w, const JCoordinate h);
~LayoutWidget() override;
virtual void StreamOut(std::ostream& output) const;
LayoutContainer* GetParentContainer() const;
virtual bool GetLayoutContainer(const JIndex index, LayoutContainer** layout) const;
virtual bool GetLayoutContainerIndex(const LayoutWidget* widget, JIndex* index) const;
const JString& GetVarName(bool* isMemberData, bool* isPredeclared) const;
void SetVarName(const JString& name, const bool isMember,
const bool isPredeclared);
bool IsSelected() const;
void SetSelected(const bool on);
bool WantsInput() const;
bool GetTabIndex(JIndex* i) const;
void SetTabIndex(const JIndex i);
JPoint GetDragStartPointGlobal() const;
void EditConfiguration(const bool createUndo = true);
bool GenerateCode(std::ostream& output, const JString& indent,
JPtrArray<JString>* objTypes,
JPtrArray<JString>* objNames,
JArray<bool>* isMemberVar,
JStringManager* stringdb) const;
virtual void PrepareToGenerateCode(std::ostream& output, const JString& indent,
JStringManager* stringdb) const;
virtual void GenerateCodeFinished(std::ostream& output, const JString& indent,
JStringManager* stringdb) const;
void PrepareToAcceptDrag();
virtual JString GetEnclosureName(const LayoutWidget* widget) const;
JString ToString() const override;
protected:
void SetWantsInput(const bool wantsInput);
virtual JString GetClassName() const = 0;
virtual JString GetCtor() const;
virtual void PrintCtorArgsWithComma(std::ostream& output,
const JString& varName,
JStringManager* stringdb) const;
virtual void PrintConfiguration(std::ostream& output,
const JString& indent,
const JString& varName,
JStringManager* stringdb) const;
virtual bool WaitForCodeDependency(const JPtrArray<JString>& objNames) const;
void PrintStringForArg(const JString& text, const JString& baseID,
JStringManager* stringdb, std::ostream& output) const;
void PrintStringIDForArg(const JString& text, const JString& baseID,
JStringManager* stringdb, std::ostream& output) const;
virtual void AddPanels(WidgetParametersDialog* dlog);
virtual void SavePanelData();
void DrawOver(JXWindowPainter& p, const JRect& rect) override;
void AdjustCursor(const JPoint& pt, const JXKeyModifiers& modifiers) override;
bool StealMouse(const int eventType, const JPoint& ptG,
const JXMouseButton button,
const unsigned int state) override;
void HandleMouseDown(const JPoint& pt, const JXMouseButton button,
const JSize clickCount,
const JXButtonStates& buttonStates,
const JXKeyModifiers& modifiers) override;
void HandleMouseDrag(const JPoint& pt, const JXButtonStates& buttonStates,
const JXKeyModifiers& modifiers) override;
void HandleMouseUp(const JPoint& pt, const JXMouseButton button,
const JXButtonStates& buttonStates,
const JXKeyModifiers& modifiers) override;
Atom GetDNDAction(const JXContainer* target,
const JXButtonStates& buttonStates,
const JXKeyModifiers& modifiers) override;
void DNDFinish(const bool isDrop, const JXContainer* target) override;
virtual bool IsDNDLayoutTarget() const;
private:
enum
{
kTopLeftHandle,
kTopHandle,
kTopRightHandle,
kRightHandle,
kBottomRightHandle,
kBottomHandle,
kBottomLeftHandle,
kLeftHandle,
kHandleCount
};
private:
LayoutContainer* itsParent;
JString itsVarName; // can be empty
bool itsIsMemberVarFlag;
bool itsIsPredeclaredVarFlag;
bool itsSelectedFlag;
JIndex itsTabIndex;
// used during dragging
JPoint itsStartPtG;
JPoint itsPrevPtG;
JSize itsLastClickCount;
bool itsWaitingForDragFlag;
bool itsClearIfNotDNDFlag;
bool itsExpectingDragFlag; // receive drag from child LayoutContainer
time_t itsLastExpectingTime;
JSize itsExpectingClickCount;
// used during resize drag
bool itsIsResizingFlag;
JIndex itsResizeDragType;
JRect itsHandles[ kHandleCount ];
JCursorIndex itsCursors[ kHandleCount ];
private:
void LayoutWidgetX();
};
/******************************************************************************
GetParentContainer
******************************************************************************/
inline LayoutContainer*
LayoutWidget::GetParentContainer()
const
{
return itsParent;
}
/******************************************************************************
Variable name
******************************************************************************/
inline const JString&
LayoutWidget::GetVarName
(
bool* isMemberData,
bool* isPredeclared
)
const
{
*isMemberData = itsIsMemberVarFlag;
*isPredeclared = itsIsPredeclaredVarFlag;
return itsVarName;
}
inline void
LayoutWidget::SetVarName
(
const JString& name,
const bool isMember,
const bool isPredeclared
)
{
itsVarName = name;
itsIsMemberVarFlag = isMember;
itsIsPredeclaredVarFlag = isPredeclared;
}
/******************************************************************************
IsSelected
******************************************************************************/
inline bool
LayoutWidget::IsSelected()
const
{
return itsSelectedFlag;
}
/******************************************************************************
WantsInput
******************************************************************************/
inline bool
LayoutWidget::WantsInput()
const
{
return itsTabIndex > 0;
}
/******************************************************************************
GetTabIndex
******************************************************************************/
inline bool
LayoutWidget::GetTabIndex
(
JIndex* i
)
const
{
*i = itsTabIndex;
return itsTabIndex > 0;
}
/******************************************************************************
GetDragStartPointGlobal
******************************************************************************/
inline JPoint
LayoutWidget::GetDragStartPointGlobal()
const
{
return itsStartPtG;
}
#endif