mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-09 19:03:29 +00:00
gdi fix and etc
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@176 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -85,6 +85,8 @@ struct _MwWidget {
|
|||||||
MwTextKeyValue* text;
|
MwTextKeyValue* text;
|
||||||
MwUserHandlerKeyValue* handler;
|
MwUserHandlerKeyValue* handler;
|
||||||
MwVoidKeyValue* data;
|
MwVoidKeyValue* data;
|
||||||
|
|
||||||
|
MwWidget* destroy_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MwMenu {
|
struct _MwMenu {
|
||||||
|
|||||||
@@ -134,6 +134,8 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
|||||||
void MwLLDestroy(MwLL handle) {
|
void MwLLDestroy(MwLL handle) {
|
||||||
MwLLDestroyCommon(handle);
|
MwLLDestroyCommon(handle);
|
||||||
|
|
||||||
|
/* for safety */
|
||||||
|
SetWindowLongPtr(handle->hWnd, GWLP_USERDATA, (LONG_PTR)NULL);
|
||||||
DestroyWindow(handle->hWnd);
|
DestroyWindow(handle->hWnd);
|
||||||
|
|
||||||
free(handle);
|
free(handle);
|
||||||
|
|||||||
45
src/core.c
45
src/core.c
@@ -80,6 +80,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
|
|||||||
h->widget_class = widget_class;
|
h->widget_class = widget_class;
|
||||||
h->pressed = 0;
|
h->pressed = 0;
|
||||||
h->close = 0;
|
h->close = 0;
|
||||||
|
h->destroy_queue = NULL;
|
||||||
|
|
||||||
h->lowlevel->user = h;
|
h->lowlevel->user = h;
|
||||||
h->lowlevel->handler->draw = lldrawhandler;
|
h->lowlevel->handler->draw = lldrawhandler;
|
||||||
@@ -130,29 +131,17 @@ MwWidget MwVaListCreateWidget(MwClass widget_class, const char* name, MwWidget p
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwDestroyWidget(MwWidget handle) {
|
static void MwFreeWidget(MwWidget handle) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
MwDispatch(handle, destroy);
|
MwDispatch(handle, destroy);
|
||||||
|
|
||||||
|
for(i = 0; i < arrlen(handle->children); i++) {
|
||||||
|
MwFreeWidget(handle->children[i]);
|
||||||
|
}
|
||||||
|
|
||||||
free(handle->name);
|
free(handle->name);
|
||||||
|
|
||||||
if(handle->children != NULL) {
|
|
||||||
for(i = 0; i < arrlen(handle->children); i++) {
|
|
||||||
MwDestroyWidget(handle->children[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
arrfree(handle->children);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(handle->parent != NULL) {
|
|
||||||
for(i = 0; i < arrlen(handle->parent->children); i++) {
|
|
||||||
if(handle->parent->children[i] == handle) {
|
|
||||||
arrdel(handle->parent->children, i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MwLLDestroy(handle->lowlevel);
|
MwLLDestroy(handle->lowlevel);
|
||||||
|
|
||||||
shfree(handle->integer);
|
shfree(handle->integer);
|
||||||
@@ -165,14 +154,34 @@ void MwDestroyWidget(MwWidget handle) {
|
|||||||
shfree(handle->handler);
|
shfree(handle->handler);
|
||||||
shfree(handle->data);
|
shfree(handle->data);
|
||||||
|
|
||||||
|
arrfree(handle->destroy_queue);
|
||||||
|
|
||||||
free(handle);
|
free(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MwDestroyWidget(MwWidget handle) {
|
||||||
|
arrput(handle->parent->destroy_queue, handle);
|
||||||
|
}
|
||||||
|
|
||||||
void MwStep(MwWidget handle) {
|
void MwStep(MwWidget handle) {
|
||||||
int i;
|
int i, j;
|
||||||
if(setjmp(handle->before_step)) return;
|
if(setjmp(handle->before_step)) return;
|
||||||
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
|
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
|
||||||
MwLLNextEvent(handle->lowlevel);
|
MwLLNextEvent(handle->lowlevel);
|
||||||
|
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
|
||||||
|
MwWidget w = handle->destroy_queue[i];
|
||||||
|
|
||||||
|
MwFreeWidget(w);
|
||||||
|
}
|
||||||
|
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
|
||||||
|
for(j = 0; j < arrlen(handle->children); j++) {
|
||||||
|
if(handle->children[j] == handle->destroy_queue[i]) {
|
||||||
|
arrdel(handle->children, j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arrfree(handle->destroy_queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MwPending(MwWidget handle) {
|
int MwPending(MwWidget handle) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ static void null_all(MwMenu menu) {
|
|||||||
static void destroy(MwWidget handle) {
|
static void destroy(MwWidget handle) {
|
||||||
MwMenu menu = handle->internal;
|
MwMenu menu = handle->internal;
|
||||||
|
|
||||||
|
menu->wsub = NULL;
|
||||||
null_all(menu);
|
null_all(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,27 +123,24 @@ static void click(MwWidget handle) {
|
|||||||
MwSubMenuAppear(menu->sub[i]->wsub, menu->sub[i], &p);
|
MwSubMenuAppear(menu->sub[i]->wsub, menu->sub[i], &p);
|
||||||
i = -1;
|
i = -1;
|
||||||
} else if(menu->sub[i]->wsub != NULL && arrlen(menu->sub[i]->sub) > 0) {
|
} else if(menu->sub[i]->wsub != NULL && arrlen(menu->sub[i]->sub) > 0) {
|
||||||
|
while(w->parent->widget_class != MwMenuClass) w = w->parent;
|
||||||
|
|
||||||
MwDestroyWidget(menu->sub[i]->wsub);
|
MwDestroyWidget(menu->sub[i]->wsub);
|
||||||
menu->sub[i]->wsub = NULL;
|
menu->sub[i]->wsub = NULL;
|
||||||
|
|
||||||
|
MwForceRender(w->parent);
|
||||||
|
|
||||||
MwForceRender(handle);
|
MwForceRender(handle);
|
||||||
} else if(arrlen(menu->sub[i]->sub) == 0) {
|
} else if(arrlen(menu->sub[i]->sub) == 0) {
|
||||||
MwWidget p;
|
|
||||||
|
|
||||||
while(w->parent->widget_class != MwMenuClass) w = w->parent;
|
while(w->parent->widget_class != MwMenuClass) w = w->parent;
|
||||||
MwGetBeforeStep(w, &jmp);
|
MwGetBeforeStep(w, &jmp);
|
||||||
|
|
||||||
p = w->parent;
|
|
||||||
|
|
||||||
MwDestroyWidget(w);
|
MwDestroyWidget(w);
|
||||||
|
((MwMenu)w->internal)->wsub = NULL;
|
||||||
|
|
||||||
MwForceRender(p);
|
MwForceRender(w->parent);
|
||||||
|
|
||||||
MwDispatchUserHandler(p, MwNmenuHandler, menu->sub[i]);
|
MwDispatchUserHandler(w->parent, MwNmenuHandler, menu->sub[i]);
|
||||||
|
|
||||||
longjmp(jmp, 1);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +165,22 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
|
|||||||
int i, w = 0, h = 0;
|
int i, w = 0, h = 0;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
RECT rc;
|
RECT rc;
|
||||||
|
LONG_PTR ex = GetWindowLongPtr(handle->lowlevel->hWnd, GWL_EXSTYLE);
|
||||||
|
#else
|
||||||
|
Atom wndtype = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE", False);
|
||||||
|
Atom wndmenu = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE_MENU", False);
|
||||||
|
int x = 0, y = 0;
|
||||||
|
Window child;
|
||||||
|
XSetWindowAttributes xswa;
|
||||||
|
#endif
|
||||||
|
|
||||||
SetWindowLongPtr(handle->lowlevel->hWnd, GWL_STYLE, (LONG_PTR)WS_POPUP);
|
handle->internal = menu;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
ex |= WS_EX_TOOLWINDOW;
|
||||||
|
|
||||||
|
SetWindowLongPtr(handle->lowlevel->hWnd, GWL_STYLE, (LONG_PTR)0);
|
||||||
|
SetWindowLongPtr(handle->lowlevel->hWnd, GWL_EXSTYLE, ex);
|
||||||
|
|
||||||
GetWindowRect(handle->parent->lowlevel->hWnd, &rc);
|
GetWindowRect(handle->parent->lowlevel->hWnd, &rc);
|
||||||
|
|
||||||
@@ -177,18 +189,12 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
|
|||||||
rc.left += point->x;
|
rc.left += point->x;
|
||||||
rc.top += point->y;
|
rc.top += point->y;
|
||||||
|
|
||||||
SetWindowPos(handle->lowlevel->hWnd, NULL, rc.left, rc.top, 1, 1, SWP_NOREDRAW);
|
SetWindowPos(handle->lowlevel->hWnd, HWND_TOPMOST, rc.left, rc.top, 1, 1, SWP_NOREDRAW);
|
||||||
|
|
||||||
ShowWindow(handle->lowlevel->hWnd, SW_NORMAL);
|
ShowWindow(handle->lowlevel->hWnd, SW_NORMAL);
|
||||||
UpdateWindow(handle->lowlevel->hWnd);
|
|
||||||
|
|
||||||
SetFocus(handle->lowlevel->hWnd);
|
SetFocus(handle->lowlevel->hWnd);
|
||||||
#else
|
#else
|
||||||
Atom wndtype = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE", False);
|
|
||||||
Atom wndmenu = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE_MENU", False);
|
|
||||||
int x = 0, y = 0;
|
|
||||||
Window child;
|
|
||||||
XSetWindowAttributes xswa;
|
|
||||||
|
|
||||||
xswa.override_redirect = True;
|
xswa.override_redirect = True;
|
||||||
|
|
||||||
@@ -203,8 +209,6 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
|
|||||||
XSetInputFocus(handle->lowlevel->display, handle->lowlevel->window, RevertToNone, CurrentTime);
|
XSetInputFocus(handle->lowlevel->display, handle->lowlevel->window, RevertToNone, CurrentTime);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
handle->internal = menu;
|
|
||||||
|
|
||||||
for(i = 0; i < arrlen(menu->sub); i++) {
|
for(i = 0; i < arrlen(menu->sub); i++) {
|
||||||
int tw = MwTextWidth(handle, menu->sub[i]->name);
|
int tw = MwTextWidth(handle, menu->sub[i]->name);
|
||||||
h += MwTextHeight(handle, menu->sub[i]->name) + 3;
|
h += MwTextHeight(handle, menu->sub[i]->name) + 3;
|
||||||
|
|||||||
Reference in New Issue
Block a user