Skip to content

Commit ec3c785

Browse files
committed
ComboBox now properly reacts on the 'ESC' key pressure and hides the dropdown list
1 parent 15d1054 commit ec3c785

5 files changed

Lines changed: 70 additions & 20 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Added process_pending_events() in the tk::Display class for handling pending
1212
events at the main loop start and at the main loop end.
1313
* Changed behaviour of the AudioSample widget related to displaying load status.
14+
* ComboBox now properly reacts on the 'ESC' key pressure and hides the dropdown list.
1415
* Updated build scripts.
1516

1617
=== 1.0.33 ===

include/lsp-plug.in/tk/widgets/compound/ComboBox.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ namespace lsp
171171
protected:
172172
static status_t slot_on_change(Widget *sender, void *ptr, void *data);
173173
static status_t slot_on_submit(Widget *sender, void *ptr, void *data);
174+
static status_t slot_on_cancel(Widget *sender, void *ptr, void *data);
175+
static status_t slot_on_listbox_cancel(Widget *sender, void *ptr, void *data);
174176

175177
protected:
176178
virtual void property_changed(Property *prop) override;
@@ -236,6 +238,7 @@ namespace lsp
236238
public:
237239
virtual status_t on_change();
238240
virtual status_t on_submit();
241+
virtual status_t on_cancel();
239242
};
240243
} /* namespace tk */
241244
} /* namespace lsp */

include/lsp-plug.in/tk/widgets/compound/ListBox.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ namespace lsp
194194
static status_t slot_on_scroll_change(Widget *sender, void *ptr, void *data);
195195
static status_t slot_on_change(Widget *sender, void *ptr, void *data);
196196
static status_t slot_on_submit(Widget *sender, void *ptr, void *data);
197+
static status_t slot_on_cancel(Widget *sender, void *ptr, void *data);
197198
static status_t slot_on_scroll_key_event(Widget *sender, void *ptr, void *data);
198199

199200
static void on_add_item(void *obj, Property *prop, void *w);
@@ -267,6 +268,7 @@ namespace lsp
267268
public:
268269
virtual status_t on_change();
269270
virtual status_t on_submit();
271+
virtual status_t on_cancel();
270272

271273
virtual void scroll_to_current();
272274
virtual void scroll_to(size_t index);

src/main/widgets/compound/ComboBox.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ namespace lsp
296296
// Bind slots
297297
id = sSlots.add(SLOT_CHANGE, slot_on_change, self());
298298
if (id >= 0) id = sSlots.add(SLOT_SUBMIT, slot_on_change, self());
299+
if (id >= 0) id = sSlots.add(SLOT_CANCEL, slot_on_cancel, self());
300+
if (id < 0)
301+
return -id;
302+
303+
// Bind ListBox slots
304+
id = sLBox.slots()->bind(SLOT_CANCEL, slot_on_listbox_cancel, self());
299305
if (id < 0)
300306
return -id;
301307

@@ -672,14 +678,27 @@ namespace lsp
672678

673679
status_t ComboBox::slot_on_change(Widget *sender, void *ptr, void *data)
674680
{
675-
ComboBox *_this = widget_ptrcast<ComboBox>(ptr);
676-
return (_this != NULL) ? _this->on_change() : STATUS_BAD_ARGUMENTS;
681+
ComboBox * const self = widget_ptrcast<ComboBox>(ptr);
682+
return (self != NULL) ? self->on_change() : STATUS_BAD_ARGUMENTS;
677683
}
678684

679685
status_t ComboBox::slot_on_submit(Widget *sender, void *ptr, void *data)
680686
{
681-
ComboBox *_this = widget_ptrcast<ComboBox>(ptr);
682-
return (_this != NULL) ? _this->on_submit() : STATUS_BAD_ARGUMENTS;
687+
ComboBox * const self = widget_ptrcast<ComboBox>(ptr);
688+
return (self != NULL) ? self->on_submit() : STATUS_BAD_ARGUMENTS;
689+
}
690+
691+
status_t ComboBox::slot_on_cancel(Widget *sender, void *ptr, void *data)
692+
{
693+
ComboBox * const self = widget_ptrcast<ComboBox>(ptr);
694+
return (self != NULL) ? self->on_cancel() : STATUS_BAD_ARGUMENTS;
695+
}
696+
697+
status_t ComboBox::slot_on_listbox_cancel(Widget *sender, void *ptr, void *data)
698+
{
699+
ComboBox * const self = widget_ptrcast<ComboBox>(ptr);
700+
self->sOpened.set(false);
701+
return self->sSlots.execute(SLOT_CANCEL, self, NULL);
683702
}
684703

685704
status_t ComboBox::on_mouse_down(const ws::event_t *e)
@@ -790,6 +809,10 @@ namespace lsp
790809
sOpened.toggle();
791810
break;
792811

