summaryrefslogtreecommitdiff
path: root/ldmicro
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro')
-rw-r--r--ldmicro/ldmicro.cpp377
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h30
-rw-r--r--ldmicro/maincontrols.cpp3
-rw-r--r--ldmicro/schematic.cpp204
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;
+ }
+ }
}
//-----------------------------------------------------------------------------