From 7eafe025a1b57cac75d9881c235681212616f19e Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 27 Jun 2018 10:04:58 +0530 Subject: Added keyboard hook. --- ldmicro/ldmicro.cpp | 304 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index d2b54b5..c7a78d3 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -641,6 +641,309 @@ cmp: // return 1; // } +gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + /* Handles: + * WM_KEYDOWN + */ + // g_print("ky call\n"); + switch(event->key.state) + { + case GDK_SHIFT_MASK: + g_print("SHIFT+"); + break; + case GDK_CONTROL_MASK: + g_print("CONTROL+"); + break; + } + + g_print("%c\n", (char)gdk_keyval_to_unicode(event->key.keyval)); + + // 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; + // 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; + // g_print("ky call end\n"); + return FALSE; +} + void LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) { /* Handles: @@ -1188,6 +1491,7 @@ int main(int argc, char** argv) /// Keyboard and mouse hooks equivalent to MainWndProc g_signal_connect (MainWindow, "delete_event", G_CALLBACK (LD_WM_Close_call), NULL); + g_signal_connect (MainWindow, "key_press_event", G_CALLBACK (LD_WM_KeyDown_call), NULL); g_signal_connect (MainWindow, "button_press_event", G_CALLBACK (LD_GTK_mouse_click_hook), NULL); g_signal_connect (MainWindow, "scroll_event", G_CALLBACK (LD_GTK_mouse_scroll_hook), NULL); g_signal_connect (MainWindow, "motion_notify_event", G_CALLBACK (LD_WM_MouseMove_call), NULL); -- cgit From 2af296bf83d9c3aa432e94f27dbaf2085bebeea3 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 27 Jun 2018 13:35:42 +0530 Subject: Added keyboard integration for cursor movement. --- ldmicro/ldmicro.cpp | 377 ++++++++++-------------------------------- ldmicro/lib/linuxUI/linuxUI.h | 30 ++++ ldmicro/maincontrols.cpp | 3 +- ldmicro/schematic.cpp | 204 +++++++++++------------ 4 files changed, 222 insertions(+), 392 deletions(-) diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index c7a78d3..d1416cf 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -641,306 +641,105 @@ cmp: // return 1; // } -gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { /* Handles: * WM_KEYDOWN */ - // g_print("ky call\n"); - switch(event->key.state) + + UINT wParam = event->keyval; + + if(wParam == VK_TAB) { + // SetFocus(IoList); + gtk_window_set_focus (GTK_WINDOW(MainWindow), view); + // BlinkCursor(0, 0, 0, 0); + + } + + if(InSimulationMode) + { + switch(wParam) + { + case VK_DOWN: + if(ScrollYOffset < ScrollYOffsetMax) + ScrollYOffset++; + RefreshScrollbars(); + gtk_widget_queue_draw(DrawWindow); + break; + + case VK_UP: + if(ScrollYOffset > 0) + ScrollYOffset--; + RefreshScrollbars(); + gtk_widget_queue_draw(DrawWindow); + break; + + case VK_LEFT: + ScrollXOffset -= FONT_WIDTH; + if(ScrollXOffset < 0) + ScrollXOffset = 0; + RefreshScrollbars(); + gtk_widget_queue_draw(DrawWindow); + break; + + case VK_RIGHT: + ScrollXOffset += FONT_WIDTH; + if(ScrollXOffset >= ScrollXOffsetMax) + ScrollXOffset = ScrollXOffsetMax; + RefreshScrollbars(); + gtk_widget_queue_draw(DrawWindow); + break; + + case VK_RETURN: + case VK_ESCAPE: + ToggleSimulationMode(); + break; + } + } + + switch(wParam) { - case GDK_SHIFT_MASK: - g_print("SHIFT+"); + case VK_UP: + if(event->state & GDK_SHIFT_MASK) + { + CHANGING_PROGRAM(PushRungUp()); + } + else + { + MoveCursorKeyboard(wParam); + } + + gtk_widget_queue_draw(DrawWindow); break; - case GDK_CONTROL_MASK: - g_print("CONTROL+"); + + case VK_DOWN: + if(event->state & GDK_SHIFT_MASK) + { + CHANGING_PROGRAM(PushRungDown()); + } + else + { + MoveCursorKeyboard(wParam); + } + + gtk_widget_queue_draw(DrawWindow); break; - } - - g_print("%c\n", (char)gdk_keyval_to_unicode(event->key.keyval)); - // 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 VK_RIGHT: + case VK_LEFT: + MoveCursorKeyboard(wParam); + gtk_widget_queue_draw(DrawWindow); + 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 VK_RETURN: + CHANGING_PROGRAM(EditSelectedElement()); + gtk_widget_queue_draw(DrawWindow); + break; + default: + 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; - // g_print("ky call end\n"); return FALSE; } diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index b1a3d48..53040ec 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -60,6 +60,36 @@ /// PatBlt paint flags #define PATINVERT 0x00000100L +/// Key masks +#define VK_TAB GDK_KEY_Tab + +#define VK_DOWN 65364 +#define VK_UP 65362 +#define VK_LEFT 65361 +#define VK_RIGHT 65363 + +#define VK_NP_DOWN 65433 +#define VK_NP_UP 65431 +#define VK_NP_LEFT 65430 +#define VK_NP_RIGHT 65432 + +#define VK_RETURN GDK_KEY_Return +#define VK_ESCAPE GDK_KEY_Escape +#define VK_F5 GDK_KEY_F5 +#define VK_F1 GDK_KEY_F1 + +#define VK_OEM_PLUS GDK_KEY_plus +#define VK_OEM_MINUS GDK_KEY_minus +#define VK_OEM_PERIOD GDK_KEY_period +#define VK_OEM_COMMA GDK_KEY_comma + +#define VK_DELETE GDK_KEY_Delete +#define VK_NP_DELETE GDK_KEY_KP_Delete + +// #define VK_OEM_1 GDK_KEY_colon // GDK_KEY_semicolon +// #define VK_OEM_2 GDK_KEY_question // GDK_KEY_slash +// #define VK_OEM_5 GDK_KEY_backslash // GDK_KEY_bar + /// Window brushes #define BS_SOLID 0x00000001L #define BS_HOLLOW 0x00000002L diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index 0deaf73..14aa308 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -541,6 +541,7 @@ void MakeMainWindowControls(void) /// Creating a list view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(IoList)); gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (IoList)); + gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE); column = gtk_tree_view_column_new_with_attributes("Name", gtk_cell_renderer_text_new(), @@ -908,7 +909,7 @@ void ToggleSimulationMode(void) EnableMenuItem(TopMenu, Settings, MF_GRAYED); EnableMenuItem(TopMenu, InstructionMenu, MF_GRAYED); EnableMenuItem(TopMenu, Compile, MF_GRAYED); - + CheckMenuItem(SimulateMenu, SimulationModeMenu, MF_CHECKED); ClearSimulationData(); // simulation.cpp, ldmicro.h diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index a53c9c2..e9a6844 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -290,108 +290,108 @@ BOOL MoveCursorTopLeft(void) //----------------------------------------------------------------------------- void MoveCursorKeyboard(int keyCode) { - // if(!Selected || Selected->selectedState == SELECTED_NONE) { - // MoveCursorTopLeft(); - // return; - // } - - // switch(keyCode) { - // case VK_LEFT: { - // if(!Selected || Selected->selectedState == SELECTED_NONE) { - // break; - // } - // if(Selected->selectedState != SELECTED_LEFT) { - // SelectElement(-1, -1, SELECTED_LEFT); - // break; - // } - // if(SelectedWhich == ELEM_COMMENT) break; - // int i, j; - // if(FindSelected(&i, &j)) { - // i--; - // while(i >= 0 && (!VALID_LEAF(DisplayMatrix[i][j]) || - // (DisplayMatrix[i][j] == Selected))) - // { - // i--; - // } - // if(i >= 0) { - // SelectElement(i, j, SELECTED_RIGHT); - // } - // } - // break; - // } - // case VK_RIGHT: { - // if(!Selected || Selected->selectedState == SELECTED_NONE) { - // break; - // } - // if(Selected->selectedState != SELECTED_RIGHT) { - // SelectElement(-1, -1, SELECTED_RIGHT); - // break; - // } - // if(SelectedWhich == ELEM_COMMENT) break; - // int i, j; - // if(FindSelected(&i, &j)) { - // i++; - // while(i < DISPLAY_MATRIX_X_SIZE && - // !VALID_LEAF(DisplayMatrix[i][j])) - // { - // i++; - // } - // if(i != DISPLAY_MATRIX_X_SIZE) { - // SelectElement(i, j, SELECTED_LEFT); - // } - // } - // break; - // } - // case VK_UP: { - // if(!Selected || Selected->selectedState == SELECTED_NONE) { - // break; - // } - // if(Selected->selectedState != SELECTED_ABOVE && - // SelectedWhich != ELEM_PLACEHOLDER) - // { - // SelectElement(-1, -1, SELECTED_ABOVE); - // break; - // } - // int i, j; - // if(FindSelected(&i, &j)) { - // j--; - // while(j >= 0 && !VALID_LEAF(DisplayMatrix[i][j])) - // j--; - // if(j >= 0) { - // SelectElement(i, j, SELECTED_BELOW); - // } - // } - // break; - // } - // case VK_DOWN: { - // if(!Selected || Selected->selectedState == SELECTED_NONE) { - // break; - // } - // if(Selected->selectedState != SELECTED_BELOW && - // SelectedWhich != ELEM_PLACEHOLDER) - // { - // SelectElement(-1, -1, SELECTED_BELOW); - // break; - // } - // int i, j; - // if(FindSelected(&i, &j)) { - // j++; - // while(j < DISPLAY_MATRIX_Y_SIZE && - // !VALID_LEAF(DisplayMatrix[i][j])) - // { - // j++; - // } - // if(j != DISPLAY_MATRIX_Y_SIZE) { - // SelectElement(i, j, SELECTED_ABOVE); - // } else if(ScrollYOffsetMax - ScrollYOffset < 3) { - // // special case: scroll the end marker into view - // ScrollYOffset = ScrollYOffsetMax; - // RefreshScrollbars(); - // } - // } - // break; - // } - // } + if(!Selected || Selected->selectedState == SELECTED_NONE) { + MoveCursorTopLeft(); + return; + } + + switch(keyCode) { + case VK_LEFT: { + if(!Selected || Selected->selectedState == SELECTED_NONE) { + break; + } + if(Selected->selectedState != SELECTED_LEFT) { + SelectElement(-1, -1, SELECTED_LEFT); + break; + } + if(SelectedWhich == ELEM_COMMENT) break; + int i, j; + if(FindSelected(&i, &j)) { + i--; + while(i >= 0 && (!VALID_LEAF(DisplayMatrix[i][j]) || + (DisplayMatrix[i][j] == Selected))) + { + i--; + } + if(i >= 0) { + SelectElement(i, j, SELECTED_RIGHT); + } + } + break; + } + case VK_RIGHT: { + if(!Selected || Selected->selectedState == SELECTED_NONE) { + break; + } + if(Selected->selectedState != SELECTED_RIGHT) { + SelectElement(-1, -1, SELECTED_RIGHT); + break; + } + if(SelectedWhich == ELEM_COMMENT) break; + int i, j; + if(FindSelected(&i, &j)) { + i++; + while(i < DISPLAY_MATRIX_X_SIZE && + !VALID_LEAF(DisplayMatrix[i][j])) + { + i++; + } + if(i != DISPLAY_MATRIX_X_SIZE) { + SelectElement(i, j, SELECTED_LEFT); + } + } + break; + } + case VK_UP: { + if(!Selected || Selected->selectedState == SELECTED_NONE) { + break; + } + if(Selected->selectedState != SELECTED_ABOVE && + SelectedWhich != ELEM_PLACEHOLDER) + { + SelectElement(-1, -1, SELECTED_ABOVE); + break; + } + int i, j; + if(FindSelected(&i, &j)) { + j--; + while(j >= 0 && !VALID_LEAF(DisplayMatrix[i][j])) + j--; + if(j >= 0) { + SelectElement(i, j, SELECTED_BELOW); + } + } + break; + } + case VK_DOWN: { + if(!Selected || Selected->selectedState == SELECTED_NONE) { + break; + } + if(Selected->selectedState != SELECTED_BELOW && + SelectedWhich != ELEM_PLACEHOLDER) + { + SelectElement(-1, -1, SELECTED_BELOW); + break; + } + int i, j; + if(FindSelected(&i, &j)) { + j++; + while(j < DISPLAY_MATRIX_Y_SIZE && + !VALID_LEAF(DisplayMatrix[i][j])) + { + j++; + } + if(j != DISPLAY_MATRIX_Y_SIZE) { + SelectElement(i, j, SELECTED_ABOVE); + } else if(ScrollYOffsetMax - ScrollYOffset < 3) { + // special case: scroll the end marker into view + ScrollYOffset = ScrollYOffsetMax; + RefreshScrollbars(); + } + } + break; + } + } } //----------------------------------------------------------------------------- -- cgit From d02d387ca89ffdb070f56bf263a35729b205ca77 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 27 Jun 2018 13:42:05 +0530 Subject: Removed unused code. --- ldmicro/ldmicro.cpp | 56 ++++++++++------------------------------------------- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index d1416cf..cd65ed8 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -595,52 +595,8 @@ cmp: } //----------------------------------------------------------------------------- -// WndProc for MainWindow. +// WndProc functions for MainWindow. //----------------------------------------------------------------------------- -// LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -// { -// // switch (msg) { -// // case WM_ERASEBKGND: -// // break; - -// // case WM_SETFOCUS: - -// // case WM_PAINT: { -// // } - -// // case WM_KEYDOWN: { -// // } - -// // case WM_LBUTTONDBLCLK: { -// // } - -// // case WM_LBUTTONDOWN: { -// // } -// // case WM_MOUSEMOVE: { -// // } -// // case WM_MOUSEWHEEL: { -// // } - -// // case WM_SIZE: - -// // case WM_NOTIFY: { - -// // case WM_VSCROLL: - -// // case WM_HSCROLL: - -// // case WM_COMMAND: - -// // case WM_CLOSE: -// // case WM_DESTROY: - -// // default: -// // return DefWindowProc(hwnd, msg, wParam, lParam); -// // } - -// return 1; -// } - gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { /* Handles: @@ -871,7 +827,15 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_ // SetCursor(LoadCursor(NULL, IDC_ARROW)); // } - // break; + // int dy = MouseY - mhs->pt.y; + + // int dy = MouseY - mhs->pt.y; + + // IoListHeight += dy; + // if(IoListHeight < 50) IoListHeight = 50; + // MouseY = mhs->pt.y; + // MainWindowResized(); + return FALSE; } -- cgit From 2df93eeac5ef7550e750fc894c1ff789f3034bc9 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 27 Jun 2018 13:50:30 +0530 Subject: Minor bugfixes --- ldmicro/ldmicro.cpp | 9 -- ldmicro/schematic.cpp | 243 +++++++++++++++++++++++++------------------------- 2 files changed, 121 insertions(+), 131 deletions(-) diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index cd65ed8..be02fd5 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -732,17 +732,8 @@ gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer us int x = event->button.x; int y = event->button.y - 30 + gtk_adjustment_get_value(adjustment); - // if((y > (IoListTop - 9)) && (y < (IoListTop + 3))) { - // // POINT pt; - // // pt.x = x; pt.y = y; - // // ClientToScreen(MainWindow, &pt); - // MouseY = y; //pt.y; - // // MouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, - // // (HOOKPROC)MouseHook, Instance, 0); - // } if(!InSimulationMode) MoveCursorMouseClick(x, y); - // SetFocus(MainWindow); gtk_widget_queue_draw(DrawWindow); } break; diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index e9a6844..f47a568 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -401,103 +401,103 @@ void MoveCursorKeyboard(int keyCode) void EditSelectedElement(void) { - ShowLookUpTableDialog(Selected); - // ShowContactsDialog(&(Selected->d.contacts.negated),Selected->d.contacts.name); - -// if(!Selected || Selected->selectedState == SELECTED_NONE) return; - -// switch(SelectedWhich) { -// case ELEM_COMMENT: -// ShowCommentDialog(Selected->d.comment.str); -// break; - -// case ELEM_CONTACTS: -// ShowContactsDialog(&(Selected->d.contacts.negated), -// Selected->d.contacts.name); -// break; - -// case ELEM_COIL: -// ShowCoilDialog(&(Selected->d.coil.negated), -// &(Selected->d.coil.setOnly), &(Selected->d.coil.resetOnly), -// Selected->d.coil.name); -// break; - -// case ELEM_TON: -// case ELEM_TOF: -// case ELEM_RTO: -// ShowTimerDialog(SelectedWhich, &(Selected->d.timer.delay), -// Selected->d.timer.name); -// break; - -// case ELEM_CTU: -// case ELEM_CTD: -// case ELEM_CTC: -// ShowCounterDialog(SelectedWhich, &(Selected->d.counter.max), -// Selected->d.counter.name); -// break; - -// case ELEM_EQU: -// case ELEM_NEQ: -// case ELEM_GRT: -// case ELEM_GEQ: -// case ELEM_LES: -// case ELEM_LEQ: -// ShowCmpDialog(SelectedWhich, Selected->d.cmp.op1, -// Selected->d.cmp.op2); -// break; - -// case ELEM_ADD: -// case ELEM_SUB: -// case ELEM_MUL: -// case ELEM_DIV: -// ShowMathDialog(SelectedWhich, Selected->d.math.dest, -// Selected->d.math.op1, Selected->d.math.op2); -// break; - -// case ELEM_RES: -// ShowResetDialog(Selected->d.reset.name); -// break; - -// case ELEM_MOVE: -// ShowMoveDialog(Selected->d.move.dest, Selected->d.move.src); -// break; - -// case ELEM_SET_PWM: -// ShowSetPwmDialog(Selected->d.setPwm.name, -// &(Selected->d.setPwm.targetFreq)); -// break; - -// case ELEM_READ_ADC: -// ShowReadAdcDialog(Selected->d.readAdc.name+1); -// break; - -// case ELEM_UART_RECV: -// case ELEM_UART_SEND: -// ShowUartDialog(SelectedWhich, Selected->d.uart.name); -// break; - -// case ELEM_PERSIST: -// ShowPersistDialog(Selected->d.persist.var); -// break; - -// case ELEM_SHIFT_REGISTER: -// ShowShiftRegisterDialog(Selected->d.shiftRegister.name, -// &(Selected->d.shiftRegister.stages)); -// break; - -// case ELEM_FORMATTED_STRING: -// ShowFormattedStringDialog(Selected->d.fmtdStr.var, -// Selected->d.fmtdStr.string); -// break; - -// case ELEM_PIECEWISE_LINEAR: -// ShowPiecewiseLinearDialog(Selected); -// break; - -// case ELEM_LOOK_UP_TABLE: -// ShowLookUpTableDialog(Selected); -// break; -// } + + ShowContactsDialog(&(Selected->d.contacts.negated),Selected->d.contacts.name); + + if(!Selected || Selected->selectedState == SELECTED_NONE) return; + + switch(SelectedWhich) { + case ELEM_COMMENT: + // ShowCommentDialog(Selected->d.comment.str); + break; + + case ELEM_CONTACTS: + // ShowContactsDialog(&(Selected->d.contacts.negated), + // Selected->d.contacts.name); + break; + + case ELEM_COIL: + // ShowCoilDialog(&(Selected->d.coil.negated), + // &(Selected->d.coil.setOnly), &(Selected->d.coil.resetOnly), + // Selected->d.coil.name); + break; + + case ELEM_TON: + case ELEM_TOF: + case ELEM_RTO: + // ShowTimerDialog(SelectedWhich, &(Selected->d.timer.delay), + // Selected->d.timer.name); + break; + + case ELEM_CTU: + case ELEM_CTD: + case ELEM_CTC: + // ShowCounterDialog(SelectedWhich, &(Selected->d.counter.max), + // Selected->d.counter.name); + break; + + case ELEM_EQU: + case ELEM_NEQ: + case ELEM_GRT: + case ELEM_GEQ: + case ELEM_LES: + case ELEM_LEQ: + // ShowCmpDialog(SelectedWhich, Selected->d.cmp.op1, + // Selected->d.cmp.op2); + break; + + case ELEM_ADD: + case ELEM_SUB: + case ELEM_MUL: + case ELEM_DIV: + // ShowMathDialog(SelectedWhich, Selected->d.math.dest, + // Selected->d.math.op1, Selected->d.math.op2); + break; + + case ELEM_RES: + // ShowResetDialog(Selected->d.reset.name); + break; + + case ELEM_MOVE: + // ShowMoveDialog(Selected->d.move.dest, Selected->d.move.src); + break; + + case ELEM_SET_PWM: + // ShowSetPwmDialog(Selected->d.setPwm.name, + // &(Selected->d.setPwm.targetFreq)); + break; + + case ELEM_READ_ADC: + // ShowReadAdcDialog(Selected->d.readAdc.name+1); + break; + + case ELEM_UART_RECV: + case ELEM_UART_SEND: + // ShowUartDialog(SelectedWhich, Selected->d.uart.name); + break; + + case ELEM_PERSIST: + // ShowPersistDialog(Selected->d.persist.var); + break; + + case ELEM_SHIFT_REGISTER: + // ShowShiftRegisterDialog(Selected->d.shiftRegister.name, + // &(Selected->d.shiftRegister.stages)); + break; + + case ELEM_FORMATTED_STRING: + // ShowFormattedStringDialog(Selected->d.fmtdStr.var, + // Selected->d.fmtdStr.string); + break; + + case ELEM_PIECEWISE_LINEAR: + // ShowPiecewiseLinearDialog(Selected); + break; + + case ELEM_LOOK_UP_TABLE: + ShowLookUpTableDialog(Selected); + break; + } } //----------------------------------------------------------------------------- @@ -509,31 +509,30 @@ void EditSelectedElement(void) //----------------------------------------------------------------------------- void EditElementMouseDoubleclick(int x, int y) { -// x += ScrollXOffset; - -// y += FONT_HEIGHT/2; - -// int gx = (x - X_PADDING)/(POS_WIDTH*FONT_WIDTH); -// int gy = (y - Y_PADDING)/(POS_HEIGHT*FONT_HEIGHT); - -// gy += ScrollYOffset; - -// if(InSimulationMode) { -// ElemLeaf *l = DisplayMatrix[gx][gy]; -// if(l && DisplayMatrixWhich[gx][gy] == ELEM_CONTACTS) { -// char *name = l->d.contacts.name; -// if(name[0] == 'X') { -// SimulationToggleContact(name); -// } -// } else if(l && DisplayMatrixWhich[gx][gy] == ELEM_READ_ADC) { -// ShowAnalogSliderPopup(l->d.readAdc.name); -// } -// } else { -// if(DisplayMatrix[gx][gy] == Selected) { -// EditSelectedElement(); -// } -// } - EditSelectedElement(); + x += ScrollXOffset; + + y += FONT_HEIGHT/2; + + int gx = (x - X_PADDING)/(POS_WIDTH*FONT_WIDTH); + int gy = (y - Y_PADDING)/(POS_HEIGHT*FONT_HEIGHT); + + gy += ScrollYOffset; + + if(InSimulationMode) { + ElemLeaf *l = DisplayMatrix[gx][gy]; + if(l && DisplayMatrixWhich[gx][gy] == ELEM_CONTACTS) { + char *name = l->d.contacts.name; + if(name[0] == 'X') { + SimulationToggleContact(name); + } + } else if(l && DisplayMatrixWhich[gx][gy] == ELEM_READ_ADC) { + ShowAnalogSliderPopup(l->d.readAdc.name); + } + } else { + if(DisplayMatrix[gx][gy] == Selected) { + EditSelectedElement(); + } + } } //----------------------------------------------------------------------------- -- cgit