1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 29 апр. 2018 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef UI_TK_WIDGETS_LSPCOMBOGROUP_H_ 23 #define UI_TK_WIDGETS_LSPCOMBOGROUP_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 30 class LSPComboGroup: public LSPWidgetContainer 31 { 32 public: 33 static const w_class_t metadata; 34 35 protected: 36 enum flags_t 37 { 38 F_OPENED = 1 << 0, 39 F_CIRCULAR = 1 << 1, 40 F_MOUSE_OUT = 1 << 2 41 }; 42 43 typedef struct dimensions_t 44 { 45 size_t nGapLeft; 46 size_t nGapTop; 47 size_t nGapRight; 48 size_t nGapBottom; 49 size_t nMinWidth; 50 size_t nMinHeight; 51 } dimensions_t; 52 53 class LSPComboList: public LSPListBox 54 { 55 protected: 56 LSPComboGroup *pWidget; 57 58 protected: 59 virtual void on_selection_change(); 60 61 virtual void on_item_change(ssize_t index, LSPItem *item); 62 63 virtual void on_item_add(size_t index); 64 65 virtual void on_item_remove(size_t index); 66 67 virtual void on_item_swap(size_t idx1, size_t idx2); 68 69 virtual void on_item_clear(); 70 71 public: 72 LSPComboList(LSPDisplay *dpy, LSPComboGroup *widget); 73 virtual ~LSPComboList(); 74 }; 75 76 class LSPComboPopup: public LSPWindow 77 { 78 protected: 79 LSPComboGroup *pWidget; 80 81 protected: 82 virtual status_t handle_event(const ws_event_t *e); 83 84 public: 85 LSPComboPopup(LSPDisplay *dpy, LSPComboGroup *widget, ssize_t screen = -1); 86 virtual ~LSPComboPopup(); 87 }; 88 89 protected: 90 size_t nRadius; 91 size_t nBorder; 92 size_t nCBFlags; 93 size_t nMFlags; 94 realize_t sGroupHdr; 95 LSPColor sColor; 96 cvector<LSPWidget> vWidgets; 97 LSPComboList sListBox; 98 LSPFont sFont; 99 LSPWindow *pPopup; 100 bool bEmbed; 101 102 protected: 103 virtual LSPWidget *find_widget(ssize_t x, ssize_t y); 104 LSPWidget *current_widget(); 105 void query_dimensions(dimensions_t *d); 106 void do_destroy(); 107 bool check_mouse_over(ssize_t x, ssize_t y); 108 109 status_t on_list_change(); 110 status_t on_list_submit(); 111 112 static status_t slot_on_change(LSPWidget *sender, void *ptr, void *data); 113 static status_t slot_on_submit(LSPWidget *sender, void *ptr, void *data); 114 static status_t slot_on_list_change(LSPWidget *sender, void *ptr, void *data); 115 static status_t slot_on_list_submit(LSPWidget *sender, void *ptr, void *data); 116 static status_t slot_on_list_focus_out(LSPWidget *sender, void *ptr, void *data); 117 118 static status_t slot_on_list_show(LSPWidget *sender, void *ptr, void *data); 119 static status_t slot_on_list_mouse_down(LSPWidget *sender, void *ptr, void *data); 120 static status_t slot_on_list_key_down(LSPWidget *sender, void *ptr, void *data); 121 122 protected: 123 virtual void on_selection_change(); 124 virtual void on_item_change(size_t index, LSPItem *item); 125 virtual void on_item_add(size_t index); 126 virtual void on_item_remove(size_t index); 127 virtual void on_item_swap(size_t idx1, size_t idx2); 128 virtual void on_item_clear(); 129 virtual status_t on_list_focus_out(); 130 virtual status_t on_list_show(); 131 132 virtual status_t on_grab_mouse_down(const ws_event_t *e); 133 virtual status_t on_grab_key_down(const ws_event_t *e); 134 135 public: 136 const LSPLocalString *text() const; color()137 inline LSPColor *color() { return &sColor; } radius()138 inline size_t radius() const { return nRadius; } border()139 inline size_t border() const { return nBorder; } font()140 inline LSPFont *font() { return &sFont; } embed()141 inline bool embed() const { return bEmbed; } 142 143 ssize_t selected() const; items()144 inline LSPItemList *items() { return sListBox.items(); } opened()145 inline bool opened() const { return nCBFlags & F_OPENED; } circular()146 inline bool circular() const { return nCBFlags & F_CIRCULAR; } list_color()147 inline LSPColor *list_color() { return sListBox.color(); } list_bg_color()148 inline LSPColor *list_bg_color() { return sListBox.bg_color(); } 149 150 public: 151 void set_radius(size_t value); 152 void set_border(size_t value); 153 154 status_t set_selected(ssize_t value); 155 status_t set_opened(bool open = true); 156 inline status_t set_closed(bool closed = true) { return set_opened(!closed); }; 157 void set_circular(bool circular = true); 158 void set_embed(bool embed); 159 open()160 inline status_t open() { return set_opened(true); } toggle()161 inline status_t toggle(){ return set_opened(!(nFlags & F_OPENED)); } close()162 inline status_t close() { return set_opened(false); } 163 164 public: 165 explicit LSPComboGroup(LSPDisplay *dpy); 166 virtual ~LSPComboGroup(); 167 168 virtual status_t init(); 169 virtual void destroy(); 170 171 public: 172 virtual void render(ISurface *s, bool force); 173 174 virtual status_t add(LSPWidget *widget); 175 176 virtual status_t remove(LSPWidget *widget); 177 178 virtual void size_request(size_request_t *r); 179 180 virtual void realize(const realize_t *r); 181 182 183 virtual status_t on_mouse_down(const ws_event_t *e); 184 185 virtual status_t on_mouse_up(const ws_event_t *e); 186 187 virtual status_t on_mouse_scroll(const ws_event_t *e); 188 189 virtual status_t on_change(); 190 191 virtual status_t on_submit(); 192 }; 193 194 } /* namespace tk */ 195 } /* namespace lsp */ 196 197 #endif /* UI_TK_WIDGETS_LSPCOMBOGROUP_H_ */ 198