diff options
-rw-r--r-- | ldmicro/CMakeLists.txt | 6 | ||||
-rw-r--r-- | ldmicro/contactsdialog.cpp | 3 | ||||
-rw-r--r-- | ldmicro/lutdialog.cpp | 706 | ||||
-rw-r--r-- | ldmicro/schematic.cpp | 8 | ||||
-rw-r--r-- | ldmicro/simpledialog.cpp | 338 |
5 files changed, 360 insertions, 701 deletions
diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt index ec4c2d3..b354d8d 100644 --- a/ldmicro/CMakeLists.txt +++ b/ldmicro/CMakeLists.txt @@ -139,12 +139,12 @@ endif() compilecommon.cpp intcode.cpp lang.cpp - miscutil.cpp + miscutil.cpp #add message boxes to Error(), CompileSuccessfulMessage() iolist.cpp #confdialog.cpp - #lutdialog.cpp + lutdialog.cpp resetdialog.cpp - # simpledialog.cpp + simpledialog.cpp coildialog.cpp contactsdialog.cpp commentdialog.cpp diff --git a/ldmicro/contactsdialog.cpp b/ldmicro/contactsdialog.cpp index 01c55fb..32f794a 100644 --- a/ldmicro/contactsdialog.cpp +++ b/ldmicro/contactsdialog.cpp @@ -97,7 +97,8 @@ void ShowContactsDialog(BOOL *negated, char *name) // CoilDialog->setFixedSize(359,115); MakeControls(); NameTextbox->setValidator( - new QRegExpValidator(QRegExp("[a-zA-Z0-9_]+"))); + new QRegExpValidator( + QRegExp("[a-zA-Z0-9_]+"))); if(name[0] == 'R') { SourceInternalRelayRadio->setChecked(TRUE); diff --git a/ldmicro/lutdialog.cpp b/ldmicro/lutdialog.cpp index 04e7684..a4e5987 100644 --- a/ldmicro/lutdialog.cpp +++ b/ldmicro/lutdialog.cpp @@ -33,86 +33,65 @@ using namespace std; -static HWID LutDialog; +static QDialog* LutDialog; -static HWID AsStringCheckbox; -static HWID CountTextbox; -static HWID DestTextbox; -static HWID IndexTextbox; -static HWID Labels[3]; +static QCheckBox* AsStringCheckbox; +static QLineEdit* CountTextbox; +static QLineEdit* DestTextbox; +static QLineEdit* IndexTextbox; +static QLabel* Labels[3]; -static HWID StringTextbox; +static QLineEdit* StringTextbox; static bool checkString; static BOOL WasAsString; +static BOOL asString; +static int ControlCount; static int WasCount; -static HWID ValuesTextbox[MAX_LOOK_UP_TABLE_LEN]; +static QLineEdit* ValuesTextbox[MAX_LOOK_UP_TABLE_LEN]; static LONG_PTR PrevValuesProc[MAX_LOOK_UP_TABLE_LEN]; -static HWID ValuesLabel[MAX_LOOK_UP_TABLE_LEN]; +static QLabel* 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; +static QDialogButtonBox* ButtonBox; static UINT LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; static UINT LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; -HWID LutGrid; -HWID LutPackingBox; +static QGridLayout* LutGrid; +static QGridLayout* LutPackingBox; +static QGridLayout* FixedControlGrid; +static QGridLayout* LutControlGrid; +char PrevTableAsString[1024]; -struct LookUpTableDialogBuffer{ +/*struct LookUpTableDialogBuffer{ int tmpcount; bool tmpasString; char PrevTableAsString[1024] = ""; -} temp; +} temp;*/ static int piecewiseTmpCount; - -//----------------------------------------------------------------------------- -// Don't allow any characters other than 0-9 and minus in the values. -//----------------------------------------------------------------------------- - -void LutDialogMyNumberProc (GtkEditable *editable, gchar *NewText, gint length, - gint *position, gpointer data){ - 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. -//----------------------------------------------------------------------------- - -void LutDialogMyDigitsProc (GtkEditable *editable, gchar *NewText, gint length, - gint *position, gpointer data){ - 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. -//----------------------------------------------------------------------------- - -void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, - gint *position, gpointer data){ - 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; - } - } +void CheckBoxFunction(int state); +void CountFunction(QString text); +void StringFunction(QString text); + + +inline void DestroyWindow (){ + delete Labels[0]; + delete Labels[1]; + delete Labels[2]; + delete DestTextbox; + delete IndexTextbox; + delete CountTextbox; + delete AsStringCheckbox; + delete FixedControlGrid; + delete LutGrid; + delete ButtonBox; + ProgramChanged(); } //----------------------------------------------------------------------------- @@ -124,44 +103,51 @@ void LutDialogMyNameProc (GtkEditable *editable, gchar *NewText, gint length, static void MakeFixedControls(BOOL forPwl) { bool madeCheckbox = FALSE; - 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); + FixedControlGrid = new QGridLayout(); + Labels[0] = new QLabel(_("Destination")); + Labels[1] = new QLabel(_("Index:")); + Labels[2] = new QLabel(forPwl ? _("Points:") : _("Count:")); + + DestTextbox = new QLineEdit(); + // gtk_entry_set_max_length (GTK_ENTRY (DestTextbox), 0); + IndexTextbox = new QLineEdit(); + // gtk_entry_set_max_length (GTK_ENTRY (IndexTextbox), 0); + CountTextbox = new QLineEdit(); + // gtk_entry_set_max_length (GTK_ENTRY (CountTextbox), 0); + DestTextbox->setValidator( + new QRegExpValidator( + QRegExp("[a-zA-Z0-9_]+"))); + IndexTextbox->setValidator( + new QRegExpValidator( + QRegExp("[a-zA-Z0-9_]+"))); + CountTextbox->setValidator( + new QRegExpValidator( + QRegExp("[0-9]+"))); if(!forPwl) { - AsStringCheckbox = gtk_check_button_new_with_label - ("Edit table of ASCII values like a string"); - madeCheckbox = TRUE; + AsStringCheckbox = new QCheckBox( + _("Edit table of ASCII values like a string"), LutDialog); } - - 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); - if (madeCheckbox){ - gtk_grid_attach (GTK_GRID (LutGrid), AsStringCheckbox, 0, 8, 1, 1); + FixedControlGrid->addWidget(Labels[0],0,0); + FixedControlGrid->addWidget(DestTextbox,0,1); + FixedControlGrid->addWidget(Labels[1],1,0); + FixedControlGrid->addWidget(IndexTextbox,1,1); + FixedControlGrid->addWidget(Labels[2],2,0); + FixedControlGrid->addWidget(CountTextbox,2,1); + if (!forPwl){ + FixedControlGrid->addWidget(AsStringCheckbox, 3, 0, 1, 0, + Qt::AlignTop); } - - 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); + LutGrid->addLayout(FixedControlGrid, 0, 0, + Qt::AlignLeft | Qt::AlignTop); + ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok + | QDialogButtonBox::Cancel, Qt::Vertical, + LutDialog); + LutGrid->addWidget(ButtonBox,0,1); + QObject::connect(ButtonBox, SIGNAL(accepted()), LutDialog, SLOT(accept())); + QObject::connect(ButtonBox, SIGNAL(rejected()), LutDialog, SLOT(reject())); + QObject::connect(AsStringCheckbox, &QCheckBox::stateChanged,CheckBoxFunction); + QObject::connect(CountTextbox, &QLineEdit::textChanged,CountFunction); } //----------------------------------------------------------------------------- @@ -175,77 +161,47 @@ static void DestroyLutControls(BOOL destroyFlag = TRUE) // 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. + delete StringTextbox; } else { int i; for(i = 0; i < WasCount; i++) { - char buf[20]; - char *tmpB = (char*)gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i])); - strcpy (buf, tmpB); + const char* buf; + buf = ValuesTextbox[i]->text().toStdString().c_str(); ValuesCache[i] = atoi(buf); + delete ValuesTextbox[i]; + delete ValuesLabel[i]; } + delete LutControlGrid; } - - if (destroyFlag){ - for(int i = 0; i < temp.tmpcount; i++) - { - if (GTK_IS_ENTRY(ValuesTextbox[i])) - { - DestroyWindow(ValuesTextbox[i]); - DestroyWindow(ValuesLabel[i]); - } - } - ProgramChanged(); - } -} -static void DestroyLutControlsPiecewise(BOOL destroyFlag = TRUE) -{ - 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]; - char *tmpB = (char*)gtk_entry_get_text (GTK_ENTRY (ValuesTextbox[i])); - strcpy (buf, tmpB); - ValuesCache[i] = atoi(buf); - } - } - - if (destroyFlag) - { - int i; - for(i = 0; i < WasCount; i++) { - DestroyWindow(ValuesTextbox[i]); - DestroyWindow(ValuesLabel[i]); - } - ProgramChanged(); - } + // int i; + /*for(i = 0; i < MAX_LOOK_UP_TABLE_LEN; i++) { + delete ValuesTextbox[i]; + delete ValuesLabel[i]; + }*/ } + //----------------------------------------------------------------------------- // Make the controls that hold the LUT. The exact configuration of the dialog // will depend on (a) whether the user chose table-type or string-type entry, // 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) +static void MakeLutControls(BOOL asString, int counts, 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; + WasCount = counts; 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++) { + for(i = 0; i < counts; i++) { int c = ValuesCache[i]; if(c >= 32 && c <= 127 && c != '\\') { str[j++] = c; @@ -269,13 +225,17 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) } } str[j++] = '\0'; - StringTextbox = gtk_entry_new (); - gtk_grid_attach (GTK_GRID (LutGrid), StringTextbox, 0, 9, 1, 1); - checkString = TRUE; - gtk_widget_show_all (LutGrid); - gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), FALSE); + StringTextbox = new QLineEdit(); + FixedFont(StringTextbox); + FixedControlGrid->addWidget(StringTextbox, 4, 0, 1, 0, + Qt::AlignTop); + StringTextbox->setText(str); + QObject::connect(StringTextbox, &QLineEdit::textChanged,StringFunction); + /*checkString = TRUE;*/ + CountTextbox->setReadOnly(TRUE); } else { + LutControlGrid = new QGridLayout(); int i; int base; if(forPwl) { @@ -284,23 +244,28 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) else { base = 140; } - for(i = 0; i < count; i++) { + for(i = 0; i < counts; i++) { int x, y; if(i < 16) { - x = 10; - y = base+30*i; + x = i; + y = 0; } else { - x = 160; - y = base+30*(i-16); + x = i % 16; + y = 2; } char buf[20]; sprintf(buf, "%d", ValuesCache[i]); - ValuesTextbox[i] = gtk_entry_new (); - gtk_entry_set_max_length (GTK_ENTRY (ValuesTextbox[i]), 0); - gtk_entry_set_text (GTK_ENTRY (ValuesTextbox[i]), buf); + ValuesTextbox[i] = new QLineEdit(); + ValuesTextbox[i]->setMaximumWidth(80); + ValuesTextbox[i]->setValidator( + new QRegExpValidator( + QRegExp("-?[0-9]+"))); + NiceFont(ValuesTextbox[i]); + ValuesTextbox[i]->setText(buf); + LutControlGrid->addWidget(ValuesTextbox[i], x, y + 1); if(forPwl) { sprintf(buf, "%c%d:", (i & 1) ? 'y' : 'x', i/2); @@ -309,28 +274,21 @@ static void MakeLutControls(BOOL asString, int count, BOOL forPwl) 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); + ValuesLabel[i] = new QLabel(buf); + FixedFont(ValuesLabel[i]); + LutControlGrid->addWidget(ValuesLabel[i], x , y); } - if(count > 16) count = 16; - gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), TRUE); + // if(counts > 16) + FixedControlGrid->addLayout(LutControlGrid, 4, 0, 1, 0, + Qt::AlignTop); + // else + // FixedControlGrid->addLayout(LutControlGrid, 4, 0, 1, 0, + // Qt::AlignTop); + CountTextbox->setReadOnly(FALSE); } } + //----------------------------------------------------------------------------- // Decode a string into a look-up table; store the values in ValuesCache[], // and update the count checkbox (which in string mode is read-only) to @@ -363,148 +321,11 @@ BOOL StringToValuesCache(char *str, int *c) char buf[10]; sprintf(buf, "%d", count); - gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf); + CountTextbox->setText(buf); *c = count; return TRUE; } -void LookUpTableGetData (gpointer data){ - ElemLeaf *l = (ElemLeaf *) data; - ElemLookUpTable *t = &(l->d.lookUpTable); - strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox))); - strcpy (t->index, gtk_entry_get_text (GTK_ENTRY (IndexTextbox))); - DestroyLutControls(FALSE); - - // 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), ""); - } - 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]; - 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)); - checkString = x; - if((x && !asString) || (!x && asString)) { - asString = x; - if (x == 1){ - MakeLutControls(asString, count, FALSE); - - for(int i = 0; i < temp.tmpcount; i++) { - if (GTK_IS_ENTRY(ValuesTextbox[i])) - { - DestroyWindow(ValuesTextbox[i]); - DestroyWindow(ValuesLabel[i]); - } - } - ProgramChanged(); - } - else { - DestroyLutControls(); - if (!x && GTK_IS_ENTRY(StringTextbox)) - { - DestroyWindow(StringTextbox); - ProgramChanged(); - gtk_editable_set_editable (GTK_EDITABLE (CountTextbox), TRUE); - } - } - } - - temp.tmpcount = count; - temp.tmpasString = asString; -} - -// Checks for the required key press -gboolean LookUpTableKeyPress (HWID widget, GdkEventKey* event, gpointer data){ - - if (event -> keyval == GDK_KEY_Return){ - LookUpTableCheckMode (); - LookUpTableGetData((gpointer) data); - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); - LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; - } - else if (event -> keyval == GDK_KEY_Escape){ - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); - LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; - } - return FALSE; -} - -/// Dialog refresh function -BOOL LutDialogRefresh(gpointer data) -{ - LookUpTableCheckMode (); - LookUpTableGetData((gpointer) data); - return TRUE; -} -// Ok button call -void LutDialogOk (HWID widget, gpointer data) -{ - LookUpTableCheckMode (); - LookUpTableGetData((gpointer) data); - - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); - LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; -} - -// Cancel button call -void LutCallCancel (HWID widget, gpointer data) -{ - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_1); - LUT_DIALOG_REFRESH_TIMER_ID_1 = 0; -} - //----------------------------------------------------------------------------- // Show the look-up table dialog. This one is nasty, mostly because there are // two ways to enter a look-up table: as a table, or as a string. Presumably @@ -520,151 +341,109 @@ void ShowLookUpTableDialog(ElemLeaf *l) // bad to update those in the leaf before the user clicks okay (as he // might cancel). - int count = t->count; - BOOL asString = t->editAsString; + ControlCount = t->count; + asString = t->editAsString; memset(ValuesCache, 0, sizeof(ValuesCache)); int i; - for(i = 0; i < count; i++) { + for(i = 0; i < ControlCount; 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(); - 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); + LutDialog = CreateWindowClient(_("Look-Up Table"), + 100, 100, 320, 375, MainWindow); + LutPackingBox = new QGridLayout(); + LutGrid = new QGridLayout(LutDialog); + LutDialog->setWindowTitle(_("Look-Up Table")); MakeFixedControls(FALSE); - MakeLutControls(asString, count, FALSE); - - // 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); - + MakeLutControls(asString, ControlCount, FALSE); + DestTextbox->setText(t->dest); + IndexTextbox->setText(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; - temp.tmpasString = asString; - - g_signal_connect (G_OBJECT (LutDialog), "key-press-event", - G_CALLBACK(LookUpTableKeyPress), (gpointer)l); - g_signal_connect (G_OBJECT (OkButton), "clicked", - G_CALLBACK(LutDialogOk), (gpointer)l); - g_signal_connect (G_OBJECT (CancelButton), "clicked", - G_CALLBACK(LutCallCancel), NULL); - - if (LUT_DIALOG_REFRESH_TIMER_ID_1 == 0) - LUT_DIALOG_REFRESH_TIMER_ID_1 = g_timeout_add(100, (GSourceFunc)LutDialogRefresh, (gpointer)l); -} - -// Piecewise Dialog - -void PiecewiseDialogGetData(gpointer data){ - - ElemLeaf *l = (ElemLeaf *) data; - ElemPiecewiseLinear *t = &(l->d.piecewiseLinear); - int count = piecewiseTmpCount; - strcpy (t->dest, gtk_entry_get_text (GTK_ENTRY (DestTextbox))); - strcpy (t->index, gtk_entry_get_text (GTK_ENTRY (IndexTextbox))); - DestroyLutControlsPiecewise(FALSE); - // MakeLutControls(FALSE, count*2, TRUE); - - // The call to DestroyLutControlsPiecewise 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; -} - -void PiecewiseDialogPointTextbox (int count){ - char* buf; - char *tmpBuf = (char*)gtk_entry_get_text (GTK_ENTRY (CountTextbox)); - buf = (char*)malloc(strlen(tmpBuf)); - strcpy (buf, tmpBuf); - if(atoi(buf) != count) { - count = atoi(buf); - if(count < 0 || count > 10) { - count = 0; - gtk_entry_set_text (GTK_ENTRY (CountTextbox), ""); + CountTextbox->setText(buf); + AsStringCheckbox->setChecked(asString); + PrevTableAsString[0] = NULL; + int ret = LutDialog->exec(); + switch(ret) + { + case QDialog::Accepted: + { + strncpy(t->dest, + DestTextbox->text().toStdString().c_str(),16); + strncpy(t->index, + IndexTextbox->text().toStdString().c_str(),16); + int count = ControlCount; + 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]; + printf("Value:%d\n", ValuesCache[i]); } - DestroyLutControlsPiecewise(); - MakeLutControls(FALSE, count*2, TRUE); + t->count = count; + t->editAsString = asString; + printf("Count:%d\n", count); } - piecewiseTmpCount = count; + break; + case QDialog::Rejected: + break; + } + DestroyWindow(); } -/// Dialog refresh function -BOOL PiecewiseDialogRefresh(gpointer data) -{ - PiecewiseDialogPointTextbox (piecewiseTmpCount); - PiecewiseDialogGetData((gpointer) data); - return TRUE; -} +// The function to handle checkbox event separated from +// ShowLookUpTableDialog function to improve performance in Qt -// Ok button call -void PiecewiseDialogOk (HWID widget, gpointer data) +void CheckBoxFunction(int state) { - PiecewiseDialogPointTextbox (piecewiseTmpCount); - PiecewiseDialogGetData((gpointer) data); - - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); - LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; + printf("CheckBoxFunctionCalled\n"); + asString = state; + DestroyLutControls(); + const char* buf; + buf = CountTextbox->text().toStdString().c_str(); + MakeLutControls(asString, atoi(buf), FALSE); } -// Checks for the required key press -gboolean PiecewiseDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){ - - if (event -> keyval == GDK_KEY_Return){ - PiecewiseDialogPointTextbox (piecewiseTmpCount); - PiecewiseDialogGetData((gpointer) data); - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); - LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; - } - else if (event -> keyval == GDK_KEY_Escape){ - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); - LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; - } - return FALSE; +// The function to handle change in CountTextbox separated from +// ShowLookUpTableDialog function to improve performance in Qt +void CountFunction(QString text) +{ + printf("TextFunction called:%s\n",text.toStdString().c_str()); + const char* buf; + buf = text.toStdString().c_str(); + if(atoi(buf) != ControlCount && !asString) { + ControlCount = atoi(buf); + if(ControlCount < 0 || ControlCount > 32) { + ControlCount = 0; + CountTextbox->setText(""); + } + DestroyLutControls(); + MakeLutControls(asString, ControlCount, FALSE); + } } -// Cancel button call -void PiecewiseCallCancel (HWID widget, gpointer data) +// The function to handle change in StringTextbox separated from +// ShowLookUpTableDialog function to improve performance in Qt +void StringFunction(QString text) { - DestroyWindow (LutDialog); - ProgramChanged(); - gtk_widget_set_sensitive (MainWindow, TRUE); - g_source_remove (LUT_DIALOG_REFRESH_TIMER_ID_2); - LUT_DIALOG_REFRESH_TIMER_ID_2 = 0; + printf("StringFunction called \n"); + char* scratch = (char*)text.toStdString().c_str(); + // SendMessage(StringTextbox, WM_GETTEXT, (WPARAM)sizeof(scratch), + // (LPARAM)scratch); + if(strcmp(scratch, PrevTableAsString)!=0) { + if(StringToValuesCache(scratch, &ControlCount)) { + strcpy(PrevTableAsString, scratch); + } else { + // Too long; put back the old one + // SendMessage(StringTextbox, WM_SETTEXT, 0, + // (LPARAM)PrevTableAsString); + StringTextbox->setText(PrevTableAsString); + } + } } //----------------------------------------------------------------------------- @@ -688,43 +467,40 @@ void ShowPiecewiseLinearDialog(ElemLeaf *l) // 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(); - LutPackingBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - - LutDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(LutDialog), "Piecewise Linear 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); - + LutDialog = CreateWindowClient(_("Piecewise Linear Table"), + 100, 100, 320, 375, MainWindow); + LutPackingBox = new QGridLayout(); + LutGrid = new QGridLayout(LutDialog); + LutDialog->setWindowTitle(_("Piecewise Linear Table")); MakeFixedControls(TRUE); - MakeLutControls(FALSE, count*2, TRUE); - - // 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); + MakeLutControls(FALSE, ControlCount, TRUE); + DestTextbox->setText(t->dest); + IndexTextbox->setText(t->index); char buf[30]; sprintf(buf, "%d", t->count); - gtk_entry_set_text (GTK_ENTRY (CountTextbox), buf); - - // And show the window - gtk_widget_set_sensitive (MainWindow, FALSE); - gtk_widget_show_all (LutDialog); - // gtk_widget_grab_focus (DestTextbox); - - piecewiseTmpCount = count; - - g_signal_connect (G_OBJECT (LutDialog), "key-press-event", - G_CALLBACK(PiecewiseDialogKeyPress), (gpointer)l); - g_signal_connect (G_OBJECT (OkButton), "clicked", - G_CALLBACK(PiecewiseDialogOk), (gpointer)l); - g_signal_connect (G_OBJECT (CancelButton), "clicked", - G_CALLBACK(PiecewiseCallCancel), NULL); - - if (LUT_DIALOG_REFRESH_TIMER_ID_2 == 0) - LUT_DIALOG_REFRESH_TIMER_ID_2 = g_timeout_add(100, (GSourceFunc)PiecewiseDialogRefresh, (gpointer)l); -} + CountTextbox->setText(buf); + int ret = LutDialog->exec(); + switch(ret) + { + case QDialog::Accepted: + { + strncpy(t->dest, + DestTextbox->text().toStdString().c_str(),16); + strncpy(t->index, + IndexTextbox->text().toStdString().c_str(),16); + int count = ControlCount; + 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; + } + break; + case QDialog::Rejected: + break; + } + DestroyWindow(); +}
\ No newline at end of file diff --git a/ldmicro/schematic.cpp b/ldmicro/schematic.cpp index 840d095..7bba676 100644 --- a/ldmicro/schematic.cpp +++ b/ldmicro/schematic.cpp @@ -417,7 +417,7 @@ void EditSelectedElement(void) &(Selected->d.coil.setOnly), &(Selected->d.coil.resetOnly), Selected->d.coil.name); break; -/* + case ELEM_TON: case ELEM_TOF: case ELEM_RTO: @@ -449,11 +449,11 @@ void EditSelectedElement(void) ShowMathDialog(SelectedWhich, Selected->d.math.dest, Selected->d.math.op1, Selected->d.math.op2); break; -*/ + case ELEM_RES: ShowResetDialog(Selected->d.reset.name); break; -/* + case ELEM_MOVE: ShowMoveDialog(Selected->d.move.dest, Selected->d.move.src); break; @@ -492,7 +492,7 @@ void EditSelectedElement(void) case ELEM_LOOK_UP_TABLE: ShowLookUpTableDialog(Selected); - break;*/ + break; } } diff --git a/ldmicro/simpledialog.cpp b/ldmicro/simpledialog.cpp index 6291e24..f1ebd28 100644 --- a/ldmicro/simpledialog.cpp +++ b/ldmicro/simpledialog.cpp @@ -29,23 +29,23 @@ #include "ldmicro.h" -static HWID SimpleDialog; -static HWID OkButton; -static HWID CancelButton; +static QDialog* SimpleDialog; #define MAX_BOXES 5 -static HWID Textboxes[MAX_BOXES]; -static HWID Labels[MAX_BOXES]; +static QLineEdit* Textboxes[MAX_BOXES]; +static QLabel* Labels[MAX_BOXES]; -static LONG_PTR PrevAlnumOnlyProc[MAX_BOXES]; -static LONG_PTR PrevNumOnlyProc[MAX_BOXES]; +static QGridLayout* SimpleGrid; + +/*static LONG_PTR PrevAlnumOnlyProc[MAX_BOXES]; +static LONG_PTR PrevNumOnlyProc[MAX_BOXES];*/ static BOOL NoCheckingOnBox[MAX_BOXES]; -static BOOL SIMPLE_DIALOG_ACTIVE = FALSE; +/*static BOOL SIMPLE_DIALOG_ACTIVE = FALSE;*/ -static SimpleDialogData SDdata; +/*static SimpleDialogData SDdata;*/ /// Simple dialog data flags #define SD_TIMER 0x0000001 @@ -124,6 +124,16 @@ static void MyNumOnlyProc (GtkEditable *editable, gchar *NewText, gint length, // } // } // oops(); +}*/ + +inline void DestroyWindow (int boxes){ + for(int i = 0; i < boxes; i++) { + delete Labels[i]; + delete Textboxes[i]; + } + delete SimpleGrid; + delete SimpleDialog; + ProgramChanged(); } static void MakeControls(int boxes, char **labels, DWORD fixedFontMask) @@ -146,51 +156,34 @@ static void MakeControls(int boxes, char **labels, DWORD fixedFontMask) // } else { // adj = 0; // } - HWID grid = gtk_grid_new(); + QGridLayout* grid = new QGridLayout(); + QDialogButtonBox *ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok + | QDialogButtonBox::Cancel, Qt::Vertical, + SimpleDialog); + NiceFont(SimpleDialog); for(i = 0; i < boxes; i++) { // GetTextExtentPoint32(hdc, labels[i], strlen(labels[i]), &si); - Labels[i] = gtk_label_new (labels[i]); - // CreateWindowEx(0, WC_STATIC, labels[i], - // WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, - // (80 + adj) - si.cx - 4, 13 + i*30, si.cx, 21, - // SimpleDialog, NULL, Instance, NULL); + Labels[i] = new QLabel(labels[i]); NiceFont(Labels[i]); - gtk_grid_attach (GTK_GRID (grid), Labels[i], 0, i, 1, 1); + grid->addWidget(Labels[i],i,0); - Textboxes[i] = gtk_entry_new (); - // CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", - // WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | - // WS_VISIBLE, - // 80 + adj, 12 + 30*i, 120 - adj, 21, - // SimpleDialog, NULL, Instance, NULL); + Textboxes[i] = new QLineEdit(); if(fixedFontMask & (1 << i)) { FixedFont(Textboxes[i]); } else { NiceFont(Textboxes[i]); } - gtk_grid_attach (GTK_GRID (grid), Textboxes[i], 1, i, 1, 1); + grid->addWidget(Textboxes[i],i,1); } - // ReleaseDC(SimpleDialog, hdc); - - OkButton = gtk_button_new_with_label (_("OK")); - // CreateWindowEx(0, WC_BUTTON, _("OK"), - // WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, - // 218, 11, 70, 23, SimpleDialog, NULL, Instance, NULL); - NiceFont(OkButton); - gtk_grid_attach (GTK_GRID (grid), OkButton, 2, 0, 1, 1); - - CancelButton = gtk_button_new_with_label(_("Cancel")); - // CreateWindowEx(0, WC_BUTTON, _("Cancel"), - // WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, - // 218, 41, 70, 23, SimpleDialog, NULL, Instance, NULL); - NiceFont(CancelButton); - gtk_grid_attach (GTK_GRID (grid), CancelButton, 2, 1, 1, 1); - gtk_container_add(GTK_CONTAINER(SimpleDialog), grid); + SimpleGrid->addLayout(grid, 0,0); + SimpleGrid->addWidget(ButtonBox, 0, 1); + QObject::connect(ButtonBox, SIGNAL(accepted()), SimpleDialog, SLOT(accept())); + QObject::connect(ButtonBox, SIGNAL(rejected()), SimpleDialog, SLOT(reject())); } - +/* void SimpleDialogWrapUp() { // if(!didCancel) @@ -330,91 +323,79 @@ static gboolean SimpleDialogKeyPressProc(HWID widget, GdkEventKey* event, gpoint return FALSE; }*/ -void ShowSimpleDialog(char *title, int boxes, char **labels, DWORD numOnlyMask, +BOOL ShowSimpleDialog(char *title, int boxes, char **labels, DWORD numOnlyMask, DWORD alnumOnlyMask, DWORD fixedFontMask, char **dests) { - if(SIMPLE_DIALOG_ACTIVE) + /*if(SIMPLE_DIALOG_ACTIVE) return; SIMPLE_DIALOG_ACTIVE = TRUE; - BOOL didCancel = FALSE; + BOOL didCancel = FALSE;*/ + BOOL RetVal = FALSE; if(boxes > MAX_BOXES) oops(); - SimpleDialog = CreateWindowClient(GTK_WINDOW_TOPLEVEL, GDK_WINDOW_TYPE_HINT_NORMAL, - title, 100, 100, 304, 15 + 30*(boxes < 2 ? 2 : boxes), MainWindow); - SimpleDialog->show(); - // CreateWindowClient(0, "LDmicroDialog", title, - // WS_OVERLAPPED | WS_SYSMENU, - // 100, 100, 304, 15 + 30*(boxes < 2 ? 2 : boxes), NULL, NULL, - // Instance, NULL); - -/* MakeControls(boxes, labels, fixedFontMask); - + SimpleDialog = CreateWindowClient(title, 100, 100, + 304, 15 + 30*(boxes < 2 ? 2 : boxes), MainWindow); + SimpleGrid = new QGridLayout(SimpleDialog); + SimpleDialog->setWindowTitle(title); + MakeControls(boxes, labels, fixedFontMask); int i; - for(i = 0; i < boxes; i++) - { - // SendMessage(Textboxes[i], WM_SETTEXT, 0, (LPARAM)dests[i]); - gtk_entry_set_text (GTK_ENTRY(Textboxes[i]), dests[i]); + for(i = 0; i < boxes; i++) { + Textboxes[i]->setText(dests[i]); - if(numOnlyMask & (1 << i)) - { - g_signal_connect (G_OBJECT(Textboxes[i]), "insert-text", - G_CALLBACK(MyNumOnlyProc), NULL); - // PrevNumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, - // (LONG_PTR)MyNumOnlyProc); - } else if(alnumOnlyMask & (1 << i)) + if(numOnlyMask & (1 << i)) { + Textboxes[i]->setValidator( + new QRegExpValidator(QRegExp("-?[0-9]+[.]?[0-9]+"))); + } + if(alnumOnlyMask & (1 << i)) { + /*PrevAlnumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, + (LONG_PTR)MyAlnumOnlyProc);*/ + Textboxes[i]->setValidator( + new QRegExpValidator( + QRegExp("[a-zA-Z0-9_'-]+"))); + } + } + int ret = SimpleDialog->exec(); + switch(ret) + { + case QDialog::Accepted: { - g_signal_connect (G_OBJECT(Textboxes[i]), "insert-text", - G_CALLBACK(MyAlnumOnlyProc), NULL); - // PrevAlnumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, - // (LONG_PTR)MyAlnumOnlyProc); + for(i = 0; i < boxes; i++) { + if(NoCheckingOnBox[i]) { + strncpy(dests[i], + Textboxes[i]->text().toStdString().c_str(),60); + } else { + char get[20]; + // SendMessage(Textboxes[i], WM_GETTEXT, 15, (LPARAM)get); + strncpy(get, Textboxes[i]->text().toStdString().c_str(),15); + + if( (!strchr(get, '\'')) || + (get[0] == '\'' && get[2] == '\'' && strlen(get)==3) ) + { + if(strlen(get) == 0) { + Error(_("Empty textbox; not permitted.")); + } else { + strcpy(dests[i], get); + } + } else { + Error(_("Bad use of quotes: <%s>"), get); + } + } + } + RetVal = TRUE; + break; } + case QDialog::Rejected: + RetVal = FALSE; + break; } - - g_signal_connect (CancelButton, "clicked", G_CALLBACK (SimpleDialogCancelProc), NULL); - g_signal_connect (OkButton, "clicked", G_CALLBACK (SimpleDialogWrapUp), NULL); - g_signal_connect (SimpleDialog, "key_press_event", G_CALLBACK (SimpleDialogKeyPressProc), NULL); - - // EnableWindow(MainWindow, FALSE); - // ShowWindow(SimpleDialog, TRUE); - gtk_widget_show_all(SimpleDialog); -*/ // SetFocus(Textboxes[0]); - // SendMessage(Textboxes[0], 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(SimpleDialog, &msg)) continue; - // TranslateMessage(&msg); - // DispatchMessage(&msg); - // } - - // didCancel = DialogCancel; - - - - // EnableWindow(MainWindow, TRUE); - // DestroyWindow(SimpleDialog); - - // return !didCancel; + DestroyWindow(boxes); + return RetVal; } -/*void ShowTimerDialog(int which, int *delay, char *name) +void ShowTimerDialog(int which, int *delay, char *name) { char *s; switch(which) { @@ -431,21 +412,18 @@ void ShowSimpleDialog(char *title, int boxes, char **labels, DWORD numOnlyMask, sprintf(delBuf, "%.3f", (*delay / 1000.0)); strcpy(nameBuf, name+1); char *dests[] = { nameBuf, delBuf }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_TIMER; - SDdata.boxes = 2; - SDdata.str1 = name; - SDdata.num1 = delay; - SDdata.dests = new char*[2]; - SDdata.dests[0] = new char[16]; - SDdata.dests[1] = new char[16]; - sprintf(SDdata.dests[1], "%.3f", (*delay / 1000.0)); - strcpy(SDdata.dests[0], name+1); - - ShowSimpleDialog(s, 2, labels, (1 << 1), (1 << 0), (1 << 0), dests); + if(ShowSimpleDialog(s, 2, labels, (1 << 1), (1 << 0), (1 << 0), dests)) { + name[0] = 'T'; + strcpy(name+1, nameBuf); + double del = atof(delBuf); + if(del > 2140000) { // 2**31/1000, don't overflow signed int + Error(_("Delay too long; maximum is 2**31 us.")); + } else if(del <= 0) { + Error(_("Delay cannot be zero or negative.")); + } else { + *delay = (int)(1000*del + 0.5); + } + } } void ShowCounterDialog(int which, int *maxV, char *name) @@ -465,20 +443,8 @@ void ShowCounterDialog(int which, int *maxV, char *name) char maxS[128]; sprintf(maxS, "%d", *maxV); char *dests[] = { name+1, maxS }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_COUNTER; - SDdata.boxes = 2; - SDdata.str1 = name; - SDdata.num1 = maxV; - SDdata.dests = new char*[2]; - SDdata.dests[0] = name+1; - SDdata.dests[1] = new char[128]; - sprintf(SDdata.dests[1], "%d", *maxV); - ShowSimpleDialog(title, 2, labels, 0x2, 0x1, 0x1, dests); + *maxV = atoi(maxS); } void ShowCmpDialog(int which, char *op1, char *op2) @@ -521,16 +487,6 @@ void ShowCmpDialog(int which, char *op1, char *op2) } char *labels[] = { _("'Closed' if:"), l2 }; char *dests[] = { op1, op2 }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_CMP; - SDdata.boxes = 2; - SDdata.dests = new char*[2]; - SDdata.dests[0] = op1; - SDdata.dests[1] = op2; - ShowSimpleDialog(title, 2, labels, 0, 0x3, 0x3, dests); } @@ -538,16 +494,6 @@ void ShowMoveDialog(char *dest, char *src) { char *labels[] = { _("Destination:"), _("Source:") }; char *dests[] = { dest, src }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_MOVE; - SDdata.boxes = 2; - SDdata.dests = new char*[2]; - SDdata.dests[0] = dest; - SDdata.dests[1] = src; - ShowSimpleDialog(_("Move"), 2, labels, 0, 0x3, 0x3, dests); } @@ -555,15 +501,6 @@ void ShowReadAdcDialog(char *name) { char *labels[] = { _("Destination:") }; char *dests[] = { name }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_READ_ADC; - SDdata.boxes = 1; - SDdata.dests = new char*[1]; - SDdata.dests[0] = name; - ShowSimpleDialog(_("Read A/D Converter"), 1, labels, 0, 0x1, 0x1, dests); } @@ -574,19 +511,8 @@ void ShowSetPwmDialog(char *name, int *targetFreq) char *labels[] = { _("Duty cycle var:"), _("Frequency (Hz):") }; char *dests[] = { name, freq }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_SET_PWM; - SDdata.boxes = 2; - SDdata.num1 = targetFreq; - SDdata.dests = new char*[2]; - SDdata.dests[0] = name; - SDdata.dests[1] = new char[100]; - sprintf(SDdata.dests[1], "%d", *targetFreq); - ShowSimpleDialog(_("Set PWM Duty Cycle"), 2, labels, 0x2, 0x1, 0x1, dests); + *targetFreq = atoi(freq); } void ShowUartDialog(int which, char *name) @@ -595,14 +521,6 @@ void ShowUartDialog(int which, char *name) _("Source:") }; char *dests[] = { name }; - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_UART; - SDdata.boxes = 1; - SDdata.dests = new char*[2]; - SDdata.dests[0] = name; - ShowSimpleDialog((which == ELEM_UART_RECV) ? _("Receive from UART") : _("Send to UART"), 1, labels, 0, 0x1, 0x1, dests); } @@ -626,17 +544,6 @@ void ShowMathDialog(int which, char *dest, char *op1, char *op2) char *labels[] = { _("Destination:"), _("is set := :"), l2 }; char *dests[] = { dest, op1, op2 }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_MATH; - SDdata.boxes = 3; - SDdata.dests = new char*[3]; - SDdata.dests[0] = dest; - SDdata.dests[1] = op1; - SDdata.dests[2] = op2; - ShowSimpleDialog(title, 3, labels, 0, 0x7, 0x7, dests); } @@ -648,34 +555,19 @@ void ShowShiftRegisterDialog(char *name, int *stages) char *labels[] = { _("Name:"), _("Stages:") }; char *dests[] = { name, stagesStr }; - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_SHIFT_REGISTER; - SDdata.boxes = 2; - SDdata.num1 = stages; - SDdata.dests = new char*[2]; - SDdata.dests[0] = name; - SDdata.dests[1] = new char[20]; - sprintf(SDdata.dests[1], "%d", *stages); - ShowSimpleDialog(_("Shift Register"), 2, labels, 0x2, 0x1, 0x1, dests); + *stages = atoi(stagesStr); + + if(*stages <= 0 || *stages >= 200) { + Error(_("Not a reasonable size for a shift register.")); + *stages = 1; + } } void ShowFormattedStringDialog(char *var, char *string) { char *labels[] = { _("Variable:"), _("String:") }; char *dests[] = { var, string }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_FORMATTED_STRING; - SDdata.boxes = 2; - SDdata.dests = new char*[2]; - SDdata.dests[0] = var; - SDdata.dests[1] = string; - NoCheckingOnBox[0] = TRUE; NoCheckingOnBox[1] = TRUE; ShowSimpleDialog(_("Formatted String Over UART"), 2, labels, 0x0, @@ -688,15 +580,5 @@ void ShowPersistDialog(char *var) { char *labels[] = { _("Variable:") }; char *dests[] = { var }; - - if (SIMPLE_DIALOG_ACTIVE) - return; - - SDdata.uflag = SD_PERSIST; - SDdata.boxes = 1; - SDdata.dests = new char*[1]; - SDdata.dests[0] = var; - ShowSimpleDialog(_("Make Persistent"), 1, labels, 0, 1, 1, dests); } -*/
\ No newline at end of file |