Serenity Operating System
at master 72 lines 1.9 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <LibGUI/AbstractView.h> 10#include <LibGUI/Frame.h> 11#include <LibGUI/Model.h> 12 13namespace GUI { 14 15class ComboBoxEditor; 16 17class ComboBox : public Frame { 18 C_OBJECT(ComboBox); 19 20public: 21 virtual ~ComboBox() override; 22 23 DeprecatedString text() const; 24 void set_text(DeprecatedString const&, AllowCallback = AllowCallback::Yes); 25 26 void open(); 27 void close(); 28 void select_all(); 29 30 Model* model(); 31 Model const* model() const; 32 void set_model(NonnullRefPtr<Model>); 33 34 size_t selected_index() const; 35 void set_selected_index(size_t index, AllowCallback = AllowCallback::Yes); 36 void clear_selection(); 37 38 bool only_allow_values_from_model() const { return m_only_allow_values_from_model; } 39 void set_only_allow_values_from_model(bool); 40 41 int model_column() const; 42 void set_model_column(int); 43 44 void set_editor_placeholder(StringView placeholder); 45 DeprecatedString const& editor_placeholder() const; 46 47 int max_visible_items() const { return m_max_visible_items; } 48 void set_max_visible_items(int max) { m_max_visible_items = max; } 49 50 Function<void(DeprecatedString const&, ModelIndex const&)> on_change; 51 Function<void()> on_return_pressed; 52 53protected: 54 ComboBox(); 55 virtual void resize_event(ResizeEvent&) override; 56 57private: 58 void selection_updated(ModelIndex const&); 59 void navigate(AbstractView::CursorMovement); 60 void navigate_relative(int); 61 62 RefPtr<ComboBoxEditor> m_editor; 63 RefPtr<Button> m_open_button; 64 RefPtr<Window> m_list_window; 65 RefPtr<ListView> m_list_view; 66 Optional<ModelIndex> m_selected_index; 67 bool m_only_allow_values_from_model { false }; 68 bool m_updating_model { false }; 69 int m_max_visible_items { 15 }; 70}; 71 72}