summaryrefslogtreecommitdiff
path: root/ldmicro/confdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/confdialog.cpp')
-rw-r--r--ldmicro/confdialog.cpp309
1 files changed, 161 insertions, 148 deletions
diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp
index f908893..a70cbef 100644
--- a/ldmicro/confdialog.cpp
+++ b/ldmicro/confdialog.cpp
@@ -25,20 +25,25 @@
#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 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 +70,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);
+ }
+
+ HWID OkButton = gtk_button_new_with_label ("OK");
+ HWID CancelButton = 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, _("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."));
+
+ 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), OkButton, 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), CancelButton, 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;
@@ -182,68 +175,88 @@ static void MakeControls(void)
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);
+ // The window's height will be resized later, to fit the explanation text.
+ MakeControls();
+
+ 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);
+ cout << "Created Window" << "\n";
+
+ gtk_widget_set_sensitive (MainWindow, FALSE);
+ gtk_widget_grab_focus (CycleTextbox);
+ gtk_widget_show_all (ConfDialog);
+
// 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;
-// }
-// }
+ DialogDone = FALSE;
+ DialogCancel = FALSE;
+ // g_signal_connect (G_OBJECT (ConfDialog), "keyboard_press",
+ // G_CALLBACK (KeyPressEnter), NULL);
+ // g_signal_connect (G_OBJECT (ConfDialog), "keyboard_press",
+ // G_CALLBACK (KeyPressEsc), NULL);
+
+ // while (!DialogDone) {
+ // if (KeyPressEnter(ConfDialog, GDK_KEY_PRESS, NULL)){
+ // DialogDone = TRUE;
+ // break;
+ // }
+ // else if (KeyPressEsc(ConfDialog, GDK_KEY_PRESS, NULL)){
+ // DialogDone = TRUE;
+ // DialogCancel = TRUE;
+ // break;
+ // }
+ // }
+ // 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;
-// }
-
-// SendMessage(CrystalTextbox, WM_GETTEXT, (WPARAM)sizeof(buf),
-// (LPARAM)(buf));
-// Prog.mcuClock = (int)(1e6*atof(buf) + 0.5);
-
-// SendMessage(BaudTextbox, WM_GETTEXT, (WPARAM)sizeof(buf),
-// (LPARAM)(buf));
-// Prog.baudRate = atoi(buf);
-// }
-
-// EnableWindow(MainWindow, TRUE);
-// DestroyWindow(ConfDialog);
-// return;
-}
+ if(!DialogCancel) {
+ 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);
+
+ buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY(BaudTextbox)));
+ Prog.baudRate = atoi(buf);
+ }
+
+ 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, TRUE);
+ // gtk_widget_destroy (ConfDialog);
+
+ return;
+} \ No newline at end of file