diff options
author | Ramana | 2018-06-27 10:01:08 +0530 |
---|---|---|
committer | GitHub | 2018-06-27 10:01:08 +0530 |
commit | 4f88b81d90a572e28daa4fe4ec975cb822ef71b2 (patch) | |
tree | 0a5bfb530124245a022145b480b4b7d00ca96e61 | |
parent | 7eafe025a1b57cac75d9881c235681212616f19e (diff) | |
parent | 78fc70bd2d6d296697060bce13221edc909b71a5 (diff) | |
download | LDMicroGtk-4f88b81d90a572e28daa4fe4ec975cb822ef71b2.tar.gz LDMicroGtk-4f88b81d90a572e28daa4fe4ec975cb822ef71b2.tar.bz2 LDMicroGtk-4f88b81d90a572e28daa4fe4ec975cb822ef71b2.zip |
Merge pull request #27 from akshay-c/GUI_Port_2
-rw-r--r-- | ldmicro/coildialog.cpp | 169 | ||||
-rw-r--r-- | ldmicro/confdialog.cpp | 79 | ||||
-rw-r--r-- | ldmicro/contactsdialog.cpp | 271 | ||||
-rw-r--r-- | ldmicro/includes/ldmicro.h | 4 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 3 | ||||
-rw-r--r-- | ldmicro/lutdialog.cpp | 911 | ||||
-rw-r--r-- | ldmicro/miscutil.cpp | 4 | ||||
-rw-r--r-- | ldmicro/resetdialog.cpp | 234 | ||||
-rw-r--r-- | ldmicro/schematic.cpp | 8 |
9 files changed, 895 insertions, 788 deletions
diff --git a/ldmicro/coildialog.cpp b/ldmicro/coildialog.cpp index 22fd10c..f04de10 100644 --- a/ldmicro/coildialog.cpp +++ b/ldmicro/coildialog.cpp @@ -27,108 +27,109 @@ #include "ldmicro.h" -static HWND CoilDialog; - -static HWND SourceInternalRelayRadio; -static HWND SourceMcuPinRadio; -static HWND NegatedRadio; -static HWND NormalRadio; -static HWND SetOnlyRadio; -static HWND ResetOnlyRadio; -static HWND NameTextbox; +static HWID CoilDialog; + +static HWID SourceInternalRelayRadio; +static HWID SourceMcuPinRadio; +static HWID NegatedRadio; +static HWID NormalRadio; +static HWID SetOnlyRadio; +static HWID ResetOnlyRadio; +static HWID NameTextbox; +static HWID OkButton; +static HWID CancelButton; static LONG_PTR PrevNameProc; -//----------------------------------------------------------------------------- -// Don't allow any characters other than A-Za-z0-9_ in the name. -//----------------------------------------------------------------------------- -// static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, -// LPARAM lParam) -// { -// if(msg == WM_CHAR) { -// if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || -// wParam == '\b')) -// { -// return 0; +HWID CoilGrid; +HWID CoilPackingBox; + +// //----------------------------------------------------------------------------- +// // Don't allow any characters other than A-Za-z0-9_ in the name. +// //----------------------------------------------------------------------------- +// // static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, +// // LPARAM lParam) +// // { +// // if(msg == WM_CHAR) { +// // if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || +// // wParam == '\b')) +// // { +// // return 0; +// // } +// // } + +// // return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); +// // } + +// void CoilDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, +// gint *position, gpointer data){ +// // gtk_widget_set_sensitive (MainWindow, TRUE); +// for (int i = 0; i < length; i++){ +// if (!(isalpha (NewText[i]) || NewText[i] == '_' || isdigit (NewText[i]) +// || NewText[i] == '\b' )){ +// g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); +// return; // } // } - -// return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); // } + // static void MakeControls(void) // { -// HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Type"), -// WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, -// 7, 3, 120, 105, CoilDialog, NULL, Instance, NULL); -// NiceFont(grouper); - // NormalRadio = CreateWindowEx(0, WC_BUTTON, _("( ) Normal"), // WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, // 16, 21, 100, 20, CoilDialog, NULL, Instance, NULL); // NiceFont(NormalRadio); -// NegatedRadio = CreateWindowEx(0, WC_BUTTON, _("(/) Negated"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 41, 100, 20, CoilDialog, NULL, Instance, NULL); -// NiceFont(NegatedRadio); - -// SetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(S) Set-Only"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 61, 100, 20, CoilDialog, NULL, Instance, NULL); -// NiceFont(SetOnlyRadio); - -// ResetOnlyRadio = CreateWindowEx(0, WC_BUTTON, _("(R) Reset-Only"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 81, 105, 20, CoilDialog, NULL, Instance, NULL); -// NiceFont(ResetOnlyRadio); - -// HWND grouper2 = CreateWindowEx(0, WC_BUTTON, _("Source"), -// WS_CHILD | BS_GROUPBOX | WS_VISIBLE, -// 140, 3, 120, 65, CoilDialog, NULL, Instance, NULL); -// NiceFont(grouper2); - -// SourceInternalRelayRadio = CreateWindowEx(0, WC_BUTTON, _("Internal Relay"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_GROUP | WS_TABSTOP, -// 149, 21, 100, 20, CoilDialog, NULL, Instance, NULL); -// NiceFont(SourceInternalRelayRadio); - -// SourceMcuPinRadio = CreateWindowEx(0, WC_BUTTON, _("Pin on MCU"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_TABSTOP, -// 149, 41, 100, 20, CoilDialog, NULL, Instance, NULL); -// NiceFont(SourceMcuPinRadio); - -// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 135, 80, 50, 21, CoilDialog, NULL, Instance, NULL); -// NiceFont(textLabel); - -// NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 190, 80, 155, 21, CoilDialog, NULL, Instance, NULL); -// FixedFont(NameTextbox); - -// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, -// 276, 10, 70, 23, CoilDialog, NULL, Instance, NULL); -// NiceFont(OkButton); - -// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 276, 40, 70, 23, CoilDialog, NULL, Instance, NULL); -// NiceFont(CancelButton); - -// PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, -// (LONG_PTR)MyNameProc); +// NormalRadio = gtk_radio_button_new_with_label (NULL, "( ) Normal"); +// NegatedRadio = gtk_radio_button_new_with_label_from_widget +// (GTK_RADIO_BUTTON (NormalRadio), "(/) Negated"); +// SetOnlyRadio = gtk_radio_button_new_with_label_from_widget +// (GTK_RADIO_BUTTON (NormalRadio), "(S) Set-Only"); +// ResetOnlyRadio = gtk_radio_button_new_with_label_from_widget +// (GTK_RADIO_BUTTON (NormalRadio), "(R) Reset-Only"); + +// SourceInternalRelayRadio = gtk_radio_button_new_with_label (NULL, "Internal Relay"); +// SourceMcuPinRadio = gtk_radio_button_new_with_label_from_widget +// (GTK_RADIO_BUTTON (SourceInternalRelayRadio), "Pin on MCU"); + +// HWID textLabel = gtk_label_new ("Name:"); + +// NameTextbox = gtk_entry_new(); +// gtk_entry_set_max_length (GTK_ENTRY (NameTextbox), 0); + +// OkButton = gtk_button_new_with_label ("OK"); +// CancelButton = gtk_button_new_with_label ("Cancel"); + +// gtk_grid_attach (GTK_GRID (CoilGrid), SourceInternalRelayRadio, 1, 2, 1, 1); +// gtk_grid_attach (GTK_GRID (CoilGrid), SourceInputPinRadio, 1, 3, 1, 1); +// gtk_grid_attach (GTK_GRID (CoilGrid), SourceOutputPinRadio, 1, 4, 1, 1); +// gtk_grid_attach (GTK_GRID (CoilGrid), textLabel, 2, 2, 1, 1); +// gtk_grid_attach (GTK_GRID (CoilGrid), NegatedCheckbox, 2, 3, 1, 1); +// gtk_grid_attach (GTK_GRID (CoilGrid), NameTextbox, 3, 2, 1, 1); +// gtk_grid_attach (GTK_GRID (CoilGrid), OkButton, 4, 2, 1, 1); +// gtk_grid_attach (GTK_GRID (CoilGrid), CancelButton, 4, 3, 1, 1); + +// gtk_grid_set_column_spacing (GTK_GRID (CoilGrid), 1); +// gtk_box_pack_start(GTK_BOX(CoilPackingBox), CoilGrid, TRUE, TRUE, 0); + + +// // PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, +// // (LONG_PTR)MyNameProc); // } // void ShowCoilDialog(BOOL *negated, BOOL *setOnly, BOOL *resetOnly, char *name) // { -// CoilDialog = CreateWindowClient(0, "LDmicroDialog", -// _("Coil"), WS_OVERLAPPED | WS_SYSMENU, -// 100, 100, 359, 115, NULL, NULL, Instance, NULL); -// RECT r; -// GetClientRect(CoilDialog, &r); +// CoilGrid = gtk_grid_new(); +// CoilPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + +// CoilDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); +// gtk_window_set_title(GTK_WINDOW(CoilDialog), "Coil"); +// gtk_window_set_default_size(GTK_WINDOW(CoilDialog), 100, 50); +// gtk_window_set_resizable (GTK_WINDOW (CoilDialog), FALSE); +// gtk_container_add(GTK_CONTAINER(CoilDialog), CoilPackingBox); +// gtk_widget_add_events (CoilDialog, GDK_KEY_PRESS_MASK); +// gtk_widget_add_events (CoilDialog, GDK_BUTTON_PRESS_MASK); // MakeControls(); diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp index a99c8c3..2fd8dd7 100644 --- a/ldmicro/confdialog.cpp +++ b/ldmicro/confdialog.cpp @@ -36,15 +36,15 @@ static HWID ConfDialog; static HWID CrystalTextbox; static HWID CycleTextbox; static HWID BaudTextbox; -static HWID ButtonOk; -static HWID ButtonCancel; +static HWID OkButton; +static HWID CancelButton; static LONG_PTR PrevCrystalProc; static LONG_PTR PrevCycleProc; static LONG_PTR PrevBaudProc; -HWID Grid; -HWID PackingBox; +HWID ConfGrid; +HWID ConfPackingBox; static void MakeControls(void) { @@ -74,8 +74,8 @@ static void MakeControls(void) gtk_widget_set_sensitive (textLabel2, FALSE); } - ButtonOk = gtk_button_new_with_label ("OK"); - ButtonCancel = gtk_button_new_with_label ("Cancel"); + OkButton = gtk_button_new_with_label ("OK"); + CancelButton = gtk_button_new_with_label ("Cancel"); char explanation[1024] = ""; @@ -111,22 +111,22 @@ static void MakeControls(void) 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); + ConfGrid = gtk_grid_new(); + ConfPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + gtk_grid_attach (GTK_GRID (ConfGrid), textLabel, 1, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ConfGrid), CycleTextbox, 3, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ConfGrid), OkButton, 6, 2, 2, 1); + gtk_grid_attach (GTK_GRID (ConfGrid), textLabel2, 1, 4, 1, 1); + gtk_grid_attach (GTK_GRID (ConfGrid), CrystalTextbox, 3, 4, 1, 1); + gtk_grid_attach (GTK_GRID (ConfGrid), CancelButton, 6, 4, 2, 1); + gtk_grid_attach (GTK_GRID (ConfGrid), textLabel3, 1, 6, 1, 1); + gtk_grid_attach (GTK_GRID (ConfGrid), BaudTextbox, 3, 6, 1, 1); - gtk_grid_set_column_spacing (GTK_GRID (Grid), 2); + gtk_grid_set_column_spacing (GTK_GRID (ConfGrid), 2); - gtk_box_pack_start(GTK_BOX(PackingBox), Grid, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(PackingBox), textLabel4, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(ConfPackingBox), ConfGrid, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(ConfPackingBox), textLabel4, TRUE, TRUE, 0); // PrevCycleProc = SetWindowLongPtr(CycleTextbox, GWLP_WNDPROC, // (LONG_PTR)MyNumberProc); @@ -142,8 +142,9 @@ static void MakeControls(void) // Don't allow any characters other than 0-9. in the text boxes. //----------------------------------------------------------------------------- -void MyNumberProc (GtkEditable *editable, gchar *NewText, gint length, +void ConfDialogMyNumberProc (GtkEditable *editable, gchar *NewText, gint length, gint *position, gpointer data){ + gtk_widget_set_sensitive (MainWindow, TRUE); for (int i = 0; i < length; i++){ if (!(isdigit (NewText[i]) || NewText[i] == '.' || NewText[i] == '\b')){ g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); @@ -153,7 +154,7 @@ void MyNumberProc (GtkEditable *editable, gchar *NewText, gint length, } // Gets data from the text boxes -void GetData (GtkWidget* widget, gpointer data){ +void ConfDialogGetData (GtkWidget* widget, gpointer data){ char* buf; buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY (CycleTextbox))); @@ -172,30 +173,36 @@ void GetData (GtkWidget* widget, gpointer data){ } // Checks for the required key press -gboolean KeyPress (GtkWidget* widget, GdkEventKey* event, gpointer data){ +gboolean ConfDialogKeyPress (GtkWidget* widget, GdkEventKey* event, gpointer data){ if (event -> keyval == GDK_KEY_Return){ - GetData(NULL, NULL); + ConfDialogGetData(NULL, NULL); } else if (event -> keyval == GDK_KEY_Escape){ DestroyWindow (ConfDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); } return FALSE; } +void ConfCallDestroyWindow (HWID widget, gpointer data){ + DestroyWindow (ConfDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); +} + // Consists of all the signal calls -void SignalCall () { +void ConfDialogSignalCall () { g_signal_connect (G_OBJECT(CycleTextbox), "insert-text", - G_CALLBACK(MyNumberProc), NULL); + G_CALLBACK(ConfDialogMyNumberProc), NULL); g_signal_connect (G_OBJECT(CrystalTextbox), "insert-text", - G_CALLBACK(MyNumberProc), NULL); + G_CALLBACK(ConfDialogMyNumberProc), NULL); g_signal_connect (G_OBJECT(BaudTextbox), "insert-text", - G_CALLBACK(MyNumberProc), NULL); + G_CALLBACK(ConfDialogMyNumberProc), NULL); g_signal_connect (G_OBJECT (ConfDialog), "key-press-event", - G_CALLBACK(KeyPress), NULL); - g_signal_connect (G_OBJECT (ButtonOk), "clicked", - G_CALLBACK(GetData), NULL); - g_signal_connect (G_OBJECT (ButtonCancel), "clicked", - G_CALLBACK(DestroyWindow), NULL); + G_CALLBACK(ConfDialogKeyPress), NULL); + g_signal_connect (G_OBJECT (OkButton), "clicked", + G_CALLBACK(ConfDialogGetData), NULL); + g_signal_connect (G_OBJECT (CancelButton), "clicked", + G_CALLBACK(ConfCallDestroyWindow), NULL); } void ShowConfDialog(void) @@ -208,7 +215,7 @@ void ShowConfDialog(void) 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_container_add(GTK_CONTAINER(ConfDialog), ConfPackingBox); gtk_widget_add_events (ConfDialog, GDK_KEY_PRESS_MASK); gtk_widget_add_events (ConfDialog, GDK_BUTTON_PRESS_MASK); @@ -223,12 +230,12 @@ void ShowConfDialog(void) gtk_entry_set_text (GTK_ENTRY (BaudTextbox), buf); gtk_widget_set_sensitive (MainWindow, FALSE); - gtk_widget_grab_focus (ButtonOk); + gtk_widget_grab_focus (OkButton); gtk_widget_set_state_flags (CycleTextbox, GTK_STATE_FLAG_FOCUSED, TRUE); gtk_widget_grab_focus (CycleTextbox); gtk_widget_show_all (ConfDialog); - SignalCall(); + ConfDialogSignalCall(); return; }
\ No newline at end of file diff --git a/ldmicro/contactsdialog.cpp b/ldmicro/contactsdialog.cpp index a845220..8d6e8d4 100644 --- a/ldmicro/contactsdialog.cpp +++ b/ldmicro/contactsdialog.cpp @@ -27,16 +27,21 @@ #include "ldmicro.h" -static HWND ContactsDialog; +static HWID ContactsDialog; -static HWND NegatedCheckbox; -static HWND SourceInternalRelayRadio; -static HWND SourceInputPinRadio; -static HWND SourceOutputPinRadio; -static HWND NameTextbox; +static HWID NegatedCheckbox; +static HWID SourceInternalRelayRadio; +static HWID SourceInputPinRadio; +static HWID SourceOutputPinRadio; +static HWID NameTextbox; +static HWID OkButton; +static HWID CancelButton; static LONG_PTR PrevNameProc; - +HWID ContactsGrid; +HWID ContactsPackingBox; +char* tmpname; +BOOL* tmpnegated; //----------------------------------------------------------------------------- // Don't allow any characters other than A-Za-z0-9_ in the name. //----------------------------------------------------------------------------- @@ -54,124 +59,142 @@ static LONG_PTR PrevNameProc; // return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); // } -// static void MakeControls(void) -// { -// HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Source"), -// WS_CHILD | BS_GROUPBOX | WS_VISIBLE, -// 7, 3, 120, 85, ContactsDialog, NULL, Instance, NULL); -// NiceFont(grouper); - -// SourceInternalRelayRadio = CreateWindowEx(0, WC_BUTTON, _("Internal Relay"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 21, 100, 20, ContactsDialog, NULL, Instance, NULL); -// NiceFont(SourceInternalRelayRadio); - -// SourceInputPinRadio = CreateWindowEx(0, WC_BUTTON, _("Input pin"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 41, 100, 20, ContactsDialog, NULL, Instance, NULL); -// NiceFont(SourceInputPinRadio); - -// SourceOutputPinRadio = CreateWindowEx(0, WC_BUTTON, _("Output pin"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 61, 100, 20, ContactsDialog, NULL, Instance, NULL); -// NiceFont(SourceOutputPinRadio); - -// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 135, 16, 50, 21, ContactsDialog, NULL, Instance, NULL); -// NiceFont(textLabel); - -// NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 190, 16, 115, 21, ContactsDialog, NULL, Instance, NULL); -// FixedFont(NameTextbox); - -// NegatedCheckbox = CreateWindowEx(0, WC_BUTTON, _("|/| Negated"), -// WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP | WS_VISIBLE, -// 146, 44, 160, 20, ContactsDialog, NULL, Instance, NULL); -// NiceFont(NegatedCheckbox); - -// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, -// 321, 10, 70, 23, ContactsDialog, NULL, Instance, NULL); -// NiceFont(OkButton); - -// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 321, 40, 70, 23, ContactsDialog, NULL, Instance, NULL); -// NiceFont(CancelButton); +void ContactsDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, + gint *position, gpointer data){ + // gtk_widget_set_sensitive (MainWindow, TRUE); + for (int i = 0; i < length; i++){ + if (!(isalpha (NewText[i]) || NewText[i] == '_' || isdigit (NewText[i]) + || NewText[i] == '\b' )){ + g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); + return; + } + } +} + +static void MakeControls(void) +{ + SourceInternalRelayRadio = gtk_radio_button_new_with_label (NULL, "Internal Relay"); + + SourceInputPinRadio = gtk_radio_button_new_with_label_from_widget + (GTK_RADIO_BUTTON (SourceInternalRelayRadio), "Input pin"); + + SourceOutputPinRadio = gtk_radio_button_new_with_label_from_widget + (GTK_RADIO_BUTTON (SourceInternalRelayRadio), "Output pin"); + + HWID textLabel = gtk_label_new ("Name:"); + + NameTextbox = gtk_entry_new(); + gtk_entry_set_max_length (GTK_ENTRY (NameTextbox), 0); + + NegatedCheckbox = gtk_check_button_new_with_label ("|/| Negated"); + + OkButton = gtk_button_new_with_label ("OK"); + CancelButton = gtk_button_new_with_label ("Cancel"); + + gtk_grid_attach (GTK_GRID (ContactsGrid), SourceInternalRelayRadio, 1, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ContactsGrid), SourceInputPinRadio, 1, 3, 1, 1); + gtk_grid_attach (GTK_GRID (ContactsGrid), SourceOutputPinRadio, 1, 4, 1, 1); + gtk_grid_attach (GTK_GRID (ContactsGrid), textLabel, 2, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ContactsGrid), NegatedCheckbox, 2, 3, 1, 1); + gtk_grid_attach (GTK_GRID (ContactsGrid), NameTextbox, 3, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ContactsGrid), OkButton, 4, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ContactsGrid), CancelButton, 4, 3, 1, 1); + + gtk_grid_set_column_spacing (GTK_GRID (ContactsGrid), 1); + gtk_box_pack_start(GTK_BOX(ContactsPackingBox), ContactsGrid, TRUE, TRUE, 0); // PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, // (LONG_PTR)MyNameProc); -// } - -// void ShowContactsDialog(BOOL *negated, char *name) -// { -// ContactsDialog = CreateWindowClient(0, "LDmicroDialog", -// _("Contacts"), WS_OVERLAPPED | WS_SYSMENU, -// 100, 100, 404, 95, NULL, NULL, Instance, NULL); - -// MakeControls(); +} + +void ContactsDialogGetData (BOOL* negated, char* name){ + if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (NegatedCheckbox))) { + *negated = TRUE; + } + else { + *negated = FALSE; + } + if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (SourceInternalRelayRadio))) { + name[0] = 'R'; + } + else if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (SourceInputPinRadio))) { + name[0] = 'X'; + } + else { + name[0] = 'Y'; + } + strcpy (name+1, gtk_entry_get_text (GTK_ENTRY (NameTextbox))); + + DestroyWindow (ContactsDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); +} + +// Mouse click callback +void ContactsDialogMouseClick(HWID widget, gpointer data){ + ContactsDialogGetData(tmpnegated, tmpname); +} + +// Checks for the required key press +gboolean ContactsDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){ + if (event -> keyval == GDK_KEY_Return){ + ContactsDialogGetData(tmpnegated, tmpname); + } + else if (event -> keyval == GDK_KEY_Escape){ + DestroyWindow (ContactsDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + } + return FALSE; +} + +void ContactsCallDestroyWindow (HWID widget, gpointer data){ + DestroyWindow (ContactsDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); +} + +void ShowContactsDialog(BOOL *negated, char *name) +{ + ContactsGrid = gtk_grid_new(); + ContactsPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + ContactsDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(ContactsDialog), "Contacts"); + gtk_window_set_default_size(GTK_WINDOW(ContactsDialog), 100, 50); + gtk_window_set_resizable (GTK_WINDOW (ContactsDialog), FALSE); + gtk_container_add(GTK_CONTAINER(ContactsDialog), ContactsPackingBox); + gtk_widget_add_events (ContactsDialog, GDK_KEY_PRESS_MASK); + gtk_widget_add_events (ContactsDialog, GDK_BUTTON_PRESS_MASK); + + MakeControls(); -// if(name[0] == 'R') { -// SendMessage(SourceInternalRelayRadio, BM_SETCHECK, BST_CHECKED, 0); -// } else if(name[0] == 'Y') { -// SendMessage(SourceOutputPinRadio, BM_SETCHECK, BST_CHECKED, 0); -// } else { -// SendMessage(SourceInputPinRadio, BM_SETCHECK, BST_CHECKED, 0); -// } -// if(*negated) { -// SendMessage(NegatedCheckbox, BM_SETCHECK, BST_CHECKED, 0); -// } -// SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); - -// EnableWindow(MainWindow, FALSE); -// ShowWindow(ContactsDialog, TRUE); -// SetFocus(NameTextbox); -// SendMessage(NameTextbox, EM_SETSEL, 0, -1); - -// 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(ContactsDialog, &msg)) continue; -// TranslateMessage(&msg); -// DispatchMessage(&msg); -// } - -// if(!DialogCancel) { -// if(SendMessage(NegatedCheckbox, BM_GETSTATE, 0, 0) & BST_CHECKED) { -// *negated = TRUE; -// } else { -// *negated = FALSE; -// } -// if(SendMessage(SourceInternalRelayRadio, BM_GETSTATE, 0, 0) -// & BST_CHECKED) -// { -// name[0] = 'R'; -// } else if(SendMessage(SourceInputPinRadio, BM_GETSTATE, 0, 0) -// & BST_CHECKED) -// { -// name[0] = 'X'; -// } else { -// name[0] = 'Y'; -// } -// SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); -// } - -// EnableWindow(MainWindow, TRUE); -// DestroyWindow(ContactsDialog); -// return; -// } + if(name[0] == 'R') { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (SourceInternalRelayRadio), TRUE); + } + else if(name[0] == 'Y') { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (SourceOutputPinRadio), TRUE); + } + else { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (SourceInputPinRadio), TRUE); + } + if(*negated) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (NegatedCheckbox), TRUE); + } + gtk_entry_set_text (GTK_ENTRY (NameTextbox), name + 1); + + gtk_widget_set_sensitive (MainWindow, FALSE); + gtk_widget_show_all (ContactsDialog); + gtk_widget_grab_focus (NameTextbox); + tmpname = name; + tmpnegated = negated; + + g_signal_connect (G_OBJECT(NameTextbox), "insert-text", + G_CALLBACK(ContactsDialogMyNameProc), NULL); + g_signal_connect (G_OBJECT (ContactsDialog), "key-press-event", + G_CALLBACK(ContactsDialogKeyPress), NULL); + g_signal_connect (G_OBJECT (OkButton), "clicked", + G_CALLBACK(ContactsDialogMouseClick), NULL); + g_signal_connect (G_OBJECT (CancelButton), "clicked", + G_CALLBACK(ContactsCallDestroyWindow), NULL); + +} diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h index 800f2f0..8bf490f 100644 --- a/ldmicro/includes/ldmicro.h +++ b/ldmicro/includes/ldmicro.h @@ -792,8 +792,8 @@ void CompileSuccessfulMessage(char *str); extern BOOL RunningInBatchMode; extern HFONT MyNiceFont; extern HFONT MyFixedFont; -// extern HWND OkButton; -// extern HWND CancelButton; +// extern HWID OkButton; +// extern HWID CancelButton; // extern BOOL DialogDone; // extern BOOL DialogCancel; diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index ba5eb95..d7248b7 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -498,6 +498,7 @@ BOOL GetWindowRect(HWID hWid, PRECT pRect) return TRUE; } + UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, BOOL (*lpTimerFunc)(BOOL) ) { auto record_it = std::find_if(timerRecords.begin(), timerRecords.end(), [&nIDEvent](TimerRecord &Record) { return Record.ufID == nIDEvent; }); @@ -531,4 +532,4 @@ BOOL KillTimer(HWID hWid, UINT uIDEvent) void DestroyWindow (HWID widget) { gtk_widget_destroy (widget); -}
\ No newline at end of file +} diff --git a/ldmicro/lutdialog.cpp b/ldmicro/lutdialog.cpp index fde3156..188b1a8 100644 --- a/ldmicro/lutdialog.cpp +++ b/ldmicro/lutdialog.cpp @@ -26,95 +26,93 @@ #include "linuxUI.h" #include <stdio.h> #include <stdlib.h> +#include <iostream> //#include <commctrl.h> #include "ldmicro.h" -// static HWND LutDialog; +using namespace std; -// static HWND AsStringCheckbox; -// static HWND CountTextbox; -// static HWND DestTextbox; -// static HWND IndexTextbox; -// static HWND Labels[3]; +static HWID LutDialog; -// static HWND StringTextbox; +static HWID AsStringCheckbox; +static HWID CountTextbox; +static HWID DestTextbox; +static HWID IndexTextbox; +static HWID Labels[3]; + +static HWID StringTextbox; +static bool checkString; static BOOL WasAsString; static int WasCount; -//static HWND ValuesTextbox[MAX_LOOK_UP_TABLE_LEN]; +static HWID ValuesTextbox[MAX_LOOK_UP_TABLE_LEN]; static LONG_PTR PrevValuesProc[MAX_LOOK_UP_TABLE_LEN]; -//static HWND ValuesLabel[MAX_LOOK_UP_TABLE_LEN]; +static HWID ValuesLabel[MAX_LOOK_UP_TABLE_LEN]; static SWORD ValuesCache[MAX_LOOK_UP_TABLE_LEN]; static LONG_PTR PrevDestProc; static LONG_PTR PrevIndexProc; static LONG_PTR PrevCountProc; +static HWID OkButton; +static HWID CancelButton; + +HWID LutGrid; +HWID LutPackingBox; + +struct ShowLookUpTableDialogBuffer{ + int tmpcount; + bool tmpasString; + char PrevTableAsString[1024] = ""; +} temp; //----------------------------------------------------------------------------- // Don't allow any characters other than 0-9 and minus in the values. //----------------------------------------------------------------------------- -// static LRESULT CALLBACK MyNumberProc(HWND hwnd, UINT msg, WPARAM wParam, -// LPARAM lParam) -// { -// if(msg == WM_CHAR) { -// if(!(isdigit(wParam) || wParam == '\b' || wParam == '-')) { -// return 0; -// } -// } - -// WNDPROC w; -// int i; -// for(i = 0; i < MAX_LOOK_UP_TABLE_LEN; i++) { -// if(hwnd == ValuesTextbox[i]) { -// w = (WNDPROC)PrevValuesProc[i]; -// break; -// } -// } -// if(i == MAX_LOOK_UP_TABLE_LEN) oops(); -// return CallWindowProc(w, hwnd, msg, wParam, lParam); -// } +void LutDialogMyNumberProc (GtkEditable *editable, gchar *NewText, gint length, + gint *position, gpointer data){ + // gtk_widget_set_sensitive (MainWindow, TRUE); + for (int i = 0; i < length; i++){ + if (!(isdigit (NewText[i]) || NewText[i] == '\b' || NewText[i] == '-')){ + g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); + return; + } + } +} //----------------------------------------------------------------------------- // Don't allow any characters other than 0-9 in the count. //----------------------------------------------------------------------------- -// static LRESULT CALLBACK MyDigitsProc(HWND hwnd, UINT msg, WPARAM wParam, -// LPARAM lParam) -// { -// if(msg == WM_CHAR) { -// if(!(isdigit(wParam) || wParam == '\b')) { -// return 0; -// } -// } -// return CallWindowProc((WNDPROC)PrevCountProc, hwnd, msg, wParam, lParam); -// } +void LutDialogMyDigitsProc (GtkEditable *editable, gchar *NewText, gint length, + gint *position, gpointer data){ + // gtk_widget_set_sensitive (MainWindow, TRUE); + for (int i = 0; i < length; i++){ + if (!(isdigit (NewText[i]) || NewText[i] == '\b' )){ + g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); + return; + } + } +} //----------------------------------------------------------------------------- // Don't allow any characters other than A-Za-z0-9_ in the name. //----------------------------------------------------------------------------- -// static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, -// LPARAM lParam) -// { -// if(msg == WM_CHAR) { -// if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || -// wParam == '\b')) -// { -// return 0; -// } -// } -// WNDPROC w; -// if(hwnd == DestTextbox) { -// w = (WNDPROC)PrevDestProc; -// } else if(hwnd == IndexTextbox) { -// w = (WNDPROC)PrevIndexProc; -// } -// return CallWindowProc(w, hwnd, msg, wParam, lParam); -// } +void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, + gint *position, gpointer data){ + // gtk_widget_set_sensitive (MainWindow, TRUE); + for (int i = 0; i < length; i++){ + if (!(isalpha (NewText[i]) || NewText[i] == '_' || isdigit (NewText[i]) + || NewText[i] == '\b' )){ + g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); + return; + } + } +} //----------------------------------------------------------------------------- // Make the controls that are guaranteed not to move around as the count/ @@ -122,92 +120,87 @@ static LONG_PTR PrevCountProc; // because in that case we should not provide a checkbox to change whether // the table is edited as a string or table. //----------------------------------------------------------------------------- -// static void MakeFixedControls(BOOL forPwl) -// { -// Labels[0] = CreateWindowEx(0, WC_STATIC, _("Destination:"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 0, 10, 78, 21, LutDialog, NULL, Instance, NULL); -// NiceFont(Labels[0]); - -// DestTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 85, 10, 120, 21, LutDialog, NULL, Instance, NULL); -// FixedFont(DestTextbox); - -// Labels[1] = CreateWindowEx(0, WC_STATIC, _("Index:"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 10, 40, 68, 21, LutDialog, NULL, Instance, NULL); -// NiceFont(Labels[1]); - -// IndexTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 85, 40, 120, 21, LutDialog, NULL, Instance, NULL); -// FixedFont(IndexTextbox); - -// Labels[2] = CreateWindowEx(0,WC_STATIC, forPwl ? _("Points:") : _("Count:"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 0, 70, 78, 21, LutDialog, NULL, Instance, NULL); -// NiceFont(Labels[2]); - -// CountTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 85, 70, 120, 21, LutDialog, NULL, Instance, NULL); -// NiceFont(CountTextbox); - -// if(!forPwl) { -// AsStringCheckbox = CreateWindowEx(0, WC_BUTTON, -// _("Edit table of ASCII values like a string"), WS_CHILD | -// WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_AUTOCHECKBOX, -// 10, 100, 300, 21, LutDialog, NULL, Instance, NULL); -// NiceFont(AsStringCheckbox); -// } - -// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, -// 231, 10, 70, 23, LutDialog, NULL, Instance, NULL); -// NiceFont(OkButton); - -// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 231, 40, 70, 23, LutDialog, NULL, Instance, NULL); -// NiceFont(CancelButton); - -// PrevDestProc = SetWindowLongPtr(DestTextbox, GWLP_WNDPROC, -// (LONG_PTR)MyNameProc); -// PrevIndexProc = SetWindowLongPtr(IndexTextbox, GWLP_WNDPROC, -// (LONG_PTR)MyNameProc); -// PrevCountProc = SetWindowLongPtr(CountTextbox, GWLP_WNDPROC, -// (LONG_PTR)MyDigitsProc); -// } +static void MakeFixedControls(BOOL forPwl) +{ + // cout << "Inside MakeFixedControls ()" << "\n"; + Labels[0] = gtk_label_new ("Destination"); + Labels[1] = gtk_label_new ("Index:"); + Labels[2] = forPwl ? gtk_label_new ("Points:") : gtk_label_new ("Count:"); + + DestTextbox = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (DestTextbox), 0); + IndexTextbox = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (IndexTextbox), 0); + CountTextbox = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (CountTextbox), 0); + + // cout << "Created Labels, Dest, Index and Count text boxes" << "\n"; + + if(!forPwl) { + AsStringCheckbox = gtk_check_button_new_with_label + ("Edit table of ASCII values like a string"); + // cout << "Created CheckButton" << "\n"; + } + + + OkButton = gtk_button_new_with_label ("OK"); + CancelButton = gtk_button_new_with_label ("Cancel"); + + gtk_grid_attach (GTK_GRID (LutGrid), Labels[0], 0, 2, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), DestTextbox, 1, 2, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), OkButton, 3, 2, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), Labels[1], 0, 4, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), IndexTextbox, 1, 4, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), CancelButton, 3, 4, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), Labels[2], 0, 6, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), CountTextbox, 1, 6, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), AsStringCheckbox, 0, 8, 1, 1); + + g_signal_connect (G_OBJECT(DestTextbox), "insert-text", + G_CALLBACK(LutDialogMyNameProc), NULL); + g_signal_connect (G_OBJECT(IndexTextbox), "insert-text", + G_CALLBACK(LutDialogMyNameProc), NULL); + g_signal_connect (G_OBJECT(CountTextbox), "insert-text", + G_CALLBACK(LutDialogMyDigitsProc), NULL); +} //----------------------------------------------------------------------------- // Destroy all of the controls so that we can start anew. This is necessary // because if the size of the LUT changes, or if the user switches from // table entry to string entry, we must completely reconfigure the dialog. //----------------------------------------------------------------------------- -// static void DestroyLutControls(void) -// { -// if(WasAsString) { -// // Nothing to do; we constantly update the cache from the user- -// // specified string, because we might as well do that when we -// // calculate the length. -// } else { -// int i; -// for(i = 0; i < WasCount; i++) { -// char buf[20]; -// SendMessage(ValuesTextbox[i], WM_GETTEXT, (WPARAM)16, (LPARAM)buf); -// ValuesCache[i] = atoi(buf); -// } -// } - -// DestroyWindow(StringTextbox); - -// int i; -// for(i = 0; i < MAX_LOOK_UP_TABLE_LEN; i++) { -// DestroyWindow(ValuesTextbox[i]); -// DestroyWindow(ValuesLabel[i]); -// } -// } +static void DestroyLutControls(void) +{ + cout << "Inside DestroyLutControls ()" << "\n"; + if(WasAsString) { + // Nothing to do; we constantly update the cache from the user- + // specified string, because we might as well do that when we + // calculate the length. + } + else { + cout << "In DestroyLut WasCount : " << WasCount << "\n"; + int i; + for(i = 0; i < WasCount; i++) { + char buf[20]; + // SendMessage(ValuesTextbox[i], WM_GETTEXT, (WPARAM)16, (LPARAM)buf); + strcpy (buf, gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i]))); + ValuesCache[i] = atoi(buf); + } + cout << "Exiting else of WasAsString" << "\n"; + } + if (checkString){ + DestroyWindow(StringTextbox); + cout << "Destroyed StringTextbox" << "\n"; + } + int i; + // *** Changed from MAX_LOOK_UP_TABLE_LEN to count ***** // + for(i = 0; i < temp.tmpcount; i++) { + cout << "Destroy ValueTextbox i = " << i << "\n"; + DestroyWindow(ValuesTextbox[i]); + DestroyWindow(ValuesLabel[i]); + cout << "Called DestroyWindow() for ValuesTextbox and ValuesLabels" << "\n"; + } +} //----------------------------------------------------------------------------- // Make the controls that hold the LUT. The exact configuration of the dialog @@ -215,96 +208,109 @@ static LONG_PTR PrevCountProc; // and for table-type entry, on (b) the number of entries, and on (c) // whether we are editing a PWL table (list of points) or a straight LUT. //----------------------------------------------------------------------------- -// static void MakeLutControls(BOOL asString, int count, BOOL forPwl) -// { -// // Remember these, so that we know from where to cache stuff if we have -// // to destroy these textboxes and make something new later. -// WasAsString = asString; -// WasCount = count; - -// if(forPwl && asString) oops(); - -// if(asString) { -// char str[3*MAX_LOOK_UP_TABLE_LEN+1]; -// int i, j; -// j = 0; -// for(i = 0; i < count; i++) { -// int c = ValuesCache[i]; -// if(c >= 32 && c <= 127 && c != '\\') { -// str[j++] = c; -// } else if(c == '\\') { -// str[j++] = '\\'; -// str[j++] = '\\'; -// } else if(c == '\r') { -// str[j++] = '\\'; -// str[j++] = 'r'; -// } else if(c == '\b') { -// str[j++] = '\\'; -// str[j++] = 'b'; -// } else if(c == '\f') { -// str[j++] = '\\'; -// str[j++] = 'f'; -// } else if(c == '\n') { -// str[j++] = '\\'; -// str[j++] = 'n'; -// } else { -// str[j++] = 'X'; -// } -// } -// str[j++] = '\0'; -// StringTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, str, -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | -// WS_VISIBLE, -// 10, 130, 294, 21, LutDialog, NULL, Instance, NULL); -// FixedFont(StringTextbox); -// SendMessage(CountTextbox, EM_SETREADONLY, (WPARAM)TRUE, 0); -// MoveWindow(LutDialog, 100, 30, 320, 185, TRUE); -// } else { -// int i; -// int base; -// if(forPwl) { -// base = 100; -// } else { -// base = 140; -// } -// for(i = 0; i < count; i++) { -// int x, y; - -// if(i < 16) { -// x = 10; -// y = base+30*i; -// } else { -// x = 160; -// y = base+30*(i-16); -// } - -// char buf[20]; -// sprintf(buf, "%d", ValuesCache[i]); -// ValuesTextbox[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, buf, -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | -// WS_VISIBLE, -// x+30, y, 80, 21, LutDialog, NULL, Instance, NULL); -// NiceFont(ValuesTextbox[i]); - -// if(forPwl) { -// sprintf(buf, "%c%d:", (i & 1) ? 'y' : 'x', i/2); -// } else { -// sprintf(buf, "%2d:", i); -// } -// ValuesLabel[i] = CreateWindowEx(0, WC_STATIC, buf, -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, -// x, y+3, 100, 21, LutDialog, NULL, Instance, NULL); -// FixedFont(ValuesLabel[i]); - -// PrevValuesProc[i] = SetWindowLongPtr(ValuesTextbox[i], -// GWLP_WNDPROC, (LONG_PTR)MyNumberProc); -// } -// if(count > 16) count = 16; -// SendMessage(CountTextbox, EM_SETREADONLY, (WPARAM)FALSE, 0); - -// MoveWindow(LutDialog, 100, 30, 320, base + 30 + count*30, TRUE); -// } -// } +static void MakeLutControls(BOOL asString, int count, BOOL forPwl) +{ + // Remember these, so that we know from where to cache stuff if we have + // to destroy these textboxes and make something new later. + WasAsString = asString; + cout << "asString in MakeLutControls : " << asString <<"\n"; + WasCount = count; + cout << "Count in MakeLutControls : " << count << "\n"; + if(forPwl && asString) oops(); + + if(asString) { + char str[3*MAX_LOOK_UP_TABLE_LEN+1]; + cout << "Inside if (asString) in MakeLutControls" << "\n"; + int i, j; + j = 0; + for(i = 0; i < count; i++) { + int c = ValuesCache[i]; + if(c >= 32 && c <= 127 && c != '\\') { + str[j++] = c; + } else if(c == '\\') { + str[j++] = '\\'; + str[j++] = '\\'; + } else if(c == '\r') { + str[j++] = '\\'; + str[j++] = 'r'; + } else if(c == '\b') { + str[j++] = '\\'; + str[j++] = 'b'; + } else if(c == '\f') { + str[j++] = '\\'; + str[j++] = 'f'; + } else if(c == '\n') { + str[j++] = '\\'; + str[j++] = 'n'; + } else { + str[j++] = 'X'; + } + } + str[j++] = '\0'; + StringTextbox = gtk_entry_new (); + gtk_grid_attach (GTK_GRID (LutGrid), StringTextbox, 1, 9, 1, 1); + checkString = TRUE; + gtk_widget_show_all (LutGrid); + gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), FALSE); + // MoveWindow(StringTextbox, 100, 30, 320, 185, TRUE); // Changed LutDialog to StringTextbox + } + else { + int i; + int base; + if(forPwl) { + base = 100; + } + else { + base = 140; + } + for(i = 0; i < count; i++) { + int x, y; + + if(i < 16) { + x = 10; + y = base+30*i; + } + else { + x = 160; + y = base+30*(i-16); + } + + char buf[20]; + sprintf(buf, "%d", ValuesCache[i]); + ValuesTextbox[i] = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (ValuesTextbox[i]), 0); + // cout << "Made ValuesTextbox" << "\n"; + + if(forPwl) { + sprintf(buf, "%c%d:", (i & 1) ? 'y' : 'x', i/2); + } + else { + sprintf(buf, "%2d:", i); + } + + ValuesLabel[i] = gtk_label_new (buf); + if (i<10){ + gtk_grid_attach (GTK_GRID (LutGrid), ValuesLabel[i], 0, i+12, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), ValuesTextbox[i], 1, i+12, 1, 1); + } + else if ((i>=10) && (i<20)){ + gtk_grid_attach (GTK_GRID (LutGrid), ValuesLabel[i], 2, i+2, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), ValuesTextbox[i], 3, i+2, 1, 1); + } + else if ((i>=20) && (i<30)){ + gtk_grid_attach (GTK_GRID (LutGrid), ValuesLabel[i], 4, i-8, 1, 1); + gtk_grid_attach (GTK_GRID (LutGrid), ValuesTextbox[i], 5, i-8, 1, 1); + } + gtk_widget_show_all (LutDialog); + g_signal_connect (G_OBJECT(ValuesTextbox[i]), "insert-text", + G_CALLBACK(LutDialogMyNumberProc), NULL); + } + if(count > 16) count = 16; + gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), TRUE); + + // MoveWindow(LutDialog, 100, 30, 320, base + 30 + count*30, TRUE); + } +} //----------------------------------------------------------------------------- // Decode a string into a look-up table; store the values in ValuesCache[], @@ -312,36 +318,136 @@ static LONG_PTR PrevCountProc; // reflect the new length. Returns FALSE if the new string is too long, else // TRUE. //----------------------------------------------------------------------------- -// BOOL StringToValuesCache(char *str, int *c) -// { -// int count = 0; -// while(*str) { -// if(*str == '\\') { -// str++; -// switch(*str) { -// case 'r': ValuesCache[count++] = '\r'; break; -// case 'n': ValuesCache[count++] = '\n'; break; -// case 'f': ValuesCache[count++] = '\f'; break; -// case 'b': ValuesCache[count++] = '\b'; break; -// default: ValuesCache[count++] = *str; break; -// } -// } else { -// ValuesCache[count++] = *str; -// } -// if(*str) { -// str++; -// } -// if(count >= 32) { -// return FALSE; -// } -// } - -// char buf[10]; -// sprintf(buf, "%d", count); -// SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)(buf)); -// *c = count; -// return TRUE; -// } +BOOL StringToValuesCache(char *str, int *c) +{ + // cout << "Inside StringToValuesCache" << "\n"; + int count = 0; + while(*str) { + if(*str == '\\') { + str++; + switch(*str) { + case 'r': ValuesCache[count++] = '\r'; break; + case 'n': ValuesCache[count++] = '\n'; break; + case 'f': ValuesCache[count++] = '\f'; break; + case 'b': ValuesCache[count++] = '\b'; break; + default: ValuesCache[count++] = *str; break; + } + } else { + ValuesCache[count++] = *str; + } + if(*str) { + str++; + } + if(count >= 32) { + return FALSE; + } + } + + char buf[10]; + sprintf(buf, "%d", count); + gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf); + *c = count; + return TRUE; +} + +void LookUpTableGetData (HWID widget, gpointer data){ + ElemLeaf *l = (ElemLeaf *) data; + ElemLookUpTable *t = &(l->d.lookUpTable); + strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox))); + // t->index = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY (IndexTextbox))); + strcpy (t->index, gtk_entry_get_text (GTK_ENTRY (IndexTextbox))); + // DestroyLutControls(); + + // The call to DestroyLutControls updated ValuesCache, so just read + // them out of there (whichever mode we were in before). + int i; + for(i = 0; i < temp.tmpcount; i++) { + t->vals[i] = ValuesCache[i]; + } + t->count = temp.tmpcount; + t->editAsString = temp.tmpasString; + gtk_widget_set_sensitive (MainWindow, TRUE); +} + +void LookUpTableCheckMode (void){ + int count = temp.tmpcount; + bool asString = temp.tmpasString; + + // Are we in table mode? In that case watch the (user-editable) count + // field, and use that to determine how many textboxes to show. + char buf[20]; + // buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY (CountTextbox))); + strcpy (buf, gtk_entry_get_text (GTK_ENTRY (CountTextbox))); + if(atoi(buf) != count && !asString) { + count = atoi(buf); + if(count < 0 || count > 32) { + count = 0; + gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); + } + cout << "Count in LookUpTableCheckMode : " << count << "\n"; + DestroyLutControls(); + MakeLutControls(asString, count, FALSE); + } + + // Are we in string mode? In that case watch the string textbox, + // and use that to update the (read-only) count field. + if(asString) { + char scratch[1024]; + // scratch = const_cast <char*> (gtk_entry_get_text + // (GTK_ENTRY (StringTextbox))); + strcpy (scratch, gtk_entry_get_text (GTK_ENTRY (StringTextbox))); + if(strcmp(scratch, temp.PrevTableAsString)!=0) { + if(StringToValuesCache(scratch, &count)) { + strcpy(temp.PrevTableAsString, scratch); + } + else { + // Too long; put back the old one + gtk_entry_set_text (GTK_ENTRY (StringTextbox), + temp.PrevTableAsString); + } + } + } + // Did we just change modes? + BOOL x = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (AsStringCheckbox)); + if((x && !asString) || (!x && asString)) { + cout << "x is " << x << "\n"; + asString = x; + if (x == 1){ + MakeLutControls(asString, count, FALSE); + } + else { + DestroyLutControls(); + } + } + + temp.tmpcount = count; + temp.tmpasString = asString; +} + +// Checks for the required key press +gboolean LookUpTableKeyPress (HWID widget, GdkEventKey* event, gpointer data){ + LookUpTableCheckMode (); + if (event -> keyval == GDK_KEY_Return){ + LookUpTableGetData(NULL, (gpointer) data); + } + else if (event -> keyval == GDK_KEY_Escape){ + DestroyWindow (LutDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + } + return FALSE; +} + +// Mouse click callback +void LutDialogMouseClick (HWID widget, gpointer data){ + LookUpTableCheckMode (); + LookUpTableGetData(NULL, (gpointer) data); +} + +// Calls DestroyWindow +void LutCallDestroyWindow (HWID widget, gpointer data){ + DestroyWindow (LutDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); +} //----------------------------------------------------------------------------- // Show the look-up table dialog. This one is nasty, mostly because there are @@ -349,132 +455,79 @@ static LONG_PTR PrevCountProc; // I should convert between those two representations on the fly, as the user // edit things, so I do. //----------------------------------------------------------------------------- -// void ShowLookUpTableDialog(ElemLeaf *l) -// { -// ElemLookUpTable *t = &(l->d.lookUpTable); - -// // First copy over all the stuff from the leaf structure; in particular, -// // we need our own local copy of the table entries, because it would be -// // bad to update those in the leaf before the user clicks okay (as he -// // might cancel). -// int count = t->count; -// BOOL asString = t->editAsString; -// memset(ValuesCache, 0, sizeof(ValuesCache)); -// int i; -// for(i = 0; i < count; i++) { -// ValuesCache[i] = t->vals[i]; -// } - -// // Now create the dialog's fixed controls, plus the changing (depending -// // on show style/entry count) controls for the initial configuration. -// LutDialog = CreateWindowClient(0, "LDmicroDialog", -// _("Look-Up Table"), WS_OVERLAPPED | WS_SYSMENU, -// 100, 100, 320, 375, NULL, NULL, Instance, NULL); -// MakeFixedControls(FALSE); -// MakeLutControls(asString, count, FALSE); +void ShowLookUpTableDialog(ElemLeaf *l) +{ + ElemLookUpTable *t = &(l->d.lookUpTable); + GdkEventKey* event; + + // First copy over all the stuff from the leaf structure; in particular, + // we need our own local copy of the table entries, because it would be + // bad to update those in the leaf before the user clicks okay (as he + // might cancel). + + int count = t->count; + cout << "Initially count is " << count << "\n"; + BOOL asString = t->editAsString; + cout << "Initially asString is " << asString << "\n"; + memset(ValuesCache, 0, sizeof(ValuesCache)); + int i; + for(i = 0; i < count; i++) { + ValuesCache[i] = t->vals[i]; + } + + // Now create the dialog's fixed controls, plus the changing (depending + // on show style/entry count) controls for the initial configuration. + + LutGrid = gtk_grid_new(); + // LutGrid[1] = gtk_grid_new(); + // gtk_grid_set_column_spacing (GTK_GRID (LutGrid), 1); + LutPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + LutDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(LutDialog), "Look-Up Table"); + gtk_window_set_default_size(GTK_WINDOW(LutDialog), 100, 200); + gtk_window_set_resizable (GTK_WINDOW (LutDialog), FALSE); + gtk_box_pack_start(GTK_BOX(LutPackingBox), LutGrid, TRUE, TRUE, 0); + gtk_container_add(GTK_CONTAINER(LutDialog), LutPackingBox); + gtk_widget_add_events (LutDialog, GDK_KEY_PRESS_MASK); + gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK); + MakeFixedControls(FALSE); + MakeLutControls(asString, count, FALSE); -// // Set up the controls to reflect the initial configuration. -// SendMessage(DestTextbox, WM_SETTEXT, 0, (LPARAM)(t->dest)); -// SendMessage(IndexTextbox, WM_SETTEXT, 0, (LPARAM)(t->index)); -// char buf[30]; -// sprintf(buf, "%d", t->count); -// SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)buf); -// if(asString) { -// SendMessage(AsStringCheckbox, BM_SETCHECK, BST_CHECKED, 0); -// } - -// // And show the window -// EnableWindow(MainWindow, FALSE); -// ShowWindow(LutDialog, TRUE); -// SetFocus(DestTextbox); -// SendMessage(DestTextbox, EM_SETSEL, 0, -1); - -// char PrevTableAsString[1024] = ""; - -// 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(LutDialog, &msg)) { -// TranslateMessage(&msg); -// DispatchMessage(&msg); -// } - -// // Are we in table mode? In that case watch the (user-editable) count -// // field, and use that to determine how many textboxes to show. -// char buf[20]; -// SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf); -// if(atoi(buf) != count && !asString) { -// count = atoi(buf); -// if(count < 0 || count > 32) { -// count = 0; -// SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)""); -// } -// DestroyLutControls(); -// MakeLutControls(asString, count, FALSE); -// } - -// // Are we in string mode? In that case watch the string textbox, -// // and use that to update the (read-only) count field. -// if(asString) { -// char scratch[1024]; -// SendMessage(StringTextbox, WM_GETTEXT, (WPARAM)sizeof(scratch), -// (LPARAM)scratch); -// if(strcmp(scratch, PrevTableAsString)!=0) { -// if(StringToValuesCache(scratch, &count)) { -// strcpy(PrevTableAsString, scratch); -// } else { -// // Too long; put back the old one -// SendMessage(StringTextbox, WM_SETTEXT, 0, -// (LPARAM)PrevTableAsString); -// } -// } -// } - -// // Did we just change modes? -// BOOL x = SendMessage(AsStringCheckbox, BM_GETCHECK, 0, 0)==BST_CHECKED; -// if((x && !asString) || (!x && asString)) { -// asString = x; -// DestroyLutControls(); -// MakeLutControls(asString, count, FALSE); -// } - -// } - -// if(!DialogCancel) { -// SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest)); -// SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index)); -// DestroyLutControls(); -// // The call to DestroyLutControls updated ValuesCache, so just read -// // them out of there (whichever mode we were in before). -// int i; -// for(i = 0; i < count; i++) { -// t->vals[i] = ValuesCache[i]; -// } -// t->count = count; -// t->editAsString = asString; -// } - -// EnableWindow(MainWindow, TRUE); -// DestroyWindow(LutDialog); -// } + // Set up the controls to reflect the initial configuration. + gtk_entry_set_text (GTK_ENTRY (DestTextbox), t->dest); + gtk_entry_set_text (GTK_ENTRY (IndexTextbox), t->index); + + char buf[30]; + sprintf(buf, "%d", t->count); + gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf); + if(asString) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (AsStringCheckbox), TRUE); + } + + // And show the window + gtk_widget_set_sensitive (MainWindow, FALSE); + gtk_widget_show_all (LutDialog); + gtk_widget_grab_focus(DestTextbox); + gtk_widget_grab_focus(OkButton); + + temp.tmpcount = count; + cout << "Count in ShowLookUp : " << count << "\n"; + temp.tmpasString = asString; + cout << "asString in ShowLookUp : " << asString << "\n"; + + g_signal_connect (G_OBJECT (LutDialog), "key-press-event", + G_CALLBACK(LookUpTableKeyPress), (gpointer)l); + g_signal_connect (G_OBJECT (OkButton), "clicked", + G_CALLBACK(LutDialogMouseClick), (gpointer)l); + g_signal_connect (G_OBJECT (CancelButton), "clicked", + G_CALLBACK(LutCallDestroyWindow), NULL); +} //----------------------------------------------------------------------------- // Show the piecewise linear table dialog. This one can only be edited in // only a single format, which makes things easier than before. -//----------------------------------------------------------------------------- +// //----------------------------------------------------------------------------- // void ShowPiecewiseLinearDialog(ElemLeaf *l) // { // ElemPiecewiseLinear *t = &(l->d.piecewiseLinear); @@ -492,74 +545,78 @@ static LONG_PTR PrevCountProc; // // Now create the dialog's fixed controls, plus the changing (depending // // on show style/entry count) controls for the initial configuration. -// LutDialog = CreateWindowClient(0, "LDmicroDialog", -// _("Piecewise Linear Table"), WS_OVERLAPPED | WS_SYSMENU, -// 100, 100, 320, 375, NULL, NULL, Instance, NULL); + +// LutDialog = gtk_dialog_new_with_buttons ("Piecewise Linear Table", GTK_WINDOW (MainWindow), +// GTK_DIALOG_MODAL, "Ok", GTK_RESPONSE_ACCEPT, +// "Cancel", GTK_RESPONSE_REJECT, NULL); +// gtk_widget_add_events (LutDialog, GDK_KEY_PRESS_MASK); +// gtk_widget_add_events (LutDialog, GDK_BUTTON_PRESS_MASK); // MakeFixedControls(TRUE); // MakeLutControls(FALSE, count*2, TRUE); // // Set up the controls to reflect the initial configuration. -// SendMessage(DestTextbox, WM_SETTEXT, 0, (LPARAM)(t->dest)); -// SendMessage(IndexTextbox, WM_SETTEXT, 0, (LPARAM)(t->index)); +// gtk_entry_set_text (GTK_ENTRY (DestTextbox), t->dest); +// gtk_entry_set_text (GTK_ENTRY (IndexTextbox), t->index); // char buf[30]; // sprintf(buf, "%d", t->count); -// SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)buf); +// gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf); // // And show the window -// EnableWindow(MainWindow, FALSE); -// ShowWindow(LutDialog, TRUE); -// SetFocus(DestTextbox); -// SendMessage(DestTextbox, EM_SETSEL, 0, -1); - -// 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(LutDialog, &msg)) { -// TranslateMessage(&msg); -// DispatchMessage(&msg); -// } +// gtk_widget_set_sensitive (MainWindow, FALSE); +// gtk_widget_show_all (LutDialog); +// gtk_widget_grab_focus (DestTextbox); +// // SendMessage(DestTextbox, EM_SETSEL, 0, -1); + +// // 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(LutDialog, &msg)) { +// // TranslateMessage(&msg); +// // DispatchMessage(&msg); +// // } // // Watch the (user-editable) count field, and use that to // // determine how many textboxes to show. -// char buf[20]; -// SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf); +// char* buf; +// buf = gtk_entry_get_text (GTK_ENTRY (CountTextbox)); +// // SendMessage(CountTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)buf); // if(atoi(buf) != count) { // count = atoi(buf); // if(count < 0 || count > 10) { // count = 0; -// SendMessage(CountTextbox, WM_SETTEXT, 0, (LPARAM)""); +// gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); // } // DestroyLutControls(); // MakeLutControls(FALSE, count*2, TRUE); // } // } -// if(!DialogCancel) { -// SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest)); -// SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index)); -// DestroyLutControls(); -// // The call to DestroyLutControls updated ValuesCache, so just read -// // them out of there. -// int i; -// for(i = 0; i < count*2; i++) { -// t->vals[i] = ValuesCache[i]; -// } -// t->count = count; -// } - -// EnableWindow(MainWindow, TRUE); -// DestroyWindow(LutDialog); +// // if(!DialogCancel) { +// // SendMessage(DestTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->dest)); +// // SendMessage(IndexTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(t->index)); +// // DestroyLutControls(); +// // // The call to DestroyLutControls updated ValuesCache, so just read +// // // them out of there. +// // int i; +// // for(i = 0; i < count*2; i++) { +// // t->vals[i] = ValuesCache[i]; +// // } +// // t->count = count; +// // } + +// // EnableWindow(MainWindow, TRUE); +// // DestroyWindow(LutDialog); // } diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp index 05704e7..f0f9aa8 100644 --- a/ldmicro/miscutil.cpp +++ b/ldmicro/miscutil.cpp @@ -40,8 +40,8 @@ static int IhexChecksum; // Try to common a bit of stuff between the dialog boxes, since only one // can be open at any time. -HWND OkButton; -HWND CancelButton; +HWID OkButton; +HWID CancelButton; BOOL DialogDone; BOOL DialogCancel; diff --git a/ldmicro/resetdialog.cpp b/ldmicro/resetdialog.cpp index 70a5218..cbcfd30 100644 --- a/ldmicro/resetdialog.cpp +++ b/ldmicro/resetdialog.cpp @@ -24,125 +24,135 @@ #include "linuxUI.h" #include <stdio.h> //#include <commctrl.h> - +#include <iostream> #include "ldmicro.h" -static HWND ResetDialog; +using namespace std; + +static HWID ResetDialog; -static HWND TypeTimerRadio; -static HWND TypeCounterRadio; -static HWND NameTextbox; +static HWID TypeTimerRadio; +static HWID TypeCounterRadio; +static HWID NameTextbox; +static HWID OkButton; +static HWID CancelButton; static LONG_PTR PrevNameProc; +HWID ResetGrid; +HWID ResetPackingBox; //----------------------------------------------------------------------------- // Don't allow any characters other than A-Za-z0-9_ in the name. //----------------------------------------------------------------------------- -// static LRESULT CALLBACK MyNameProc(HWND hwnd, UINT msg, WPARAM wParam, -// LPARAM lParam) -// { -// if(msg == WM_CHAR) { -// if(!(isalpha(wParam) || isdigit(wParam) || wParam == '_' || -// wParam == '\b')) -// { -// return 0; -// } -// } - -// return CallWindowProc((WNDPROC)PrevNameProc, hwnd, msg, wParam, lParam); -// } - -// static void MakeControls(void) -// { -// HWND grouper = CreateWindowEx(0, WC_BUTTON, _("Type"), -// WS_CHILD | BS_GROUPBOX | WS_VISIBLE, -// 7, 3, 120, 65, ResetDialog, NULL, Instance, NULL); -// NiceFont(grouper); - -// TypeTimerRadio = CreateWindowEx(0, WC_BUTTON, _("Timer"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 21, 100, 20, ResetDialog, NULL, Instance, NULL); -// NiceFont(TypeTimerRadio); - -// TypeCounterRadio = CreateWindowEx(0, WC_BUTTON, _("Counter"), -// WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, -// 16, 41, 100, 20, ResetDialog, NULL, Instance, NULL); -// NiceFont(TypeCounterRadio); - -// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Name:"), -// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT, -// 135, 16, 50, 21, ResetDialog, NULL, Instance, NULL); -// NiceFont(textLabel); - -// NameTextbox = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", -// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 190, 16, 115, 21, ResetDialog, NULL, Instance, NULL); -// FixedFont(NameTextbox); - -// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, -// 321, 10, 70, 23, ResetDialog, NULL, Instance, NULL); -// NiceFont(OkButton); - -// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"), -// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, -// 321, 40, 70, 23, ResetDialog, NULL, Instance, NULL); -// NiceFont(CancelButton); - -// PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, -// (LONG_PTR)MyNameProc); -// } - -// void ShowResetDialog(char *name) -// { -// ResetDialog = CreateWindowClient(0, "LDmicroDialog", -// _("Reset"), WS_OVERLAPPED | WS_SYSMENU, -// 100, 100, 404, 75, NULL, NULL, Instance, NULL); - -// MakeControls(); + +void ResetDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, + gint *position, gpointer data){ + // gtk_widget_set_sensitive (MainWindow, TRUE); + for (int i = 0; i < length; i++){ + if (!(isalpha (NewText[i]) || NewText[i] == '_' || isdigit (NewText[i]) + || NewText[i] == '\b' )){ + g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text"); + return; + } + } +} + +static void MakeControls(void) +{ + TypeTimerRadio = gtk_radio_button_new_with_label (NULL, "Timer"); + + TypeCounterRadio = gtk_radio_button_new_with_label_from_widget + (GTK_RADIO_BUTTON (TypeTimerRadio), "Counter"); + + HWID textLabel = gtk_label_new ("Name"); + + NameTextbox = gtk_entry_new(); + gtk_entry_set_max_length (GTK_ENTRY (NameTextbox), 0); + + OkButton = gtk_button_new_with_label ("OK"); + CancelButton = gtk_button_new_with_label ("Cancel"); + + gtk_grid_attach (GTK_GRID (ResetGrid), TypeTimerRadio, 1, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ResetGrid), TypeCounterRadio, 1, 3, 1, 1); + gtk_grid_attach (GTK_GRID (ResetGrid), textLabel, 2, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ResetGrid), NameTextbox, 3, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ResetGrid), OkButton, 4, 2, 1, 1); + gtk_grid_attach (GTK_GRID (ResetGrid), CancelButton, 4, 3, 1, 1); + + gtk_grid_set_column_spacing (GTK_GRID (ResetGrid), 1); + gtk_box_pack_start(GTK_BOX(ResetPackingBox), ResetGrid, TRUE, TRUE, 0); + + // PrevNameProc = SetWindowLongPtr(NameTextbox, GWLP_WNDPROC, + // (LONG_PTR)MyNameProc); +} + +void ResetDialogGetData (char* name){ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (TypeTimerRadio))){ + name[0] = 'T'; + } + else { + name[0] = 'C'; + } + strcpy (name+1, gtk_entry_get_text (GTK_ENTRY (NameTextbox))); + gtk_widget_set_sensitive (MainWindow, TRUE); + DestroyWindow (ResetDialog); +} + +// Mouse click callback +void ResetDialogMouseClick (HWID widget, gpointer data){ + ResetDialogGetData((char*)data); +} + +// Checks for the required key press +gboolean ResetDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){ + if (event -> keyval == GDK_KEY_Return){ + ResetDialogGetData((char*)data); + } + else if (event -> keyval == GDK_KEY_Escape){ + DestroyWindow (ResetDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); + } + return FALSE; +} + +void ResetCallDestroyWindow (HWID widget, gpointer data){ + DestroyWindow (ResetDialog); + gtk_widget_set_sensitive (MainWindow, TRUE); +} + +void ShowResetDialog(char *name) +{ + ResetGrid = gtk_grid_new(); + ResetPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + ResetDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(ResetDialog), "Reset"); + gtk_window_set_default_size(GTK_WINDOW(ResetDialog), 100, 50); + gtk_window_set_resizable (GTK_WINDOW (ResetDialog), FALSE); + gtk_container_add(GTK_CONTAINER(ResetDialog), ResetPackingBox); + gtk_widget_add_events (ResetDialog, GDK_KEY_PRESS_MASK); + gtk_widget_add_events (ResetDialog, GDK_BUTTON_PRESS_MASK); + + MakeControls(); -// if(name[0] == 'T') { -// SendMessage(TypeTimerRadio, BM_SETCHECK, BST_CHECKED, 0); -// } else { -// SendMessage(TypeCounterRadio, BM_SETCHECK, BST_CHECKED, 0); -// } -// SendMessage(NameTextbox, WM_SETTEXT, 0, (LPARAM)(name + 1)); - -// EnableWindow(MainWindow, FALSE); -// ShowWindow(ResetDialog, TRUE); -// SetFocus(NameTextbox); -// SendMessage(NameTextbox, EM_SETSEL, 0, -1); - -// 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(ResetDialog, &msg)) continue; -// TranslateMessage(&msg); -// DispatchMessage(&msg); -// } - -// if(!DialogCancel) { -// if(SendMessage(TypeTimerRadio, BM_GETSTATE, 0, 0) & BST_CHECKED) { -// name[0] = 'T'; -// } else { -// name[0] = 'C'; -// } -// SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1)); -// } - -// EnableWindow(MainWindow, TRUE); -// DestroyWindow(ResetDialog); -// } + if(name[0] == 'T') { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (TypeTimerRadio), TRUE); + } + else { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (TypeCounterRadio), TRUE); + } + gtk_entry_set_text (GTK_ENTRY (NameTextbox), name+1); + + gtk_widget_set_sensitive (MainWindow, FALSE); + gtk_widget_show_all (ResetDialog); + gtk_widget_grab_focus (NameTextbox); + + g_signal_connect (G_OBJECT(NameTextbox), "insert-text", + G_CALLBACK(ResetDialogMyNameProc), NULL); + g_signal_connect (G_OBJECT (ResetDialog), "key-press-event", + G_CALLBACK(ResetDialogKeyPress), (gpointer)name); + g_signal_connect (G_OBJECT (OkButton), "clicked", + G_CALLBACK(ResetDialogMouseClick), (gpointer)name); + g_signal_connect (G_OBJECT (CancelButton), "clicked", + G_CALLBACK(ResetCallDestroyWindow), NULL); +} diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index 5a91934..a53c9c2 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -24,9 +24,12 @@ #include "linuxUI.h" #include <stdio.h> #include <stdlib.h> +#include <iostream> #include "ldmicro.h" +using namespace std; + // Not all options all available e.g. can't delete the only relay coil in // a rung, can't insert two coils in series, etc. Keep track of what is // allowed so we don't corrupt our program. @@ -395,8 +398,12 @@ void MoveCursorKeyboard(int keyCode) // Edit the selected element. Pop up the appropriate modal dialog box to do // this. //----------------------------------------------------------------------------- + void EditSelectedElement(void) { + ShowLookUpTableDialog(Selected); + // ShowContactsDialog(&(Selected->d.contacts.negated),Selected->d.contacts.name); + // if(!Selected || Selected->selectedState == SELECTED_NONE) return; // switch(SelectedWhich) { @@ -526,6 +533,7 @@ void EditElementMouseDoubleclick(int x, int y) // EditSelectedElement(); // } // } + EditSelectedElement(); } //----------------------------------------------------------------------------- |