summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldmicro/ldmicro.cpp927
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp24
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h57
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp55
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h21
-rw-r--r--ldmicro/maincontrols.cpp6
6 files changed, 605 insertions, 485 deletions
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/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp
index cd53da1..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)
{
@@ -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 831a7c5..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 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 3bebf6d..907cb35 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -7,8 +7,8 @@ const UINT MF_CHECKED = 2;
const UINT MF_UNCHECKED = 3;
/// ListStore
-GtkWidget* view;
-GtkTreeViewColumn* column;
+HWID view;
+HTVC column;
/// Wraper function for gtk_window_has_toplevel_focus
BOOL isFocus(HWID window)
@@ -18,15 +18,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;
@@ -152,7 +165,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);
@@ -163,7 +177,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);
@@ -172,4 +187,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 7cb4d55..4bd6e71 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;
@@ -65,5 +70,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 330d5e1..20cc906 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -411,9 +411,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,