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: 13 авг. 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 #include <ui/ctl/ctl.h> 23 24 namespace lsp 25 { 26 namespace ctl 27 { 28 const ctl_class_t CtlListBox::metadata = { "CtlListBox", &CtlWidget::metadata }; 29 CtlListBox(CtlRegistry * src,LSPListBox * widget)30 CtlListBox::CtlListBox(CtlRegistry *src, LSPListBox *widget): CtlWidget(src, widget) 31 { 32 pClass = &metadata; 33 pDialog = NULL; 34 35 // char str[32]; 36 37 LSPItemList *items = widget->items(); 38 LSPItem *item; 39 40 #define MP(x) items->add(&item); item->text()->set_raw(#x); item->set_value(x); 41 42 MP(MP_NONE); 43 MP(MP_ARROW); 44 MP(MP_HAND); 45 MP(MP_CROSS); 46 MP(MP_IBEAM); 47 MP(MP_DRAW); 48 MP(MP_PLUS); 49 MP(MP_SIZE_NESW); 50 MP(MP_SIZE_NS); 51 MP(MP_SIZE_WE); 52 MP(MP_SIZE_NWSE); 53 MP(MP_UP_ARROW); 54 MP(MP_HOURGLASS); 55 MP(MP_DRAG); 56 MP(MP_NO_DROP); 57 MP(MP_DANGER); 58 MP(MP_HSPLIT); 59 MP(MP_VSPLIT); 60 MP(MP_MULTIDRAG); 61 MP(MP_APP_START); 62 MP(MP_HELP); 63 64 #undef MP 65 66 /*for (size_t i=0; i<20; ++i) 67 { 68 sprintf(str, "item %d", int(i)); 69 items->add(str, i); 70 }*/ 71 // widget->selection()->set_value(1); 72 widget->selection()->set_value(MP_DEFAULT); 73 74 widget->slots()->bind(LSPSLOT_SUBMIT, slot_submit, this); 75 } 76 ~CtlListBox()77 CtlListBox::~CtlListBox() 78 { 79 if (pDialog != NULL) 80 { 81 pDialog->destroy(); 82 delete pDialog; 83 pDialog = NULL; 84 } 85 } 86 slot_submit(LSPWidget * sender,void * ptr,void * data)87 status_t CtlListBox::slot_submit(LSPWidget *sender, void *ptr, void *data) 88 { 89 CtlListBox *_this = static_cast<CtlListBox *>(ptr); 90 return (_this != NULL) ? _this->on_submit() : STATUS_OK; 91 } 92 slot_on_ok(LSPWidget * sender,void * ptr,void * data)93 status_t CtlListBox::slot_on_ok(LSPWidget *sender, void *ptr, void *data) 94 { 95 CtlListBox *_this = static_cast<CtlListBox *>(ptr); 96 return (_this != NULL) ? _this->on_ok() : STATUS_OK; 97 } 98 on_submit()99 status_t CtlListBox::on_submit() 100 { 101 /* if (pDialog == NULL) 102 { 103 pDialog = new LSPMessageBox(pWidget->display()); 104 pDialog->init(); 105 106 pDialog->set_title("Notification"); 107 pDialog->set_heading("ListBox value has been changed"); 108 pDialog->add_button("Okay", slot_on_ok, this); 109 pDialog->add_button("Not okay"); 110 pDialog->add_button("Cancel"); 111 } 112 113 char text[256]; 114 LSPListBox *lb = static_cast<LSPListBox *>(pWidget); 115 ssize_t index = lb->selection()->value(); 116 LSPItem *itm = (index >= 0) ? lb->items()->get(index) : NULL; 117 118 sprintf(text, "You've selected item '%s', it's value is %f, selected index = %d", 119 (itm != NULL) ? itm->text() : NULL, (itm != NULL) ? itm->value() : 0.0f, 120 int(index) 121 ); 122 123 pDialog->set_message(text); 124 pDialog->show(pWidget);*/ 125 LSPListBox *lb = widget_cast<LSPListBox>(pWidget); 126 if (lb == NULL) 127 return STATUS_OK; 128 129 // LSPWindow *wnd = widget_cast<LSPWindow>(pWidget->toplevel()); 130 // if (wnd == NULL) 131 // return STATUS_OK; 132 size_t index = lb->selection()->value(); 133 LSPItem *item = lb->items()->get(index); 134 135 if (item != NULL) 136 lb->set_cursor(mouse_pointer_t(item->value())); 137 138 return STATUS_OK; 139 } 140 on_ok()141 status_t CtlListBox::on_ok() 142 { 143 lsp_trace("OK button pressed"); 144 return STATUS_OK; 145 } 146 } 147 148 } /* namespace lsp */ 149