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: 2 авг. 2017 г. 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_LSPLISTBOX_H_ 23 #define UI_TK_WIDGETS_LSPLISTBOX_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 class LSPListBox: public LSPComplexWidget 30 { 31 public: 32 static const w_class_t metadata; 33 34 protected: 35 class LSPListBoxList: public LSPItemList 36 { 37 protected: 38 LSPListBox *pWidget; 39 40 protected: 41 virtual void on_item_change(LSPListItem *item); // Triggered when the content of item has been changed 42 43 virtual void on_item_add(size_t index); 44 45 virtual void on_item_remove(size_t index); 46 47 virtual void on_item_swap(size_t idx1, size_t idx2); 48 49 virtual void on_item_clear(); 50 51 public: 52 explicit LSPListBoxList(LSPListBox *widget); 53 virtual ~LSPListBoxList(); 54 }; 55 56 class LSPListBoxSelection: public LSPItemSelection 57 { 58 protected: 59 LSPListBox *pWidget; 60 61 protected: 62 virtual void on_remove(ssize_t value); 63 64 virtual void on_add(ssize_t value); 65 66 virtual bool validate(ssize_t value); 67 68 virtual void request_fill(ssize_t *first, ssize_t *last); 69 70 virtual void on_fill(); 71 72 virtual void on_clear(); 73 74 public: 75 explicit LSPListBoxSelection(LSPListBox *widget); 76 virtual ~LSPListBoxSelection(); 77 }; 78 79 enum flags_t 80 { 81 F_MDOWN = 1 << 0, 82 F_SUBMIT = 1 << 1 83 }; 84 85 protected: 86 LSPListBoxList sItems; 87 LSPListBoxSelection sSelection; 88 LSPScrollBar sHBar; 89 LSPScrollBar sVBar; 90 LSPSizeConstraints sConstraints; 91 LSPColor sColor; 92 LSPFont sFont; 93 realize_t sArea; 94 size_t nFlags; 95 size_t nBMask; 96 ISurface *pArea; 97 98 protected: 99 static status_t slot_on_change(LSPWidget *sender, void *ptr, void *data); 100 static status_t slot_on_submit(LSPWidget *sender, void *ptr, void *data); 101 static status_t slot_on_sbar_vscroll(LSPWidget *sender, void *ptr, void *data); 102 static status_t slot_on_sbar_hscroll(LSPWidget *sender, void *ptr, void *data); 103 104 static status_t slot_on_vscroll(LSPWidget *sender, void *ptr, void *data); 105 static status_t slot_on_hscroll(LSPWidget *sender, void *ptr, void *data); 106 107 virtual LSPWidget *find_widget(ssize_t x, ssize_t y); 108 109 void on_click(ssize_t x, ssize_t y); 110 void do_destroy(); 111 112 protected: 113 virtual void on_item_change(size_t index, LSPItem *item); 114 115 virtual void on_item_add(size_t index); 116 117 virtual void on_item_remove(size_t index); 118 119 virtual void on_item_swap(size_t idx1, size_t idx2); 120 121 virtual void on_item_clear(); 122 123 virtual void on_selection_change(); 124 125 public: 126 explicit LSPListBox(LSPDisplay *dpy); 127 virtual ~LSPListBox(); 128 129 virtual status_t init(); 130 virtual void destroy(); 131 132 public: items()133 inline LSPItemList *items() { return &sItems; } 134 selection()135 inline LSPItemSelection *selection() { return &sSelection; } 136 color()137 inline LSPColor *color() { return &sColor; } 138 constraints()139 inline LSPSizeConstraints *constraints() { return &sConstraints; } 140 font()141 inline LSPFont *font() { return &sFont; } 142 vscroll()143 inline float vscroll() const { return sVBar.value(); } vscroll_min()144 inline float vscroll_min() const { return sVBar.min_value(); } vscroll_max()145 inline float vscroll_max() const { return sVBar.max_value(); } vscroll_on()146 inline float vscroll_on() const { return sVBar.visible(); } hscroll()147 inline float hscroll() const { return sHBar.value(); } hscroll_min()148 inline float hscroll_min() const { return sHBar.min_value(); } hscroll_max()149 inline float hscroll_max() const { return sHBar.max_value(); } hscroll_on()150 inline bool hscroll_on() const { return sHBar.visible(); } 151 152 public: 153 void set_min_width(ssize_t value); 154 155 void set_min_height(ssize_t value); 156 set_vscroll(float value)157 void set_vscroll(float value) { sVBar.set_value(value); } set_hscroll(float value)158 void set_hscroll(float value) { sHBar.set_value(value); } 159 160 public: 161 virtual void size_request(size_request_t *r); 162 163 virtual void optimal_size_request(size_request_t *r); 164 165 virtual void realize(const realize_t *r); 166 167 virtual status_t on_change(); 168 169 virtual status_t on_submit(); 170 171 virtual status_t on_hscroll(); 172 173 virtual status_t on_vscroll(); 174 175 virtual status_t on_mouse_down(const ws_event_t *e); 176 177 virtual status_t on_mouse_up(const ws_event_t *e); 178 179 virtual status_t on_mouse_move(const ws_event_t *e); 180 181 virtual status_t on_mouse_scroll(const ws_event_t *e); 182 183 virtual void render(ISurface *s, bool force); 184 185 virtual void draw(ISurface *s); 186 187 virtual bool hide(); 188 }; 189 190 } /* namespace tk */ 191 } /* namespace lsp */ 192 193 #endif /* UI_TK_WIDGETS_LSPLISTBOX_H_ */ 194