812+
case ws::WSK_ESCAPE:
813+
sOpened.set(false);
814+
break;
815+
793816
default:
794817
break;
795818
}
@@ -807,6 +830,11 @@ namespace lsp
807830
return STATUS_OK;
808831
}
809832

833+
status_t ComboBox::on_cancel()
834+
{
835+
return STATUS_OK;
836+
}
837+
810838
} /* namespace tk */
811839
} /* namespace lsp */
812840

src/main/widgets/compound/ListBox.cpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ namespace lsp
238238
// Bind slots
239239
id = sSlots.add(SLOT_CHANGE, slot_on_change, self());
240240
if (id >= 0) id = sSlots.add(SLOT_SUBMIT, slot_on_submit, self());
241+
if (id >= 0) id = sSlots.add(SLOT_CANCEL, slot_on_cancel, self());
241242

242243
return (id >= 0) ? STATUS_OK : -id;
243244
}
@@ -795,41 +796,47 @@ namespace lsp
795796

796797
status_t ListBox::slot_on_scroll_change(Widget *sender, void *ptr, void *data)
797798
{
798-
ListBox *_this = widget_ptrcast<ListBox>(ptr);
799-
if (_this == NULL)
799+
ListBox * const self = widget_ptrcast<ListBox>(ptr);
800+
if (self == NULL)
800801
return STATUS_OK;
801802

802-
if ((&_this->sHBar != sender) && (&_this->sVBar != sender))
803+
if ((&self->sHBar != sender) && (&self->sVBar != sender))
803804
return STATUS_OK;
804805

805-
if (&_this->sHBar == sender)
806-
_this->sHScroll.commit_value(_this->sHBar.value()->get());
807-
else if (&_this->sVBar == sender)
808-
_this->sVScroll.commit_value(_this->sVBar.value()->get());
806+
if (&self->sHBar == sender)
807+
self->sHScroll.commit_value(self->sHBar.value()->get());
808+
else if (&self->sVBar == sender)
809+
self->sVScroll.commit_value(self->sVBar.value()->get());
809810

810-
_this->realize_children();
811-
_this->query_draw();
811+
self->realize_children();
812+
self->query_draw();
812813

813814
return STATUS_OK;
814815
}
815816

816817
status_t ListBox::slot_on_scroll_key_event(Widget *sender, void *ptr, void *data)
817818
{
818-
ListBox *_this = widget_ptrcast<ListBox>(ptr);
819-
const ws::event_t *e = static_cast<ws::event_t *>(data);
820-
return (_this != NULL) ? _this->handle_event(e) : STATUS_OK;
819+
ListBox * const self = widget_ptrcast<ListBox>(ptr);
820+
const ws::event_t * const e = static_cast<ws::event_t *>(data);
821+
return (self != NULL) ? self->handle_event(e) : STATUS_OK;
821822
}
822823

823824
status_t ListBox::slot_on_change(Widget *sender, void *ptr, void *data)
824825
{
825-
ListBox *_this = widget_ptrcast<ListBox>(ptr);
826-
return (_this != NULL) ? _this->on_change() : STATUS_BAD_ARGUMENTS;
826+
ListBox * const self = widget_ptrcast<ListBox>(ptr);
827+
return (self != NULL) ? self->on_change() : STATUS_BAD_ARGUMENTS;
827828
}
828829

829830
status_t ListBox::slot_on_submit(Widget *sender, void *ptr, void *data)
830831
{
831-
ListBox *_this = widget_ptrcast<ListBox>(ptr);
832-
return (_this != NULL) ? _this->on_submit() : STATUS_BAD_ARGUMENTS;
832+
ListBox * const self = widget_ptrcast<ListBox>(ptr);
833+
return (self != NULL) ? self->on_submit() : STATUS_BAD_ARGUMENTS;
834+
}
835+
836+
status_t ListBox::slot_on_cancel(Widget *sender, void *ptr, void *data)
837+
{
838+
ListBox * const self = widget_ptrcast<ListBox>(ptr);
839+
return (self != NULL) ? self->on_cancel() : STATUS_BAD_ARGUMENTS;
833840
}
834841

835842
void ListBox::on_add_item(void *obj, Property *prop, void *w)
@@ -1190,6 +1197,10 @@ namespace lsp
11901197
sSlots.execute(SLOT_SUBMIT, this, NULL);
11911198
break;
11921199

1200+
case ws::WSK_ESCAPE:
1201+
sSlots.execute(SLOT_CANCEL, this, NULL);
1202+
break;
1203+
11931204
default:
11941205
break;
11951206
}
@@ -1343,5 +1354,10 @@ namespace lsp
13431354
return STATUS_OK;
13441355
}
13451356

1357+
status_t ListBox::on_cancel()
1358+
{
1359+
return STATUS_OK;
1360+
}
1361+
13461362
} /* namespace tk */
13471363
} /* namespace lsp */

0 commit comments

Comments
 (0)