From 54ccef6df50a7d92a1869c6b54ae4b1f57356933 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 1 Aug 2015 10:23:48 -0700 Subject: [PATCH] Window->Form, cause names. --- resources/default_skin/skin.tb.txt | 42 +++--- src/el/animation.h | 4 +- src/el/config.h | 4 +- .../{designer_window.cc => designer_form.cc} | 16 +-- .../{designer_window.h => designer_form.h} | 20 +-- src/el/element.cc | 41 +++--- src/el/element.h | 24 ++-- src/el/element_animation.h | 4 +- src/el/element_animation_manager.cc | 28 ++-- src/el/elements.h | 9 +- src/el/elements/drop_down_button.cc | 44 +++--- src/el/elements/drop_down_button.h | 18 +-- src/el/{window.cc => elements/form.cc} | 135 +++++++++--------- src/el/{window.h => elements/form.h} | 80 ++++++----- src/el/elements/list_box.cc | 14 +- .../elements/{menu_window.cc => menu_form.cc} | 20 +-- .../elements/{menu_window.h => menu_form.h} | 20 +-- .../{message_window.cc => message_form.cc} | 40 +++--- .../{message_window.h => message_form.h} | 40 +++--- .../{modal_window.cc => modal_form.cc} | 29 ++-- .../elements/{modal_window.h => modal_form.h} | 24 ++-- .../{popup_window.cc => popup_form.cc} | 26 ++-- .../elements/{popup_window.h => popup_form.h} | 20 +-- src/el/elements/text_box.cc | 4 +- src/el/graphics/renderer.h | 2 +- src/el/list_item.cc | 8 +- src/el/parsing/element_factory.h | 6 +- src/el/skin.h | 22 +-- src/el/testing/test_tb_style_edit.cpp | 8 +- src/el/text/text_view.h | 6 +- src/el/tooltip_manager.cc | 24 ++-- src/el/tooltip_manager.h | 4 +- src/el/util/debug.cc | 26 ++-- src/el/util/debug.h | 6 +- testbed/resource_edit_window.cc | 8 +- testbed/resource_edit_window.h | 6 +- testbed/testbed_application.cc | 31 ++-- testbed/testbed_application.h | 2 +- 38 files changed, 431 insertions(+), 434 deletions(-) rename src/el/design/{designer_window.cc => designer_form.cc} (90%) rename src/el/design/{designer_window.h => designer_form.h} (80%) rename src/el/{window.cc => elements/form.cc} (65%) rename src/el/{window.h => elements/form.h} (63%) rename src/el/elements/{menu_window.cc => menu_form.cc} (72%) rename src/el/elements/{menu_window.h => menu_form.h} (68%) rename src/el/elements/{message_window.cc => message_form.cc} (78%) rename src/el/elements/{message_window.h => message_form.h} (58%) rename src/el/elements/{modal_window.cc => modal_form.cc} (74%) rename src/el/elements/{modal_window.h => modal_form.h} (68%) rename src/el/elements/{popup_window.cc => popup_form.cc} (81%) rename src/el/elements/{popup_window.h => popup_form.h} (85%) diff --git a/resources/default_skin/skin.tb.txt b/resources/default_skin/skin.tb.txt index 586481e..3d48963 100644 --- a/resources/default_skin/skin.tb.txt +++ b/resources/default_skin/skin.tb.txt @@ -273,50 +273,50 @@ elements img-position-x 0 img-ofs-x 5 - # == Window skin ================================================================================= - Window + # == Form skin ================================================================================= + Form bitmap window.png cut 16 expand 12 padding 10 overrides - element Window.selected + element Form.selected state selected - Window.fullscreen - clone Window + Form.fullscreen + clone Form expand 12 padding 0 - Window.selected + Form.selected bitmap window_active.png cut 16 expand 12 - Window.close + Form.close bitmap window_close.png type image children - element Window.close.pressed + element Form.close.pressed state pressed - Window.close.pressed + Form.close.pressed bitmap window_close_pressed.png type image - Window.mover + Form.mover text-color #b8b8b8 bitmap window_mover_bg_tile.png type tile expand -1 padding 4 overrides - element Window.mover.active + element Form.mover.active state selected children - element Window.mover.overlay + element Form.mover.overlay state all - Window.mover.overlay + Form.mover.overlay bitmap window_mover_overlay.png cut 12 expand 3 - Window.mover.active - clone Window.mover + Form.mover.active + clone Form.mover text-color #fefefe overrides overlays @@ -373,13 +373,13 @@ elements clone Button DropDownButton.arrow clone arrow.down - DropDownButton.window - clone PopupWindow - PopupWindow - clone Window + DropDownButton.form + clone PopupForm + PopupForm + clone Form padding 2 - MenuWindow - clone PopupWindow + MenuForm + clone PopupForm ListItem padding 4 10 children diff --git a/src/el/animation.h b/src/el/animation.h index 7b8493c..5542cfb 100644 --- a/src/el/animation.h +++ b/src/el/animation.h @@ -41,8 +41,8 @@ enum class AnimationTime { // Using this is most often preferable since starting a animation is often // accompanied with some extra work that might eat up a considerable time of // the total duration (and chop of the beginning of it). - // F.ex: Creating a window and starting its appearance animation. During - // initialization of the window, you might initiate loading of additional + // F.ex: Creating a form and starting its appearance animation. During + // initialization of the form, you might initiate loading of additional // resources. When that is done and you finally end up updating animations, // most of the animation time might already have passed. If the animation // start time is adjusted to the first update, the whole animation will run diff --git a/src/el/config.h b/src/el/config.h index f838438..424e56e 100644 --- a/src/el/config.h +++ b/src/el/config.h @@ -16,8 +16,8 @@ #define EL_CONFIG_H_ // Enables for some handy runtime debugging, enabled by modifying the various -// settings in DebugInfo::get()-> A settings window can be shown by calling -// ShowDebugInfoSettingsWindow. +// settings in DebugInfo::get()-> A settings form can be shown by calling +// ShowDebugInfoSettingsForm. #ifndef NDEBUG #define EL_RUNTIME_DEBUG_INFO #endif // !NDEBUG diff --git a/src/el/design/designer_window.cc b/src/el/design/designer_form.cc similarity index 90% rename from src/el/design/designer_window.cc rename to src/el/design/designer_form.cc index beecfdf..b171ab6 100644 --- a/src/el/design/designer_window.cc +++ b/src/el/design/designer_form.cc @@ -9,13 +9,13 @@ #include -#include "el/design/designer_window.h" +#include "el/design/designer_form.h" #include "el/elements.h" namespace el { namespace design { -DesignerWindow::DesignerWindow() { +DesignerForm::DesignerForm() { set_text("Empty Designer"); LoadData( @@ -69,16 +69,16 @@ DesignerWindow::DesignerWindow() { build_content_root_ = build_container_->content_root(); } -DesignerWindow::~DesignerWindow() { CloseContent(); } +DesignerForm::~DesignerForm() { CloseContent(); } -void DesignerWindow::Show(Element* root_element) { +void DesignerForm::Show(Element* root_element) { set_rect({100, 50, 900, 600}); auto root = root_element->parent_root(); root->AddChild(this); } -void DesignerWindow::BindContent(Element* bind_element) { +void DesignerForm::BindContent(Element* bind_element) { CloseContent(); bind_element_ = bind_element; @@ -88,12 +88,12 @@ void DesignerWindow::BindContent(Element* bind_element) { RefreshContent(); } -void DesignerWindow::CloseContent() { +void DesignerForm::CloseContent() { bind_element_.reset(); RefreshContent(); } -void DesignerWindow::RefreshContent() { +void DesignerForm::RefreshContent() { // Clear existing content. build_content_root_->DeleteAllChildren(); @@ -123,7 +123,7 @@ void DesignerWindow::RefreshContent() { source_text_box_->set_focus(FocusReason::kUnknown); } -void DesignerWindow::PopulateElementListBox() { +void DesignerForm::PopulateElementListBox() { element_list_source_.clear(); // TODO(benvanik): walk tree. diff --git a/src/el/design/designer_window.h b/src/el/design/designer_form.h similarity index 80% rename from src/el/design/designer_window.h rename to src/el/design/designer_form.h index 2ced172..8ffe4e0 100644 --- a/src/el/design/designer_window.h +++ b/src/el/design/designer_form.h @@ -7,28 +7,28 @@ ****************************************************************************** */ -#ifndef EL_DESIGN_DESIGNER_WINDOW_H_ -#define EL_DESIGN_DESIGNER_WINDOW_H_ +#ifndef EL_DESIGN_DESIGNER_FORM_H_ +#define EL_DESIGN_DESIGNER_FORM_H_ #include "el/element.h" #include "el/element_listener.h" +#include "el/elements/form.h" #include "el/elements/list_box.h" #include "el/elements/text_box.h" #include "el/event_handler.h" #include "el/message_handler.h" -#include "el/window.h" namespace el { namespace design { -class DesignerWindow : public Window, - public MessageHandler, - public ElementListener { +class DesignerForm : public elements::Form, + public MessageHandler, + public ElementListener { public: - TBOBJECT_SUBCLASS(DesignerWindow, Window); + TBOBJECT_SUBCLASS(DesignerForm, Form); - DesignerWindow(); - ~DesignerWindow() override; + DesignerForm(); + ~DesignerForm() override; void Show(Element* root_element); @@ -62,4 +62,4 @@ class DesignerWindow : public Window, } // namespace design } // namespace el -#endif // EL_DESIGN_DESIGNER_WINDOW_H_ +#endif // EL_DESIGN_DESIGNER_FORM_H_ diff --git a/src/el/element.cc b/src/el/element.cc index bfad0f6..c9bad46 100644 --- a/src/el/element.cc +++ b/src/el/element.cc @@ -11,6 +11,7 @@ #include "el/element.h" #include "el/element_listener.h" +#include "el/elements/form.h" #include "el/elements/parts/scroller.h" #include "el/elements/tab_container.h" #include "el/elements/text_box.h" @@ -25,7 +26,6 @@ #include "el/util/metrics.h" #include "el/util/string.h" #include "el/value.h" -#include "el/window.h" namespace el { @@ -720,16 +720,16 @@ bool Element::set_focus(FocusReason reason, InvokeInfo info) { return false; } - // Update windows last focus. - Window* window = parent_window(); - if (window) { - window->set_last_focus(this); - // If not active, just return. We should get focus when the window is + // Update forms last focus. + auto form = parent_form(); + if (form) { + form->set_last_focus(this); + // If not active, just return. We should get focus when the form is // activated. - // Exception for windows that doesn't activate. They may contain focusable + // Exception for forms that doesn't activate. They may contain focusable // elements. - if (!window->is_active() && - any(window->settings() & WindowSettings::kCanActivate)) { + if (!form->is_active() && + any(form->settings() & elements::FormSettings::kCanActivate)) { return true; } } @@ -795,7 +795,7 @@ bool Element::MoveFocus(bool forward) { origin = this; } - Element* root = origin->parent_window(); + Element* root = origin->parent_form(); if (!root) { root = origin->parent_root(); } @@ -937,12 +937,12 @@ Element* Element::parent_root() { return tmp; } -Window* Element::parent_window() { +elements::Form* Element::parent_form() { Element* tmp = this; - while (tmp && !tmp->IsOfType()) { + while (tmp && !tmp->IsOfType()) { tmp = tmp->m_parent; } - return static_cast(tmp); + return static_cast(tmp); } void Element::AddListener(ElementListener* listener) { @@ -1505,11 +1505,10 @@ bool Element::InvokePointerDown(int x, int y, int click_count, captured_element->StartLongClickTimer(touch); } - // Get the closest parent window and bring it to the top. - Window* window = - captured_element ? captured_element->parent_window() : nullptr; - if (window) { - window->Activate(); + // Get the closest parent form and bring it to the top. + auto form = captured_element ? captured_element->parent_form() : nullptr; + if (form) { + form->Activate(); } } if (captured_element) { @@ -1931,9 +1930,9 @@ bool ElementSkinConditionContext::GetCondition( switch (info.prop) { case SkinProperty::kSkin: return element->background_skin() == info.value; - case SkinProperty::kWindowActive: - if (Window* window = element->parent_window()) { - return window->is_active(); + case SkinProperty::kFormActive: + if (auto form = element->parent_form()) { + return form->is_active(); } return false; case SkinProperty::kAxis: diff --git a/src/el/element.h b/src/el/element.h index 0b3a0df..365ea7d 100644 --- a/src/el/element.h +++ b/src/el/element.h @@ -32,8 +32,8 @@ class ElementListener; class EventHandler; class GenericStringItemSource; class LongClickTimer; -class Window; namespace elements { +class Form; namespace parts { class Scroller; } // namespace parts @@ -505,7 +505,7 @@ class Element : public util::TypedObject, // Sets if this element is a group root. // Grouped elements (such as RadioButton) will toggle all other elements with // the same group_id under the nearest parent group root. - // Window is a group root by default. + // Form is a group root by default. void set_group_root(bool group_root) { m_packed.is_group_root = group_root; } bool is_focusable() const { return m_packed.is_focusable; } @@ -542,11 +542,11 @@ class Element : public util::TypedObject, // keyboard input. // Elements can be focused only after enabling it (see set_focusable(true)). // Invisible or disabled elements can not be focused. - // If SetFocus is called on a element in a inactive window, it will succeed - // (return true), but it won't actually become focused until that window is - // activated (see Window::set_last_focus). + // If SetFocus is called on a element in a inactive form, it will succeed + // (return true), but it won't actually become focused until that form is + // activated (see Form::set_last_focus). // Returns true if successfully focused, or if set as last focus in its - // window. + // form. bool set_focus(FocusReason reason, InvokeInfo info = InvokeInfo::kNormal); // Calls SetFocus on all children and their children, until a element is found @@ -556,8 +556,8 @@ class Element : public util::TypedObject, // Moves focus from the currently focused element to another focusable // element. - // It will search for a focusable element in the same Window (or top root if - // there is no window) forward or backwards in the element order. + // It will search for a focusable element in the same Form (or top root if + // there is no form) forward or backwards in the element order. bool MoveFocus(bool forward); // Returns the child element that contains the coordinate or nullptr if no one @@ -748,10 +748,10 @@ class Element : public util::TypedObject, // Gets this element or a parent element that is the absolute root parent. Element* parent_root(); - // Gets the closest parent element that is a Window or nullptr if there is + // Gets the closest parent element that is a Form or nullptr if there is // none. - // If this element is a window itself, this will be returned. - Window* parent_window(); + // If this element is a form itself, this will be returned. + elements::Form* parent_form(); // Gets the parent element, or nullptr if this element is not added. inline Element* parent() const { return m_parent; } @@ -1299,7 +1299,7 @@ struct ElementNode : public Node { set("tooltip", value); return *reinterpret_cast(this); } - // The Element will be focused automatically the first time its Window is + // The Element will be focused automatically the first time its Form is // activated. R& autofocus(bool value) { set("autofocus", value ? 1 : 0); diff --git a/src/el/element_animation.h b/src/el/element_animation.h index 46c12b5..5f9b933 100644 --- a/src/el/element_animation.h +++ b/src/el/element_animation.h @@ -25,9 +25,9 @@ class ElementAnimation : public Animation, TBOBJECT_SUBCLASS(ElementAnimation, Animation); // Don't use 0.0 for opacity animations since that may break focus code. - // At the moment a window should appear and start fading in from opacity 0, + // At the moment a form should appear and start fading in from opacity 0, // it would also attempt setting the focus to it, but if opacity is 0 it will - // think focus should not be set in that window and fail. + // think focus should not be set in that form and fail. static const float kAlmostZeroOpacity; ElementAnimation(Element* element); diff --git a/src/el/element_animation_manager.cc b/src/el/element_animation_manager.cc index 2458e88..a868722 100644 --- a/src/el/element_animation_manager.cc +++ b/src/el/element_animation_manager.cc @@ -12,8 +12,8 @@ #include "el/element_animation.h" #include "el/element_animation_manager.h" #include "el/elements/dimmer.h" -#include "el/elements/message_window.h" -#include "el/window.h" +#include "el/elements/form.h" +#include "el/elements/message_form.h" namespace el { @@ -59,16 +59,16 @@ void ElementAnimationManager::OnElementDelete(Element* element) { bool ElementAnimationManager::OnElementDying(Element* element) { bool handled = false; - if (Window* window = SafeCast(element)) { - // Fade out dying windows. + if (auto form = SafeCast(element)) { + // Fade out dying forms. auto anim = new OpacityElementAnimation( - window, 1.f, ElementAnimation::kAlmostZeroOpacity, true); + form, 1.f, ElementAnimation::kAlmostZeroOpacity, true); AnimationManager::StartAnimation(anim, AnimationCurve::kBezier); handled = true; } - if (auto window = SafeCast(element)) { - // Move out dying message windows. - auto anim = new RectElementAnimation(window, Rect(0, 50, 0, 0), + if (auto form = SafeCast(element)) { + // Move out dying message forms. + auto anim = new RectElementAnimation(form, Rect(0, 50, 0, 0), RectElementAnimation::Mode::kDeltaIn); AnimationManager::StartAnimation(anim, AnimationCurve::kSpeedUp); handled = true; @@ -85,15 +85,15 @@ bool ElementAnimationManager::OnElementDying(Element* element) { void ElementAnimationManager::OnElementAdded(Element* parent, Element* element) { - if (Window* window = SafeCast(element)) { - // Fade in new windows. + if (auto form = SafeCast(element)) { + // Fade in new forms. auto anim = new OpacityElementAnimation( - window, ElementAnimation::kAlmostZeroOpacity, 1.f, false); + form, ElementAnimation::kAlmostZeroOpacity, 1.f, false); AnimationManager::StartAnimation(anim, AnimationCurve::kBezier); } - if (auto window = SafeCast(element)) { - // Move in new message windows. - auto anim = new RectElementAnimation(window, Rect(0, -50, 0, 0), + if (auto form = SafeCast(element)) { + // Move in new message forms. + auto anim = new RectElementAnimation(form, Rect(0, -50, 0, 0), RectElementAnimation::Mode::kDeltaOut); AnimationManager::StartAnimation(anim); } diff --git a/src/el/elements.h b/src/el/elements.h index 9533fc8..b35bcf7 100644 --- a/src/el/elements.h +++ b/src/el/elements.h @@ -17,6 +17,7 @@ #include "el/elements/check_box.h" #include "el/elements/dimmer.h" #include "el/elements/drop_down_button.h" +#include "el/elements/form.h" #include "el/elements/group_box.h" #include "el/elements/icon_box.h" #include "el/elements/image_box.h" @@ -24,11 +25,11 @@ #include "el/elements/label_container.h" #include "el/elements/layout_box.h" #include "el/elements/list_box.h" -#include "el/elements/menu_window.h" -#include "el/elements/message_window.h" -#include "el/elements/modal_window.h" +#include "el/elements/menu_form.h" +#include "el/elements/message_form.h" +#include "el/elements/modal_form.h" #include "el/elements/mover.h" -#include "el/elements/popup_window.h" +#include "el/elements/popup_form.h" #include "el/elements/progress_spinner.h" #include "el/elements/radio_button.h" #include "el/elements/resizer.h" diff --git a/src/el/elements/drop_down_button.cc b/src/el/elements/drop_down_button.cc index a9f57ab..262a3bf 100644 --- a/src/el/elements/drop_down_button.cc +++ b/src/el/elements/drop_down_button.cc @@ -8,7 +8,7 @@ */ #include "el/elements/drop_down_button.h" -#include "el/elements/menu_window.h" +#include "el/elements/menu_form.h" #include "el/parsing/element_inflater.h" #include "el/util/string.h" #include "el/util/string_builder.h" @@ -33,7 +33,7 @@ DropDownButton::DropDownButton() { DropDownButton::~DropDownButton() { content_root()->RemoveChild(&m_arrow); set_source(nullptr); - CloseWindow(); + CloseForm(); } void DropDownButton::OnInflate(const parsing::InflateInfo& info) { @@ -72,25 +72,25 @@ TBID DropDownButton::selected_item_id() { return TBID(); } -void DropDownButton::OpenWindow() { - if (!m_source || !m_source->size() || m_window_pointer.get()) { +void DropDownButton::OpenForm() { + if (!m_source || !m_source->size() || m_form_pointer.get()) { return; } - MenuWindow* window = new MenuWindow(this, TBIDC("DropDownButton.window")); - m_window_pointer.reset(window); - window->set_background_skin(TBIDC("DropDownButton.window")); - window->Show(m_source, PopupAlignment(), value()); + MenuForm* form = new MenuForm(this, TBIDC("DropDownButton.form")); + m_form_pointer.reset(form); + form->set_background_skin(TBIDC("DropDownButton.form")); + form->Show(m_source, PopupAlignment(), value()); } -void DropDownButton::CloseWindow() { - if (MenuWindow* window = menu_if_open()) { - window->Close(); +void DropDownButton::CloseForm() { + if (MenuForm* form = menu_if_open()) { + form->Close(); } } -MenuWindow* DropDownButton::menu_if_open() const { - return util::SafeCast(m_window_pointer.get()); +MenuForm* DropDownButton::menu_if_open() const { + return util::SafeCast(m_form_pointer.get()); } bool DropDownButton::OnEvent(const Event& ev) { @@ -98,29 +98,29 @@ bool DropDownButton::OnEvent(const Event& ev) { // Open the menu, or set the value and close it if already open (this will // happen when clicking by keyboard since that will call click on this // button). - if (MenuWindow* menu_window = menu_if_open()) { + if (MenuForm* menu_form = menu_if_open()) { WeakElementPointer tmp(this); - int value = menu_window->list_box()->value(); - menu_window->Die(); + int value = menu_form->list_box()->value(); + menu_form->Die(); if (tmp.get()) { set_value(value); } } else { - OpenWindow(); + OpenForm(); } return true; - } else if (ev.target->id() == TBIDC("DropDownButton.window") && + } else if (ev.target->id() == TBIDC("DropDownButton.form") && ev.type == EventType::kClick) { // Set the value of the clicked item. - if (MenuWindow* menu_window = menu_if_open()) { - set_value(menu_window->list_box()->value()); + if (MenuForm* menu_form = menu_if_open()) { + set_value(menu_form->list_box()->value()); } return true; } else if (ev.target == this && m_source && ev.is_key_event()) { - if (MenuWindow* menu_window = menu_if_open()) { + if (MenuForm* menu_form = menu_if_open()) { // Redirect the key strokes to the list. Event redirected_ev(ev); - return menu_window->list_box()->InvokeEvent(redirected_ev); + return menu_form->list_box()->InvokeEvent(redirected_ev); } } return Element::OnEvent(ev); diff --git a/src/el/elements/drop_down_button.h b/src/el/elements/drop_down_button.h index 203e8af..afa347b 100644 --- a/src/el/elements/drop_down_button.h +++ b/src/el/elements/drop_down_button.h @@ -11,14 +11,14 @@ #define EL_ELEMENTS_DROP_DOWN_BUTTON_H_ #include "el/element.h" +#include "el/elements/form.h" #include "el/elements/icon_box.h" #include "el/list_item.h" -#include "el/window.h" namespace el { namespace elements { -class MenuWindow; +class MenuForm; // Shows a button that opens a popup with a ListBox with items provided by a // ItemSource. @@ -46,14 +46,14 @@ class DropDownButton : public Button, public ListItemObserver { // Gets the ID of the selected item, or 0 if there is no item selected. TBID selected_item_id(); - // Opens the window if the model has items. - void OpenWindow(); + // Opens the form if the model has items. + void OpenForm(); - // Closes the window if it is open. - void CloseWindow(); + // Closes the form if it is open. + void CloseForm(); - // Returns the menu window if it's open, or nullptr. - MenuWindow* menu_if_open() const; + // Returns the menu form if it's open, or nullptr. + MenuForm* menu_if_open() const; void OnInflate(const parsing::InflateInfo& info) override; bool OnEvent(const Event& ev) override; @@ -68,7 +68,7 @@ class DropDownButton : public Button, public ListItemObserver { GenericStringItemSource m_default_source; IconBox m_arrow; int m_value = -1; - WeakElementPointer m_window_pointer; // Dropdown window, if opened. + WeakElementPointer m_form_pointer; // Dropdown form, if opened. }; } // namespace elements diff --git a/src/el/window.cc b/src/el/elements/form.cc similarity index 65% rename from src/el/window.cc rename to src/el/elements/form.cc index 1c5e80f..34ff7af 100644 --- a/src/el/window.cc +++ b/src/el/elements/form.cc @@ -10,31 +10,32 @@ #include #include -#include "el/design/designer_window.h" +#include "el/design/designer_form.h" +#include "el/elements/form.h" #include "el/util/math.h" -#include "el/window.h" namespace el { +namespace elements { -Window::Window() { - set_background_skin(TBIDC("Window"), InvokeInfo::kNoCallbacks); +Form::Form() { + set_background_skin(TBIDC("Form"), InvokeInfo::kNoCallbacks); AddChild(&title_mover_); AddChild(&title_resizer_); - title_mover_.set_background_skin(TBIDC("Window.mover")); + title_mover_.set_background_skin(TBIDC("Form.mover")); title_mover_.AddChild(&title_label_); title_label_.set_ignoring_input(true); title_mover_.AddChild(&title_design_button_); - title_design_button_.set_background_skin(TBIDC("Window.close")); + title_design_button_.set_background_skin(TBIDC("Form.close")); title_design_button_.set_focusable(false); - title_design_button_.set_id(TBIDC("Window.design")); + title_design_button_.set_id(TBIDC("Form.design")); title_mover_.AddChild(&title_close_button_); - title_close_button_.set_background_skin(TBIDC("Window.close")); + title_close_button_.set_background_skin(TBIDC("Form.close")); title_close_button_.set_focusable(false); - title_close_button_.set_id(TBIDC("Window.close")); + title_close_button_.set_id(TBIDC("Form.close")); set_group_root(true); } -Window::~Window() { +Form::~Form() { title_resizer_.RemoveFromParent(); title_mover_.RemoveFromParent(); title_design_button_.RemoveFromParent(); @@ -42,7 +43,7 @@ Window::~Window() { title_mover_.RemoveChild(&title_label_); } -Rect Window::GetResizeToFitContentRect(ResizeFit fit) { +Rect Form::GetResizeToFitContentRect(ResizeFit fit) { PreferredSize ps = GetPreferredSize(); int new_w = ps.pref_w; int new_h = ps.pref_h; @@ -60,32 +61,32 @@ Rect Window::GetResizeToFitContentRect(ResizeFit fit) { return Rect(rect().x, rect().y, new_w, new_h); } -void Window::ResizeToFitContent(ResizeFit fit) { +void Form::ResizeToFitContent(ResizeFit fit) { set_rect(GetResizeToFitContentRect(fit)); } -void Window::Close() { Die(); } +void Form::Close() { Die(); } -bool Window::is_active() const { return has_state(Element::State::kSelected); } +bool Form::is_active() const { return has_state(Element::State::kSelected); } -Window* Window::GetTopMostOtherWindow(bool only_activable_windows) { - Window* other_window = nullptr; +Form* Form::GetTopMostOtherForm(bool only_activable_forms) { + Form* other_form = nullptr; Element* sibling = parent()->last_child(); - while (sibling && !other_window) { + while (sibling && !other_form) { if (sibling != this) { - other_window = util::SafeCast(sibling); + other_form = util::SafeCast
(sibling); } - if (only_activable_windows && other_window && - !any(other_window->window_settings_ & WindowSettings::kCanActivate)) { - other_window = nullptr; + if (only_activable_forms && other_form && + !any(other_form->form_settings_ & FormSettings::kCanActivate)) { + other_form = nullptr; } sibling = sibling->GetPrev(); } - return other_window; + return other_form; } -void Window::Activate() { - if (!parent() || !any(window_settings_ & WindowSettings::kCanActivate)) { +void Form::Activate() { + if (!parent() || !any(form_settings_ & FormSettings::kCanActivate)) { return; } if (is_active()) { @@ -95,19 +96,19 @@ void Window::Activate() { return; } - // Deactivate currently active window. - Window* active_window = GetTopMostOtherWindow(true); - if (active_window) { - active_window->Deactivate(); + // Deactivate currently active form. + Form* active_form = GetTopMostOtherForm(true); + if (active_form) { + active_form->Deactivate(); } - // Activate this window. + // Activate this form. set_z(ElementZ::kTop); - SetWindowActiveState(true); + SetFormActiveState(true); EnsureFocus(); } -bool Window::EnsureFocus() { +bool Form::EnsureFocus() { // If we already have focus, we're done. if (focused_element && IsAncestorOf(focused_element)) { return true; @@ -125,42 +126,42 @@ bool Window::EnsureFocus() { return success; } -void Window::Deactivate() { +void Form::Deactivate() { if (!is_active()) return; - SetWindowActiveState(false); + SetFormActiveState(false); } -void Window::SetWindowActiveState(bool active) { +void Form::SetFormActiveState(bool active) { set_state(Element::State::kSelected, active); title_mover_.set_state(Element::State::kSelected, active); } -void Window::set_settings(WindowSettings settings) { - if (settings == window_settings_) return; - window_settings_ = settings; +void Form::set_settings(FormSettings settings) { + if (settings == form_settings_) return; + form_settings_ = settings; - if (any(settings & WindowSettings::kTitleBar)) { + if (any(settings & FormSettings::kTitleBar)) { if (!title_mover_.parent()) { AddChild(&title_mover_); } } else { title_mover_.RemoveFromParent(); } - if (any(settings & WindowSettings::kResizable)) { + if (any(settings & FormSettings::kResizable)) { if (!title_resizer_.parent()) { AddChild(&title_resizer_); } } else { title_resizer_.RemoveFromParent(); } - if (any(settings & WindowSettings::kDesignButton)) { + if (any(settings & FormSettings::kDesignButton)) { if (!title_design_button_.parent()) { title_mover_.AddChild(&title_design_button_); } } else { title_design_button_.RemoveFromParent(); } - if (any(settings & WindowSettings::kCloseButton)) { + if (any(settings & FormSettings::kCloseButton)) { if (!title_close_button_.parent()) { title_mover_.AddChild(&title_close_button_); } @@ -168,19 +169,19 @@ void Window::set_settings(WindowSettings settings) { title_close_button_.RemoveFromParent(); } - if (any(settings & WindowSettings::kFullScreen)) { - set_background_skin(TBIDC("Window.fullscreen")); + if (any(settings & FormSettings::kFullScreen)) { + set_background_skin(TBIDC("Form.fullscreen")); set_gravity(Gravity::kAll); FitToParent(); } else { - set_background_skin(TBIDC("Window")); + set_background_skin(TBIDC("Form")); } - // FIX: invalidate layout / resize window! + // FIX: invalidate layout / resize form! Invalidate(); } -void Window::CenterInParent() { +void Form::CenterInParent() { if (!parent()) { return; } @@ -188,14 +189,14 @@ void Window::CenterInParent() { set_rect(rect().CenterIn(bounds).MoveIn(bounds).Clip(bounds)); } -int Window::title_bar_height() { - if (any(window_settings_ & WindowSettings::kTitleBar)) { +int Form::title_bar_height() { + if (any(form_settings_ & FormSettings::kTitleBar)) { return title_mover_.GetPreferredSize().pref_h; } return 0; } -Rect Window::padding_rect() { +Rect Form::padding_rect() { Rect padding_rect = Element::padding_rect(); int title_height = title_bar_height(); padding_rect.y += title_height; @@ -203,25 +204,25 @@ Rect Window::padding_rect() { return padding_rect; } -PreferredSize Window::OnCalculatePreferredSize( +PreferredSize Form::OnCalculatePreferredSize( const SizeConstraints& constraints) { PreferredSize ps = OnCalculatePreferredContentSize(constraints); - // Add window skin padding + // Add form skin padding if (auto e = background_skin_element()) { ps.min_w += e->padding_left + e->padding_right; ps.pref_w += e->padding_left + e->padding_right; ps.min_h += e->padding_top + e->padding_bottom; ps.pref_h += e->padding_top + e->padding_bottom; } - // Add window title bar height + // Add form title bar height int title_height = title_bar_height(); ps.min_h += title_height; ps.pref_h += title_height; return ps; } -bool Window::OnEvent(const Event& ev) { +bool Form::OnEvent(const Event& ev) { if (ev.target == &title_close_button_) { if (ev.type == EventType::kClick) { Close(); @@ -236,31 +237,30 @@ bool Window::OnEvent(const Event& ev) { return Element::OnEvent(ev); } -void Window::OnAdded() { +void Form::OnAdded() { // If we was added last, call Activate to update status etc. if (parent()->last_child() == this) { Activate(); } // Fit if needed. - if (any(window_settings_ & WindowSettings::kFullScreen)) { + if (any(form_settings_ & FormSettings::kFullScreen)) { FitToParent(); } } -void Window::OnRemove() { +void Form::OnRemove() { Deactivate(); - // Active the top most other window - if (Window* active_window = GetTopMostOtherWindow(true)) - active_window->Activate(); + // Active the top most other form + if (Form* active_form = GetTopMostOtherForm(true)) active_form->Activate(); } -void Window::OnChildAdded(Element* child) { +void Form::OnChildAdded(Element* child) { title_resizer_.set_z(ElementZ::kTop); } -void Window::OnResized(int old_w, int old_h) { +void Form::OnResized(int old_w, int old_h) { // Apply gravity on children. Element::OnResized(old_w, old_h); // Manually move our own decoration children. @@ -278,19 +278,20 @@ void Window::OnResized(int old_w, int old_h) { title_close_button_.set_rect( {title_mover_rect.x + title_mover_rect.w - button_size, title_mover_rect.y, button_size, button_size}); - if (any(window_settings_ & WindowSettings::kDesignButton)) { + if (any(form_settings_ & FormSettings::kDesignButton)) { title_mover_rect.w -= button_size; } - if (any(window_settings_ & WindowSettings::kCloseButton)) { + if (any(form_settings_ & FormSettings::kCloseButton)) { title_mover_rect.w -= button_size; } title_label_.set_rect(title_mover_rect); } -void Window::OpenDesigner() { - auto designer_window = new design::DesignerWindow(); - designer_window->BindContent(this); - designer_window->Show(this); +void Form::OpenDesigner() { + auto designer_form = new design::DesignerForm(); + designer_form->BindContent(this); + designer_form->Show(this); } +} // namespace elements } // namespace el diff --git a/src/el/window.h b/src/el/elements/form.h similarity index 63% rename from src/el/window.h rename to src/el/elements/form.h index a2ed3d5..063f483 100644 --- a/src/el/window.h +++ b/src/el/elements/form.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef EL_WINDOW_H_ -#define EL_WINDOW_H_ +#ifndef EL_ELEMENTS_FORM_H_ +#define EL_ELEMENTS_FORM_H_ #include "el/element_listener.h" #include "el/elements/button.h" @@ -17,69 +17,70 @@ #include "el/elements/resizer.h" namespace el { +namespace elements { -enum class WindowSettings { - kNone = 0, // Chrome less window without any other settings. - kTitleBar = 1 << 0, // Show a title bar that can also move the window. - kResizable = 1 << 1, // Show an element for resizing the window. - kCloseButton = 1 << 2, // Show an element for closing the window. - kCanActivate = 1 << 3, // Can be activated and deactivate other windows. - kDesignButton = 1 << 4, // Show a button to open a designer for the window. +enum class FormSettings { + kNone = 0, // Chrome less form without any other settings. + kTitleBar = 1 << 0, // Show a title bar that can also move the form. + kResizable = 1 << 1, // Show an element for resizing the form. + kCloseButton = 1 << 2, // Show an element for closing the form. + kCanActivate = 1 << 3, // Can be activated and deactivate other forms. + kDesignButton = 1 << 4, // Show a button to open a designer for the form. kFullScreen = 1 << 5, // Fully fill parent. kDefault = kTitleBar | kResizable | kCloseButton | kCanActivate | kDesignButton, }; -MAKE_ENUM_FLAG_COMBO(WindowSettings); +MAKE_ENUM_FLAG_COMBO(FormSettings); -// A Element that provides some window-like features. +// A Element that provides some form-like features. // It can have a titlebar, be movable, resizable etc. -// It will activate and deactivate other windows on click (which will restore +// It will activate and deactivate other forms on click (which will restore // focus to the last focused child element). -class Window : public Element { +class Form : public Element { public: - TBOBJECT_SUBCLASS(Window, Element); + TBOBJECT_SUBCLASS(Form, Element); - Window(); - ~Window() override; + Form(); + ~Form() override; - // Closes this window. - // NOTE: This window will be deleted after this call! + // Closes this form. + // NOTE: This form will be deleted after this call! void Close(); - // Returns true if this window is active. + // Returns true if this form is active. bool is_active() const; - // Activates this window if it's not already activated. - // This will deactivate any currently activated window. + // Activates this form if it's not already activated. + // This will deactivate any currently activated form. // This will automatically call EnsureFocus to restore/set focus to this - // window. + // form. void Activate(); - // Ensures that this window has focus by attempting to find a focusable child + // Ensures that this form has focus by attempting to find a focusable child // element. // It will first try to restore focus to the last focused element in this - // window, or a element that has received SetFocus while the window was + // form, or a element that has received SetFocus while the form was // inactive. If that doesn't succeed, it will go through all children and try // to set focus. // Returns false if no focusable child was found. bool EnsureFocus(); - // Sets the element that should be focused when this window is activated next + // Sets the element that should be focused when this form is activated next // time. // This should not be used to change focus. Call Element::SetFocus to focus, - // which will call this method if the window is inactive! + // which will call this method if the form is inactive! void set_last_focus(Element* last_focus) { last_focus_element_.reset(last_focus); } - WindowSettings settings() const { return window_settings_; } - // Sets settings for how this window should look and behave. - void set_settings(WindowSettings settings); + FormSettings settings() const { return form_settings_; } + // Sets settings for how this form should look and behave. + void set_settings(FormSettings settings); void CenterInParent(); - // ResizeFit specifies how ResizeToFitContent should resize the window. + // ResizeFit specifies how ResizeToFitContent should resize the form. enum class ResizeFit { kPreferred, // Fit the preferred size of all content. kMinimal, // Fit the minimal size of all content. @@ -88,21 +89,21 @@ class Window : public Element { // size. }; - // Gets a suitable rect for the window based on the contents and the given + // Gets a suitable rect for the form based on the contents and the given // fit. Rect GetResizeToFitContentRect(ResizeFit fit = ResizeFit::kPreferred); - // Resizes the window to fit the its content. This is the same as doing + // Resizes the form to fit the its content. This is the same as doing // set_rect(GetResizeToFitContentRect(fit)). void ResizeToFitContent(ResizeFit fit = ResizeFit::kPreferred); std::string text() override { return title_label_.text(); } - // Sets the window title. + // Sets the form title. void set_text(const char* text) override { title_label_.set_text(text); } using Element::set_text; - // Gets the height of the title bar (or 0 if the WindowSettings say this - // window shouldn't have any title bar). + // Gets the height of the title bar (or 0 if the FormSettings say this + // form shouldn't have any title bar). int title_bar_height(); Rect padding_rect() override; @@ -118,8 +119,8 @@ class Window : public Element { void OpenDesigner(); protected: - Window* GetTopMostOtherWindow(bool only_activable_windows); - void SetWindowActiveState(bool active); + Form* GetTopMostOtherForm(bool only_activable_forms); + void SetFormActiveState(bool active); void Deactivate(); elements::Mover title_mover_; @@ -127,10 +128,11 @@ class Window : public Element { elements::Label title_label_; elements::Button title_design_button_; elements::Button title_close_button_; - WindowSettings window_settings_ = WindowSettings::kDefault; + FormSettings form_settings_ = FormSettings::kDefault; WeakElementPointer last_focus_element_; }; +} // namespace elements } // namespace el -#endif // EL_WINDOW_H_ +#endif // EL_ELEMENTS_FORM_H_ diff --git a/src/el/elements/list_box.cc b/src/el/elements/list_box.cc index 559c0b1..3834ff1 100644 --- a/src/el/elements/list_box.cc +++ b/src/el/elements/list_box.cc @@ -7,13 +7,13 @@ ****************************************************************************** */ +#include "el/elements/form.h" #include "el/elements/label.h" #include "el/elements/list_box.h" -#include "el/elements/menu_window.h" +#include "el/elements/menu_form.h" #include "el/parsing/element_inflater.h" #include "el/util/string.h" #include "el/util/string_table.h" -#include "el/window.h" namespace el { namespace elements { @@ -277,15 +277,15 @@ bool ListBox::OnEvent(const Event& ev) { // If we're still around, invoke the click event too. if (this_element.get()) { ListBox* target_list = this; - // If the parent window is a MenuWindow, we will iterate up the event - // destination chain to find the top MenuWindow and invoke the event + // If the parent form is a MenuForm, we will iterate up the event + // destination chain to find the top MenuForm and invoke the event // there. // That way events in submenus will reach the caller properly, and seem // like it was invoked on the top menu. - Window* window = parent_window(); - while (auto menu_win = util::SafeCast(window)) { + Form* form = parent_form(); + while (auto menu_win = util::SafeCast(form)) { target_list = menu_win->list_box(); - window = menu_win->event_destination()->parent_window(); + form = menu_win->event_destination()->parent_form(); } // Invoke the click event on the target list. diff --git a/src/el/elements/menu_window.cc b/src/el/elements/menu_form.cc similarity index 72% rename from src/el/elements/menu_window.cc rename to src/el/elements/menu_form.cc index 1d907bb..81b7a2a 100644 --- a/src/el/elements/menu_window.cc +++ b/src/el/elements/menu_form.cc @@ -8,16 +8,16 @@ */ #include "el/element_listener.h" -#include "el/elements/menu_window.h" +#include "el/elements/menu_form.h" namespace el { namespace elements { -MenuWindow::MenuWindow(Element* target, TBID id) : PopupWindow(target) { +MenuForm::MenuForm(Element* target, TBID id) : PopupForm(target) { set_id(id); - set_background_skin(TBIDC("MenuWindow"), InvokeInfo::kNoCallbacks); + set_background_skin(TBIDC("MenuForm"), InvokeInfo::kNoCallbacks); m_select_list.scroll_container()->set_adapt_to_content_size(true); - // Avoid it autoclosing its window on click: + // Avoid it autoclosing its form on click: m_select_list.set_focusable(false); m_select_list.set_background_skin(""); m_select_list.set_rect(padding_rect()); @@ -25,17 +25,17 @@ MenuWindow::MenuWindow(Element* target, TBID id) : PopupWindow(target) { AddChild(&m_select_list); } -MenuWindow::~MenuWindow() { RemoveChild(&m_select_list); } +MenuForm::~MenuForm() { RemoveChild(&m_select_list); } -void MenuWindow::Show(ListItemSource* source, const PopupAlignment& alignment, - int initial_value) { +void MenuForm::Show(ListItemSource* source, const PopupAlignment& alignment, + int initial_value) { m_select_list.set_value(initial_value); m_select_list.set_source(source); m_select_list.ValidateList(); - PopupWindow::Show(alignment); + PopupForm::Show(alignment); } -bool MenuWindow::OnEvent(const Event& ev) { +bool MenuForm::OnEvent(const Event& ev) { if (ev.type == EventType::kClick && &m_select_list == ev.target) { WeakElementPointer this_element(this); @@ -50,7 +50,7 @@ bool MenuWindow::OnEvent(const Event& ev) { } return true; } - return PopupWindow::OnEvent(ev); + return PopupForm::OnEvent(ev); } } // namespace elements diff --git a/src/el/elements/menu_window.h b/src/el/elements/menu_form.h similarity index 68% rename from src/el/elements/menu_window.h rename to src/el/elements/menu_form.h index 70e1314..9eb800f 100644 --- a/src/el/elements/menu_window.h +++ b/src/el/elements/menu_form.h @@ -7,25 +7,25 @@ ****************************************************************************** */ -#ifndef EL_ELEMENTS_MENU_WINDOW_H_ -#define EL_ELEMENTS_MENU_WINDOW_H_ +#ifndef EL_ELEMENTS_MENU_FORM_H_ +#define EL_ELEMENTS_MENU_FORM_H_ #include "el/elements/list_box.h" -#include "el/elements/popup_window.h" +#include "el/elements/popup_form.h" namespace el { namespace elements { -// MenuWindow is a popup window that shows a list of items (ListBox). +// MenuForm is a popup form that shows a list of items (ListBox). // When selected it will invoke a click with the id given to the menu, // and the id of the clicked item as ref_id, and then close itself. -// It may open sub items as new windows at the same time as this window is open. -class MenuWindow : public PopupWindow { +// It may open sub items as new forms at the same time as this form is open. +class MenuForm : public PopupForm { public: - TBOBJECT_SUBCLASS(MenuWindow, PopupWindow); + TBOBJECT_SUBCLASS(MenuForm, PopupForm); - MenuWindow(Element* target, TBID id); - ~MenuWindow() override; + MenuForm(Element* target, TBID id); + ~MenuForm() override; void Show(ListItemSource* source, const PopupAlignment& alignment, int initial_value = -1); @@ -41,4 +41,4 @@ class MenuWindow : public PopupWindow { } // namespace elements } // namespace el -#endif // EL_ELEMENTS_MENU_WINDOW_H_ +#endif // EL_ELEMENTS_MENU_FORM_H_ diff --git a/src/el/elements/message_window.cc b/src/el/elements/message_form.cc similarity index 78% rename from src/el/elements/message_window.cc rename to src/el/elements/message_form.cc index 76948c8..b934543 100644 --- a/src/el/elements/message_window.cc +++ b/src/el/elements/message_form.cc @@ -11,19 +11,19 @@ #include "el/elements/dimmer.h" #include "el/elements/icon_box.h" -#include "el/elements/message_window.h" +#include "el/elements/message_form.h" #include "el/elements/text_box.h" #include "el/util/string_table.h" namespace el { namespace elements { -MessageWindow::MessageWindow(Element* target, TBID id) : m_target(target) { +MessageForm::MessageForm(Element* target, TBID id) : m_target(target) { ElementListener::AddGlobalListener(this); set_id(id); } -MessageWindow::~MessageWindow() { +MessageForm::~MessageForm() { ElementListener::RemoveGlobalListener(this); if (Element* dimmer = m_dimmer.get()) { dimmer->parent()->RemoveChild(dimmer); @@ -31,12 +31,12 @@ MessageWindow::~MessageWindow() { } } -bool MessageWindow::Show(const std::string& title, const std::string& message, - MessageWindowSettings* settings) { +bool MessageForm::Show(const std::string& title, const std::string& message, + MessageFormSettings* settings) { Element* target = m_target.get(); if (!target) return false; - MessageWindowSettings default_settings; + MessageFormSettings default_settings; if (!settings) { settings = &default_settings; } @@ -63,14 +63,14 @@ bool MessageWindow::Show(const std::string& title, const std::string& message, text_box->set_background_skin(""); // Create buttons. - if (settings->msg == MessageWindowButtons::kOk) { - AddButton("MessageWindow.ok", true); - } else if (settings->msg == MessageWindowButtons::kOkCancel) { - AddButton("MessageWindow.ok", true); - AddButton("MessageWindow.cancel", false); - } else if (settings->msg == MessageWindowButtons::kYesNo) { - AddButton("MessageWindow.yes", true); - AddButton("MessageWindow.no", false); + if (settings->msg == MessageFormButtons::kOk) { + AddButton("MessageForm.ok", true); + } else if (settings->msg == MessageFormButtons::kOkCancel) { + AddButton("MessageForm.ok", true); + AddButton("MessageForm.cancel", false); + } else if (settings->msg == MessageFormButtons::kYesNo) { + AddButton("MessageForm.yes", true); + AddButton("MessageForm.no", false); } // Size to fit content. This will use the default size of the textfield. @@ -98,7 +98,7 @@ bool MessageWindow::Show(const std::string& title, const std::string& message, return true; } -void MessageWindow::AddButton(TBID id, bool focused) { +void MessageForm::AddButton(TBID id, bool focused) { auto layout = GetElementById(3); if (!layout) return; Button* btn = new Button(); @@ -110,7 +110,7 @@ void MessageWindow::AddButton(TBID id, bool focused) { } } -bool MessageWindow::OnEvent(const Event& ev) { +bool MessageForm::OnEvent(const Event& ev) { if (ev.type == EventType::kClick && ev.target->IsOfType