forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combobox.h
124 lines (95 loc) · 3.05 KB
/
combobox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Aseprite UI Library
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UI_COMBOBOX_H_INCLUDED
#define UI_COMBOBOX_H_INCLUDED
#pragma once
#include "obs/signal.h"
#include "ui/widget.h"
#include <string>
#include <vector>
namespace ui {
class Button;
class Entry;
class Event;
class ListBox;
class Window;
class ComboBoxEntry;
class ComboBoxListBox;
class ComboBox : public Widget {
friend class ComboBoxEntry;
friend class ComboBoxListBox;
public:
typedef std::vector<Widget*> Items;
ComboBox();
~ComboBox();
Items::iterator begin() { return m_items.begin(); }
Items::iterator end() { return m_items.end(); }
void setEditable(bool state);
void setClickOpen(bool state);
void setCaseSensitive(bool state);
void setUseCustomWidget(bool state);
bool isEditable() const { return m_editable; }
bool isClickOpen() const { return m_clickopen; }
bool isCaseSensitive() const { return m_casesensitive; }
bool useCustomWidget() const { return m_useCustomWidget; }
int addItem(Widget* item);
int addItem(const std::string& text);
void insertItem(int itemIndex, Widget* item);
void insertItem(int itemIndex, const std::string& text);
// Removes the given item (you must delete it).
void removeItem(Widget* item);
// Removes and deletes the given item.
void removeItem(int itemIndex);
void removeAllItems();
int getItemCount() const;
Widget* getItem(int itemIndex);
const std::string& getItemText(int itemIndex) const;
void setItemText(int itemIndex, const std::string& text);
int findItemIndex(const std::string& text) const;
int findItemIndexByValue(const std::string& value) const;
Widget* getSelectedItem() const;
void setSelectedItem(Widget* item);
int getSelectedItemIndex() const;
void setSelectedItemIndex(int itemIndex);
std::string getValue() const;
void setValue(const std::string& value);
Entry* getEntryWidget();
Button* getButtonWidget();
void openListBox();
void closeListBox();
void switchListBox();
gfx::Rect getListBoxPos() const;
// Signals
obs::signal<void()> Change;
obs::signal<void()> OpenListBox;
obs::signal<void()> CloseListBox;
protected:
bool onProcessMessage(Message* msg) override;
void onResize(ResizeEvent& ev) override;
void onSizeHint(SizeHintEvent& ev) override;
void onInitTheme(InitThemeEvent& ev) override;
virtual void onChange();
virtual void onOpenListBox();
virtual void onCloseListBox();
private:
void onButtonClick(Event& ev);
void filterMessages();
void removeMessageFilters();
void putSelectedItemAsCustomWidget();
ComboBoxEntry* m_entry;
Button* m_button;
Window* m_window;
ComboBoxListBox* m_listbox;
Items m_items;
int m_selected;
bool m_editable;
bool m_clickopen;
bool m_casesensitive;
bool m_filtering;
bool m_useCustomWidget;
};
} // namespace ui
#endif