Use Native Dialog and fix filter for windows

This commit is contained in:
daleclack 2021-06-27 16:14:08 +08:00
parent 3cae17cf8d
commit cde3346f99
3 changed files with 118 additions and 8 deletions

View File

@ -21,10 +21,12 @@
"/usr/include/uuid/**",
*/
//For manjaro(Arch linux)
"/usr/lib/dbus-1.0/include/**",
"/usr/lib/glib-2.0/include/**",
"/usr/include/lzo/**",
"/usr/include/cloudproviders/**",
"${workspaceFolder}/**",
"/usr/include/gtk-3.0/**",
"/usr/include/at-spi2-atk/2.0/**",
@ -48,11 +50,83 @@
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-arm64",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [
"`pkg-config --cflags --libs gtk+-3.0`"
],
"configurationProvider": "ms-vscode.cmake-tools"
},
{
"name": "win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/src/**",
//I assume the msys2 installed in D:/msys64
"D:/msys64/mingw64/include/**",
"D:/msys64/mingw64/include/glib-2.0/**",
"D:/msys64/mingw64/lib/glib-2.0/include/**",
"D:/msys64/mingw64/include/gtk-3.0/**",
"D:/msys64/mingw64/include/pango-1.0/**",
"D:/msys64/mingw64/include/harfbuzz/**",
"D:/msys64/mingw64/include/freetype2/**",
"D:/msys64/mingw64/include/libpng16/**",
"D:/msys64/mingw64/include/fribidi/**",
"D:/msys64/mingw64/include/cairo/**",
"D:/msys64/mingw64/include/lzo/**",
"D:/msys64/mingw64/include/pixman-1/**",
"D:/msys64/mingw64/include/gdk-pixbuf-2.0",
"D:/msys64/mingw64/include/atk-1.0"
],
"defines": [],
"compilerPath": "D:/msys64/MinGW64/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
},
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/Cellar/libffi/3.3_3/include/**",
"/usr/local/Cellar/gtk+3/3.24.29/include/gtk-3.0/**",
"/usr/local/Cellar/glib/2.68.2/include/gio-unix-2.0/**",
"/usr/local/Cellar/cairo/1.16.0_5/include/cairo/**",
"/usr/local/Cellar/libepoxy/1.5.7/include/**",
"/usr/local/Cellar/pango/1.48.4/include/pango-1.0",
"/usr/local/Cellar/harfbuzz/2.8.1/include/harfbuzz",
"/usr/local/Cellar/pango/1.48.4/include/pango-1.0/**",
"/usr/local/Cellar/fribidi/1.0.10/include/fribidi/**",
"/usr/local/Cellar/harfbuzz/2.8.1/include/harfbuzz/**",
"/usr/local/Cellar/graphite2/1.3.14/include/**",
"/usr/local/Cellar/atk/2.36.0/include/atk-1.0/**",
"/usr/local/Cellar/cairo/1.16.0_5/include/cairo/**",
"/usr/local/Cellar/pixman/0.40.0/include/pixman-1/**",
"/usr/local/Cellar/fontconfig/2.13.1/include/**",
"/usr/local/opt/freetype/include/freetype2/**",
"/usr/local/Cellar/libpng/1.6.37/include/libpng16/**",
"/usr/local/Cellar/libxcb/1.14_1/include/**",
"/usr/local/Cellar/libxrender/0.9.10/include/**",
"/usr/local/Cellar/libxext/1.3.4/include/**",
"/usr/local/Cellar/libx11/1.7.0/include/**",
"/usr/local/Cellar/libxcb/1.14_1/include/**",
"/usr/local/Cellar/libxau/1.0.9/include/**",
"/usr/local/Cellar/libxdmcp/1.1.3/include/**",
"/usr/local/Cellar/gdk-pixbuf/2.42.6/include/gdk-pixbuf-2.0/**",
"/usr/local/Cellar/libpng/1.6.37/include/libpng16/**",
"/usr/local/Cellar/libtiff/4.3.0/include/**",
"/usr/local/Cellar/glib/2.68.2/include/**",
"/usr/local/Cellar/glib/2.68.2/include/glib-2.0/**",
"/usr/local/Cellar/glib/2.68.2/lib/glib-2.0/include/**",
"/usr/local/opt/gettext/include/**",
"/usr/local/Cellar/pcre/8.44/include/**",
"/usr/local/Cellar/xorgproto/2021.4/include/**"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-11",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4

View File

@ -16,5 +16,10 @@ include_directories (${GTK3_INCLUDE_DIRS})
link_directories (${GTK3_LIBRARY_DIRS})
add_executable(My_GtkUi src/main.cpp src/background.cpp src/game.cpp src/TextEditor.cpp
src/panel1.cpp src/panel2.cpp src/win1.cpp src/winconf.cpp src/resources.cpp)
IF(WIN32)
SET(CMAKE_EXE_LINKER_FLAGS -mwindows)
ENDIF(WIN32)
add_definitions (${GTK3_CFLAGS_OTHER})
target_link_libraries (${PROJECT_NAME} ${GTK3_LIBRARIES} -lpthread -lm)

View File

@ -2,7 +2,7 @@
#include "winconf.h"
#include "winpe.xpm"
static void dialog_response(GtkWidget *widget,int response,GtkBuilder *builder){
static void dialog_response(GtkNativeDialog *widget,int response,GtkBuilder *builder){
//Handle file chooser response and set background
int width=640,height=360;
get_config(&width,&height);
@ -10,7 +10,7 @@ static void dialog_response(GtkWidget *widget,int response,GtkBuilder *builder){
const gchar *filename;
GFile *file;
//g_print("%s\n",filename);
if(response==GTK_RESPONSE_OK){
if(response==GTK_RESPONSE_ACCEPT){
file=gtk_file_chooser_get_file(GTK_FILE_CHOOSER(widget));
filename=g_file_get_path(file);
GdkPixbuf *pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
@ -19,27 +19,58 @@ static void dialog_response(GtkWidget *widget,int response,GtkBuilder *builder){
g_object_unref(pixbuf);
g_object_unref(sized);
}
gtk_widget_destroy(widget);
//gtk_widget_destroy(widget);
gtk_native_dialog_destroy(widget);
}
static const char * const supported_globs[]={
"*.jpg",
"*.jpeg",
"*.png",
"*.bmp",
"*.xpm",
NULL
};
void fileopen(GtkWidget *widget,GtkBuilder *builder){
GObject *parent=gtk_builder_get_object(builder,"window");
//Change background
GtkWidget *dialog;
GtkFileChooserNative *dialog;
GtkFileChooserAction action=GTK_FILE_CHOOSER_ACTION_OPEN;
dialog=gtk_file_chooser_dialog_new("Choose a image File",GTK_WINDOW(parent),action,
"OK",GTK_RESPONSE_OK,"Cancel",GTK_RESPONSE_CANCEL,NULL);
dialog=gtk_file_chooser_native_new("Choose a Image file",GTK_WINDOW(parent),action,"OK","Cancel");
//Use GtkFileFilter to select image file
GtkFileFilter *filter=gtk_file_filter_new();
gtk_file_filter_set_name(filter,"Image Files");
/*
Microsoft Windows doesn't support mine types,
For Microsoft Windows,I use a list to store image extenstions;
And For Linux,just use the image/* mime type
*/
#ifdef G_OS_WIN32
int i;
for (i = 0; supported_globs != NULL && supported_globs[i] != NULL; i++)
{
const char *glob = supported_globs[i];
gtk_file_filter_add_pattern (filter, glob);
}
#else
gtk_file_filter_add_mime_type(filter,"image/*");
#endif
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
//Filter For All Files
filter=gtk_file_filter_new();
gtk_file_filter_set_name(filter,"All Files");
gtk_file_filter_add_pattern(filter,"*");
gtk_file_chooser_add_filter((GtkFileChooser*)dialog,filter);
gtk_widget_show(dialog);
//Show Dialog and wait for response
gtk_native_dialog_show(GTK_NATIVE_DIALOG(dialog));
g_signal_connect(dialog,"response",G_CALLBACK(dialog_response),builder);
}