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

@ -483,5 +483,6 @@ void MwFocus(MwWidget handle){
} }
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

@ -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;
} }