diff --git a/Gtkmm3/gtk137_editor_keyboard/CMakeLists.txt b/Gtkmm3/gtk137_editor_keyboard/CMakeLists.txt index ecf2ed9..e764f71 100644 --- a/Gtkmm3/gtk137_editor_keyboard/CMakeLists.txt +++ b/Gtkmm3/gtk137_editor_keyboard/CMakeLists.txt @@ -31,6 +31,7 @@ set(SOURCE_FILE src/main.cc src/TextEditor.cc) #Compile Resource set(RESOURCE_LIST + expender.ui text_menu.xml) compile_gresources(RESOURCE_FILE diff --git a/Gtkmm3/gtk137_editor_keyboard/res/expender.ui b/Gtkmm3/gtk137_editor_keyboard/res/expender.ui new file mode 100644 index 0000000..ec05028 --- /dev/null +++ b/Gtkmm3/gtk137_editor_keyboard/res/expender.ui @@ -0,0 +1,440 @@ + + + + + + True + True + True + + + + True + False + True + True + + + Q + True + True + True + + + 2 + 0 + 2 + + + + + W + True + True + True + + + 4 + 0 + 2 + + + + + E + True + True + True + + + 6 + 0 + 2 + + + + + R + True + True + True + + + 8 + 0 + 2 + + + + + T + True + True + True + + + 10 + 0 + 2 + + + + + Y + True + True + True + + + 12 + 0 + 2 + + + + + U + True + True + True + + + 14 + 0 + 2 + + + + + I + True + True + True + + + 16 + 0 + 2 + + + + + O + True + True + True + + + 18 + 0 + 2 + + + + + P + True + True + True + + + 20 + 0 + 2 + + + + + A + True + True + True + + + 3 + 1 + 2 + + + + + Z + True + True + True + + + 4 + 2 + 2 + + + + + S + True + True + True + + + 5 + 1 + 2 + + + + + D + True + True + True + + + 7 + 1 + 2 + + + + + F + True + True + True + + + 9 + 1 + 2 + + + + + G + True + True + True + + + 11 + 1 + 2 + + + + + H + True + True + True + + + 13 + 1 + 2 + + + + + J + True + True + True + + + 15 + 1 + 2 + + + + + K + True + True + True + + + 17 + 1 + 2 + + + + + L + True + True + True + + + 19 + 1 + 2 + + + + + CapsLK + True + True + True + + + 0 + 1 + 3 + + + + + X + True + True + True + + + 6 + 2 + 2 + + + + + C + True + True + True + + + 8 + 2 + 2 + + + + + V + True + True + True + + + 10 + 2 + 2 + + + + + B + True + True + True + + + 12 + 2 + 2 + + + + + N + True + True + True + + + 14 + 2 + 2 + + + + + M + True + True + True + + + 16 + 2 + 2 + + + + + Shift + True + True + True + + + 0 + 2 + 4 + + + + + tab + True + True + True + + + 0 + 0 + 2 + + + + + enter + True + True + True + + + 21 + 1 + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + False + Keyboard + + + + diff --git a/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.cc b/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.cc index 29c7129..a8437e8 100644 --- a/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.cc +++ b/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.cc @@ -3,6 +3,7 @@ #include "../json_nlohmann/json.hpp" #include #include +#include using json = nlohmann::json; @@ -27,7 +28,7 @@ TextEditor::TextEditor() json_file.close(); // Initalize Window - vbox.set_size_request(width, height); + set_default_size(width, height); set_icon_name("my_textedit"); // Initalize HeaderBar @@ -90,17 +91,61 @@ TextEditor::TextEditor() infobox = dynamic_cast(infobar.get_content_area()); infobox->pack_start(label1); vbox.pack_start(infobar, Gtk::PACK_SHRINK); + vbox.pack_start(hbox); // Save config when the window is closed signal_delete_event().connect(sigc::mem_fun(*this, &TextEditor::window_delete_event)); + // Add Intergated keyboard + expend_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/expender.ui"); + expend_builder->get_widget("key_expend", expender); + expend_builder->get_widget("btnshift", btnshift); + expend_builder->get_widget("btn_caps", btncaps); + expend_builder->get_widget("btntab", btntab); + expend_builder->get_widget("btnenter", btnenter); + vbox.pack_start(*expender, Gtk::PACK_SHRINK); + + // Get alphabet buttons + for(int i = 0; i < 26; i++){ + char name[10]; + sprintf(name, "btn%d", i); + expend_builder->get_widget(name, btns[i]); + btns[i]->signal_clicked().connect(sigc::bind( + sigc::mem_fun(*this, &TextEditor::key_pressed), + btns[i] + )); + } + btntab->signal_clicked().connect(sigc::mem_fun(*this, &TextEditor::btntab_clicked)); + btnenter->signal_clicked().connect(sigc::mem_fun(*this, &TextEditor::btnenter_clicked)); + // Show everything - vbox.pack_start(hbox); add(vbox); show_all_children(); infobar.hide(); } +void TextEditor::key_pressed(Gtk::Button *button){ + auto label = button->get_label(); + Glib::ustring::size_type pos = 0,len = 1; + char buf[2]; + if(btncaps->get_active() || btnshift->get_active()){ + btnshift->set_active(false); + }else{ + sprintf(buf, "%c", label[0] + 32); + label.replace(pos, len, buf); + } + //std::cout << label << std::endl; + buffer1->insert_at_cursor(label); +} + +void TextEditor::btntab_clicked(){ + buffer1->insert_at_cursor("\t"); +} + +void TextEditor::btnenter_clicked(){ + buffer1->insert_at_cursor("\n"); +} + bool TextEditor::window_delete_event(GdkEventAny *event) { // Create json raw data @@ -110,8 +155,8 @@ bool TextEditor::window_delete_event(GdkEventAny *event) })"); // Override config in json file - data["width"] = vbox.get_width(); - data["height"] = vbox.get_height(); + data["width"] = sw1.get_width(); + data["height"] = sw1.get_height(); // Output json data to file std::fstream outfile; diff --git a/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.hh b/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.hh index 22eac44..2238cf0 100644 --- a/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.hh +++ b/Gtkmm3/gtk137_editor_keyboard/src/TextEditor.hh @@ -13,7 +13,7 @@ private: Gtk::MenuButton menubtn; Gtk::Popover popover; Gtk::ToggleButton search_button; - Glib::RefPtr menu_builder; + Glib::RefPtr menu_builder, expend_builder; // SearchBar Gtk::SearchBar searchbar; @@ -25,11 +25,14 @@ private: // Window widgets Gtk::Box vbox, hbox, *infobox; - Gtk::ScrolledWindow sw1, sw2; + Gtk::ScrolledWindow sw1; Glib::RefPtr buffer1; Gtk::TextView textview1; Gtk::InfoBar infobar; Gtk::Label label1; + Gtk::Expander *expender; + Gtk::Button *btns[26], *btntab, *btnenter; + Gtk::ToggleButton *btnshift, *btncaps; // File Dialog Glib::RefPtr dialog; @@ -59,6 +62,11 @@ private: void search_forward(); void search_backward(); + // Keyboard press + void key_pressed(Gtk::Button *button); + void btntab_clicked(); + void btnenter_clicked(); + // Other Signal Handlers void about_activated(); };