| 
									
										
										
										
											2013-08-09 08:01:20 +08:00
										 |  |  | // Aseprite UI Library
 | 
					
						
							| 
									
										
										
										
											2023-01-12 22:00:16 +08:00
										 |  |  | // Copyright (C) 2018-2023  Igara Studio S.A.
 | 
					
						
							| 
									
										
										
										
											2017-02-14 05:34:23 +08:00
										 |  |  | // Copyright (C) 2001-2017  David Capello
 | 
					
						
							| 
									
										
										
										
											2010-09-28 06:18:17 +08:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-03-30 07:08:05 +08:00
										 |  |  | // This file is released under the terms of the MIT license.
 | 
					
						
							|  |  |  | // Read LICENSE.txt for more information.
 | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-07-13 04:29:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-23 02:43:53 +08:00
										 |  |  | #include "ui/combobox.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-26 03:22:32 +08:00
										 |  |  | #include "gfx/size.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-09 23:58:43 +08:00
										 |  |  | #include "os/font.h"
 | 
					
						
							| 
									
										
										
										
											2017-05-23 02:43:53 +08:00
										 |  |  | #include "ui/button.h"
 | 
					
						
							|  |  |  | #include "ui/entry.h"
 | 
					
						
							| 
									
										
										
										
											2021-04-20 23:13:19 +08:00
										 |  |  | #include "ui/fit_bounds.h"
 | 
					
						
							| 
									
										
										
										
											2017-05-23 02:43:53 +08:00
										 |  |  | #include "ui/listbox.h"
 | 
					
						
							|  |  |  | #include "ui/listitem.h"
 | 
					
						
							|  |  |  | #include "ui/manager.h"
 | 
					
						
							|  |  |  | #include "ui/message.h"
 | 
					
						
							|  |  |  | #include "ui/resize_event.h"
 | 
					
						
							|  |  |  | #include "ui/scale.h"
 | 
					
						
							|  |  |  | #include "ui/size_hint_event.h"
 | 
					
						
							|  |  |  | #include "ui/system.h"
 | 
					
						
							|  |  |  | #include "ui/theme.h"
 | 
					
						
							|  |  |  | #include "ui/view.h"
 | 
					
						
							|  |  |  | #include "ui/window.h"
 | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-21 02:08:34 +08:00
										 |  |  | #include <algorithm>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | namespace ui { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | using namespace gfx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ComboBoxButton : public Button { | 
					
						
							| 
									
										
										
										
											2011-03-07 03:15:05 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   ComboBoxButton() : Button("") { setFocusStop(false); } | 
					
						
							| 
									
										
										
										
											2011-03-07 03:15:05 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  | class ComboBoxEntry : public Entry { | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   ComboBoxEntry(ComboBox* comboBox) : Entry(256, ""), m_comboBox(comboBox) {} | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2014-08-15 10:07:47 +08:00
										 |  |  |   bool onProcessMessage(Message* msg) override; | 
					
						
							|  |  |  |   void onPaint(PaintEvent& ev) override; | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  |   void onChange() override; | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |   ComboBox* m_comboBox; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  | class ComboBoxListBox : public ListBox { | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   ComboBoxListBox(ComboBox* comboBox) : m_comboBox(comboBox) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  |     for (auto item : *comboBox) { | 
					
						
							|  |  |  |       if (item->parent()) | 
					
						
							|  |  |  |         item->parent()->removeChild(item); | 
					
						
							|  |  |  |       addChild(item); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   void clean() | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |     // Remove all added items so ~Widget() don't delete them.
 | 
					
						
							| 
									
										
										
										
											2015-03-05 03:38:01 +08:00
										 |  |  |     removeAllChildren(); | 
					
						
							|  |  |  |     selectChild(nullptr); | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2014-08-15 10:07:47 +08:00
										 |  |  |   bool onProcessMessage(Message* msg) override; | 
					
						
							| 
									
										
										
										
											2015-08-26 00:56:21 +08:00
										 |  |  |   void onChange() override; | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   bool isValidItem(int index) const { return (index >= 0 && index < m_comboBox->getItemCount()); } | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ComboBox* m_comboBox; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | ComboBox::ComboBox() | 
					
						
							| 
									
										
										
										
											2013-04-04 09:07:24 +08:00
										 |  |  |   : Widget(kComboBoxWidget) | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   , m_entry(new ComboBoxEntry(this)) | 
					
						
							|  |  |  |   , m_button(new ComboBoxButton()) | 
					
						
							|  |  |  |   , m_window(nullptr) | 
					
						
							|  |  |  |   , m_listbox(nullptr) | 
					
						
							|  |  |  |   , m_selected(-1) | 
					
						
							|  |  |  |   , m_editable(false) | 
					
						
							|  |  |  |   , m_clickopen(true) | 
					
						
							|  |  |  |   , m_casesensitive(true) | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  |   , m_filtering(false) | 
					
						
							|  |  |  |   , m_useCustomWidget(false) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-06 06:00:19 +08:00
										 |  |  |   m_entry->setExpansive(true); | 
					
						
							| 
									
										
										
										
											2010-08-24 04:41:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // When the "m_button" is clicked ("Click" signal) call onButtonClick() method
 | 
					
						
							|  |  |  |   m_button->Click.connect(&ComboBox::onButtonClick, this); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-30 08:35:17 +08:00
										 |  |  |   addChild(m_entry); | 
					
						
							|  |  |  |   addChild(m_button); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |   setFocusStop(true); | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   setEditable(m_editable); | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-15 20:00:29 +08:00
										 |  |  |   initTheme(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | ComboBox::~ComboBox() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  |   removeMessageFilters(); | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  |   deleteAllItems(); | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | void ComboBox::setEditable(bool state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   m_editable = state; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (state) { | 
					
						
							| 
									
										
										
										
											2010-12-09 01:28:13 +08:00
										 |  |  |     m_entry->setReadOnly(false); | 
					
						
							|  |  |  |     m_entry->showCaret(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2010-12-09 01:28:13 +08:00
										 |  |  |     m_entry->setReadOnly(true); | 
					
						
							|  |  |  |     m_entry->hideCaret(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | void ComboBox::setClickOpen(bool state) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   m_clickopen = state; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | void ComboBox::setCaseSensitive(bool state) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   m_casesensitive = state; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  | void ComboBox::setUseCustomWidget(bool state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   m_useCustomWidget = state; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  | int ComboBox::addItem(Widget* item) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   bool sel_first = m_items.empty(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   m_items.push_back(item); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   if (sel_first && !isEditable()) | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |     setSelectedItemIndex(0); | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   return m_items.size() - 1; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 06:53:27 +08:00
										 |  |  | int ComboBox::addItem(const std::string& text) | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | { | 
					
						
							|  |  |  |   return addItem(new ListItem(text)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  | void ComboBox::insertItem(int itemIndex, Widget* item) | 
					
						
							| 
									
										
										
										
											2010-03-08 09:48:01 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   bool sel_first = m_items.empty(); | 
					
						
							| 
									
										
										
										
											2010-03-08 09:48:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   m_items.insert(m_items.begin() + itemIndex, item); | 
					
						
							| 
									
										
										
										
											2010-03-08 09:48:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (sel_first) | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |     setSelectedItemIndex(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 06:53:27 +08:00
										 |  |  | void ComboBox::insertItem(int itemIndex, const std::string& text) | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | { | 
					
						
							|  |  |  |   insertItem(itemIndex, new ListItem(text)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  | void ComboBox::removeItem(Widget* item) | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   auto it = std::find(m_items.begin(), m_items.end(), item); | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |   ASSERT(it != m_items.end()); | 
					
						
							|  |  |  |   if (it != m_items.end()) | 
					
						
							|  |  |  |     m_items.erase(it); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Do not delete the given "item"
 | 
					
						
							| 
									
										
										
										
											2010-03-08 09:48:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  | void ComboBox::deleteItem(int itemIndex) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-05 08:35:11 +08:00
										 |  |  |   ASSERT(itemIndex >= 0 && (std::size_t)itemIndex < m_items.size()); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   Widget* item = m_items[itemIndex]; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   m_items.erase(m_items.begin() + itemIndex); | 
					
						
							|  |  |  |   delete item; | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  | void ComboBox::deleteAllItems() | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-05-20 21:57:50 +08:00
										 |  |  |   // Delete all items back to front, in this way Widget::removeChild()
 | 
					
						
							|  |  |  |   // doesn't have to use linear search to update m_parentIndex of all
 | 
					
						
							|  |  |  |   // other children.
 | 
					
						
							|  |  |  |   auto end = m_items.rend(); | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   for (auto it = m_items.rbegin(); it != end; ++it) | 
					
						
							|  |  |  |     delete *it; // widget
 | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   m_items.clear(); | 
					
						
							| 
									
										
										
										
											2015-08-13 02:17:53 +08:00
										 |  |  |   m_selected = -1; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | int ComboBox::getItemCount() const | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   return m_items.size(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  | Widget* ComboBox::getItem(const int itemIndex) const | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-05 08:35:11 +08:00
										 |  |  |   if (itemIndex >= 0 && (std::size_t)itemIndex < m_items.size()) { | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |     return m_items[itemIndex]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2020-04-09 04:48:06 +08:00
										 |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 06:53:27 +08:00
										 |  |  | const std::string& ComboBox::getItemText(int itemIndex) const | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-05 08:35:11 +08:00
										 |  |  |   if (itemIndex >= 0 && (std::size_t)itemIndex < m_items.size()) { | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |     Widget* item = m_items[itemIndex]; | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |     return item->text(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-10-15 06:58:11 +08:00
										 |  |  |   else { | 
					
						
							|  |  |  |     // Returns the text of the combo-box (it should be empty).
 | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |     ASSERT(text().empty()); | 
					
						
							|  |  |  |     return text(); | 
					
						
							| 
									
										
										
										
											2013-10-15 06:58:11 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 06:53:27 +08:00
										 |  |  | void ComboBox::setItemText(int itemIndex, const std::string& text) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-05 08:35:11 +08:00
										 |  |  |   ASSERT(itemIndex >= 0 && (std::size_t)itemIndex < m_items.size()); | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   Widget* item = m_items[itemIndex]; | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |   item->setText(text); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  | int ComboBox::findItemIndex(const std::string& text) const | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  |   int i = 0; | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   for (const Widget* item : m_items) { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |     if ((m_casesensitive && item->text() == text) || (!m_casesensitive && item->text() == text)) { | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  |       return i; | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  |     i++; | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  |   return -1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  | int ComboBox::findItemIndexByValue(const std::string& value) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int i = 0; | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   for (const Widget* item : m_items) { | 
					
						
							|  |  |  |     if (auto listItem = dynamic_cast<const ListItem*>(item)) { | 
					
						
							|  |  |  |       if (listItem->getValue() == value) | 
					
						
							|  |  |  |         return i; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ++i; | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  | Widget* ComboBox::getSelectedItem() const | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  |   return getItem(m_selected); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  | void ComboBox::setSelectedItem(Widget* item) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   auto it = std::find(m_items.begin(), m_items.end(), item); | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |   if (it != m_items.end()) | 
					
						
							|  |  |  |     setSelectedItemIndex(std::distance(m_items.begin(), it)); | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   else if (m_selected >= 0) { | 
					
						
							|  |  |  |     m_selected = -1; | 
					
						
							|  |  |  |     onChange(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | int ComboBox::getSelectedItemIndex() const | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   return (!m_items.empty() ? m_selected : -1); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  | void ComboBox::setSelectedItemIndex(int itemIndex) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   if (itemIndex >= 0 && (std::size_t)itemIndex < m_items.size() && m_selected != itemIndex) { | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |     m_selected = itemIndex; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |     auto it = m_items.begin() + itemIndex; | 
					
						
							|  |  |  |     Widget* item = *it; | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |     m_entry->setText(item->text()); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |     if (isEditable()) | 
					
						
							| 
									
										
										
										
											2017-02-21 21:48:25 +08:00
										 |  |  |       m_entry->setCaretToEnd(); | 
					
						
							| 
									
										
										
										
											2014-03-30 05:42:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     onChange(); | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  | std::string ComboBox::getValue() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   if (isEditable()) | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |     return m_entry->text(); | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   int index = getSelectedItemIndex(); | 
					
						
							|  |  |  |   if (index >= 0) { | 
					
						
							|  |  |  |     if (auto listItem = dynamic_cast<ListItem*>(m_items[index])) | 
					
						
							|  |  |  |       return listItem->getValue(); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   return std::string(); | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ComboBox::setValue(const std::string& value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   if (isEditable()) { | 
					
						
							|  |  |  |     m_entry->setText(value); | 
					
						
							| 
									
										
										
										
											2022-06-15 23:25:31 +08:00
										 |  |  |     if (hasFocus()) | 
					
						
							|  |  |  |       m_entry->selectAllText(); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     int index = findItemIndexByValue(value); | 
					
						
							|  |  |  |     if (index >= 0) | 
					
						
							|  |  |  |       setSelectedItemIndex(index); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-09 18:46:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-09 01:28:13 +08:00
										 |  |  | Entry* ComboBox::getEntryWidget() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   return m_entry; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-24 04:41:19 +08:00
										 |  |  | Button* ComboBox::getButtonWidget() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   return m_button; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-03 00:14:07 +08:00
										 |  |  | bool ComboBox::onProcessMessage(Message* msg) | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  |   switch (msg->type()) { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |     case kCloseMessage: closeListBox(); break; | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 08:53:29 +08:00
										 |  |  |     case kWinMoveMessage: | 
					
						
							| 
									
										
										
										
											2021-04-20 23:13:19 +08:00
										 |  |  |       // If we mouse the parent window, we close the list box popup.
 | 
					
						
							|  |  |  |       closeListBox(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-07 03:27:45 +08:00
										 |  |  |     case kKeyDownMessage: | 
					
						
							|  |  |  |       if (m_window) { | 
					
						
							|  |  |  |         KeyMessage* keymsg = static_cast<KeyMessage*>(msg); | 
					
						
							|  |  |  |         KeyScancode scancode = keymsg->scancode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // If the popup is opened
 | 
					
						
							|  |  |  |         if (scancode == kKeyEsc) { | 
					
						
							|  |  |  |           closeListBox(); | 
					
						
							|  |  |  |           return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 08:53:29 +08:00
										 |  |  |     case kMouseDownMessage: | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |       if (m_window) { | 
					
						
							| 
									
										
										
										
											2021-04-20 23:13:19 +08:00
										 |  |  |         if (View::getView(m_listbox)->hasMouse()) { | 
					
						
							|  |  |  |           // As we are filtering the kMouseDownMessage, and the
 | 
					
						
							|  |  |  |           // ListBox has the mouse, we "return false" here to say "we
 | 
					
						
							|  |  |  |           // are not interested in this mouse message, it will be
 | 
					
						
							|  |  |  |           // processed by the ListBox itself". In other case, if we
 | 
					
						
							|  |  |  |           // "break" and call Widget::onProcessMessage(), the message
 | 
					
						
							|  |  |  |           // will be propagated to the parent window and could be used
 | 
					
						
							|  |  |  |           // to move the parent window (instead of clicking a listbox
 | 
					
						
							|  |  |  |           // item of the popup m_window).
 | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2021-05-29 02:44:27 +08:00
										 |  |  |           MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // Use the nativeWindow() from the mouseMsg before we close
 | 
					
						
							|  |  |  |           // the listbox because the mouseMsg->display() could be from
 | 
					
						
							|  |  |  |           // the same popup.
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |           const gfx::Point screenPos = mouseMsg->display()->nativeWindow()->pointToScreen( | 
					
						
							|  |  |  |             mouseMsg->position()); | 
					
						
							| 
									
										
										
										
											2021-05-29 02:44:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |           closeListBox(); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-29 02:44:27 +08:00
										 |  |  |           Widget* pick = manager()->pickFromScreenPos(screenPos); | 
					
						
							| 
									
										
										
										
											2018-12-13 00:25:12 +08:00
										 |  |  |           if (pick && pick->hasAncestor(this)) | 
					
						
							|  |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-25 03:45:35 +08:00
										 |  |  |     case kFocusEnterMessage: | 
					
						
							|  |  |  |       // Here we focus the entry field only if the combobox is
 | 
					
						
							|  |  |  |       // editable and receives the focus in a direct way (e.g. when
 | 
					
						
							|  |  |  |       // the window was just opened and the combobox is the first
 | 
					
						
							|  |  |  |       // child or has the "focus magnet" flag enabled.)
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |       if ((isEditable()) && (manager()->getFocus() == this)) { | 
					
						
							| 
									
										
										
										
											2015-08-25 03:45:35 +08:00
										 |  |  |         m_entry->requestFocus(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 08:29:56 +08:00
										 |  |  |   return Widget::onProcessMessage(msg); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 21:39:06 +08:00
										 |  |  | void ComboBox::onInitTheme(InitThemeEvent& ev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Widget::onInitTheme(ev); | 
					
						
							|  |  |  |   if (m_window) { | 
					
						
							|  |  |  |     m_window->initTheme(); | 
					
						
							|  |  |  |     m_window->noBorderNoChildSpacing(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-12 04:56:27 +08:00
										 |  |  | void ComboBox::onResize(ResizeEvent& ev) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |   gfx::Rect bounds = ev.bounds(); | 
					
						
							| 
									
										
										
										
											2013-05-12 04:56:27 +08:00
										 |  |  |   setBoundsQuietly(bounds); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Button
 | 
					
						
							| 
									
										
										
										
											2015-12-04 08:50:05 +08:00
										 |  |  |   Size buttonSize = m_button->sizeHint(); | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   m_button->setBounds(Rect(bounds.x2() - buttonSize.w, bounds.y, buttonSize.w, bounds.h)); | 
					
						
							| 
									
										
										
										
											2013-05-12 04:56:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Entry
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   m_entry->setBounds(Rect(bounds.x, bounds.y, bounds.w - buttonSize.w, bounds.h)); | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   putSelectedItemAsCustomWidget(); | 
					
						
							| 
									
										
										
										
											2013-05-12 04:56:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-04 08:50:05 +08:00
										 |  |  | void ComboBox::onSizeHint(SizeHintEvent& ev) | 
					
						
							| 
									
										
										
										
											2010-08-03 09:57:41 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-27 03:46:02 +08:00
										 |  |  |   Size reqSize(0, 0); | 
					
						
							| 
									
										
										
										
											2010-08-03 09:57:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-27 03:46:02 +08:00
										 |  |  |   // Calculate the max required width depending on the text-length of
 | 
					
						
							|  |  |  |   // each item.
 | 
					
						
							|  |  |  |   for (const auto& item : m_items) | 
					
						
							|  |  |  |     reqSize |= Entry::sizeHintWithText(m_entry, item->text()); | 
					
						
							| 
									
										
										
										
											2010-08-03 09:57:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-04 08:50:05 +08:00
										 |  |  |   Size buttonSize = m_button->sizeHint(); | 
					
						
							| 
									
										
										
										
											2010-08-03 09:57:41 +08:00
										 |  |  |   reqSize.w += buttonSize.w; | 
					
						
							| 
									
										
										
										
											2019-12-21 02:08:34 +08:00
										 |  |  |   reqSize.h = std::max(reqSize.h, buttonSize.h); | 
					
						
							| 
									
										
										
										
											2018-11-27 03:46:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-04 08:50:05 +08:00
										 |  |  |   ev.setSizeHint(reqSize); | 
					
						
							| 
									
										
										
										
											2010-08-03 09:57:41 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | bool ComboBoxEntry::onProcessMessage(Message* msg) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  |   switch (msg->type()) { | 
					
						
							| 
									
										
										
										
											2013-04-05 08:53:29 +08:00
										 |  |  |     case kKeyDownMessage: | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |       if (hasFocus()) { | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  |         KeyMessage* keymsg = static_cast<KeyMessage*>(msg); | 
					
						
							|  |  |  |         KeyScancode scancode = keymsg->scancode(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |         // In a non-editable ComboBox
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |         if (!m_comboBox->isEditable()) { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |           if (scancode == kKeySpace || scancode == kKeyEnter || scancode == kKeyEnterPad) { | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |             m_comboBox->switchListBox(); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |             return true; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |         // In a editable ComboBox
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |         else { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |           if (scancode == kKeyUp || scancode == kKeyDown || scancode == kKeyPageUp || | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |               scancode == kKeyPageDown) { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |             if (m_comboBox->m_listbox && m_comboBox->m_listbox->isVisible()) { | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |               m_comboBox->m_listbox->requestFocus(); | 
					
						
							|  |  |  |               m_comboBox->m_listbox->sendMessage(msg); | 
					
						
							|  |  |  |               return true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |           else if (scancode == kKeyEnter || scancode == kKeyEnterPad) { | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  |             m_comboBox->onEnterOnEditableEntry(); | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 08:53:29 +08:00
										 |  |  |     case kMouseDownMessage: | 
					
						
							| 
									
										
										
										
											2015-05-07 00:07:54 +08:00
										 |  |  |       if (m_comboBox->isClickOpen() && | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |           (!m_comboBox->isEditable() || !m_comboBox->m_items.empty())) { | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |         m_comboBox->switchListBox(); | 
					
						
							| 
									
										
										
										
											2007-12-05 05:50:31 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |       if (m_comboBox->isEditable()) { | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |         requestFocus(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-02-09 07:09:42 +08:00
										 |  |  |       else { | 
					
						
							|  |  |  |         captureMouse(); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2014-02-09 07:09:42 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case kMouseUpMessage: | 
					
						
							|  |  |  |       if (hasCapture()) | 
					
						
							|  |  |  |         releaseMouse(); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case kMouseMoveMessage: | 
					
						
							|  |  |  |       if (hasCapture()) { | 
					
						
							|  |  |  |         MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg); | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |         gfx::Point screenPos = mouseMsg->display()->nativeWindow()->pointToScreen( | 
					
						
							|  |  |  |           mouseMsg->position()); | 
					
						
							| 
									
										
										
										
											2021-04-21 06:42:41 +08:00
										 |  |  |         Widget* pick = manager()->pickFromScreenPos(screenPos); | 
					
						
							| 
									
										
										
										
											2014-02-09 07:09:42 +08:00
										 |  |  |         Widget* listbox = m_comboBox->m_listbox; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |         if (pick != nullptr && (pick == listbox || pick->hasAncestor(listbox))) { | 
					
						
							| 
									
										
										
										
											2014-02-09 07:09:42 +08:00
										 |  |  |           releaseMouse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |           MouseMessage mouseMsg2(kMouseDownMessage, | 
					
						
							|  |  |  |                                  *mouseMsg, | 
					
						
							|  |  |  |                                  mouseMsg->positionForDisplay(pick->display())); | 
					
						
							| 
									
										
										
										
											2022-12-16 06:29:28 +08:00
										 |  |  |           mouseMsg2.setRecipient(pick); | 
					
						
							| 
									
										
										
										
											2021-04-21 06:42:41 +08:00
										 |  |  |           mouseMsg2.setDisplay(pick->display()); | 
					
						
							| 
									
										
										
										
											2014-02-24 19:30:43 +08:00
										 |  |  |           pick->sendMessage(&mouseMsg2); | 
					
						
							| 
									
										
										
										
											2014-02-09 07:09:42 +08:00
										 |  |  |           return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |       break; | 
					
						
							| 
									
										
										
										
											2009-11-22 08:26:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |     case kFocusEnterMessage: { | 
					
						
							|  |  |  |       bool result = Entry::onProcessMessage(msg); | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |       if (m_comboBox && m_comboBox->isEditable() && m_comboBox->m_listbox && | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |           m_comboBox->m_listbox->isVisible()) { | 
					
						
							|  |  |  |         // In case that the ListBox is visible and the focus is
 | 
					
						
							|  |  |  |         // obtained by the Entry field, we set the carret at the end
 | 
					
						
							|  |  |  |         // of the text. We don't select the whole text so the user can
 | 
					
						
							|  |  |  |         // delete the last caracters using backspace and complete the
 | 
					
						
							|  |  |  |         // item name.
 | 
					
						
							| 
									
										
										
										
											2017-02-21 21:48:25 +08:00
										 |  |  |         setCaretToEnd(); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       return result; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-15 23:25:31 +08:00
										 |  |  |     case kFocusLeaveMessage: | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |       if (m_comboBox->isEditable() && m_comboBox->m_window && | 
					
						
							| 
									
										
										
										
											2022-06-15 23:25:31 +08:00
										 |  |  |           !View::getView(m_comboBox->m_listbox)->hasMouse()) { | 
					
						
							|  |  |  |         m_comboBox->closeListBox(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |   return Entry::onProcessMessage(msg); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-21 07:40:18 +08:00
										 |  |  | void ComboBoxEntry::onPaint(PaintEvent& ev) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |   theme()->paintComboBoxEntry(ev); | 
					
						
							| 
									
										
										
										
											2013-05-21 07:40:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  | void ComboBoxEntry::onChange() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Entry::onChange(); | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   if (m_comboBox && m_comboBox->isEditable()) { | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  |     m_comboBox->onEntryChange(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | bool ComboBoxListBox::onProcessMessage(Message* msg) | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  |   switch (msg->type()) { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |     case kMouseUpMessage: m_comboBox->closeListBox(); return true; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 08:53:29 +08:00
										 |  |  |     case kKeyDownMessage: | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |       if (hasFocus()) { | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  |         KeyMessage* keymsg = static_cast<KeyMessage*>(msg); | 
					
						
							|  |  |  |         KeyScancode scancode = keymsg->scancode(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |         if (scancode == kKeySpace || scancode == kKeyEnter || scancode == kKeyEnterPad) { | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |           m_comboBox->closeListBox(); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |           return true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     case kFocusEnterMessage: | 
					
						
							|  |  |  |       // If the ComboBox is editable, we prefer the focus in the Entry
 | 
					
						
							|  |  |  |       // field (so the user can continue editing it).
 | 
					
						
							|  |  |  |       if (m_comboBox->isEditable()) | 
					
						
							|  |  |  |         m_comboBox->getEntryWidget()->requestFocus(); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  |   return ListBox::onProcessMessage(msg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 00:56:21 +08:00
										 |  |  | void ComboBoxListBox::onChange() | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-26 00:56:21 +08:00
										 |  |  |   ListBox::onChange(); | 
					
						
							| 
									
										
										
										
											2012-06-16 10:37:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   int index = getSelectedIndex(); | 
					
						
							| 
									
										
										
										
											2014-03-30 05:42:17 +08:00
										 |  |  |   if (isValidItem(index)) | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |     m_comboBox->setSelectedItemIndex(index); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-24 04:41:19 +08:00
										 |  |  | // When the mouse is clicked we switch the visibility-status of the list-box
 | 
					
						
							| 
									
										
										
										
											2023-01-12 22:00:16 +08:00
										 |  |  | void ComboBox::onButtonClick() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-08-24 04:41:19 +08:00
										 |  |  |   switchListBox(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | void ComboBox::openListBox() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-14 08:29:16 +08:00
										 |  |  |   if (!isEnabled() || m_window) | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  |   onBeforeOpenListBox(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   m_window = new Window(Window::WithoutTitleBar); | 
					
						
							|  |  |  |   View* view = new View(); | 
					
						
							|  |  |  |   m_listbox = new ComboBoxListBox(this); | 
					
						
							| 
									
										
										
										
											2021-05-22 22:58:59 +08:00
										 |  |  |   m_window->setAutoRemap(false); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   m_window->setOnTop(true); | 
					
						
							|  |  |  |   m_window->setWantFocus(false); | 
					
						
							| 
									
										
										
										
											2021-02-18 23:30:14 +08:00
										 |  |  |   m_window->setSizeable(false); | 
					
						
							|  |  |  |   m_window->setMoveable(false); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |   Widget* viewport = view->viewport(); | 
					
						
							| 
									
										
										
										
											2017-05-23 02:43:53 +08:00
										 |  |  |   { | 
					
						
							|  |  |  |     gfx::Rect entryBounds = m_entry->bounds(); | 
					
						
							|  |  |  |     gfx::Size size; | 
					
						
							|  |  |  |     size.w = m_button->bounds().x2() - entryBounds.x - view->border().width(); | 
					
						
							|  |  |  |     size.h = viewport->border().height(); | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |     for (Widget* item : m_items) | 
					
						
							| 
									
										
										
										
											2019-10-16 04:00:00 +08:00
										 |  |  |       if (!item->hasFlags(HIDDEN)) | 
					
						
							|  |  |  |         size.h += item->sizeHint().h; | 
					
						
							| 
									
										
										
										
											2017-05-23 02:43:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 23:13:19 +08:00
										 |  |  |     if (!get_multiple_displays()) { | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |       const int maxVal = std::max(entryBounds.y, display()->size().h - entryBounds.y2()) - | 
					
						
							|  |  |  |                          8 * guiscale(); | 
					
						
							| 
									
										
										
										
											2022-06-10 21:31:13 +08:00
										 |  |  |       size.h = std::clamp(size.h, textHeight(), maxVal); | 
					
						
							| 
									
										
										
										
											2021-04-20 23:13:19 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-23 02:43:53 +08:00
										 |  |  |     viewport->setMinSize(size); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   m_window->addChild(view); | 
					
						
							|  |  |  |   view->attachToView(m_listbox); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   m_listbox->selectIndex(m_selected); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 21:39:06 +08:00
										 |  |  |   initTheme(); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |   m_window->remapWindow(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 23:13:19 +08:00
										 |  |  |   updateListBoxPos(); | 
					
						
							| 
									
										
										
										
											2015-05-07 03:27:45 +08:00
										 |  |  |   m_window->openWindow(); | 
					
						
							| 
									
										
										
										
											2008-02-04 10:37:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  |   filterMessages(); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (isEditable()) | 
					
						
							|  |  |  |     m_entry->requestFocus(); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     m_listbox->requestFocus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onOpenListBox(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | void ComboBox::closeListBox() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   if (m_window) { | 
					
						
							| 
									
										
										
										
											2021-05-26 19:26:39 +08:00
										 |  |  |     removeMessageFilters(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-04 07:31:02 +08:00
										 |  |  |     m_listbox->clean(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |     m_window->closeWindow(this); | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |     delete m_window; // window, frame
 | 
					
						
							| 
									
										
										
										
											2021-03-03 00:50:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |     m_window = nullptr; | 
					
						
							|  |  |  |     m_listbox = nullptr; | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  |     putSelectedItemAsCustomWidget(); | 
					
						
							| 
									
										
										
										
											2015-05-05 01:58:24 +08:00
										 |  |  |     m_entry->requestFocus(); | 
					
						
							| 
									
										
										
										
											2014-03-09 07:31:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     onCloseListBox(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  | void ComboBox::switchListBox() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |   if (!m_window) | 
					
						
							|  |  |  |     openListBox(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2010-06-25 10:44:59 +08:00
										 |  |  |     closeListBox(); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 23:13:19 +08:00
										 |  |  | void ComboBox::updateListBoxPos() | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-23 02:43:53 +08:00
										 |  |  |   gfx::Rect entryBounds = m_entry->bounds(); | 
					
						
							| 
									
										
										
										
											2024-12-16 21:10:34 +08:00
										 |  |  |   gfx::Rect rc(gfx::Point(entryBounds.x, entryBounds.y2()), | 
					
						
							|  |  |  |                gfx::Point(m_button->bounds().x2(), entryBounds.y2() + m_window->bounds().h)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   fit_bounds(display(), | 
					
						
							|  |  |  |              m_window, | 
					
						
							|  |  |  |              rc, | 
					
						
							|  |  |  |              [this](const gfx::Rect& workarea, | 
					
						
							|  |  |  |                     gfx::Rect& bounds, | 
					
						
							|  |  |  |                     std::function<gfx::Rect(Widget*)> getWidgetBounds) { | 
					
						
							|  |  |  |                if (bounds.y2() > workarea.y2()) | 
					
						
							|  |  |  |                  bounds.offset(0, -(bounds.h + getWidgetBounds(m_entry).h)); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2007-09-19 07:57:02 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-30 03:16:24 +08:00
										 |  |  | void ComboBox::onChange() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Change(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  | void ComboBox::onEntryChange() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   // Do nothing
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ComboBox::onBeforeOpenListBox() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   // Do nothing
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-30 05:42:17 +08:00
										 |  |  | void ComboBox::onOpenListBox() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   OpenListBox(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 07:31:55 +08:00
										 |  |  | void ComboBox::onCloseListBox() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   CloseListBox(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 21:28:37 +08:00
										 |  |  | void ComboBox::onEnterOnEditableEntry() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   // Do nothing
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  | void ComboBox::filterMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!m_filtering) { | 
					
						
							|  |  |  |     manager()->addMessageFilter(kMouseDownMessage, this); | 
					
						
							|  |  |  |     manager()->addMessageFilter(kKeyDownMessage, this); | 
					
						
							|  |  |  |     m_filtering = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ComboBox::removeMessageFilters() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (m_filtering) { | 
					
						
							|  |  |  |     manager()->removeMessageFilter(kMouseDownMessage, this); | 
					
						
							|  |  |  |     manager()->removeMessageFilter(kKeyDownMessage, this); | 
					
						
							|  |  |  |     m_filtering = false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ComboBox::putSelectedItemAsCustomWidget() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!useCustomWidget()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 02:13:32 +08:00
										 |  |  |   Widget* item = getSelectedItem(); | 
					
						
							| 
									
										
										
										
											2017-05-24 00:41:11 +08:00
										 |  |  |   if (item && item->parent() == nullptr) { | 
					
						
							|  |  |  |     if (!m_listbox) { | 
					
						
							|  |  |  |       item->setBounds(m_entry->childrenBounds()); | 
					
						
							|  |  |  |       m_entry->addChild(item); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       m_entry->removeChild(item); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | } // namespace ui
 |