This commit is contained in:
parent
39b3c035fc
commit
147124d408
5 changed files with 105 additions and 29 deletions
|
|
@ -1,10 +1,10 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget cpicker;
|
||||
MwWidget fpicker;
|
||||
MwWidget window;
|
||||
MwWidget button;
|
||||
|
||||
void MWAPI color_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
void MWAPI file_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
char hexColor[8];
|
||||
MwRGB* rgb = call_data;
|
||||
|
||||
|
|
@ -18,14 +18,14 @@ void MWAPI color_callback(MwWidget handle, void* user_data, void* call_data) {
|
|||
MwSetText(window, MwNbackground, hexColor);
|
||||
}
|
||||
|
||||
void MWAPI color_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
void MWAPI file_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
MwWidget cpicker = MwColorPicker(window, "cpicker");
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwAddUserHandler(cpicker, MwNcolorChosenHandler, color_callback, NULL);
|
||||
MwAddUserHandler(cpicker, MwNcolorChosenHandler, file_callback, NULL);
|
||||
|
||||
MwSetText(cpicker, MwNbackground, MwGetInteger(cpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ int main() {
|
|||
NULL);
|
||||
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
MwAddUserHandler(button, MwNactivateHandler, color_picker, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, file_picker, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
|
|||
70
examples/basic/filechooser.c
Normal file
70
examples/basic/filechooser.c
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget fpicker;
|
||||
MwWidget window;
|
||||
MwWidget button;
|
||||
MwWidget mb;
|
||||
|
||||
MwBool fpicker_wait = MwFALSE;
|
||||
MwBool msgbox_wait = MwFALSE;
|
||||
|
||||
void MWAPI ok(MwWidget handle, void* user, void* call) {
|
||||
(void)handle;
|
||||
(void)call;
|
||||
msgbox_wait = MwFALSE;
|
||||
}
|
||||
|
||||
void MWAPI file_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
mb = MwMessageBox(handle, call_data, "File chosen", MwMB_ICONERROR | MwMB_BUTTONOK);
|
||||
|
||||
(void)user_data;
|
||||
|
||||
MwAddUserHandler(MwMessageBoxGetChild(mb, MwMB_BUTTONOK), MwNactivateHandler, ok, mb);
|
||||
MwAddUserHandler(mb, MwNcloseHandler, ok, mb);
|
||||
|
||||
msgbox_wait = MwTRUE;
|
||||
|
||||
while(msgbox_wait) {
|
||||
MwStep(mb);
|
||||
}
|
||||
|
||||
fpicker_wait = MwFALSE;
|
||||
}
|
||||
|
||||
void MWAPI file_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
fpicker = MwFileChooserEx(handle, "file chooser", 0);
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwAddUserHandler(fpicker, MwNfileChosenHandler, file_callback, NULL);
|
||||
|
||||
MwSetText(fpicker, MwNbackground, MwGetInteger(fpicker, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
||||
|
||||
fpicker_wait = MwTRUE;
|
||||
|
||||
while(fpicker_wait) {
|
||||
MwStep(fpicker);
|
||||
}
|
||||
|
||||
MwDestroyWidget(fpicker);
|
||||
MwDestroyWidget(mb);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MwLibraryInit();
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
||||
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
||||
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
||||
MwNtext, "select file",
|
||||
NULL);
|
||||
MwSetText(button, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
||||
|
||||
MwAddUserHandler(button, MwNactivateHandler, file_picker, NULL);
|
||||
|
||||
MwLoop(window);
|
||||
}
|
||||
|
|
@ -191,6 +191,7 @@ new_example("examples/basic/box");
|
|||
new_example("examples/basic/clipboard");
|
||||
new_example("examples/basic/sevensegment");
|
||||
new_example("examples/basic/calculator");
|
||||
new_example("examples/basic/filechooser");
|
||||
new_example("examples/basic/periodic");
|
||||
|
||||
if (param_get("opengl")) {
|
||||
|
|
|
|||
|
|
@ -2498,6 +2498,7 @@ static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
|
|||
struct xdg_toplevel_icon_v1* icon = xdg_toplevel_icon_manager_v1_create_icon(icon_manager);
|
||||
MwU64 size = pixmap->common.width * pixmap->common.height * 4;
|
||||
int i = 0;
|
||||
int line = (pixmap->common.width < pixmap->common.height) ? pixmap->common.height : pixmap->common.width;
|
||||
|
||||
if(handle->wayland.icon == NULL) {
|
||||
handle->wayland.icon = malloc(sizeof(struct _MwLLWaylandShmBuffer));
|
||||
|
|
@ -2511,7 +2512,7 @@ static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
|
|||
}
|
||||
handle->wayland.icon->surface = wl_compositor_create_surface(handle->wayland.compositor);
|
||||
|
||||
buffer_setup(handle->wayland.icon, pixmap->common.width, pixmap->common.height);
|
||||
buffer_setup(handle->wayland.icon, line, line);
|
||||
|
||||
wl_surface_attach(handle->wayland.icon->surface, handle->wayland.icon->shm_buffer, 0, 0);
|
||||
wl_surface_commit(handle->wayland.icon->surface);
|
||||
|
|
|
|||
|
|
@ -504,32 +504,12 @@ static void scan(MwWidget handle, const char* path, int record) {
|
|||
}
|
||||
}
|
||||
|
||||
MwWidget MwFileChooserEx(MwWidget handle, const char* title, int dir) {
|
||||
MwWidget window;
|
||||
int w, h;
|
||||
filechooser_t* fc = malloc(sizeof(*fc));
|
||||
static void setup_fallback_filechooser(MwWidget window, int dir) {
|
||||
char* path;
|
||||
MwLLPixmap icon;
|
||||
int wx;
|
||||
int wy;
|
||||
|
||||
filechooser_t* fc = malloc(sizeof(*fc));
|
||||
memset(fc, 0, sizeof(*fc));
|
||||
|
||||
w = 700;
|
||||
h = w * 2 / 3;
|
||||
|
||||
if(handle == NULL) {
|
||||
wx = wy = MwDEFAULT;
|
||||
} else {
|
||||
wx = MwGetInteger(handle, MwNx) + (MwGetInteger(handle, MwNwidth) - w) / 2;
|
||||
wy = MwGetInteger(handle, MwNy) + (MwGetInteger(handle, MwNheight) - h) / 2;
|
||||
}
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "filechooser", NULL, wx, wy, w, h,
|
||||
MwNtitle, title,
|
||||
NULL);
|
||||
if(handle != NULL) MwReparent(window, handle);
|
||||
|
||||
fc->history_seek = 0;
|
||||
|
||||
fc->dir = MwLoadIcon(window, MwIconDirectory);
|
||||
|
|
@ -558,8 +538,32 @@ MwWidget MwFileChooserEx(MwWidget handle, const char* title, int dir) {
|
|||
free(path);
|
||||
|
||||
MwLLBeginStateChange(window->lowlevel);
|
||||
MwLLMakePopup(window->lowlevel, handle == NULL ? NULL : handle->lowlevel);
|
||||
MwLLMakePopup(window->lowlevel, window == NULL ? NULL : window->lowlevel);
|
||||
MwLLEndStateChange(window->lowlevel);
|
||||
}
|
||||
|
||||
MwWidget MwFileChooserEx(MwWidget handle, const char* title, int dir) {
|
||||
MwWidget window;
|
||||
int w, h;
|
||||
int wx;
|
||||
int wy;
|
||||
|
||||
w = 700;
|
||||
h = w * 2 / 3;
|
||||
|
||||
if(handle == NULL) {
|
||||
wx = wy = MwDEFAULT;
|
||||
} else {
|
||||
wx = MwGetInteger(handle, MwNx) + (MwGetInteger(handle, MwNwidth) - w) / 2;
|
||||
wy = MwGetInteger(handle, MwNy) + (MwGetInteger(handle, MwNheight) - h) / 2;
|
||||
}
|
||||
|
||||
window = MwVaCreateWidget(MwWindowClass, "filechooser", NULL, wx, wy, w, h,
|
||||
MwNtitle, title,
|
||||
NULL);
|
||||
if(handle != NULL) MwReparent(window, handle);
|
||||
|
||||
setup_fallback_filechooser(window, dir);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue