-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux.cpp
135 lines (104 loc) · 3.79 KB
/
linux.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
////////////////////////////////////////////////////////////////////////////
// linux.cpp -- Hiragana Calculator Calc-H for Linux
// This file is part of Calc-H. See file "ReadMe.txt" and "License.txt".
////////////////////////////////////////////////////////////////////////////
// (Japanese, UTF-8)
#include "stdafx.h"
#include <thread>
////////////////////////////////////////////////////////////////////////////
class MainWindow : public Gtk::Window {
public:
MainWindow();
virtual ~MainWindow();
protected:
virtual void on_button_enter();
Gtk::VBox m_vbox;
Gtk::TextView m_textview;
Gtk::HBox m_hbox;
Gtk::Label m_label;
Gtk::Entry m_entry;
Gtk::Button m_button_enter;
Glib::RefPtr<Gtk::TextBuffer> m_text_buf;
void add_output(const std::string& contents);
}; // class MainWindow
////////////////////////////////////////////////////////////////////////////
MainWindow::MainWindow() {
set_title("ひらがな電卓Calc-H ver.0.8.8");
set_size_request(500, 280);
Pango::FontDescription font_desc;
#ifdef _WIN32
font_desc.set_family("MS Gothic");
#else
font_desc.set_family("typewriter");
#endif
m_label.modify_font(font_desc);
m_entry.modify_font(font_desc);
m_textview.modify_font(font_desc);
m_button_enter.modify_font(font_desc);
set_border_width(4);
m_hbox.set_border_width(8);
m_vbox.set_border_width(8);
m_text_buf = Gtk::TextBuffer::create();
m_textview.set_buffer(m_text_buf);
m_label.set_label("にゅうりょく:");
m_entry.set_text("");
m_button_enter.set_label("Enter");
m_button_enter.signal_clicked().connect(
sigc::mem_fun(*this, &MainWindow::on_button_enter)
);
m_hbox.pack_start(m_label, Gtk::PACK_SHRINK);
m_hbox.pack_start(m_entry);
m_hbox.pack_start(m_button_enter, Gtk::PACK_SHRINK);
m_vbox.pack_start(m_textview);
m_vbox.pack_start(m_hbox, Gtk::PACK_SHRINK);
add(m_vbox);
show_all_children();
m_button_enter.set_can_default();
set_focus(m_entry);
std::string contents;
contents += ch_logo;
contents += '\n';
add_output(contents);
} // MainWindow::MainWindow
MainWindow::~MainWindow() {
;
} // MainWindow::~MainWindow
void MainWindow::on_button_enter() {
std::thread(
[this](int dummy) {
std::string query = m_entry.get_text();
m_entry.set_sensitive(false);
m_entry.set_text("計算中です...");
CrTrimString(query);
auto result = ChJustDoIt(query);
ChFixResultForDisplay(result);
std::string contents("にゅうりょく:");
contents += query;
contents += '\n';
contents += result;
contents += '\n';
add_output(contents);
if (result.find("しゅうりょうします") != std::string::npos) {
m_entry.set_text("終了中です...");
hide();
}
m_entry.set_text("");
m_entry.set_sensitive(true);
set_focus(m_entry);
}, 0
).detach();
}
void MainWindow::add_output(const std::string& contents) {
m_text_buf->set_text(m_text_buf->get_text() + contents);
auto end = m_text_buf->get_iter_at_line(m_text_buf->get_line_count() + 100);
m_textview.scroll_to(end);
}
////////////////////////////////////////////////////////////////////////////
extern "C"
int main(int argc, char **argv) {
Gtk::Main kit(argc, argv);
MainWindow window;
Gtk::Main::run(window);
return 0;
}
////////////////////////////////////////////////////////////////////////////