summaryrefslogtreecommitdiff
path: root/ldmicro/lib/linuxUI
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/lib/linuxUI')
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h14
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp109
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h22
3 files changed, 87 insertions, 58 deletions
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index fc60259..db2a42f 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -20,17 +20,21 @@ typedef wchar_t WCHAR;
typedef char CHAR;
typedef CONST WCHAR *LPCWSTR;
typedef CONST CHAR *LPCSTR; /// should be __nullterminated
+
#ifdef UNICODE
typedef LPCWSTR LPCTSTR;
#else
typedef LPCSTR LPCTSTR;
#endif
-// #ifdef UNICODE
-// typedef LPWSTR LPTSTR;
-// #else
-// typedef LPSTR LPTSTR;
-// #endif
+typedef WCHAR *LPWSTR;
+typedef CHAR *LPSTR;
+
+#ifdef UNICODE
+ typedef LPWSTR LPTSTR;
+#else
+ typedef LPSTR LPTSTR;
+#endif
/// all handles will hold a GtkWindow* type
typedef void* PVOID;
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 3dbe1bb..9d912ea 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -59,51 +59,76 @@ void MessageBox(HWID pWindow, char* message, char* title, UINT mFlags)
gtk_widget_destroy (dialog);
}
-// BOOL GetSaveFileName(OPENFILENAME ofn)
-// {
-// GtkWidget *dialog;
-// GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
-
-// dialog = gtk_file_chooser_dialog_new ("Open File",
-// GTK_WINDOW(window),
-// action,
-// "_Cancel",
-// GTK_RESPONSE_CANCEL,
-// "_Open",
-// GTK_RESPONSE_ACCEPT,
-// NULL);
-
-// GtkFileFilter *filter = gtk_file_filter_new ();
-// gtk_file_filter_add_pattern (filter, "*");
-// gtk_file_filter_set_name (filter, "All files");
-// gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+BOOL GetSaveFileName(OPENFILENAME *ofn)
+{
+ GtkWidget *dialog;
+ GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
-// filter = gtk_file_filter_new ();
-// gtk_file_filter_add_pattern (filter, "*.c");
-// gtk_file_filter_add_pattern (filter, "*.cpp");
-// gtk_file_filter_set_name (filter, "C source files");
-// gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ dialog = gtk_file_chooser_dialog_new (ofn->lpstrTitle,
+ GTK_WINDOW(ofn->parentWindow),
+ action,
+ "_Cancel",
+ GTK_RESPONSE_CANCEL,
+ "_Open",
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+ //g_print("filter created\n");
+
+ if (ofn->Flags & OFN_OVERWRITEPROMPT == OFN_OVERWRITEPROMPT)
+ gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
-// filter = gtk_file_filter_new ();
-// gtk_file_filter_add_pattern (filter, "*.h");
-// gtk_file_filter_set_name (filter, "C hedder files");
-// gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ GtkFileFilter *filter = gtk_file_filter_new ();
+ char* strFilter = new char[strlen(ofn->lpstrFilter)];
+ DWORD strFilterLen = 0;
+ BOOL filterResetFlag = FALSE;
+
+ for (int i = 0; !(ofn->lpstrFilter[i] == '\0' && ofn->lpstrFilter[i-1] == '\0'); ++i)
+ {
+ memcpy (strFilter + strFilterLen, &ofn->lpstrFilter[i], 1 );
+ ++strFilterLen;
+ if (ofn->lpstrFilter[i] == '\0')
+ if (filterResetFlag)
+ {
+ gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter);
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter);
+ filter = gtk_file_filter_new ();
+ strFilterLen = 0;
+ //g_print("filter pat: %s\n", strFilter);
+ //g_print("filter reset\n");
+ filterResetFlag = FALSE;
+ }
+ else
+ {
+ gtk_file_filter_set_name (GTK_FILE_FILTER(filter), strFilter);
+ //g_print("filter name: %s\n", strFilter);
+ strFilterLen = 0;
+ filterResetFlag = TRUE;
+ }
+ }
+ //g_print("filter rules added\n");
-// filter = gtk_file_filter_new ();
-// gtk_file_filter_add_pattern (filter, "*.hex");
-// gtk_file_filter_set_name (filter, "hex files");
-// gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ sprintf(strFilter, "*.%s", ofn->lpstrDefExt);
+ gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter);
+ //gtk_file_filter_set_name (filter, "int files");
+ gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(dialog), filter);
-// filter = gtk_file_filter_new ();
-// gtk_file_filter_add_pattern (filter, "*.int");
-// gtk_file_filter_set_name (filter, "int files");
-// gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-// gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+ delete strFilter;
+
+ //g_print("default filter set\n");
+
+ BOOL exitStatus = gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (exitStatus)
+ {
+ char* str;
+ str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog));
+ strcpy(ofn->lpstrFile, str);
+ g_free(str);
+ }
+ //g_print("file path saved: %s\n", ofn->lpstrFile);
-// BOOL exitStatus = gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT;
-// if (exitStatus)
-// filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-// gtk_widget_destroy (dialog);
+ gtk_widget_destroy (dialog);
-// return exitStatus;
-// } \ No newline at end of file
+ //g_print("exit\n");
+
+ return exitStatus;
+}
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 18afd60..904599e 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -30,21 +30,21 @@
/// data types
-// typedef struct OpenFileInfoData {
-// DWORD lStructSize;
-// HWID parentWindow;
-// LPCTSTR lpstrFilter;
-// LPTSTR lpstrFile;
-// DWORD nMaxFile;
-// LPCTSTR lpstrTitle;
-// DWORD Flags;
-// LPCTSTR lpstrDefExt;
-// } OPENFILENAME;
+typedef struct OpenFileInfoData {
+ DWORD lStructSize;
+ HWID parentWindow;
+ LPTSTR lpstrFile;
+ LPCTSTR lpstrFilter;
+ DWORD nMaxFile;
+ LPCTSTR lpstrTitle;
+ DWORD Flags;
+ LPCTSTR lpstrDefExt;
+} OPENFILENAME;
/// functions
BOOL isFocus(HWID);
COLORREF RGB(int, int, int);
void MessageBox(HWID, char*, char*, UINT);
-BOOL GetSaveFileName(HWID, char*);
+BOOL GetSaveFileName(OPENFILENAME* );
#endif \ No newline at end of file