summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRr422018-06-26 13:55:10 +0530
committerRr422018-06-26 13:55:10 +0530
commitf0d0df7fb0658b315f79748e713aa4103c4b335e (patch)
treee5510eb55cc8ea7d0133358f1b485a6b4df5c87b
parent7a8317eba93c87465a3b192369e6ce9a3e19b57c (diff)
downloadLDMicroGtk-f0d0df7fb0658b315f79748e713aa4103c4b335e.tar.gz
LDMicroGtk-f0d0df7fb0658b315f79748e713aa4103c4b335e.tar.bz2
LDMicroGtk-f0d0df7fb0658b315f79748e713aa4103c4b335e.zip
Added UART terminal window. Porting of simulation functionality complete
-rw-r--r--ldmicro/confdialog.cpp9
-rw-r--r--ldmicro/includes/ldmicro.h9
-rw-r--r--ldmicro/iolist.cpp137
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp5
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h7
-rw-r--r--ldmicro/maincontrols.cpp8
-rw-r--r--ldmicro/miscutil.cpp23
-rw-r--r--ldmicro/simulate.cpp226
8 files changed, 217 insertions, 207 deletions
diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp
index cb61ce7..a99c8c3 100644
--- a/ldmicro/confdialog.cpp
+++ b/ldmicro/confdialog.cpp
@@ -138,11 +138,6 @@ static void MakeControls(void)
// (LONG_PTR)MyNumberProc);
}
-void DestroyWindow (GtkWidget* widget, gpointer data){
- gtk_widget_destroy (ConfDialog);
- gtk_widget_set_sensitive (MainWindow, TRUE);
-}
-
//-----------------------------------------------------------------------------
// Don't allow any characters other than 0-9. in the text boxes.
//-----------------------------------------------------------------------------
@@ -173,7 +168,7 @@ void GetData (GtkWidget* widget, gpointer data){
buf = const_cast <char*> (gtk_entry_get_text (GTK_ENTRY(BaudTextbox)));
Prog.baudRate = atoi(buf);
- DestroyWindow (ConfDialog, NULL);
+ DestroyWindow (ConfDialog);
}
// Checks for the required key press
@@ -182,7 +177,7 @@ gboolean KeyPress (GtkWidget* widget, GdkEventKey* event, gpointer data){
GetData(NULL, NULL);
}
else if (event -> keyval == GDK_KEY_Escape){
- DestroyWindow (ConfDialog, NULL);
+ DestroyWindow (ConfDialog);
}
return FALSE;
}
diff --git a/ldmicro/includes/ldmicro.h b/ldmicro/includes/ldmicro.h
index 5f4275e..1c56074 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, 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 cc9fb6b..e3ba581 100644
--- a/ldmicro/iolist.cpp
+++ b/ldmicro/iolist.cpp
@@ -47,6 +47,7 @@ static BOOL DialogDone;
static BOOL DialogCancel;
static HWID IoDialog;
+static HWID textLabel;
static HWID PinList;
static HWID OkButton;
@@ -402,19 +403,16 @@ static gboolean AnalogSliderDialogKeyboardProc(GtkWidget* widget, GdkEventKey* e
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;
}
@@ -428,8 +426,7 @@ static gboolean AnalogSliderDialogMouseProc(GtkWidget *widget, GdkEventButton *e
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;
}
@@ -465,22 +462,13 @@ void ShowAnalogSliderPopup(char *name)
return;
}
- int x, y;
- // gtk_window_get_position(GTK_WINDOW(view), &x, &y);
- // gint wx, wy;
- gdk_window_get_origin (gtk_widget_get_window (view), &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);
-
- // if(top + 110 >= r.bottom) {
- // top = r.bottom - 110;
- // }
+ int x, y;
+ gdk_window_get_origin (gtk_widget_get_window (view), &x, &y);
if(top < 0) top = y + 10;
if(left < 0) left = x + 20;
@@ -489,7 +477,7 @@ void ShowAnalogSliderPopup(char *name)
return;
AnalogSliderMain = gtk_window_new(GTK_WINDOW_POPUP);
- gtk_window_set_title(GTK_WINDOW(AnalogSliderMain), "I/O Pin");
+ 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);
@@ -534,9 +522,7 @@ void ShowAnalogSliderPopup(char *name)
AnalogSliderDone = FALSE;
AnalogSliderCancel = FALSE;
-
- // SWORD orig = GetAdcShadow(name);
-
+
// ListView_RedrawItems(IoList, 0, Prog.io.count - 1);
}
@@ -600,10 +586,11 @@ static BOOL MakeWindowClass()
static void MakeControls(void)
{
+ // textLabel = gtk_text_view_new ();
// HWND textLabel = CreateWindowEx(0, WC_STATIC, _("Assign:"),
// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
// 6, 1, 80, 17, IoDialog, NULL, Instance, NULL);
-// NiceFont(textLabel);
+ // NiceFont(textLabel);
// PinList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTBOX, "",
// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | WS_VSCROLL |
@@ -623,59 +610,60 @@ static void MakeControls(void)
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) {
+ 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_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.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] != '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(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;
-// }
+ 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();
+ // 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);
+ // 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();
+ // MakeControls();
// SendMessage(PinList, LB_ADDSTRING, 0, (LPARAM)_("(no pin)"));
// int i;
@@ -728,7 +716,8 @@ void ShowIoDialog(int item)
// }
// EnableWindow(MainWindow, FALSE);
-// ShowWindow(IoDialog, TRUE);
+ // ShowWindow(IoDialog, TRUE);
+ // gtk_widget_show_all(IoDialog);
// SetFocus(PinList);
// MSG msg;
@@ -909,10 +898,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/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 46e9a40..e65c7d5 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -507,4 +507,9 @@ BOOL KillTimer(HWID hWid, UINT uIDEvent)
timerRecords.erase(record_it);
return TRUE;
+}
+
+void DestroyWindow (HWID widget)
+{
+ gtk_widget_destroy (widget);
} \ No newline at end of file
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 68d5ef4..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
@@ -219,4 +224,6 @@ BOOL KillTimer(
HWID hWid,
UINT uIDEvent);
+void DestroyWindow (HWID widget);
+
#endif \ No newline at end of file
diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp
index 9e3770d..c24c4af 100644
--- a/ldmicro/maincontrols.cpp
+++ b/ldmicro/maincontrols.cpp
@@ -940,9 +940,9 @@ void ToggleSimulationMode(void)
CheckMenuItem(SimulateMenu, SimulationModeMenu, MF_UNCHECKED);
- // if(UartFunctionUsed()) {
- // DestroyUartSimulationWindow();
- // }
+ if(UartFunctionUsed()) {
+ DestroyUartSimulationWindow();
+ }
}
UpdateMainWindowTitleBar();
@@ -1159,6 +1159,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 882cccd..fdf1647 100644
--- a/ldmicro/miscutil.cpp
+++ b/ldmicro/miscutil.cpp
@@ -204,10 +204,13 @@ 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, 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);
// HWND h = CreateWindowEx(exStyle, className, windowName, style, x, y,
// width, height, parent, menu, instance, param);
@@ -218,7 +221,7 @@ HWND CreateWindowClient(DWORD exStyle, char *className, char *windowName,
// SetWindowPos(h, HWND_TOP, x, y, width, height, 0);
- return NULL;
+ return h;
}
//-----------------------------------------------------------------------------
@@ -263,7 +266,7 @@ 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"));
+ gtk_widget_override_font(GTK_WIDGET(h), pango_font_description_from_string(MyNiceFont->lpszFace));
// SendMessage(h, WM_SETFONT, (WPARAM)MyNiceFont, TRUE);
}
@@ -300,15 +303,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/simulate.cpp b/ldmicro/simulate.cpp
index 6b38896..a3faf38 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, "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));
}