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 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
#if defined(Hiro_Object)
mObject::mObject() {
Application::initialize();
}
mObject::~mObject() {
}
auto mObject::allocate() -> pObject* {
return new pObject(*this);
}
auto mObject::construct() -> void {
if(delegate) return;
delegate = allocate();
signal(construct);
}
auto mObject::destruct() -> void {
if(!delegate) return;
signal(destruct);
delete delegate;
delegate = nullptr;
}
//
//used to test if returned items "exist" from eg Window::sizable(), ListView::selected(), etc.
mObject::operator bool() const {
return parent() || !abstract();
}
//this is used to control dynamic allocation of pObject delegates
//an mObject is abstract only if it has no top-level object (eg a Button not attached to any Window)
//if the mObject is not abstract, the pObject delegate is allocated immediately
//otherwise, the pObject is not allocated until it is attached to a non-abstract parent
auto mObject::abstract() const -> bool {
#if defined(Hiro_Group)
if(dynamic_cast<const mGroup*>(this)) return false;
#endif
#if defined(Hiro_Timer)
if(dynamic_cast<const mTimer*>(this)) return false;
#endif
#if defined(Hiro_Window)
if(dynamic_cast<const mWindow*>(this)) return false;
#endif
#if defined(Hiro_PopupMenu)
if(dynamic_cast<const mPopupMenu*>(this)) return false;
#endif
if(auto object = parent()) return object->abstract();
return true;
}
auto mObject::adjustOffset(s32 displacement) -> type& {
state.offset += displacement;
return *this;
}
auto mObject::enabled(bool recursive) const -> bool {
if(!recursive || !state.enabled) return state.enabled;
if(auto object = parent()) return object->enabled(true);
return true;
}
auto mObject::focused() const -> bool {
return signal(focused);
}
auto mObject::font(bool recursive) const -> Font {
if(!recursive || state.font) return state.font;
if(auto object = parent()) return object->font(true);
return Application::font();
}
auto mObject::group() const -> Group {
return {};
}
auto mObject::offset() const -> s32 {
return state.offset;
}
auto mObject::parent() const -> mObject* {
return state.parent;
}
#if defined(Hiro_ComboButton)
auto mObject::parentComboButton(bool recursive) const -> mComboButton* {
if(auto comboButton = dynamic_cast<mComboButton*>(parent())) return comboButton;
if(recursive) {
if(auto object = parent()) return object->parentComboButton(true);
}
return nullptr;
}
#endif
#if defined(Hiro_ComboEdit)
auto mObject::parentComboEdit(bool recursive) const -> mComboEdit* {
if(auto comboEdit = dynamic_cast<mComboEdit*>(parent())) return comboEdit;
if(recursive) {
if(auto object = parent()) return object->parentComboEdit(true);
}
return nullptr;
}
#endif
#if defined(Hiro_Frame)
auto mObject::parentFrame(bool recursive) const -> mFrame* {
if(auto frame = dynamic_cast<mFrame*>(parent())) return frame;
if(recursive) {
if(auto object = parent()) return object->parentFrame(true);
}
return nullptr;
}
#endif
#if defined(Hiro_IconView)
auto mObject::parentIconView(bool recursive) const -> mIconView* {
if(auto iconView = dynamic_cast<mIconView*>(parent())) return iconView;
if(recursive) {
if(auto object = parent()) return object->parentIconView(true);
}
return nullptr;
}
#endif
#if defined(Hiro_Menu)
auto mObject::parentMenu(bool recursive) const -> mMenu* {
if(auto menu = dynamic_cast<mMenu*>(parent())) return menu;
if(recursive) {
if(auto object = parent()) return object->parentMenu(true);
}
return nullptr;
}
#endif
#if defined(Hiro_MenuBar)
auto mObject::parentMenuBar(bool recursive) const -> mMenuBar* {
if(auto menuBar = dynamic_cast<mMenuBar*>(parent())) return menuBar;
if(recursive) {
if(auto object = parent()) return object->parentMenuBar(true);
}
return nullptr;
}
#endif
#if defined(Hiro_PopupMenu)
auto mObject::parentPopupMenu(bool recursive) const -> mPopupMenu* {
if(auto popupMenu = dynamic_cast<mPopupMenu*>(parent())) return popupMenu;
if(recursive) {
if(auto object = parent()) return object->parentPopupMenu(true);
}
return nullptr;
}
#endif
#if defined(Hiro_Sizable)
auto mObject::parentSizable(bool recursive) const -> mSizable* {
if(auto sizable = dynamic_cast<mSizable*>(parent())) return sizable;
if(recursive) {
if(auto object = parent()) return object->parentSizable(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TabFrame)
auto mObject::parentTabFrame(bool recursive) const -> mTabFrame* {
if(auto tabFrame = dynamic_cast<mTabFrame*>(parent())) return tabFrame;
if(recursive) {
if(auto object = parent()) return object->parentTabFrame(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TabFrame)
auto mObject::parentTabFrameItem(bool recursive) const -> mTabFrameItem* {
if(auto tabFrameItem = dynamic_cast<mTabFrameItem*>(parent())) return tabFrameItem;
if(recursive) {
if(auto object = parent()) return object->parentTabFrameItem(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TableView)
auto mObject::parentTableView(bool recursive) const -> mTableView* {
if(auto tableView = dynamic_cast<mTableView*>(parent())) return tableView;
if(recursive) {
if(auto object = parent()) return object->parentTableView(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TableView)
auto mObject::parentTableViewItem(bool recursive) const -> mTableViewItem* {
if(auto tableViewItem = dynamic_cast<mTableViewItem*>(parent())) return tableViewItem;
if(recursive) {
if(auto object = parent()) return object->parentTableViewItem(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TreeView)
auto mObject::parentTreeView(bool recursive) const -> mTreeView* {
if(auto treeView = dynamic_cast<mTreeView*>(parent())) return treeView;
if(recursive) {
if(auto object = parent()) return object->parentTreeView(true);
}
return nullptr;
}
#endif
#if defined(Hiro_TreeView)
auto mObject::parentTreeViewItem(bool recursive) const -> mTreeViewItem* {
if(auto treeViewItem = dynamic_cast<mTreeViewItem*>(parent())) return treeViewItem;
if(recursive) {
if(auto object = parent()) return object->parentTreeViewItem(true);
}
return nullptr;
}
#endif
#if defined(Hiro_Widget)
auto mObject::parentWidget(bool recursive) const -> mWidget* {
if(auto widget = dynamic_cast<mWidget*>(parent())) return widget;
if(recursive) {
if(auto object = parent()) return object->parentWidget(true);
}
return nullptr;
}
#endif
#if defined(Hiro_Window)
auto mObject::parentWindow(bool recursive) const -> mWindow* {
if(auto window = dynamic_cast<mWindow*>(parent())) return window;
if(recursive) {
if(auto object = parent()) return object->parentWindow(true);
}
return nullptr;
}
#endif
auto mObject::remove() -> type& {
signal(remove);
return *this;
}
auto mObject::reset() -> type& {
signal(reset);
return *this;
}
auto mObject::setEnabled(bool enabled) -> type& {
state.enabled = enabled;
signal(setEnabled, this->enabled(true));
return *this;
}
auto mObject::setFocused() -> type& {
signal(setFocused);
return *this;
}
auto mObject::setFont(const Font& font) -> type& {
state.font = font;
signal(setFont, this->font(true));
return *this;
}
auto mObject::setGroup(sGroup group) -> type& {
return *this;
}
auto mObject::setParent(mObject* parent, s32 offset) -> type& {
destruct();
state.parent = parent;
state.offset = offset;
if(!abstract()) construct();
return *this;
}
auto mObject::setVisible(bool visible) -> type& {
state.visible = visible;
signal(setVisible, this->visible(true));
return *this;
}
auto mObject::visible(bool recursive) const -> bool {
if(!recursive || !state.visible) return state.visible;
if(auto object = parent()) return object->visible(true);
return true;
}
#endif
|