git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@403 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
Nishi 2025-10-17 19:44:55 +00:00
commit b608931b21
10 changed files with 79 additions and 80 deletions

View file

@ -7,6 +7,7 @@
#define __MW_STRING_H__ #define __MW_STRING_H__
#include <Mw/MachDep.h> #include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -27,6 +28,20 @@ MWDECL char* MwStringDupliacte(const char* str);
*/ */
MWDECL char* MwStringConcat(const char* str1, const char* str2); MWDECL char* MwStringConcat(const char* str1, const char* str2);
/*!
* %brief Converts size to string
* %param out Output
* %param size Size
*/
MWDECL void MwStringSize(char* out, MwOffset size);
/*!
* %brief Converts time to string
* %param out Output
* %param t Time
*/
MWDECL void MwStringTime(char* out, time_t t);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -157,6 +157,7 @@ struct _MwDirectoryEntry {
char* name; char* name;
int type; int type;
MwOffset size; MwOffset size;
time_t mtime;
}; };
#define MwCursorDataHeight 16 #define MwCursorDataHeight 16

View file

@ -91,7 +91,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
p.x = LOWORD(lp); p.x = LOWORD(lp);
p.y = HIWORD(lp); p.y = HIWORD(lp);
if(u->ll->grabbed){ if(u->ll->grabbed) {
RECT rc; RECT rc;
GetClientRect(hWnd, &rc); GetClientRect(hWnd, &rc);
@ -101,7 +101,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
MwLLDispatch(u->ll, move, &p); MwLLDispatch(u->ll, move, &p);
if(u->ll->grabbed && (p.x != 0 || p.y != 0)){ if(u->ll->grabbed && (p.x != 0 || p.y != 0)) {
RECT rc; RECT rc;
POINT p; POINT p;
@ -130,9 +130,9 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
int n = wp; int n = wp;
MwLLDispatch(u->ll, key, &n); MwLLDispatch(u->ll, key, &n);
}else if(msg == WM_SETFOCUS){ } else if(msg == WM_SETFOCUS) {
MwLLDispatch(u->ll, focus_in, NULL); MwLLDispatch(u->ll, focus_in, NULL);
}else if(msg == WM_KILLFOCUS){ } else if(msg == WM_KILLFOCUS) {
MwLLDispatch(u->ll, focus_out, NULL); MwLLDispatch(u->ll, focus_out, NULL);
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP) { } else if(msg == WM_KEYDOWN || msg == WM_KEYUP) {
int n = -1; int n = -1;
@ -589,12 +589,12 @@ long MwLLGetTick(void) {
return GetTickCount(); return GetTickCount();
} }
void MwLLFocus(MwLL handle){ void MwLLFocus(MwLL handle) {
SetFocus(handle->hWnd); SetFocus(handle->hWnd);
} }
void MwLLGrabPointer(MwLL handle, int toggle){ void MwLLGrabPointer(MwLL handle, int toggle) {
if(toggle){ if(toggle) {
POINT p; POINT p;
RECT rc; RECT rc;
@ -616,7 +616,7 @@ void MwLLGrabPointer(MwLL handle, int toggle){
ClipCursor(&rc); ClipCursor(&rc);
SetCursorPos(p.x, p.y); SetCursorPos(p.x, p.y);
}else{ } else {
handle->grabbed = 0; handle->grabbed = 0;
ClipCursor(NULL); ClipCursor(NULL);
} }

View file

@ -286,9 +286,9 @@ void MwLLNextEvent(MwLL handle) {
if(ev.xclient.data.l[0] == (long)handle->wm_delete) { if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
MwLLDispatch(handle, close, NULL); MwLLDispatch(handle, close, NULL);
} }
} else if(ev.type == FocusIn){ } else if(ev.type == FocusIn) {
MwLLDispatch(handle, focus_in, NULL); MwLLDispatch(handle, focus_in, NULL);
} else if(ev.type == FocusOut){ } else if(ev.type == FocusOut) {
MwLLDispatch(handle, focus_out, NULL); MwLLDispatch(handle, focus_out, NULL);
} else if(ev.type == MotionNotify) { } else if(ev.type == MotionNotify) {
MwPoint p; MwPoint p;
@ -299,13 +299,13 @@ void MwLLNextEvent(MwLL handle) {
p.x = ev.xmotion.x; p.x = ev.xmotion.x;
p.y = ev.xmotion.y; p.y = ev.xmotion.y;
if(handle->grabbed){ if(handle->grabbed) {
p.x -= attr.width / 2; p.x -= attr.width / 2;
p.y -= attr.height / 2; p.y -= attr.height / 2;
} }
MwLLDispatch(handle, move, &p); MwLLDispatch(handle, move, &p);
if(handle->grabbed && (p.x != 0 || p.y != 0)){ if(handle->grabbed && (p.x != 0 || p.y != 0)) {
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2); XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
} }
} else if(ev.type == KeyPress || ev.type == KeyRelease) { } else if(ev.type == KeyPress || ev.type == KeyRelease) {
@ -343,13 +343,13 @@ void MwLLNextEvent(MwLL handle) {
n = MwLLKeyUp; n = MwLLKeyUp;
} else if(strcmp(str, "Down") == 0) { } else if(strcmp(str, "Down") == 0) {
n = MwLLKeyDown; n = MwLLKeyDown;
} else if(strcmp(str, "Return") == 0){ } else if(strcmp(str, "Return") == 0) {
n = MwLLKeyEnter; n = MwLLKeyEnter;
} else if(strcmp(str, "Escape") == 0){ } else if(strcmp(str, "Escape") == 0) {
n = MwLLKeyEscape; n = MwLLKeyEscape;
}else if(strcmp(str, "Shift_L") == 0){ } else if(strcmp(str, "Shift_L") == 0) {
n = MwLLKeyLeftShift; n = MwLLKeyLeftShift;
}else if(strcmp(str, "Shift_R") == 0){ } else if(strcmp(str, "Shift_R") == 0) {
n = MwLLKeyRightShift; n = MwLLKeyRightShift;
} }
@ -690,20 +690,20 @@ long MwLLGetTick(void) {
return n; return n;
} }
void MwLLFocus(MwLL handle){ void MwLLFocus(MwLL handle) {
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime); XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
} }
void MwLLGrabPointer(MwLL handle, int toggle){ void MwLLGrabPointer(MwLL handle, int toggle) {
XWindowAttributes attr; XWindowAttributes attr;
XGetWindowAttributes(handle->display, handle->window, &attr); XGetWindowAttributes(handle->display, handle->window, &attr);
if(toggle){ if(toggle) {
handle->grabbed = 1; handle->grabbed = 1;
XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2); XWarpPointer(handle->display, None, handle->window, 0, 0, 0, 0, attr.width / 2, attr.height / 2);
}else{ } else {
handle->grabbed = 0; handle->grabbed = 0;
} }
} }

View file

@ -414,7 +414,7 @@ void MwSetDefault(MwWidget handle) {
inherit_text(handle, MwNforeground, MwDefaultForeground); inherit_text(handle, MwNforeground, MwDefaultForeground);
} }
void MwHideCursor(MwWidget handle){ void MwHideCursor(MwWidget handle) {
MwLLSetCursor(handle->lowlevel, &MwCursorHidden, &MwCursorHiddenMask); MwLLSetCursor(handle->lowlevel, &MwCursorHidden, &MwCursorHiddenMask);
} }
@ -478,10 +478,11 @@ void MwAddTickList(MwWidget handle) {
arrput(root->tick_list, handle); arrput(root->tick_list, handle);
} }
void MwFocus(MwWidget handle){ void MwFocus(MwWidget handle) {
MwLLFocus(handle->lowlevel); MwLLFocus(handle->lowlevel);
} }
void MwGrabPointer(MwWidget handle, int toggle){ void MwGrabPointer(MwWidget handle, int toggle) {
if(toggle) MwFocus(handle);
MwLLGrabPointer(handle->lowlevel, toggle); MwLLGrabPointer(handle->lowlevel, toggle);
} }

