diff --git a/include/Mw/Milsko.h b/include/Mw/Milsko.h index 0b61e80..53efe4b 100644 --- a/include/Mw/Milsko.h +++ b/include/Mw/Milsko.h @@ -46,5 +46,6 @@ #include #include #include +#include #endif diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index bb5bef6..c16a058 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -18,6 +18,7 @@ typedef struct _MwMenu* MwMenu; typedef struct _MwEntry* MwEntry; typedef struct _MwViewport* MwViewport; typedef struct _MwListBox* MwListBox; +typedef struct _MwComboBox* MwComboBox; typedef struct _MwListBoxEntry MwListBoxEntry; typedef struct _MwDirectoryEntry MwDirectoryEntry; typedef struct _MwListBoxPacket MwListBoxPacket; @@ -129,6 +130,10 @@ struct _MwListBox { int changed; }; +struct _MwComboBox { + int opened; +}; + struct _MwDirectoryEntry { char* name; int type; diff --git a/include/Mw/Widget/ComboBox.h b/include/Mw/Widget/ComboBox.h new file mode 100644 index 0000000..3b4d629 --- /dev/null +++ b/include/Mw/Widget/ComboBox.h @@ -0,0 +1,25 @@ +/* $Id: ComboBox.h 206 2025-10-07 15:10:46Z nishi $ */ +/*! + * @file Mw/Widget/ComboBox.h + * @brief ComboBox widget + */ +#ifndef __MW_WIDGET_COMBOBOX_H__ +#define __MW_WIDGET_COMBOBOX_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * @brief ComboBox widget class + */ +MWDECL MwClass MwComboBoxClass; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/pl/rules.pl b/pl/rules.pl index f9915e9..cefb1c2 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -55,6 +55,7 @@ new_object("src/cursor/*.c"); new_object("src/widget/button.c"); new_object("src/widget/checkbox.c"); +new_object("src/widget/combobox.c"); new_object("src/widget/entry.c"); new_object("src/widget/frame.c"); new_object("src/widget/image.c"); diff --git a/src/draw.c b/src/draw.c index d02d2ca..c47eba3 100644 --- a/src/draw.c +++ b/src/draw.c @@ -269,7 +269,7 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) { MwPoint p1[4], p2[4], p3[4], p4[3]; - const int border = MwGetInteger(handle, MwNmodernLook) ? 1 : MwDefaultBorderWidth(handle); + const int border = MwGetInteger(handle, MwNmodernLook) ? 2 : MwDefaultBorderWidth(handle); int ColorDiff = get_color_diff(handle); MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff); diff --git a/src/widget/combobox.c b/src/widget/combobox.c new file mode 100644 index 0000000..46d8b1f --- /dev/null +++ b/src/widget/combobox.c @@ -0,0 +1,87 @@ +/* $Id$ */ +#include + +static int create(MwWidget handle) { + MwComboBox cb = malloc(sizeof(*cb)); + + cb->opened = 0; + handle->internal = cb; + + MwSetDefault(handle); + + return 0; +} + +static void destroy(MwWidget handle) { + free(handle->internal); +} + +static void draw(MwWidget handle) { + MwRect r, rc; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwComboBox cb = handle->internal; + + r.x = 0; + r.y = 0; + r.width = MwGetInteger(handle, MwNwidth); + r.height = MwGetInteger(handle, MwNheight); + + MwDrawWidgetBack(handle, &r, base, 0, 1); + + rc = r; + + /* draw text */ + + r = rc; + r.height /= 5; + r.width = r.height * 3; + r.x = MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) - r.width - (r.width / 3) * 2; + r.y = MwDefaultBorderWidth(handle); + r.height = rc.height; + r.width += (r.width / 3) * 2; + MwDrawWidgetBack(handle, &r, base, 0, 0); + + r = rc; + r.width = r.height * 3 / 5; + r.height = r.width - MwDefaultBorderWidth(handle) * 2; + r.x = MwGetInteger(handle, MwNwidth) - MwDefaultBorderWidth(handle) - r.width - r.width / 3; + r.y = (MwGetInteger(handle, MwNheight) - (r.height + MwDefaultBorderWidth(handle) * 2)) / 2; + MwDrawTriangle(handle, &r, base, cb->opened, MwSOUTH); + + r.y += r.height; + r.height = MwDefaultBorderWidth(handle) * 2; + MwDrawFrame(handle, &r, base, 0); + + MwLLFreeColor(base); +} + +static void click(MwWidget handle) { + MwComboBox cb = handle->internal; + + cb->opened = cb->opened ? 0 : 1; + + MwForceRender(handle); +} + +static void func_handler(MwWidget handle, const char* name, void* out, va_list va) { + if(strcmp(name, "mwComboBoxAdd") == 0) { + } +} + +MwClassRec MwComboBoxClassRec = { + create, /* create */ + destroy, /* destroy */ + draw, /* draw */ + click, /* click */ + NULL, /* parent_resize */ + NULL, /* prop_change */ + NULL, /* mouse_move */ + MwForceRender2, /* mouse_up */ + MwForceRender2, /* mouse_down */ + NULL, /* key */ + func_handler, /* execute */ + NULL, /* tick */ + NULL, + NULL, + NULL}; +MwClass MwComboBoxClass = &MwComboBoxClassRec;