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 @@
+
+
+
+
+
+
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();
};