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/includes/ldmicro.h | 8 ++--- ldmicro/ldmicro.cpp | 71 ++++++++++++++++++-------------------- ldmicro/lib/freezeLD/freezeLD.cpp | 12 +++---- 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 ++++++ ldmicro/miscutil.cpp | 10 ++---- 9 files changed, 106 insertions(+), 60 deletions(-) create mode 100644 ldmicro/lib/linuxUI/linuxLD.cpp (limited to 'ldmicro') diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 2c6f720..579d3a7 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -31,8 +31,8 @@ typedef signed long SDWORD; //----------------------------------------------- // `Configuration options.' -// The library that I use to do registry stuff. -#define FREEZE_SUBKEY "LDMicro" +// The library that I use to do registry stuff. decleared in freezeLD.h due to build issues +// #define FREEZE_SUBKEY "LDMicro" // Size of the font that we will use to draw the ladder diagrams, in pixels #define FONT_WIDTH 7 @@ -501,7 +501,7 @@ typedef struct McuIoInfoTag { #define NUM_SUPPORTED_MCUS 16 - +/* //----------------------------------------------- // Function prototypes @@ -777,5 +777,5 @@ void CompileAnsiC(char *outFile); void CompileInterpreted(char *outFile); //Arduino.cpp void CompileArduino(char *outFile); - +*/ #endif diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index cc0a525..ca86246 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -30,7 +30,7 @@ #include #include "ldmicro.h" -#include "freeze.h" +#include "freezeLD.h" #include "mcutable.h" #include "advanceddialog.h" @@ -1051,44 +1051,11 @@ static BOOL MakeWindowClass() //----------------------------------------------------------------------------- // Entry point into the program. //----------------------------------------------------------------------------- -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPSTR lpCmdLine, INT nCmdShow) +int main(int argc, char** argv) { - Instance = hInstance; - - MainHeap = HeapCreate(0, 1024*64, 0); - - MakeWindowClass(); - MakeDialogBoxClass(); - MakeAdvancedDialogClass(); - MakeAdvancedWorkspaceClass(); - MakeComponentListClass(); - MakeSmplDialogClass(); - MakeNamingListClass(); - HMENU top = MakeMainWindowMenus(); - - MainWindow = CreateWindowEx(0, "LDmicro", "", - WS_OVERLAPPED | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | - WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX, - 10, 10, 800, 600, NULL, top, Instance, NULL); - ThawWindowPos(MainWindow); - IoListHeight = 100; - ThawDWORD(IoListHeight); - - InitCommonControls(); - InitForDrawing(); - - MakeMainWindowControls(); - MainWindowResized(); - NewProgram(); - strcpy(CurrentSaveFile, ""); - // Check if we're running in non-interactive mode; in that case we should // load the file, compile, and exit. - while(isspace(*lpCmdLine)) { - lpCmdLine++; - } - if(memcmp(lpCmdLine, "/c", 2)==0) { + if(argc >= 2) { RunningInBatchMode = TRUE; char *err = @@ -1115,10 +1082,40 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } strcpy(CurrentCompileFile, dest); GenerateIoList(-1); - CompileProgram(FALSE); + CompileProgram(FALSE); /// Requires an open dialog to get file name exit(0); } + Instance = hInstance; + + MainHeap = HeapCreate(0, 1024*64, 0); + + // MakeWindowClass(); + // MakeDialogBoxClass(); + // MakeAdvancedDialogClass(); + // MakeAdvancedWorkspaceClass(); + // MakeComponentListClass(); + // MakeSmplDialogClass(); + // MakeNamingListClass(); + HMENU top = MakeMainWindowMenus(); + + /// Make main window + // MainWindow = CreateWindowEx(0, "LDmicro", "", + // WS_OVERLAPPED | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | + // WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX, + // 10, 10, 800, 600, NULL, top, Instance, NULL); + ThawWindowPos(MainWindow); + IoListHeight = 100; + ThawDWORD(IoListHeight); + + InitCommonControls(); + InitForDrawing(); + + MakeMainWindowControls(); + MainWindowResized(); + NewProgram(); + strcpy(CurrentSaveFile, ""); + // We are running interactively, or we would already have exited. We // can therefore show the window now, and otherwise set up the GUI. diff --git a/ldmicro/lib/freezeLD/freezeLD.cpp b/ldmicro/lib/freezeLD/freezeLD.cpp index 5241af1..6a52575 100644 --- a/ldmicro/lib/freezeLD/freezeLD.cpp +++ b/ldmicro/lib/freezeLD/freezeLD.cpp @@ -36,7 +36,7 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) Key newKey; int val; - g_print("get width"); + //g_print("get width"); sprintf(keyName, "%s_width", name); std::ofstream Register(keyName, std::ios::binary | std::ios::trunc); if (!Register.is_open()) @@ -47,7 +47,7 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) Register.write((char*) &newKey, sizeof(newKey)); Register.close(); - g_print("get height"); + //g_print("get height"); sprintf(keyName, "%s_height", name); Register.open(keyName, std::ios::binary | std::ios::trunc); if (!Register.is_open()) @@ -58,7 +58,7 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) Register.write((char*) &newKey, sizeof(newKey)); Register.close(); - g_print("get posX"); + //g_print("get posX"); sprintf(keyName, "%s_posX", name); Register.open(keyName, std::ios::binary | std::ios::trunc); if (!Register.is_open()) @@ -69,7 +69,7 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) Register.write((char*) &newKey, sizeof(newKey)); Register.close(); - g_print("get posY"); + //g_print("get posY"); sprintf(keyName, "%s_posY", name); Register.open(keyName, std::ios::binary | std::ios::trunc); if (!Register.is_open()) @@ -80,7 +80,7 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) Register.write((char*) &newKey, sizeof(newKey)); Register.close(); - g_print("get max"); + //g_print("get max"); sprintf(keyName, "%s_maximized", name); Register.open(keyName, std::ios::binary | std::ios::trunc); if (!Register.is_open()) @@ -91,7 +91,7 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) Register.close(); free(keyName); - g_print("freezed"); + //g_print("freezed"); } static void Clamp(LONG *v, LONG min, LONG max) 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 diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp index 116d584..defa1fa 100644 --- a/ldmicro/miscutil.cpp +++ b/ldmicro/miscutil.cpp @@ -90,18 +90,14 @@ void Error(char *str, ...) vsprintf(buf, str, f); if(RunningInBatchMode) { AttachConsoleDynamic(ATTACH_PARENT_PROCESS); - HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); - DWORD written; // Indicate that it's an error, plus the output filename - char str[MAX_PATH+100]; - sprintf(str, "compile error ('%s'): ", CurrentCompileFile); - WriteFile(h, str, strlen(str), &written, NULL); + printf("compile error ('%s'): ", CurrentCompileFile); // The error message itself - WriteFile(h, buf, strlen(buf), &written, NULL); + printf(buf); // And an extra newline to be safe. strcpy(str, "\n"); - WriteFile(h, str, strlen(str), &written, NULL); + printf(str); } else { HWND h = GetForegroundWindow(); MessageBox(h, buf, _("LDmicro Error"), MB_OK | MB_ICONERROR); -- 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/ldmicro.cpp | 2 +- ldmicro/lib/freezeLD/freezeLD.cpp | 2 +- ldmicro/lib/linuxUI/linuxLD.h | 17 ++++++++++++- ldmicro/lib/linuxUI/linuxUI.cpp | 51 ++++++++++++++++++++++++++++++++++++++- ldmicro/lib/linuxUI/linuxUI.h | 20 +++++++++++++++ ldmicro/miscutil.cpp | 5 ++-- 6 files changed, 91 insertions(+), 6 deletions(-) (limited to 'ldmicro') diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index ca86246..984ffbb 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -148,7 +148,7 @@ static void CompileProgram(BOOL compileAs) memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); - ofn.hInstance = Instance; + ofn.parentWindow = parentWindow; ofn.lpstrTitle = _("Compile To"); if(Prog.mcu && Prog.mcu->whichIsa == ISA_ANSIC) { ofn.lpstrFilter = C_PATTERN; diff --git a/ldmicro/lib/freezeLD/freezeLD.cpp b/ldmicro/lib/freezeLD/freezeLD.cpp index 6a52575..0bbd33f 100644 --- a/ldmicro/lib/freezeLD/freezeLD.cpp +++ b/ldmicro/lib/freezeLD/freezeLD.cpp @@ -18,7 +18,7 @@ */ void FreezeWindowPosF(HWID hwid, char *subKey, char *name) { - g_print("freezing"); + //g_print("freezing"); char* moveToKeyLocatin = (char *)malloc(strlen(subKey) + 35); if(!moveToKeyLocatin) return; 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 diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp index defa1fa..428e5f6 100644 --- a/ldmicro/miscutil.cpp +++ b/ldmicro/miscutil.cpp @@ -89,8 +89,9 @@ void Error(char *str, ...) va_start(f, str); vsprintf(buf, str, f); if(RunningInBatchMode) { - AttachConsoleDynamic(ATTACH_PARENT_PROCESS); - + /* Only required for windows + * AttachConsoleDynamic(ATTACH_PARENT_PROCESS); + */ // Indicate that it's an error, plus the output filename printf("compile error ('%s'): ", CurrentCompileFile); // The error message itself -- cgit