seems to work

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@677 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-12 19:18:15 +00:00
parent 73646dce99
commit fef5fceea9
7 changed files with 90 additions and 11 deletions

View File

@@ -27,6 +27,7 @@
#define MwNmodernLook "ImodernLook"
#define MwNwaitMS "IwaitMS"
#define MwNhideInput "IhideInput"
#define MwNsingleClickSelectable "IsingleClickSelectable"
#define MwNtitle "Stitle"
#define MwNtext "Stext"
@@ -46,7 +47,7 @@
#define MwNmouseDownHandler "CmouseDown" /* MwLLMouse* */
#define MwNmouseUpHandler "CmouseUp" /* same as MwNmouseDownHandler */
#define MwNmouseMoveHandler "CmouseMove" /* MwPoint* */
#define MwNchangedHandler "Cchanged" /* NULL */
#define MwNchangedHandler "Cchanged" /* NULL/int* (MwComboBox) */
#define MwNkeyHandler "Ckey" /* int* (MwLLKeyEnum or character code) */
#define MwNkeyReleaseHandler "CkeyRelease" /* same as MwNkeyHandler */
#define MwNcloseHandler "Cclose" /* NULL */

View File

@@ -131,9 +131,10 @@ struct _MwListBox {
};
struct _MwComboBox {
char** list;
int opened;
int selected;
char** list;
int opened;
int selected;
MwWidget listbox;
};
struct _MwDirectoryEntry {

View File

@@ -19,7 +19,7 @@ extern "C" {
MWDECL MwClass MwComboBoxClass;
/*!
* @brief Adds the entry to ComboBox
* @brief Adds the entry to combobox
* @param handle Widget
* @param index Index
* @param text Text
@@ -28,6 +28,19 @@ MwInline void MwComboBoxAdd(MwWidget handle, int index, const char* text) {
MwVaWidgetExecute(handle, "mwComboBoxAdd", NULL, index, text);
}
/*!
* @brief Gets the entry from combobox
* @param handle Widget
* @param index Index
* @return Text
*/
MwInline const char* MwComboBoxGet(MwWidget handle, int index) {
const char* text;
MwVaWidgetExecute(handle, "mwComboBoxGet", (void*)&text, index);
return text;
}
#ifdef __cplusplus
}
#endif

View File

@@ -63,6 +63,7 @@
<integer name="modernLook" />
<integer name="waitMS" />
<integer name="hideInput" />
<integer name="singleClickSelectable" />
<string name="title" />
<string name="text" />
@@ -459,6 +460,8 @@
<widget name="ListBox">
<properties>
<property name="leftPadding" />
<property name="hasHeading" />
<property name="singleClickSelectable" />
</properties>
<functions>
<function name="Insert">

View File

@@ -9,6 +9,7 @@ static int create(MwWidget handle) {
cb->list = NULL;
cb->opened = 0;
cb->selected = 0;
cb->listbox = NULL;
handle->internal = cb;
MwSetDefault(handle);
@@ -49,7 +50,7 @@ static void draw(MwWidget handle) {
p.x = MwDefaultBorderWidth(handle) * 2;
p.y = MwGetInteger(handle, MwNheight) / 2;
MwDrawText(handle, &p, cb->list[0], 0, MwALIGNMENT_BEGINNING, text);
MwDrawText(handle, &p, cb->list[cb->selected], 0, MwALIGNMENT_BEGINNING, text);
}
r = rc;
@@ -76,14 +77,66 @@ static void draw(MwWidget handle) {
MwLLFreeColor(base);
}
static void listbox_activate(MwWidget handle, void* user, void* client) {
MwComboBox cb = handle->parent->internal;
(void)user;
cb->selected = *(int*)client;
cb->opened = 0;
cb->listbox = NULL;
MwForceRender(handle->parent);
MwDispatchUserHandler(handle->parent, MwNchangedHandler, client);
MwDestroyWidget(handle);
}
static void click(MwWidget handle) {
MwComboBox cb = handle->internal;
cb->opened = cb->opened ? 0 : 1;
if(cb->opened) {
MwPoint p;
int i;
void* packet;
int width = MwGetInteger(handle, MwNwidth);
MwLLSetCursor(handle->lowlevel, &MwCursorArrow, &MwCursorArrowMask);
for(i = 0; i < arrlen(cb->list); i++) {
int l = MwTextWidth(handle, cb->list[i]) + MwDefaultBorderWidth(handle) * 2;
if(l > width) width = l;
}
cb->listbox = MwVaCreateWidget(MwListBoxClass, "listbox", handle, 0, 0, width, MwTextHeight(handle, "M") * 6 + MwDefaultBorderWidth(handle) * 2,
MwNsingleClickSelectable, 1,
NULL);
MwLLShow(cb->listbox->lowlevel, 0);
packet = MwListBoxCreatePacket();
for(i = 0; i < arrlen(cb->list); i++) {
int index = MwListBoxPacketInsert(packet, -1);
MwListBoxPacketSet(packet, index, 0, cb->list[i]);
}
MwListBoxInsert(cb->listbox, -1, packet);
MwListBoxDestroyPacket(packet);
MwAddUserHandler(cb->listbox, MwNactivateHandler, listbox_activate, NULL);
p.x = 0;
p.y = MwGetInteger(handle, MwNheight);
MwLLDetach(cb->listbox->lowlevel, &p);
MwLLMakeToolWindow(cb->listbox->lowlevel);
MwLLShow(cb->listbox->lowlevel, 1);
} else {
MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
if(cb->listbox != NULL) {
MwDestroyWidget(cb->listbox);
cb->listbox = NULL;
}
}
MwForceRender(handle);
@@ -100,13 +153,22 @@ static void mwComboBoxAddImpl(MwWidget handle, int index, const char* text) {
if(index <= cb->selected) MwForceRender(handle);
}
static const char* mwComboBoxGetImpl(MwWidget handle, int index) {
MwComboBox cb = handle->internal;
return cb->list[index];
}
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
(void)out;
if(strcmp(name, "mwComboBoxAdd") == 0) {
int index = va_arg(va, int);
const char* text = va_arg(va, const char*);
mwComboBoxAddImpl(handle, index, text);
}
if(strcmp(name, "mwComboBoxGet") == 0) {
int index = va_arg(va, int);
*(const char**)out = mwComboBoxGetImpl(handle, index);
}
}
MwClassRec MwComboBoxClassRec = {

View File

@@ -135,7 +135,7 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) {
lb->selected = st + i;
if(((t = MwTimeGetTick()) - lb->click_time) < 250 && old == st + i) {
if((((t = MwTimeGetTick()) - lb->click_time) < 250 && old == st + i) || MwGetInteger(handle->parent, MwNsingleClickSelectable)) {
MwDispatchUserHandler(handle->parent, MwNactivateHandler, &lb->selected);
}
@@ -307,7 +307,8 @@ static int create(MwWidget handle) {
MwSetDefault(handle);
MwSetInteger(handle, MwNleftPadding, 0);
MwSetInteger(handle, MwNsingleClickSelectable, 0);
MwSetInteger(handle, MwNhasHeading, 0);
MwSetInteger(handle, MwNhasHeading, 0);
resize(handle);

View File

@@ -166,9 +166,7 @@ static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point) {
handle->internal = menu;
MwLLDetach(handle->lowlevel, point);
MwLLMakeToolWindow(handle->lowlevel);
MwLLShow(handle->lowlevel, 1);
for(i = 0; i < arrlen(menu->sub); i++) {