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

View File

@@ -7,6 +7,7 @@
#define __MW_STRING_H__
#include <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#ifdef __cplusplus
extern "C" {
@@ -27,6 +28,20 @@ MWDECL char* MwStringDupliacte(const char* str);
*/
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
}
#endif

View File

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

View File

@@ -483,5 +483,6 @@ void MwFocus(MwWidget handle){
}
void MwGrabPointer(MwWidget handle, int toggle) {
if(toggle) MwFocus(handle);
MwLLGrabPointer(handle->lowlevel, toggle);
}

View File

@@ -1,40 +1,6 @@
/* $Id$ */
#include <Mw/Milsko.h>
MwCursor MwCursorHidden = {
1, 1, 0, -1, {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}};
1, 1, 0, -1, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
MwCursor MwCursorHiddenMask = {
1, 1, 0, -1, {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
}};
1, 1, 0, -1, {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->size = s.st_size;
entry->mtime = s.st_mtime;
free(p);
#endif

View File

@@ -284,8 +284,12 @@ static void scan(MwWidget handle, const char* path) {
for(i = 0; i < arrlen(entries); i++) {
if(strcmp(entries[i]->name, ".") == 0 || strcmp(entries[i]->name, "..") == 0) continue;
if(entries[i]->type == MwDIRECTORY_DIRECTORY) {
char* date = malloc(128);
MwStringTime(date, entries[i]->mtime);
arrput(names, entries[i]->name);
arrput(dates, NULL);
arrput(dates, date);
arrput(sizes, NULL);
arrput(icons, fc->dir);
}
@@ -295,18 +299,8 @@ static void scan(MwWidget handle, const char* path) {
char* date = malloc(128);
char* size = malloc(128);
memset(date, 0, 128);
memset(size, 0, 128);
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);
}
MwStringTime(date, entries[i]->mtime);
MwStringSize(size, entries[i]->size);
arrput(names, entries[i]->name);
arrput(dates, date);

View File

@@ -15,3 +15,22 @@ char* MwStringConcat(const char* str1, const char* str2) {
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;
MwDrawText(handle, &p, lb->list[i].name[j], 0, MwALIGNMENT_BEGINNING, selected ? base : text);
p.x += get_col_width(lb, j) - MwDefaultBorderWidth;
if(j == 0) p.x -= MwGetInteger(handle->parent, MwNleftPadding);
}
p.y += MwTextHeight(handle, "M") / 2;
}