summaryrefslogtreecommitdiff
path: root/ldmicro
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro')
-rw-r--r--ldmicro/confdialog.cpp7
-rw-r--r--ldmicro/contactsdialog.cpp9
-rw-r--r--ldmicro/draw_outputdev.cpp187
-rw-r--r--ldmicro/includes/ldmicro.h9
-rw-r--r--ldmicro/iolist.cpp548
-rw-r--r--ldmicro/ldmicro.cpp28
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h2
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp33
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h11
-rw-r--r--ldmicro/lutdialog.cpp10
-rw-r--r--ldmicro/maincontrols.cpp25
-rw-r--r--ldmicro/miscutil.cpp62
-rw-r--r--ldmicro/resetdialog.cpp6
-rw-r--r--ldmicro/simulate.cpp226
-rw-r--r--ldmicro/undoredo.cpp12
15 files changed, 614 insertions, 561 deletions
diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp
index 253ebec..2fd8dd7 100644
--- a/ldmicro/confdialog.cpp
+++ b/ldmicro/confdialog.cpp
@@ -169,8 +169,7 @@ void ConfDialogGetData (GtkWidget* widget, gpointer data){
buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY(BaudTextbox)));
Prog.baudRate = atoi(buf);
- DestroyWindow (ConfDialog, NULL);
- gtk_widget_set_sensitive (MainWindow, TRUE);
+ DestroyWindow (ConfDialog);
}
// Checks for the required key press
@@ -179,14 +178,14 @@ gboolean ConfDialogKeyPress (GtkWidget* widget, GdkEventKey* event, gpointer dat
ConfDialogGetData(NULL, NULL);
}
else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (ConfDialog, NULL);
+ DestroyWindow (ConfDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
return FALSE;
}
void ConfCallDestroyWindow (HWID widget, gpointer data){
- DestroyWindow (ConfDialog, NULL);
+ DestroyWindow (ConfDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
diff --git a/ldmicro/contactsdialog.cpp b/ldmicro/contactsdialog.cpp
index 2f34c08..8d6e8d4 100644
--- a/ldmicro/contactsdialog.cpp
+++ b/ldmicro/contactsdialog.cpp
@@ -126,9 +126,8 @@ void ContactsDialogGetData (BOOL* negated, char* name){
name[0] = 'Y';
}
strcpy (name+1, gtk_entry_get_text (GTK_ENTRY (NameTextbox)));
- // ******** Check this *******
- // SendMessage(NameTextbox, WM_GETTEXT, (WPARAM)16, (LPARAM)(name+1));
- DestroyWindow (ContactsDialog, NULL);
+
+ DestroyWindow (ContactsDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
@@ -143,14 +142,14 @@ gboolean ContactsDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data)
ContactsDialogGetData(tmpnegated, tmpname);
}
else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (ContactsDialog, NULL);
+ DestroyWindow (ContactsDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
return FALSE;
}
void ContactsCallDestroyWindow (HWID widget, gpointer data){
- DestroyWindow (ContactsDialog, NULL);
+ DestroyWindow (ContactsDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp
index eab7324..cf2cae4 100644
--- a/ldmicro/draw_outputdev.cpp
+++ b/ldmicro/draw_outputdev.cpp
@@ -102,7 +102,7 @@ BOOL BlinkCursor(BOOL kill = FALSE)
// if(!GDK_IS_DRAWING_CONTEXT(Hdc))
// return FALSE;
- HCRDC Hcr = gdk_cairo_create(gtk_widget_get_window(DrawWindow));//gdk_drawing_context_get_cairo_context(Hdc);//
+ HCRDC Hcr = gdk_cairo_create(gtk_widget_get_window(DrawWindow));
static int PREV_x = c.left;
static int PREV_y = c.top;
@@ -429,7 +429,7 @@ void InitForDrawing(void)
// DrawChars function, for drawing to the export buffer instead of to the
// screen.
//-----------------------------------------------------------------------------
-static void DrawCharsToExportBuffer(int cx, int cy, char *str)
+static void DrawCharsToExportBuffer(HCRDC Hcr, int cx, int cy, const char *str)
{
while(*str) {
if(*str >= 10) {
@@ -445,105 +445,106 @@ static void DrawCharsToExportBuffer(int cx, int cy, char *str)
//-----------------------------------------------------------------------------
void ExportDrawingAsText(char *file)
{
- // int maxWidth = ProgCountWidestRow();
- // ColsAvailable = maxWidth;
-
- // int totalHeight = 0;
- // int i;
- // for(i = 0; i < Prog.numRungs; i++) {
- // totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]);
- // totalHeight += 1;
- // }
- // totalHeight *= POS_HEIGHT;
- // totalHeight += 3;
-
- // ExportBuffer = (char **)CheckMalloc(totalHeight * sizeof(char *));
+ int maxWidth = ProgCountWidestRow();
+ ColsAvailable = maxWidth;
+
+ int totalHeight = 0;
+ int i;
+ for(i = 0; i < Prog.numRungs; i++) {
+ totalHeight += CountHeightOfElement(ELEM_SERIES_SUBCKT, Prog.rungs[i]);
+ totalHeight += 1;
+ }
+ totalHeight *= POS_HEIGHT;
+ totalHeight += 3;
+
+ ExportBuffer = (char **)CheckMalloc(totalHeight * sizeof(char *));
- // int l = maxWidth*POS_WIDTH + 8;
- // for(i = 0; i < totalHeight; i++) {
- // ExportBuffer[i] = (char *)CheckMalloc(l);
- // memset(ExportBuffer[i], ' ', l-1);
- // ExportBuffer[i][4] = '|';
- // ExportBuffer[i][3] = '|';
- // ExportBuffer[i][l-3] = '|';
- // ExportBuffer[i][l-2] = '|';
- // ExportBuffer[i][l-1] = '\0';
- // }
-
- // DrawChars = DrawCharsToExportBuffer;
-
- // int cy = 1;
- // for(i = 0; i < Prog.numRungs; i++) {
- // int cx = 5;
- // DrawElement(ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
- // Prog.rungPowered[i]);
-
- // if((i + 1) < 10) {
- // ExportBuffer[cy+1][1] = '0' + (i + 1);
- // } else {
- // ExportBuffer[cy+1][1] = '0' + ((i + 1) % 10);
- // ExportBuffer[cy+1][0] = '0' + ((i + 1) / 10);
- // }
-
- // cy += POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT,
- // Prog.rungs[i]);
- // cy += POS_HEIGHT;
- // }
- // cy -= 2;
- // DrawEndRung(5, cy);
-
- // FILE *f = fopen(file, "w");
- // if(!f) {
- // Error(_("Couldn't open '%s'\n"), f);
- // return;
- // }
-
- // fprintf(f, "LDmicro export text\n");
-
- // if(Prog.mcu) {
- // fprintf(f, "for '%s', %.6f MHz crystal, %.1f ms cycle time\n\n",
- // Prog.mcu->mcuName, Prog.mcuClock/1e6, Prog.cycleTime/1e3);
- // } else {
- // fprintf(f, "no MCU assigned, %.6f MHz crystal, %.1f ms cycle time\n\n",
- // Prog.mcuClock/1e6, Prog.cycleTime/1e3);
- // }
-
- // fprintf(f, "\nLADDER DIAGRAM:\n\n");
-
- // for(i = 0; i < totalHeight; i++) {
- // ExportBuffer[i][4] = '|';
- // fprintf(f, "%s\n", ExportBuffer[i]);
- // CheckFree(ExportBuffer[i]);
- // }
- // CheckFree(ExportBuffer);
- // ExportBuffer = NULL;
-
- // fprintf(f, _("\n\nI/O ASSIGNMENT:\n\n"));
+ int l = maxWidth*POS_WIDTH + 8;
+ for(i = 0; i < totalHeight; i++) {
+ ExportBuffer[i] = (char *)CheckMalloc(l);
+ memset(ExportBuffer[i], ' ', l-1);
+ ExportBuffer[i][4] = '|';
+ ExportBuffer[i][3] = '|';
+ ExportBuffer[i][l-3] = '|';
+ ExportBuffer[i][l-2] = '|';
+ ExportBuffer[i][l-1] = '\0';
+ }
+
+ DrawChars = DrawCharsToExportBuffer;
+
+ int cy = 1;
+
+ for(i = 0; i < Prog.numRungs; i++) {
+ int cx = 5;
+ DrawElement(NULL, ELEM_SERIES_SUBCKT, Prog.rungs[i], &cx, &cy,
+ Prog.rungPowered[i]);
+
+ if((i + 1) < 10) {
+ ExportBuffer[cy+1][1] = '0' + (i + 1);
+ } else {
+ ExportBuffer[cy+1][1] = '0' + ((i + 1) % 10);
+ ExportBuffer[cy+1][0] = '0' + ((i + 1) / 10);
+ }
+
+ cy += POS_HEIGHT*CountHeightOfElement(ELEM_SERIES_SUBCKT,
+ Prog.rungs[i]);
+ cy += POS_HEIGHT;
+ }
+ cy -= 2;
+ DrawEndRung(NULL, 5, cy);
+
+ FILE *f = fopen(file, "w");
+ if(!f) {
+ Error(_("Couldn't open '%s'\n"), f);
+ return;
+ }
+
+ fprintf(f, "LDmicro export text\n");
+
+ if(Prog.mcu) {
+ fprintf(f, "for '%s', %.6f MHz crystal, %.1f ms cycle time\n\n",
+ Prog.mcu->mcuName, Prog.mcuClock/1e6, Prog.cycleTime/1e3);
+ } else {
+ fprintf(f, "no MCU assigned, %.6f MHz crystal, %.1f ms cycle time\n\n",
+ Prog.mcuClock/1e6, Prog.cycleTime/1e3);
+ }
+
+ fprintf(f, "\nLADDER DIAGRAM:\n\n");
+
+ for(i = 0; i < totalHeight; i++) {
+ ExportBuffer[i][4] = '|';
+ fprintf(f, "%s\n", ExportBuffer[i]);
+ CheckFree(ExportBuffer[i]);
+ }
+ CheckFree(ExportBuffer);
+ ExportBuffer = NULL;
+
+ fprintf(f, _("\n\nI/O ASSIGNMENT:\n\n"));
- // fprintf(f, _(" Name | Type | Pin\n"));
- // fprintf(f, " ----------------------------+--------------------+------\n");
- // for(i = 0; i < Prog.io.count; i++) {
- // char b[1024];
- // memset(b, '\0', sizeof(b));
+ fprintf(f, _(" Name | Type | Pin\n"));
+ fprintf(f, " ----------------------------+--------------------+------\n");
+ for(i = 0; i < Prog.io.count; i++) {
+ char b[1024];
+ memset(b, '\0', sizeof(b));
- // PlcProgramSingleIo *io = &Prog.io.assignment[i];
- // char *type = IoTypeToString(io->type);
- // char pin[MAX_NAME_LEN];
+ PlcProgramSingleIo *io = &Prog.io.assignment[i];
+ char *type = IoTypeToString(io->type);
+ char pin[MAX_NAME_LEN];
- // PinNumberForIo(pin, io);
+ PinNumberForIo(pin, io);
- // sprintf(b, " | | %s\n",
- // pin);
+ sprintf(b, " | | %s\n",
+ pin);
- // memcpy(b+2, io->name, strlen(io->name));
- // memcpy(b+31, type, strlen(type));
- // fprintf(f, "%s", b);
- // }
+ memcpy(b+2, io->name, strlen(io->name));
+ memcpy(b+31, type, strlen(type));
+ fprintf(f, "%s", b);
+ }
- // fclose(f);
+ fclose(f);
- // // we may have trashed the grid tables a bit; a repaint will fix that
- // InvalidateRect(MainWindow, NULL, FALSE);
+ // we may have trashed the grid tables a bit; a repaint will fix that
+ InvalidateRect(MainWindow, NULL, FALSE);
}
//-----------------------------------------------------------------------------
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index d531a68..8bf490f 100644
--- a/ldmicro/includes/ldmicro.h
+++ b/ldmicro/includes/ldmicro.h
@@ -780,15 +780,14 @@ void WriteIhex(FILE *f, BYTE b);
void FinishIhex(FILE *f);
char *IoTypeToString(int ioType);
void PinNumberForIo(char *dest, PlcProgramSingleIo *io);
-HWND CreateWindowClient(DWORD exStyle, char *className, char *windowName,
- DWORD style, int x, int y, int width, int height, HWND parent,
- HMENU menu, HINSTANCE instance, void *param);
+HWID CreateWindowClient(GtkWindowType wType, GdkWindowTypeHint wthint, char *windowName,
+ int x, int y, int width, int height, HWND parent);
void MakeComponentListClass(void);
void MakeNamingListClass(void);
void MakeDialogBoxClass(void);
-void NiceFont(HWND h);
-void FixedFont(HWND h);
+void NiceFont(HWID h);
+void FixedFont(HWID h);
void CompileSuccessfulMessage(char *str);
extern BOOL RunningInBatchMode;
extern HFONT MyNiceFont;
diff --git a/ldmicro/iolist.cpp b/ldmicro/iolist.cpp
index 33ec2d9..f20b2f7 100644
--- a/ldmicro/iolist.cpp
+++ b/ldmicro/iolist.cpp
@@ -396,25 +396,20 @@ void SaveIoListToFile(FILE *f)
//-----------------------------------------------------------------------------
static gboolean AnalogSliderDialogKeyboardProc(GtkWidget* widget, GdkEventKey* event, gpointer name)
{
- // g_print("key click!\n");
-
SWORD v = (SWORD)gtk_range_get_value(GTK_RANGE(AnalogSliderTrackbar));
SetAdcShadow((char*)name, v);
if (AnalogSliderDone == TRUE || AnalogSliderCancel == TRUE)
{
- gtk_widget_destroy (AnalogSliderTrackbar);
- gtk_widget_destroy (AnalogSliderMain);
+ DestroyWindow (AnalogSliderMain);
return FALSE;
}
if (event->keyval == GDK_KEY_Return){
- gtk_widget_destroy (AnalogSliderTrackbar);
- gtk_widget_destroy (AnalogSliderMain);
+ DestroyWindow (AnalogSliderMain);
AnalogSliderDone = TRUE;
}
else if (event->keyval == GDK_KEY_Escape){
- gtk_widget_destroy (AnalogSliderTrackbar);
- gtk_widget_destroy (AnalogSliderMain);
+ DestroyWindow (AnalogSliderMain);
AnalogSliderDone = TRUE;
AnalogSliderCancel = TRUE;
}
@@ -424,12 +419,10 @@ static gboolean AnalogSliderDialogKeyboardProc(GtkWidget* widget, GdkEventKey* e
static gboolean AnalogSliderDialogMouseProc(GtkWidget *widget, GdkEventButton *event, gpointer name)
{
- // g_print("mouse click! %i, %i\n", event->button, event->type == GDK_BUTTON_PRESS);
SWORD v = (SWORD)gtk_range_get_value(GTK_RANGE(AnalogSliderTrackbar));
SetAdcShadow((char*)name, v);
if (event->button == 1 && event->type == GDK_BUTTON_RELEASE){
- gtk_widget_destroy (AnalogSliderTrackbar);
- gtk_widget_destroy (AnalogSliderMain);
+ DestroyWindow (AnalogSliderMain);
AnalogSliderDone = TRUE;
}
@@ -438,7 +431,6 @@ static gboolean AnalogSliderDialogMouseProc(GtkWidget *widget, GdkEventButton *e
void AnalogSliderUpdateProc (GtkRange *range, GtkScrollType step, gpointer name)
{
- // g_print("dlide bar adj\n");
SWORD v = (SWORD)gtk_range_get_value(GTK_RANGE(AnalogSliderTrackbar));
SetAdcShadow((char*)name, v);
}
@@ -449,9 +441,6 @@ void AnalogSliderUpdateProc (GtkRange *range, GtkScrollType step, gpointer name)
//-----------------------------------------------------------------------------
void ShowAnalogSliderPopup(char *name)
{
- // POINT pt;
- // GetCursorPos(&pt);
-
SWORD currentVal = GetAdcShadow(name);
SWORD maxVal;
@@ -464,119 +453,147 @@ void ShowAnalogSliderPopup(char *name)
Error(_("No ADC or ADC not supported for selected micro."));
return;
}
-
- // int x, y;
- // gtk_window_get_position(GTK_WINDOW(MainWindow), &x, &y);
+
int left = GLOBAL_mouse_last_clicked_x - 10;
// try to put the slider directly under the cursor (though later we might
// realize that that would put the popup off the screen)
int top = GLOBAL_mouse_last_clicked_y - (15 + (73*currentVal)/maxVal);
- // RECT r;
- // SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
+ int x, y;
+ gdk_window_get_origin (gtk_widget_get_window (view), &x, &y);
- // if(top + 110 >= r.bottom) {
- // top = r.bottom - 110;
- // }
- if(top < 0) top = 100;
- if(left < 0) left = 100;
+ if(top < 0) top = y + 10;
+ if(left < 0) left = x + 20;
- if (!GTK_IS_WINDOW(AnalogSliderMain))
- {
- AnalogSliderMain = gtk_window_new(GTK_WINDOW_POPUP);
- gtk_window_set_title(GTK_WINDOW(AnalogSliderMain), "I/O Pin");
- gtk_window_resize (GTK_WINDOW(AnalogSliderMain), 30, 100);
- gtk_window_move(GTK_WINDOW(AnalogSliderMain), left, top);
- }
-
- if (!GTK_IS_SCALE(AnalogSliderTrackbar))
- {
- AnalogSliderTrackbar = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
- 0,
- maxVal,
- 1);
- }
+ if (GTK_IS_WINDOW(AnalogSliderMain))
+ return;
+ AnalogSliderMain = gtk_window_new(GTK_WINDOW_POPUP);
+ gtk_window_set_title(GTK_WINDOW(AnalogSliderMain), _("I/O Pin"));
+ gtk_window_resize (GTK_WINDOW(AnalogSliderMain), 30, 100);
+ gtk_window_move(GTK_WINDOW(AnalogSliderMain), left, top);
+
+ AnalogSliderTrackbar = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
+ 0,
+ maxVal,
+ 1);
+
gtk_range_set_value (GTK_RANGE(AnalogSliderTrackbar), currentVal);
- // gtk_scale_add_mark (GTK_SCALE(AnalogSliderTrackbar), (maxVal + 1)/8, GTK_POS_LEFT, NULL);
-
- // AnalogSliderMain = CreateWindowClient(0, "LDmicroAnalogSlider", "I/O Pin",
- // WS_VISIBLE | WS_POPUP | WS_DLGFRAME,
- // left, top, 30, 100, NULL, NULL, Instance, NULL);
-
- // AnalogSliderTrackbar = CreateWindowEx(0, TRACKBAR_CLASS, "", WS_CHILD |
- // TBS_AUTOTICKS | TBS_VERT | TBS_TOOLTIPS | WS_CLIPSIBLINGS | WS_VISIBLE,
- // 0, 0, 30, 100, AnalogSliderMain, NULL, Instance, NULL);
- // SendMessage(AnalogSliderTrackbar, TBM_SETRANGE, FALSE,
- // MAKELONG(0, maxVal));
- // SendMessage(AnalogSliderTrackbar, TBM_SETTICFREQ, (maxVal + 1)/8, 0);
- // SendMessage(AnalogSliderTrackbar, TBM_SETPOS, TRUE, currentVal);
-
- // EnableWindow(MainWindow, FALSE);
- // ShowWindow(AnalogSliderMain, TRUE);
gtk_container_add(GTK_CONTAINER(AnalogSliderMain), AnalogSliderTrackbar);
// SetFocus(AnalogSliderTrackbar);
gtk_window_set_focus_visible (GTK_WINDOW(AnalogSliderMain), TRUE);
gtk_window_set_keep_above (GTK_WINDOW(AnalogSliderMain), TRUE);
- // gtk_window_set_focus (, AnalogSliderTrackbar);
+ gtk_window_set_focus (GTK_WINDOW(AnalogSliderMain), AnalogSliderTrackbar);
- g_signal_connect (AnalogSliderMain, "key-press-event",
+ g_signal_connect (GTK_RANGE(AnalogSliderTrackbar), "key-press-event",
G_CALLBACK(AnalogSliderDialogKeyboardProc), (PVOID)name);
g_signal_connect (GTK_RANGE(AnalogSliderTrackbar), "button-release-event",
G_CALLBACK (AnalogSliderDialogMouseProc), (PVOID)name);
- g_signal_connect (GTK_SCALE(AnalogSliderTrackbar), "move-slider",
+ g_signal_connect (GTK_RANGE(AnalogSliderTrackbar), "value-changed",
G_CALLBACK (AnalogSliderUpdateProc), (PVOID)name);
gtk_widget_show_all(AnalogSliderMain);
AnalogSliderDone = FALSE;
AnalogSliderCancel = FALSE;
-
- // SWORD orig = GetAdcShadow(name);
-
+
// ListView_RedrawItems(IoList, 0, Prog.io.count - 1);
}
//-----------------------------------------------------------------------------
// Window proc for the contacts dialog box
//-----------------------------------------------------------------------------
-// static LRESULT CALLBACK IoDialogProc(HWND hwnd, UINT msg, WPARAM wParam,
-// LPARAM lParam)
-// {
-// switch (msg) {
-// case WM_COMMAND: {
-// HWND h = (HWND)lParam;
-// if(h == OkButton && wParam == BN_CLICKED) {
-// DialogDone = TRUE;
-// } else if(h == CancelButton && wParam == BN_CLICKED) {
-// DialogDone = TRUE;
-// DialogCancel = TRUE;
-// } else if(h == PinList && HIWORD(wParam) == LBN_DBLCLK) {
-// DialogDone = TRUE;
-// }
-// break;
-// }
-
-// case WM_CLOSE:
-// case WM_DESTROY:
-// DialogDone = TRUE;
-// DialogCancel = TRUE;
-// return 1;
-
-// default:
-// return DefWindowProc(hwnd, msg, wParam, lParam);
-// }
-
-// return 1;
-// }
+static void IoDialogProc(BOOL DialogDone, int item)
+{
+ if(DialogDone)
+ {
+ char pin[16];
+ ITLIST iter;
+
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PinList));
+ gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
+
+ if(gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ GValue valproc = G_VALUE_INIT;
+
+ gtk_tree_model_get_value (gtk_tree_view_get_model (GTK_TREE_VIEW(PinList)),
+ &iter, 0, &valproc);
+ gchar* str = (char*)g_value_get_string(&valproc);
+ strcpy(pin, str);
+ g_free(str);
+ }
+ else
+ strcpy(pin, _("(no pin)"));
+
+ if(strcmp(pin, _("(no pin)"))==0)
+ {
+ int i;
+ for(i = 0; i < IoSeenPreviouslyCount; i++) {
+ if(strcmp(IoSeenPreviously[i].name,
+ Prog.io.assignment[item].name)==0)
+ {
+ IoSeenPreviously[i].pin = NO_PIN_ASSIGNED;
+ }
+ }
+ Prog.io.assignment[item].pin = NO_PIN_ASSIGNED;
+ }
+ else
+ {
+ Prog.io.assignment[item].pin = atoi(pin);
+ // Only one name can be bound to each pin; make sure that there's
+ // not another entry for this pin in the IoSeenPreviously list,
+ // that might get used if the user creates a new pin with that
+ // name.
+ int i;
+ for(i = 0; i < IoSeenPreviouslyCount; i++) {
+ if(IoSeenPreviously[i].pin == atoi(pin)) {
+ IoSeenPreviously[i].pin = NO_PIN_ASSIGNED;
+ }
+ }
+ }
+ RefreshControlsToSettings();
+ }
+
+ DestroyWindow(IoDialog);
+}
+
+void IoDialogRowActivateProc(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
+{
+ IoDialogProc(TRUE, GPOINTER_TO_INT(user_data));
+}
+
+void IoDialogCancelProc(HWID widget, gpointer data)
+{
+ IoDialogProc(FALSE, GPOINTER_TO_INT(data));
+}
+
+void IoDialogOkProc(HWID widget, gpointer data)
+{
+ IoDialogProc(TRUE, GPOINTER_TO_INT(data));
+}
+
+static gboolean IoDialogKeyPressProc(HWID widget, GdkEventKey* event, gpointer data)
+{
+ if (event -> keyval == GDK_KEY_Return)
+ {
+ IoDialogProc(TRUE, GPOINTER_TO_INT(data));
+ }
+ else if (event -> keyval == GDK_KEY_Escape)
+ {
+ IoDialogProc(FALSE, GPOINTER_TO_INT(data));
+ }
+
+ return FALSE;
+}
//-----------------------------------------------------------------------------
// Create our window class; nothing exciting.
//-----------------------------------------------------------------------------
-static BOOL MakeWindowClass()
-{
+// static BOOL MakeWindowClass()
+// {
// WNDCLASSEX wc;
// memset(&wc, 0, sizeof(wc));
// wc.cbSize = sizeof(wc);
@@ -595,194 +612,166 @@ static BOOL MakeWindowClass()
// IMAGE_ICON, 16, 16, 0);
// return RegisterClassEx(&wc);
-}
+// }
-static void MakeControls(void)
+static void MakeControls(HWID Dialog)
{
-// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Assign:"),
-// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
-// 6, 1, 80, 17, IoDialog, NULL, Instance, NULL);
-// NiceFont(textLabel);
-
-// PinList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTBOX, "",
-// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | WS_VSCROLL |
-// LBS_NOTIFY, 6, 18, 95, 320, IoDialog, NULL, Instance, NULL);
-// FixedFont(PinList);
-
-// OkButton = CreateWindowEx(0, WC_BUTTON, _("OK"),
-// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON,
-// 6, 325, 95, 23, IoDialog, NULL, Instance, NULL);
-// NiceFont(OkButton);
-
-// CancelButton = CreateWindowEx(0, WC_BUTTON, _("Cancel"),
-// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE,
-// 6, 356, 95, 23, IoDialog, NULL, Instance, NULL);
-// NiceFont(CancelButton);
+ HLIST IoPinList = (GtkTreeModel*)gtk_list_store_new (1, G_TYPE_STRING);
+
+ PinList = gtk_tree_view_new_with_model (GTK_TREE_MODEL(IoPinList));
+ HTVC column = gtk_tree_view_column_new_with_attributes(_("Assign:"),
+ gtk_cell_renderer_text_new(),
+ "text", 0,
+ NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(PinList), column);
+ FixedFont(PinList);
+
+ OkButton = gtk_button_new_with_label (_("OK"));
+ NiceFont(OkButton);
+
+ CancelButton = gtk_button_new_with_label (_("Cancel"));
+ NiceFont(CancelButton);
+
+ /// Add list to scrolled window to enable scrolling
+ HWID PinScroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (PinScroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_ALWAYS);
+ gtk_widget_set_hexpand(GTK_WIDGET(PinScroll), TRUE);
+ gtk_widget_set_vexpand(GTK_WIDGET(PinScroll), TRUE);
+
+ gtk_container_add (GTK_CONTAINER(PinScroll), PinList);
+
+ /// Pack all the widgets into main window
+ HWID PinBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ gtk_box_pack_start(GTK_BOX(PinBox), PinScroll, FALSE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(PinBox), OkButton, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(PinBox), CancelButton, FALSE, FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(Dialog), PinBox);
}
void ShowIoDialog(int item)
{
-// if(!Prog.mcu) {
-// MessageBox(MainWindow,
-// _("No microcontroller has been selected. You must select a "
-// "microcontroller before you can assign I/O pins.\r\n\r\n"
-// "Select a microcontroller under the Settings menu and try "
-// "again."), _("I/O Pin Assignment"), MB_OK | MB_ICONWARNING);
-// return;
-// }
-
-// if(Prog.mcu->whichIsa == ISA_ANSIC) {
-// Error(_("Can't specify I/O assignment for ANSI C target; compile and "
-// "see comments in generated source code."));
-// return;
-// }
-
-// if(Prog.mcu->whichIsa == ISA_INTERPRETED) {
-// Error(_("Can't specify I/O assignment for interpretable target; see "
-// "comments in reference implementation of interpreter."));
-// return;
-// }
-
-// if(Prog.io.assignment[item].name[0] != 'X' &&
-// Prog.io.assignment[item].name[0] != 'Y' &&
-// Prog.io.assignment[item].name[0] != 'A')
-// {
-// Error(_("Can only assign pin number to input/output pins (Xname or "
-// "Yname or Aname)."));
-// return;
-// }
-
-// if(Prog.io.assignment[item].name[0] == 'A' && Prog.mcu->adcCount == 0) {
-// Error(_("No ADC or ADC not supported for this micro."));
-// return;
-// }
-
-// if(strcmp(Prog.io.assignment[item].name+1, "new")==0) {
-// Error(_("Rename I/O from default name ('%s') before assigning "
-// "MCU pin."), Prog.io.assignment[item].name);
-// return;
-// }
-
-// MakeWindowClass();
-
-// // We need the TOOLWINDOW style, or else the window will be forced to
-// // a minimum width greater than our current width. And without the
-// // APPWINDOW style, it becomes impossible to get the window back (by
-// // Alt+Tab or taskbar).
-// IoDialog = CreateWindowClient(WS_EX_TOOLWINDOW | WS_EX_APPWINDOW,
-// "LDmicroIo", _("I/O Pin"),
-// WS_OVERLAPPED | WS_SYSMENU,
-// 100, 100, 107, 387, NULL, NULL, Instance, NULL);
-
-// MakeControls();
-
-// SendMessage(PinList, LB_ADDSTRING, 0, (LPARAM)_("(no pin)"));
-// int i;
-// for(i = 0; i < Prog.mcu->pinCount; i++) {
-// int j;
-// for(j = 0; j < Prog.io.count; j++) {
-// if(j == item) continue;
-// if(Prog.io.assignment[j].pin == Prog.mcu->pinInfo[i].pin) {
-// goto cant_use_this_io;
-// }
-// }
-
-// if(UartFunctionUsed() && Prog.mcu &&
-// ((Prog.mcu->pinInfo[i].pin == Prog.mcu->uartNeeds.rxPin) ||
-// (Prog.mcu->pinInfo[i].pin == Prog.mcu->uartNeeds.txPin)))
-// {
-// goto cant_use_this_io;
-// }
-
-// if(PwmFunctionUsed() &&
-// Prog.mcu->pinInfo[i].pin == Prog.mcu->pwmNeedsPin)
-// {
-// goto cant_use_this_io;
-// }
-
-// if(Prog.io.assignment[item].name[0] == 'A') {
-// for(j = 0; j < Prog.mcu->adcCount; j++) {
-// if(Prog.mcu->adcInfo[j].pin == Prog.mcu->pinInfo[i].pin) {
-// // okay; we know how to connect it up to the ADC
-// break;
-// }
-// }
-// if(j == Prog.mcu->adcCount) {
-// goto cant_use_this_io;
-// }
-// }
-
-// char buf[40];
-// if(Prog.mcu->pinCount <= 21) {
-// sprintf(buf, "%3d %c%c%d", Prog.mcu->pinInfo[i].pin,
-// Prog.mcu->portPrefix, Prog.mcu->pinInfo[i].port,
-// Prog.mcu->pinInfo[i].bit);
-// } else {
-// sprintf(buf, "%3d %c%c%d", Prog.mcu->pinInfo[i].pin,
-// Prog.mcu->portPrefix, Prog.mcu->pinInfo[i].port,
-// Prog.mcu->pinInfo[i].bit);
-// }
-// SendMessage(PinList, LB_ADDSTRING, 0, (LPARAM)buf);
-// cant_use_this_io:;
-// }
-
-// EnableWindow(MainWindow, FALSE);
-// ShowWindow(IoDialog, TRUE);
-// SetFocus(PinList);
-
-// 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(IoDialog, &msg)) continue;
-// TranslateMessage(&msg);
-// DispatchMessage(&msg);
-// }
-
-// if(!DialogCancel) {
-// int sel = SendMessage(PinList, LB_GETCURSEL, 0, 0);
-// char pin[16];
-// SendMessage(PinList, LB_GETTEXT, (WPARAM)sel, (LPARAM)pin);
-// if(strcmp(pin, _("(no pin)"))==0) {
-// int i;
-// for(i = 0; i < IoSeenPreviouslyCount; i++) {
-// if(strcmp(IoSeenPreviously[i].name,
-// Prog.io.assignment[item].name)==0)
-// {
-// IoSeenPreviously[i].pin = NO_PIN_ASSIGNED;
-// }
-// }
-// Prog.io.assignment[item].pin = NO_PIN_ASSIGNED;
-// } else {
-// Prog.io.assignment[item].pin = atoi(pin);
-// // Only one name can be bound to each pin; make sure that there's
-// // not another entry for this pin in the IoSeenPreviously list,
-// // that might get used if the user creates a new pin with that
-// // name.
-// int i;
-// for(i = 0; i < IoSeenPreviouslyCount; i++) {
-// if(IoSeenPreviously[i].pin == atoi(pin)) {
-// IoSeenPreviously[i].pin = NO_PIN_ASSIGNED;
-// }
-// }
-// }
-// }
-
-// EnableWindow(MainWindow, TRUE);
-// DestroyWindow(IoDialog);
-// return;
+ if(!Prog.mcu) {
+ MessageBox(MainWindow,
+ _("No microcontroller has been selected. You must select a "
+ "microcontroller before you can assign I/O pins.\r\n\r\n"
+ "Select a microcontroller under the Settings menu and try "
+ "again."), _("I/O Pin Assignment"), MB_OK | MB_ICONWARNING);
+ return;
+ }
+
+ if(Prog.mcu->whichIsa == ISA_ANSIC) {
+ Error(_("Can't specify I/O assignment for ANSI C target; compile and "
+ "see comments in generated source code."));
+ return;
+ }
+
+ if(Prog.mcu->whichIsa == ISA_INTERPRETED) {
+ Error(_("Can't specify I/O assignment for interpretable target; see "
+ "comments in reference implementation of interpreter."));
+ return;
+ }
+
+ if(Prog.io.assignment[item].name[0] != 'X' &&
+ Prog.io.assignment[item].name[0] != 'Y' &&
+ Prog.io.assignment[item].name[0] != 'A')
+ {
+ Error(_("Can only assign pin number to input/output pins (Xname or "
+ "Yname or Aname)."));
+ return;
+ }
+
+ if(Prog.io.assignment[item].name[0] == 'A' && Prog.mcu->adcCount == 0) {
+ Error(_("No ADC or ADC not supported for this micro."));
+ return;
+ }
+
+ if(strcmp(Prog.io.assignment[item].name+1, "new")==0) {
+ Error(_("Rename I/O from default name ('%s') before assigning "
+ "MCU pin."), Prog.io.assignment[item].name);
+ return;
+ }
+
+ // We need the TOOLWINDOW style, or else the window will be forced to
+ // a minimum width greater than our current width. And without the
+ // APPWINDOW style, it becomes impossible to get the window back (by
+ // Alt+Tab or taskbar).
+ IoDialog = CreateWindowClient(GTK_WINDOW_TOPLEVEL, GDK_WINDOW_TYPE_HINT_MENU, _("I/O Pin"),
+ 100, 100, 107, 387, NULL);
+
+ MakeControls(IoDialog);
+
+ ITLIST iter;
+ GValue val = G_VALUE_INIT;
+ g_value_init (&val, G_TYPE_STRING);
+
+ HLIST model = gtk_tree_view_get_model (GTK_TREE_VIEW(PinList));
+
+ gtk_tree_model_get_iter_first (GTK_TREE_MODEL(model), &iter);
+
+ gtk_list_store_append (GTK_LIST_STORE(model), &iter);
+
+ g_value_set_string(&val, _("(no pin)"));
+ gtk_list_store_set_value (GTK_LIST_STORE(model), &iter, 0, &val);
+
+ int i;
+ for(i = 0; i < Prog.mcu->pinCount; i++) {
+ int j;
+ for(j = 0; j < Prog.io.count; j++) {
+ if(j == item) continue;
+ if(Prog.io.assignment[j].pin == Prog.mcu->pinInfo[i].pin) {
+ goto cant_use_this_io;
+ }
+ }
+
+ if(UartFunctionUsed() && Prog.mcu &&
+ ((Prog.mcu->pinInfo[i].pin == Prog.mcu->uartNeeds.rxPin) ||
+ (Prog.mcu->pinInfo[i].pin == Prog.mcu->uartNeeds.txPin)))
+ {
+ goto cant_use_this_io;
+ }
+
+ if(PwmFunctionUsed() &&
+ Prog.mcu->pinInfo[i].pin == Prog.mcu->pwmNeedsPin)
+ {
+ goto cant_use_this_io;
+ }
+
+ if(Prog.io.assignment[item].name[0] == 'A') {
+ for(j = 0; j < Prog.mcu->adcCount; j++) {
+ if(Prog.mcu->adcInfo[j].pin == Prog.mcu->pinInfo[i].pin) {
+ // okay; we know how to connect it up to the ADC
+ break;
+ }
+ }
+ if(j == Prog.mcu->adcCount) {
+ goto cant_use_this_io;
+ }
+ }
+
+ char buf[40];
+ if(Prog.mcu->pinCount <= 21) {
+ sprintf(buf, "%3d %c%c%d", Prog.mcu->pinInfo[i].pin,
+ Prog.mcu->portPrefix, Prog.mcu->pinInfo[i].port,
+ Prog.mcu->pinInfo[i].bit);
+ } else {
+ sprintf(buf, "%3d %c%c%d", Prog.mcu->pinInfo[i].pin,
+ Prog.mcu->portPrefix, Prog.mcu->pinInfo[i].port,
+ Prog.mcu->pinInfo[i].bit);
+ }
+ gtk_list_store_append (GTK_LIST_STORE(model), &iter);
+ g_value_set_string(&val, buf);
+ gtk_list_store_set_value (GTK_LIST_STORE(model), &iter, 0, &val);
+cant_use_this_io:;
+ }
+
+ gtk_widget_show_all(IoDialog);
+
+ g_signal_connect (PinList, "row_activated", G_CALLBACK (IoDialogRowActivateProc), GINT_TO_POINTER(item));
+ g_signal_connect (IoDialog, "key_press_event", G_CALLBACK (IoDialogKeyPressProc), GINT_TO_POINTER(item));
+ g_signal_connect (CancelButton, "clicked", G_CALLBACK (IoDialogCancelProc), GINT_TO_POINTER(item));
+ g_signal_connect (OkButton, "clicked", G_CALLBACK (IoDialogOkProc), GINT_TO_POINTER(item));
}
//-----------------------------------------------------------------------------
@@ -820,7 +809,6 @@ void IoListProc(NMHDR *h)
g_value_set_string(&val, (const char*)&IO_value_holder);
gtk_list_store_set_value (GTK_LIST_STORE(h->hlistFrom), h->hlistIter, LV_IO_PIN, &val);
}
-
/// case LV_IO_TYPE:
char *s = IoTypeToString(Prog.io.assignment[item].type);
@@ -908,10 +896,10 @@ void IoListProc(NMHDR *h)
ShowAnalogSliderPopup(name);
}
} else {
- // UndoRemember();
- // ShowIoDialog(h->item.iItem);
- // ProgramChanged();
- // InvalidateRect(MainWindow, NULL, FALSE);
+ UndoRemember();
+ ShowIoDialog(h->item.iItem);
+ ProgramChanged();
+ InvalidateRect(MainWindow, NULL, FALSE);
}
break;
}
diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp
index db4d588..d2b54b5 100644
--- a/ldmicro/ldmicro.cpp
+++ b/ldmicro/ldmicro.cpp
@@ -646,6 +646,8 @@ void LD_WM_Close_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)
/* Handles:
* WM_CLOSE
*/
+
+ CheckSaveUserCancels();
FreezeWindowPos(MainWindow);
FreezeDWORD(IoListHeight);
@@ -806,18 +808,18 @@ gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data)
return FALSE;
}
-gboolean LD_WM_Destroy_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)
+void LD_WM_Destroy_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
/* Handles:
* WM_DESTROY
*/
- // if(CheckSaveUserCancels()) break;
+ CheckSaveUserCancels();
- // PostQuitMessage(0);
- // return 1;
+ FreezeWindowPos(MainWindow);
+ FreezeDWORD(IoListHeight);
- return FALSE;
+ gtk_main_quit();
}
gboolean LD_WM_Size_call(GtkWidget *widget, GdkEvent *event, gpointer user_data)
@@ -854,15 +856,15 @@ void LD_WM_Notify_Row_Activate_call(GtkTreeView *tree_view, GtkTreePath *path, G
* WM_NOTIFY
*/
- g_print("Row activated!\n");
-
+ // g_print("Row activated!\n");
+
int *ip = gtk_tree_path_get_indices ( path );
NMHDR h;
h.code = LVN_ITEMACTIVATE;
h.item.iItem = ip[0];
h.hlistFrom = IoList;
-
+
IoListProc(&h);
}
@@ -874,28 +876,27 @@ void LD_WM_Notify_Cursor_Change_call(GtkTreeView *tree_view, gpointer user_data)
ITLIST iter;
- BOOL empty = !gtk_tree_model_get_iter_first (IoList, &iter);
+ // BOOL empty = !gtk_tree_model_get_iter_first (IoList, &iter);
// g_print("empty = %i\n", (empty == TRUE) );
HLIST pTreeModel;
int *ip;
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
-
if(gtk_tree_selection_get_selected (selection, &pTreeModel, &iter))
{
GtkTreePath *path = gtk_tree_model_get_path ( pTreeModel , &iter ) ;
ip = gtk_tree_path_get_indices ( path );
}
else
- gtk_tree_model_get_iter_first (IoList, &iter);
+ if(!gtk_tree_model_get_iter_first (IoList, &iter))
+ return;
NMHDR h;
h.code = LVN_GETDISPINFO;
h.item.iItem = (ip == NULL) ? 0 : ip[0];
h.hlistFrom = IoList;
h.hlistIter = &iter;
-
IoListProc(&h);
}
@@ -1173,7 +1174,8 @@ int main(int argc, char** argv)
IMAGE_ICON, 32, 32, 0));
/// Make main window - end
- // MakeMainWindowMenus();
+ MakeMainWindowMenus();
+ MakeDialogBoxClass();
InitForDrawing();
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 28116b2..ce0b812 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -182,7 +182,7 @@ typedef struct FontTag {
int nOrientation;
int fnWeight;
DWORD fdwItalic;
- LPCTSTR lpszFace;
+ LPTSTR lpszFace;
} *HFONT, FONT;
typedef struct tagLOGBRUSH {
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 5b87a60..d7248b7 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -282,6 +282,9 @@ HANDLE GetStockObject(int fnObject)
void SelectObject(HCRDC hcr, HFONT hfont)
{
+ if (hcr ==NULL)
+ return;
+
cairo_select_font_face(hcr, hfont->lpszFace,
hfont->fdwItalic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
hfont->fnWeight == FW_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);
@@ -313,19 +316,23 @@ HBRUSH CreateBrushIndirect(PLOGBRUSH plb)
HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight,
DWORD fdwItalic, LPCTSTR lpszFace)
{
- HFONT font = new FONT;
+ HFONT font = (HFONT)malloc(strlen(lpszFace) + 1 + sizeof(FONT));
font->nHeight = nHeight;
font->nWidth = nWidth;
font->nOrientation = nOrientation;
font->fnWeight = fnWeight;
font->fdwItalic = fdwItalic;
- font->lpszFace = lpszFace;
-
+ font->lpszFace = (char*)malloc(strlen(lpszFace)+1);
+ strcpy(font->lpszFace, lpszFace);
+
return font;
}
void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol)
{
+ if (hcr == NULL)
+ return;
+
gtk_widget_override_background_color(GTK_WIDGET(widget),
GTK_STATE_FLAG_NORMAL, &bkCol);
@@ -349,12 +356,18 @@ void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol)
void SetTextColor(HCRDC hcr, COLORREF color)
{
+ if (hcr == NULL)
+ return;
+
HdcCurrentTextColor = color;
gdk_cairo_set_source_rgba (hcr, &color);
}
void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, int cchString)
{
+ if (hcr == NULL)
+ return;
+
nYStart += 30;
cairo_text_extents_t extents;
@@ -419,6 +432,9 @@ BOOL InvalidateRect(HWID hWid, const RECT *lpRect, BOOL bErase)
int FillRect(HCRDC hDC, const RECT *lprc, HBRUSH hbr)
{
+ if (hDC == NULL)
+ return -1;
+
GDRECT gdrc;
RECT_to_GDRECT(lprc, &gdrc);
@@ -432,6 +448,9 @@ int FillRect(HCRDC hDC, const RECT *lprc, HBRUSH hbr)
BOOL PatBlt(HCRDC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD dwRop, HBRUSH hbr)
{
+ if (hdc == NULL)
+ return FALSE;
+
cairo_set_source_rgb(hdc, hbr->red, hbr->green, hbr->blue);
cairo_rectangle(hdc, nXLeft, nYLeft + 20, nWidth, nHeight);
cairo_stroke_preserve(hdc);
@@ -479,9 +498,6 @@ BOOL GetWindowRect(HWID hWid, PRECT pRect)
return TRUE;
}
-void DestroyWindow (GtkWidget* widget, gpointer data){
- gtk_widget_destroy (widget);
-}
UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, BOOL (*lpTimerFunc)(BOOL) )
{
@@ -512,3 +528,8 @@ BOOL KillTimer(HWID hWid, UINT uIDEvent)
return TRUE;
}
+
+void DestroyWindow (HWID widget)
+{
+ gtk_widget_destroy (widget);
+}
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 41b281f..b1a3d48 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -43,6 +43,11 @@
#define SB_THUMBTRACK 0x00000040
#define SB_THUMBPOSITION 0x00000080
+/// UART terminal flags
+#define WM_GETTEXT 0x00000001
+#define WM_SETTEXT 0x00000002
+#define WM_SETTEXT_END 0x00000004
+
/// List view flags
#define LVN_ITEMACTIVATE 0x00000001
#define LVN_GETDISPINFO 0x00000002
@@ -205,10 +210,6 @@ BOOL MoveWindow(
int nHeight,
BOOL bRepaint);
-void DestroyWindow (
- HWID widget,
- gpointer data);
-
BOOL GetWindowRect(
HWID hWid,
PRECT pRect);
@@ -223,4 +224,6 @@ BOOL KillTimer(
HWID hWid,
UINT uIDEvent);
+void DestroyWindow (HWID widget);
+
#endif \ No newline at end of file
diff --git a/ldmicro/lutdialog.cpp b/ldmicro/lutdialog.cpp
index 5c563eb..188b1a8 100644
--- a/ldmicro/lutdialog.cpp
+++ b/ldmicro/lutdialog.cpp
@@ -189,15 +189,15 @@ static void DestroyLutControls(void)
cout << "Exiting else of WasAsString" << "\n";
}
if (checkString){
- DestroyWindow(StringTextbox, NULL);
+ 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], NULL);
- DestroyWindow(ValuesLabel[i], NULL);
+ DestroyWindow(ValuesTextbox[i]);
+ DestroyWindow(ValuesLabel[i]);
cout << "Called DestroyWindow() for ValuesTextbox and ValuesLabels" << "\n";
}
}
@@ -431,7 +431,7 @@ gboolean LookUpTableKeyPress (HWID widget, GdkEventKey* event, gpointer data){
LookUpTableGetData(NULL, (gpointer) data);
}
else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (LutDialog, NULL);
+ DestroyWindow (LutDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
return FALSE;
@@ -445,7 +445,7 @@ void LutDialogMouseClick (HWID widget, gpointer data){
// Calls DestroyWindow
void LutCallDestroyWindow (HWID widget, gpointer data){
- DestroyWindow (LutDialog, NULL);
+ DestroyWindow (LutDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp
index 9e3770d..0deaf73 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -131,7 +131,6 @@ static int IoListSelectionPoint;
static BOOL IoListOutOfSync;
int IoListHeight;
int IoListTop;
-GtkTreeModel **IoListPtr = (GtkTreeModel**)GTK_TREE_MODEL (IoList);
// whether the simulation is running in real time
static BOOL RealTimeSimulationRunning;
@@ -940,9 +939,9 @@ void ToggleSimulationMode(void)
CheckMenuItem(SimulateMenu, SimulationModeMenu, MF_UNCHECKED);
- // if(UartFunctionUsed()) {
- // DestroyUartSimulationWindow();
- // }
+ if(UartFunctionUsed()) {
+ DestroyUartSimulationWindow();
+ }
}
UpdateMainWindowTitleBar();
@@ -970,9 +969,10 @@ void RefreshControlsToSettings(void)
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
- if(gtk_tree_selection_get_selected (selection, IoListPtr, &iter))
+ GtkTreeModel *IoModelPtr;
+ if(gtk_tree_selection_get_selected (selection, &IoModelPtr, &iter))
{
- GtkTreePath *path = gtk_tree_model_get_path ( *IoListPtr , &iter ) ;
+ GtkTreePath *path = gtk_tree_model_get_path ( IoModelPtr, &iter ) ;
ip = gtk_tree_path_get_indices ( path ) ;
i = ip[0];
IoListSelectionPoint = i;
@@ -986,6 +986,7 @@ void RefreshControlsToSettings(void)
h.code = LVN_GETDISPINFO;
h.hlistFrom = IoList;
+ gtk_tree_model_get_iter_first (GTK_TREE_MODEL(IoList), &iter);
for(i = 0; i < Prog.io.count; i++) {
gtk_list_store_append (GTK_LIST_STORE(IoList), &iter);
h.item.iItem = i;
@@ -1065,21 +1066,20 @@ void GenerateIoListDontLoseSelection(void)
int * i ;
IoListSelectionPoint = -1;
-
+
// GtkTreeSelection * tsel = gtk_tree_view_get_selection (tv);
// GtkTreeModel * tm ;
GtkTreePath * path ;
+ GtkTreeModel *IoModelPtr;
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
-
- if(gtk_tree_selection_get_selected (selection, IoListPtr, &iter))
+ if(gtk_tree_selection_get_selected (selection, &IoModelPtr, &iter))
{
- path = gtk_tree_model_get_path ( *IoListPtr , &iter ) ;
+ path = gtk_tree_model_get_path ( IoModelPtr , &iter ) ;
i = gtk_tree_path_get_indices ( path ) ;
IoListSelectionPoint = i[0];
}
-
// gtk_tree_model_iter_next (GTK_TREE_MODEL(IoList), iter);
// BOOL iter_v = gtk_list_store_iter_is_valid(GTK_LIST_STORE(IoList), iter);
// g_print("iter = %i\n", iter_v);
@@ -1095,7 +1095,6 @@ void GenerateIoListDontLoseSelection(void)
// can't just update the listview index; if I/O has been added then the
// new selection point might be out of range till we refill it
-
IoListOutOfSync = TRUE;
RefreshControlsToSettings();
}
@@ -1159,6 +1158,6 @@ void StopSimulation(void)
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED);
KillTimer(MainWindow, TIMER_SIMULATE);
-
+
UpdateMainWindowTitleBar();
} \ No newline at end of file
diff --git a/ldmicro/miscutil.cpp b/ldmicro/miscutil.cpp
index 167543a..f0f9aa8 100644
--- a/ldmicro/miscutil.cpp
+++ b/ldmicro/miscutil.cpp
@@ -204,10 +204,15 @@ void FinishIhex(FILE *f)
//-----------------------------------------------------------------------------
// Create a window with a given client area.
//-----------------------------------------------------------------------------
-HWND CreateWindowClient(DWORD exStyle, char *className, char *windowName,
- DWORD style, int x, int y, int width, int height, HWND parent,
- HMENU menu, HINSTANCE instance, void *param)
+HWID CreateWindowClient(GtkWindowType wType, GdkWindowTypeHint wthint, char *windowName,
+ int x, int y, int width, int height, HWND parent)
{
+ HWID h = gtk_window_new(wType);
+ gtk_window_set_title(GTK_WINDOW(h), windowName);
+ gtk_window_resize (GTK_WINDOW(h), width, height);
+ gtk_window_move(GTK_WINDOW(h), x, y);
+ gtk_window_set_type_hint (GTK_WINDOW(h), wthint);
+
// HWND h = CreateWindowEx(exStyle, className, windowName, style, x, y,
// width, height, parent, menu, instance, param);
@@ -218,16 +223,16 @@ HWND CreateWindowClient(DWORD exStyle, char *className, char *windowName,
// SetWindowPos(h, HWND_TOP, x, y, width, height, 0);
- return NULL;
+ return h;
}
//-----------------------------------------------------------------------------
// Window proc for the dialog boxes. This Ok/Cancel stuff is common to a lot
// of places, and there are no other callbacks from the children.
//-----------------------------------------------------------------------------
-static LRESULT CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam,
- LPARAM lParam)
-{
+// static LRESULT CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam,
+// LPARAM lParam)
+// {
// switch (msg) {
// case WM_NOTIFY:
// break;
@@ -253,8 +258,8 @@ static LRESULT CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam,
// return DefWindowProc(hwnd, msg, wParam, lParam);
// }
- return 1;
-}
+// return 1;
+// }
@@ -263,7 +268,19 @@ static LRESULT CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam,
//-----------------------------------------------------------------------------
void NiceFont(HWID h)
{
- // gtk_widget_override_font(GTK_WIDGET(h), pango_font_description_from_string("Times New Roman"));
+ GtkCssProvider *provider = gtk_css_provider_new ();
+
+ char *cssdata = new char[strlen(MyNiceFont->lpszFace) + 26];
+ int fontSize = 10;
+ sprintf(cssdata, "textview { font: %ipx %s; }", fontSize, MyNiceFont->lpszFace);
+
+ gtk_css_provider_load_from_data (provider, cssdata, -1, NULL);
+
+ delete cssdata;
+
+ gtk_style_context_add_provider (gtk_widget_get_style_context(h),
+ GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
+
// SendMessage(h, WM_SETFONT, (WPARAM)MyNiceFont, TRUE);
}
@@ -271,8 +288,21 @@ void NiceFont(HWID h)
// Set the font of a control to a pretty fixed-width font (typ. Lucida
// Console).
//-----------------------------------------------------------------------------
-void FixedFont(HWND h)
+void FixedFont(HWID h)
{
+ GtkCssProvider *provider = gtk_css_provider_new ();
+
+ char *cssdata = new char[strlen(MyFixedFont->lpszFace) + 26];
+ int fontSize = 10;
+ sprintf(cssdata, "textview { font: %ipx %s; }", fontSize, MyFixedFont->lpszFace);
+
+ gtk_css_provider_load_from_data (provider, cssdata, -1, NULL);
+
+ delete cssdata;
+
+ gtk_style_context_add_provider (gtk_widget_get_style_context(h),
+ GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
+
// SendMessage(h, WM_SETFONT, (WPARAM)MyFixedFont, TRUE);
}
@@ -300,15 +330,13 @@ void MakeDialogBoxClass(void)
// RegisterClassEx(&wc);
- // MyNiceFont = CreateFont(16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE,
- // ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- // FF_DONTCARE, "Tahoma");
+ MyNiceFont = CreateFont(16, 0, 0, FW_REGULAR, FALSE, "Tahoma");
+
// if(!MyNiceFont)
// MyNiceFont = (HFONT)GetStockObject(SYSTEM_FONT);
- // MyFixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE,
- // ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- // FF_DONTCARE, "Lucida Console");
+ MyFixedFont = CreateFont(14, 0, 0, FW_REGULAR, FALSE, "Lucida Console");
+
// if(!MyFixedFont)
// MyFixedFont = (HFONT)GetStockObject(SYSTEM_FONT);
}
diff --git a/ldmicro/resetdialog.cpp b/ldmicro/resetdialog.cpp
index 4fdb9cd..cbcfd30 100644
--- a/ldmicro/resetdialog.cpp
+++ b/ldmicro/resetdialog.cpp
@@ -95,7 +95,7 @@ void ResetDialogGetData (char* name){
}
strcpy (name+1, gtk_entry_get_text (GTK_ENTRY (NameTextbox)));
gtk_widget_set_sensitive (MainWindow, TRUE);
- DestroyWindow (ResetDialog, NULL);
+ DestroyWindow (ResetDialog);
}
// Mouse click callback
@@ -109,14 +109,14 @@ gboolean ResetDialogKeyPress (HWID widget, GdkEventKey* event, gpointer data){
ResetDialogGetData((char*)data);
}
else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (ResetDialog, NULL);
+ DestroyWindow (ResetDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
return FALSE;
}
void ResetCallDestroyWindow (HWID widget, gpointer data){
- DestroyWindow (ResetDialog, NULL);
+ DestroyWindow (ResetDialog);
gtk_widget_set_sensitive (MainWindow, TRUE);
}
diff --git a/ldmicro/simulate.cpp b/ldmicro/simulate.cpp
index 6b38896..0b3c206 100644
--- a/ldmicro/simulate.cpp
+++ b/ldmicro/simulate.cpp
@@ -89,8 +89,8 @@ static int IntPc;
// A window to allow simulation with the UART stuff (insert keystrokes into
// the program, view the output, like a terminal window).
-static HWND UartSimulationWindow;
-static HWND UartSimulationTextControl;
+static HWID UartSimulationWindow;
+static HWID UartSimulationTextControl;
static LONG_PTR PrevTextProc;
static int QueuedUartCharacter = -1;
@@ -837,17 +837,53 @@ void SimulationToggleContact(char *name)
//-----------------------------------------------------------------------------
// Intercept WM_CHAR messages that to the terminal simulation window so that
// we can redirect them to the PLC program.
+//
+// Ported: Read and write text fron the text view widget.
//-----------------------------------------------------------------------------
-// static LRESULT CALLBACK UartSimulationTextProc(HWND hwnd, UINT msg,
-// WPARAM wParam, LPARAM lParam)
-// {
-// if(msg == WM_CHAR) {
-// QueuedUartCharacter = (BYTE)wParam;
-// return 0;
-// }
-
-// return CallWindowProc((WNDPROC)PrevTextProc, hwnd, msg, wParam, lParam);
-// }
+static void UartSimulationTextProc(HWID hwid, UINT umsg, char *text, UINT uszbuf)
+{
+ switch(umsg)
+ {
+ case WM_SETTEXT:
+ {
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(hwid));
+ gtk_text_buffer_set_text (buffer, text, -1);
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW(hwid), buffer);
+
+ GtkTextIter end;
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW(hwid), &end, 0.2, FALSE, 1, 1);
+ break;
+ }
+ case WM_SETTEXT_END:
+ {
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(hwid));
+ gtk_text_buffer_insert_at_cursor (buffer, text, -1);
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW(hwid), buffer);
+
+ GtkTextIter end;
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW(hwid), &end, 0.2, FALSE, 1, 1);
+ break;
+ }
+ case WM_GETTEXT:
+ {
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(hwid));
+ GtkTextIter start, end;
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+
+ char *txtBuf = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+
+ strcpy(text, txtBuf);
+ strcat(text, "\0");
+ g_free(txtBuf);
+ break;
+ }
+ default:
+ break;
+ }
+}
//-----------------------------------------------------------------------------
// Pop up the UART simulation window; like a terminal window where the
@@ -856,61 +892,41 @@ void SimulationToggleContact(char *name)
//-----------------------------------------------------------------------------
void ShowUartSimulationWindow(void)
{
-// WNDCLASSEX wc;
-// memset(&wc, 0, sizeof(wc));
-// wc.cbSize = sizeof(wc);
-
-// wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC |
-// CS_DBLCLKS;
-// wc.lpfnWndProc = (WNDPROC)UartSimulationProc;
-// wc.hInstance = Instance;
-// wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
-// wc.lpszClassName = "LDmicroUartSimulationWindow";
-// wc.lpszMenuName = NULL;
-// wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-
-// RegisterClassEx(&wc);
-
-// DWORD TerminalX = 200, TerminalY = 200, TerminalW = 300, TerminalH = 150;
-
-// ThawDWORD(TerminalX);
-// ThawDWORD(TerminalY);
-// ThawDWORD(TerminalW);
-// ThawDWORD(TerminalH);
-
-// if(TerminalW > 800) TerminalW = 100;
-// if(TerminalH > 800) TerminalH = 100;
-
-// RECT r;
-// GetClientRect(GetDesktopWindow(), &r);
-// if(TerminalX >= (DWORD)(r.right - 10)) TerminalX = 100;
-// if(TerminalY >= (DWORD)(r.bottom - 10)) TerminalY = 100;
-
-// UartSimulationWindow = CreateWindowClient(WS_EX_TOOLWINDOW |
-// WS_EX_APPWINDOW, "LDmicroUartSimulationWindow",
-// "UART Simulation (Terminal)", WS_VISIBLE | WS_SIZEBOX,
-// TerminalX, TerminalY, TerminalW, TerminalH,
-// NULL, NULL, Instance, NULL);
-
-// UartSimulationTextControl = CreateWindowEx(0, WC_EDIT, "", WS_CHILD |
-// WS_CLIPSIBLINGS | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE |
-// WS_VSCROLL, 0, 0, TerminalW, TerminalH, UartSimulationWindow, NULL,
-// Instance, NULL);
-
-// HFONT fixedFont = CreateFont(14, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE,
-// ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
-// FF_DONTCARE, "Lucida Console");
-// if(!fixedFont)
-// fixedFont = (HFONT)GetStockObject(SYSTEM_FONT);
-
-// SendMessage((HWND)UartSimulationTextControl, WM_SETFONT, (WPARAM)fixedFont,
-// TRUE);
-
-// PrevTextProc = SetWindowLongPtr(UartSimulationTextControl,
-// GWLP_WNDPROC, (LONG_PTR)UartSimulationTextProc);
-
-// ShowWindow(UartSimulationWindow, TRUE);
-// SetFocus(MainWindow);
+ DWORD TerminalX = 200, TerminalY = 200, TerminalW = 300, TerminalH = 150;
+
+ ThawDWORD(TerminalX);
+ ThawDWORD(TerminalY);
+ ThawDWORD(TerminalW);
+ ThawDWORD(TerminalH);
+
+ if(TerminalW > 800) TerminalW = 100;
+ if(TerminalH > 800) TerminalH = 100;
+
+ UartSimulationWindow = CreateWindowClient(GTK_WINDOW_TOPLEVEL, GDK_WINDOW_TYPE_HINT_NORMAL,
+ "UART Simulation (Terminal)", TerminalX, TerminalY, TerminalW, TerminalH, NULL);
+ /// remove close button
+ gtk_window_set_deletable (GTK_WINDOW(UartSimulationWindow), FALSE);
+
+ UartSimulationTextControl = gtk_text_view_new();
+
+ gtk_widget_override_font(GTK_WIDGET(UartSimulationTextControl), pango_font_description_from_string("Lucida Console"));
+
+ /// Add text view into a scrolled window to enable scrolling functionality
+ HWID TextViewScroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (TextViewScroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_widget_set_hexpand(GTK_WIDGET(TextViewScroll), TRUE);
+ gtk_widget_set_vexpand(GTK_WIDGET(TextViewScroll), TRUE);
+
+ gtk_container_add (GTK_CONTAINER(TextViewScroll), UartSimulationTextControl);
+ gtk_container_add (GTK_CONTAINER(UartSimulationWindow), TextViewScroll);
+
+ gtk_widget_show_all(UartSimulationWindow);
+
+ gtk_window_set_keep_above (GTK_WINDOW(MainWindow), TRUE);
+ gtk_window_set_focus_visible (GTK_WINDOW(MainWindow), TRUE);
+ gtk_window_set_keep_above (GTK_WINDOW(MainWindow), FALSE);
}
//-----------------------------------------------------------------------------
@@ -918,29 +934,29 @@ void ShowUartSimulationWindow(void)
//-----------------------------------------------------------------------------
void DestroyUartSimulationWindow(void)
{
-// // Try not to destroy the window if it is already destroyed; that is
-// // not for the sake of the window, but so that we don't trash the
-// // stored position.
-// if(UartSimulationWindow == NULL) return;
+ // Try not to destroy the window if it is already destroyed; that is
+ // not for the sake of the window, but so that we don't trash the
+ // stored position.
+ if(UartSimulationWindow == NULL) return;
-// DWORD TerminalX, TerminalY, TerminalW, TerminalH;
-// RECT r;
+ DWORD TerminalX, TerminalY, TerminalW, TerminalH;
+ RECT r;
-// GetClientRect(UartSimulationWindow, &r);
-// TerminalW = r.right - r.left;
-// TerminalH = r.bottom - r.top;
+ GetClientRect(UartSimulationWindow, &r);
+ TerminalW = r.right - r.left;
+ TerminalH = r.bottom - r.top;
-// GetWindowRect(UartSimulationWindow, &r);
-// TerminalX = r.left;
-// TerminalY = r.top;
+ GetWindowRect(UartSimulationWindow, &r);
+ TerminalX = r.left;
+ TerminalY = r.top;
-// FreezeDWORD(TerminalX);
-// FreezeDWORD(TerminalY);
-// FreezeDWORD(TerminalW);
-// FreezeDWORD(TerminalH);
+ FreezeDWORD(TerminalX);
+ FreezeDWORD(TerminalY);
+ FreezeDWORD(TerminalW);
+ FreezeDWORD(TerminalH);
-// DestroyWindow(UartSimulationWindow);
-// UartSimulationWindow = NULL;
+ DestroyWindow(UartSimulationWindow);
+ UartSimulationWindow = NULL;
}
//-----------------------------------------------------------------------------
@@ -948,29 +964,27 @@ void DestroyUartSimulationWindow(void)
//-----------------------------------------------------------------------------
static void AppendToUartSimulationTextControl(BYTE b)
{
-// char append[5];
-
-// if((isalnum(b) || strchr("[]{};':\",.<>/?`~ !@#$%^&*()-=_+|", b) ||
-// b == '\r' || b == '\n') && b != '\0')
-// {
-// append[0] = b;
-// append[1] = '\0';
-// } else {
-// sprintf(append, "\\x%02x", b);
-// }
+ char append[5];
+
+ if((isalnum(b) || strchr("[]{};':\",.<>/?`~ !@#$%^&*()-=_+|", b) ||
+ b == '\r' || b == '\n') && b != '\0')
+ {
+ append[0] = b;
+ append[1] = '\0';
+ } else {
+ sprintf(append, "\\x%02x", b);
+ }
-// #define MAX_SCROLLBACK 256
-// char buf[MAX_SCROLLBACK];
+#define MAX_SCROLLBACK 256
+ char buf[MAX_SCROLLBACK];
-// SendMessage(UartSimulationTextControl, WM_GETTEXT, (WPARAM)sizeof(buf),
-// (LPARAM)buf);
+ UartSimulationTextProc(UartSimulationTextControl, WM_GETTEXT, buf, strlen(buf));
-// int overBy = (strlen(buf) + strlen(append) + 1) - sizeof(buf);
-// if(overBy > 0) {
-// memmove(buf, buf + overBy, strlen(buf));
-// }
-// strcat(buf, append);
+ int overBy = (strlen(buf) + strlen(append) + 1) - sizeof(buf);
+ if(overBy > 0) {
+ memmove(buf, buf + overBy, strlen(buf));
+ }
+ strcat(buf, append);
-// SendMessage(UartSimulationTextControl, WM_SETTEXT, 0, (LPARAM)buf);
-// SendMessage(UartSimulationTextControl, EM_LINESCROLL, 0, (LPARAM)INT_MAX);
+ UartSimulationTextProc(UartSimulationTextControl, WM_SETTEXT, buf, strlen(buf));
}
diff --git a/ldmicro/undoredo.cpp b/ldmicro/undoredo.cpp
index 2a3c2fd..8bcfcc8 100644
--- a/ldmicro/undoredo.cpp
+++ b/ldmicro/undoredo.cpp
@@ -201,9 +201,9 @@ void UndoUndo(void)
} else {
SetUndoEnabled(FALSE, TRUE);
}
- // RefreshControlsToSettings();
- // RefreshScrollbars();
- // InvalidateRect(MainWindow, NULL, FALSE);
+ RefreshControlsToSettings();
+ RefreshScrollbars();
+ InvalidateRect(MainWindow, NULL, FALSE);
}
//-----------------------------------------------------------------------------
@@ -224,9 +224,9 @@ void UndoRedo(void)
} else {
SetUndoEnabled(TRUE, FALSE);
}
- //RefreshControlsToSettings();
- //RefreshScrollbars();
- //InvalidateRect(MainWindow, NULL, FALSE);
+ RefreshControlsToSettings();
+ RefreshScrollbars();
+ InvalidateRect(MainWindow, NULL, FALSE);
}
//-----------------------------------------------------------------------------