Clapkit
Loading...
Searching...
No Matches
ckObject.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 * CKObject
9 * ----------------------------------------------------------------------
10 * The base of everything we have.
11 *
12 */
13
14#pragma once
15
16#include "ckProperty.h"
17#include <map>
18
23#define CKOBSERVEVALUE(name) [this]() { this->RaisePropertyChange(name); };
24
25enum class CKEventType;
26class CKEvent;
27class CKObject;
28
32using CKEventHandlerFunc = std::function<void(const CKEvent&)>;
33
37using CKPropertyObserverFunc = std::function<void(const CKObject*, const char*)>;
38
43class CKObject {
44
45 public:
46 CKObject();
47 virtual ~CKObject();
48 virtual void AddHandler(CKEventType type, CKEventHandlerFunc cb);
49 virtual void RemoveHandler(CKEventType type);
50 virtual bool HasHandler(CKEventType type) const;
51 virtual bool HandleEvent(const CKEvent& evt);
53 virtual void UnsetPropertyObserver();
54 virtual void RaisePropertyChange(const char* propertyName);
55
56 protected:
57 std::map<CKEventType, CKEventHandlerFunc> __handlers;
59};
Defines the base class for all controls and objects.
Definition ckObject.h:43
CKPropertyObserverFunc propertyObserverCB
Definition ckObject.h:58
virtual bool HasHandler(CKEventType type) const
Definition ckObject.cpp:40
std::map< CKEventType, CKEventHandlerFunc > __handlers
Definition ckObject.h:57
virtual void AddHandler(CKEventType type, CKEventHandlerFunc cb)
Definition ckObject.cpp:28
virtual ~CKObject()
Definition ckObject.cpp:23
virtual bool HandleEvent(const CKEvent &evt)
Definition ckObject.cpp:45
CKObject()
Definition ckObject.cpp:20
virtual void RemoveHandler(CKEventType type)
Definition ckObject.cpp:33
virtual void UnsetPropertyObserver()
Definition ckObject.cpp:62
virtual void SetPropertyObserver(CKPropertyObserverFunc cb)
Definition ckObject.cpp:57
virtual void RaisePropertyChange(const char *propertyName)
Definition ckObject.cpp:67
std::function< void(const CKObject *, const char *)> CKPropertyObserverFunc
Definition ckObject.h:37
CKEventType
Defines an event type for controls (and windows.)
Definition ckTypes.h:334
std::function< void(const CKEvent &)> CKEventHandlerFunc
Definition ckObject.h:32
Defines an event raised by the framework, mostly for user actions.
Definition ckTypes.h:490