From a19c6e383399b666c521854502e0d0c2222cc2f8 Mon Sep 17 00:00:00 2001 From: NatsuDrag9 Date: Tue, 19 Jun 2018 19:46:17 +0530 Subject: Ported confdialog completely. --- ldmicro/confdialog.cpp | 92 ++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 55 deletions(-) diff --git a/ldmicro/confdialog.cpp b/ldmicro/confdialog.cpp index e7f0c71..21f7ca5 100644 --- a/ldmicro/confdialog.cpp +++ b/ldmicro/confdialog.cpp @@ -46,31 +46,6 @@ static LONG_PTR PrevBaudProc; HWID Grid; HWID PackingBox; -//----------------------------------------------------------------------------- -// Don't allow any characters other than 0-9. in the text boxes. -//----------------------------------------------------------------------------- -// static LRESULT CALLBACK MyNumberProc(HWND hwnd, UINT msg, WPARAM wParam, -// LPARAM lParam) -// { -// if(msg == WM_CHAR) { -// if(!(isdigit(wParam) || wParam == '.' || wParam == '\b')) { -// return 0; -// } -// } - -// LONG_PTR t; -// if(hwnd == CrystalTextbox) -// t = PrevCrystalProc; -// else if(hwnd == CycleTextbox) -// t = PrevCycleProc; -// else if(hwnd == BaudTextbox) -// t = PrevBaudProc; -// else -// oops(); - -// return CallWindowProc((WNDPROC)t, hwnd, msg, wParam, lParam); -// } - static void MakeControls(void) { // Creating text labels @@ -80,8 +55,12 @@ static void MakeControls(void) // Creating text boxes CycleTextbox = gtk_entry_new (); - CrystalTextbox = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (CycleTextbox), 0); + // gtk_entry_set_input_purpose (GTK_ENTRY (CycleTextbox), GTK_INPUT_PURPOSE_DIGITS); + CrystalTextbox = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (CrystalTextbox), 0); BaudTextbox = gtk_entry_new (); + gtk_entry_set_max_length (GTK_ENTRY (BaudTextbox), 0); if(!UartFunctionUsed()) { gtk_widget_set_sensitive (BaudTextbox, FALSE); @@ -143,28 +122,12 @@ static void MakeControls(void) gtk_grid_attach (GTK_GRID (Grid), ButtonCancel, 6, 4, 2, 1); gtk_grid_attach (GTK_GRID (Grid), textLabel3, 1, 6, 1, 1); gtk_grid_attach (GTK_GRID (Grid), BaudTextbox, 3, 6, 1, 1); + gtk_grid_set_column_spacing (GTK_GRID (Grid), 2); gtk_box_pack_start(GTK_BOX(PackingBox), Grid, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(PackingBox), textLabel4, TRUE, TRUE, 0); -// // Measure the explanation string, so that we know how to size our window -// RECT tr, cr; -// HDC hdc = CreateCompatibleDC(NULL); -// SelectObject(hdc, MyNiceFont); -// SetRect(&tr, 0, 0, 310, 400); -// DrawText(hdc, explanation, -1, &tr, DT_CALCRECT | -// DT_LEFT | DT_TOP | DT_WORDBREAK); -// DeleteDC(hdc); -// int h = 104 + tr.bottom + 10; -// SetWindowPos(ConfDialog, NULL, 0, 0, 344, h, SWP_NOMOVE); -// // h is the desired client height, but SetWindowPos includes title bar; -// // so fix it up by hand -// GetClientRect(ConfDialog, &cr); -// int nh = h + (h - (cr.bottom - cr.top)); -// SetWindowPos(ConfDialog, NULL, 0, 0, 344, nh, SWP_NOMOVE); - - // PrevCycleProc = SetWindowLongPtr(CycleTextbox, GWLP_WNDPROC, // (LONG_PTR)MyNumberProc); @@ -180,10 +143,26 @@ void DestroyWindow (GtkWidget* widget, gpointer data){ gtk_widget_set_sensitive (MainWindow, TRUE); } -void SaveData (GtkWidget* widget, gpointer data){ +//----------------------------------------------------------------------------- +// Don't allow any characters other than 0-9. in the text boxes. +//----------------------------------------------------------------------------- + +void MyNumberProc (GtkEditable *editable, gchar *NewText, gint length, + gint *position, gpointer data){ + for (int i = 0; i < length; i++){ + if (!(isdigit (NewText[i]) || NewText[i] == '.' || NewText[i] == '\b')){ + g_signal_stop_emission_by_name (G_OBJECT (editable), "insert_text"); + return; + } + } +} + +// Gets data from the text boxes +void GetData (GtkWidget* widget, gpointer data){ char* buf; buf = const_cast (gtk_entry_get_text (GTK_ENTRY (CycleTextbox))); + // cout << sizeof (buf)/sizeof (*buf) << "\n"; Prog.cycleTime = (int)(1000*atof(buf) + 0.5); if(Prog.cycleTime == 0) { Error(_("Zero cycle time not valid; resetting to 10 ms.")); @@ -192,30 +171,35 @@ void SaveData (GtkWidget* widget, gpointer data){ buf = const_cast (gtk_entry_get_text (GTK_ENTRY(CrystalTextbox))); Prog.mcuClock = (int)(1e6*atof(buf) + 0.5); - cout << Prog.mcuClock << "\n"; buf = const_cast (gtk_entry_get_text (GTK_ENTRY(BaudTextbox))); Prog.baudRate = atoi(buf); DestroyWindow (ConfDialog, NULL); } -void KeyPress (GtkWidget* widget, GdkEventKey* event, gpointer data){ +// Checks for the required key press +gboolean KeyPress (GtkWidget* widget, GdkEventKey* event, gpointer data){ if (event -> keyval == GDK_KEY_Return){ - SaveData(NULL, NULL); - DestroyWindow (ConfDialog, NULL); + GetData(NULL, NULL); } else if (event -> keyval == GDK_KEY_Escape){ DestroyWindow (ConfDialog, NULL); } + return FALSE; } +// Consists of all the signal calls void SignalCall () { + g_signal_connect (G_OBJECT(CycleTextbox), "insert-text", + G_CALLBACK(MyNumberProc), NULL); + g_signal_connect (G_OBJECT(CrystalTextbox), "insert-text", + G_CALLBACK(MyNumberProc), NULL); + g_signal_connect (G_OBJECT(BaudTextbox), "insert-text", + G_CALLBACK(MyNumberProc), NULL); g_signal_connect (G_OBJECT (ConfDialog), "key-press-event", G_CALLBACK(KeyPress), NULL); - g_signal_connect (G_OBJECT (ConfDialog), "key_press_event", - G_CALLBACK(KeyPress), NULL); g_signal_connect (G_OBJECT (ButtonOk), "clicked", - G_CALLBACK(SaveData), NULL); + G_CALLBACK(GetData), NULL); g_signal_connect (G_OBJECT (ButtonCancel), "clicked", G_CALLBACK(DestroyWindow), NULL); } @@ -245,12 +229,10 @@ void ShowConfDialog(void) gtk_entry_set_text (GTK_ENTRY (BaudTextbox), buf); gtk_widget_set_sensitive (MainWindow, FALSE); - gtk_widget_grab_focus (CycleTextbox); gtk_widget_grab_focus (ButtonOk); + gtk_widget_set_state_flags (CycleTextbox, GTK_STATE_FLAG_FOCUSED, TRUE); + gtk_widget_grab_focus (CycleTextbox); gtk_widget_show_all (ConfDialog); - - DialogDone = FALSE; - DialogCancel = FALSE; SignalCall(); -- cgit From db313e63f75bf7e142299a4ec2c26cee0f1213d7 Mon Sep 17 00:00:00 2001 From: NatsuDrag9 Date: Tue, 19 Jun 2018 19:47:52 +0530 Subject: Removed local variable - TopMenu from MakeMainMenus(). --- ldmicro/maincontrols.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ldmicro/maincontrols.cpp b/ldmicro/maincontrols.cpp index f7dc8c4..5921c3f 100644 --- a/ldmicro/maincontrols.cpp +++ b/ldmicro/maincontrols.cpp @@ -254,9 +254,8 @@ void AddMenuAccelerators (void){ //----------------------------------------------------------------------------- HMENU MakeMainWindowMenus(void) { - HMENU MenuBox; // Box for alignment - HMENU PackedMenuBox; // Stores the packed box - HMENU TopMenu; // Menu Bar + HMENU MenuBox; // Box for packing and alignment + // HMENU TopMenu; // Menu Bar HWID FileLabel; // File menu label HWID EditLabel; // Edit menu label HWID InstructionLabel; // Instruction menu label -- cgit From d4202cbb3bfe98ce433674afeb99af5bb1f0072a Mon Sep 17 00:00:00 2001 From: NatsuDrag9 Date: Tue, 19 Jun 2018 19:48:18 +0530 Subject: Removed draw called print statements. --- ldmicro/ldmicro.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index c3d84d6..0d02d8d 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -973,8 +973,6 @@ gboolean LD_GTK_mouse_click_hook(GtkWidget *widget, GdkEvent *event, gpointer us * WM_LBUTTONDBLCLK, WM_LBUTTONDOWN */ - g_print("x = %f\n", event->button.x_root); - g_print("y = %f\n", event->button.y_root); switch(event->button.type) { case GDK_BUTTON_PRESS:// To Do: run only for left click @@ -1043,8 +1041,6 @@ gboolean LD_WM_MouseMove_call(GtkWidget *widget, GdkEvent *event, gpointer user_ * WM_MOUSEMOVE */ - g_print("x = %f\n", event->button.x_root); - g_print("y = %f\n", event->button.y_root); // int x = LOWORD(lParam); // int y = HIWORD(lParam); @@ -1064,8 +1060,6 @@ gboolean LD_WM_Paint_call(HWID widget, HCRDC cr, gpointer data) * WM_PAINT */ - g_print("draw called\n"); - // guint width, height; // GdkRGBA color; // GtkStyleContext *context; @@ -1310,17 +1304,17 @@ int main(int argc, char** argv) /// Keyboard and mouse hooks equivalent to MainWndProc g_signal_connect (MainWindow, "delete_event", G_CALLBACK (LD_WM_Close_call), NULL); - g_signal_connect (MainWindow, "key_press_event", G_CALLBACK (LD_WM_KeyDown_call), NULL); + // g_signal_connect (MainWindow, "key_press_event", G_CALLBACK (LD_WM_KeyDown_call), NULL); g_signal_connect (MainWindow, "button_press_event", G_CALLBACK (LD_GTK_mouse_click_hook), NULL); g_signal_connect (MainWindow, "scroll_event", G_CALLBACK (LD_GTK_mouse_scroll_hook), NULL); g_signal_connect (MainWindow, "motion_notify_event", G_CALLBACK (LD_WM_MouseMove_call), NULL); g_signal_connect (DrawWindow, "draw", G_CALLBACK (LD_WM_Paint_call), NULL); g_signal_connect (MainWindow, "destroy_event", G_CALLBACK (LD_WM_Destroy_call), NULL); g_signal_connect (MainWindow, "configure_event", G_CALLBACK (LD_WM_Size_call), NULL); - g_signal_connect (MainWindow, "focus_in_event", G_CALLBACK (LD_WM_SetFocus_call), NULL); + // g_signal_connect (MainWindow, "focus_in_event", G_CALLBACK (LD_WM_SetFocus_call), NULL); /// Keyboard and mouse hooks equivalent to MainWndProc - end - // NewProgram(); + NewProgram(); // strcpy(CurrentSaveFile, ""); // We are running interactively, or we would already have exited. We -- cgit