ASPiK SDK
cframe.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __cframe__
6 #define __cframe__
7 
8 #include "vstguifwd.h"
9 #include "cviewcontainer.h"
10 #include "platform/iplatformframecallback.h"
11 
12 namespace VSTGUI {
13 
14 //----------------------------
15 // @brief Knob Mode
16 //----------------------------
17 enum CKnobMode
18 {
19  kCircularMode = 0,
20  kRelativCircularMode,
21  kLinearMode
22 };
23 
24 extern IdStringPtr kMsgNewFocusView;
25 extern IdStringPtr kMsgOldFocusView;
26 
27 //-----------------------------------------------------------------------------
28 // CFrame Declaration
31 //-----------------------------------------------------------------------------
32 class CFrame final : public CViewContainer, public IPlatformFrameCallback
33 {
34 public:
35  CFrame (const CRect& size, VSTGUIEditorInterface* pEditor);
36 
37  //-----------------------------------------------------------------------------
39  //-----------------------------------------------------------------------------
41  bool open (void* pSystemWindow, PlatformType systemWindowType = kDefaultNative, IPlatformFrameConfig* = nullptr);
42  void close ();
43 
44  bool setZoom (double zoomFactor);
45  double getZoom () const;
46 
47  double getScaleFactor () const;
48 
49  void idle ();
50 
51  uint32_t getTicks () const;
52 
53  static int32_t kDefaultKnobMode;
54  int32_t getKnobMode () const;
55 
56  bool setPosition (CCoord x, CCoord y);
57  bool getPosition (CCoord& x, CCoord& y) const;
58 
59  bool setSize (CCoord width, CCoord height);
60  bool getSize (CRect* pSize) const;
61  bool getSize (CRect& pSize) const;
62 
63  bool setModalView (CView* pView);
64  CView* getModalView () const;
65 
66  void beginEdit (int32_t index);
67  void endEdit (int32_t index);
68 
69  bool getCurrentMouseLocation (CPoint& where) const;
71  void setCursor (CCursorType type);
72 
73  void setFocusView (CView* pView);
74  CView* getFocusView () const;
75  bool advanceNextFocusView (CView* oldFocus, bool reverse = false) override;
76 
77  void onViewAdded (CView* pView);
78  void onViewRemoved (CView* pView);
79 
80  void onActivate (bool state);
81 
82  void invalidate (const CRect& rect);
83 
84  void scrollRect (const CRect& src, const CPoint& distance);
85 
86  void enableTooltips (bool state);
87 
89 
91  void setClipboard (const SharedPointer<IDataPackage>& data);
92 
93  IViewAddedRemovedObserver* getViewAddedRemovedObserver () const;
94  void setViewAddedRemovedObserver (IViewAddedRemovedObserver* observer);
95 
96  void registerKeyboardHook (IKeyboardHook* hook);
98 
99  void registerMouseObserver (IMouseObserver* observer);
100  void unregisterMouseObserver (IMouseObserver* observer);
101 
102  void registerScaleFactorChangedListeneer (IScaleFactorChangedListener* listener);
103  void unregisterScaleFactorChangedListeneer (IScaleFactorChangedListener* listener);
104 
105  void registerFocusViewObserver (IFocusViewObserver* observer);
106  void unregisterFocusViewObserver (IFocusViewObserver* observer);
107 
109 
110  //-----------------------------------------------------------------------------
114  //-----------------------------------------------------------------------------
116  void setFocusDrawingEnabled (bool state);
117  bool focusDrawingEnabled () const;
118 
119  void setFocusColor (const CColor& color);
120  CColor getFocusColor () const;
121 
122  void setFocusWidth (CCoord width);
123  CCoord getFocusWidth () const;
124 
125 
126  using Function = std::function<void ()>;
133  bool doAfterEventProcessing (Function&& func);
140  bool doAfterEventProcessing (const Function& func);
142  bool inEventProcessing () const;
143 
144  void onStartLocalEventLoop ();
145 
146  void invalid () override { invalidRect (getViewSize ()); setDirty (false); }
147  void invalidRect (const CRect& rect) override;
148 
149  bool removeView (CView* pView, bool withForget = true) override;
150  bool removeAll (bool withForget = true) override;
151  CView* getViewAt (const CPoint& where, const GetViewOptions& options = GetViewOptions ()) const override;
152  CViewContainer* getContainerAt (const CPoint& where, const GetViewOptions& options = GetViewOptions ().deep ()) const override;
153  bool hitTestSubViews (const CPoint& where, const CButtonState& buttons = -1) override;
154 
155  // CView
156  bool attached (CView* parent) override;
157  void draw (CDrawContext* pContext) override;
158  void drawRect (CDrawContext* pContext, const CRect& updateRect) override;
159  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
160  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
161  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
162  CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override;
163  bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) override;
164  bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override;
165  int32_t onKeyDown (VstKeyCode& keyCode) override;
166  int32_t onKeyUp (VstKeyCode& keyCode) override;
167  DragResult doDrag (IDataPackage* source, const CPoint& offset, CBitmap* dragBitmap) override;
168  void setViewSize (const CRect& rect, bool invalid = true) override;
169 
170  VSTGUIEditorInterface* getEditor () const override;
171  IPlatformFrame* getPlatformFrame () const;
172 
173  #if DEBUG
174  void dumpHierarchy () override;
175  #endif
176 
177  CLASS_METHODS(CFrame, CViewContainer)
178 
179  //-------------------------------------------
180 protected:
181  struct CollectInvalidRects;
182 
183  ~CFrame () noexcept override = default;
184  void beforeDelete () override;
185 
186  void checkMouseViews (const CPoint& where, const CButtonState& buttons);
187  void clearMouseViews (const CPoint& where, const CButtonState& buttons, bool callMouseExit = true);
188  void removeFromMouseViews (CView* view);
189  void setCollectInvalidRects (CollectInvalidRects* collectInvalidRects);
190 
191  // keyboard hooks
192  int32_t keyboardHooksOnKeyDown (const VstKeyCode& key);
193  int32_t keyboardHooksOnKeyUp (const VstKeyCode& key);
194 
195  // mouse observers
196  void callMouseObserverMouseEntered (CView* view);
197  void callMouseObserverMouseExited (CView* view);
198  CMouseEventResult callMouseObserverMouseDown (const CPoint& where, const CButtonState& buttons);
199  CMouseEventResult callMouseObserverMouseMoved (const CPoint& where, const CButtonState& buttons);
200 
201  void dispatchNewScaleFactor (double newScaleFactor);
202 
203  // platform frame
204  bool platformDrawRect (CDrawContext* context, const CRect& rect) override;
205  CMouseEventResult platformOnMouseDown (CPoint& where, const CButtonState& buttons) override;
206  CMouseEventResult platformOnMouseMoved (CPoint& where, const CButtonState& buttons) override;
207  CMouseEventResult platformOnMouseUp (CPoint& where, const CButtonState& buttons) override;
208  CMouseEventResult platformOnMouseExited (CPoint& where, const CButtonState& buttons) override;
209  bool platformOnMouseWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override;
210  bool platformOnDrop (IDataPackage* drag, const CPoint& where) override;
211  void platformOnDragEnter (IDataPackage* drag, const CPoint& where) override;
212  void platformOnDragLeave (IDataPackage* drag, const CPoint& where) override;
213  void platformOnDragMove (IDataPackage* drag, const CPoint& where) override;
214  bool platformOnKeyDown (VstKeyCode& keyCode) override;
215  bool platformOnKeyUp (VstKeyCode& keyCode) override;
216  void platformOnActivate (bool state) override;
217  void platformOnWindowActivate (bool state) override;
218  void platformScaleFactorChanged (double newScaleFactor) override;
219 #if VSTGUI_TOUCH_EVENT_HANDLING
220  void platformOnTouchEvent (ITouchEvent& event) override;
221 #endif
222 
223 private:
224  struct Impl;
225  Impl* pImpl {nullptr};
226 };
227 
228 //----------------------------------------------------
230 {
231 public:
232  virtual void doIdleStuff () {}
233  virtual int32_t getKnobMode () const { return -1; }
234 
235  virtual void beginEdit (int32_t index) {}
236  virtual void endEdit (int32_t index) {}
237 
238  virtual bool beforeSizeChange (const CRect& newSize, const CRect& oldSize) { return true; }
239 
240  virtual CFrame* getFrame () const { return frame; }
241 protected:
242  VSTGUIEditorInterface () = default;
243  virtual ~VSTGUIEditorInterface () noexcept = default;
244 
245  CFrame* frame {nullptr};
246 };
247 
248 //-----------------------------------------------------------------------------
249 // IMouseObserver Declaration
251 //-----------------------------------------------------------------------------
253 {
254 public:
255  virtual ~IMouseObserver() noexcept = default;
256  virtual void onMouseEntered (CView* view, CFrame* frame) = 0;
257  virtual void onMouseExited (CView* view, CFrame* frame) = 0;
258  virtual CMouseEventResult onMouseMoved (CFrame* frame, const CPoint& where, const CButtonState& buttons) { return kMouseEventNotHandled; }
259  virtual CMouseEventResult onMouseDown (CFrame* frame, const CPoint& where, const CButtonState& buttons) { return kMouseEventNotHandled; }
260 };
261 
262 //-----------------------------------------------------------------------------
263 // IKeyboardHook Declaration
266 //-----------------------------------------------------------------------------
268 {
269 public:
270  virtual ~IKeyboardHook () noexcept = default;
271 
272  virtual int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) = 0;
273  virtual int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) = 0;
274 };
275 
276 //-----------------------------------------------------------------------------
277 // IViewAddedRemovedObserver Declaration
280 //-----------------------------------------------------------------------------
282 {
283 public:
284  virtual ~IViewAddedRemovedObserver () noexcept = default;
285 
286  virtual void onViewAdded (CFrame* frame, CView* view) = 0;
287  virtual void onViewRemoved (CFrame* frame, CView* view) = 0;
288 };
289 
290 //-----------------------------------------------------------------------------
291 // IFocusViewObserver Declaration
294 //-----------------------------------------------------------------------------
296 {
297 public:
298  virtual ~IFocusViewObserver () noexcept = default;
299 
300  virtual void onFocusViewChanged (CFrame* frame, CView* newFocusView, CView* oldFocusView) = 0;
301 };
302 
303 } // namespace
304 
305 #endif
bool inEventProcessing() const
Definition: cframe.cpp:1704
Container Class of CView objects.
Definition: cviewcontainer.h:52
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: cframe.cpp:772
void onViewAdded(CView *pView)
Definition: cframe.cpp:967
void setFocusWidth(CCoord width)
set focus draw width
Definition: cframe.cpp:1254
SharedPointer< IDataPackage > getClipboard()
get the clipboard data. data is owned by the caller
Definition: cframe.cpp:674
void close()
closes the frame and calls forget
Definition: cframe.cpp:165
void onActivate(bool state)
called when the platform view/window is activated/deactivated
Definition: cframe.cpp:1185
CViewContainer * getContainerAt(const CPoint &where, const GetViewOptions &options=GetViewOptions().deep()) const override
get the container at point where
Definition: cframe.cpp:1164
Rect structure.
Definition: crect.h:17
bool getSize(CRect *pSize) const
Definition: cframe.cpp:817
void setFocusColor(const CColor &color)
set focus draw color
Definition: cframe.cpp:1248
void setFocusView(CView *pView)
Definition: cframe.cpp:982
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cframe.cpp:522
Definition: cviewcontainer.h:22
view added removed observer interface for CFrame
Definition: cframe.h:281
virtual bool beforeSizeChange(const CRect &newSize, const CRect &oldSize)
frame will change size, if this returns false the upstream implementation does not allow it and thus ...
Definition: cframe.h:238
Definition: vstkeycode.h:12
Definition: cframe.h:229
Definition: vstguibase.h:299
VSTGUIEditorInterface * getEditor() const override
get editor
Definition: cframe.cpp:1454
bool setZoom(double zoomFactor)
set zoom factor
Definition: cframe.cpp:216
CButtonState getCurrentMouseButtons() const
get current mouse buttons and key modifiers
Definition: cframe.cpp:913
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
bool attached(CView *parent) override
view is attached to a parent view
Definition: cframe.cpp:198
void draw(CDrawContext *pContext) override
called if the view should draw itself
Definition: cframe.cpp:272
void setClipboard(const SharedPointer< IDataPackage > &data)
set the clipboard data.
Definition: cframe.cpp:682
void registerMouseObserver(IMouseObserver *observer)
register a mouse observer
Definition: cframe.cpp:1366
RGBA Color structure.
Definition: ccolor.h:15
bool onWheel(const CPoint &where, const float &distance, const CButtonState &buttons) override
called if a mouse wheel event is happening over this view
Definition: cframe.cpp:660
void setCursor(CCursorType type)
set mouse cursor
Definition: cframe.cpp:927
void enableTooltips(bool state)
enable or disable tooltips
Definition: cframe.cpp:258
virtual int32_t onKeyUp(const VstKeyCode &code, CFrame *frame)=0
should return 1 if no further key up processing should apply, otherwise -1
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cframe.cpp:485
bool advanceNextFocusView(CView *oldFocus, bool reverse=false) override
Definition: cframe.cpp:1047
void invalid() override
mark whole view as invalid
Definition: cframe.h:146
bool doAfterEventProcessing(Function &&func)
Definition: cframe.cpp:1688
void registerKeyboardHook(IKeyboardHook *hook)
register a keyboard hook
Definition: cframe.cpp:1316
uint32_t getTicks() const
get the current time (in ms)
Definition: cframe.cpp:708
DragResult doDrag(IDataPackage *source, const CPoint &offset, CBitmap *dragBitmap) override
start a drag operation. See CDropSource to create the source data package
Definition: cframe.cpp:666
bool hitTestSubViews(const CPoint &where, const CButtonState &buttons=-1) override
Definition: cframe.cpp:465
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
bool setPosition(CCoord x, CCoord y)
Definition: cframe.cpp:734
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cframe.cpp:531
CView * getViewAt(const CPoint &where, const GetViewOptions &options=GetViewOptions()) const override
get the view at point where
Definition: cframe.cpp:1141
Definition: customcontrols.cpp:8
virtual int32_t onKeyDown(const VstKeyCode &code, CFrame *frame)=0
should return 1 if no further key down processing should apply, otherwise -1
focus view observer interface for CFrame
Definition: cframe.h:295
bool getPosition(CCoord &x, CCoord &y) const
Definition: cframe.cpp:756
virtual CMouseEventResult onMouseMoved(CFrame *frame, const CPoint &where, const CButtonState &buttons)
a mouse move event happend on the frame at position where. If the observer handles this...
Definition: cframe.h:258
Button and Modifier state.
Definition: cbuttonstate.h:34
const CRect & getViewSize() const
read only access to view size
Definition: cview.cpp:661
virtual void setDirty(bool val=true)
set the view to dirty so that it is redrawn in the next idle. Thread Safe !
Definition: cview.cpp:333
bool focusDrawingEnabled() const
is focus drawing enabled
Definition: cframe.cpp:1212
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cframe.cpp:586
bool getCurrentMouseLocation(CPoint &where) const
get current mouse location
Definition: cframe.cpp:896
Base Class of all view objects.
Definition: cview.h:44
Animation runner.
Definition: animator.h:20
virtual CMouseEventResult onMouseDown(CFrame *frame, const CPoint &where, const CButtonState &buttons)
a mouse down event happend on the frame at position where. If the observer handles this...
Definition: cframe.h:259
CCoord getFocusWidth() const
get focus draw width
Definition: cframe.cpp:1230
interface for drag&drop and clipboard data
Definition: idatapackage.h:15
bool setSize(CCoord width, CCoord height)
Definition: cframe.cpp:784
Definition: iscalefactorchangedlistener.h:13
double getZoom() const
get zoom factor
Definition: cframe.cpp:246
CMouseEventResult onMouseExited(CPoint &where, const CButtonState &buttons) override
called when the mouse leaves this view
Definition: cframe.cpp:572
static int32_t kDefaultKnobMode
default knob mode if host does not provide one
Definition: cframe.h:53
generic keyboard hook interface for CFrame
Definition: cframe.h:267
bool removeView(CView *pView, bool withForget=true) override
remove a child view
Definition: cframe.cpp:1119
int32_t getKnobMode() const
get hosts knob mode
Definition: cframe.cpp:719
void unregisterKeyboardHook(IKeyboardHook *hook)
unregister a keyboard hook
Definition: cframe.cpp:1322
bool setModalView(CView *pView)
Definition: cframe.cpp:835
Point structure.
Definition: cpoint.h:17
void invalidRect(const CRect &rect) override
mark rect as invalid
Definition: cframe.cpp:1289
CColor getFocusColor() const
get focus draw color
Definition: cframe.cpp:1221
void setFocusDrawingEnabled(bool state)
enable focus drawing
Definition: cframe.cpp:1239
bool removeAll(bool withForget=true) override
remove all child views
Definition: cframe.cpp:1127
int32_t onKeyUp(VstKeyCode &keyCode) override
called if a key up event occurs and this view has focus
Definition: cframe.cpp:620
void scrollRect(const CRect &src, const CPoint &distance)
scroll src rect by distance
Definition: cframe.cpp:1264
void drawRect(CDrawContext *pContext, const CRect &updateRect) override
called if the view should draw itself
Definition: cframe.cpp:278
The CFrame is the parent container of all views.
Definition: cframe.h:32
void unregisterMouseObserver(IMouseObserver *observer)
unregister a mouse observer
Definition: cframe.cpp:1384
Animation::Animator * getAnimator()
get animator for this frame
Definition: cframe.cpp:697
void onViewRemoved(CView *pView)
Definition: cframe.cpp:937
generic mouse observer interface for CFrame
Definition: cframe.h:252