menu works on windows
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@139 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
parent
6db4808815
commit
06b2178ecc
5 changed files with 63 additions and 26 deletions
|
|
@ -82,7 +82,12 @@ int main() {
|
||||||
m2 = MwMenuAdd(menu, m, "test 6");
|
m2 = MwMenuAdd(menu, m, "test 6");
|
||||||
MwMenuAdd(menu, m2, "test 7");
|
MwMenuAdd(menu, m2, "test 7");
|
||||||
MwMenuAdd(menu, m2, "test 8");
|
MwMenuAdd(menu, m2, "test 8");
|
||||||
MwMenuAdd(menu, NULL, "?test 9");
|
m2 = MwMenuAdd(menu, m, "test 9");
|
||||||
|
MwMenuAdd(menu, m2, "test 10");
|
||||||
|
m2 = MwMenuAdd(menu, m2, "test 11");
|
||||||
|
MwMenuAdd(menu, m2, "test 12");
|
||||||
|
MwMenuAdd(menu, m2, "test 13");
|
||||||
|
MwMenuAdd(menu, NULL, "?test 14");
|
||||||
|
|
||||||
MwLoop(window);
|
MwLoop(window);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,12 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||||
SetCapture(NULL);
|
SetCapture(NULL);
|
||||||
MwLLDispatch(u->ll, up, &p);
|
MwLLDispatch(u->ll, up, &p);
|
||||||
InvalidateRect(hWnd, NULL, FALSE);
|
InvalidateRect(hWnd, NULL, FALSE);
|
||||||
|
} else if(msg == WM_MOUSEMOVE) {
|
||||||
|
MwPoint p;
|
||||||
|
p.x = LOWORD(lp);
|
||||||
|
p.y = HIWORD(lp);
|
||||||
|
|
||||||
|
MwLLDispatch(u->ll, move, &p);
|
||||||
} else if(msg == WM_SIZE) {
|
} else if(msg == WM_SIZE) {
|
||||||
MwLLDispatch(u->ll, resize, NULL);
|
MwLLDispatch(u->ll, resize, NULL);
|
||||||
} else if(msg == WM_ERASEBKGND) {
|
} else if(msg == WM_ERASEBKGND) {
|
||||||
|
|
@ -310,6 +316,6 @@ void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap) {
|
||||||
DestroyIcon(ico);
|
DestroyIcon(ico);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwLLForceRender(MwLL handle){
|
void MwLLForceRender(MwLL handle) {
|
||||||
InvalidateRect(handle->hWnd, NULL, FALSE);
|
InvalidateRect(handle->hWnd, NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -328,7 +328,7 @@ void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap) {
|
||||||
free(icon);
|
free(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwLLForceRender(MwLL handle){
|
void MwLLForceRender(MwLL handle) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
memset(&ev, 0, sizeof(ev));
|
memset(&ev, 0, sizeof(ev));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ static void draw(MwWidget handle) {
|
||||||
m->sub[i]->wsub = NULL;
|
m->sub[i]->wsub = NULL;
|
||||||
m->sub[i]->keep = 0;
|
m->sub[i]->keep = 0;
|
||||||
m->wait = 1;
|
m->wait = 1;
|
||||||
}else if(arrlen(m->sub[i]->sub) == 0){
|
} else if(arrlen(m->sub[i]->sub) == 0) {
|
||||||
MwDispatchUserHandler(handle, MwNmenuHandler, m->sub[i]);
|
MwDispatchUserHandler(handle, MwNmenuHandler, m->sub[i]);
|
||||||
}
|
}
|
||||||
} else if(!handle->pressed && m->sub[i]->wsub != NULL) {
|
} else if(!handle->pressed && m->sub[i]->wsub != NULL) {
|
||||||
|
|
|
||||||
|
|
@ -45,13 +45,13 @@ static void draw(MwWidget handle) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
p.x = 0;
|
p.x = 0;
|
||||||
p.y = 5;
|
p.y = 3;
|
||||||
|
|
||||||
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);
|
||||||
int th = MwTextHeight(handle, menu->sub[i]->name);
|
int th = MwTextHeight(handle, menu->sub[i]->name);
|
||||||
|
|
||||||
if(menu->sub[i]->wsub != NULL){
|
if(menu->sub[i]->wsub != NULL) {
|
||||||
r.x = 0;
|
r.x = 0;
|
||||||
r.y = p.y - 3;
|
r.y = p.y - 3;
|
||||||
r.width = tw + 15 + 5 * 2;
|
r.width = tw + 15 + 5 * 2;
|
||||||
|
|
@ -64,7 +64,7 @@ static void draw(MwWidget handle) {
|
||||||
p.y += th / 2;
|
p.y += th / 2;
|
||||||
MwDrawText(handle, &p, menu->sub[i]->name, 1, text);
|
MwDrawText(handle, &p, menu->sub[i]->name, 1, text);
|
||||||
|
|
||||||
if(arrlen(menu->sub[i]->sub) > 0){
|
if(arrlen(menu->sub[i]->sub) > 0) {
|
||||||
MwPoint pl[3];
|
MwPoint pl[3];
|
||||||
|
|
||||||
p.x = 5 + tw + 10;
|
p.x = 5 + tw + 10;
|
||||||
|
|
@ -81,7 +81,7 @@ static void draw(MwWidget handle) {
|
||||||
MwLLPolygon(handle->lowlevel, pl, 3, text);
|
MwLLPolygon(handle->lowlevel, pl, 3, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.y += th / 2 + 5;
|
p.y += th / 2 + 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ static void click(MwWidget handle) {
|
||||||
MwRect rc;
|
MwRect rc;
|
||||||
|
|
||||||
rc.x = 5;
|
rc.x = 5;
|
||||||
rc.y = 5;
|
rc.y = 3;
|
||||||
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);
|
||||||
if(tw > ww) ww = tw;
|
if(tw > ww) ww = tw;
|
||||||
|
|
@ -115,26 +115,35 @@ static void click(MwWidget handle) {
|
||||||
MwPoint p;
|
MwPoint p;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
for(j = 0; j < arrlen(menu->sub); j++){
|
for(j = 0; j < arrlen(menu->sub); j++) {
|
||||||
if(menu->sub[j]->wsub != NULL) MwDestroyWidget(menu->sub[j]->wsub);
|
if(menu->sub[j]->wsub != NULL) MwDestroyWidget(menu->sub[j]->wsub);
|
||||||
menu->sub[j]->wsub = NULL;
|
menu->sub[j]->wsub = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.x = rc.x + rc.width + 5;
|
p.x = rc.x + rc.width + 3;
|
||||||
p.y = rc.y - 5;
|
p.y = rc.y - 3;
|
||||||
|
|
||||||
menu->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
menu->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
||||||
MwSubMenuAppear(menu->sub[i]->wsub, menu->sub[i], &p);
|
MwSubMenuAppear(menu->sub[i]->wsub, menu->sub[i], &p);
|
||||||
i = -1;
|
i = -1;
|
||||||
}else if(arrlen(menu->sub[i]->sub) == 0){
|
} else if(menu->sub[i]->wsub != NULL && arrlen(menu->sub[i]->sub) > 0) {
|
||||||
|
MwDestroyWidget(menu->sub[i]->wsub);
|
||||||
|
menu->sub[i]->wsub = NULL;
|
||||||
|
|
||||||
|
MwLLForceRender(handle->lowlevel);
|
||||||
|
} 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);
|
||||||
|
|
||||||
MwLLForceRender(w->parent->lowlevel);
|
MwLLForceRender(p->lowlevel);
|
||||||
|
|
||||||
MwDispatchUserHandler(w->parent, MwNmenuHandler, menu->sub[i]);
|
MwDispatchUserHandler(p, MwNmenuHandler, menu->sub[i]);
|
||||||
|
|
||||||
longjmp(jmp, 1);
|
longjmp(jmp, 1);
|
||||||
|
|
||||||
|
|
@ -142,7 +151,7 @@ static void click(MwWidget handle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.y += rc.height + 5;
|
rc.y += rc.height + 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -159,6 +168,23 @@ MwClass MwSubMenuClass = &MwSubMenuClassRec;
|
||||||
void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
|
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;
|
||||||
|
|
||||||
|
SetWindowLongPtr(handle->lowlevel->hWnd, GWL_STYLE, (LONG_PTR)WS_POPUP);
|
||||||
|
|
||||||
|
GetWindowRect(handle->parent->lowlevel->hWnd, &rc);
|
||||||
|
|
||||||
|
SetParent(handle->lowlevel->hWnd, NULL);
|
||||||
|
|
||||||
|
rc.left += point->x;
|
||||||
|
rc.top += point->y;
|
||||||
|
|
||||||
|
SetWindowPos(handle->lowlevel->hWnd, NULL, rc.left, rc.top, 1, 1, SWP_NOREDRAW);
|
||||||
|
|
||||||
|
ShowWindow(handle->lowlevel->hWnd, SW_NORMAL);
|
||||||
|
UpdateWindow(handle->lowlevel->hWnd);
|
||||||
|
|
||||||
|
SetFocus(handle->lowlevel->hWnd);
|
||||||
#else
|
#else
|
||||||
Atom wndtype = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE", False);
|
Atom wndtype = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE", False);
|
||||||
Atom wndmenu = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE_MENU", False);
|
Atom wndmenu = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE_MENU", False);
|
||||||
|
|
@ -183,14 +209,14 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
|
||||||
|
|
||||||
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) + 5;
|
h += MwTextHeight(handle, menu->sub[i]->name) + 3;
|
||||||
if(tw > w) {
|
if(tw > w) {
|
||||||
w = tw;
|
w = tw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w += 10 + 15;
|
w += 10 + 15;
|
||||||
h += 5;
|
h += 3;
|
||||||
|
|
||||||
MwVaApply(handle,
|
MwVaApply(handle,
|
||||||
MwNwidth, w,
|
MwNwidth, w,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue