summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldmicro/includes/ldmicro.h4
-rw-r--r--ldmicro/ldmicro.cpp73
-rw-r--r--ldmicro/lib/freezeLD/freezeLD.cpp14
-rw-r--r--ldmicro/lib/linuxUI/CMakeLists.txt2
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp2
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h26
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp88
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h31
-rw-r--r--ldmicro/miscutil.cpp15
9 files changed, 193 insertions, 62 deletions
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index 214ee3b..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
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index cc0a525..984ffbb 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -30,7 +30,7 @@
#include <stdlib.h>
#include "ldmicro.h"
-#include "freeze.h"
+#include "freezeLD.h"
#include "mcutable.h"
#include "advanceddialog.h"
@@ -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;
@@ -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..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;
@@ -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..c1b0829 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -9,24 +9,38 @@
#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;
-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 +72,6 @@ class COLORREF : public GdkRGBA{
}
};
+/// functions
+
#endif
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 13af88b..6dabd80 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -53,4 +53,92 @@ COLORREF RGB(int red, int green, int blue)
col.alpha = 1.0;
return col;
+}
+
+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);
+ }
+
+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 3e49de0..920dcce 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -12,8 +12,39 @@
#define LDMicro_VERSION_MAJOR 1
#define LDMicro_VERSION_MINOR 0
+/// Flags
+/// message box
+#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
+
+/// 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 116d584..428e5f6 100644
--- a/ldmicro/miscutil.cpp
+++ b/ldmicro/miscutil.cpp
@@ -89,19 +89,16 @@ void Error(char *str, ...)
va_start(f, str);
vsprintf(buf, str, f);
if(RunningInBatchMode) {
- AttachConsoleDynamic(ATTACH_PARENT_PROCESS);
- HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
- DWORD written;
-
+ /* Only required for windows
+ * AttachConsoleDynamic(ATTACH_PARENT_PROCESS);
+ */
// 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);