Clapkit
Loading...
Searching...
No Matches
ckWindow.h
Go to the documentation of this file.
1/*
2 *
3 * Clapkit
4 * ----------------------------------------------------------------------
5 * A wrapper for creating a 'generalized' app for Classic MacOS
6 * that (hopefully) can be ported easily to other platforms.
7 *
8 * CKWindow
9 * ----------------------------------------------------------------------
10 * Defines a window.
11 *
12 */
13
14#pragma once
15
16#include "ckApp.h"
17#include "ckControl.h"
18#include "ckObject.h"
19#include <MacWindows.h>
20#include <cstring>
21#include <vector>
22
27enum class CKWindowType {
28 Standard = 0,
30 Modal = 2,
31 Floating = 3,
32};
33
35
45 public:
47 std::optional<CKPoint> origin;
49 char* title = nullptr;
50
51 public:
60 this->size = size;
61 }
62
64 CKSafeCopyString(this->title, title);
65 return *this;
66 }
67
69 this->type = type;
70 return *this;
71 }
72
74 this->origin = point;
75 return *this;
76 }
77
79 this->origin.reset();
80 return *this;
81 }
82};
83
89class CKWindow : public CKObject {
90
91 public:
93 virtual ~CKWindow();
94 void Loop();
95
96 void SetTitle(const char* title);
97 char* GetTitle();
98
99 void Show();
100 void Hide();
101 void Focus();
102 void Center();
103 void Close();
104
105 bool AddControl(CKControl* control);
106 void RemoveControl(CKControl* control, bool free);
107 void Redraw(CKRect rectToRedraw);
108
109 void SetOwner(CKApp* owner);
110 CKApp* GetOwner();
111
113 const std::vector<CKControl*>& GetControls() const;
114
122 template <typename T>
123 std::vector<T*> GetControlsOfType() const {
124
125 std::vector<T*> out;
126 out.reserve(__controls.size());
127 for (auto* c : __controls) {
128 if (auto* t = dynamic_cast<T*>(c)) {
129 out.push_back(t);
130 }
131 }
132 return out;
133 }
134
135 bool ContainsControl(CKControl* control);
137 void SetActiveControl(CKControl* control);
138
139 virtual bool HandleEvent(const CKEvent& evt);
140
141 CKControl* GetLastControl() const;
142 void SetLastControl(CKControl* control);
143
144 const CKWindowPtr GetWindowPtr() const;
145
146 void DirtyArea(const CKRect r);
147
148 bool GetIsActive();
149
150 private:
151 void __InvalidateEntireWindow();
152
153 protected:
154 friend class CKApp;
155 void SetIsActive(bool active);
156 void __ReflectToOS();
157 virtual void RaisePropertyChange(const char* propertyName);
158
159 public:
165
168 int maximumWidth = 1000;
169 int maximumHeight = 1000;
170
176
177 private:
178 CKApp* __owner;
179 std::vector<CKControl*> __controls;
180 CKWindowPtr __windowPtr = nullptr;
181 CKControl* __activeTextInputControl = nullptr;
182 CKControl* __lastDownControl = nullptr;
183 bool __dead = false;
184 bool __isCurrentlyActive = false;
185 CKWindowType __type;
186 std::vector<CKRect> __controlDirtifiedAreas;
187};
WindowPtr CKWindowPtr
Definition ckPlatform.h:62
Defines the main entry point for a Clapkit application.
Definition ckApp.h:57
Defines the base of all UI Controls.
Definition ckControl.h:89
A base for controls that can have a "focus" - i.e. textfields.
Definition ck_pFocusableControl.h:22
Defines the base class for all controls and objects.
Definition ckObject.h:43
Defines an observable value.
Definition ckProperty.h:60
Defines a window. Window type (modal, document) is determined by CKWindowInitParams and CKWindowType.
Definition ckWindow.h:89
const CKWindowPtr GetWindowPtr() const
Definition ckWindow.cpp:501
void RemoveControl(CKControl *control, bool free)
Definition ckWindow.cpp:253
const std::vector< CKControl * > & GetControls() const
Get the list of controls in this window.
Definition ckWindow.cpp:402
void Center()
Definition ckWindow.cpp:185
bool AddControl(CKControl *control)
Definition ckWindow.cpp:216
CKProperty< CKRect > rect
Definition ckWindow.h:160
CKControl * GetLastControl() const
Definition ckWindow.cpp:491
CKProperty< CKColor > backgroundColor
Definition ckWindow.h:163
bool shouldReceiveMouseMoveEvents
True if we should receive mouseMove events. We are storing this as a hack to speed things up as HasHa...
Definition ckWindow.h:175
void SetIsActive(bool active)
Definition ckWindow.cpp:468
CKProperty< bool > visible
Definition ckWindow.h:161
void DirtyArea(const CKRect r)
Definition ckWindow.cpp:511
int minimumHeight
Definition ckWindow.h:167
CKProperty< bool > hasCustomBackgroundColor
Definition ckWindow.h:162
void SetLastControl(CKControl *control)
Definition ckWindow.cpp:496
void Redraw(CKRect rectToRedraw)
Definition ckWindow.cpp:289
int minimumWidth
Definition ckWindow.h:166
bool GetIsActive()
Definition ckWindow.cpp:506
void SetTitle(const char *title)
Definition ckWindow.cpp:125
CKProperty< bool > closable
Definition ckWindow.h:164
CKApp * GetOwner()
Return the app this window is a part of.
Definition ckWindow.cpp:366
virtual ~CKWindow()
Definition ckWindow.cpp:93
void __ReflectToOS()
Definition ckWindow.cpp:570
char * GetTitle()
Definition ckWindow.cpp:137
int maximumHeight
Definition ckWindow.h:169
virtual void RaisePropertyChange(const char *propertyName)
Definition ckWindow.cpp:592
void Show()
Definition ckWindow.cpp:152
void Close()
Definition ckWindow.cpp:197
virtual bool HandleEvent(const CKEvent &evt)
Definition ckWindow.cpp:529
CKControl * FindControl(CKPoint point)
Definition ckWindow.cpp:379
void Loop()
Called from CKApp to do stuff like blinking the caret, etc.
Definition ckWindow.cpp:113
void Focus()
Make the window foremost window. Make visible if invisible.
Definition ckWindow.cpp:174
std::vector< T * > GetControlsOfType() const
Get the list of controls of type T in this window.
Definition ckWindow.h:123
void SetOwner(CKApp *owner)
Definition ckWindow.cpp:358
void SetActiveControl(CKControl *control)
Called by ckApp on a click event - to set the active control (like a textfield.)
Definition ckWindow.cpp:440
bool ContainsControl(CKControl *control)
Definition ckWindow.cpp:409
void Hide()
Definition ckWindow.cpp:164
int maximumWidth
Definition ckWindow.h:168
CKFocusableControl * GetActiveControl()
Called by ckApp to determine UI Changes needed, like enabling/disabling menu items.
Definition ckWindow.cpp:427
#define CKSafeCopyString(dest, src)
Copy a string (if it is a string) to a destination. Free the destination if there is already somethin...
Definition ckMemory.h:93
CKWindowType
Defines the type of the window.
Definition ckWindow.h:27
Defines an RGB color. A (Alpha) is usually not used in our case.
Definition ckTypes.h:87
Defines an event raised by the framework, mostly for user actions.
Definition ckTypes.h:490
Defines a point on the screen.
Definition ckTypes.h:121
Defines a rectangular area at a specific location.
Definition ckTypes.h:227
Defines a rectangular area.
Definition ckTypes.h:179
Initialization parameters for a CKWindow.
Definition ckWindow.h:44
CKWindowInitParams & SetType(CKWindowType type)
Definition ckWindow.h:68
CKWindowInitParams & UnsetOrigin()
Definition ckWindow.h:78
CKWindowType type
Definition ckWindow.h:48
std::optional< CKPoint > origin
Definition ckWindow.h:47
CKSize size
Definition ckWindow.h:46
CKWindowInitParams(CKSize size)
Initialization parameters for a CKWindow. You must set a size larger than 0x0. Title/type can be set ...
Definition ckWindow.h:59
char * title
Definition ckWindow.h:49
CKWindowInitParams & SetOrigin(CKPoint point)
Definition ckWindow.h:73
CKWindowInitParams & SetTitle(const char *title)
Definition ckWindow.h:63