summaryrefslogtreecommitdiff
path: root/ldmicro
diff options
context:
space:
mode:
authorNatsuDrag92018-06-12 13:38:02 +0530
committerNatsuDrag92018-06-12 13:38:02 +0530
commite747a36b374a0c37fadb4d4b09a9207d89fad828 (patch)
tree0c77752f4b42765b74f6f2c35b2aebd6189a21eb /ldmicro
parentc9a07df3d7f1c14b0c5f91605b4d7acf4b646f63 (diff)
parent9be96591b989efd41fa0d8a55a600ad6bab78922 (diff)
downloadLDMicroGtk-e747a36b374a0c37fadb4d4b09a9207d89fad828.tar.gz
LDMicroGtk-e747a36b374a0c37fadb4d4b09a9207d89fad828.tar.bz2
LDMicroGtk-e747a36b374a0c37fadb4d4b09a9207d89fad828.zip
Updated changes
Diffstat (limited to 'ldmicro')
-rw-r--r--ldmicro/CMakeLists.txt19
-rw-r--r--ldmicro/includes/ldmicro.h16
-rw-r--r--ldmicro/ldmicro.cpp927
-rw-r--r--ldmicro/lib/freezeLD/freezeLD.cpp187
-rw-r--r--ldmicro/lib/freezeLD/freezeLD.h2
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp28
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h67
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp55
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h23
-rw-r--r--ldmicro/maincontrols.cpp6
-rw-r--r--ldmicro/reg/go.bat1
-rw-r--r--ldmicro/reg/run-tests.pl2
12 files changed, 799 insertions, 534 deletions
diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt
index 90a1616..49668a3 100644
--- a/ldmicro/CMakeLists.txt
+++ b/ldmicro/CMakeLists.txt
@@ -130,6 +130,10 @@ IF(UNIX)
maincontrols.cpp
ldmicro.cpp)
+ ## Build *.int interpreter
+ add_executable (ldinterpret ldinterpret.c)
+ target_link_libraries (ldinterpret LinuxUI)
+
## Build main LDMicro executable
add_executable (LDMicro ${COMPILE_CPP_SOURCES})
add_dependencies(LDMicro LDMicro_SCRIPT_GENERATED_FILES)
@@ -137,13 +141,12 @@ IF(UNIX)
target_link_libraries (LDMicro LinuxUI)
target_link_libraries (LDMicro FreezeLD)
- ## Build *.int interpreter
- add_executable (ldinterpret ldinterpret.c)
- target_link_libraries (ldinterpret LinuxUI)
-
- #add_executable (testMain testMain.cpp)
- #install (TARGETS testMain DESTINATION bin)
- #target_link_libraries (testMain LinuxUI)
- #target_link_libraries (testMain FreezeLD)
+ ## Add tests
+ MESSAGE( STATUS "Adding tests.." )
+ add_custom_command(
+ TARGET LDMicro
+ POST_BUILD
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/reg
+ COMMAND perl run-tests.pl)
ENDIF(UNIX)
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index 715fd39..64f16c8 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -558,14 +558,14 @@ extern BOOL SelectionActive;
extern BOOL ThisHighlighted;
// draw_outputdev.cpp
-// extern void (*DrawChars)(int, int, char *);
-// void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time);
-// void PaintWindow(void);
-// void ExportDrawingAsText(char *file);
-// void InitForDrawing(void);
-// void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert);
-// int ScreenRowsAvailable(void);
-// int ScreenColsAvailable(void);
+extern void (*DrawChars)(int, int, char *);
+void CALLBACK BlinkCursor(HWND hwnd, UINT msg, UINT_PTR id, DWORD time);
+void PaintWindow(void);
+void ExportDrawingAsText(char *file);
+void InitForDrawing(void);
+void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert);
+int ScreenRowsAvailable(void);
+int ScreenColsAvailable(void);
extern HFONT FixedWidthFont;
extern HFONT FixedWidthFontBold;
extern int SelectedGxAfterNextPaint;
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index 6bb39d2..6851d9d 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -585,447 +585,448 @@ static void CompileProgram(BOOL compileAs)
//-----------------------------------------------------------------------------
// WndProc for MainWindow.
//-----------------------------------------------------------------------------
-// LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-// {
-// switch (msg) {
-// case WM_ERASEBKGND:
-// break;
-
-// case WM_SETFOCUS:
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
-
-// case WM_PAINT: {
-// PAINTSTRUCT ps;
-// Hdc = BeginPaint(hwnd, &ps);
-
-// // This draws the schematic.
-// PaintWindow();
-
-// RECT r;
-// // Fill around the scroll bars
-// if(NeedHoriz) {
-// r.top = IoListTop - ScrollHeight - 2;
-// r.bottom = IoListTop - 2;
-// FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
-// }
-// GetClientRect(MainWindow, &r);
-// r.left = r.right - ScrollWidth - 2;
-// FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
-
-// // Draw the splitter thing to grab to resize the I/O listview.
-// GetClientRect(MainWindow, &r);
-// r.top = IoListTop - 2;
-// r.bottom = IoListTop;
-// FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
-// r.top = IoListTop - 2;
-// r.bottom = IoListTop - 1;
-// FillRect(Hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
-// r.top = IoListTop;
-// r.bottom = IoListTop + 1;
-// FillRect(Hdc, &r, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
-
-// EndPaint(hwnd, &ps);
-// return 1;
-// }
-
-// case WM_KEYDOWN: {
-// if(wParam == 'M') {
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
-// ToggleSimulationMode();
-// break;
-// }
-// } else if(wParam == VK_TAB) {
-// SetFocus(IoList);
-// BlinkCursor(0, 0, 0, 0);
-// break;
-// } else if(wParam == VK_F1) {
-// ShowHelpDialog(FALSE);
-// break;
-// }
-
-// if(InSimulationMode) {
-// switch(wParam) {
-// case ' ':
-// SimulateOneCycle(TRUE);
-// break;
-
-// case 'R':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000)
-// StartSimulation();
-// break;
-
-// case 'H':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000)
-// StopSimulation();
-// break;
-
-// case VK_DOWN:
-// if(ScrollYOffset < ScrollYOffsetMax)
-// ScrollYOffset++;
-// RefreshScrollbars();
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
-
-// case VK_UP:
-// if(ScrollYOffset > 0)
-// ScrollYOffset--;
-// RefreshScrollbars();
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
-
-// case VK_LEFT:
-// ScrollXOffset -= FONT_WIDTH;
-// if(ScrollXOffset < 0) ScrollXOffset = 0;
-// RefreshScrollbars();
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
-
-// case VK_RIGHT:
-// ScrollXOffset += FONT_WIDTH;
-// if(ScrollXOffset >= ScrollXOffsetMax)
-// ScrollXOffset = ScrollXOffsetMax;
-// RefreshScrollbars();
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
-
-// case VK_RETURN:
-// case VK_ESCAPE:
-// ToggleSimulationMode();
-// break;
-// }
-// break;
-// }
-
-
-// switch(wParam) {
-// case VK_F5:
-// CompileProgram(FALSE);
-// break;
-
-// case VK_UP:
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(PushRungUp());
-// } else {
-// MoveCursorKeyboard(wParam);
-// }
-// break;
-
-// case VK_DOWN:
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(PushRungDown());
-// } else {
-// MoveCursorKeyboard(wParam);
-// }
-// break;
-
-// case VK_RIGHT:
-// case VK_LEFT:
-// MoveCursorKeyboard(wParam);
-// break;
-
-// case VK_RETURN:
-// CHANGING_PROGRAM(EditSelectedElement());
-// break;
-
-// case VK_DELETE:
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(DeleteSelectedRung());
-// } else {
-// CHANGING_PROGRAM(DeleteSelectedFromProgram());
-// }
-// break;
-
-// case VK_OEM_1:
-// CHANGING_PROGRAM(AddComment(_("--add comment here--")));
-// break;
-
-// case 'C':
-// CHANGING_PROGRAM(AddContact());
-// break;
-
-// // TODO: rather country-specific here
-// case VK_OEM_2:
-// CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_RISING));
-// break;
-
-// case VK_OEM_5:
-// CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_FALLING));
-// break;
-
-// case 'L':
-// CHANGING_PROGRAM(AddCoil());
-// break;
-
-// case 'R':
-// CHANGING_PROGRAM(MakeResetOnlySelected());
-// break;
-
-// case 'E':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
-// ExportDialog();
-// } else {
-// CHANGING_PROGRAM(AddReset());
-// }
-// break;
-
-// case 'S':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
-// SaveProgram();
-// UpdateMainWindowTitleBar();
-// } else {
-// CHANGING_PROGRAM(MakeSetOnlySelected());
-// }
-// break;
-
-// case 'N':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
-// if(CheckSaveUserCancels()) break;
-// if(!ProgramChangedNotSaved) {
-// int r = MessageBox(MainWindow,
-// _("Start new program?"),
-// "LDmicro", MB_YESNO | MB_DEFBUTTON2 |
-// MB_ICONQUESTION);
-// if(r == IDNO) break;
-// }
-// NewProgram();
-// strcpy(CurrentSaveFile, "");
-// strcpy(CurrentCompileFile, "");
-// GenerateIoListDontLoseSelection();
-// RefreshScrollbars();
-// UpdateMainWindowTitleBar();
-// } else {
-// CHANGING_PROGRAM(NegateSelected());
-// }
-// break;
-
-// case 'A':
-// CHANGING_PROGRAM(MakeNormalSelected());
-// break;
-
-// case 'T':
-// CHANGING_PROGRAM(AddTimer(ELEM_RTO));
-// break;
-
-// case 'O':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
-// if(CheckSaveUserCancels()) break;
-// OpenDialog();
-// } else {
-// CHANGING_PROGRAM(AddTimer(ELEM_TON));
-// }
-// break;
-
-// case 'F':
-// CHANGING_PROGRAM(AddTimer(ELEM_TOF));
-// break;
-
-// case 'U':
-// CHANGING_PROGRAM(AddCounter(ELEM_CTU));
-// break;
-
-// case 'I':
-// CHANGING_PROGRAM(AddCounter(ELEM_CTD));
-// break;
-
-// case 'J':
-// CHANGING_PROGRAM(AddCounter(ELEM_CTC));
-// break;
-
-// case 'M':
-// CHANGING_PROGRAM(AddMove());
-// break;
-
-// case 'P':
-// CHANGING_PROGRAM(AddReadAdc());
-// break;
-
-// case VK_OEM_PLUS:
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(AddMath(ELEM_ADD));
-// } else {
-// CHANGING_PROGRAM(AddCmp(ELEM_EQU));
-// }
-// break;
-
-// case VK_OEM_MINUS:
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// } else {
-// CHANGING_PROGRAM(AddMath(ELEM_SUB));
-// }
-// break;
-
-// case '8':
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(AddMath(ELEM_MUL));
-// }
-// break;
-
-// case 'D':
-// CHANGING_PROGRAM(AddMath(ELEM_DIV));
-// break;
-
-// case VK_OEM_PERIOD:
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(AddCmp(ELEM_GRT));
-// } else {
-// CHANGING_PROGRAM(AddCmp(ELEM_GEQ));
-// }
-// break;
-
-// case VK_OEM_COMMA:
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(AddCmp(ELEM_LES));
-// } else {
-// CHANGING_PROGRAM(AddCmp(ELEM_LEQ));
-// }
-// break;
-
-// case 'V':
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(InsertRung(TRUE));
-// }
-// break;
+LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ // switch (msg) {
+ // case WM_ERASEBKGND:
+ // break;
+
+ // case WM_SETFOCUS:
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
+
+ // case WM_PAINT: {
+ // PAINTSTRUCT ps;
+ // Hdc = BeginPaint(hwnd, &ps);
+
+ // // This draws the schematic.
+ // PaintWindow();
+
+ // RECT r;
+ // // Fill around the scroll bars
+ // if(NeedHoriz) {
+ // r.top = IoListTop - ScrollHeight - 2;
+ // r.bottom = IoListTop - 2;
+ // FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
+ // }
+ // GetClientRect(MainWindow, &r);
+ // r.left = r.right - ScrollWidth - 2;
+ // FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
+
+ // // Draw the splitter thing to grab to resize the I/O listview.
+ // GetClientRect(MainWindow, &r);
+ // r.top = IoListTop - 2;
+ // r.bottom = IoListTop;
+ // FillRect(Hdc, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
+ // r.top = IoListTop - 2;
+ // r.bottom = IoListTop - 1;
+ // FillRect(Hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
+ // r.top = IoListTop;
+ // r.bottom = IoListTop + 1;
+ // FillRect(Hdc, &r, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
+
+ // EndPaint(hwnd, &ps);
+ // return 1;
+ // }
-// case '6':
-// if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
-// CHANGING_PROGRAM(InsertRung(FALSE));
-// }
-// break;
+ // case WM_KEYDOWN: {
+ // if(wParam == 'M') {
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
+ // ToggleSimulationMode();
+ // break;
+ // }
+ // } else if(wParam == VK_TAB) {
+ // SetFocus(IoList);
+ // BlinkCursor(0, 0, 0, 0);
+ // break;
+ // } else if(wParam == VK_F1) {
+ // ShowHelpDialog(FALSE);
+ // break;
+ // }
-// case 'Z':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
-// UndoUndo();
-// }
-// break;
+ // if(InSimulationMode) {
+ // switch(wParam) {
+ // case ' ':
+ // SimulateOneCycle(TRUE);
+ // break;
+
+ // case 'R':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000)
+ // StartSimulation();
+ // break;
+
+ // case 'H':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000)
+ // StopSimulation();
+ // break;
+
+ // case VK_DOWN:
+ // if(ScrollYOffset < ScrollYOffsetMax)
+ // ScrollYOffset++;
+ // RefreshScrollbars();
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
+
+ // case VK_UP:
+ // if(ScrollYOffset > 0)
+ // ScrollYOffset--;
+ // RefreshScrollbars();
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
+
+ // case VK_LEFT:
+ // ScrollXOffset -= FONT_WIDTH;
+ // if(ScrollXOffset < 0) ScrollXOffset = 0;
+ // RefreshScrollbars();
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
+
+ // case VK_RIGHT:
+ // ScrollXOffset += FONT_WIDTH;
+ // if(ScrollXOffset >= ScrollXOffsetMax)
+ // ScrollXOffset = ScrollXOffsetMax;
+ // RefreshScrollbars();
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
+
+ // case VK_RETURN:
+ // case VK_ESCAPE:
+ // ToggleSimulationMode();
+ // break;
+ // }
+ // break;
+ // }
-// case 'Y':
-// if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
-// UndoRedo();
-// }
-// break;
-// default:
-// break;
-// }
-// if(wParam != VK_SHIFT && wParam != VK_CONTROL) {
-// InvalidateRect(MainWindow, NULL, FALSE);
-// }
-// break;
-// }
+ // switch(wParam) {
+ // case VK_F5:
+ // CompileProgram(FALSE);
+ // break;
+
+ // case VK_UP:
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(PushRungUp());
+ // } else {
+ // MoveCursorKeyboard(wParam);
+ // }
+ // break;
+
+ // case VK_DOWN:
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(PushRungDown());
+ // } else {
+ // MoveCursorKeyboard(wParam);
+ // }
+ // break;
+
+ // case VK_RIGHT:
+ // case VK_LEFT:
+ // MoveCursorKeyboard(wParam);
+ // break;
+
+ // case VK_RETURN:
+ // CHANGING_PROGRAM(EditSelectedElement());
+ // break;
+
+ // case VK_DELETE:
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(DeleteSelectedRung());
+ // } else {
+ // CHANGING_PROGRAM(DeleteSelectedFromProgram());
+ // }
+ // break;
+
+ // case VK_OEM_1:
+ // CHANGING_PROGRAM(AddComment(_("--add comment here--")));
+ // break;
+
+ // case 'C':
+ // CHANGING_PROGRAM(AddContact());
+ // break;
+
+ // // TODO: rather country-specific here
+ // case VK_OEM_2:
+ // CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_RISING));
+ // break;
+
+ // case VK_OEM_5:
+ // CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_FALLING));
+ // break;
+
+ // case 'L':
+ // CHANGING_PROGRAM(AddCoil());
+ // break;
+
+ // case 'R':
+ // CHANGING_PROGRAM(MakeResetOnlySelected());
+ // break;
+
+ // case 'E':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
+ // ExportDialog();
+ // } else {
+ // CHANGING_PROGRAM(AddReset());
+ // }
+ // break;
+
+ // case 'S':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
+ // SaveProgram();
+ // UpdateMainWindowTitleBar();
+ // } else {
+ // CHANGING_PROGRAM(MakeSetOnlySelected());
+ // }
+ // break;
+
+ // case 'N':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
+ // if(CheckSaveUserCancels()) break;
+ // if(!ProgramChangedNotSaved) {
+ // int r = MessageBox(MainWindow,
+ // _("Start new program?"),
+ // "LDmicro", MB_YESNO | MB_DEFBUTTON2 |
+ // MB_ICONQUESTION);
+ // if(r == IDNO) break;
+ // }
+ // NewProgram();
+ // strcpy(CurrentSaveFile, "");
+ // strcpy(CurrentCompileFile, "");
+ // GenerateIoListDontLoseSelection();
+ // RefreshScrollbars();
+ // UpdateMainWindowTitleBar();
+ // } else {
+ // CHANGING_PROGRAM(NegateSelected());
+ // }
+ // break;
+
+ // case 'A':
+ // CHANGING_PROGRAM(MakeNormalSelected());
+ // break;
+
+ // case 'T':
+ // CHANGING_PROGRAM(AddTimer(ELEM_RTO));
+ // break;
+
+ // case 'O':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
+ // if(CheckSaveUserCancels()) break;
+ // OpenDialog();
+ // } else {
+ // CHANGING_PROGRAM(AddTimer(ELEM_TON));
+ // }
+ // break;
+
+ // case 'F':
+ // CHANGING_PROGRAM(AddTimer(ELEM_TOF));
+ // break;
+
+ // case 'U':
+ // CHANGING_PROGRAM(AddCounter(ELEM_CTU));
+ // break;
+
+ // case 'I':
+ // CHANGING_PROGRAM(AddCounter(ELEM_CTD));
+ // break;
+
+ // case 'J':
+ // CHANGING_PROGRAM(AddCounter(ELEM_CTC));
+ // break;
+
+ // case 'M':
+ // CHANGING_PROGRAM(AddMove());
+ // break;
+
+ // case 'P':
+ // CHANGING_PROGRAM(AddReadAdc());
+ // break;
+
+ // case VK_OEM_PLUS:
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(AddMath(ELEM_ADD));
+ // } else {
+ // CHANGING_PROGRAM(AddCmp(ELEM_EQU));
+ // }
+ // break;
+
+ // case VK_OEM_MINUS:
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // } else {
+ // CHANGING_PROGRAM(AddMath(ELEM_SUB));
+ // }
+ // break;
+
+ // case '8':
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(AddMath(ELEM_MUL));
+ // }
+ // break;
+
+ // case 'D':
+ // CHANGING_PROGRAM(AddMath(ELEM_DIV));
+ // break;
+
+ // case VK_OEM_PERIOD:
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(AddCmp(ELEM_GRT));
+ // } else {
+ // CHANGING_PROGRAM(AddCmp(ELEM_GEQ));
+ // }
+ // break;
+
+ // case VK_OEM_COMMA:
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(AddCmp(ELEM_LES));
+ // } else {
+ // CHANGING_PROGRAM(AddCmp(ELEM_LEQ));
+ // }
+ // break;
+
+ // case 'V':
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(InsertRung(TRUE));
+ // }
+ // break;
+
+ // case '6':
+ // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
+ // CHANGING_PROGRAM(InsertRung(FALSE));
+ // }
+ // break;
+
+ // case 'Z':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
+ // UndoUndo();
+ // }
+ // break;
+
+ // case 'Y':
+ // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
+ // UndoRedo();
+ // }
+ // break;
+
+ // default:
+ // break;
+ // }
+ // if(wParam != VK_SHIFT && wParam != VK_CONTROL) {
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // }
+ // break;
+ // }
-// case WM_LBUTTONDBLCLK: {
-// int x = LOWORD(lParam);
-// int y = HIWORD(lParam);
-// if(InSimulationMode) {
-// EditElementMouseDoubleclick(x, y);
-// } else {
-// CHANGING_PROGRAM(EditElementMouseDoubleclick(x, y));
-// }
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
-// }
+ // case WM_LBUTTONDBLCLK: {
+ // int x = LOWORD(lParam);
+ // int y = HIWORD(lParam);
+ // if(InSimulationMode) {
+ // EditElementMouseDoubleclick(x, y);
+ // } else {
+ // CHANGING_PROGRAM(EditElementMouseDoubleclick(x, y));
+ // }
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
+ // }
-// case WM_LBUTTONDOWN: {
-// int x = LOWORD(lParam);
-// int y = HIWORD(lParam);
-// if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) {
-// POINT pt;
-// pt.x = x; pt.y = y;
-// ClientToScreen(MainWindow, &pt);
-// MouseY = pt.y;
-// MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL,
-// (HOOKPROC)MouseHook, Instance, 0);
-// }
-// if(!InSimulationMode) MoveCursorMouseClick(x, y);
+ // case WM_LBUTTONDOWN: {
+ // int x = LOWORD(lParam);
+ // int y = HIWORD(lParam);
+ // if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) {
+ // POINT pt;
+ // pt.x = x; pt.y = y;
+ // ClientToScreen(MainWindow, &pt);
+ // MouseY = pt.y;
+ // MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL,
+ // (HOOKPROC)MouseHook, Instance, 0);
+ // }
+ // if(!InSimulationMode) MoveCursorMouseClick(x, y);
-// SetFocus(MainWindow);
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
-// }
-// case WM_MOUSEMOVE: {
-// int x = LOWORD(lParam);
-// int y = HIWORD(lParam);
-
-// if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) {
-// SetCursor(LoadCursor(NULL, IDC_SIZENS));
-// } else {
-// SetCursor(LoadCursor(NULL, IDC_ARROW));
-// }
+ // SetFocus(MainWindow);
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
+ // }
+ // case WM_MOUSEMOVE: {
+ // int x = LOWORD(lParam);
+ // int y = HIWORD(lParam);
+
+ // if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) {
+ // SetCursor(LoadCursor(NULL, IDC_SIZENS));
+ // } else {
+ // SetCursor(LoadCursor(NULL, IDC_ARROW));
+ // }
-// break;
-// }
-// case WM_MOUSEWHEEL: {
-// if((GET_WHEEL_DELTA_WPARAM(wParam)) > 0) {
-// VscrollProc(SB_LINEUP);
-// } else {
-// VscrollProc(SB_LINEDOWN);
-// }
-// break;
-// }
+ // break;
+ // }
+ // case WM_MOUSEWHEEL: {
+ // if((GET_WHEEL_DELTA_WPARAM(wParam)) > 0) {
+ // VscrollProc(SB_LINEUP);
+ // } else {
+ // VscrollProc(SB_LINEDOWN);
+ // }
+ // break;
+ // }
-// case WM_SIZE:
-// MainWindowResized();
-// break;
+ // case WM_SIZE:
+ // MainWindowResized();
+ // break;
-// case WM_NOTIFY: {
-// NMHDR *h = (NMHDR *)lParam;
-// if(h->hwndFrom == IoList) {
-// IoListProc(h);
-// }
-// return 0;
-// }
-// case WM_VSCROLL:
-// VscrollProc(wParam);
-// break;
+ // case WM_NOTIFY: {
+ // NMHDR *h = (NMHDR *)lParam;
+ // if(h->hwndFrom == IoList) {
+ // IoListProc(h);
+ // }
+ // return 0;
+ // }
+ // case WM_VSCROLL:
+ // VscrollProc(wParam);
+ // break;
-// case WM_HSCROLL:
-// HscrollProc(wParam);
-// break;
+ // case WM_HSCROLL:
+ // HscrollProc(wParam);
+ // break;
-// case WM_COMMAND:
-// ProcessMenu(LOWORD(wParam));
-// InvalidateRect(MainWindow, NULL, FALSE);
-// break;
+ // case WM_COMMAND:
+ // ProcessMenu(LOWORD(wParam));
+ // InvalidateRect(MainWindow, NULL, FALSE);
+ // break;
-// case WM_CLOSE:
-// case WM_DESTROY:
-// if(CheckSaveUserCancels()) break;
+ // case WM_CLOSE:
+ // case WM_DESTROY:
+ // if(CheckSaveUserCancels()) break;
-// PostQuitMessage(0);
-// return 1;
+ // PostQuitMessage(0);
+ // return 1;
-// default:
-// return DefWindowProc(hwnd, msg, wParam, lParam);
-// }
+ // default:
+ // return DefWindowProc(hwnd, msg, wParam, lParam);
+ // }
-// return 1;
-// }
+ return 1;
+}
//-----------------------------------------------------------------------------
// Create our window class; nothing exciting.
//-----------------------------------------------------------------------------
-// static BOOL MakeWindowClass()
-// {
-// WNDCLASSEX wc;
-// memset(&wc, 0, sizeof(wc));
-// wc.cbSize = sizeof(wc);
-
-// wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC |
-// CS_DBLCLKS;
-// wc.lpfnWndProc = (WNDPROC)MainWndProc;
-// wc.hInstance = Instance;
-// wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
-// wc.lpszClassName = "LDmicro";
-// wc.lpszMenuName = NULL;
-// wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-// wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
-// IMAGE_ICON, 32, 32, 0);
-// wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
-// IMAGE_ICON, 16, 16, 0);
-
-// return RegisterClassEx(&wc);
-// }
+static BOOL MakeWindowClass()
+{
+ WNDCLASSEX wc;
+ memset(&wc, 0, sizeof(wc));
+ wc.cbSize = sizeof(wc);
+
+ // wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC |
+ // CS_DBLCLKS;
+ // wc.lpfnWndProc = (WNDPROC)MainWndProc;
+ wc.hInstance = NULL;
+ wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+ wc.lpszClassName = "LDmicro";
+ // wc.lpszMenuName = Instance;
+ // wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = (HICON)LoadImage(Instance, LDMICRO_ICON,
+ IMAGE_ICON, 32, 32, 0);
+ wc.hIconSm = (HICON)LoadImage(Instance, LDMICRO_ICON,
+ IMAGE_ICON, 16, 16, 0);//MAKEINTRESOURCE(4000)
+
+ return RegisterClassEx(&wc);
+}
+
void LDMicro_close(HWND window)
{
FreezeWindowPos(MainWindow);
@@ -1101,7 +1102,8 @@ int main(int argc, char** argv)
}
gtk_init(&argc, &argv);
-
+ Instance = NULL;
+ /* TEST
MainWindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(MainWindow), "LDMicro");
g_signal_connect (MainWindow, "delete_event", G_CALLBACK (LDMicro_close), NULL);
@@ -1111,7 +1113,6 @@ int main(int argc, char** argv)
ThawWindowPos(MainWindow);
ThawDWORD(IoListHeight);
- gtk_widget_show(MainWindow);
// Title bar
UpdateMainWindowTitleBar();
@@ -1121,50 +1122,46 @@ int main(int argc, char** argv)
// Calling the Simulation functions
- StartSimulation();
- SetMenusEnabled(true, true, false,
- true, false, false, false,
- true, true, true);
- // ToggleSimulationMode();
+ // StartSimulation(); // test
+ // SetMenusEnabled(true, true, false,
+ // true, false, false, false,
+ // true, true, true); // test
+ // ToggleSimulationMode(); //test
// GenerateIoListDontLoseSelection();
- StopSimulation();
+ StopSimulation(); //Test
+ */
+
+ MainHeap = HeapCreate(0, 1024*64, 0);
+
+ MakeWindowClass();
+ // MakeDialogBoxClass();
+ // MakeComponentListClass();
+ // MakeSmplDialogClass();
+ // MakeNamingListClass();
+ HMENU top = MakeMainWindowMenus();
+
+ /// Make main window
+ // WS_OVERLAPPED | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX |
+ // WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX
+ MainWindow = CreateWindowEx(0, "LDmicro", "",
+ 0,
+ 10, 10, 800, 600, NULL, top, NULL, NULL);
+ g_signal_connect (MainWindow, "delete_event", G_CALLBACK (LDMicro_close), NULL);
+
+ ThawWindowPos(MainWindow);
+ IoListHeight = 100;
+ ThawDWORD(IoListHeight);
- // Displaying the window
- gtk_widget_show_all(MainWindow);
+ // InitCommonControls(); /// NOT USED, Only for windows
+ InitForDrawing();
- gtk_main();
-
- // /// ~~~
- // Instance = hInstance; /// parent window
-
- // MainHeap = HeapCreate(0, 1024*64, 0);
-
- // // MakeWindowClass();
- // // MakeDialogBoxClass();
- // // 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();
+ 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.
+ // We are running interactively, or we would already have exited. We
+ // can therefore show the window now, and otherwise set up the GUI.
// ShowWindow(MainWindow, SW_SHOW);
// SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor);
@@ -1188,9 +1185,9 @@ int main(int argc, char** argv)
// UndoFlush();
// }
- // GenerateIoListDontLoseSelection();
+ // GenerateIoListDontLoseSelection(); ~
// RefreshScrollbars();
- // UpdateMainWindowTitleBar();
+ // UpdateMainWindowTitleBar(); ~
// MSG msg;
// DWORD ret;
@@ -1213,6 +1210,10 @@ int main(int argc, char** argv)
// TranslateMessage(&msg);
// DispatchMessage(&msg);
// }
+
+ // Displaying the window
+ gtk_widget_show_all(MainWindow);
+ gtk_main();
return EXIT_SUCCESS;
} \ No newline at end of file
diff --git a/ldmicro/lib/freezeLD/freezeLD.cpp b/ldmicro/lib/freezeLD/freezeLD.cpp
index 0bbd33f..ea3fae2 100644
--- a/ldmicro/lib/freezeLD/freezeLD.cpp
+++ b/ldmicro/lib/freezeLD/freezeLD.cpp
@@ -19,19 +19,34 @@
void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
{
//g_print("freezing");
- char* moveToKeyLocatin = (char *)malloc(strlen(subKey) + 35);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey);
+ }
+ sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey);
system(moveToKeyLocatin);
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
char *keyName = (char *)malloc(strlen(name) + 30);
if(!keyName)
+ {
+ free(Ld_CWD);
return;
+ }
Key newKey;
@@ -40,7 +55,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_width", name);
std::ofstream Register(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_size(GTK_WINDOW(hwid), &val, NULL);
newKey.type = 'i';
newKey.val.i = val;
@@ -51,7 +70,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_height", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_size(GTK_WINDOW(hwid), NULL, &val);
newKey.type = 'i';
newKey.val.i = val;
@@ -62,7 +85,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_posX", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_position(GTK_WINDOW(hwid), &val, NULL);
newKey.type = 'i';
newKey.val.i = val;
@@ -73,7 +100,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_posY", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_position(GTK_WINDOW(hwid), NULL, &val);
newKey.type = 'i';
newKey.val.i = val;
@@ -84,13 +115,19 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_maximized", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
newKey.type = 'b';
newKey.val.b = gtk_window_is_maximized(GTK_WINDOW(hwid));
Register.write((char*) &newKey, sizeof(newKey));
Register.close();
free(keyName);
+ chdir(Ld_CWD);
+ free(Ld_CWD);
//g_print("freezed");
}
@@ -105,17 +142,33 @@ static void Clamp(LONG *v, LONG min, LONG max)
*/
void ThawWindowPosF(HWID hwid, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
char *keyName = (char *)malloc(strlen(name) + 30);
if(!keyName)
+ {
+ free(Ld_CWD);
return;
+ }
Key newKey1, newKey2;
@@ -123,14 +176,22 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_width", name);
std::ifstream Register(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey1, sizeof(newKey1));
Register.close();
sprintf(keyName, "%s_height", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey2, sizeof(newKey2));
Register.close();
if (newKey1.type == 'i' && newKey2.type == 'i')
@@ -141,14 +202,22 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_posX", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey1, sizeof(newKey1));
Register.close();
sprintf(keyName, "%s_posY", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey2, sizeof(newKey2));
Register.close();
if (newKey1.type == 'i' && newKey2.type == 'i')
@@ -158,7 +227,11 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_maximized", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey1, sizeof(newKey1));
Register.close();
if (newKey1.type == 'b')
@@ -169,6 +242,8 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
/// gtk_window_move handles off-screen window placement
free(keyName);
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}
/*
@@ -176,14 +251,27 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
*/
void FreezeDWORDF(DWORD val, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey);
- system(moveToKeyLocatin);
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey);
+ system(moveToKeyLocatin);
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
Key newKey;
@@ -192,6 +280,9 @@ void FreezeDWORDF(DWORD val, char *subKey, char *name)
std::ofstream Register(name, std::ios::binary | std::ios::trunc);
Register.write((char*) &newKey, sizeof(newKey));
Register.close();
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}
/*
@@ -199,12 +290,25 @@ void FreezeDWORDF(DWORD val, char *subKey, char *name)
*/
DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return val;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return val;
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return val;
+ }
free(moveToKeyLocatin);
Key newKey;
@@ -212,6 +316,10 @@ DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
std::ifstream Register(name, std::ios::binary);
Register.read((char*) &newKey, sizeof(newKey));
Register.close();
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
+
if(Register.bad())
return val;
@@ -226,20 +334,36 @@ DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
*/
void FreezeStringF(char *val, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey);
- system(moveToKeyLocatin);
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey);
+ system(moveToKeyLocatin);
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
std::ofstream Register(name, std::ios::trunc);
Register << strlen(val)+1 << "\n";
Register << val;
Register.close();
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}
/*
@@ -247,19 +371,38 @@ void FreezeStringF(char *val, char *subKey, char *name)
*/
void ThawStringF(char *val, int max, char *subKey, char *name)
{
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
std::ifstream Register(name);
int l;
Register >> l;
if (l >= max)
+ {
+ free(Ld_CWD);
return;
+ }
Register >> val;
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}
diff --git a/ldmicro/lib/freezeLD/freezeLD.h b/ldmicro/lib/freezeLD/freezeLD.h
index f14ef07..5c00504 100644
--- a/ldmicro/lib/freezeLD/freezeLD.h
+++ b/ldmicro/lib/freezeLD/freezeLD.h
@@ -10,7 +10,7 @@
#ifndef __FREEZE_H
#define __FREEZE_H
-#define LDMICRO_REGISTER "/usr/share/ldmicro"
+#define FREEZE_REGISTER "/usr/share/ldmicro"
#define FREEZE_SUBKEY "LDMicro"
diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp
index e4fd018..ce9899b 100644
--- a/ldmicro/lib/linuxUI/linuxLD.cpp
+++ b/ldmicro/lib/linuxUI/linuxLD.cpp
@@ -1,6 +1,7 @@
#include "linuxUI.h"
std::vector<HEAPRECORD> HeapRecords;
+std::vector<WNDCLASSEX> WindClassRecord;
HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
{
@@ -25,7 +26,7 @@ LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
{
if (hHeap == NULL)
{
- printf("Alloc**********NULL HEAP***************\n");
+ // printf("Alloc**********NULL HEAP***************\n");
LPVOID p = malloc(dwBytes);
return p;
}
@@ -73,7 +74,7 @@ BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
/// if NULL free()
if (hHeap == NULL)
{
- printf("free*********NULL HEAP***************\n");
+ // printf("free*********NULL HEAP***************\n");
free(lpMem);
return TRUE;
}
@@ -99,6 +100,27 @@ BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
}
+BOOL RegisterClassEx(const WNDCLASSEX *lpwcx)
+{
+ WindClassRecord.push_back(*lpwcx);
+ return TRUE;
+}
+
+HANDLE LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired,
+ int cyDesired, UINT fuLoad)
+{
+ HICON pixbuf;
+ GError *error = NULL;
+ pixbuf = gdk_pixbuf_new_from_file(lpszName, &error);
+
+ if(!pixbuf) {
+ fprintf(stderr, "%s\n", error->message);
+ g_error_free(error);
+ }
+
+ return (HANDLE) pixbuf;
+}
+
void OutputDebugString(char* str)
{
@@ -111,4 +133,4 @@ double GetTickCount(void)
// if (clock_gettime(CLOCK_MONOTONIC, &now))
// return 0;
return 10.2;//now.tv_sec * 1000.0 + now.tv_nsec / 1000000.0;
-} \ No newline at end of file
+}
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 062bc49..25d42bb 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -17,6 +17,10 @@
#define HEAP_ZERO_MEMORY 0x00000008
+/// Image loading flags
+#define IMAGE_ICON 1
+#define LDMICRO_ICON "ldmicro.ico"
+
/// Typedefs
//typedef int64_t __int64;
typedef bool BOOL;
@@ -31,6 +35,7 @@ typedef char CHAR;
typedef CONST WCHAR *LPCWSTR;
typedef CONST CHAR *LPCSTR; /// should be __nullterminated
+typedef WORD ATOM;
#ifdef UNICODE
typedef LPCWSTR LPCTSTR;
@@ -52,18 +57,18 @@ typedef void *LPVOID;
typedef PVOID HFONT;
typedef PVOID HMODULE;
typedef PVOID HHOOK;
-typedef PVOID HBRUSH;
+
typedef PVOID HFONT;
typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
typedef HANDLE HDC;
-
-typedef GtkWidget* HWID;
-typedef GtkWidget* HMENU;
-typedef GtkWindow* HWND;
-typedef GtkListStore* HLIST;
-typedef GtkApplication* HAPP;
-
+typedef GtkWidget *HWID;
+typedef GtkWidget *HMENU;
+typedef GtkWindow *HWND;
+typedef GtkListStore *HLIST;
+typedef GtkApplication *HAPP;
+typedef GtkTreeViewColumn *HTVC;
+typedef GdkPixbuf *HICON;
/// Check if system is x64 or x86
#if defined(__UNIX64)
typedef uint64_t UINT_PTR;
@@ -82,26 +87,32 @@ typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;
typedef LONG_PTR LRESULT;
-/// Custom classes
-class COLORREF : public GdkRGBA{
+/// Classes
+typedef class tagColorReferance: public GdkRGBA{
public:
- COLORREF()
+ tagColorReferance()
{
this->red = 0.0;
this->green = 0.0;
this->blue = 0.0;
this->alpha = 1.0;
}
- COLORREF(int r, int g, int b)
+
+ tagColorReferance(int r, int g, int b)
{
this->red = r/255.0;
this->green = g/255.0;
this->blue = b/255.0;
this->alpha = 1.0;
}
-};
-/// Custom structures
+ GdkRGBA* getThis()
+ {
+ return this;
+ }
+} COLORREF, *HBRUSH;
+
+/// Structures
typedef struct HeapRecordChunckTag{
PVOID Chunck;
SIZE_T dwSize;
@@ -132,8 +143,25 @@ typedef struct tagNMHDR {
UINT code;
} NMHDR;
+typedef struct tagWNDCLASSEX {
+ UINT cbSize;
+ UINT style;
+// WNDPROC lpfnWndProc;
+ int cbClsExtra;
+ int cbWndExtra;
+ HINSTANCE hInstance;
+ HICON hIcon;
+// HCURSOR hCursor;
+ HBRUSH hbrBackground;
+ LPCTSTR lpszMenuName;
+ LPCTSTR lpszClassName;
+ HICON hIconSm;
+} WNDCLASSEX, *PWNDCLASSEX;
+
+
/// Variables
extern std::vector<HEAPRECORD> HeapRecord;
+extern std::vector<WNDCLASSEX> WindClassRecord;
/// Functions
HANDLE HeapCreate(
@@ -151,6 +179,17 @@ BOOL HeapFree(
DWORD dwFlags,
LPVOID lpMem);
+BOOL RegisterClassEx(const WNDCLASSEX *lpwcx);
+
+HANDLE LoadImage(
+ HINSTANCE hinst,
+ LPCTSTR lpszName,
+ UINT uType,
+ int cxDesired,
+ int cyDesired,
+ UINT fuLoad
+);
+
/// functions to be ported
void OutputDebugString(char*);
double GetTickCount(void);
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 1033f07..c20dec1 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -11,8 +11,8 @@ GtkAccelGroup* AccelGroup;
GClosure* closure;
/// ListStore
-GtkWidget* view;
-GtkTreeViewColumn* column;
+HWID view;
+HTVC column;
/// Wraper function for gtk_window_has_toplevel_focus
BOOL isFocus(HWID window)
@@ -22,15 +22,28 @@ BOOL isFocus(HWID window)
COLORREF RGB(int red, int green, int blue)
{
- COLORREF col;
- col.red = red/255.0;
- col.green = green/255.0;
- col.blue = blue/255.0;
- col.alpha = 1.0;
+ COLORREF col(red, green, blue);
+ // col.red = red/255.0;
+ // col.green = green/255.0;
+ // col.blue = blue/255.0;
+ // col.alpha = 1.0;
return col;
}
+HBRUSH GetStockObject(int fnObject)
+{
+ switch(fnObject)
+ {
+ case BLACK_BRUSH:
+ return new COLORREF(0, 0, 0);
+ break;
+
+ default:
+ return new COLORREF(255, 255, 255);
+ }
+}
+
int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags)
{
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
@@ -156,7 +169,8 @@ BOOL GetSaveFileName(OPENFILENAME *ofn)
return exitStatus;
}
-void EnableMenuItem(HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem) {
+void EnableMenuItem(HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem)
+{
switch (CheckEnabledItem){
case MF_ENABLED :
gtk_widget_set_sensitive (MenuItem, true);
@@ -167,7 +181,8 @@ void EnableMenuItem(HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem) {
}
}
-void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check){
+void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check)
+{
switch (Check){
case MF_CHECKED :
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(MenuItem), true);
@@ -176,4 +191,26 @@ void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check){
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(MenuItem), false);
break;
}
+}
+
+HWID CreateWindowEx(DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName,
+ DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent,
+ HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
+{
+
+ auto WinClR_it = std::find_if(WindClassRecord.begin(), WindClassRecord.end(), [&lpClassName](WNDCLASSEX &Record) { return Record.lpszClassName == lpClassName; });
+
+ if (WinClR_it == WindClassRecord.end())
+ return NULL;
+
+ HWID window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), lpWindowName);
+ gtk_window_set_default_size (GTK_WINDOW(window), nWidth, nHeight);
+ gtk_window_resize (GTK_WINDOW(window), nWidth, nHeight);
+ gtk_window_move(GTK_WINDOW(window), x, y);
+ gtk_widget_override_background_color(GTK_WIDGET(window), GTK_STATE_FLAG_NORMAL, WinClR_it->hbrBackground->getThis());
+ gtk_window_set_default_icon(WinClR_it->hIcon);
+ gtk_window_set_icon(GTK_WINDOW(window), WinClR_it->hIcon);
+
+ return window;
} \ No newline at end of file
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index ff56863..4ddf164 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -10,6 +10,8 @@
#include <stdlib.h>
#include "linuxLD.h"
+// 4000 ICON "ldmicro.ico"
+
/// version control
#define LDMicro_VERSION_MAJOR 1
#define LDMicro_VERSION_MINOR 0
@@ -36,6 +38,9 @@
#define OFN_HIDEREADONLY 0x00000200L
#define OFN_OVERWRITEPROMPT 0x00000400L
+/// window brushes
+#define BLACK_BRUSH 0x00000401L
+
/// EnableMenuItem variables
extern const UINT MF_ENABLED;
extern const UINT MF_GRAYED;
@@ -48,7 +53,7 @@ extern GClosure* closure;
/// ListStore
-extern GtkWidget* view;
+extern GtkWidget *view;
extern GtkTreeViewColumn *column;
/// data types
@@ -70,5 +75,21 @@ int MessageBox(HWID, char*, char*, UINT);
BOOL GetSaveFileName(OPENFILENAME* );
void EnableMenuItem(HMENU, HMENU, UINT);
void CheckMenuItem(HMENU, HMENU, UINT);
+HBRUSH GetStockObject(int fnObject);
+
+HWID CreateWindowEx(
+ DWORD dwExStyle,
+ LPCTSTR lpClassName,
+ LPCTSTR lpWindowName,
+ DWORD dwStyle,
+ int x,
+ int y,
+ int nWidth,
+ int nHeight,
+ HWND hWndParent,
+ HMENU hMenu,
+ HINSTANCE hInstance,
+ LPVOID lpParam
+);
#endif \ No newline at end of file
diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp
index acb6ac2..9a3d737 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -517,9 +517,9 @@ HMENU MakeMainWindowMenus(void)
//-----------------------------------------------------------------------------
void MakeMainWindowControls(void)
{
- GtkWidget* PackBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- GtkWidget* grid = gtk_grid_new();
- GtkWidget* pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
+ HWID PackBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ HWID grid = gtk_grid_new();
+ HWID pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
IoList = gtk_list_store_new (5,
G_TYPE_STRING,
diff --git a/ldmicro/reg/go.bat b/ldmicro/reg/go.bat
deleted file mode 100644
index 5338cea..0000000
--- a/ldmicro/reg/go.bat
+++ /dev/null
@@ -1 +0,0 @@
-@perl run-tests.pl
diff --git a/ldmicro/reg/run-tests.pl b/ldmicro/reg/run-tests.pl
index 91e81b8..94d5ed0 100644
--- a/ldmicro/reg/run-tests.pl
+++ b/ldmicro/reg/run-tests.pl
@@ -12,7 +12,7 @@ for $test (<tests/*.ld>) {
unlink $output;
- $cmd = "../ldmicro.exe /c $test $output";
+ $cmd = "../build/LDMicro /c $test $output";
system $cmd;
$c++;
}