2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-06-22 11:47:29 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-12-31 07:01:07 +03:00
|
|
|
#include <LibGUI/AbstractView.h>
|
2020-12-13 01:17:41 +03:00
|
|
|
#include <LibGUI/Frame.h>
|
2020-12-31 07:01:07 +03:00
|
|
|
#include <LibGUI/Model.h>
|
2019-06-22 11:47:29 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
namespace GUI {
|
2019-06-22 11:47:29 +03:00
|
|
|
|
2020-05-12 16:10:31 +03:00
|
|
|
class ComboBoxEditor;
|
|
|
|
|
2020-12-13 01:17:41 +03:00
|
|
|
class ComboBox : public Frame {
|
|
|
|
C_OBJECT(ComboBox);
|
|
|
|
|
2019-06-22 11:47:29 +03:00
|
|
|
public:
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual ~ComboBox() override;
|
2019-06-22 11:47:29 +03:00
|
|
|
|
|
|
|
String text() const;
|
2019-06-23 08:55:28 +03:00
|
|
|
void set_text(const String&);
|
2019-06-22 11:47:29 +03:00
|
|
|
|
|
|
|
void open();
|
|
|
|
void close();
|
2019-06-23 09:18:28 +03:00
|
|
|
void select_all();
|
2019-06-22 11:47:29 +03:00
|
|
|
|
2020-02-23 12:42:43 +03:00
|
|
|
Model* model();
|
|
|
|
const Model* model() const;
|
2020-02-02 17:07:41 +03:00
|
|
|
void set_model(NonnullRefPtr<Model>);
|
2019-06-22 11:47:29 +03:00
|
|
|
|
2020-08-21 21:01:45 +03:00
|
|
|
size_t selected_index() const;
|
2020-03-29 18:56:31 +03:00
|
|
|
void set_selected_index(size_t index);
|
|
|
|
|
2019-06-23 09:18:28 +03:00
|
|
|
bool only_allow_values_from_model() const { return m_only_allow_values_from_model; }
|
|
|
|
void set_only_allow_values_from_model(bool);
|
|
|
|
|
2020-02-23 12:42:43 +03:00
|
|
|
int model_column() const;
|
|
|
|
void set_model_column(int);
|
2019-08-05 19:32:04 +03:00
|
|
|
|
2021-11-11 02:55:02 +03:00
|
|
|
void set_editor_placeholder(StringView placeholder);
|
2021-03-08 19:38:43 +03:00
|
|
|
const String& editor_placeholder() const;
|
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
Function<void(const String&, const ModelIndex&)> on_change;
|
2019-06-23 08:55:28 +03:00
|
|
|
Function<void()> on_return_pressed;
|
2019-06-22 11:47:29 +03:00
|
|
|
|
|
|
|
protected:
|
2020-02-23 14:07:13 +03:00
|
|
|
ComboBox();
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual void resize_event(ResizeEvent&) override;
|
2019-06-22 11:47:29 +03:00
|
|
|
|
|
|
|
private:
|
2020-12-31 07:01:07 +03:00
|
|
|
void selection_updated(const ModelIndex&);
|
|
|
|
void navigate(AbstractView::CursorMovement);
|
|
|
|
void navigate_relative(int);
|
|
|
|
|
2020-05-12 16:10:31 +03:00
|
|
|
RefPtr<ComboBoxEditor> m_editor;
|
2021-02-27 16:23:42 +03:00
|
|
|
RefPtr<Button> m_open_button;
|
2020-02-02 17:07:41 +03:00
|
|
|
RefPtr<Window> m_list_window;
|
|
|
|
RefPtr<ListView> m_list_view;
|
2020-12-31 07:01:07 +03:00
|
|
|
Optional<ModelIndex> m_selected_index;
|
2019-06-23 09:18:28 +03:00
|
|
|
bool m_only_allow_values_from_model { false };
|
2020-12-31 07:01:07 +03:00
|
|
|
bool m_updating_model { false };
|
2019-06-22 11:47:29 +03:00
|
|
|
};
|
2020-02-02 17:07:41 +03:00
|
|
|
|
|
|
|
}
|