messagebox

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@257 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-11 06:21:43 +00:00
parent 72ba706b31
commit 22b6c60f45
16 changed files with 3371 additions and 11 deletions

View File

@@ -406,3 +406,12 @@ void MwLLShow(MwLL handle, int show) {
ShowWindow(handle->hWnd, show ? SW_NORMAL : SW_HIDE);
if(show) SetFocus(handle->hWnd);
}
void MwLLMakePopup(MwLL handle, MwLL parent) {
(void)handle;
(void)parent;
/* TODO */
}
void MwLLSetSizeHints(MwLL handle, int minx, int miny, int maxx, int maxy) {
}

View File

@@ -452,3 +452,25 @@ void MwLLShow(MwLL handle, int show) {
XUnmapWindow(handle->display, handle->window);
}
}
void MwLLMakePopup(MwLL handle, MwLL parent) {
Atom wndtype = XInternAtom(handle->display, "_NET_WM_WINDOW_TYPE", False);
Atom wnddlg = XInternAtom(handle->display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
Atom wndstate = XInternAtom(handle->display, "_NET_WM_STATE", False);
Atom wndmodal = XInternAtom(handle->display, "_NET_WM_STATE_MODAL", False);
XSetTransientForHint(handle->display, handle->window, parent->window);
XChangeProperty(handle->display, handle->window, wndtype, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wnddlg, 1);
XChangeProperty(handle->display, handle->window, wndstate, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wndmodal, 1);
}
void MwLLSetSizeHints(MwLL handle, int minx, int miny, int maxx, int maxy) {
XSizeHints* hints = XAllocSizeHints();
hints->flags = PMinSize | PMaxSize;
hints->min_width = minx;
hints->min_height = miny;
hints->max_width = maxx;
hints->max_height = maxy;
XSetWMSizeHints(handle->display, handle->window, hints, XA_WM_NORMAL_HINTS);
XFree(hints);
}

View File

@@ -8,6 +8,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xcursor/Xcursor.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/Xrender.h>

2964
src/color.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -52,6 +52,8 @@ MwLLColor MwParseColor(MwWidget handle, const char* text) {
r = hex(text + 1, 2);
g = hex(text + 3, 2);
b = hex(text + 5, 2);
} else {
return MwParseColorName(handle, text);
}
return MwLLAllocColor(handle->lowlevel, r, g, b);
@@ -560,9 +562,26 @@ MwLLPixmap MwLoadImage(MwWidget handle, const char* path) {
}
MwLLPixmap MwLoadRaw(MwWidget handle, unsigned char* rgb, int width, int height) {
MwLLPixmap px;
MwLLPixmap px;
MwLLColor bg = MwParseColor(handle, MwGetText(handle, MwNbackground));
unsigned char* out = malloc(width * height * 4);
int y, x;
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
unsigned char* pin = &rgb[(y * width + x) * 4];
unsigned char* pout = &out[(y * width + x) * 4];
pout[0] = pin[0] * (pin[3] / 255.0) + bg->red * (1.0 - pin[3] / 255.0);
pout[1] = pin[1] * (pin[3] / 255.0) + bg->green * (1.0 - pin[3] / 255.0);
pout[2] = pin[2] * (pin[3] / 255.0) + bg->blue * (1.0 - pin[3] / 255.0);
pout[3] = 255;
}
}
px = MwLLCreatePixmap(handle->lowlevel, rgb, width, height);
MwLLFreeColor(bg);
px = MwLLCreatePixmap(handle->lowlevel, out, width, height);
free(out);
return px;
}
@@ -576,27 +595,75 @@ void MwGetColor(MwLLColor color, int* red, int* green, int* blue) {
typedef struct color {
char* key;
char* value;
int r;
int g;
int b;
int a;
} color_t;
MwLLPixmap MwLoadXPM(MwWidget handle, char** data) {
int col, row, colors, cpp;
unsigned char* rgb;
MwLLPixmap px;
char k[512];
color_t* c = NULL;
int i;
int i, y, x;
char* comp;
sh_new_strdup(c);
sscanf(data[0], "%d %d %d %d", &col, &row, &colors, &cpp);
for(i = 0; i < colors; i++) {
memcpy(k, data[i + 1], cpp);
k[cpp] = 0;
printf("%s\n", k);
char k[128];
char* v = data[i + 1] + cpp + 3;
int ind;
if(strcmp(v, "None") == 0) {
memcpy(k, data[i + 1], cpp);
k[cpp] = 0;
shput(c, k, v);
ind = shgeti(c, k);
c[ind].r = 0;
c[ind].g = 0;
c[ind].b = 0;
c[ind].a = 0;
} else {
MwLLColor color = MwParseColor(handle, v);
memcpy(k, data[i + 1], cpp);
k[cpp] = 0;
shput(c, k, v);
ind = shgeti(c, k);
c[ind].r = color->red;
c[ind].g = color->green;
c[ind].b = color->blue;
c[ind].a = 255;
MwLLFreeColor(color);
}
}
rgb = malloc(row * col * 4);
rgb = malloc(row * col * 4);
comp = malloc(cpp + 1);
comp[cpp] = 0;
for(y = 0; y < row; y++) {
for(x = 0; x < col; x++) {
unsigned char* pout = &rgb[(y * col + x) * 4];
color_t colent;
memcpy(comp, &data[1 + colors + y][x * cpp], cpp);
colent = shgets(c, comp);
pout[0] = colent.r;
pout[1] = colent.g;
pout[2] = colent.b;
pout[3] = colent.a;
}
}
free(comp);
px = MwLoadRaw(handle, rgb, col, row);

55
src/messagebox.c Normal file
View File

@@ -0,0 +1,55 @@
/* $Id$ */
#include <Mw/Milsko.h>
MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsigned int flag) {
MwWidget window, ok;
MwPoint p;
int w, h;
p.x = 0;
p.y = 0;
window = MwVaCreateWidget(MwWindowClass, "messagebox", handle, 0, 0, (w = 512), (h = 32 * 4),
MwNtitle, title,
NULL);
ok = MwVaCreateWidget(MwButtonClass, "ok", window, w - 8 - 64, h - 8 - 24, 64, 24,
MwNtext, "OK",
NULL);
if((flag & MwMB_ICONMASK) != 0) {
MwWidget icon;
MwLLPixmap px;
char** data = NULL;
icon = MwCreateWidget(MwImageClass, "image", window, 16, (h - 48) / 2, 48, 48);
switch(flag & MwMB_ICONMASK) {
case MwMB_ICONWARNING: {
data = MwIconWarning;
break;
}
case MwMB_ICONINFO: {
data = MwIconInfo;
break;
}
case MwMB_ICONNOTE: {
data = MwIconNote;
break;
}
case MwMB_ICONQUESTION: {
data = MwIconQuestion;
break;
}
}
px = MwLoadXPM(icon, data);
MwSetVoid(icon, MwNpixmap, px);
}
MwLLDetach(window->lowlevel, &p);
MwLLSetSizeHints(window->lowlevel, w, h, w, h);
MwLLMakePopup(window->lowlevel, handle->lowlevel);
return window;
}

View File

@@ -174,7 +174,7 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
xswa.override_redirect = True;
XChangeWindowAttributes(handle->lowlevel->display, handle->lowlevel->window, CWOverrideRedirect, &xswa);
XChangeProperty(handle->lowlevel->display, handle->lowlevel->window, wndtype, 4, 32, PropModeReplace, (unsigned char*)&wndmenu, 1);
XChangeProperty(handle->lowlevel->display, handle->lowlevel->window, wndtype, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wndmenu, 1);
#endif
handle->internal = menu;