From eb8f6932fe45f550bc2b77c1b3e578884ed60d91 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 30 May 2018 12:11:46 +0530 Subject: Added message box functionality --- ldmicro/lib/linuxUI/CMakeLists.txt | 2 +- ldmicro/lib/linuxUI/linuxLD.cpp | 2 ++ ldmicro/lib/linuxUI/linuxLD.h | 9 +++++---- ldmicro/lib/linuxUI/linuxUI.cpp | 41 +++++++++++++++++++++++++++++++++++++- ldmicro/lib/linuxUI/linuxUI.h | 11 ++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 ldmicro/lib/linuxUI/linuxLD.cpp (limited to 'ldmicro/lib/linuxUI') diff --git a/ldmicro/lib/linuxUI/CMakeLists.txt b/ldmicro/lib/linuxUI/CMakeLists.txt index 16226dc..25ba6b2 100644 --- a/ldmicro/lib/linuxUI/CMakeLists.txt +++ b/ldmicro/lib/linuxUI/CMakeLists.txt @@ -1,3 +1,3 @@ project(LinuxUI) -add_library(LinuxUI linuxUI.cpp) +add_library(LinuxUI linuxUI.cpp linuxLD.cpp) diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp new file mode 100644 index 0000000..69c5f6e --- /dev/null +++ b/ldmicro/lib/linuxUI/linuxLD.cpp @@ -0,0 +1,2 @@ +#include "linuxUI.h" + diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h index 9aba23d..d2ce90f 100644 --- a/ldmicro/lib/linuxUI/linuxLD.h +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -19,14 +19,13 @@ typedef long LONG; /// all handles will hold a GtkWindow* type typedef void* PVOID; -typedef GtkWidget* HANDLE; +typedef PVOID HANDLE; typedef HANDLE HINSTANCE; -typedef HANDLE HWID; typedef HANDLE HDC; -typedef HANDLE HMENU; +typedef GtkWidget* HWID; +typedef GtkWidget* HMENU; typedef GtkWindow* HWND; - typedef GtkApplication* HAPP; /// Check if system is x64 or x86 @@ -58,4 +57,6 @@ class COLORREF : public GdkRGBA{ } }; +/// functions + #endif diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index 8237d7d..ffaf023 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -15,4 +15,43 @@ COLORREF RGB(int red, int green, int blue) col.alpha = 1.0; return col; -} \ No newline at end of file +} + +void MessageBox(HWID pWindow, char* message, char* title, UINT mFlags) + { + GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT; + GtkMessageType mType; + GtkButtonsType mButtons; + + if (mFlags & MB_OK == MB_OK) + mButtons = GTK_BUTTONS_OK; + else if (mFlags & MB_OKCANCEL == MB_OKCANCEL) + mButtons = GTK_BUTTONS_OK_CANCEL; + else if (mFlags & MB_YESNO == MB_YESNO) + mButtons = GTK_BUTTONS_YES_NO; + else + mButtons = GTK_BUTTONS_CLOSE; + + if (mFlags & MB_ICONERROR == MB_ICONERROR) + mType = GTK_MESSAGE_ERROR; + else if (mFlags & MB_ICONQUESTION == MB_ICONQUESTION) + mType = GTK_MESSAGE_QUESTION; + else if (mFlags & MB_ICONWARNING == MB_ICONWARNING) + mType = GTK_MESSAGE_WARNING; + else if (mFlags & MB_ICONINFORMATION == MB_ICONINFORMATION) + mType = GTK_MESSAGE_INFO; + else + mType = GTK_MESSAGE_OTHER; + + mType = GTK_MESSAGE_ERROR; + HWID dialog = gtk_message_dialog_new (GTK_WINDOW(pWindow), + flags, + mType, + mButtons, + message); + gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG(dialog), + title); + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), message); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } \ No newline at end of file diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 3e49de0..f6105bc 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -12,8 +12,19 @@ #define LDMicro_VERSION_MAJOR 1 #define LDMicro_VERSION_MINOR 0 +/// Flags +#define MB_OK 0x00000000L +#define MB_OKCANCEL 0x00000001L +#define MB_YESNO 0x00000004L + +#define MB_ICONERROR 0x00000010L +#define MB_ICONQUESTION 0x00000020L +#define MB_ICONWARNING 0x00000030L +#define MB_ICONINFORMATION 0x00000040L + /// functions BOOL isFocus(HWID); COLORREF RGB(int, int, int); +void MessageBox(HWID, char*, char*, UINT); #endif \ No newline at end of file -- cgit From 8f1f63ff88e62cb47cad286481033275e8490650 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 30 May 2018 16:57:42 +0530 Subject: ported GetSaveFileName function from windows.h --- ldmicro/lib/linuxUI/linuxLD.h | 17 +++++++++++++- ldmicro/lib/linuxUI/linuxUI.cpp | 51 ++++++++++++++++++++++++++++++++++++++++- ldmicro/lib/linuxUI/linuxUI.h | 20 ++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) (limited to 'ldmicro/lib/linuxUI') diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h index d2ce90f..c1b0829 100644 --- a/ldmicro/lib/linuxUI/linuxLD.h +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -9,13 +9,28 @@ #define MAX_PATH PATH_MAX /// CALLBACK or __stdcall os defined empty #define CALLBACK - +#define CONST const /// typedefs //typedef int64_t __int64; typedef bool BOOL; typedef unsigned char BYTE; typedef unsigned int DWORD; typedef long LONG; +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 /// 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 ffaf023..74269d9 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -54,4 +54,53 @@ void MessageBox(HWID pWindow, char* message, char* title, UINT mFlags) gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), message); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); - } \ No newline at end of file + } + +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); + + 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); + + 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); + + 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); + + 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); + + 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); + + return exitStatus; +} \ No newline at end of file diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index f6105bc..920dcce 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -13,6 +13,7 @@ #define LDMicro_VERSION_MINOR 0 /// Flags +/// message box #define MB_OK 0x00000000L #define MB_OKCANCEL 0x00000001L #define MB_YESNO 0x00000004L @@ -22,9 +23,28 @@ #define MB_ICONWARNING 0x00000030L #define MB_ICONINFORMATION 0x00000040L +/// open/save file +#define OFN_PATHMUSTEXIST 0x00000800 +#define OFN_HIDEREADONLY 0x00000004 +#define OFN_OVERWRITEPROMPT 0x00000002 + + +/// data types +typedef struct OpenFileInfoData { + DWORD lStructSize; + HWID parentWindow; + LPCTSTR lpstrFilter; + LPTSTR lpstrFile; + 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*); #endif \ No newline at end of file -- cgit