View file

@ -1,40 +1,6 @@
/* $Id$ */ /* $Id$ */
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
MwCursor MwCursorHidden = { MwCursor MwCursorHidden = {
1, 1, 0, -1, { 1, 1, 0, -1, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}};
MwCursor MwCursorHiddenMask = { MwCursor MwCursorHiddenMask = {
1, 1, 0, -1, { 1, 1, 0, -1, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}};

View file

@ -99,6 +99,7 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) {
entry->type = MwDIRECTORY_FILE; entry->type = MwDIRECTORY_FILE;
} }
entry->size = s.st_size; entry->size = s.st_size;
entry->mtime = s.st_mtime;
free(p); free(p);
#endif #endif

View file

@ -43,7 +43,7 @@ static void cancel(MwWidget handle, void* user, void* call) {
destroy(handle->parent); destroy(handle->parent);
} }
static void cancel_window(MwWidget handle, void* user, void* call){ static void cancel_window(MwWidget handle, void* user, void* call) {
(void)user; (void)user;
(void)call; (void)call;
@ -284,8 +284,12 @@ static void scan(MwWidget handle, const char* path) {
for(i = 0; i < arrlen(entries); i++) { for(i = 0; i < arrlen(entries); i++) {
if(strcmp(entries[i]->name, ".") == 0 || strcmp(entries[i]->name, "..") == 0) continue; if(strcmp(entries[i]->name, ".") == 0 || strcmp(entries[i]->name, "..") == 0) continue;
if(entries[i]->type == MwDIRECTORY_DIRECTORY) { if(entries[i]->type == MwDIRECTORY_DIRECTORY) {
char* date = malloc(128);
MwStringTime(date, entries[i]->mtime);
arrput(names, entries[i]->name); arrput(names, entries[i]->name);
arrput(dates, NULL); arrput(dates, date);
arrput(sizes, NULL); arrput(sizes, NULL);
arrput(icons, fc->dir); arrput(icons, fc->dir);
} }
@ -295,18 +299,8 @@ static void scan(MwWidget handle, const char* path) {
char* date = malloc(128); char* date = malloc(128);
char* size = malloc(128); char* size = malloc(128);
memset(date, 0, 128); MwStringTime(date, entries[i]->mtime);
memset(size, 0, 128); MwStringSize(size, entries[i]->size);
if(entries[i]->size / 1024 == 0) {
sprintf(size, "%d", (int)entries[i]->size);
} else if(entries[i]->size / 1024 / 1024 == 0) {
sprintf(size, "%.1fK", (double)entries[i]->size / 1024);
} else if(entries[i]->size / 1024 / 1024 / 1024 == 0) {
sprintf(size, "%.1fM", (double)entries[i]->size / 1024 / 1024);
} else {
sprintf(size, "%.1fG", (double)entries[i]->size / 1024 / 1024 / 1024);
}
arrput(names, entries[i]->name); arrput(names, entries[i]->name);
arrput(dates, date); arrput(dates, date);

View file

@ -15,3 +15,22 @@ char* MwStringConcat(const char* str1, const char* str2) {
return r; return r;
} }
void MwStringSize(char* out, MwOffset size) {
if(size / 1024 == 0) {
sprintf(out, "%d", (int)size);
} else if(size / 1024 / 1024 == 0) {
sprintf(out, "%.1fK", (double)size / 1024);
} else if(size / 1024 / 1024 / 1024 == 0) {
sprintf(out, "%.1fM", (double)size / 1024 / 1024);
} else {
sprintf(out, "%.1fG", (double)size / 1024 / 1024 / 1024);
}
}
void MwStringTime(char* out, time_t t) {
struct tm* tm = localtime(&t);
const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
sprintf(out, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year);
}

View file

@ -171,6 +171,8 @@ static void frame_draw(MwWidget handle) {
p.x += MwDefaultBorderWidth; p.x += MwDefaultBorderWidth;
MwDrawText(handle, &p, lb->list[i].name[j], 0, MwALIGNMENT_BEGINNING, selected ? base : text); MwDrawText(handle, &p, lb->list[i].name[j], 0, MwALIGNMENT_BEGINNING, selected ? base : text);
p.x += get_col_width(lb, j) - MwDefaultBorderWidth; p.x += get_col_width(lb, j) - MwDefaultBorderWidth;
if(j == 0) p.x -= MwGetInteger(handle->parent, MwNleftPadding);
} }
p.y += MwTextHeight(handle, "M") / 2; p.y += MwTextHeight(handle, "M") / 2;
} }