diff --git a/GNUmakefile b/GNUmakefile index 0680167..230671f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -30,7 +30,7 @@ L_OBJS = src/core.o src/default.o src/draw.o src/lowlevel.o src/font.o src/boldf L_OBJS += src/external/ds.o src/external/image.o L_OBJS += src/widget/window.o src/widget/button.o src/widget/frame.o src/widget/menu.o src/widget/submenu.o src/widget/image.o src/widget/scrollbar.o src/widget/checkbox.o src/widget/label.o src/widget/entry.o src/widget/numberentry.o L_OBJS += src/cursor/default.o src/cursor/cross.o src/cursor/text.o -L_OBJS += src/icon/question.o src/icon/warning.o src/icon/note.o src/icon/info.o src/icon/news.o +L_OBJS += src/icon/question.o src/icon/warning.o src/icon/note.o src/icon/info.o src/icon/news.o src/icon/error.o OOL_CXXFLAGS = $(DEPINC) $(CFLAGS) -std=c++98 -fPIC OOL_LDFLAGS = $(LDFLAGS) -L src diff --git a/examples/messagebox.c b/examples/messagebox.c index d4d2fe5..e599b07 100644 --- a/examples/messagebox.c +++ b/examples/messagebox.c @@ -6,15 +6,22 @@ void ok(MwWidget handle, void* user, void* call) { } void spawn(MwWidget handle, void* user, void* call) { - MwWidget mb = MwMessageBox(user, "new news arrived!", "title", MwMB_ICONNEWS | MwMB_BUTTONOK); + MwWidget mb = MwMessageBox(user, "news has arrived!", "title", MwMB_ICONNEWS | MwMB_BUTTONOK); + MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb); +} + +void spawn2(MwWidget handle, void* user, void* call) { + MwWidget mb = MwMessageBox(user, "something went wrong!", "title", MwMB_ICONERROR | MwMB_BUTTONOK); MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb); } int main() { - MwWidget msg = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 300, 100, MwNtitle, "test", NULL); - MwWidget btn = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8, 300 - 16, 100 - 16, MwNtext, "press me!", NULL); + MwWidget msg = MwVaCreateWidget(MwWindowClass, "test", NULL, MwDEFAULT, MwDEFAULT, 300, 100, MwNtitle, "test", NULL); + MwWidget btn = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8, 300 - 16, (100 - 16) / 2, MwNtext, "press me!", NULL); + MwWidget btn2 = MwVaCreateWidget(MwButtonClass, "button", msg, 8, 8 + (100 - 16) / 2, 300 - 16, (100 - 16) / 2, MwNtext, "press me!", NULL); MwAddUserHandler(btn, MwNactivateHandler, spawn, msg); + MwAddUserHandler(btn2, MwNactivateHandler, spawn2, msg); MwLoop(msg); } diff --git a/include/Mw/Constants.h b/include/Mw/Constants.h index ab0a0f9..be777df 100644 --- a/include/Mw/Constants.h +++ b/include/Mw/Constants.h @@ -68,6 +68,11 @@ enum MwALIGNMENT { */ #define MwMB_ICONNEWS 0x5 +/*! + * %brief Error icon + */ +#define MwMB_ICONERROR 0x6 + /*! * %brief Button mask */ diff --git a/include/Mw/Icon.h b/include/Mw/Icon.h index 102bff4..6c9ad88 100644 --- a/include/Mw/Icon.h +++ b/include/Mw/Icon.h @@ -12,6 +12,11 @@ extern "C" { #endif +/*! + * %brief Error icon + */ +MWDECL char* MwIconError[]; + /*! * %brief Info icon */ diff --git a/resource/icon/error.gif b/resource/icon/error.gif new file mode 100644 index 0000000..ab06944 Binary files /dev/null and b/resource/icon/error.gif differ diff --git a/resource/icon/error.png b/resource/icon/error.png new file mode 100644 index 0000000..e9c3a7d Binary files /dev/null and b/resource/icon/error.png differ diff --git a/resource/icon/info.png b/resource/icon/info.png index 17f1778..278da5a 100644 Binary files a/resource/icon/info.png and b/resource/icon/info.png differ diff --git a/resource/icon/news.png b/resource/icon/news.png index 0e37df6..11ecbc3 100644 Binary files a/resource/icon/news.png and b/resource/icon/news.png differ diff --git a/resource/icon/note.png b/resource/icon/note.png index 49f9ee4..47c1f9b 100644 Binary files a/resource/icon/note.png and b/resource/icon/note.png differ diff --git a/resource/icon/question.png b/resource/icon/question.png index d891ffc..57adc03 100644 Binary files a/resource/icon/question.png and b/resource/icon/question.png differ diff --git a/resource/icon/warning.png b/resource/icon/warning.png index 5b072f0..382c213 100644 Binary files a/resource/icon/warning.png and b/resource/icon/warning.png differ diff --git a/src/backend/gdi.c b/src/backend/gdi.c index 8d79ad6..f13b719 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -2,8 +2,11 @@ #include typedef struct userdata { - MwLL ll; - WNDPROC old; + MwLL ll; + POINT min; + POINT max; + int min_set; + int max_set; } userdata_t; static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { @@ -83,8 +86,39 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { if(wp == VK_LEFT) n = MwLLKeyLeft; if(wp == VK_RIGHT) n = MwLLKeyRight; if(n != -1) MwLLDispatch(u->ll, key, &n); + } else if(msg == WM_GETMINMAXINFO) { + if(u->min_set || u->max_set) { + LPARAM style = GetWindowLongPtr(hWnd, GWL_STYLE); + MINMAXINFO* mmi = (MINMAXINFO*)lp; + if(u->min_set) { + RECT rc; + + rc.left = 0; + rc.top = 0; + rc.right = u->min.x; + rc.bottom = u->min.y; + AdjustWindowRect(&rc, style, FALSE); + + mmi->ptMinTrackSize.x = rc.right - rc.left; + mmi->ptMinTrackSize.y = rc.bottom - rc.top; + } + if(u->max_set) { + RECT rc; + + rc.left = 0; + rc.top = 0; + rc.right = u->min.x; + rc.bottom = u->min.y; + AdjustWindowRect(&rc, style, FALSE); + + mmi->ptMaxTrackSize.x = rc.right - rc.left; + mmi->ptMaxTrackSize.y = rc.bottom - rc.top; + } + } else { + return DefWindowProc(hWnd, msg, wp, lp); + } } else { - return (u->old == NULL) ? DefWindowProc(hWnd, msg, wp, lp) : CallWindowProc(u->old, hWnd, msg, wp, lp); + return DefWindowProc(hWnd, msg, wp, lp); } return 0; } @@ -113,15 +147,12 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) { RegisterClassEx(&wc); r->copy_buffer = 1; - r->hWnd = CreateWindow(parent == NULL ? "milsko" : "STATIC", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL); + r->hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL); r->hInstance = wc.hInstance; - u->ll = r; - if(parent == NULL) { - u->old = NULL; - } else { - u->old = (WNDPROC)SetWindowLongPtr(r->hWnd, GWLP_WNDPROC, (LPARAM)wndproc); - } + u->ll = r; + u->min_set = 0; + u->max_set = 0; SetWindowLongPtr(r->hWnd, GWLP_USERDATA, (LPARAM)u); if(parent == NULL) { @@ -383,23 +414,22 @@ void MwLLSetCursor(MwLL handle, MwCursor* image, MwCursor* mask) { } void MwLLDetach(MwLL handle, MwPoint* point) { - RECT rc, rc2; - LPARAM style = GetWindowLongPtr(handle->hWnd, GWL_STYLE); - - style |= WS_OVERLAPPEDWINDOW; - + RECT rc, rc2; GetWindowRect(GetParent(handle->hWnd), &rc); GetClientRect(handle->hWnd, &rc2); + SetWindowLongPtr(handle->hWnd, GWL_STYLE, (LPARAM)WS_OVERLAPPEDWINDOW | WS_VISIBLE); SetParent(handle->hWnd, NULL); rc.left += point->x; rc.top += point->y; - SetWindowPos(handle->hWnd, HWND_TOPMOST, rc.left, rc.top, rc2.right == 0 ? 1 : rc2.right, rc2.bottom == 0 ? 1 : rc2.bottom, SWP_NOREDRAW); + AdjustWindowRect(&rc2, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE); + rc2.right -= rc2.left; + rc2.bottom -= rc2.top; - SetWindowLongPtr(handle->hWnd, GWL_STYLE, style); + SetWindowPos(handle->hWnd, HWND_TOPMOST, rc.left, rc.top, rc2.right == 0 ? 1 : rc2.right, rc2.bottom == 0 ? 1 : rc2.bottom, SWP_FRAMECHANGED | SWP_NOACTIVATE); } void MwLLShow(MwLL handle, int show) { @@ -414,4 +444,11 @@ void MwLLMakePopup(MwLL handle, MwLL parent) { } void MwLLSetSizeHints(MwLL handle, int minx, int miny, int maxx, int maxy) { + userdata_t* u = (userdata_t*)GetWindowLongPtr(handle->hWnd, GWLP_USERDATA); + + u->min_set = u->max_set = 1; + u->min.x = minx; + u->min.y = miny; + u->max.x = maxx; + u->max.y = maxy; } diff --git a/src/icon/error.c b/src/icon/error.c new file mode 100644 index 0000000..2fc11d9 --- /dev/null +++ b/src/icon/error.c @@ -0,0 +1,48 @@ +/* $Id$ */ +#include + +/* XPM */ +char* MwIconError[] = { + /* columns rows colors chars-per-pixel */ + "32 32 8 1 ", + " c None", + ". c black", + "X c white", + "o c gray", + "O c gainsboro", + "+ c lavender", + "@ c DarkSlateGray", + "# c SlateGray", + /* pixels */ + " ... ... ", + " .Xo. .XX. ", + "..XXo. .XXX..", + ".XXoo. .XXOo.", + ".XXooo. ......... .XOooo.", + " ...Xoo...O+++++++o.. .Xoo...@", + " .Xo.#O++XXXXX++Oo. .Xoo.@@@@", + " ..#OO+XXXXXX+OOOo.#oo.@@ ", + " .OOO+XXXXX++OOOo.@#.@@ ", + " .#OOO+XXXX++OOOoo#..@@ ", + " .#OOO+XX+++OOOOoo#.@@ ", + " .#ooo+++++OOOOo###.@@@ ", + " .ooXXXXX+OOO++++##.@@@ ", + " .oXXOOOOOOO++OOoo#.@@@ ", + " .oo...OOOOO...oo..@@@ ", + " .o.....ooo.....o.@@@@ ", + " .X.....ooo...@#o.@@@ ", + " .oX@@@@.Xoo.@##@oo.@@ ", + " .OXo@@.Xo.oX.@@oXo.@@@ ", + " .OOXXXXo...oXXXOoo.@@@ ", + " ..oOOXo.o.oOOOo..@.@@ ", + " ..oOOo.o.oOOo..@##.@ ", + " ..o.oXXXXXOOo.o..###. ", + " .oo.o.@oXXo...o.@@.#oX... ", + " .XXo.X@o....@o.o.@@@.ooXXX. ", + " ...XXo..X@X@o@o@X.o.@@@ .oXoo. ", + ".XXXoo.@@.X.@X@X@.o.@@@@ .Xoo..@", + ".XXXo.@@@.X.@o@o@.o.@@@ .oo.@@@", + "..ooo.@@ .X.....o.@@@@ ...@@ ", + " .oo.@ .XXXXooo.@@@ @@@ ", + " ...@@ .ooooo.@@@ ", + " @@@@ .....@@ "}; diff --git a/src/messagebox.c b/src/messagebox.c index 478067d..33ce760 100644 --- a/src/messagebox.c +++ b/src/messagebox.c @@ -25,12 +25,14 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi int w, h; int left = 8; int th; - int x = 0; + int x = 0; + int ww = MwGetInteger(handle, MwNwidth); + int wh = MwGetInteger(handle, MwNheight); p.x = 0; p.y = 0; - window = MwVaCreateWidget(MwWindowClass, "messagebox", handle, 0, 0, (w = 512), (h = 32 * 4), + window = MwVaCreateWidget(MwWindowClass, "messagebox", handle, ww, wh, (w = 512), (h = 32 * 4), MwNtitle, title, NULL); @@ -70,6 +72,10 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi data = MwIconNews; break; } + case MwMB_ICONERROR: { + data = MwIconError; + break; + } } px = MwLoadXPM(icon, data);