git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@758 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-19 14:06:56 +00:00
parent d24a255297
commit 2ed6053819
5 changed files with 114 additions and 72 deletions

View File

@@ -151,6 +151,8 @@ struct _MwTreeView {
MwWidget vscroll;
int changed;
MwTreeViewEntry* tree;
MwPoint pressed;
};
struct _MwDirectoryEntry {

View File

@@ -48,7 +48,7 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi
sh.min_width = sh.max_width = w;
sh.min_height = sh.max_height = h;
window = MwVaCreateWidget(MwWindowClass, "messagebox", window, wx, wy, w, h,
window = MwVaCreateWidget(MwWindowClass, "messagebox", NULL, wx, wy, w, h,
MwNtitle, title,
MwNsizeHints, &sh,
NULL);

View File

@@ -212,6 +212,7 @@ static void mouse_down(MwWidget handle, void* ptr) {
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNminValue) == 0 || strcmp(key, MwNvalue) == 0 || strcmp(key, MwNmaxValue) == 0 || strcmp(key, MwNareaShown) == 0) {
if(MwGetInteger(handle, MwNvalue) > MwGetInteger(handle, MwNmaxValue)) MwSetInteger(handle, MwNvalue, MwGetInteger(handle, MwNmaxValue));
if(handle->prop_event) MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
MwForceRender(handle);
}

View File

@@ -15,7 +15,7 @@ static void vscroll_changed(MwWidget handle, void* user, void* call) {
tv->changed = 1;
}
static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwLLColor base, MwLLColor text, MwPoint* p, int next, int shift, int* skip, int* shared){
static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwLLColor base, MwLLColor text, MwPoint* p, int next, int shift, int* skip, int* shared, int draw, MwPoint* mouse) {
int i;
MwPoint l[2];
int skipped = 0;
@@ -32,7 +32,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwLLColor base, Mw
l[0] = *p;
l[0].x -= LineSpace / 2;
l[1] = *p;
MwLLLine(handle->lowlevel, &l[0], text);
if(draw) MwLLLine(handle->lowlevel, &l[0], text);
l[0] = *p;
l[0].x -= LineSpace / 2;
@@ -41,14 +41,20 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwLLColor base, Mw
if(next) {
l[1].y += MwTextHeight(handle, "M") / 2;
}
MwLLLine(handle->lowlevel, &l[0], text);
if(draw) MwLLLine(handle->lowlevel, &l[0], text);
}
if(tree->tree != NULL) {
r.width = OpenerSize;
r.height = OpenerSize;
r.x = p->x - LineSpace + (LineSpace - r.width) / 2;
r.y = p->y - MwTextHeight(handle, "M") / 2 + (MwTextHeight(handle, "M") - r.height) / 2;
if(draw) {
MwDrawWidgetBack(handle, &r, base, tree->opened, 1);
} else if(shift != 0) {
if(r.x <= mouse->x && mouse->x <= (r.x + r.width) && r.y <= mouse->y && mouse->y <= (r.y + r.height)) {
tree->opened = tree->opened ? 0 : 1;
}
}
}
if(tree->pixmap != NULL) {
@@ -57,10 +63,10 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwLLColor base, Mw
r.x = p->x;
r.y = p->y - MwTextHeight(handle, "M") / 2;
MwLLDrawPixmap(handle->lowlevel, &r, tree->pixmap);
if(draw) MwLLDrawPixmap(handle->lowlevel, &r, tree->pixmap);
}
p->x += MwGetInteger(handle->parent, MwNleftPadding);
MwDrawText(handle, p, tree->label, 0, MwALIGNMENT_BEGINNING, text);
if(draw) MwDrawText(handle, p, tree->label, 0, MwALIGNMENT_BEGINNING, text);
p->x -= MwGetInteger(handle->parent, MwNleftPadding);
p->y += MwTextHeight(handle, "M") / 2;
@@ -74,7 +80,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwLLColor base, Mw
l[0].x += shift + LineSpace / 2;
l[0].y += MwTextHeight(handle, "M") - (MwTextHeight(handle, "M") - OpenerSize) / 2;
recursion(handle, &tree->tree[i], base, text, p, i != (arrlen(tree->tree) - 1) ? 1 : 0, shift + LineSpace, skip, shared);
recursion(handle, &tree->tree[i], base, text, p, i != (arrlen(tree->tree) - 1) ? 1 : 0, shift + LineSpace, skip, shared, draw, mouse);
l[1] = *p;
l[1].x += shift + LineSpace / 2;
@@ -82,8 +88,7 @@ static void recursion(MwWidget handle, MwTreeViewEntry* tree, MwLLColor base, Mw
if(skipped && p->y > l[0].y) {
skipped = 0;
}
if(!skipped && i != (arrlen(tree->tree) - 1)) MwLLLine(handle->lowlevel, &l[0], text);
if(draw && !skipped && i != (arrlen(tree->tree) - 1)) MwLLLine(handle->lowlevel, &l[0], text);
}
}
@@ -107,7 +112,7 @@ static void frame_draw(MwWidget handle) {
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (r.height / MwTextHeight(handle, "M"))) break;
recursion(handle, &tv->tree[i], base, text, &p, 0, 0, &skip, &shared);
recursion(handle, &tv->tree[i], base, text, &p, 0, 0, &skip, &shared, 1, NULL);
}
MwDrawFrame(handle, &r, base, 1);
@@ -126,6 +131,38 @@ static int recursive_length(MwTreeViewEntry* e){
return l;
}
static void frame_mouse_down(MwWidget handle, void* user, void* call) {
MwTreeView tv = handle->parent->internal;
MwLLMouse* mouse = call;
(void)user;
if(mouse->button == MwLLMouseLeft) tv->pressed = mouse->point;
}
static void resize(MwWidget handle);
static void frame_mouse_up(MwWidget handle, void* user, void* call) {
MwTreeView tv = handle->parent->internal;
int shared = 0;
int skip = MwGetInteger(tv->vscroll, MwNvalue) * (MwGetInteger(tv->vscroll, MwNmaxValue) - MwGetInteger(tv->vscroll, MwNareaShown)) / MwGetInteger(tv->vscroll, MwNmaxValue);
MwPoint p;
MwLLMouse* mouse = call;
(void)user;
if(mouse->button == MwLLMouseLeft) {
int i;
p.x = MwDefaultBorderWidth(tv->frame);
p.y = MwDefaultBorderWidth(tv->frame);
for(i = 0; i < arrlen(tv->tree); i++) {
if(shared > (MwGetInteger(tv->frame, MwNheight) / MwTextHeight(tv->frame, "M"))) break;
recursion(tv->frame, &tv->tree[i], NULL, NULL, &p, 0, 0, &skip, &shared, 0, &tv->pressed);
}
resize(handle->parent);
}
}
static void resize(MwWidget handle) {
MwTreeView tv = handle->internal;
int w = MwGetInteger(handle, MwNwidth);
@@ -135,7 +172,7 @@ static void resize(MwWidget handle) {
if(tv->vscroll == NULL) {
tv->vscroll = MwCreateWidget(MwScrollBarClass, "vscroll", handle, w - 16, 0, 16, h);
MwAddUserHandler(tv->vscroll, MwNchangedHandler, vscroll_changed, NULL);
MwSetInteger(tv->vscroll, MwNvalue, 7);
MwSetInteger(tv->vscroll, MwNvalue, 5);
} else {
MwVaApply(tv->vscroll,
MwNx, w - 16,
@@ -151,6 +188,8 @@ static void resize(MwWidget handle) {
MwNinverted, 1,
NULL);
tv->frame->draw_inject = frame_draw;
MwAddUserHandler(tv->frame, MwNmouseDownHandler, frame_mouse_down, NULL);
MwAddUserHandler(tv->frame, MwNmouseUpHandler, frame_mouse_up, NULL);
} else {
MwVaApply(tv->frame,
MwNx, 0,