diff options
author | NatsuDrag9 | 2018-06-18 15:30:37 +0530 |
---|---|---|
committer | GitHub | 2018-06-18 15:30:37 +0530 |
commit | 7cd301a9276a066633f9a566360b9aec80fb134f (patch) | |
tree | 9a8441ab0c4a95c467a5d1f447763d9d90c57227 | |
parent | e830165b756ed21f21e1ced3d7aba556c1de616a (diff) | |
parent | efb4f9c16313b421eb64dd0024b2f17725b0026f (diff) | |
download | LDMicroGtk-7cd301a9276a066633f9a566360b9aec80fb134f.tar.gz LDMicroGtk-7cd301a9276a066633f9a566360b9aec80fb134f.tar.bz2 LDMicroGtk-7cd301a9276a066633f9a566360b9aec80fb134f.zip |
Merge pull request #16 from NatsuDrag9/GUI_port
Gui port
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | ldmicro/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ldmicro/confdialog.cpp | 319 | ||||
-rw-r--r-- | ldmicro/draw.cpp | 1766 | ||||
-rw-r--r-- | ldmicro/draw_outputdev.cpp | 283 | ||||
-rw-r--r-- | ldmicro/includes/ldmicro.h | 223 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 1347 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxLD.cpp | 11 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxLD.h | 54 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 124 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.h | 84 | ||||
-rw-r--r-- | ldmicro/maincontrols.cpp | 955 | ||||
-rw-r--r-- | ldmicro/miscutil.cpp | 3 | ||||
-rw-r--r-- | ldmicro/reg/t.pl | 205 |
14 files changed, 3038 insertions, 2338 deletions
@@ -7,3 +7,4 @@ /ldmicro/reg/results/* /ldmicro/includes/testMain.h LDMicro-linux-Workspace.code-workspace +ldmicro/reg/t.pl diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt index 49668a3..49d8405 100644 --- a/ldmicro/CMakeLists.txt +++ b/ldmicro/CMakeLists.txt @@ -26,6 +26,7 @@ ENDIF (MSVC) IF(UNIX) MESSAGE( STATUS "Initializing.." ) + add_definitions ("-w") add_definitions(-D__UNIX__) add_definitions(-DLDLANG_EN) use_cxx11() diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp index f908893..e7f0c71 100644 --- a/ldmicro/confdialog.cpp +++ b/ldmicro/confdialog.cpp @@ -25,20 +25,27 @@ #include <linuxUI.h> #include <stdio.h> #include <stdlib.h> +#include <iostream> //#include <commctrl.h> - #include "ldmicro.h" -// static HWND ConfDialog; +using namespace std; + +static HWID ConfDialog; -// static HWND CrystalTextbox; -// static HWND CycleTextbox; -// static HWND BaudTextbox; +static HWID CrystalTextbox; +static HWID CycleTextbox; +static HWID BaudTextbox; +static HWID ButtonOk; +static HWID ButtonCancel; static LONG_PTR PrevCrystalProc; static LONG_PTR PrevCycleProc; static LONG_PTR PrevBaudProc; +HWID Grid; +HWID PackingBox; + //----------------------------------------------------------------------------- // Don't allow any characters other than 0-9. in the text boxes. //----------------------------------------------------------------------------- @@ -65,93 +72,81 @@ static LONG_PTR PrevBaudProc; // } static void MakeControls(void) -{ -// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Cycle Time (ms):"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 5, 13, 145, 21, ConfDialog, NULL, Instance, NULL); -// NiceFont(textLabel); - -// CycleTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 155, 12, 85, 21, ConfDialog, NULL, Instance, NULL); -// NiceFont(CycleTextbox); - -// HWND textLabel2 = CreateWindowEx(0, WC_STATIC, -// _("Crystal Frequency (MHz):"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 0, 43, 150, 21, ConfDialog, NULL, Instance, NULL); -// NiceFont(textLabel2); - -// CrystalTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 155, 42, 85, 21, ConfDialog, NULL, Instance, NULL); -// NiceFont(CrystalTextbox); - -// HWND textLabel3 = CreateWindowEx(0, WC_STATIC, _("UART Baud Rate (bps):"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 5, 73, 145, 21, ConfDialog, NULL, Instance, NULL); -// NiceFont(textLabel3); - -// BaudTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 155, 72, 85, 21, ConfDialog, NULL, Instance, NULL); -// NiceFont(BaudTextbox); - -// if(!UartFunctionUsed()) { -// EnableWindow(BaudTextbox, FALSE); -// EnableWindow(textLabel3, FALSE); -// } - -// if(Prog.mcu && (Prog.mcu->whichIsa == ISA_ANSIC || -// Prog.mcu->whichIsa == ISA_INTERPRETED)) -// { -// EnableWindow(CrystalTextbox, FALSE); -// EnableWindow(textLabel2, FALSE); -// } - -// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, -// 258, 11, 70, 23, ConfDialog, NULL, Instance, NULL); -// NiceFont(OkButton); - -// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 258, 41, 70, 23, ConfDialog, NULL, Instance, NULL); -// NiceFont(CancelButton); - -// char explanation[1024] = ""; - -// if(UartFunctionUsed()) { -// if(Prog.mcu && Prog.mcu->uartNeeds.rxPin != 0) { -// sprintf(explanation, -// _("Serial (UART) will use pins %d and %d.\r\n\r\n"), -// Prog.mcu->uartNeeds.rxPin, Prog.mcu->uartNeeds.txPin); -// } else { -// strcpy(explanation, -// _("Please select a micro with a UART.\r\n\r\n")); -// } -// } else { -// strcpy(explanation, _("No serial instructions (UART Send/UART Receive) " -// "are in use; add one to program before setting baud rate.\r\n\r\n") -// ); -// } - -// strcat(explanation, -// _("The cycle time for the 'PLC' runtime generated by LDmicro is user-" -// "configurable. Very short cycle times may not be achievable due " -// "to processor speed constraints, and very long cycle times may not " -// "be achievable due to hardware overflows. Cycle times between 10 ms " -// "and 100 ms will usually be practical.\r\n\r\n" -// "The compiler must know what speed crystal you are using with the " -// "micro to convert between timing in clock cycles and timing in " -// "seconds. A 4 MHz to 20 MHz crystal is typical; check the speed " -// "grade of the part you are using to determine the maximum allowable " -// "clock speed before choosing a crystal.")); - -// HWND textLabel4 = CreateWindowEx(0, WC_STATIC, explanation, -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, -// 11, 104, 310, 400, ConfDialog, NULL, Instance, NULL); -// NiceFont(textLabel4); +{ + // Creating text labels + HWID textLabel = gtk_label_new ("Cycle Time (ms):"); + HWID textLabel2 = gtk_label_new ("Crystal Frequency (MHz):"); + HWID textLabel3 = gtk_label_new ("UART Baud Rate (bps):"); + + // Creating text boxes + CycleTextbox = gtk_entry_new (); + CrystalTextbox = gtk_entry_new (); + BaudTextbox = gtk_entry_new (); + + if(!UartFunctionUsed()) { + gtk_widget_set_sensitive (BaudTextbox, FALSE); + gtk_widget_set_sensitive (textLabel3, FALSE); + } + + if(Prog.mcu && (Prog.mcu->whichIsa == ISA_ANSIC || + Prog.mcu->whichIsa == ISA_INTERPRETED)) + { + gtk_widget_set_sensitive (CrystalTextbox, FALSE); + gtk_widget_set_sensitive (textLabel2, FALSE); + } + + ButtonOk = gtk_button_new_with_label ("OK"); + ButtonCancel = gtk_button_new_with_label ("Cancel"); + + char explanation[1024] = ""; + + if(UartFunctionUsed()) { + if(Prog.mcu && Prog.mcu->uartNeeds.rxPin != 0) { + sprintf(explanation, + _("Serial (UART) will use pins %d and %d.\r\n\r\n"), + Prog.mcu->uartNeeds.rxPin, Prog.mcu->uartNeeds.txPin); + } + else { + strcpy(explanation, + _("Please select a micro with a UART.\r\n\r\n")); + } + } + else { + strcpy(explanation, _("\n No serial instructions (UART Send/UART Receive) \n" + "are in use; add one to program before \n" + "setting baud rate.\r\n\r\n") ); + } + + strcat(explanation, + _("The cycle time for the 'PLC' runtime generated by \n" "LDmicro is user-" + "configurable. Very short cycle \n" "times may not be achievable due " + "to processor \n" "speed constraints, and very long cycle times may \n" + "not be achievable due to hardware overflows. Cycle \n" "times between 10 ms \n" + "and 100 ms will usually be practical.\r\n\r\n" + "The compiler must know what speed crystal you \n" "are using with the " + "micro to convert between timing \n" "in clock cycles and timing in" + "seconds. A 4 MHz to \n" "20 MHz crystal is typical; check the speed " + "grade of \n" "the part you are using to determine the maximum \n" "allowable" + "clock speed before choosing a crystal.\n")); + + HWID textLabel4 = gtk_label_new (explanation); + + // Creating required containers for packing + Grid = gtk_grid_new(); + PackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + gtk_grid_attach (GTK_GRID (Grid), textLabel, 1, 2, 1, 1); + gtk_grid_attach (GTK_GRID (Grid), CycleTextbox, 3, 2, 1, 1); + gtk_grid_attach (GTK_GRID (Grid), ButtonOk, 6, 2, 2, 1); + gtk_grid_attach (GTK_GRID (Grid), textLabel2, 1, 4, 1, 1); + gtk_grid_attach (GTK_GRID (Grid), CrystalTextbox, 3, 4, 1, 1); + gtk_grid_attach (GTK_GRID (Grid), ButtonCancel, 6, 4, 2, 1); + gtk_grid_attach (GTK_GRID (Grid), textLabel3, 1, 6, 1, 1); + gtk_grid_attach (GTK_GRID (Grid), BaudTextbox, 3, 6, 1, 1); + gtk_grid_set_column_spacing (GTK_GRID (Grid), 2); + + gtk_box_pack_start(GTK_BOX(PackingBox), Grid, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(PackingBox), textLabel4, TRUE, TRUE, 0); // // Measure the explanation string, so that we know how to size our window // RECT tr, cr; @@ -180,70 +175,84 @@ static void MakeControls(void) // (LONG_PTR)MyNumberProc); } -void ShowConfDialog(void) -{ -// // The window's height will be resized later, to fit the explanation text. -// ConfDialog = CreateWindowClient(0, "LDmicroDialog", _("PLC Configuration"), -// WS_OVERLAPPED | WS_SYSMENU, -// 100, 100, 0, 0, NULL, NULL, Instance, NULL); - -// MakeControls(); - -// char buf[16]; -// sprintf(buf, "%.1f", (Prog.cycleTime / 1000.0)); -// SendMessage(CycleTextbox, WM_SETTEXT, 0, (LPARAM)buf); - -// sprintf(buf, "%.6f", Prog.mcuClock / 1e6); -// SendMessage(CrystalTextbox, WM_SETTEXT, 0, (LPARAM)buf); - -// sprintf(buf, "%d", Prog.baudRate); -// SendMessage(BaudTextbox, WM_SETTEXT, 0, (LPARAM)buf); - -// EnableWindow(MainWindow, FALSE); -// ShowWindow(ConfDialog, TRUE); -// SetFocus(CycleTextbox); - -// MSG msg; -// DWORD ret; -// DialogDone = FALSE; -// DialogCancel = FALSE; -// while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) { -// if(msg.message == WM_KEYDOWN) { -// if(msg.wParam == VK_RETURN) { -// DialogDone = TRUE; -// break; -// } else if(msg.wParam == VK_ESCAPE) { -// DialogDone = TRUE; -// DialogCancel = TRUE; -// break; -// } -// } - -// if(IsDialogMessage(ConfDialog, &msg)) continue; -// TranslateMessage(&msg); -// DispatchMessage(&msg); -// } - -// if(!DialogCancel) { -// char buf[16]; -// SendMessage(CycleTextbox, WM_GETTEXT, (WPARAM)sizeof(buf), -// (LPARAM)(buf)); -// Prog.cycleTime = (int)(1000*atof(buf) + 0.5); -// if(Prog.cycleTime == 0) { -// Error(_("Zero cycle time not valid; resetting to 10 ms.")); -// Prog.cycleTime = 10000; -// } +void DestroyWindow (GtkWidget* widget, gpointer data){ + gtk_widget_destroy (ConfDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); +} -// SendMessage(CrystalTextbox, WM_GETTEXT, (WPARAM)sizeof(buf), -// (LPARAM)(buf)); -// Prog.mcuClock = (int)(1e6*atof(buf) + 0.5); +void SaveData (GtkWidget* widget, gpointer data){ + char* buf; + + buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY (CycleTextbox))); + Prog.cycleTime = (int)(1000*atof(buf) + 0.5); + if(Prog.cycleTime == 0) { + Error(_("Zero cycle time not valid; resetting to 10 ms.")); + Prog.cycleTime = 10000; + } + + buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY(CrystalTextbox))); + Prog.mcuClock = (int)(1e6*atof(buf) + 0.5); + cout << Prog.mcuClock << "\n"; + + buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY(BaudTextbox))); + Prog.baudRate = atoi(buf); + DestroyWindow (ConfDialog, NULL); +} -// SendMessage(BaudTextbox, WM_GETTEXT, (WPARAM)sizeof(buf), -// (LPARAM)(buf)); -// Prog.baudRate = atoi(buf); -// } +void KeyPress (GtkWidget* widget, GdkEventKey* event, gpointer data){ + if (event -> keyval == GDK_KEY_Return){ + SaveData(NULL, NULL); + DestroyWindow (ConfDialog, NULL); + } + else if (event -> keyval == GDK_KEY_Escape){ + DestroyWindow (ConfDialog, NULL); + } +} -// EnableWindow(MainWindow, TRUE); -// DestroyWindow(ConfDialog); -// return; +void SignalCall () { + g_signal_connect (G_OBJECT (ConfDialog), "key-press-event", + G_CALLBACK(KeyPress), NULL); + g_signal_connect (G_OBJECT (ConfDialog), "key_press_event", + G_CALLBACK(KeyPress), NULL); + g_signal_connect (G_OBJECT (ButtonOk), "clicked", + G_CALLBACK(SaveData), NULL); + g_signal_connect (G_OBJECT (ButtonCancel), "clicked", + G_CALLBACK(DestroyWindow), NULL); } + +void ShowConfDialog(void) +{ + // The window's height will be resized later, to fit the explanation text. + MakeControls(); + GdkEventKey* event; + + ConfDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(ConfDialog), "PLC Configuration"); + gtk_window_set_default_size(GTK_WINDOW(ConfDialog), 200, 250); + gtk_window_set_resizable (GTK_WINDOW (ConfDialog), FALSE); + gtk_container_add(GTK_CONTAINER(ConfDialog), PackingBox); + gtk_widget_add_events (ConfDialog, GDK_KEY_PRESS_MASK); + gtk_widget_add_events (ConfDialog, GDK_BUTTON_PRESS_MASK); + + char buf[16]; + sprintf(buf, "%.1f", (Prog.cycleTime / 1000.0)); + gtk_entry_set_text (GTK_ENTRY (CycleTextbox), buf); + + sprintf(buf, "%.6f", Prog.mcuClock / 1e6); + gtk_entry_set_text (GTK_ENTRY (CrystalTextbox), buf); + + sprintf(buf, "%d", Prog.baudRate); + gtk_entry_set_text (GTK_ENTRY (BaudTextbox), buf); + + gtk_widget_set_sensitive (MainWindow, FALSE); + gtk_widget_grab_focus (CycleTextbox); + gtk_widget_grab_focus (ButtonOk); + gtk_widget_show_all (ConfDialog); + + DialogDone = FALSE; + DialogCancel = FALSE; + + SignalCall(); + + return; +}
\ No newline at end of file diff --git a/ldmicro/draw.cpp b/ldmicro/draw.cpp index ad70101..78232ba 100644 --- a/ldmicro/draw.cpp +++ b/ldmicro/draw.cpp @@ -69,182 +69,182 @@ BOOL ThisHighlighted; // return FALSE; // } -// //----------------------------------------------------------------------------- -// // Determine the width, in leaf element units, of a particular subcircuit. -// // The width of a leaf is 1, the width of a series circuit is the sum of -// // of the widths of its members, and the width of a parallel circuit is -// // the maximum of the widths of its members. -// //----------------------------------------------------------------------------- -// static int CountWidthOfElement(int which, void *elem, int soFar) -// { -// switch(which) { -// case ELEM_PLACEHOLDER: -// case ELEM_OPEN: -// case ELEM_SHORT: -// case ELEM_CONTACTS: -// case ELEM_TON: -// case ELEM_TOF: -// case ELEM_RTO: -// case ELEM_CTU: -// case ELEM_CTD: -// case ELEM_ONE_SHOT_RISING: -// case ELEM_ONE_SHOT_FALLING: -// case ELEM_EQU: -// case ELEM_NEQ: -// case ELEM_GRT: -// case ELEM_GEQ: -// case ELEM_LES: -// case ELEM_LEQ: -// case ELEM_UART_RECV: -// case ELEM_UART_SEND: -// return 1; - -// case ELEM_FORMATTED_STRING: -// return 2; - -// case ELEM_COMMENT: { -// if(soFar != 0) oops(); - -// ElemLeaf *l = (ElemLeaf *)elem; -// char tbuf[MAX_COMMENT_LEN]; - -// strcpy(tbuf, l->d.comment.str); -// char *b = strchr(tbuf, '\n'); - -// int len; -// if(b) { -// *b = '\0'; -// len = max(strlen(tbuf)-1, strlen(b+1)); -// } else { -// len = strlen(tbuf); -// } -// // round up, and allow space for lead-in -// len = (len + 7 + (POS_WIDTH-1)) / POS_WIDTH; -// return max(ColsAvailable, len); -// } -// case ELEM_CTC: -// case ELEM_RES: -// case ELEM_COIL: -// case ELEM_MOVE: -// case ELEM_SHIFT_REGISTER: -// case ELEM_LOOK_UP_TABLE: -// case ELEM_PIECEWISE_LINEAR: -// case ELEM_MASTER_RELAY: -// case ELEM_READ_ADC: -// case ELEM_SET_PWM: -// case ELEM_PERSIST: -// if(ColsAvailable - soFar > 1) { -// return ColsAvailable - soFar; -// } else { -// return 1; -// } - -// case ELEM_ADD: -// case ELEM_SUB: -// case ELEM_MUL: -// case ELEM_DIV: -// if(ColsAvailable - soFar > 2) { -// return ColsAvailable - soFar; -// } else { -// return 2; -// } - -// case ELEM_SERIES_SUBCKT: { -// // total of the width of the members -// int total = 0; -// int i; -// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; -// for(i = 0; i < s->count; i++) { -// total += CountWidthOfElement(s->contents[i].which, -// s->contents[i].d.any, total+soFar); -// } -// return total; -// } - -// case ELEM_PARALLEL_SUBCKT: { -// // greatest of the width of the members -// int max = 0; -// int i; -// ElemSubcktParallel *p = (ElemSubcktParallel *)elem; -// for(i = 0; i < p->count; i++) { -// int w = CountWidthOfElement(p->contents[i].which, -// p->contents[i].d.any, soFar); -// if(w > max) { -// max = w; -// } -// } -// return max; -// } - -// default: -// oops(); -// } -// } - -// //----------------------------------------------------------------------------- -// // Determine the height, in leaf element units, of a particular subcircuit. -// // The height of a leaf is 1, the height of a parallel circuit is the sum of -// // of the heights of its members, and the height of a series circuit is the -// // maximum of the heights of its members. (This is the dual of the width -// // case.) -// //----------------------------------------------------------------------------- -// int CountHeightOfElement(int which, void *elem) -// { -// switch(which) { -// CASE_LEAF -// return 1; - -// case ELEM_PARALLEL_SUBCKT: { -// // total of the height of the members -// int total = 0; -// int i; -// ElemSubcktParallel *s = (ElemSubcktParallel *)elem; -// for(i = 0; i < s->count; i++) { -// total += CountHeightOfElement(s->contents[i].which, -// s->contents[i].d.any); -// } -// return total; -// } - -// case ELEM_SERIES_SUBCKT: { -// // greatest of the height of the members -// int max = 0; -// int i; -// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; -// for(i = 0; i < s->count; i++) { -// int w = CountHeightOfElement(s->contents[i].which, -// s->contents[i].d.any); -// if(w > max) { -// max = w; -// } -// } -// return max; -// } +//----------------------------------------------------------------------------- +// Determine the width, in leaf element units, of a particular subcircuit. +// The width of a leaf is 1, the width of a series circuit is the sum of +// of the widths of its members, and the width of a parallel circuit is +// the maximum of the widths of its members. +//----------------------------------------------------------------------------- +static int CountWidthOfElement(int which, void *elem, int soFar) +{ + switch(which) { + case ELEM_PLACEHOLDER: + case ELEM_OPEN: + case ELEM_SHORT: + case ELEM_CONTACTS: + case ELEM_TON: + case ELEM_TOF: + case ELEM_RTO: + case ELEM_CTU: + case ELEM_CTD: + case ELEM_ONE_SHOT_RISING: + case ELEM_ONE_SHOT_FALLING: + case ELEM_EQU: + case ELEM_NEQ: + case ELEM_GRT: + case ELEM_GEQ: + case ELEM_LES: + case ELEM_LEQ: + case ELEM_UART_RECV: + case ELEM_UART_SEND: + return 1; + + case ELEM_FORMATTED_STRING: + return 2; + + case ELEM_COMMENT: { + if(soFar != 0) oops(); + + ElemLeaf *l = (ElemLeaf *)elem; + char tbuf[MAX_COMMENT_LEN]; + + strcpy(tbuf, l->d.comment.str); + char *b = strchr(tbuf, '\n'); + + int len; + if(b) { + *b = '\0'; + len = max(strlen(tbuf)-1, strlen(b+1)); + } else { + len = strlen(tbuf); + } + // round up, and allow space for lead-in + len = (len + 7 + (POS_WIDTH-1)) / POS_WIDTH; + return max(ColsAvailable, len); + } + case ELEM_CTC: + case ELEM_RES: + case ELEM_COIL: + case ELEM_MOVE: + case ELEM_SHIFT_REGISTER: + case ELEM_LOOK_UP_TABLE: + case ELEM_PIECEWISE_LINEAR: + case ELEM_MASTER_RELAY: + case ELEM_READ_ADC: + case ELEM_SET_PWM: + case ELEM_PERSIST: + if(ColsAvailable - soFar > 1) { + return ColsAvailable - soFar; + } else { + return 1; + } + + case ELEM_ADD: + case ELEM_SUB: + case ELEM_MUL: + case ELEM_DIV: + if(ColsAvailable - soFar > 2) { + return ColsAvailable - soFar; + } else { + return 2; + } + + case ELEM_SERIES_SUBCKT: { + // total of the width of the members + int total = 0; + int i; + ElemSubcktSeries *s = (ElemSubcktSeries *)elem; + for(i = 0; i < s->count; i++) { + total += CountWidthOfElement(s->contents[i].which, + s->contents[i].d.any, total+soFar); + } + return total; + } + + case ELEM_PARALLEL_SUBCKT: { + // greatest of the width of the members + int max = 0; + int i; + ElemSubcktParallel *p = (ElemSubcktParallel *)elem; + for(i = 0; i < p->count; i++) { + int w = CountWidthOfElement(p->contents[i].which, + p->contents[i].d.any, soFar); + if(w > max) { + max = w; + } + } + return max; + } + + default: + oops(); + } +} -// default: -// oops(); -// } -// } +//----------------------------------------------------------------------------- +// Determine the height, in leaf element units, of a particular subcircuit. +// The height of a leaf is 1, the height of a parallel circuit is the sum of +// of the heights of its members, and the height of a series circuit is the +// maximum of the heights of its members. (This is the dual of the width +// case.) +//----------------------------------------------------------------------------- +int CountHeightOfElement(int which, void *elem) +{ + switch(which) { + CASE_LEAF + return 1; + + case ELEM_PARALLEL_SUBCKT: { + // total of the height of the members + int total = 0; + int i; + ElemSubcktParallel *s = (ElemSubcktParallel *)elem; + for(i = 0; i < s->count; i++) { + total += CountHeightOfElement(s->contents[i].which, + s->contents[i].d.any); + } + return total; + } + + case ELEM_SERIES_SUBCKT: { + // greatest of the height of the members + int max = 0; + int i; + ElemSubcktSeries *s = (ElemSubcktSeries *)elem; + for(i = 0; i < s->count; i++) { + int w = CountHeightOfElement(s->contents[i].which, + s->contents[i].d.any); + if(w > max) { + max = w; + } + } + return max; + } + + default: + oops(); + } +} -// //----------------------------------------------------------------------------- -// // Determine the width, in leaf element units, of the widest row of the PLC -// // program (i.e. loop over all the rungs and find the widest). -// //----------------------------------------------------------------------------- -// int ProgCountWidestRow(void) -// { -// int i; -// int max = 0; -// int colsTemp = ColsAvailable; -// ColsAvailable = 0; -// for(i = 0; i < Prog.numRungs; i++) { -// int w = CountWidthOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], 0); -// if(w > max) { -// max = w; -// } -// } -// ColsAvailable = colsTemp; -// return max; -// } +//----------------------------------------------------------------------------- +// Determine the width, in leaf element units, of the widest row of the PLC +// program (i.e. loop over all the rungs and find the widest). +//----------------------------------------------------------------------------- +int ProgCountWidestRow(void) +{ + int i; + int max = 0; + int colsTemp = ColsAvailable; + ColsAvailable = 0; + for(i = 0; i < Prog.numRungs; i++) { + int w = CountWidthOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], 0); + if(w > max) { + max = w; + } + } + ColsAvailable = colsTemp; + return max; +} // //----------------------------------------------------------------------------- // // Draw a vertical wire one leaf element unit high up from (cx, cy), where cx @@ -355,716 +355,716 @@ BOOL ThisHighlighted; // } // } -// //----------------------------------------------------------------------------- -// // Draw a string, centred in the space of a single position, with en dashes on -// // the left and right coloured according to the powered state. Draws on the -// // middle line. -// //----------------------------------------------------------------------------- -// // static void CenterWithWires(int cx, int cy, char *str, BOOL before, BOOL after) -// // { -// // CenterWithWiresWidth(cx, cy, str, before, after, POS_WIDTH); -// // } +//----------------------------------------------------------------------------- +// Draw a string, centred in the space of a single position, with en dashes on +// the left and right coloured according to the powered state. Draws on the +// middle line. +//----------------------------------------------------------------------------- +// static void CenterWithWires(int cx, int cy, char *str, BOOL before, BOOL after) +// { +// CenterWithWiresWidth(cx, cy, str, before, after, POS_WIDTH); +// } -// //----------------------------------------------------------------------------- -// // Draw an end of line element (coil, RES, MOV, etc.). Special things about -// // an end of line element: we must right-justify it. -// //----------------------------------------------------------------------------- -// // static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, -// // BOOL poweredBefore) -// // { -// // int cx0 = *cx, cy0 = *cy; - -// // BOOL poweredAfter = leaf->poweredAfter; - -// // int thisWidth; -// // switch(which) { -// // case ELEM_ADD: -// // case ELEM_SUB: -// // case ELEM_MUL: -// // case ELEM_DIV: -// // thisWidth = 2; -// // break; - -// // default: -// // thisWidth = 1; -// // break; -// // } - -// // NormText(); -// // PoweredText(poweredBefore); -// // while(*cx < (ColsAvailable-thisWidth)*POS_WIDTH) { -// // int gx = *cx/POS_WIDTH; -// // int gy = *cy/POS_HEIGHT; - -// // if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; - -// // if(gx >= DISPLAY_MATRIX_X_SIZE) oops(); -// // DM_BOUNDS(gx, gy); -// // DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; -// // DisplayMatrixWhich[gx][gy] = ELEM_PADDING; - -// // int i; -// // for(i = 0; i < POS_WIDTH; i++) { -// // DrawChars(*cx + i, *cy + (POS_HEIGHT/2), "-"); -// // } -// // *cx += POS_WIDTH; -// // cx0 += POS_WIDTH; -// // } - -// // if(leaf == Selected && !InSimulationMode) { -// // EmphText(); -// // ThisHighlighted = TRUE; -// // } else { -// // ThisHighlighted = FALSE; -// // } - -// // switch(which) { -// // case ELEM_CTC: { -// // char buf[256]; -// // ElemCounter *c = &leaf->d.counter; -// // sprintf(buf, "{\x01""CTC\x02 0:%d}", c->max); - -// // CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); -// // break; -// // } -// // case ELEM_RES: { -// // ElemReset *r = &leaf->d.reset; -// // CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, "{RES}", poweredBefore, poweredAfter); -// // break; -// // } -// // case ELEM_READ_ADC: { -// // ElemReadAdc *r = &leaf->d.readAdc; -// // CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, "{READ ADC}", poweredBefore, -// // poweredAfter); -// // break; -// // } -// // case ELEM_SET_PWM: { -// // ElemSetPwm *s = &leaf->d.setPwm; -// // CenterWithSpaces(*cx, *cy, s->name, poweredAfter, TRUE); -// // char l[50]; -// // if(s->targetFreq >= 100000) { -// // sprintf(l, "{PWM %d kHz}", (s->targetFreq+500)/1000); -// // } else if(s->targetFreq >= 10000) { -// // sprintf(l, "{PWM %.1f kHz}", s->targetFreq/1000.0); -// // } else if(s->targetFreq >= 1000) { -// // sprintf(l, "{PWM %.2f kHz}", s->targetFreq/1000.0); -// // } else { -// // sprintf(l, "{PWM %d Hz}", s->targetFreq); -// // } -// // CenterWithWires(*cx, *cy, l, poweredBefore, -// // poweredAfter); -// // break; -// // } -// // case ELEM_PERSIST: -// // CenterWithSpaces(*cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); -// // break; - -// // case ELEM_MOVE: { -// // char top[256]; -// // char bot[256]; -// // ElemMove *m = &leaf->d.move; - -// // if((strlen(m->dest) > (POS_WIDTH - 9)) || -// // (strlen(m->src) > (POS_WIDTH - 9))) -// // { -// // CenterWithWires(*cx, *cy, TOO_LONG, poweredBefore, -// // poweredAfter); -// // break; -// // } - -// // strcpy(top, "{ }"); -// // memcpy(top+1, m->dest, strlen(m->dest)); -// // top[strlen(m->dest) + 3] = ':'; -// // top[strlen(m->dest) + 4] = '='; - -// // strcpy(bot, "{ \x01MOV\x02}"); -// // memcpy(bot+2, m->src, strlen(m->src)); - -// // CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); -// // CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); -// // break; -// // } -// // case ELEM_MASTER_RELAY: -// // CenterWithWires(*cx, *cy, "{MASTER RLY}", poweredBefore, -// // poweredAfter); -// // break; - -// // case ELEM_SHIFT_REGISTER: { -// // char bot[MAX_NAME_LEN+20]; -// // memset(bot, ' ', sizeof(bot)); -// // bot[0] = '{'; -// // sprintf(bot+2, "%s0..%d", leaf->d.shiftRegister.name, -// // leaf->d.shiftRegister.stages-1); -// // bot[strlen(bot)] = ' '; -// // bot[13] = '}'; -// // bot[14] = '\0'; -// // CenterWithSpaces(*cx, *cy, "{\x01SHIFT REG\x02 }", -// // poweredAfter, FALSE); -// // CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); -// // break; -// // } -// // case ELEM_PIECEWISE_LINEAR: -// // case ELEM_LOOK_UP_TABLE: { -// // char top[MAX_NAME_LEN+20], bot[MAX_NAME_LEN+20]; -// // char *dest, *index, *str; -// // if(which == ELEM_PIECEWISE_LINEAR) { -// // dest = leaf->d.piecewiseLinear.dest; -// // index = leaf->d.piecewiseLinear.index; -// // str = "PWL"; -// // } else { -// // dest = leaf->d.lookUpTable.dest; -// // index = leaf->d.lookUpTable.index; -// // str = "LUT"; -// // } -// // memset(top, ' ', sizeof(top)); -// // top[0] = '{'; -// // sprintf(top+2, "%s :=", dest); -// // top[strlen(top)] = ' '; -// // top[13] = '}'; -// // top[14] = '\0'; -// // CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); -// // memset(bot, ' ', sizeof(bot)); -// // bot[0] = '{'; -// // sprintf(bot+2, " %s[%s]", str, index); -// // bot[strlen(bot)] = ' '; -// // bot[13] = '}'; -// // bot[14] = '\0'; -// // CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); -// // break; -// // } -// // case ELEM_COIL: { -// // char buf[4]; -// // ElemCoil *c = &leaf->d.coil; - -// // buf[0] = '('; -// // if(c->negated) { -// // buf[1] = '/'; -// // } else if(c->setOnly) { -// // buf[1] = 'S'; -// // } else if(c->resetOnly) { -// // buf[1] = 'R'; -// // } else { -// // buf[1] = ' '; -// // } -// // buf[2] = ')'; -// // buf[3] = '\0'; - -// // CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); -// // break; -// // } -// // case ELEM_DIV: -// // case ELEM_MUL: -// // case ELEM_SUB: -// // case ELEM_ADD: { -// // char top[POS_WIDTH*2-3+2]; -// // char bot[POS_WIDTH*2-3]; - -// // memset(top, ' ', sizeof(top)-1); -// // top[0] = '{'; - -// // memset(bot, ' ', sizeof(bot)-1); -// // bot[0] = '{'; - -// // int lt = 1; -// // if(which == ELEM_ADD) { -// // memcpy(top+lt, "\x01""ADD\x02", 5); -// // } else if(which == ELEM_SUB) { -// // memcpy(top+lt, "\x01SUB\x02", 5); -// // } else if(which == ELEM_MUL) { -// // memcpy(top+lt, "\x01MUL\x02", 5); -// // } else if(which == ELEM_DIV) { -// // memcpy(top+lt, "\x01""DIV\x02", 5); -// // } else oops(); - -// // lt += 7; -// // memcpy(top+lt, leaf->d.math.dest, strlen(leaf->d.math.dest)); -// // lt += strlen(leaf->d.math.dest) + 2; -// // top[lt++] = ':'; -// // top[lt++] = '='; - -// // int lb = 2; -// // memcpy(bot+lb, leaf->d.math.op1, strlen(leaf->d.math.op1)); -// // lb += strlen(leaf->d.math.op1) + 1; -// // if(which == ELEM_ADD) { -// // bot[lb++] = '+'; -// // } else if(which == ELEM_SUB) { -// // bot[lb++] = '-'; -// // } else if(which == ELEM_MUL) { -// // bot[lb++] = '*'; -// // } else if(which == ELEM_DIV) { -// // bot[lb++] = '/'; -// // } else oops(); -// // lb++; -// // memcpy(bot+lb, leaf->d.math.op2, strlen(leaf->d.math.op2)); -// // lb += strlen(leaf->d.math.op2); - -// // int l = max(lb, lt - 2); -// // top[l+2] = '}'; top[l+3] = '\0'; -// // bot[l] = '}'; bot[l+1] = '\0'; - -// // int extra = 2*POS_WIDTH - FormattedStrlen(top); -// // PoweredText(poweredAfter); -// // DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, top); -// // CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, -// // 2*POS_WIDTH); - -// // *cx += POS_WIDTH; - -// // break; -// // } -// // default: -// // oops(); -// // break; -// // } - -// // *cx += POS_WIDTH; - -// // return poweredAfter; -// // } +//----------------------------------------------------------------------------- +// Draw an end of line element (coil, RES, MOV, etc.). Special things about +// an end of line element: we must right-justify it. +//----------------------------------------------------------------------------- +// static BOOL DrawEndOfLine(int which, ElemLeaf *leaf, int *cx, int *cy, +// BOOL poweredBefore) +// { +// int cx0 = *cx, cy0 = *cy; -// //----------------------------------------------------------------------------- -// // Draw a leaf element. Special things about a leaf: no need to recurse -// // further, and we must put it into the display matrix. -// //----------------------------------------------------------------------------- -// // static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, -// // BOOL poweredBefore) -// // { -// // int cx0 = *cx, cy0 = *cy; -// // BOOL poweredAfter = leaf->poweredAfter; - -// // switch(which) { -// // case ELEM_COMMENT: { -// // char tbuf[MAX_COMMENT_LEN]; -// // char tlbuf[MAX_COMMENT_LEN+8]; - -// // strcpy(tbuf, leaf->d.comment.str); -// // char *b = strchr(tbuf, '\n'); - -// // if(b) { -// // if(b[-1] == '\r') b[-1] = '\0'; -// // *b = '\0'; -// // sprintf(tlbuf, "\x03 ; %s\x02", tbuf); -// // DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); -// // sprintf(tlbuf, "\x03 ; %s\x02", b+1); -// // DrawChars(*cx, *cy + (POS_HEIGHT/2), tlbuf); -// // } else { -// // sprintf(tlbuf, "\x03 ; %s\x02", tbuf); -// // DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); -// // } - -// // *cx += ColsAvailable*POS_WIDTH; -// // break; -// // } -// // case ELEM_PLACEHOLDER: { -// // NormText(); -// // CenterWithWiresWidth(*cx, *cy, "--", FALSE, FALSE, 2); -// // *cx += POS_WIDTH; -// // break; -// // } -// // case ELEM_CONTACTS: { -// // char buf[4]; -// // ElemContacts *c = &leaf->d.contacts; - -// // buf[0] = ']'; -// // buf[1] = c->negated ? '/' : ' '; -// // buf[2] = '['; -// // buf[3] = '\0'; - -// // CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - -// // *cx += POS_WIDTH; -// // break; -// // } -// // { -// // char *s; -// // case ELEM_EQU: -// // s = "=="; goto cmp; -// // case ELEM_NEQ: -// // s = "/="; goto cmp; -// // case ELEM_GRT: -// // s = ">"; goto cmp; -// // case ELEM_GEQ: -// // s = ">="; goto cmp; -// // case ELEM_LES: -// // s = "<"; goto cmp; -// // case ELEM_LEQ: -// // s = "<="; goto cmp; -// // cmp: -// // char s1[POS_WIDTH+10], s2[POS_WIDTH+10]; -// // int l1, l2, lmax; - -// // l1 = 2 + 1 + strlen(s) + strlen(leaf->d.cmp.op1); -// // l2 = 2 + 1 + strlen(leaf->d.cmp.op2); -// // lmax = max(l1, l2); - -// // if(lmax < POS_WIDTH) { -// // memset(s1, ' ', sizeof(s1)); -// // s1[0] = '['; -// // s1[lmax-1] = ']'; -// // s1[lmax] = '\0'; -// // strcpy(s2, s1); -// // memcpy(s1+1, leaf->d.cmp.op1, strlen(leaf->d.cmp.op1)); -// // memcpy(s1+strlen(leaf->d.cmp.op1)+2, s, strlen(s)); -// // memcpy(s2+2, leaf->d.cmp.op2, strlen(leaf->d.cmp.op2)); -// // } else { -// // strcpy(s1, ""); -// // strcpy(s2, TOO_LONG); -// // } - -// // CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); -// // CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); - -// // *cx += POS_WIDTH; -// // break; -// // } -// // case ELEM_OPEN: -// // CenterWithWires(*cx, *cy, "+ +", poweredBefore, poweredAfter); -// // *cx += POS_WIDTH; -// // break; - -// // case ELEM_SHORT: -// // CenterWithWires(*cx, *cy, "+------+", poweredBefore, poweredAfter); -// // *cx += POS_WIDTH; -// // break; - -// // case ELEM_ONE_SHOT_RISING: -// // case ELEM_ONE_SHOT_FALLING: { -// // char *s1, *s2; -// // if(which == ELEM_ONE_SHOT_RISING) { -// // s1 = " _ "; -// // s2 = "[\x01OSR\x02_/ ]"; -// // } else if(which == ELEM_ONE_SHOT_FALLING) { -// // s1 = " _ "; -// // s2 = "[\x01OSF\x02 \\_]"; -// // } else oops(); - -// // CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); -// // CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); - -// // *cx += POS_WIDTH; -// // break; -// // } -// // case ELEM_CTU: -// // case ELEM_CTD: { -// // char *s; -// // if(which == ELEM_CTU) -// // s = "\x01""CTU\x02"; -// // else if(which == ELEM_CTD) -// // s = "\x01""CTD\x02"; -// // else oops(); - -// // char buf[256]; -// // ElemCounter *c = &leaf->d.counter; -// // sprintf(buf, "[%s >=%d]", s, c->max); - -// // CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - -// // *cx += POS_WIDTH; -// // break; -// // } -// // case ELEM_RTO: -// // case ELEM_TON: -// // case ELEM_TOF: { -// // char *s; -// // if(which == ELEM_TON) -// // s = "\x01TON\x02"; -// // else if(which == ELEM_TOF) -// // s = "\x01TOF\x02"; -// // else if(which == ELEM_RTO) -// // s = "\x01RTO\x02"; -// // else oops(); - -// // char buf[256]; -// // ElemTimer *t = &leaf->d.timer; -// // if(t->delay >= 1000*1000) { -// // sprintf(buf, "[%s %.3f s]", s, t->delay/1000000.0); -// // } else if(t->delay >= 100*1000) { -// // sprintf(buf, "[%s %.1f ms]", s, t->delay/1000.0); -// // } else { -// // sprintf(buf, "[%s %.2f ms]", s, t->delay/1000.0); -// // } - -// // CenterWithSpaces(*cx, *cy, t->name, poweredAfter, TRUE); -// // CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); - -// // *cx += POS_WIDTH; -// // break; -// // } -// // case ELEM_FORMATTED_STRING: { -// // // Careful, string could be longer than fits in our space. -// // char str[POS_WIDTH*2]; -// // memset(str, 0, sizeof(str)); -// // char *srcStr = leaf->d.fmtdStr.string; -// // memcpy(str, srcStr, min(strlen(srcStr), POS_WIDTH*2 - 7)); - -// // char bot[100]; -// // sprintf(bot, "{\"%s\"}", str); - -// // int extra = 2*POS_WIDTH - strlen(leaf->d.fmtdStr.var); -// // PoweredText(poweredAfter); -// // NameText(); -// // DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, -// // leaf->d.fmtdStr.var); -// // BodyText(); - -// // CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, -// // 2*POS_WIDTH); -// // *cx += 2*POS_WIDTH; -// // break; -// // } -// // case ELEM_UART_RECV: -// // case ELEM_UART_SEND: -// // CenterWithWires(*cx, *cy, -// // (which == ELEM_UART_RECV) ? "{UART RECV}" : "{UART SEND}", -// // poweredBefore, poweredAfter); -// // CenterWithSpaces(*cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); -// // *cx += POS_WIDTH; -// // break; - -// // default: -// // poweredAfter = DrawEndOfLine(which, leaf, cx, cy, poweredBefore); -// // break; -// // } - -// // // And now we can enter the element into the display matrix so that the -// // // UI routines know what element is at position (gx, gy) when the user -// // // clicks there, and so that we know where to put the cursor if this -// // // element is selected. - -// // // Don't use original cx0, as an end of line element might be further -// // // along than that. -// // cx0 = *cx - POS_WIDTH; - -// // int gx = cx0/POS_WIDTH; -// // int gy = cy0/POS_HEIGHT; -// // if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; -// // DM_BOUNDS(gx, gy); - -// // DisplayMatrix[gx][gy] = leaf; -// // DisplayMatrixWhich[gx][gy] = which; - -// // int xadj = 0; -// // switch(which) { -// // case ELEM_ADD: -// // case ELEM_SUB: -// // case ELEM_MUL: -// // case ELEM_DIV: -// // case ELEM_FORMATTED_STRING: -// // DM_BOUNDS(gx-1, gy); -// // DisplayMatrix[gx-1][gy] = leaf; -// // DisplayMatrixWhich[gx-1][gy] = which; -// // xadj = POS_WIDTH*FONT_WIDTH; -// // break; -// // } - -// // if(which == ELEM_COMMENT) { -// // int i; -// // for(i = 0; i < ColsAvailable; i++) { -// // DisplayMatrix[i][gy] = leaf; -// // DisplayMatrixWhich[i][gy] = ELEM_COMMENT; -// // } -// // xadj = (ColsAvailable-1)*POS_WIDTH*FONT_WIDTH; -// // } - -// // int x0 = X_PADDING + cx0*FONT_WIDTH; -// // int y0 = Y_PADDING + cy0*FONT_HEIGHT; - -// // if(leaf->selectedState != SELECTED_NONE && leaf == Selected) { -// // SelectionActive = TRUE; -// // } -// // switch(leaf->selectedState) { -// // case SELECTED_LEFT: -// // Cursor.left = x0 + FONT_WIDTH - 4 - xadj; -// // Cursor.top = y0 - FONT_HEIGHT/2; -// // Cursor.width = 2; -// // Cursor.height = POS_HEIGHT*FONT_HEIGHT; -// // break; - -// // case SELECTED_RIGHT: -// // Cursor.left = x0 + (POS_WIDTH-1)*FONT_WIDTH - 5; -// // Cursor.top = y0 - FONT_HEIGHT/2; -// // Cursor.width = 2; -// // Cursor.height = POS_HEIGHT*FONT_HEIGHT; -// // break; - -// // case SELECTED_ABOVE: -// // Cursor.left = x0 + FONT_WIDTH/2 - xadj; -// // Cursor.top = y0 - 2; -// // Cursor.width = (POS_WIDTH-2)*FONT_WIDTH + xadj; -// // Cursor.height = 2; -// // break; - -// // case SELECTED_BELOW: -// // Cursor.left = x0 + FONT_WIDTH/2 - xadj; -// // Cursor.top = y0 + (POS_HEIGHT-1)*FONT_HEIGHT + -// // FONT_HEIGHT/2 - 2; -// // Cursor.width = (POS_WIDTH-2)*(FONT_WIDTH) + xadj; -// // Cursor.height = 2; -// // break; - -// // default: -// // break; -// // } - -// // return poweredAfter; -// // } +// BOOL poweredAfter = leaf->poweredAfter; -// //----------------------------------------------------------------------------- -// // Draw a particular subcircuit with its top left corner at *cx and *cy (in -// // characters). If it is a leaf element then just print it and return; else -// // loop over the elements of the subcircuit and call ourselves recursively. -// // At the end updates *cx and *cy. -// // -// // In simulation mode, returns TRUE the circuit is energized after the given -// // element, else FALSE. This is needed to colour all the wires correctly, -// // since the colouring indicates whether a wire is energized. -// //----------------------------------------------------------------------------- -// // BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) -// // { -// // BOOL poweredAfter; - -// // int cx0 = *cx, cy0 = *cy; -// // ElemLeaf *leaf = (ElemLeaf *)elem; - -// // SetBkColor(Hdc, InSimulationMode ? HighlightColours.simBg : -// // HighlightColours.bg); -// // NormText(); - -// // if(elem == Selected && !InSimulationMode) { -// // EmphText(); -// // ThisHighlighted = TRUE; -// // } else { -// // ThisHighlighted = FALSE; -// // } - -// // switch(which) { -// // case ELEM_SERIES_SUBCKT: { -// // int i; -// // ElemSubcktSeries *s = (ElemSubcktSeries *)elem; -// // poweredAfter = poweredBefore; -// // for(i = 0; i < s->count; i++) { -// // poweredAfter = DrawElement(s->contents[i].which, -// // s->contents[i].d.any, cx, cy, poweredAfter); -// // } -// // break; -// // } -// // case ELEM_PARALLEL_SUBCKT: { -// // int i; -// // ElemSubcktParallel *p = (ElemSubcktParallel *)elem; -// // int widthMax = CountWidthOfElement(which, elem, (*cx)/POS_WIDTH); -// // int heightMax = CountHeightOfElement(which, elem); - -// // poweredAfter = FALSE; - -// // int lowestPowered = -1; -// // int downBy = 0; -// // for(i = 0; i < p->count; i++) { -// // BOOL poweredThis; - -// // poweredThis = DrawElement(p->contents[i].which, -// // p->contents[i].d.any, cx, cy, poweredBefore); - -// // if(InSimulationMode) { -// // if(poweredThis) poweredAfter = TRUE; -// // PoweredText(poweredThis); -// // } - -// // while((*cx - cx0) < widthMax*POS_WIDTH) { -// // int gx = *cx/POS_WIDTH; -// // int gy = *cy/POS_HEIGHT; - -// // if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; - -// // DM_BOUNDS(gx, gy); -// // DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; -// // DisplayMatrixWhich[gx][gy] = ELEM_PADDING; - -// // char buf[256]; -// // int j; -// // for(j = 0; j < POS_WIDTH; j++) { -// // buf[j] = '-'; -// // } -// // buf[j] = '\0'; -// // DrawChars(*cx, *cy + (POS_HEIGHT/2), buf); -// // *cx += POS_WIDTH; -// // } - -// // *cx = cx0; -// // int justDrewHeight = CountHeightOfElement(p->contents[i].which, -// // p->contents[i].d.any); -// // *cy += POS_HEIGHT*justDrewHeight; - -// // downBy += justDrewHeight; -// // if(poweredThis) { -// // lowestPowered = downBy - 1; -// // } -// // } -// // *cx = cx0 + POS_WIDTH*widthMax; -// // *cy = cy0; - -// // int j; -// // BOOL needWire; - -// // if(*cx/POS_WIDTH != ColsAvailable) { -// // needWire = FALSE; -// // for(j = heightMax - 1; j >= 1; j--) { -// // if(j <= lowestPowered) PoweredText(poweredAfter); -// // if(DisplayMatrix[*cx/POS_WIDTH - 1][*cy/POS_HEIGHT + j]) { -// // needWire = TRUE; -// // } -// // if(needWire) VerticalWire(*cx - 1, *cy + j*POS_HEIGHT); -// // } -// // // stupid special case -// // if(lowestPowered == 0 && InSimulationMode) { -// // EmphText(); -// // DrawChars(*cx - 1, *cy + (POS_HEIGHT/2), "+"); -// // } -// // } - -// // PoweredText(poweredBefore); -// // needWire = FALSE; -// // for(j = heightMax - 1; j >= 1; j--) { -// // if(DisplayMatrix[cx0/POS_WIDTH][*cy/POS_HEIGHT + j]) { -// // needWire = TRUE; -// // } -// // if(needWire) VerticalWire(cx0 - 1, *cy + j*POS_HEIGHT); -// // } - -// // break; -// // } -// // default: -// // poweredAfter = DrawLeaf(which, leaf, cx, cy, poweredBefore); -// // break; -// // } - - -// // NormText(); -// // return poweredAfter; -// // } +// int thisWidth; +// switch(which) { +// case ELEM_ADD: +// case ELEM_SUB: +// case ELEM_MUL: +// case ELEM_DIV: +// thisWidth = 2; +// break; -// //----------------------------------------------------------------------------- -// // Draw the rung that signals the end of the program. Kind of useless but -// // do it anyways, for convention. -// //----------------------------------------------------------------------------- -// // void DrawEndRung(int cx, int cy) -// // { -// // int i; -// // char *str = "[END]"; -// // int lead = (POS_WIDTH - strlen(str))/2; -// // ThisHighlighted = TRUE; -// // for(i = 0; i < lead; i++) { -// // DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); -// // } -// // DrawChars(cx + i, cy + (POS_HEIGHT/2), str); -// // i += strlen(str); -// // for(; i < ColsAvailable*POS_WIDTH; i++) { -// // DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); -// // } -// // } +// default: +// thisWidth = 1; +// break; +// } + +// NormText(); +// PoweredText(poweredBefore); +// while(*cx < (ColsAvailable-thisWidth)*POS_WIDTH) { +// int gx = *cx/POS_WIDTH; +// int gy = *cy/POS_HEIGHT; + +// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; + +// if(gx >= DISPLAY_MATRIX_X_SIZE) oops(); +// DM_BOUNDS(gx, gy); +// DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; +// DisplayMatrixWhich[gx][gy] = ELEM_PADDING; + +// int i; +// for(i = 0; i < POS_WIDTH; i++) { +// DrawChars(*cx + i, *cy + (POS_HEIGHT/2), "-"); +// } +// *cx += POS_WIDTH; +// cx0 += POS_WIDTH; +// } + +// if(leaf == Selected && !InSimulationMode) { +// EmphText(); +// ThisHighlighted = TRUE; +// } else { +// ThisHighlighted = FALSE; +// } + +// switch(which) { +// case ELEM_CTC: { +// char buf[256]; +// ElemCounter *c = &leaf->d.counter; +// sprintf(buf, "{\x01""CTC\x02 0:%d}", c->max); + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_RES: { +// ElemReset *r = &leaf->d.reset; +// CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, "{RES}", poweredBefore, poweredAfter); +// break; +// } +// case ELEM_READ_ADC: { +// ElemReadAdc *r = &leaf->d.readAdc; +// CenterWithSpaces(*cx, *cy, r->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, "{READ ADC}", poweredBefore, +// poweredAfter); +// break; +// } +// case ELEM_SET_PWM: { +// ElemSetPwm *s = &leaf->d.setPwm; +// CenterWithSpaces(*cx, *cy, s->name, poweredAfter, TRUE); +// char l[50]; +// if(s->targetFreq >= 100000) { +// sprintf(l, "{PWM %d kHz}", (s->targetFreq+500)/1000); +// } else if(s->targetFreq >= 10000) { +// sprintf(l, "{PWM %.1f kHz}", s->targetFreq/1000.0); +// } else if(s->targetFreq >= 1000) { +// sprintf(l, "{PWM %.2f kHz}", s->targetFreq/1000.0); +// } else { +// sprintf(l, "{PWM %d Hz}", s->targetFreq); +// } +// CenterWithWires(*cx, *cy, l, poweredBefore, +// poweredAfter); +// break; +// } +// case ELEM_PERSIST: +// CenterWithSpaces(*cx, *cy, leaf->d.persist.var, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, "{PERSIST}", poweredBefore, poweredAfter); +// break; + +// case ELEM_MOVE: { +// char top[256]; +// char bot[256]; +// ElemMove *m = &leaf->d.move; + +// if((strlen(m->dest) > (POS_WIDTH - 9)) || +// (strlen(m->src) > (POS_WIDTH - 9))) +// { +// CenterWithWires(*cx, *cy, TOO_LONG, poweredBefore, +// poweredAfter); +// break; +// } + +// strcpy(top, "{ }"); +// memcpy(top+1, m->dest, strlen(m->dest)); +// top[strlen(m->dest) + 3] = ':'; +// top[strlen(m->dest) + 4] = '='; + +// strcpy(bot, "{ \x01MOV\x02}"); +// memcpy(bot+2, m->src, strlen(m->src)); + +// CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_MASTER_RELAY: +// CenterWithWires(*cx, *cy, "{MASTER RLY}", poweredBefore, +// poweredAfter); +// break; + +// case ELEM_SHIFT_REGISTER: { +// char bot[MAX_NAME_LEN+20]; +// memset(bot, ' ', sizeof(bot)); +// bot[0] = '{'; +// sprintf(bot+2, "%s0..%d", leaf->d.shiftRegister.name, +// leaf->d.shiftRegister.stages-1); +// bot[strlen(bot)] = ' '; +// bot[13] = '}'; +// bot[14] = '\0'; +// CenterWithSpaces(*cx, *cy, "{\x01SHIFT REG\x02 }", +// poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_PIECEWISE_LINEAR: +// case ELEM_LOOK_UP_TABLE: { +// char top[MAX_NAME_LEN+20], bot[MAX_NAME_LEN+20]; +// char *dest, *index, *str; +// if(which == ELEM_PIECEWISE_LINEAR) { +// dest = leaf->d.piecewiseLinear.dest; +// index = leaf->d.piecewiseLinear.index; +// str = "PWL"; +// } else { +// dest = leaf->d.lookUpTable.dest; +// index = leaf->d.lookUpTable.index; +// str = "LUT"; +// } +// memset(top, ' ', sizeof(top)); +// top[0] = '{'; +// sprintf(top+2, "%s :=", dest); +// top[strlen(top)] = ' '; +// top[13] = '}'; +// top[14] = '\0'; +// CenterWithSpaces(*cx, *cy, top, poweredAfter, FALSE); +// memset(bot, ' ', sizeof(bot)); +// bot[0] = '{'; +// sprintf(bot+2, " %s[%s]", str, index); +// bot[strlen(bot)] = ' '; +// bot[13] = '}'; +// bot[14] = '\0'; +// CenterWithWires(*cx, *cy, bot, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_COIL: { +// char buf[4]; +// ElemCoil *c = &leaf->d.coil; + +// buf[0] = '('; +// if(c->negated) { +// buf[1] = '/'; +// } else if(c->setOnly) { +// buf[1] = 'S'; +// } else if(c->resetOnly) { +// buf[1] = 'R'; +// } else { +// buf[1] = ' '; +// } +// buf[2] = ')'; +// buf[3] = '\0'; + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); +// break; +// } +// case ELEM_DIV: +// case ELEM_MUL: +// case ELEM_SUB: +// case ELEM_ADD: { +// char top[POS_WIDTH*2-3+2]; +// char bot[POS_WIDTH*2-3]; + +// memset(top, ' ', sizeof(top)-1); +// top[0] = '{'; + +// memset(bot, ' ', sizeof(bot)-1); +// bot[0] = '{'; + +// int lt = 1; +// if(which == ELEM_ADD) { +// memcpy(top+lt, "\x01""ADD\x02", 5); +// } else if(which == ELEM_SUB) { +// memcpy(top+lt, "\x01SUB\x02", 5); +// } else if(which == ELEM_MUL) { +// memcpy(top+lt, "\x01MUL\x02", 5); +// } else if(which == ELEM_DIV) { +// memcpy(top+lt, "\x01""DIV\x02", 5); +// } else oops(); + +// lt += 7; +// memcpy(top+lt, leaf->d.math.dest, strlen(leaf->d.math.dest)); +// lt += strlen(leaf->d.math.dest) + 2; +// top[lt++] = ':'; +// top[lt++] = '='; + +// int lb = 2; +// memcpy(bot+lb, leaf->d.math.op1, strlen(leaf->d.math.op1)); +// lb += strlen(leaf->d.math.op1) + 1; +// if(which == ELEM_ADD) { +// bot[lb++] = '+'; +// } else if(which == ELEM_SUB) { +// bot[lb++] = '-'; +// } else if(which == ELEM_MUL) { +// bot[lb++] = '*'; +// } else if(which == ELEM_DIV) { +// bot[lb++] = '/'; +// } else oops(); +// lb++; +// memcpy(bot+lb, leaf->d.math.op2, strlen(leaf->d.math.op2)); +// lb += strlen(leaf->d.math.op2); + +// int l = max(lb, lt - 2); +// top[l+2] = '}'; top[l+3] = '\0'; +// bot[l] = '}'; bot[l+1] = '\0'; + +// int extra = 2*POS_WIDTH - FormattedStrlen(top); +// PoweredText(poweredAfter); +// DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, top); +// CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, +// 2*POS_WIDTH); + +// *cx += POS_WIDTH; + +// break; +// } +// default: +// oops(); +// break; +// } + +// *cx += POS_WIDTH; + +// return poweredAfter; +// } + +//----------------------------------------------------------------------------- +// Draw a leaf element. Special things about a leaf: no need to recurse +// further, and we must put it into the display matrix. +//----------------------------------------------------------------------------- +// static BOOL DrawLeaf(int which, ElemLeaf *leaf, int *cx, int *cy, +// BOOL poweredBefore) +// { +// int cx0 = *cx, cy0 = *cy; +// BOOL poweredAfter = leaf->poweredAfter; + +// switch(which) { +// case ELEM_COMMENT: { +// char tbuf[MAX_COMMENT_LEN]; +// char tlbuf[MAX_COMMENT_LEN+8]; + +// strcpy(tbuf, leaf->d.comment.str); +// char *b = strchr(tbuf, '\n'); + +// if(b) { +// if(b[-1] == '\r') b[-1] = '\0'; +// *b = '\0'; +// sprintf(tlbuf, "\x03 ; %s\x02", tbuf); +// DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); +// sprintf(tlbuf, "\x03 ; %s\x02", b+1); +// DrawChars(*cx, *cy + (POS_HEIGHT/2), tlbuf); +// } else { +// sprintf(tlbuf, "\x03 ; %s\x02", tbuf); +// DrawChars(*cx, *cy + (POS_HEIGHT/2) - 1, tlbuf); +// } + +// *cx += ColsAvailable*POS_WIDTH; +// break; +// } +// case ELEM_PLACEHOLDER: { +// NormText(); +// CenterWithWiresWidth(*cx, *cy, "--", FALSE, FALSE, 2); +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_CONTACTS: { +// char buf[4]; +// ElemContacts *c = &leaf->d.contacts; + +// buf[0] = ']'; +// buf[1] = c->negated ? '/' : ' '; +// buf[2] = '['; +// buf[3] = '\0'; + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// { +// char *s; +// case ELEM_EQU: +// s = "=="; goto cmp; +// case ELEM_NEQ: +// s = "/="; goto cmp; +// case ELEM_GRT: +// s = ">"; goto cmp; +// case ELEM_GEQ: +// s = ">="; goto cmp; +// case ELEM_LES: +// s = "<"; goto cmp; +// case ELEM_LEQ: +// s = "<="; goto cmp; +// cmp: +// char s1[POS_WIDTH+10], s2[POS_WIDTH+10]; +// int l1, l2, lmax; + +// l1 = 2 + 1 + strlen(s) + strlen(leaf->d.cmp.op1); +// l2 = 2 + 1 + strlen(leaf->d.cmp.op2); +// lmax = max(l1, l2); + +// if(lmax < POS_WIDTH) { +// memset(s1, ' ', sizeof(s1)); +// s1[0] = '['; +// s1[lmax-1] = ']'; +// s1[lmax] = '\0'; +// strcpy(s2, s1); +// memcpy(s1+1, leaf->d.cmp.op1, strlen(leaf->d.cmp.op1)); +// memcpy(s1+strlen(leaf->d.cmp.op1)+2, s, strlen(s)); +// memcpy(s2+2, leaf->d.cmp.op2, strlen(leaf->d.cmp.op2)); +// } else { +// strcpy(s1, ""); +// strcpy(s2, TOO_LONG); +// } + +// CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_OPEN: +// CenterWithWires(*cx, *cy, "+ +", poweredBefore, poweredAfter); +// *cx += POS_WIDTH; +// break; + +// case ELEM_SHORT: +// CenterWithWires(*cx, *cy, "+------+", poweredBefore, poweredAfter); +// *cx += POS_WIDTH; +// break; + +// case ELEM_ONE_SHOT_RISING: +// case ELEM_ONE_SHOT_FALLING: { +// char *s1, *s2; +// if(which == ELEM_ONE_SHOT_RISING) { +// s1 = " _ "; +// s2 = "[\x01OSR\x02_/ ]"; +// } else if(which == ELEM_ONE_SHOT_FALLING) { +// s1 = " _ "; +// s2 = "[\x01OSF\x02 \\_]"; +// } else oops(); + +// CenterWithSpaces(*cx, *cy, s1, poweredAfter, FALSE); +// CenterWithWires(*cx, *cy, s2, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_CTU: +// case ELEM_CTD: { +// char *s; +// if(which == ELEM_CTU) +// s = "\x01""CTU\x02"; +// else if(which == ELEM_CTD) +// s = "\x01""CTD\x02"; +// else oops(); + +// char buf[256]; +// ElemCounter *c = &leaf->d.counter; +// sprintf(buf, "[%s >=%d]", s, c->max); + +// CenterWithSpaces(*cx, *cy, c->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_RTO: +// case ELEM_TON: +// case ELEM_TOF: { +// char *s; +// if(which == ELEM_TON) +// s = "\x01TON\x02"; +// else if(which == ELEM_TOF) +// s = "\x01TOF\x02"; +// else if(which == ELEM_RTO) +// s = "\x01RTO\x02"; +// else oops(); + +// char buf[256]; +// ElemTimer *t = &leaf->d.timer; +// if(t->delay >= 1000*1000) { +// sprintf(buf, "[%s %.3f s]", s, t->delay/1000000.0); +// } else if(t->delay >= 100*1000) { +// sprintf(buf, "[%s %.1f ms]", s, t->delay/1000.0); +// } else { +// sprintf(buf, "[%s %.2f ms]", s, t->delay/1000.0); +// } + +// CenterWithSpaces(*cx, *cy, t->name, poweredAfter, TRUE); +// CenterWithWires(*cx, *cy, buf, poweredBefore, poweredAfter); + +// *cx += POS_WIDTH; +// break; +// } +// case ELEM_FORMATTED_STRING: { +// // Careful, string could be longer than fits in our space. +// char str[POS_WIDTH*2]; +// memset(str, 0, sizeof(str)); +// char *srcStr = leaf->d.fmtdStr.string; +// memcpy(str, srcStr, min(strlen(srcStr), POS_WIDTH*2 - 7)); + +// char bot[100]; +// sprintf(bot, "{\"%s\"}", str); + +// int extra = 2*POS_WIDTH - strlen(leaf->d.fmtdStr.var); +// PoweredText(poweredAfter); +// NameText(); +// DrawChars(*cx + (extra/2), *cy + (POS_HEIGHT/2) - 1, +// leaf->d.fmtdStr.var); +// BodyText(); + +// CenterWithWiresWidth(*cx, *cy, bot, poweredBefore, poweredAfter, +// 2*POS_WIDTH); +// *cx += 2*POS_WIDTH; +// break; +// } +// case ELEM_UART_RECV: +// case ELEM_UART_SEND: +// CenterWithWires(*cx, *cy, +// (which == ELEM_UART_RECV) ? "{UART RECV}" : "{UART SEND}", +// poweredBefore, poweredAfter); +// CenterWithSpaces(*cx, *cy, leaf->d.uart.name, poweredAfter, TRUE); +// *cx += POS_WIDTH; +// break; + +// default: +// poweredAfter = DrawEndOfLine(which, leaf, cx, cy, poweredBefore); +// break; +// } + +// // And now we can enter the element into the display matrix so that the +// // UI routines know what element is at position (gx, gy) when the user +// // clicks there, and so that we know where to put the cursor if this +// // element is selected. + +// // Don't use original cx0, as an end of line element might be further +// // along than that. +// cx0 = *cx - POS_WIDTH; + +// int gx = cx0/POS_WIDTH; +// int gy = cy0/POS_HEIGHT; +// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; +// DM_BOUNDS(gx, gy); + +// DisplayMatrix[gx][gy] = leaf; +// DisplayMatrixWhich[gx][gy] = which; + +// int xadj = 0; +// switch(which) { +// case ELEM_ADD: +// case ELEM_SUB: +// case ELEM_MUL: +// case ELEM_DIV: +// case ELEM_FORMATTED_STRING: +// DM_BOUNDS(gx-1, gy); +// DisplayMatrix[gx-1][gy] = leaf; +// DisplayMatrixWhich[gx-1][gy] = which; +// xadj = POS_WIDTH*FONT_WIDTH; +// break; +// } + +// if(which == ELEM_COMMENT) { +// int i; +// for(i = 0; i < ColsAvailable; i++) { +// DisplayMatrix[i][gy] = leaf; +// DisplayMatrixWhich[i][gy] = ELEM_COMMENT; +// } +// xadj = (ColsAvailable-1)*POS_WIDTH*FONT_WIDTH; +// } + +// int x0 = X_PADDING + cx0*FONT_WIDTH; +// int y0 = Y_PADDING + cy0*FONT_HEIGHT; + +// if(leaf->selectedState != SELECTED_NONE && leaf == Selected) { +// SelectionActive = TRUE; +// } +// switch(leaf->selectedState) { +// case SELECTED_LEFT: +// Cursor.left = x0 + FONT_WIDTH - 4 - xadj; +// Cursor.top = y0 - FONT_HEIGHT/2; +// Cursor.width = 2; +// Cursor.height = POS_HEIGHT*FONT_HEIGHT; +// break; + +// case SELECTED_RIGHT: +// Cursor.left = x0 + (POS_WIDTH-1)*FONT_WIDTH - 5; +// Cursor.top = y0 - FONT_HEIGHT/2; +// Cursor.width = 2; +// Cursor.height = POS_HEIGHT*FONT_HEIGHT; +// break; + +// case SELECTED_ABOVE: +// Cursor.left = x0 + FONT_WIDTH/2 - xadj; +// Cursor.top = y0 - 2; +// Cursor.width = (POS_WIDTH-2)*FONT_WIDTH + xadj; +// Cursor.height = 2; +// break; + +// case SELECTED_BELOW: +// Cursor.left = x0 + FONT_WIDTH/2 - xadj; +// Cursor.top = y0 + (POS_HEIGHT-1)*FONT_HEIGHT + +// FONT_HEIGHT/2 - 2; +// Cursor.width = (POS_WIDTH-2)*(FONT_WIDTH) + xadj; +// Cursor.height = 2; +// break; + +// default: +// break; +// } + +// return poweredAfter; +// } + +//----------------------------------------------------------------------------- +// Draw a particular subcircuit with its top left corner at *cx and *cy (in +// characters). If it is a leaf element then just print it and return; else +// loop over the elements of the subcircuit and call ourselves recursively. +// At the end updates *cx and *cy. +// +// In simulation mode, returns TRUE the circuit is energized after the given +// element, else FALSE. This is needed to colour all the wires correctly, +// since the colouring indicates whether a wire is energized. +//----------------------------------------------------------------------------- +BOOL DrawElement(int which, void *elem, int *cx, int *cy, BOOL poweredBefore) +{ +// BOOL poweredAfter; + +// int cx0 = *cx, cy0 = *cy; +// ElemLeaf *leaf = (ElemLeaf *)elem; + +// SetBkColor(Hdc, InSimulationMode ? HighlightColours.simBg : +// HighlightColours.bg); +// NormText(); + +// if(elem == Selected && !InSimulationMode) { +// EmphText(); +// ThisHighlighted = TRUE; +// } else { +// ThisHighlighted = FALSE; +// } + +// switch(which) { +// case ELEM_SERIES_SUBCKT: { +// int i; +// ElemSubcktSeries *s = (ElemSubcktSeries *)elem; +// poweredAfter = poweredBefore; +// for(i = 0; i < s->count; i++) { +// poweredAfter = DrawElement(s->contents[i].which, +// s->contents[i].d.any, cx, cy, poweredAfter); +// } +// break; +// } +// case ELEM_PARALLEL_SUBCKT: { +// int i; +// ElemSubcktParallel *p = (ElemSubcktParallel *)elem; +// int widthMax = CountWidthOfElement(which, elem, (*cx)/POS_WIDTH); +// int heightMax = CountHeightOfElement(which, elem); + +// poweredAfter = FALSE; + +// int lowestPowered = -1; +// int downBy = 0; +// for(i = 0; i < p->count; i++) { +// BOOL poweredThis; + +// poweredThis = DrawElement(p->contents[i].which, +// p->contents[i].d.any, cx, cy, poweredBefore); + +// if(InSimulationMode) { +// if(poweredThis) poweredAfter = TRUE; +// PoweredText(poweredThis); +// } + +// while((*cx - cx0) < widthMax*POS_WIDTH) { +// int gx = *cx/POS_WIDTH; +// int gy = *cy/POS_HEIGHT; + +// if(CheckBoundsUndoIfFails(gx, gy)) return FALSE; + +// DM_BOUNDS(gx, gy); +// DisplayMatrix[gx][gy] = PADDING_IN_DISPLAY_MATRIX; +// DisplayMatrixWhich[gx][gy] = ELEM_PADDING; + +// char buf[256]; +// int j; +// for(j = 0; j < POS_WIDTH; j++) { +// buf[j] = '-'; +// } +// buf[j] = '\0'; +// DrawChars(*cx, *cy + (POS_HEIGHT/2), buf); +// *cx += POS_WIDTH; +// } + +// *cx = cx0; +// int justDrewHeight = CountHeightOfElement(p->contents[i].which, +// p->contents[i].d.any); +// *cy += POS_HEIGHT*justDrewHeight; + +// downBy += justDrewHeight; +// if(poweredThis) { +// lowestPowered = downBy - 1; +// } +// } +// *cx = cx0 + POS_WIDTH*widthMax; +// *cy = cy0; + +// int j; +// BOOL needWire; + +// if(*cx/POS_WIDTH != ColsAvailable) { +// needWire = FALSE; +// for(j = heightMax - 1; j >= 1; j--) { +// if(j <= lowestPowered) PoweredText(poweredAfter); +// if(DisplayMatrix[*cx/POS_WIDTH - 1][*cy/POS_HEIGHT + j]) { +// needWire = TRUE; +// } +// if(needWire) VerticalWire(*cx - 1, *cy + j*POS_HEIGHT); +// } +// // stupid special case +// if(lowestPowered == 0 && InSimulationMode) { +// EmphText(); +// DrawChars(*cx - 1, *cy + (POS_HEIGHT/2), "+"); +// } +// } + +// PoweredText(poweredBefore); +// needWire = FALSE; +// for(j = heightMax - 1; j >= 1; j--) { +// if(DisplayMatrix[cx0/POS_WIDTH][*cy/POS_HEIGHT + j]) { +// needWire = TRUE; +// } +// if(needWire) VerticalWire(cx0 - 1, *cy + j*POS_HEIGHT); +// } + +// break; +// } +// default: +// poweredAfter = DrawLeaf(which, leaf, cx, cy, poweredBefore); +// break; +// } + + +// NormText(); +// return poweredAfter; +} + +//----------------------------------------------------------------------------- +// Draw the rung that signals the end of the program. Kind of useless but +// do it anyways, for convention. +//----------------------------------------------------------------------------- +void DrawEndRung(int cx, int cy) +{ +// int i; +// char *str = "[END]"; +// int lead = (POS_WIDTH - strlen(str))/2; +// ThisHighlighted = TRUE; +// for(i = 0; i < lead; i++) { +// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); +// } +// DrawChars(cx + i, cy + (POS_HEIGHT/2), str); +// i += strlen(str); +// for(; i < ColsAvailable*POS_WIDTH; i++) { +// DrawChars(cx + i, cy + (POS_HEIGHT/2), "-"); +// } +} diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index e5aeda9..3788ff8 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -179,10 +179,9 @@ static void DrawCharsToScreen(int cx, int cy, char *str) //----------------------------------------------------------------------------- int ScreenColsAvailable(void) { - // RECT r; - // GetClientRect(MainWindow, &r); + int rw = gtk_widget_get_allocated_width (DrawWindow); - // return (r.right - (X_PADDING + X_RIGHT_PADDING)) / (POS_WIDTH*FONT_WIDTH); + return (rw - (X_PADDING + X_RIGHT_PADDING)) / (POS_WIDTH*FONT_WIDTH); } //----------------------------------------------------------------------------- @@ -193,13 +192,13 @@ int ScreenColsAvailable(void) //----------------------------------------------------------------------------- int ScreenRowsAvailable(void) { - // int adj; - // if(ScrollXOffsetMax == 0) { - // adj = 0; - // } else { - // adj = 18; - // } - // return (IoListTop - Y_PADDING - adj) / (POS_HEIGHT*FONT_HEIGHT); + int adj; + if(ScrollXOffsetMax == 0) { + adj = 0; + } else { + adj = 18; + } + return (IoListTop - Y_PADDING - adj) / (POS_HEIGHT*FONT_HEIGHT); } //----------------------------------------------------------------------------- @@ -207,18 +206,43 @@ int ScreenRowsAvailable(void) // cursor should go and fill in coordinates for BlinkCursor. Not allowed to // draw deeper than IoListTop, as we would run in to the I/O listbox. //----------------------------------------------------------------------------- -void PaintWindow(void) +void PaintWindow(HCRDC hcr) { + /* + cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G); + + cairo_select_font_face(cr, "Purisa", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_BOLD); + + cairo_set_font_size(cr, 20); + + cairo_move_to(cr, 20, height / 2.0); + cairo_show_text(cr, "-----------THIS IS A TEST DRAW----------"); + + cairo_fill (cr); + */ + + SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg : + HighlightColours.bg); + + SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum : + HighlightColours.rungNum); + + SelectObject(hcr, FixedWidthFont); + + TextOut(hcr, 5, 100, "-------] [-------------------------------------------------------------------------------------------------------------------------------------------------{RES}-------", 14); // static HBITMAP BackBitmap; // static HDC BackDc; // static int BitmapWidth; - // ok(); + ok(); // RECT r; // GetClientRect(MainWindow, &r); - // int bw = r.right; - // int bh = IoListTop; + + int bw = gtk_widget_get_allocated_width (DrawWindow);// = r.right; + int bh = IoListTop; // HDC paintDc; // if(!BackDc) { @@ -239,103 +263,103 @@ void PaintWindow(void) // fi.right = BitmapWidth; fi.bottom = bh; // FillRect(Hdc, &fi, InSimulationMode ? SimBgBrush : BgBrush); - // // now figure out how we should draw the ladder logic - // ColsAvailable = ProgCountWidestRow(); - // if(ColsAvailable < ScreenColsAvailable()) { - // ColsAvailable = ScreenColsAvailable(); - // } - // memset(DisplayMatrix, 0, sizeof(DisplayMatrix)); - // SelectionActive = FALSE; - // memset(&Cursor, 0, sizeof(Cursor)); - - // DrawChars = DrawCharsToScreen; - - // int i; - // int cy = 0; - // int rowsAvailable = ScreenRowsAvailable(); - // for(i = 0; i < Prog.numRungs; i++) { - // int thisHeight = POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT, - // Prog.rungs[i]); - - // // For speed, there is no need to draw everything all the time, but - // // we still must draw a bit above and below so that the DisplayMatrix - // // is filled in enough to make it possible to reselect using the - // // cursor keys. - // if(((cy + thisHeight) >= (ScrollYOffset - 8)*POS_HEIGHT) && - // (cy < (ScrollYOffset + rowsAvailable + 8)*POS_HEIGHT)) - // { - // SetBkColor(Hdc, InSimulationMode ? HighlightColours.simBg : - // HighlightColours.bg); - // SetTextColor(Hdc, InSimulationMode ? HighlightColours.simRungNum : - // HighlightColours.rungNum); - // SelectObject(Hdc, FixedWidthFont); - // int rung = i + 1; - // int y = Y_PADDING + FONT_HEIGHT*cy; - // int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) - - // POS_HEIGHT*FONT_HEIGHT*ScrollYOffset; - - // if(rung < 10) { - // char r[1] = { rung + '0' }; - // TextOut(Hdc, 8 + FONT_WIDTH, yp, r, 1); - // } else { - // char r[2] = { (rung / 10) + '0', (rung % 10) + '0' }; - // TextOut(Hdc, 8, yp, r, 2); - // } - - // int cx = 0; - // DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy, - // Prog.rungPowered[i]); - // } + /// now figure out how we should draw the ladder logic + ColsAvailable = ProgCountWidestRow(); + if(ColsAvailable < ScreenColsAvailable()) { + ColsAvailable = ScreenColsAvailable(); + } + memset(DisplayMatrix, 0, sizeof(DisplayMatrix)); + SelectionActive = FALSE; + memset(&Cursor, 0, sizeof(Cursor)); + + DrawChars = DrawCharsToScreen; + + int i; + int cy = 0; + int rowsAvailable = ScreenRowsAvailable(); + for(i = 0; i < Prog.numRungs; i++) { + int thisHeight = POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT, + Prog.rungs[i]); + + // For speed, there is no need to draw everything all the time, but + // we still must draw a bit above and below so that the DisplayMatrix + // is filled in enough to make it possible to reselect using the + // cursor keys. + if(((cy + thisHeight) >= (ScrollYOffset - 8)*POS_HEIGHT) && + (cy < (ScrollYOffset + rowsAvailable + 8)*POS_HEIGHT)) + { + SetBkColor(DrawWindow, hcr, InSimulationMode ? HighlightColours.simBg : + HighlightColours.bg); + SetTextColor(hcr, InSimulationMode ? HighlightColours.simRungNum : + HighlightColours.rungNum); + SelectObject(hcr, FixedWidthFont); + int rung = i + 1; + int y = Y_PADDING + FONT_HEIGHT*cy; + int yp = y + FONT_HEIGHT*(POS_HEIGHT/2) - + POS_HEIGHT*FONT_HEIGHT*ScrollYOffset; + + if(rung < 10) { + char r[1] = { rung + '0' }; + TextOut(hcr, 8 + FONT_WIDTH, yp, r, 1); + } else { + char r[2] = { (rung / 10) + '0', (rung % 10) + '0' }; + TextOut(hcr, 8, yp, r, 2); + } + + // int cx = 0; + // // DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy, + // // Prog.rungPowered[i]); + } - // cy += thisHeight; - // cy += POS_HEIGHT; - // } + cy += thisHeight; + cy += POS_HEIGHT; + } // cy -= 2; - // DrawEndRung(0, cy); + // // DrawEndRung(0, cy); // if(SelectedGxAfterNextPaint >= 0) { - // MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint); - // InvalidateRect(MainWindow, NULL, FALSE); - // SelectedGxAfterNextPaint = -1; - // SelectedGyAfterNextPaint = -1; + // // MoveCursorNear(SelectedGxAfterNextPaint, SelectedGyAfterNextPaint); + // // InvalidateRect(MainWindow, NULL, FALSE); + // // SelectedGxAfterNextPaint = -1; + // // SelectedGyAfterNextPaint = -1; // } else if(ScrollSelectedIntoViewAfterNextPaint && Selected) { - // SelectElement(-1, -1, Selected->selectedState); - // ScrollSelectedIntoViewAfterNextPaint = FALSE; - // InvalidateRect(MainWindow, NULL, FALSE); + // // SelectElement(-1, -1, Selected->selectedState); + // // ScrollSelectedIntoViewAfterNextPaint = FALSE; + // // InvalidateRect(MainWindow, NULL, FALSE); // } else { // if(!SelectionActive) { // if(Prog.numRungs > 0) { - // if(MoveCursorTopLeft()) { - // InvalidateRect(MainWindow, NULL, FALSE); - // } + // // if(MoveCursorTopLeft()) { + // // InvalidateRect(MainWindow, NULL, FALSE); + // // } // } // } // } - // // draw the `buses' at either side of the screen - // r.left = X_PADDING - FONT_WIDTH; - // r.top = 0; - // r.right = r.left + 4; - // r.bottom = IoListTop; - // FillRect(Hdc, &r, InSimulationMode ? BusLeftBrush : BusBrush); + // /// draw the `buses' at either side of the screen + // // r.left = X_PADDING - FONT_WIDTH; + // // r.top = 0; + // // r.right = r.left + 4; + // // r.bottom = IoListTop; + // // FillRect(Hdc, &r, InSimulationMode ? BusLeftBrush : BusBrush); - // r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - // r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; - // FillRect(Hdc, &r, InSimulationMode ? BusRightBus : BusBrush); + // // r.left += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; + // // r.right += POS_WIDTH*FONT_WIDTH*ColsAvailable + 2; + // // FillRect(Hdc, &r, InSimulationMode ? BusRightBus : BusBrush); // CursorDrawn = FALSE; - // BitBlt(paintDc, 0, 0, bw, bh, BackDc, ScrollXOffset, 0, SRCCOPY); + // // BitBlt(paintDc, 0, 0, bw, bh, BackDc, ScrollXOffset, 0, SRCCOPY); // if(InSimulationMode) { - // KillTimer(MainWindow, TIMER_BLINK_CURSOR); + // // KillTimer(MainWindow, TIMER_BLINK_CURSOR); // } else { - // KillTimer(MainWindow, TIMER_BLINK_CURSOR); - // BlinkCursor(NULL, 0, NULL, 0); - // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); + // // KillTimer(MainWindow, TIMER_BLINK_CURSOR); + // // BlinkCursor(NULL, 0, NULL, 0); + // // SetTimer(MainWindow, TIMER_BLINK_CURSOR, 800, BlinkCursor); // } - // Hdc = paintDc; + // // Hdc = paintDc; // ok(); } @@ -378,52 +402,39 @@ static void SetSyntaxHighlightingColours(void) //----------------------------------------------------------------------------- void InitForDrawing(void) { - // SetSyntaxHighlightingColours(); - - // FixedWidthFont = CreateFont( - // FONT_HEIGHT, FONT_WIDTH, - // 0, 0, - // FW_REGULAR, - // FALSE, - // FALSE, - // FALSE, - // ANSI_CHARSET, - // OUT_DEFAULT_PRECIS, - // CLIP_DEFAULT_PRECIS, - // DEFAULT_QUALITY, - // FF_DONTCARE, - // "Lucida Console"); - - // FixedWidthFontBold = CreateFont( - // FONT_HEIGHT, FONT_WIDTH, - // 0, 0, - // FW_REGULAR, // the bold text renders funny under Vista - // FALSE, - // FALSE, - // FALSE, - // ANSI_CHARSET, - // OUT_DEFAULT_PRECIS, - // CLIP_DEFAULT_PRECIS, - // DEFAULT_QUALITY, - // FF_DONTCARE, - // "Lucida Console"); - - // LOGBRUSH lb; - // lb.lbStyle = BS_SOLID; - // lb.lbColor = HighlightColours.simBusRight; - // BusRightBus = CreateBrushIndirect(&lb); - - // lb.lbColor = HighlightColours.simBusLeft; - // BusLeftBrush = CreateBrushIndirect(&lb); - - // lb.lbColor = HighlightColours.bus; - // BusBrush = CreateBrushIndirect(&lb); - - // lb.lbColor = HighlightColours.bg; - // BgBrush = CreateBrushIndirect(&lb); - - // lb.lbColor = HighlightColours.simBg; - // SimBgBrush = CreateBrushIndirect(&lb); + DrawWindow = gtk_drawing_area_new (); + SetSyntaxHighlightingColours(); + + FixedWidthFont = CreateFont( + FONT_HEIGHT, FONT_WIDTH, + 0, + FW_REGULAR, + FALSE, + "Lucida Console"); + + FixedWidthFontBold = CreateFont( + FONT_HEIGHT, FONT_WIDTH, + 0, + FW_REGULAR, // the bold text renders funny under Vista + FALSE, + "Lucida Console"); + + LOGBRUSH lb; + lb.lbStyle = BS_SOLID; + lb.lbColor = HighlightColours.simBusRight; + BusRightBus = CreateBrushIndirect(&lb); + + lb.lbColor = HighlightColours.simBusLeft; + BusLeftBrush = CreateBrushIndirect(&lb); + + lb.lbColor = HighlightColours.bus; + BusBrush = CreateBrushIndirect(&lb); + + lb.lbColor = HighlightColours.bg; + BgBrush = CreateBrushIndirect(&lb); + + lb.lbColor = HighlightColours.simBg; + SimBgBrush = CreateBrushIndirect(&lb); } //----------------------------------------------------------------------------- diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 64f16c8..6513078 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -51,79 +51,151 @@ typedef signed long SDWORD; #define NUM_SUPPORTED_MCUS 16 // Menu IDs -extern HMENU MNU_NEW; -extern HMENU MNU_OPEN; -extern HMENU MNU_SAVE; -extern HMENU MNU_SAVE_AS; -extern HMENU MNU_EXPORT; -extern HMENU MNU_EXIT; - -extern HMENU MNU_UNDO; -extern HMENU MNU_REDO; -extern HMENU MNU_PUSH_RUNG_UP; -extern HMENU MNU_PUSH_RUNG_DOWN; -extern HMENU MNU_INSERT_RUNG_BEFORE; -extern HMENU MNU_INSERT_RUNG_AFTER; -extern HMENU MNU_DELETE_ELEMENT; -extern HMENU MNU_DELETE_RUNG; - -extern HMENU MNU_INSERT_COMMENT; -extern HMENU MNU_INSERT_CONTACTS; -extern HMENU MNU_INSERT_COIL; -extern HMENU MNU_INSERT_TON; -extern HMENU MNU_INSERT_TOF; -extern HMENU MNU_INSERT_RTO; -extern HMENU MNU_INSERT_RES; -extern HMENU MNU_INSERT_OSR; -extern HMENU MNU_INSERT_OSF; -extern HMENU MNU_INSERT_CTU; -extern HMENU MNU_INSERT_CTD; -extern HMENU MNU_INSERT_CTC; -extern HMENU MNU_INSERT_ADD; -extern HMENU MNU_INSERT_SUB; -extern HMENU MNU_INSERT_MUL; -extern HMENU MNU_INSERT_DIV; -extern HMENU MNU_INSERT_MOV; -extern HMENU MNU_INSERT_READ_ADC; -extern HMENU MNU_INSERT_SET_PWM; -extern HMENU MNU_INSERT_UART_SEND; -extern HMENU MNU_INSERT_UART_RECV; -extern HMENU MNU_INSERT_EQU; -extern HMENU MNU_INSERT_NEQ; -extern HMENU MNU_INSERT_GRT; -extern HMENU MNU_INSERT_GEQ; -extern HMENU MNU_INSERT_LES; -extern HMENU MNU_INSERT_LEQ; -extern HMENU MNU_INSERT_OPEN; -extern HMENU MNU_INSERT_SHORT; -extern HMENU MNU_INSERT_MASTER_RLY; -extern HMENU MNU_INSERT_SHIFT_REG; -extern HMENU MNU_INSERT_LUT; -extern HMENU MNU_INSERT_FMTD_STR; -extern HMENU MNU_INSERT_PERSIST; -extern HMENU MNU_MAKE_NORMAL; -extern HMENU MNU_NEGATE; -extern HMENU MNU_MAKE_SET_ONLY; -extern HMENU MNU_MAKE_RESET_ONLY; -extern HMENU MNU_INSERT_PWL; - -extern HMENU MNU_MCU_SETTINGS; -extern HMENU MNU_PROCESSOR[NUM_SUPPORTED_MCUS+1]; -extern HMENU MNU_MICRO_CONTROLLER; - -extern HMENU MNU_SIMULATION_MODE; -extern HMENU MNU_START_SIMULATION; -extern HMENU MNU_STOP_SIMULATION; -extern HMENU MNU_SINGLE_CYCLE; - -extern HMENU MNU_COMPILE; -extern HMENU MNU_COMPILE_AS; - -extern HMENU MNU_MANUAL; -extern HMENU MNU_ABOUT; - -extern HMENU MNU_ADV_SIMULATION; - +#define MNU_NEW 0x01 +#define MNU_OPEN 0x02 +#define MNU_SAVE 0x03 +#define MNU_SAVE_AS 0x04 +#define MNU_EXPORT 0x05 +#define MNU_EXIT 0x06 + +#define MNU_UNDO 0x10 +#define MNU_REDO 0x11 +#define MNU_PUSH_RUNG_UP 0x12 +#define MNU_PUSH_RUNG_DOWN 0x13 +#define MNU_INSERT_RUNG_BEFORE 0x14 +#define MNU_INSERT_RUNG_AFTER 0x15 +#define MNU_DELETE_ELEMENT 0x16 +#define MNU_DELETE_RUNG 0x17 + +#define MNU_INSERT_COMMENT 0x20 +#define MNU_INSERT_CONTACTS 0x21 +#define MNU_INSERT_COIL 0x22 +#define MNU_INSERT_TON 0x23 +#define MNU_INSERT_TOF 0x24 +#define MNU_INSERT_RTO 0x25 +#define MNU_INSERT_RES 0x26 +#define MNU_INSERT_OSR 0x27 +#define MNU_INSERT_OSF 0x28 +#define MNU_INSERT_CTU 0x29 +#define MNU_INSERT_CTD 0x2a +#define MNU_INSERT_CTC 0x2b +#define MNU_INSERT_ADD 0x2c +#define MNU_INSERT_SUB 0x2d +#define MNU_INSERT_MUL 0x2e +#define MNU_INSERT_DIV 0x2f +#define MNU_INSERT_MOV 0x30 +#define MNU_INSERT_READ_ADC 0x31 +#define MNU_INSERT_SET_PWM 0x32 +#define MNU_INSERT_UART_SEND 0x33 +#define MNU_INSERT_UART_RECV 0x34 +#define MNU_INSERT_EQU 0x35 +#define MNU_INSERT_NEQ 0x36 +#define MNU_INSERT_GRT 0x37 +#define MNU_INSERT_GEQ 0x38 +#define MNU_INSERT_LES 0x39 +#define MNU_INSERT_LEQ 0x3a +#define MNU_INSERT_OPEN 0x3b +#define MNU_INSERT_SHORT 0x3c +#define MNU_INSERT_MASTER_RLY 0x3d +#define MNU_INSERT_SHIFT_REG 0x3e +#define MNU_INSERT_LUT 0x3f +#define MNU_INSERT_FMTD_STR 0x40 +#define MNU_INSERT_PERSIST 0x41 +#define MNU_MAKE_NORMAL 0x42 +#define MNU_NEGATE 0x43 +#define MNU_MAKE_SET_ONLY 0x44 +#define MNU_MAKE_RESET_ONLY 0x45 +#define MNU_INSERT_PWL 0x46 + +#define MNU_MCU_SETTINGS 0x50 +#define MNU_PROCESSOR_0 0xa0 + +#define MNU_SIMULATION_MODE 0x60 +#define MNU_START_SIMULATION 0x61 +#define MNU_STOP_SIMULATION 0x62 +#define MNU_SINGLE_CYCLE 0x63 + +#define MNU_COMPILE 0x70 +#define MNU_COMPILE_AS 0x71 + +#define MNU_MANUAL 0x80 +#define MNU_ABOUT 0x81 + +// #define MNU_ADV_SIMULATION + +// New menu items here +extern HMENU NewMenu; +extern HMENU OpenMenu; +extern HMENU SaveMenu; +extern HMENU SaveAsMenu; +extern HMENU ExportMenu; +extern HMENU ExitMenu; + +extern HMENU UndoMenu; +extern HMENU RedoMenu; +extern HMENU PushRungUpMenu; +extern HMENU PushRungDownMenu; +extern HMENU InsertRungBeforeMenu; +extern HMENU InsertRungAfterMenu; +extern HMENU DeleteElementMenu; +extern HMENU DeleteRungMenu; + +extern HMENU InsertCommentMenu; +extern HMENU InsertContactsMenu; +extern HMENU InsertCoilMenu; +extern HMENU InsertTonMenu; +extern HMENU InsertTofMenu; +extern HMENU InsertRtoMenu; +extern HMENU InsertResMenu; +extern HMENU InsertOsrMenu; +extern HMENU InsertOsfMenu; +extern HMENU InsertCtuMenu; +extern HMENU InsertCtdMenu; +extern HMENU InsertCtcMenu; +extern HMENU InsertAddMenu; +extern HMENU InsertSubMenu; +extern HMENU InsertMulMenu; +extern HMENU InsertDivMenu; +extern HMENU InsertMovMenu; +extern HMENU InsertReadAdcMenu; +extern HMENU InsertSetPwmMenu; +extern HMENU InsertUartSendMenu; +extern HMENU InsertUartRecvMenu; +extern HMENU InsertEquMenu; +extern HMENU InsertNeqMenu; +extern HMENU InsertGrtMenu; +extern HMENU InsertGeqMenu; +extern HMENU InsertLesMenu; +extern HMENU InsertLeqMenu; +extern HMENU InsertOpenMenu; +extern HMENU InsertShortMenu; +extern HMENU InsertMasterRlyMenu; +extern HMENU InsertShiftRegMenu; +extern HMENU InsertLutMenu; +extern HMENU InsertFmtdStrMenu; +extern HMENU InsertPersistMenu; +extern HMENU MakeNormalMenu; +extern HMENU NegateMenu; +extern HMENU MakeSetOnlyMenu; +extern HMENU MakeResetOnlyMenu; +extern HMENU InsertPwlMenu; + +extern HMENU McuSettingsMenu; +extern HMENU ProcessorMenuItems[NUM_SUPPORTED_MCUS+1]; +extern HMENU MicroControllerMenu; + +extern HMENU SimulationModeMenu; +extern HMENU StartSimulationMenu; +extern HMENU StopSimulationMenu; +extern HMENU SingleCycleMenu; + +extern HMENU CompileMenu; +extern HMENU CompileAsMenu; + +extern HMENU ManualMenu; +extern HMENU AboutMenu; + +// extern HMENU MNU_ADV_SIMULATION; // Columns within the I/O etc. listview. #define LV_IO_NAME 0x00 @@ -516,7 +588,8 @@ void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled); void RefreshScrollbars(void); extern HINSTANCE Instance; extern HWID MainWindow; -extern HDC Hdc; +extern HWID DrawWindow; +extern HCRDC Hdc; extern PlcProgram Prog; extern char CurrentSaveFile[MAX_PATH]; extern char CurrentCompileFile[MAX_PATH]; @@ -560,7 +633,7 @@ 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 PaintWindow(cairo_t *cr); void ExportDrawingAsText(char *file); void InitForDrawing(void); void SetUpScrollbars(BOOL *horizShown, SCROLLINFO *horiz, SCROLLINFO *vert); diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index 6851d9d..c3d84d6 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -31,11 +31,16 @@ #include "ldmicro.h" #include "freezeLD.h" #include "mcutable.h" +#include <iomanip> +#include <iostream> + +using namespace std; HINSTANCE Instance; HWID MainWindow; -HDC Hdc; +HWID DrawWindow; +HCRDC Hdc; // parameters used to capture the mouse when implementing our totally non- // general splitter control @@ -273,17 +278,17 @@ static void CompileProgram(BOOL compileAs) // changed so that we ask if user wants to save before exiting, and update // the I/O list. //----------------------------------------------------------------------------- -// void ProgramChanged(void) -// { -// ProgramChangedNotSaved = TRUE; -// GenerateIoListDontLoseSelection(); -// RefreshScrollbars(); -// } -// #define CHANGING_PROGRAM(x) { \ -// UndoRemember(); \ -// x; \ -// ProgramChanged(); \ -// } +void ProgramChanged(void) +{ + ProgramChangedNotSaved = TRUE; + GenerateIoListDontLoseSelection(); + // RefreshScrollbars(); +} +#define CHANGING_PROGRAM(x) { \ + UndoRemember(); \ + x; \ + ProgramChanged();\ + } //----------------------------------------------------------------------------- // Hook that we install when the user starts dragging the `splitter,' in case @@ -322,155 +327,155 @@ static void CompileProgram(BOOL compileAs) //----------------------------------------------------------------------------- // Handle a selection from the menu bar of the main window. //----------------------------------------------------------------------------- -// static void ProcessMenu(int code) -// { -// if(code >= MNU_PROCESSOR_0 && code < MNU_PROCESSOR_0+NUM_SUPPORTED_MCUS) { -// strcpy(CurrentCompileFile, ""); -// Prog.mcu = &SupportedMcus[code - MNU_PROCESSOR_0]; -// RefreshControlsToSettings(); -// return; -// } -// if(code == MNU_PROCESSOR_0+NUM_SUPPORTED_MCUS) { -// Prog.mcu = NULL; -// strcpy(CurrentCompileFile, ""); -// RefreshControlsToSettings(); -// return; -// } - -// switch(code) { -// case MNU_NEW: -// if(CheckSaveUserCancels()) break; -// NewProgram(); -// strcpy(CurrentSaveFile, ""); -// strcpy(CurrentCompileFile, ""); -// GenerateIoListDontLoseSelection(); -// RefreshScrollbars(); -// UpdateMainWindowTitleBar(); -// break; - -// case MNU_OPEN: -// if(CheckSaveUserCancels()) break; -// OpenDialog(); -// break; - -// case MNU_SAVE: -// SaveProgram(); -// UpdateMainWindowTitleBar(); -// break; - -// case MNU_SAVE_AS: -// SaveAsDialog(); -// UpdateMainWindowTitleBar(); -// break; - -// case MNU_EXPORT: -// ExportDialog(); -// break; - -// case MNU_EXIT: -// if(CheckSaveUserCancels()) break; -// PostQuitMessage(0); -// break; - -// case MNU_INSERT_COMMENT: -// CHANGING_PROGRAM(AddComment(_("--add comment here--"))); -// break; - -// case MNU_INSERT_CONTACTS: -// CHANGING_PROGRAM(AddContact()); -// break; - -// case MNU_INSERT_COIL: -// CHANGING_PROGRAM(AddCoil()); -// break; - -// case MNU_INSERT_TON: -// CHANGING_PROGRAM(AddTimer(ELEM_TON)); -// break; - -// case MNU_INSERT_TOF: -// CHANGING_PROGRAM(AddTimer(ELEM_TOF)); -// break; - -// case MNU_INSERT_RTO: -// CHANGING_PROGRAM(AddTimer(ELEM_RTO)); -// break; - -// case MNU_INSERT_CTU: -// CHANGING_PROGRAM(AddCounter(ELEM_CTU)); -// break; - -// case MNU_INSERT_CTD: -// CHANGING_PROGRAM(AddCounter(ELEM_CTD)); -// break; - -// case MNU_INSERT_CTC: -// CHANGING_PROGRAM(AddCounter(ELEM_CTC)); -// break; - -// case MNU_INSERT_RES: -// CHANGING_PROGRAM(AddReset()); -// break; - -// case MNU_INSERT_OPEN: -// CHANGING_PROGRAM(AddEmpty(ELEM_OPEN)); -// break; - -// case MNU_INSERT_SHORT: -// CHANGING_PROGRAM(AddEmpty(ELEM_SHORT)); -// break; - -// case MNU_INSERT_MASTER_RLY: -// CHANGING_PROGRAM(AddMasterRelay()); -// break; - -// case MNU_INSERT_SHIFT_REG: -// CHANGING_PROGRAM(AddShiftRegister()); -// break; +static void ProcessMenu(int code) +{ + if(code >= MNU_PROCESSOR_0 && code < MNU_PROCESSOR_0+NUM_SUPPORTED_MCUS) { + strcpy(CurrentCompileFile, ""); + Prog.mcu = &SupportedMcus[code - MNU_PROCESSOR_0]; + RefreshControlsToSettings(); + return; + } + if(code == MNU_PROCESSOR_0+NUM_SUPPORTED_MCUS) { + Prog.mcu = NULL; + strcpy(CurrentCompileFile, ""); + RefreshControlsToSettings(); + return; + } -// case MNU_INSERT_LUT: -// CHANGING_PROGRAM(AddLookUpTable()); -// break; + switch(code) { + case MNU_NEW: + // if(CheckSaveUserCancels()) break; + // NewProgram(); + // strcpy(CurrentSaveFile, ""); + // strcpy(CurrentCompileFile, ""); + // GenerateIoListDontLoseSelection(); + // RefreshScrollbars(); + // UpdateMainWindowTitleBar(); + break; + + case MNU_OPEN: + // if(CheckSaveUserCancels()) break; + // OpenDialog(); + break; + + case MNU_SAVE: + // SaveProgram(); + // UpdateMainWindowTitleBar(); + break; + + case MNU_SAVE_AS: + // SaveAsDialog(); + // UpdateMainWindowTitleBar(); + break; + + case MNU_EXPORT: + // ExportDialog(); + break; + + case MNU_EXIT: + // if(CheckSaveUserCancels()) break; + // PostQuitMessage(0); + break; + + case MNU_INSERT_COMMENT: + // CHANGING_PROGRAM(AddComment(_("--add comment here--"))); + break; + + case MNU_INSERT_CONTACTS: + // CHANGING_PROGRAM(AddContact()); + break; + + case MNU_INSERT_COIL: + // CHANGING_PROGRAM(AddCoil()); + break; + + case MNU_INSERT_TON: + // CHANGING_PROGRAM(AddTimer(ELEM_TON)); + break; + + case MNU_INSERT_TOF: + // CHANGING_PROGRAM(AddTimer(ELEM_TOF)); + break; + + case MNU_INSERT_RTO: + // CHANGING_PROGRAM(AddTimer(ELEM_RTO)); + break; + + case MNU_INSERT_CTU: + // CHANGING_PROGRAM(AddCounter(ELEM_CTU)); + break; + + case MNU_INSERT_CTD: + // CHANGING_PROGRAM(AddCounter(ELEM_CTD)); + break; + + case MNU_INSERT_CTC: + // CHANGING_PROGRAM(AddCounter(ELEM_CTC)); + break; + + case MNU_INSERT_RES: + // CHANGING_PROGRAM(AddReset()); + break; + + case MNU_INSERT_OPEN: + // CHANGING_PROGRAM(AddEmpty(ELEM_OPEN)); + break; + + case MNU_INSERT_SHORT: + // CHANGING_PROGRAM(AddEmpty(ELEM_SHORT)); + break; + + case MNU_INSERT_MASTER_RLY: + // CHANGING_PROGRAM(AddMasterRelay()); + break; + + case MNU_INSERT_SHIFT_REG: + // CHANGING_PROGRAM(AddShiftRegister()); + break; + + case MNU_INSERT_LUT: + // CHANGING_PROGRAM(AddLookUpTable()); + break; -// case MNU_INSERT_PWL: -// CHANGING_PROGRAM(AddPiecewiseLinear()); -// break; + case MNU_INSERT_PWL: + // CHANGING_PROGRAM(AddPiecewiseLinear()); + break; -// case MNU_INSERT_FMTD_STR: -// CHANGING_PROGRAM(AddFormattedString()); -// break; + case MNU_INSERT_FMTD_STR: + // CHANGING_PROGRAM(AddFormattedString()); + break; -// case MNU_INSERT_OSR: -// CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_RISING)); -// break; + case MNU_INSERT_OSR: + // CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_RISING)); + break; -// case MNU_INSERT_OSF: -// CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_FALLING)); -// break; + case MNU_INSERT_OSF: + // CHANGING_PROGRAM(AddEmpty(ELEM_ONE_SHOT_FALLING)); + break; -// case MNU_INSERT_MOV: -// CHANGING_PROGRAM(AddMove()); -// break; + case MNU_INSERT_MOV: + // CHANGING_PROGRAM(AddMove()); + break; -// case MNU_INSERT_SET_PWM: -// CHANGING_PROGRAM(AddSetPwm()); -// break; + case MNU_INSERT_SET_PWM: + // CHANGING_PROGRAM(AddSetPwm()); + break; -// case MNU_INSERT_READ_ADC: -// CHANGING_PROGRAM(AddReadAdc()); -// break; + case MNU_INSERT_READ_ADC: + // CHANGING_PROGRAM(AddReadAdc()); + break; -// case MNU_INSERT_UART_SEND: -// CHANGING_PROGRAM(AddUart(ELEM_UART_SEND)); -// break; + case MNU_INSERT_UART_SEND: + // CHANGING_PROGRAM(AddUart(ELEM_UART_SEND)); + break; -// case MNU_INSERT_UART_RECV: -// CHANGING_PROGRAM(AddUart(ELEM_UART_RECV)); -// break; + case MNU_INSERT_UART_RECV: + // CHANGING_PROGRAM(AddUart(ELEM_UART_RECV)); + break; -// case MNU_INSERT_PERSIST: -// CHANGING_PROGRAM(AddPersist()); -// break; + case MNU_INSERT_PERSIST: + // CHANGING_PROGRAM(AddPersist()); + break; // { // int elem; @@ -496,91 +501,101 @@ static void CompileProgram(BOOL compileAs) // break; // } -// case MNU_MAKE_NORMAL: -// CHANGING_PROGRAM(MakeNormalSelected()); -// break; + case MNU_MAKE_NORMAL: + // CHANGING_PROGRAM(MakeNormalSelected()); + break; -// case MNU_NEGATE: -// CHANGING_PROGRAM(NegateSelected()); -// break; + case MNU_NEGATE: + // CHANGING_PROGRAM(NegateSelected()); + break; -// case MNU_MAKE_SET_ONLY: -// CHANGING_PROGRAM(MakeSetOnlySelected()); -// break; + case MNU_MAKE_SET_ONLY: + // CHANGING_PROGRAM(MakeSetOnlySelected()); + break; -// case MNU_MAKE_RESET_ONLY: -// CHANGING_PROGRAM(MakeResetOnlySelected()); -// break; + case MNU_MAKE_RESET_ONLY: + // CHANGING_PROGRAM(MakeResetOnlySelected()); + break; -// case MNU_UNDO: -// UndoUndo(); -// break; + case MNU_UNDO: + // UndoUndo(); + break; -// case MNU_REDO: -// UndoRedo(); -// break; + case MNU_REDO: + // UndoRedo(); + break; -// case MNU_INSERT_RUNG_BEFORE: -// CHANGING_PROGRAM(InsertRung(FALSE)); -// break; + case MNU_INSERT_RUNG_BEFORE: + // CHANGING_PROGRAM(InsertRung(FALSE)); + break; -// case MNU_INSERT_RUNG_AFTER: -// CHANGING_PROGRAM(InsertRung(TRUE)); -// break; + case MNU_INSERT_RUNG_AFTER: + // CHANGING_PROGRAM(InsertRung(TRUE)); + break; -// case MNU_DELETE_RUNG: -// CHANGING_PROGRAM(DeleteSelectedRung()); -// break; + case MNU_DELETE_RUNG: + // CHANGING_PROGRAM(DeleteSelectedRung()); + break; -// case MNU_PUSH_RUNG_UP: -// CHANGING_PROGRAM(PushRungUp()); -// break; + case MNU_PUSH_RUNG_UP: + // CHANGING_PROGRAM(PushRungUp()); + break; -// case MNU_PUSH_RUNG_DOWN: -// CHANGING_PROGRAM(PushRungDown()); -// break; + case MNU_PUSH_RUNG_DOWN: + // CHANGING_PROGRAM(PushRungDown()); + break; -// case MNU_DELETE_ELEMENT: -// CHANGING_PROGRAM(DeleteSelectedFromProgram()); -// break; + case MNU_DELETE_ELEMENT: + // CHANGING_PROGRAM(DeleteSelectedFromProgram()); + break; -// case MNU_MCU_SETTINGS: -// CHANGING_PROGRAM(ShowConfDialog()); -// break; + case MNU_MCU_SETTINGS: + CHANGING_PROGRAM(ShowConfDialog()); + break; -// case MNU_SIMULATION_MODE: -// ToggleSimulationMode(); -// break; + case MNU_SIMULATION_MODE: + // ToggleSimulationMode(); + break; -// case MNU_START_SIMULATION: -// StartSimulation(); -// break; + case MNU_START_SIMULATION: + // StartSimulation(); + break; -// case MNU_STOP_SIMULATION: -// StopSimulation(); -// break; + case MNU_STOP_SIMULATION: + // StopSimulation(); + break; -// case MNU_SINGLE_CYCLE: -// SimulateOneCycle(TRUE); -// break; + case MNU_SINGLE_CYCLE: + // SimulateOneCycle(TRUE); + break; -// case MNU_COMPILE: -// CompileProgram(FALSE); -// break; + case MNU_COMPILE: + // CompileProgram(FALSE); + break; -// case MNU_COMPILE_AS: -// CompileProgram(TRUE); -// break; + case MNU_COMPILE_AS: + // CompileProgram(TRUE); + break; -// case MNU_MANUAL: -// ShowHelpDialog(FALSE); -// break; + case MNU_MANUAL: + // ShowHelpDialog(FALSE); + break; -// case MNU_ABOUT: -// ShowHelpDialog(TRUE); -// break; -// } -// } + case MNU_ABOUT: + // ShowHelpDialog(TRUE); + break; + } +} + +void WM_COMMAND (GtkMenuItem* men, gpointer gpcode){ + int tempcode = GPOINTER_TO_INT(gpcode); + ProcessMenu (tempcode); +} + +void MenuHandler (){ + g_signal_connect(G_OBJECT(McuSettingsMenu), "activate", + G_CALLBACK(WM_COMMAND), GINT_TO_POINTER(MNU_MCU_SETTINGS)); +} //----------------------------------------------------------------------------- // WndProc for MainWindow. @@ -592,448 +607,577 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) // 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; + // } + + // case WM_LBUTTONDBLCLK: { + // } + + // case WM_LBUTTONDOWN: { + // } + // case WM_MOUSEMOVE: { + // } + // case WM_MOUSEWHEEL: { + // } + + // case WM_SIZE: + + // case WM_NOTIFY: { + // NMHDR *h = (NMHDR *)lParam; + // if(h->hwndFrom == IoList) { + // IoListProc(h); // } + // return 0; + // } + // case WM_VSCROLL: - // 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; - // } + // case WM_HSCROLL: + + // case WM_COMMAND: + // ProcessMenu(LOWORD(wParam)); + // InvalidateRect(MainWindow, NULL, FALSE); + // break; + + // case WM_CLOSE: + // case WM_DESTROY: + + // default: + // return DefWindowProc(hwnd, msg, wParam, lParam); + // } + + return 1; +} + +void LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)//(HWND window) +{ + /* Handles: + * WM_CLOSE + */ + + FreezeWindowPos(MainWindow); + FreezeDWORD(IoListHeight); + + gtk_main_quit(); +} + +gboolean LD_WM_KeyDown_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + /* Handles: + * WM_KEYDOWN + */ + + 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 VK_F5: - // CompileProgram(FALSE); + // case ' ': + // SimulateOneCycle(TRUE); // break; - // case VK_UP: - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(PushRungUp()); - // } else { - // MoveCursorKeyboard(wParam); - // } + // case 'R': + // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) + // StartSimulation(); // break; - // case VK_DOWN: - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(PushRungDown()); - // } else { - // MoveCursorKeyboard(wParam); - // } + // case 'H': + // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) + // StopSimulation(); // break; - // case VK_RIGHT: - // case VK_LEFT: - // MoveCursorKeyboard(wParam); + // case VK_DOWN: + // if(ScrollYOffset < ScrollYOffsetMax) + // ScrollYOffset++; + // RefreshScrollbars(); + // InvalidateRect(MainWindow, NULL, FALSE); // break; - // case VK_RETURN: - // CHANGING_PROGRAM(EditSelectedElement()); + // case VK_UP: + // if(ScrollYOffset > 0) + // ScrollYOffset--; + // RefreshScrollbars(); + // InvalidateRect(MainWindow, NULL, FALSE); // break; - // case VK_DELETE: - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(DeleteSelectedRung()); - // } else { - // CHANGING_PROGRAM(DeleteSelectedFromProgram()); - // } + // case VK_LEFT: + // ScrollXOffset -= FONT_WIDTH; + // if(ScrollXOffset < 0) ScrollXOffset = 0; + // RefreshScrollbars(); + // InvalidateRect(MainWindow, NULL, FALSE); // break; - // case VK_OEM_1: - // CHANGING_PROGRAM(AddComment(_("--add comment here--"))); + // case VK_RIGHT: + // ScrollXOffset += FONT_WIDTH; + // if(ScrollXOffset >= ScrollXOffsetMax) + // ScrollXOffset = ScrollXOffsetMax; + // RefreshScrollbars(); + // InvalidateRect(MainWindow, NULL, FALSE); // break; - // case 'C': - // CHANGING_PROGRAM(AddContact()); + // case VK_RETURN: + // case VK_ESCAPE: + // ToggleSimulationMode(); // break; + // } + // 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; + // switch(wParam) { + // case VK_F5: + // CompileProgram(FALSE); + // break; - // case 'L': - // CHANGING_PROGRAM(AddCoil()); - // break; + // case VK_UP: + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(PushRungUp()); + // } else { + // MoveCursorKeyboard(wParam); + // } + // break; - // case 'R': - // CHANGING_PROGRAM(MakeResetOnlySelected()); - // break; + // case VK_DOWN: + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(PushRungDown()); + // } else { + // MoveCursorKeyboard(wParam); + // } + // break; - // case 'E': - // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { - // ExportDialog(); - // } else { - // CHANGING_PROGRAM(AddReset()); - // } - // break; + // case VK_RIGHT: + // case VK_LEFT: + // MoveCursorKeyboard(wParam); + // break; - // case 'S': - // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { - // SaveProgram(); - // UpdateMainWindowTitleBar(); - // } else { - // CHANGING_PROGRAM(MakeSetOnlySelected()); - // } - // break; + // case VK_RETURN: + // CHANGING_PROGRAM(EditSelectedElement()); + // 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 VK_DELETE: + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(DeleteSelectedRung()); + // } else { + // CHANGING_PROGRAM(DeleteSelectedFromProgram()); + // } + // break; - // case 'A': - // CHANGING_PROGRAM(MakeNormalSelected()); - // break; + // case VK_OEM_1: + // CHANGING_PROGRAM(AddComment(_("--add comment here--"))); + // break; - // case 'T': - // CHANGING_PROGRAM(AddTimer(ELEM_RTO)); - // 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 'O': - // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { - // if(CheckSaveUserCancels()) break; - // OpenDialog(); - // } else { - // CHANGING_PROGRAM(AddTimer(ELEM_TON)); + // 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; // } - // break; + // NewProgram(); + // strcpy(CurrentSaveFile, ""); + // strcpy(CurrentCompileFile, ""); + // GenerateIoListDontLoseSelection(); + // RefreshScrollbars(); + // UpdateMainWindowTitleBar(); + // } else { + // CHANGING_PROGRAM(NegateSelected()); + // } + // break; - // case 'F': - // CHANGING_PROGRAM(AddTimer(ELEM_TOF)); - // break; + // case 'A': + // CHANGING_PROGRAM(MakeNormalSelected()); + // break; - // case 'U': - // CHANGING_PROGRAM(AddCounter(ELEM_CTU)); - // break; + // case 'T': + // CHANGING_PROGRAM(AddTimer(ELEM_RTO)); + // break; - // case 'I': - // CHANGING_PROGRAM(AddCounter(ELEM_CTD)); - // break; + // case 'O': + // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { + // if(CheckSaveUserCancels()) break; + // OpenDialog(); + // } else { + // CHANGING_PROGRAM(AddTimer(ELEM_TON)); + // } + // break; - // case 'J': - // CHANGING_PROGRAM(AddCounter(ELEM_CTC)); - // break; + // case 'F': + // CHANGING_PROGRAM(AddTimer(ELEM_TOF)); + // break; - // case 'M': - // CHANGING_PROGRAM(AddMove()); - // break; + // case 'U': + // CHANGING_PROGRAM(AddCounter(ELEM_CTU)); + // break; - // case 'P': - // CHANGING_PROGRAM(AddReadAdc()); - // break; + // case 'I': + // CHANGING_PROGRAM(AddCounter(ELEM_CTD)); + // break; - // case VK_OEM_PLUS: - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(AddMath(ELEM_ADD)); - // } else { - // CHANGING_PROGRAM(AddCmp(ELEM_EQU)); - // } - // break; + // case 'J': + // CHANGING_PROGRAM(AddCounter(ELEM_CTC)); + // break; - // case VK_OEM_MINUS: - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // } else { - // CHANGING_PROGRAM(AddMath(ELEM_SUB)); - // } - // break; + // case 'M': + // CHANGING_PROGRAM(AddMove()); + // break; - // case '8': - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(AddMath(ELEM_MUL)); - // } - // break; + // case 'P': + // CHANGING_PROGRAM(AddReadAdc()); + // break; - // case 'D': - // CHANGING_PROGRAM(AddMath(ELEM_DIV)); - // 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_PERIOD: - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(AddCmp(ELEM_GRT)); - // } else { - // CHANGING_PROGRAM(AddCmp(ELEM_GEQ)); - // } - // break; + // case VK_OEM_MINUS: + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // } else { + // CHANGING_PROGRAM(AddMath(ELEM_SUB)); + // } + // break; - // case VK_OEM_COMMA: - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(AddCmp(ELEM_LES)); - // } else { - // CHANGING_PROGRAM(AddCmp(ELEM_LEQ)); - // } - // break; + // case '8': + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(AddMath(ELEM_MUL)); + // } + // break; - // case 'V': - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(InsertRung(TRUE)); - // } - // break; + // case 'D': + // CHANGING_PROGRAM(AddMath(ELEM_DIV)); + // break; - // case '6': - // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { - // CHANGING_PROGRAM(InsertRung(FALSE)); - // } - // break; + // case VK_OEM_PERIOD: + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(AddCmp(ELEM_GRT)); + // } else { + // CHANGING_PROGRAM(AddCmp(ELEM_GEQ)); + // } + // break; - // case 'Z': - // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { - // UndoUndo(); - // } - // break; + // case VK_OEM_COMMA: + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(AddCmp(ELEM_LES)); + // } else { + // CHANGING_PROGRAM(AddCmp(ELEM_LEQ)); + // } + // break; - // case 'Y': - // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { - // UndoRedo(); - // } - // break; + // case 'V': + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(InsertRung(TRUE)); + // } + // break; - // default: - // break; - // } - // if(wParam != VK_SHIFT && wParam != VK_CONTROL) { - // InvalidateRect(MainWindow, NULL, FALSE); - // } - // break; - // } + // case '6': + // if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { + // CHANGING_PROGRAM(InsertRung(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 'Z': + // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { + // UndoUndo(); + // } + // 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 'Y': + // if(GetAsyncKeyState(VK_CONTROL) & 0x8000) { + // UndoRedo(); + // } + // break; - // SetFocus(MainWindow); + // default: + // break; + // } + // if(wParam != VK_SHIFT && wParam != VK_CONTROL) { // InvalidateRect(MainWindow, NULL, FALSE); - // break; // } - // case WM_MOUSEMOVE: { - // int x = LOWORD(lParam); - // int y = HIWORD(lParam); + // break; + return FALSE; +} - // 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; - // } +gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + /* Handles: + * WM_LBUTTONDBLCLK, WM_LBUTTONDOWN + */ - // case WM_SIZE: - // MainWindowResized(); - // break; + g_print("x = %f\n", event->button.x_root); + g_print("y = %f\n", event->button.y_root); + switch(event->button.type) + { + case GDK_BUTTON_PRESS:// To Do: run only for left click + // 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 GDK_2BUTTON_PRESS: + // 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_NOTIFY: { - // NMHDR *h = (NMHDR *)lParam; - // if(h->hwndFrom == IoList) { - // IoListProc(h); - // } - // return 0; - // } - // case WM_VSCROLL: - // VscrollProc(wParam); - // break; + } + return FALSE; +} - // case WM_HSCROLL: - // HscrollProc(wParam); - // break; +gboolean LD_GTK_mouse_scroll_hook(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + /* Handles: + * WM_VSCROLL, WM_HSCROLL, WM_MOUSEWHEEL + */ - // case WM_COMMAND: - // ProcessMenu(LOWORD(wParam)); - // InvalidateRect(MainWindow, NULL, FALSE); - // break; + switch(event->scroll.direction) + { + case GDK_SCROLL_UP: + case GDK_SCROLL_DOWN: + // VscrollProc(wParam); + break; + case GDK_SCROLL_LEFT: + case GDK_SCROLL_RIGHT: + // HscrollProc(wParam); + break; + case GDK_SCROLL_SMOOTH: + // if((GET_WHEEL_DELTA_WPARAM(wParam)) > 0) { + // VscrollProc(SB_LINEUP); + // } else { + // VscrollProc(SB_LINEDOWN); + // } + // gdk_event_get_scroll_deltas (const GdkEvent *event, gdouble *delta_x, gdouble *delta_y); + break; - // case WM_CLOSE: - // case WM_DESTROY: - // if(CheckSaveUserCancels()) break; + } + return FALSE; +} - // PostQuitMessage(0); - // return 1; +gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + /* Handles: + * WM_MOUSEMOVE + */ - // default: - // return DefWindowProc(hwnd, msg, wParam, lParam); + g_print("x = %f\n", event->button.x_root); + g_print("y = %f\n", event->button.y_root); + // 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; + return FALSE; +} - return 1; +gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data) +{ + /* Handles: + * WM_PAINT + */ + + g_print("draw called\n"); + + // guint width, height; + // GdkRGBA color; + // GtkStyleContext *context; + + // context = gtk_widget_get_style_context (widget); + + // width = gtk_widget_get_allocated_width (widget); + // height = gtk_widget_get_allocated_height (widget); + + // gtk_render_background (context, cr, 0, 0, width, height); + + // cairo_arc (cr, + // width / 2.0, height / 2.0, + // MIN (width, height) / 3.0, + // 0, 2 * G_PI); + + // gtk_style_context_get_color (context, + // gtk_style_context_get_state (context), + // &color); + // gdk_cairo_set_source_rgba (cr, &color); + + // cairo_fill (cr); + // static double Cairo_R = 0.0, Cairo_G = 0.0, Cairo_B = 0.0; + // cairo_set_source_rgb(cr, Cairo_R, Cairo_G, Cairo_G); + // Cairo_R = (Cairo_R+0.2 > 0.4) ? 0 : Cairo_R+0.2; + // Cairo_G = (Cairo_G+0.4 > 1.0) ? 0.4 : Cairo_G+0.4; + // Cairo_B = (Cairo_B+0.1 > 0.5) ? 0 : Cairo_B+0.1; + + // cairo_select_font_face(cr, "Purisa", + // CAIRO_FONT_SLANT_NORMAL, + // CAIRO_FONT_WEIGHT_BOLD); + + // cairo_set_font_size(cr, 20); + + // cairo_move_to(cr, 20, height / 2.0); + // cairo_show_text(cr, "-----------THIS IS A TEST DRAW----------"); + + // cairo_fill (cr); + + + // PAINTSTRUCT ps; + // Hdc = BeginPaint(hwnd, &ps); + + /// This draws the schematic. + PaintWindow(cr); + + // 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 FALSE; } -//----------------------------------------------------------------------------- -// Create our window class; nothing exciting. -//----------------------------------------------------------------------------- -static BOOL MakeWindowClass() +gboolean LD_WM_Destroy_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) { - 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); + /* Handles: + * WM_DESTROY + */ + + // if(CheckSaveUserCancels()) break; + + // PostQuitMessage(0); + // return 1; + + return FALSE; } -void LDMicro_close(HWND window) +gboolean LD_WM_Size_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) { - FreezeWindowPos(MainWindow); - FreezeDWORD(IoListHeight); + /* Handles: + * WM_SIZE + */ - gtk_main_quit(); + // MainWindowResized(); + // break; + + return FALSE; +} + +gboolean LD_WM_SetFocus_call(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + /* Handles: + * WM_SETFOCUS + */ + + // InvalidateRect(MainWindow, NULL, FALSE); + // break; + + return FALSE; } + //----------------------------------------------------------------------------- // Entry point into the program. //----------------------------------------------------------------------------- @@ -1133,7 +1277,6 @@ int main(int argc, char** argv) MainHeap = HeapCreate(0, 1024*64, 0); - MakeWindowClass(); // MakeDialogBoxClass(); // MakeComponentListClass(); // MakeSmplDialogClass(); @@ -1141,22 +1284,42 @@ int main(int argc, char** argv) 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); - + MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(MainWindow), "LDmicro"); + gtk_window_set_default_size (GTK_WINDOW(MainWindow), 800, 600); + gtk_window_resize (GTK_WINDOW(MainWindow), 800, 600); + gtk_window_move(GTK_WINDOW(MainWindow), 10, 10); + gtk_widget_override_background_color(GTK_WIDGET(MainWindow), + GTK_STATE_FLAG_NORMAL, ((HBRUSH)GetStockObject(GREY_BRUSH))->getThis()); + gtk_window_set_default_icon(LoadImage(Instance, LDMICRO_ICON, + IMAGE_ICON, 32, 32, 0)); + gtk_window_set_icon(GTK_WINDOW(MainWindow), LoadImage(Instance, LDMICRO_ICON, + IMAGE_ICON, 32, 32, 0)); + /// Make main window - end + + InitForDrawing(); + ThawWindowPos(MainWindow); IoListHeight = 100; ThawDWORD(IoListHeight); - // InitCommonControls(); /// NOT USED, Only for windows - InitForDrawing(); - - MakeMainWindowControls(); + MakeMainWindowControls(); /// takes care of MakeMainWindowMenus() MainWindowResized(); + // CHANGING_PROGRAM(ShowConfDialog()); + MenuHandler(); + + /// 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); + g_signal_connect (DrawWindow, "draw", G_CALLBACK (LD_WM_Paint_call), NULL); + g_signal_connect (MainWindow, "destroy_event", G_CALLBACK (LD_WM_Destroy_call), NULL); + g_signal_connect (MainWindow, "configure_event", G_CALLBACK (LD_WM_Size_call), NULL); + g_signal_connect (MainWindow, "focus_in_event", G_CALLBACK (LD_WM_SetFocus_call), NULL); + /// Keyboard and mouse hooks equivalent to MainWndProc - end + // NewProgram(); // strcpy(CurrentSaveFile, ""); diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp index ce9899b..cdeb190 100644 --- a/ldmicro/lib/linuxUI/linuxLD.cpp +++ b/ldmicro/lib/linuxUI/linuxLD.cpp @@ -1,7 +1,6 @@ #include "linuxUI.h" std::vector<HEAPRECORD> HeapRecords; -std::vector<WNDCLASSEX> WindClassRecord; HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize) { @@ -100,13 +99,7 @@ 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, +HICON LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired, int cyDesired, UINT fuLoad) { HICON pixbuf; @@ -118,7 +111,7 @@ HANDLE LoadImage(HINSTANCE hinst, LPCTSTR lpszName, UINT uType, int cxDesired, g_error_free(error); } - return (HANDLE) pixbuf; + return pixbuf; } void OutputDebugString(char* str) diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h index 25d42bb..5f8e0e7 100644 --- a/ldmicro/lib/linuxUI/linuxLD.h +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -4,6 +4,7 @@ #include "linuxUI.h" #include <ctype.h> #include <vector> +#include <math.h> #include <algorithm> #include <sys/mman.h> @@ -19,7 +20,10 @@ /// Image loading flags #define IMAGE_ICON 1 -#define LDMICRO_ICON "ldmicro.ico" +#define LDMICRO_ICON "../ldmicro.ico" + +/// Macro functions +#define max(_A, _B) std::max(_A, _B) /// Typedefs //typedef int64_t __int64; @@ -54,14 +58,14 @@ typedef CHAR *LPSTR; typedef void *PVOID; typedef void *LPVOID; -typedef PVOID HFONT; typedef PVOID HMODULE; typedef PVOID HHOOK; -typedef PVOID HFONT; typedef PVOID HANDLE; typedef HANDLE HINSTANCE; -typedef HANDLE HDC; +typedef HANDLE HGDIOBJ; + +typedef cairo_t *HCRDC; typedef GtkWidget *HWID; typedef GtkWidget *HMENU; typedef GtkWindow *HWND; @@ -106,6 +110,14 @@ typedef class tagColorReferance: public GdkRGBA{ this->alpha = 1.0; } + // tagColorReferance(tagColorReferance &refCpy) + // { + // this->red = refCpy.red; + // this->green = refCpy.green; + // this->blue = refCpy.blue; + // this->alpha = refCpy.alpha; + // } + GdkRGBA* getThis() { return this; @@ -143,25 +155,23 @@ 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; - +typedef struct FontTag { + int nHeight; + int nWidth; + int nOrientation; + int fnWeight; + DWORD fdwItalic; + LPCTSTR lpszFace; +} *HFONT, FONT; + +typedef struct tagLOGBRUSH { + UINT lbStyle; + COLORREF lbColor; +// ULONG_PTR lbHatch; +} LOGBRUSH, *PLOGBRUSH; /// Variables extern std::vector<HEAPRECORD> HeapRecord; -extern std::vector<WNDCLASSEX> WindClassRecord; /// Functions HANDLE HeapCreate( @@ -179,9 +189,7 @@ BOOL HeapFree( DWORD dwFlags, LPVOID lpMem); -BOOL RegisterClassEx(const WNDCLASSEX *lpwcx); - -HANDLE LoadImage( +HICON LoadImage( HINSTANCE hinst, LPCTSTR lpszName, UINT uType, diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index c20dec1..bbaa001 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -1,5 +1,7 @@ #include "linuxUI.h" +void AddMenuAccelerators (void); + /// EnableMenuItem Variables const UINT MF_ENABLED = 0; const UINT MF_GRAYED = 1; @@ -31,19 +33,6 @@ COLORREF RGB(int red, int green, int blue) 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; @@ -95,6 +84,7 @@ int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags) return result; } + BOOL GetSaveFileName(OPENFILENAME *ofn) { GtkWidget *dialog; @@ -193,24 +183,98 @@ void CheckMenuItem(HMENU MenuName, HMENU MenuItem, UINT Check) } } -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) +HANDLE GetStockObject(int fnObject) { - - auto WinClR_it = std::find_if(WindClassRecord.begin(), WindClassRecord.end(), [&lpClassName](WNDCLASSEX &Record) { return Record.lpszClassName == lpClassName; }); + switch(fnObject) + { + case BLACK_BRUSH: + return new COLORREF(0, 0, 0); + break; + case WHITE_BRUSH: + return new COLORREF(255, 255, 255); + break; + case GREY_BRUSH: + return new COLORREF(128, 128, 128); + break; + default: + return new COLORREF(255, 255, 255); + } +} - if (WinClR_it == WindClassRecord.end()) - return NULL; +void SelectObject(HCRDC hcr, HFONT hfont) +{ + cairo_select_font_face(hcr, hfont->lpszFace, + hfont->fdwItalic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL, + hfont->fnWeight == FW_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); + + cairo_rotate(hcr, hfont->nOrientation); + + // cairo_text_extents_t extents; + // cairo_text_extents (hcr, "H", &extents); + + // cairo_matrix_t matrix; + // cairo_matrix_init_scale (&matrix, + // (double)hfont->nWidth / extents.width, + // (double)hfont->nHeight / extents.width); + + // cairo_set_font_matrix (hcr, &matrix); + // g_print("wR = %f\nhR = %f\n", (double)hfont->nWidth / extents.width, (double)hfont->nHeight / extents.height); + // g_print("tW = %f\ntH = %f\n", extents.width, extents.width); + cairo_set_font_size(hcr, 15); +} + +HBRUSH CreateBrushIndirect(PLOGBRUSH plb) +{ + COLORREF brush(plb->lbColor); + brush.alpha = (plb->lbStyle == BS_SOLID) ? 1 : 0.2; + + return &brush; +} + +HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight, + DWORD fdwItalic, LPCTSTR lpszFace) +{ + HFONT font = new FONT; + font->nHeight = nHeight; + font->nWidth = nWidth; + font->nOrientation = nOrientation; + font->fnWeight = fnWeight; + font->fdwItalic = fdwItalic; + font->lpszFace = lpszFace; + + return font; +} + +void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol) +{ + gtk_widget_override_background_color(GTK_WIDGET(widget), + GTK_STATE_FLAG_NORMAL, &bkCol); + + GtkStyleContext *context; + COLORREF col; + + context = gtk_widget_get_style_context (widget); + gint width = gtk_widget_get_allocated_width (widget); + gint height = gtk_widget_get_allocated_height (widget); + + gtk_style_context_get_color (context, + gtk_style_context_get_state (context), + &col); - 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; + gdk_cairo_set_source_rgba (hcr, &col); + + gtk_render_background (context, hcr, 0, 0, width, height); +} + +void SetTextColor(HCRDC hcr, COLORREF color) +{ + gdk_cairo_set_source_rgba (hcr, &color); +} + +void TextOut(HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString) +{ + cairo_move_to(hcr, nXStart, nYStart); + cairo_show_text(hcr, lpString); + + cairo_fill (hcr); }
\ No newline at end of file diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 4ddf164..08dab39 100644 --- a/ldmicro/lib/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -39,7 +39,15 @@ #define OFN_OVERWRITEPROMPT 0x00000400L /// window brushes -#define BLACK_BRUSH 0x00000401L +#define BS_SOLID 0x00000001L +#define BS_HOLLOW 0x00000002L +#define BLACK_BRUSH 0x00000004L +#define WHITE_BRUSH 0x00000008L +#define GREY_BRUSH 0x00000010L + +/// Font flags +#define FW_REGULAR 0x00000001L +#define FW_BOLD 0x00000002L /// EnableMenuItem variables extern const UINT MF_ENABLED; @@ -51,10 +59,9 @@ extern const UINT MF_UNCHECKED; extern GtkAccelGroup* AccelGroup; extern GClosure* closure; - /// ListStore -extern GtkWidget *view; -extern GtkTreeViewColumn *column; +extern HWID view; +extern HTVC column; /// data types typedef struct OpenFileInfoData { @@ -69,27 +76,52 @@ typedef struct OpenFileInfoData { } OPENFILENAME; /// functions -BOOL isFocus(HWID); -COLORREF RGB(int, int, int); -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 -); +BOOL isFocus(HWID window); + +COLORREF RGB(int red, + int green, + int blue); + +int MessageBox(HWID pWindow, + char* message, + char* title, + UINT mFlags); + +BOOL GetSaveFileName(OPENFILENAME *ofn); + +void EnableMenuItem(HMENU MenuName, + HMENU MenuItem, + UINT CheckEnabledItem); + +void CheckMenuItem(HMENU MenuName, + HMENU MenuItem, + UINT Check); + +HANDLE GetStockObject(int fnObject); + +void SelectObject(HCRDC hcr, + HFONT hfont); + +HBRUSH CreateBrushIndirect(PLOGBRUSH plb); + +HFONT CreateFont(int nHeight, + int nWidth, + int nOrientation, + int fnWeight, + DWORD fdwItalic, + LPCTSTR lpszFace); + +void SetBkColor(HWID widget, + HCRDC hcr, + COLORREF bkCol); + +void SetTextColor(HCRDC hcr, + COLORREF color); + +void TextOut(HCRDC hcr, + int nXStart, + int nYStart, + LPCTSTR lpString, + int cchString); #endif
\ No newline at end of file diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index 9a3d737..f7dc8c4 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -31,76 +31,76 @@ #include "ldmicro.h" // Menu IDs -HMENU MNU_NEW; -HMENU MNU_OPEN; -HMENU MNU_SAVE; -HMENU MNU_SAVE_AS; -HMENU MNU_EXPORT; -HMENU MNU_EXIT; - -HMENU MNU_UNDO; -HMENU MNU_REDO; -HMENU MNU_PUSH_RUNG_UP; -HMENU MNU_PUSH_RUNG_DOWN; -HMENU MNU_INSERT_RUNG_BEFORE; -HMENU MNU_INSERT_RUNG_AFTER; -HMENU MNU_DELETE_ELEMENT; -HMENU MNU_DELETE_RUNG; - -HMENU MNU_INSERT_COMMENT; -HMENU MNU_INSERT_CONTACTS; -HMENU MNU_INSERT_COIL; -HMENU MNU_INSERT_TON; -HMENU MNU_INSERT_TOF; -HMENU MNU_INSERT_RTO; -HMENU MNU_INSERT_RES; -HMENU MNU_INSERT_OSR; -HMENU MNU_INSERT_OSF; -HMENU MNU_INSERT_CTU; -HMENU MNU_INSERT_CTD; -HMENU MNU_INSERT_CTC; -HMENU MNU_INSERT_ADD; -HMENU MNU_INSERT_SUB; -HMENU MNU_INSERT_MUL; -HMENU MNU_INSERT_DIV; -HMENU MNU_INSERT_MOV; -HMENU MNU_INSERT_READ_ADC; -HMENU MNU_INSERT_SET_PWM; -HMENU MNU_INSERT_UART_SEND; -HMENU MNU_INSERT_UART_RECV; -HMENU MNU_INSERT_EQU; -HMENU MNU_INSERT_NEQ; -HMENU MNU_INSERT_GRT; -HMENU MNU_INSERT_GEQ; -HMENU MNU_INSERT_LES; -HMENU MNU_INSERT_LEQ; -HMENU MNU_INSERT_OPEN; -HMENU MNU_INSERT_SHORT; -HMENU MNU_INSERT_MASTER_RLY; -HMENU MNU_INSERT_SHIFT_REG; -HMENU MNU_INSERT_LUT; -HMENU MNU_INSERT_FMTD_STR; -HMENU MNU_INSERT_PERSIST; -HMENU MNU_MAKE_NORMAL; -HMENU MNU_NEGATE; -HMENU MNU_MAKE_SET_ONLY; -HMENU MNU_MAKE_RESET_ONLY; -HMENU MNU_INSERT_PWL; - -HMENU MNU_MCU_SETTINGS; -HMENU MNU_PROCESSOR[NUM_SUPPORTED_MCUS+1]; -HMENU MNU_MICRO_CONTROLLER; // Item for Microcontroller - -HMENU MNU_SIMULATION_MODE; -HMENU MNU_START_SIMULATION; -HMENU MNU_STOP_SIMULATION; -HMENU MNU_SINGLE_CYCLE; - -HMENU MNU_COMPILE; -HMENU MNU_COMPILE_AS; - -HMENU MNU_MANUAL; -HMENU MNU_ABOUT; +HMENU NewMenu; +HMENU OpenMenu; +HMENU SaveMenu; +HMENU SaveAsMenu_AS; +HMENU ExportMenu; +HMENU ExitMenu; + +HMENU UndoMenu; +HMENU RedoMenu; +HMENU PushRungUpMenu; +HMENU PushRungDownMenu; +HMENU InsertRungBeforeMenu; +HMENU InsertRungAfterMenu; +HMENU DeleteElementMenu; +HMENU DeleteRungMenu; + +HMENU InsertCommentMenu; +HMENU InsertContactsMenu; +HMENU InsertCoilMenu; +HMENU InsertTonMenu; +HMENU InsertTofMenu; +HMENU InsertRtoMenu; +HMENU InsertResMenu; +HMENU InsertOsrMenu; +HMENU InsertOsfMenu; +HMENU InsertCtuMenu; +HMENU InsertCtdMenu; +HMENU InsertCtcMenu; +HMENU InsertAddMenu; +HMENU InsertSubMenu; +HMENU InsertMulMenu; +HMENU InsertDivMenu; +HMENU InsertMovMenu; +HMENU InsertReadAdcMenu; +HMENU InsertSetPwmMenu; +HMENU InsertUartSendMenu; +HMENU InsertUartRecvMenu; +HMENU InsertEquMenu; +HMENU InsertNeqMenu; +HMENU InsertGrtMenu; +HMENU InsertGeqMenu; +HMENU InsertLesMenu; +HMENU InsertLeqMenu; +HMENU InsertOpenMenu; +HMENU InsertShortMenu; +HMENU InsertMasterRlyMenu; +HMENU InsertShiftRegMenu; +HMENU InsertLutMenu; +HMENU InsertFmtdStrMenu; +HMENU InsertPersistMenu; +HMENU MakeNormalMenu; +HMENU NegateMenu; +HMENU MakeSetOnlyMenu; +HMENU MakeResetOnlyMenu; +HMENU InsertPwlMenu; + +HMENU McuSettingsMenu; +HMENU ProcessorMenuItems[NUM_SUPPORTED_MCUS+1]; +HMENU MicroControllerMenu; // Item for Microcontroller + +HMENU SimulationModeMenu; +HMENU StartSimulationMenu; +HMENU StopSimulationMenu; +HMENU SingleCycleMenu; + +HMENU CompileMenu; +HMENU CompileAsMenu; + +HMENU ManualMenu; +HMENU AboutMenu; // scrollbars for the ladder logic area // static HWND HorizScrollBar; @@ -119,9 +119,9 @@ static HMENU InstructionMenu; static HMENU ProcessorMenu; static HMENU SimulateMenu; static HMENU TopMenu; // Menu Bar -static HMENU settings; -static HMENU compile; -static HMENU help; +static HMENU Settings; +static HMENU Compile; +static HMENU Help; HMENU ScrollWindow; // listview used to maintain the list of I/O pins with symbolic names, plus @@ -137,6 +137,117 @@ GtkTreeModel **IoListPtr = (GtkTreeModel**)GTK_TREE_MODEL (IoList); // whether the simulation is running in real time static BOOL RealTimeSimulationRunning; +// Displaying keyboard shortcuts for each menu item +void AddMenuAccelerators (void){ + // Declaring the accelerator group for keyboard shortcuts + AccelGroup = gtk_accel_group_new (); + + // Creating keyboard shortcuts for File menu + gtk_widget_add_accelerator (NewMenu, "activate", AccelGroup, GDK_KEY_N, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (OpenMenu, "activate", AccelGroup, GDK_KEY_O, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (SaveMenu, "activate", AccelGroup, GDK_KEY_S, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (ExportMenu, "activate", AccelGroup, GDK_KEY_E, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + + // Creating keyboard shortcuts for Edit menu + gtk_widget_add_accelerator (UndoMenu, "activate", AccelGroup, GDK_KEY_Z, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (RedoMenu, "activate", AccelGroup, GDK_KEY_Y, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertRungBeforeMenu, "activate", AccelGroup, GDK_KEY_F6, + GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertRungAfterMenu, "activate", AccelGroup, GDK_KEY_V, + GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (PushRungUpMenu, "activate", AccelGroup, GDK_KEY_uparrow, + GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (PushRungDownMenu, "activate", AccelGroup, GDK_KEY_downarrow, + GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (DeleteElementMenu, "activate", AccelGroup, GDK_KEY_Delete, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (DeleteRungMenu, "activate", AccelGroup, GDK_KEY_Delete, + GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); + + // Creating keyboard shortcuts for Instructions menu + gtk_widget_add_accelerator (InsertCommentMenu, "activate", AccelGroup, GDK_KEY_semicolon, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertContactsMenu, "activate", AccelGroup, GDK_KEY_C, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertOsrMenu, "activate", AccelGroup, GDK_KEY_backslash, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertOsfMenu, "activate", AccelGroup, GDK_KEY_slash, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertTonMenu, "activate", AccelGroup, GDK_KEY_O, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertTofMenu, "activate", AccelGroup, GDK_KEY_F, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertRtoMenu, "activate", AccelGroup, GDK_KEY_T, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertCtuMenu, "activate", AccelGroup, GDK_KEY_U, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertCtdMenu, "activate", AccelGroup, GDK_KEY_I, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertCtcMenu, "activate", AccelGroup, GDK_KEY_J, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertEquMenu, "activate", AccelGroup, GDK_KEY_equal, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertGrtMenu, "activate", AccelGroup, GDK_KEY_greater, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertGeqMenu, "activate", AccelGroup, GDK_KEY_Stop, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertLesMenu, "activate", AccelGroup, GDK_KEY_less, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertLeqMenu, "activate", AccelGroup, GDK_KEY_comma, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertCoilMenu, "activate", AccelGroup, GDK_KEY_L, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertResMenu, "activate", AccelGroup, GDK_KEY_E, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertMovMenu, "activate", AccelGroup, GDK_KEY_M, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertAddMenu, "activate", AccelGroup, GDK_KEY_plus, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertSubMenu, "activate", AccelGroup, GDK_KEY_minus, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertMulMenu, "activate", AccelGroup, GDK_KEY_multiply, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertDivMenu, "activate", AccelGroup, GDK_KEY_D, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (InsertReadAdcMenu, "activate", AccelGroup, GDK_KEY_P, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (MakeNormalMenu, "activate", AccelGroup, GDK_KEY_A, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (NegateMenu, "activate", AccelGroup, GDK_KEY_N, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (MakeSetOnlyMenu, "activate", AccelGroup, GDK_KEY_S, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (MakeResetOnlyMenu, "activate", AccelGroup, GDK_KEY_R, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + + // Creating keyboard shortcuts for Simulation menu + gtk_widget_add_accelerator (SimulationModeMenu, "activate", AccelGroup, GDK_KEY_M, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (StartSimulationMenu, "activate", AccelGroup, GDK_KEY_R, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (StopSimulationMenu, "activate", AccelGroup, GDK_KEY_H, + GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (SingleCycleMenu, "activate", AccelGroup, GDK_KEY_space, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + + // Creating keyboard shortcuts for Compile menu + gtk_widget_add_accelerator (CompileMenu, "activate", AccelGroup, GDK_KEY_F5, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + + // Creating keyboard shortcuts for Help menu + gtk_widget_add_accelerator (ManualMenu, "activate", AccelGroup, GDK_KEY_F1, + GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + + gtk_window_add_accel_group (GTK_WINDOW (MainWindow), AccelGroup); + +} + //----------------------------------------------------------------------------- // Create the top-level menu bar for the main window. Mostly static, but we // create the "select processor" menu from the list in mcutable.h dynamically. @@ -153,7 +264,6 @@ HMENU MakeMainWindowMenus(void) HWID CompileLabel; // Compile menu label HWID HelpLabel; // Help menu label HWID SimulateLabel; // Simulate menu label - HMENU ProcessorMenuItems; // Processor menu items HMENU FileMenuSeparator; // File menu separator HMENU EditMenuSeparator; // Edit menu separator HMENU InstructionMenuSeparator; // Instruction menu separator @@ -169,16 +279,12 @@ HMENU MakeMainWindowMenus(void) // Creating various menus FileMenu = gtk_menu_new(); EditMenu = gtk_menu_new(); - settings = gtk_menu_new(); + Settings = gtk_menu_new(); ProcessorMenu = gtk_menu_new(); InstructionMenu = gtk_menu_new(); SimulateMenu = gtk_menu_new(); - compile = gtk_menu_new(); - help = gtk_menu_new(); - - // Declaring the accelerator group for keyboard shortcuts - AccelGroup = gtk_accel_group_new (); - gtk_window_add_accel_group (GTK_WINDOW (MainWindow), AccelGroup); + Compile = gtk_menu_new(); + Help = gtk_menu_new(); // Creating labels for each menu FileLabel = gtk_menu_item_new_with_mnemonic("_File"); @@ -190,311 +296,209 @@ HMENU MakeMainWindowMenus(void) HelpLabel = gtk_menu_item_new_with_mnemonic("_Help"); // Creating labels for File Menu - MNU_NEW = gtk_menu_item_new_with_mnemonic("_New"); - MNU_OPEN = gtk_menu_item_new_with_mnemonic("_Open"); - MNU_SAVE = gtk_menu_item_new_with_mnemonic("_Save"); - MNU_SAVE_AS = gtk_menu_item_new_with_mnemonic("_Save As"); - MNU_EXPORT = gtk_menu_item_new_with_mnemonic("_Export As Text"); - MNU_EXIT = gtk_menu_item_new_with_mnemonic("_Exit"); + NewMenu = gtk_menu_item_new_with_mnemonic("_New"); + OpenMenu = gtk_menu_item_new_with_mnemonic("_Open"); + SaveMenu = gtk_menu_item_new_with_mnemonic("_Save"); + SaveAsMenu_AS = gtk_menu_item_new_with_mnemonic("_Save As"); + ExportMenu = gtk_menu_item_new_with_mnemonic("_Export As Text"); + ExitMenu = gtk_menu_item_new_with_mnemonic("_Exit"); - // Creating keyboard shortcuts for File menu - gtk_widget_add_accelerator (MNU_NEW, "activate", AccelGroup, GDK_KEY_N, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_OPEN, "activate", AccelGroup, GDK_KEY_O, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_SAVE, "activate", AccelGroup, GDK_KEY_S, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_EXPORT, "activate", AccelGroup, GDK_KEY_E, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - // Appending menu items (labels) to File menu and adding separators - gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), MNU_NEW); // Appending menu items - gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), MNU_OPEN); - gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), MNU_SAVE); - gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), MNU_SAVE_AS); + gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), NewMenu); // Appending menu items + gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), OpenMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), SaveMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), SaveAsMenu_AS); FileMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), FileMenuSeparator); - gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), MNU_EXPORT); + gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), ExportMenu); FileMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), FileMenuSeparator); - gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), MNU_EXIT); + gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), ExitMenu); // Creating labels for Edit Menu - MNU_UNDO = gtk_menu_item_new_with_mnemonic("_Undo"); - MNU_REDO = gtk_menu_item_new_with_mnemonic("_Redo"); - MNU_INSERT_RUNG_BEFORE = gtk_menu_item_new_with_mnemonic("_Insert rung Before"); - MNU_INSERT_RUNG_AFTER = gtk_menu_item_new_with_mnemonic("_Insert Rung After"); - MNU_PUSH_RUNG_UP = gtk_menu_item_new_with_mnemonic("_Move Selected Rung Up"); - MNU_PUSH_RUNG_DOWN = gtk_menu_item_new_with_mnemonic("_Move Selected Rung Down"); - MNU_DELETE_ELEMENT = gtk_menu_item_new_with_mnemonic("_Delete Selected Element"); - MNU_DELETE_RUNG = gtk_menu_item_new_with_mnemonic("_Delete Rung"); - - // Creating keyboard shortcuts for Edit menu - gtk_widget_add_accelerator (MNU_UNDO, "activate", AccelGroup, GDK_KEY_Z, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_REDO, "activate", AccelGroup, GDK_KEY_Y, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_RUNG_BEFORE, "activate", AccelGroup, GDK_KEY_F6, - GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_RUNG_AFTER, "activate", AccelGroup, GDK_KEY_V, - GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_PUSH_RUNG_UP, "activate", AccelGroup, GDK_KEY_uparrow, - GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_PUSH_RUNG_DOWN, "activate", AccelGroup, GDK_KEY_downarrow, - GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_DELETE_ELEMENT, "activate", AccelGroup, GDK_KEY_Delete, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_DELETE_RUNG, "activate", AccelGroup, GDK_KEY_Delete, - GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); + UndoMenu = gtk_menu_item_new_with_mnemonic("_Undo"); + RedoMenu = gtk_menu_item_new_with_mnemonic("_Redo"); + InsertRungBeforeMenu = gtk_menu_item_new_with_mnemonic("_Insert rung Before"); + InsertRungAfterMenu = gtk_menu_item_new_with_mnemonic("_Insert Rung After"); + PushRungUpMenu = gtk_menu_item_new_with_mnemonic("_Move Selected Rung Up"); + PushRungDownMenu = gtk_menu_item_new_with_mnemonic("_Move Selected Rung Down"); + DeleteElementMenu = gtk_menu_item_new_with_mnemonic("_Delete Selected Element"); + DeleteRungMenu = gtk_menu_item_new_with_mnemonic("_Delete Rung"); // Appending menu items to Edit menu and adding separators - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_UNDO); - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_REDO); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), UndoMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), RedoMenu); EditMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(EditMenu), EditMenuSeparator); - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_INSERT_RUNG_BEFORE); - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_INSERT_RUNG_AFTER); - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_PUSH_RUNG_UP); - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_PUSH_RUNG_DOWN); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), InsertRungBeforeMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), InsertRungAfterMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), PushRungUpMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), PushRungDownMenu); EditMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(EditMenu), EditMenuSeparator); - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_DELETE_ELEMENT); - gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), MNU_DELETE_RUNG); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), DeleteElementMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), DeleteRungMenu); // Creating labels for Settings Menu - MNU_MCU_SETTINGS = gtk_menu_item_new_with_mnemonic ("_MCU Parameters..."); - MNU_MICRO_CONTROLLER = gtk_menu_item_new_with_mnemonic ("_Microcontroller"); + McuSettingsMenu = gtk_menu_item_new_with_mnemonic ("_MCU Parameters..."); + MicroControllerMenu = gtk_menu_item_new_with_mnemonic ("_Microcontroller"); // Appending menu items to Settings menu - gtk_menu_shell_append (GTK_MENU_SHELL (settings), MNU_MCU_SETTINGS); - gtk_menu_shell_append (GTK_MENU_SHELL (settings), MNU_MICRO_CONTROLLER); + gtk_menu_shell_append (GTK_MENU_SHELL (Settings), McuSettingsMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (Settings), MicroControllerMenu); // Appending the microcontroller names to "Microcontroller" item for (i = 0; i < NUM_SUPPORTED_MCUS; i++){ - MNU_PROCESSOR[i] = gtk_check_menu_item_new_with_label (SupportedMcus[i].mcuName); - gtk_menu_shell_append (GTK_MENU_SHELL (ProcessorMenu), MNU_PROCESSOR[i]); + ProcessorMenuItems[i] = gtk_check_menu_item_new_with_label (SupportedMcus[i].mcuName); + gtk_menu_shell_append (GTK_MENU_SHELL (ProcessorMenu), ProcessorMenuItems[i]); } - MNU_PROCESSOR[NUM_SUPPORTED_MCUS] = gtk_check_menu_item_new_with_label ("(no microcontroller)"); - gtk_menu_shell_append (GTK_MENU_SHELL (ProcessorMenu), MNU_PROCESSOR[NUM_SUPPORTED_MCUS]); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(MNU_MICRO_CONTROLLER), ProcessorMenu); + ProcessorMenuItems[NUM_SUPPORTED_MCUS] = gtk_check_menu_item_new_with_label ("(no microcontroller)"); + gtk_menu_shell_append (GTK_MENU_SHELL (ProcessorMenu), ProcessorMenuItems[NUM_SUPPORTED_MCUS]); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(MicroControllerMenu), ProcessorMenu); // Creating labels for Instruction Menu and adding separators - MNU_INSERT_COMMENT = gtk_menu_item_new_with_mnemonic("_Insert Comment"); - MNU_INSERT_CONTACTS = gtk_menu_item_new_with_mnemonic("_Insert Contacts"); - MNU_INSERT_OSR = gtk_menu_item_new_with_mnemonic("_Insert OSR (One Shot Rising)"); - MNU_INSERT_OSF = gtk_menu_item_new_with_mnemonic("_Insert OSF (One Shot Falling)"); - MNU_INSERT_TON = gtk_menu_item_new_with_mnemonic("_Insert TON (Delayed Turn On)"); - MNU_INSERT_TOF = gtk_menu_item_new_with_mnemonic("_Insert TOF (Delayed Turn Off)"); - MNU_INSERT_RTO = gtk_menu_item_new_with_mnemonic("_Insert RTO (Retentive Delayed Turn On)"); - MNU_INSERT_CTU = gtk_menu_item_new_with_mnemonic("_Insert CTU (Count Up)"); - MNU_INSERT_CTD = gtk_menu_item_new_with_mnemonic("_Insert CTD (Count Down)"); - MNU_INSERT_CTC = gtk_menu_item_new_with_mnemonic("_Insert CTC (Count Circular)"); - MNU_INSERT_EQU = gtk_menu_item_new_with_mnemonic("_Insert EQU (Compare for Equals)"); - MNU_INSERT_NEQ = gtk_menu_item_new_with_mnemonic("_Insert NEQ (Compare for Not Equals)"); - MNU_INSERT_GRT = gtk_menu_item_new_with_mnemonic("_Insert GRT (Compare for Greater Than)"); - MNU_INSERT_GEQ = gtk_menu_item_new_with_mnemonic("_Insert GEQ (Compare for Greater Than or Equal)"); - MNU_INSERT_LES = gtk_menu_item_new_with_mnemonic("_Insert LES (Compare for Less Than)"); - MNU_INSERT_LEQ = gtk_menu_item_new_with_mnemonic("_Insert LEQ (Compare for Less Than or Equal)"); - MNU_INSERT_OPEN = gtk_menu_item_new_with_mnemonic("_Insert Open Circuit"); - MNU_INSERT_SHORT = gtk_menu_item_new_with_mnemonic("_Insert Short Circuit"); - MNU_INSERT_MASTER_RLY = gtk_menu_item_new_with_mnemonic("_Insert Master Control Relay"); - MNU_INSERT_COIL = gtk_menu_item_new_with_mnemonic("_Insert Coil"); - MNU_INSERT_RES = gtk_menu_item_new_with_mnemonic("_Insert RES (Counter/RTO Reset)"); - MNU_INSERT_MOV = gtk_menu_item_new_with_mnemonic("_Insert MOV (Move)"); - MNU_INSERT_ADD = gtk_menu_item_new_with_mnemonic("_Insert ADD (16-bit Integer Ad)"); - MNU_INSERT_SUB = gtk_menu_item_new_with_mnemonic("_Insert SUB (16-bit Integer Subtract)"); - MNU_INSERT_MUL = gtk_menu_item_new_with_mnemonic("_Insert MUL (16-bit Integer Multiply)"); - MNU_INSERT_DIV = gtk_menu_item_new_with_mnemonic("_Insert DIV (16-bit Integer Division)"); - MNU_INSERT_SHIFT_REG = gtk_menu_item_new_with_mnemonic("_Insert Shift Register"); - MNU_INSERT_LUT = gtk_menu_item_new_with_mnemonic("_Insert Look-Up Table"); - MNU_INSERT_PWL = gtk_menu_item_new_with_mnemonic("_Insert Piecewise Linear"); - MNU_INSERT_FMTD_STR = gtk_menu_item_new_with_mnemonic("_Insert Formatted String Over UART"); - MNU_INSERT_UART_SEND = gtk_menu_item_new_with_mnemonic("_Insert UART Send"); - MNU_INSERT_UART_RECV = gtk_menu_item_new_with_mnemonic("_Insert UART Receive"); - MNU_INSERT_SET_PWM = gtk_menu_item_new_with_mnemonic("_Insert Set PWM Output"); - MNU_INSERT_READ_ADC = gtk_menu_item_new_with_mnemonic("_Insert A/D Converter Read"); - MNU_INSERT_PERSIST = gtk_menu_item_new_with_mnemonic("_Insert Make Persistent"); - MNU_MAKE_NORMAL = gtk_menu_item_new_with_mnemonic("_Make Normal"); - MNU_NEGATE = gtk_menu_item_new_with_mnemonic("_Make Negated"); - MNU_MAKE_SET_ONLY = gtk_menu_item_new_with_mnemonic("_Make Set-Only"); - MNU_MAKE_RESET_ONLY = gtk_menu_item_new_with_mnemonic("_Make Reset-Only"); - - // Creating keyboard shortcuts for Instructions menu - gtk_widget_add_accelerator (MNU_INSERT_COMMENT, "activate", AccelGroup, GDK_KEY_semicolon, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_CONTACTS, "activate", AccelGroup, GDK_KEY_C, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_OSR, "activate", AccelGroup, GDK_KEY_backslash, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_OSF, "activate", AccelGroup, GDK_KEY_slash, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_TON, "activate", AccelGroup, GDK_KEY_O, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_TOF, "activate", AccelGroup, GDK_KEY_F, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_RTO, "activate", AccelGroup, GDK_KEY_T, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_CTU, "activate", AccelGroup, GDK_KEY_U, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_CTD, "activate", AccelGroup, GDK_KEY_I, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_CTC, "activate", AccelGroup, GDK_KEY_J, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_EQU, "activate", AccelGroup, GDK_KEY_equal, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_GRT, "activate", AccelGroup, GDK_KEY_greater, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_GEQ, "activate", AccelGroup, GDK_KEY_Stop, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_LES, "activate", AccelGroup, GDK_KEY_less, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_LEQ, "activate", AccelGroup, GDK_KEY_comma, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_COIL, "activate", AccelGroup, GDK_KEY_L, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_RES, "activate", AccelGroup, GDK_KEY_E, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_MOV, "activate", AccelGroup, GDK_KEY_M, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_ADD, "activate", AccelGroup, GDK_KEY_plus, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_SUB, "activate", AccelGroup, GDK_KEY_minus, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_MUL, "activate", AccelGroup, GDK_KEY_multiply, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_DIV, "activate", AccelGroup, GDK_KEY_D, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_INSERT_READ_ADC, "activate", AccelGroup, GDK_KEY_P, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_MAKE_NORMAL, "activate", AccelGroup, GDK_KEY_A, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_NEGATE, "activate", AccelGroup, GDK_KEY_N, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_MAKE_SET_ONLY, "activate", AccelGroup, GDK_KEY_S, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_MAKE_RESET_ONLY, "activate", AccelGroup, GDK_KEY_R, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + InsertCommentMenu = gtk_menu_item_new_with_mnemonic("_Insert Comment"); + InsertContactsMenu = gtk_menu_item_new_with_mnemonic("_Insert Contacts"); + InsertOsrMenu = gtk_menu_item_new_with_mnemonic("_Insert OSR (One Shot Rising)"); + InsertOsfMenu = gtk_menu_item_new_with_mnemonic("_Insert OSF (One Shot Falling)"); + InsertTonMenu = gtk_menu_item_new_with_mnemonic("_Insert TON (Delayed Turn On)"); + InsertTofMenu = gtk_menu_item_new_with_mnemonic("_Insert TOF (Delayed Turn Off)"); + InsertRtoMenu = gtk_menu_item_new_with_mnemonic("_Insert RTO (Retentive Delayed Turn On)"); + InsertCtuMenu = gtk_menu_item_new_with_mnemonic("_Insert CTU (Count Up)"); + InsertCtdMenu = gtk_menu_item_new_with_mnemonic("_Insert CTD (Count Down)"); + InsertCtcMenu = gtk_menu_item_new_with_mnemonic("_Insert CTC (Count Circular)"); + InsertEquMenu = gtk_menu_item_new_with_mnemonic("_Insert EQU (Compare for Equals)"); + InsertNeqMenu = gtk_menu_item_new_with_mnemonic("_Insert NEQ (Compare for Not Equals)"); + InsertGrtMenu = gtk_menu_item_new_with_mnemonic("_Insert GRT (Compare for Greater Than)"); + InsertGeqMenu = gtk_menu_item_new_with_mnemonic("_Insert GEQ (Compare for Greater Than or Equal)"); + InsertLesMenu = gtk_menu_item_new_with_mnemonic("_Insert LES (Compare for Less Than)"); + InsertLeqMenu = gtk_menu_item_new_with_mnemonic("_Insert LEQ (Compare for Less Than or Equal)"); + InsertOpenMenu = gtk_menu_item_new_with_mnemonic("_Insert Open Circuit"); + InsertShortMenu = gtk_menu_item_new_with_mnemonic("_Insert Short Circuit"); + InsertMasterRlyMenu = gtk_menu_item_new_with_mnemonic("_Insert Master Control Relay"); + InsertCoilMenu = gtk_menu_item_new_with_mnemonic("_Insert Coil"); + InsertResMenu = gtk_menu_item_new_with_mnemonic("_Insert RES (Counter/RTO Reset)"); + InsertMovMenu = gtk_menu_item_new_with_mnemonic("_Insert MOV (Move)"); + InsertAddMenu = gtk_menu_item_new_with_mnemonic("_Insert ADD (16-bit Integer Ad)"); + InsertSubMenu = gtk_menu_item_new_with_mnemonic("_Insert SUB (16-bit Integer Subtract)"); + InsertMulMenu = gtk_menu_item_new_with_mnemonic("_Insert MUL (16-bit Integer Multiply)"); + InsertDivMenu = gtk_menu_item_new_with_mnemonic("_Insert DIV (16-bit Integer Division)"); + InsertShiftRegMenu = gtk_menu_item_new_with_mnemonic("_Insert Shift Register"); + InsertLutMenu = gtk_menu_item_new_with_mnemonic("_Insert Look-Up Table"); + InsertPwlMenu = gtk_menu_item_new_with_mnemonic("_Insert Piecewise Linear"); + InsertFmtdStrMenu = gtk_menu_item_new_with_mnemonic("_Insert Formatted String Over UART"); + InsertUartSendMenu = gtk_menu_item_new_with_mnemonic("_Insert UART Send"); + InsertUartRecvMenu = gtk_menu_item_new_with_mnemonic("_Insert UART Receive"); + InsertSetPwmMenu = gtk_menu_item_new_with_mnemonic("_Insert Set PWM Output"); + InsertReadAdcMenu = gtk_menu_item_new_with_mnemonic("_Insert A/D Converter Read"); + InsertPersistMenu = gtk_menu_item_new_with_mnemonic("_Insert Make Persistent"); + MakeNormalMenu = gtk_menu_item_new_with_mnemonic("_Make Normal"); + NegateMenu = gtk_menu_item_new_with_mnemonic("_Make Negated"); + MakeSetOnlyMenu = gtk_menu_item_new_with_mnemonic("_Make Set-Only"); + MakeResetOnlyMenu = gtk_menu_item_new_with_mnemonic("_Make Reset-Only"); // Appending menu items to Instruction menu and adding separators - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_COMMENT); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCommentMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_CONTACTS); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertContactsMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_OSR); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertOsrMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_OSF); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_TON); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_TOF); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_RTO); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertOsfMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertTonMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertTofMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertRtoMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_CTU); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_CTD); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_CTC); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCtuMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCtdMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCtcMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_EQU); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_NEQ); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_GRT); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_GEQ); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_LES); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_LEQ); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertEquMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertNeqMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertGrtMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertGeqMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertLesMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertLeqMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_OPEN); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_SHORT); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_MASTER_RLY); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertOpenMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertShortMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertMasterRlyMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_COIL); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_RES); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCoilMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertResMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_MOV); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_ADD); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_SUB); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_MUL); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_DIV); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertMovMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertAddMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertSubMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertMulMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertDivMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_SHIFT_REG); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_LUT); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_PWL); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_FMTD_STR); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertShiftRegMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertLutMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertPwlMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertFmtdStrMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_UART_SEND); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_UART_RECV); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_SET_PWM); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_READ_ADC); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_INSERT_PERSIST); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertUartSendMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertUartRecvMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertSetPwmMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertReadAdcMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertPersistMenu); InstructionMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InstructionMenuSeparator); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_MAKE_NORMAL); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_NEGATE); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_MAKE_SET_ONLY); - gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MNU_MAKE_RESET_ONLY); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MakeNormalMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), NegateMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MakeSetOnlyMenu); + gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MakeResetOnlyMenu); // Creating labels for Compile Menu - MNU_COMPILE = gtk_menu_item_new_with_mnemonic("_Compile"); - MNU_COMPILE_AS = gtk_menu_item_new_with_mnemonic("_Compile As..."); - - // Creating keyboard shortcuts for Compile menu - gtk_widget_add_accelerator (MNU_COMPILE, "activate", AccelGroup, GDK_KEY_F5, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + CompileMenu = gtk_menu_item_new_with_mnemonic("_Compile"); + CompileAsMenu = gtk_menu_item_new_with_mnemonic("_Compile As..."); // Appending menu items to Compile menu - gtk_menu_shell_append(GTK_MENU_SHELL (compile), MNU_COMPILE); - gtk_menu_shell_append(GTK_MENU_SHELL (compile), MNU_COMPILE_AS); + gtk_menu_shell_append(GTK_MENU_SHELL (Compile), CompileMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (Compile), CompileAsMenu); // Creating labels for Help Menu - MNU_MANUAL = gtk_menu_item_new_with_mnemonic("_Manual..."); - MNU_ABOUT = gtk_menu_item_new_with_mnemonic("_About..."); - - // Creating keyboard shortcuts for Help menu - gtk_widget_add_accelerator (MNU_MANUAL, "activate", AccelGroup, GDK_KEY_F1, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + ManualMenu = gtk_menu_item_new_with_mnemonic("_Manual..."); + AboutMenu = gtk_menu_item_new_with_mnemonic("_About..."); // Appending menu items to Help menu - gtk_menu_shell_append(GTK_MENU_SHELL (help), MNU_MANUAL); - gtk_menu_shell_append(GTK_MENU_SHELL (help), MNU_ABOUT); + gtk_menu_shell_append(GTK_MENU_SHELL (Help), ManualMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (Help), AboutMenu); // Creating labels for Simulation Menu - MNU_SIMULATION_MODE = gtk_check_menu_item_new_with_mnemonic("_Simulation Mode"); - MNU_START_SIMULATION = gtk_menu_item_new_with_mnemonic("_Start Real-Time Simulation"); - MNU_STOP_SIMULATION = gtk_menu_item_new_with_mnemonic("_Halt Simulation"); - MNU_SINGLE_CYCLE = gtk_menu_item_new_with_mnemonic("_Single Cycle"); - - // Creating keyboard shortcuts for Edit menu - gtk_widget_add_accelerator (MNU_SIMULATION_MODE, "activate", AccelGroup, GDK_KEY_M, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_START_SIMULATION, "activate", AccelGroup, GDK_KEY_R, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_STOP_SIMULATION, "activate", AccelGroup, GDK_KEY_H, - GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - gtk_widget_add_accelerator (MNU_SINGLE_CYCLE, "activate", AccelGroup, GDK_KEY_space, - GDK_RELEASE_MASK, GTK_ACCEL_VISIBLE); + SimulationModeMenu = gtk_check_menu_item_new_with_mnemonic("_Simulation Mode"); + StartSimulationMenu = gtk_menu_item_new_with_mnemonic("_Start Real-Time Simulation"); + StopSimulationMenu = gtk_menu_item_new_with_mnemonic("_Halt Simulation"); + SingleCycleMenu = gtk_menu_item_new_with_mnemonic("_Single Cycle"); // Appending menu items to Simulate menu and adding separators - gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), MNU_SIMULATION_MODE); - gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), MNU_START_SIMULATION); - gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), MNU_STOP_SIMULATION); - gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), MNU_SINGLE_CYCLE); + gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), SimulationModeMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), StartSimulationMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), StopSimulationMenu); + gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), SingleCycleMenu); SimulateMenuSeparator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(SimulateMenu), SimulateMenuSeparator); // Creating submenus for each menu gtk_menu_item_set_submenu(GTK_MENU_ITEM(FileLabel), FileMenu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(EditLabel), EditMenu); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(SettingsLabel), settings); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(SettingsLabel), Settings); gtk_menu_item_set_submenu(GTK_MENU_ITEM(InstructionLabel), InstructionMenu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(SimulateLabel), SimulateMenu); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(CompileLabel), compile); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(HelpLabel), help); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(CompileLabel), Compile); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(HelpLabel), Help); // Appending the menu item to the menu bar gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), FileLabel); @@ -507,7 +511,8 @@ HMENU MakeMainWindowMenus(void) // Packing the menu bar into the box for alignment gtk_box_pack_start(GTK_BOX(MenuBox), TopMenu, FALSE, FALSE, 0); - + AddMenuAccelerators (); + return MenuBox; } @@ -519,6 +524,7 @@ void MakeMainWindowControls(void) { HWID PackBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); HWID grid = gtk_grid_new(); + /// Pane to separate Scrolled Window and other widgets HWID pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL); IoList = gtk_list_store_new (5, @@ -532,7 +538,7 @@ void MakeMainWindowControls(void) int pinWidth = 100; int portWidth = 90; - // Creating a list + /// 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)); @@ -571,39 +577,172 @@ void MakeMainWindowControls(void) gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); gtk_tree_view_column_set_min_width (column, portWidth); - // Appending Menus to grid + /// Appending Menus to grid gtk_grid_attach (GTK_GRID (grid), MakeMainWindowMenus(), 0, 0, 1, 1); - // Creating Scrolled Window + /// Creating Scrolled Window ScrollWindow = gtk_scrolled_window_new (NULL, NULL); + HWID viewport = gtk_viewport_new (NULL,NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ScrollWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + gtk_widget_set_hexpand(GTK_WIDGET(ScrollWindow), TRUE); + gtk_widget_set_vexpand(GTK_WIDGET(ScrollWindow), TRUE); - // Creating a pane to separate Scrolled Window and other widgets - gtk_paned_add1 (GTK_PANED (pane), ScrollWindow); - gtk_paned_set_position (GTK_PANED (pane), 0); - gtk_widget_set_vexpand (ScrollWindow, TRUE); - gtk_widget_set_hexpand (ScrollWindow, TRUE); + /// Adding DrawWindow to pane + gtk_container_add (GTK_CONTAINER(viewport), DrawWindow); + gtk_container_add (GTK_CONTAINER(ScrollWindow), viewport); + gtk_paned_pack1 (GTK_PANED (pane), ScrollWindow, TRUE, TRUE); + gtk_paned_set_position (GTK_PANED (pane), 0); - // Appending tree view to pane and pane to grid + /// Appending tree view to pane and pane to grid gtk_paned_pack2 (GTK_PANED(pane), view, FALSE, FALSE); - gtk_paned_set_position (GTK_PANED (pane), 250); + gtk_paned_set_position (GTK_PANED (pane), 400); gtk_grid_attach (GTK_GRID (grid), pane, 0, 0, 1, 1); - // Creating Status Bar and attaching to grid + /// Creating Status Bar and attaching to grid StatusBar = gtk_statusbar_new(); gtk_statusbar_push (GTK_STATUSBAR (StatusBar), - gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar), "Introduction"), - "LDMicro Started"); + gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar), + "Introduction"), "LDMicro Started"); - // Appneding Status Bar to box which is then added to Main Window - gtk_box_pack_start(GTK_BOX(PackBox), grid, TRUE, TRUE, 0); + /// Appneding Status Bar to box which is then added to Main Window + gtk_box_pack_start(GTK_BOX(PackBox), grid, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(PackBox), StatusBar, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(MainWindow), PackBox); } //----------------------------------------------------------------------------- +// Adjust the size and visibility of the scrollbars as necessary, either due +// to a change in the size of the program or a change in the size of the +// window. +//----------------------------------------------------------------------------- +void RefreshScrollbars(void) +{ + // SCROLLINFO vert, horiz; + // SetUpScrollbars(&NeedHoriz, &horiz, &vert); + // SetScrollInfo(HorizScrollBar, SB_CTL, &horiz, TRUE); + // SetScrollInfo(VertScrollBar, SB_CTL, &vert, TRUE); + + // RECT main; + // GetClientRect(MainWindow, &main); + + // if(NeedHoriz) { + // MoveWindow(HorizScrollBar, 0, IoListTop - ScrollHeight - 2, + // main.right - ScrollWidth - 2, ScrollHeight, TRUE); + // ShowWindow(HorizScrollBar, SW_SHOW); + // EnableWindow(HorizScrollBar, TRUE); + // } else { + // ShowWindow(HorizScrollBar, SW_HIDE); + // } + // MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth, + // NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE); + + // MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth, + // NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE); + + // InvalidateRect(MainWindow, NULL, FALSE); +} + +//----------------------------------------------------------------------------- +// Respond to a WM_VSCROLL sent to the main window, presumably by the one and +// only vertical scrollbar that it has as a child. +//----------------------------------------------------------------------------- +void VscrollProc(WPARAM wParam) +{ + // int prevY = ScrollYOffset; + // switch(LOWORD(wParam)) { + // case SB_LINEUP: + // case SB_PAGEUP: + // if(ScrollYOffset > 0) { + // ScrollYOffset--; + // } + // break; + + // case SB_LINEDOWN: + // case SB_PAGEDOWN: + // if(ScrollYOffset < ScrollYOffsetMax) { + // ScrollYOffset++; + // } + // break; + + // case SB_TOP: + // ScrollYOffset = 0; + // break; + + // case SB_BOTTOM: + // ScrollYOffset = ScrollYOffsetMax; + // break; + + // case SB_THUMBTRACK: + // case SB_THUMBPOSITION: + // ScrollYOffset = HIWORD(wParam); + // break; + // } + // if(prevY != ScrollYOffset) { + // SCROLLINFO si; + // si.cbSize = sizeof(si); + // si.fMask = SIF_POS; + // si.nPos = ScrollYOffset; + // SetScrollInfo(VertScrollBar, SB_CTL, &si, TRUE); + + // InvalidateRect(MainWindow, NULL, FALSE); + // } +} + +//----------------------------------------------------------------------------- +// Respond to a WM_HSCROLL sent to the main window, presumably by the one and +// only horizontal scrollbar that it has as a child. +//----------------------------------------------------------------------------- +void HscrollProc(WPARAM wParam) +{ + // int prevX = ScrollXOffset; + // switch(LOWORD(wParam)) { + // case SB_LINEUP: + // ScrollXOffset -= FONT_WIDTH; + // break; + + // case SB_PAGEUP: + // ScrollXOffset -= POS_WIDTH*FONT_WIDTH; + // break; + + // case SB_LINEDOWN: + // ScrollXOffset += FONT_WIDTH; + // break; + + // case SB_PAGEDOWN: + // ScrollXOffset += POS_WIDTH*FONT_WIDTH; + // break; + + // case SB_TOP: + // ScrollXOffset = 0; + // break; + + // case SB_BOTTOM: + // ScrollXOffset = ScrollXOffsetMax; + // break; + + // case SB_THUMBTRACK: + // case SB_THUMBPOSITION: + // ScrollXOffset = HIWORD(wParam); + // break; + // } + + // if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax; + // if(ScrollXOffset < 0) ScrollXOffset = 0; + + // if(prevX != ScrollXOffset) { + // SCROLLINFO si; + // si.cbSize = sizeof(si); + // si.fMask = SIF_POS; + // si.nPos = ScrollXOffset; + // SetScrollInfo(HorizScrollBar, SB_CTL, &si, TRUE); + + // InvalidateRect(MainWindow, NULL, FALSE); + // } +} + +//----------------------------------------------------------------------------- // Set up the title bar text for the main window; indicate whether we are in // simulation or editing mode, and indicate the filename. //----------------------------------------------------------------------------- @@ -636,66 +775,66 @@ void SetMenusEnabled(BOOL canNegate, BOOL canNormal, BOOL canResetOnly, BOOL canSetOnly, BOOL canDelete, BOOL canInsertEnd, BOOL canInsertOther, BOOL canPushDown, BOOL canPushUp, BOOL canInsertComment) { - EnableMenuItem(EditMenu, MNU_PUSH_RUNG_UP, + EnableMenuItem(EditMenu, PushRungUpMenu, canPushUp ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(EditMenu, MNU_PUSH_RUNG_DOWN, + EnableMenuItem(EditMenu, PushRungDownMenu, canPushDown ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(EditMenu, MNU_DELETE_RUNG, + EnableMenuItem(EditMenu, DeleteRungMenu, (Prog.numRungs > 1) ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(InstructionMenu, MNU_NEGATE, + EnableMenuItem(InstructionMenu, NegateMenu, canNegate ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(InstructionMenu, MNU_MAKE_NORMAL, + EnableMenuItem(InstructionMenu, MakeNormalMenu, canNormal ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(InstructionMenu, MNU_MAKE_RESET_ONLY, + EnableMenuItem(InstructionMenu, MakeResetOnlyMenu, canResetOnly ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(InstructionMenu, MNU_MAKE_SET_ONLY, + EnableMenuItem(InstructionMenu, MakeSetOnlyMenu, canSetOnly ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(InstructionMenu, MNU_INSERT_COMMENT, + EnableMenuItem(InstructionMenu, InsertCommentMenu, canInsertComment ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(EditMenu, MNU_DELETE_ELEMENT, + EnableMenuItem(EditMenu, DeleteElementMenu, canDelete ? MF_ENABLED : MF_GRAYED); int t; t = canInsertEnd ? MF_ENABLED : MF_GRAYED; - EnableMenuItem(InstructionMenu, MNU_INSERT_COIL, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_RES, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_MOV, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_ADD, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_SUB, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_MUL, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_DIV, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_CTC, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_PERSIST, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_READ_ADC, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_SET_PWM, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_MASTER_RLY, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_SHIFT_REG, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_LUT, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_PWL, t); + EnableMenuItem(InstructionMenu, InsertCoilMenu, t); + EnableMenuItem(InstructionMenu, InsertResMenu, t); + EnableMenuItem(InstructionMenu, InsertMovMenu, t); + EnableMenuItem(InstructionMenu, InsertAddMenu, t); + EnableMenuItem(InstructionMenu, InsertSubMenu, t); + EnableMenuItem(InstructionMenu, InsertMulMenu, t); + EnableMenuItem(InstructionMenu, InsertDivMenu, t); + EnableMenuItem(InstructionMenu, InsertCtcMenu, t); + EnableMenuItem(InstructionMenu, InsertPersistMenu, t); + EnableMenuItem(InstructionMenu, InsertReadAdcMenu, t); + EnableMenuItem(InstructionMenu, InsertSetPwmMenu, t); + EnableMenuItem(InstructionMenu, InsertMasterRlyMenu, t); + EnableMenuItem(InstructionMenu, InsertShiftRegMenu, t); + EnableMenuItem(InstructionMenu, InsertLutMenu, t); + EnableMenuItem(InstructionMenu, InsertPwlMenu, t); t = canInsertOther ? MF_ENABLED : MF_GRAYED; - EnableMenuItem(InstructionMenu, MNU_INSERT_TON, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_TOF, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_OSR, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_OSF, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_RTO, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_CONTACTS, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_CTU, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_CTD, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_EQU, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_NEQ, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_GRT, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_GEQ, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_LES, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_LEQ, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_SHORT, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_OPEN, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_UART_SEND, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_UART_RECV, t); - EnableMenuItem(InstructionMenu, MNU_INSERT_FMTD_STR, t); + EnableMenuItem(InstructionMenu, InsertTonMenu, t); + EnableMenuItem(InstructionMenu, InsertTofMenu, t); + EnableMenuItem(InstructionMenu, InsertOsrMenu, t); + EnableMenuItem(InstructionMenu, InsertOsfMenu, t); + EnableMenuItem(InstructionMenu, InsertRtoMenu, t); + EnableMenuItem(InstructionMenu, InsertContactsMenu, t); + EnableMenuItem(InstructionMenu, InsertCtuMenu, t); + EnableMenuItem(InstructionMenu, InsertCtdMenu, t); + EnableMenuItem(InstructionMenu, InsertEquMenu, t); + EnableMenuItem(InstructionMenu, InsertNeqMenu, t); + EnableMenuItem(InstructionMenu, InsertGrtMenu, t); + EnableMenuItem(InstructionMenu, InsertGeqMenu, t); + EnableMenuItem(InstructionMenu, InsertLesMenu, t); + EnableMenuItem(InstructionMenu, InsertLeqMenu, t); + EnableMenuItem(InstructionMenu, InsertShortMenu, t); + EnableMenuItem(InstructionMenu, InsertOpenMenu, t); + EnableMenuItem(InstructionMenu, InsertUartSendMenu, t); + EnableMenuItem(InstructionMenu, InsertUartRecvMenu, t); + EnableMenuItem(InstructionMenu, InsertFmtdStrMenu, t); } //----------------------------------------------------------------------------- @@ -703,8 +842,8 @@ void SetMenusEnabled(BOOL canNegate, BOOL canNormal, BOOL canResetOnly, //----------------------------------------------------------------------------- void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled) { - // EnableMenuItem(EditMenu, MNU_UNDO, undoEnabled ? MF_ENABLED : MF_GRAYED); - // EnableMenuItem(EditMenu, MNU_REDO, redoEnabled ? MF_ENABLED : MF_GRAYED); + EnableMenuItem(EditMenu, UndoMenu, undoEnabled ? MF_ENABLED : MF_GRAYED); + EnableMenuItem(EditMenu, RedoMenu, redoEnabled ? MF_ENABLED : MF_GRAYED); } //----------------------------------------------------------------------------- @@ -715,24 +854,24 @@ void ToggleSimulationMode(void) { InSimulationMode = !InSimulationMode; if(InSimulationMode) { - EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_ENABLED); - EnableMenuItem(SimulateMenu, MNU_SINGLE_CYCLE, MF_ENABLED); + EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED); + EnableMenuItem(SimulateMenu, SingleCycleMenu, MF_ENABLED); - EnableMenuItem(FileMenu, MNU_OPEN, MF_GRAYED); - EnableMenuItem(FileMenu, MNU_SAVE, MF_GRAYED); - EnableMenuItem(FileMenu, MNU_SAVE_AS, MF_GRAYED); - EnableMenuItem(FileMenu, MNU_NEW, MF_GRAYED); - EnableMenuItem(FileMenu, MNU_EXPORT, MF_GRAYED); + EnableMenuItem(FileMenu, OpenMenu, MF_GRAYED); + EnableMenuItem(FileMenu, SaveMenu, MF_GRAYED); + EnableMenuItem(FileMenu, SaveAsMenu_AS, MF_GRAYED); + EnableMenuItem(FileMenu, NewMenu, MF_GRAYED); + EnableMenuItem(FileMenu, ExportMenu, MF_GRAYED); EnableMenuItem(TopMenu, EditMenu, MF_GRAYED); - EnableMenuItem(TopMenu, settings, MF_GRAYED); + EnableMenuItem(TopMenu, Settings, MF_GRAYED); EnableMenuItem(TopMenu, InstructionMenu, MF_GRAYED); - EnableMenuItem(TopMenu, compile, MF_GRAYED); + EnableMenuItem(TopMenu, Compile, MF_GRAYED); - CheckMenuItem(SimulateMenu, MNU_SIMULATION_MODE, MF_CHECKED); + CheckMenuItem(SimulateMenu, SimulationModeMenu, MF_CHECKED); // ClearSimulationData(); // simulation.cpp, ldmicro.h - // Recheck InSimulationMode, because there could have been a compile + // Recheck InSimulationMode, because there could have been a Compile // error, which would have kicked us out of simulation mode. // if(UartFunctionUsed() && InSimulationMode) { // ShowUartSimulationWindow(); // simulate.cpp @@ -742,22 +881,22 @@ void ToggleSimulationMode(void) RealTimeSimulationRunning = FALSE; // KillTimer(MainWindow, TIMER_SIMULATE); - EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_GRAYED); - EnableMenuItem(SimulateMenu, MNU_STOP_SIMULATION, MF_GRAYED); - EnableMenuItem(SimulateMenu, MNU_SINGLE_CYCLE, MF_GRAYED); + EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_GRAYED); + EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED); + EnableMenuItem(SimulateMenu, SingleCycleMenu, MF_GRAYED); - EnableMenuItem(FileMenu, MNU_OPEN, MF_ENABLED); - EnableMenuItem(FileMenu, MNU_SAVE, MF_ENABLED); - EnableMenuItem(FileMenu, MNU_SAVE_AS, MF_ENABLED); - EnableMenuItem(FileMenu, MNU_NEW, MF_ENABLED); - EnableMenuItem(FileMenu, MNU_EXPORT, MF_ENABLED); + EnableMenuItem(FileMenu, OpenMenu, MF_ENABLED); + EnableMenuItem(FileMenu, SaveMenu, MF_ENABLED); + EnableMenuItem(FileMenu, SaveAsMenu_AS, MF_ENABLED); + EnableMenuItem(FileMenu, NewMenu, MF_ENABLED); + EnableMenuItem(FileMenu, ExportMenu, MF_ENABLED); EnableMenuItem(TopMenu, EditMenu, MF_ENABLED); - EnableMenuItem(TopMenu, settings, MF_ENABLED); + EnableMenuItem(TopMenu, Settings, MF_ENABLED); EnableMenuItem(TopMenu, InstructionMenu, MF_ENABLED); - EnableMenuItem(TopMenu, compile, MF_ENABLED); + EnableMenuItem(TopMenu, Compile, MF_ENABLED); - CheckMenuItem(SimulateMenu, MNU_SIMULATION_MODE, MF_UNCHECKED); + CheckMenuItem(SimulateMenu, SimulationModeMenu, MF_UNCHECKED); // if(UartFunctionUsed()) { // DestroyUartSimulationWindow(); @@ -807,18 +946,18 @@ void RefreshControlsToSettings(void) } for(i = 0; i < NUM_SUPPORTED_MCUS; i++) { if(&SupportedMcus[i] == Prog.mcu) { - CheckMenuItem(ProcessorMenu, MNU_PROCESSOR[i], MF_CHECKED); + CheckMenuItem(ProcessorMenu, ProcessorMenuItems[i], MF_CHECKED); } else { - CheckMenuItem(ProcessorMenu, MNU_PROCESSOR[i], MF_UNCHECKED); + CheckMenuItem(ProcessorMenu, ProcessorMenuItems[i], MF_UNCHECKED); } } // `(no microcontroller)' setting if (!Prog.mcu){ - CheckMenuItem(ProcessorMenu, MNU_PROCESSOR[NUM_SUPPORTED_MCUS], MF_CHECKED); + CheckMenuItem(ProcessorMenu, ProcessorMenuItems[NUM_SUPPORTED_MCUS], MF_CHECKED); } else { - CheckMenuItem(ProcessorMenu, MNU_PROCESSOR[NUM_SUPPORTED_MCUS], MF_UNCHECKED); + CheckMenuItem(ProcessorMenu, ProcessorMenuItems[NUM_SUPPORTED_MCUS], MF_UNCHECKED); } } @@ -869,8 +1008,8 @@ void MainWindowResized(void) void StartSimulation(void) { RealTimeSimulationRunning = TRUE; - EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_GRAYED); - EnableMenuItem(SimulateMenu, MNU_STOP_SIMULATION, MF_ENABLED); + EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_GRAYED); + EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_ENABLED); // StartSimulationTimer(); UpdateMainWindowTitleBar(); } @@ -883,8 +1022,8 @@ void StopSimulation(void) { RealTimeSimulationRunning = FALSE; - EnableMenuItem(SimulateMenu, MNU_START_SIMULATION, MF_ENABLED); - EnableMenuItem(SimulateMenu, MNU_STOP_SIMULATION, MF_GRAYED); + EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED); + EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED); // KillTimer(MainWindow, TIMER_SIMULATE); UpdateMainWindowTitleBar(); diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp index 4fddcf4..092f606 100644 --- a/ldmicro/miscutil.cpp +++ b/ldmicro/miscutil.cpp @@ -259,8 +259,9 @@ static LRESULT CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, //----------------------------------------------------------------------------- // Set the font of a control to a pretty proportional font (typ. Tahoma). //----------------------------------------------------------------------------- -void NiceFont(HWND h) +void NiceFont(HWID h) { + // gtk_widget_override_font(GTK_WIDGET(h), pango_font_description_from_string("Times New Roman")); // SendMessage(h, WM_SETFONT, (WPARAM)MyNiceFont, TRUE); } diff --git a/ldmicro/reg/t.pl b/ldmicro/reg/t.pl new file mode 100644 index 0000000..b388e96 --- /dev/null +++ b/ldmicro/reg/t.pl @@ -0,0 +1,205 @@ + 0:set bit '$mcr' + 1:# + 2:# start rung 2 + 3:let bit '$rung_top' := '$mcr' + 4: + 5:# start series [ + 6:if not 'Rosc' { + 7: clear bit '$rung_top' + 8:} + 9: + 10:if not '$Tof_antiglitch' { + 11: let var 'Tof' := 9 + 12:} + 13:set bit '$Tof_antiglitch' + 14:if not '$rung_top' { + 15: if 'Tof' < 9 { + 16: increment 'Tof' + 17: set bit '$rung_top' + 18: } + 19:} else { + 20: let var 'Tof' := 0 + 21:} + 22: + 23:if '$rung_top' { + 24: if 'Ton' < 9 { + 25: increment 'Ton' + 26: clear bit '$rung_top' + 27: } + 28:} else { + 29: let var 'Ton' := 0 + 30:} + 31: + 32:if '$rung_top' { + 33: clear bit 'Rosc' + 34:} else { + 35: set bit 'Rosc' + 36:} + 37: + 38:# ] finish series + 39:# + 40:# start rung 3 + 41:let bit '$rung_top' := '$mcr' + 42: + 43:# start series [ + 44:if not 'Rosc' { + 45: clear bit '$rung_top' + 46:} + 47: + 48:if not 'Xup' { + 49: clear bit '$rung_top' + 50:} + 51: + 52:if '$rung_top' { + 53: if not '$oneShot_0000' { + 54: increment 'Ccnt' + 55: } + 56:} + 57:let bit '$oneShot_0000' := '$rung_top' + 58:if 'Ccnt' < 20 { + 59: clear bit '$rung_top' + 60:} else { + 61: set bit '$rung_top' + 62:} + 63: + 64:if 'Trto' < 999 { + 65: if '$rung_top' { + 66: increment 'Trto' + 67: } + 68: clear bit '$rung_top' + 69:} else { + 70: set bit '$rung_top' + 71:} + 72: + 73:let bit 'Yup' := '$rung_top' + 74: + 75:# ] finish series + 76:# + 77:# start rung 4 + 78:let bit '$rung_top' := '$mcr' + 79: + 80:# start series [ + 81:if not 'Rosc' { + 82: clear bit '$rung_top' + 83:} + 84: + 85:if not 'Xdown' { + 86: clear bit '$rung_top' + 87:} + 88: + 89:if '$rung_top' { + 90: if not '$oneShot_0001' { + 91: let var '$scratch' := 1 + 92: let var 'Ccnt' := 'Ccnt' - '$scratch' + 93: } + 94:} + 95:let bit '$oneShot_0001' := '$rung_top' + 96:if 'Ccnt' < 10 { + 97: clear bit '$rung_top' + 98:} else { + 99: set bit '$rung_top' +100:} +101: +102:let bit 'Ydown' := '$rung_top' +103: +104:# ] finish series +105:# +106:# start rung 5 +107:let bit '$rung_top' := '$mcr' +108: +109:# start series [ +110:if not 'Xres' { +111: clear bit '$rung_top' +112:} +113: +114:# start parallel [ +115:clear bit '$parOut_0000' +116:let bit '$parThis_0000' := '$rung_top' +117:let bit '$scratch' := '$parThis_0000' +118:if '$oneShot_0002' { +119: clear bit '$parThis_0000' +120:} +121:let bit '$oneShot_0002' := '$scratch' +122: +123:if '$parThis_0000' { +124: set bit '$parOut_0000' +125:} +126:let bit '$parThis_0000' := '$rung_top' +127:let bit '$scratch' := '$parThis_0000' +128:if not '$parThis_0000' { +129: if '$oneShot_0003' { +130: set bit '$parThis_0000' +131: } +132:} else { +133: clear bit '$parThis_0000' +134:} +135:let bit '$oneShot_0003' := '$scratch' +136: +137:if '$parThis_0000' { +138: set bit '$parOut_0000' +139:} +140:let bit '$rung_top' := '$parOut_0000' +141:# ] finish parallel +142:if '$rung_top' { +143: let var 'Trto' := 0 +144:} +145: +146:# ] finish series +147:# +148:# start rung 6 +149:let bit '$rung_top' := '$mcr' +150: +151:# start series [ +152:if not 'Rosc' { +153: clear bit '$rung_top' +154:} +155: +156:if '$rung_top' { +157: if not '$oneShot_0004' { +158: increment 'Ccirc' +159: if 'Ccirc' < 8 { +160: } else { +161: let var 'Ccirc' := 0 +162: } +163: } +164:} +165:let bit '$oneShot_0004' := '$rung_top' +166: +167:# ] finish series +168:# +169:# start rung 7 +170:let bit '$rung_top' := '$mcr' +171: +172:# start series [ +173:let var '$scratch2' := 3 +174:if 'Ccirc' == '$scratch2' { +175:} else { +176: clear bit '$rung_top' +177:} +178: +179:let bit '$scratch' := '$rung_top' +180:if not '$rung_top' { +181: if '$oneShot_0005' { +182: set bit '$rung_top' +183: } +184:} else { +185: clear bit '$rung_top' +186:} +187:let bit '$oneShot_0005' := '$scratch' +188: +189:if not '$Tpulse_antiglitch' { +190: let var 'Tpulse' := 19 +191:} +192:set bit '$Tpulse_antiglitch' +193:if not '$rung_top' { +194: if 'Tpulse' < 19 { +195: increment 'Tpulse' +196: set bit '$rung_top' +197: } +198:} else { +199: let var 'Tpulse' := 0 +200:} +201: +202:let bit 'Ypulse' := '$rung_top' +203: +204:# ] finish series |