forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combobox.h
117 lines (88 loc) · 2.8 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
// Aseprite UI Library
// Copyright (C) 2001-2016 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 ListItem;
class Window;
class ComboBoxEntry;
class ComboBoxListBox;
class ComboBox : public Widget {
friend class ComboBoxEntry;
friend class ComboBoxListBox;
public:
typedef std::vector<ListItem*> ListItems;
ComboBox();
~ComboBox();
ListItems::iterator begin() { return m_items.begin(); }
ListItems::iterator end() { return m_items.end(); }
void setEditable(bool state);
void setClickOpen(bool state);
void setCaseSensitive(bool state);
bool isEditable() const { return m_editable; }
bool isClickOpen() const { return m_clickopen; }
bool isCaseSensitive() const { return m_casesensitive; }
int addItem(ListItem* item);
int addItem(const std::string& text);
void insertItem(int itemIndex, ListItem* item);
void insertItem(int itemIndex, const std::string& text);
// Removes the given item (you must delete it).
void removeItem(ListItem* item);
// Removes and deletes the given item.
void removeItem(int itemIndex);
void removeAllItems();
int getItemCount() const;
ListItem* 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;
ListItem* getSelectedItem() const;
void setSelectedItem(ListItem* 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;
virtual void onChange();
virtual void onOpenListBox();
virtual void onCloseListBox();
private:
void onButtonClick(Event& ev);
ComboBoxEntry* m_entry;
Button* m_button;
Window* m_window;
ComboBoxListBox* m_listbox;
ListItems m_items;
int m_selected;
bool m_editable;
bool m_clickopen;
bool m_casesensitive;
};
} // namespace ui
#endif