bsnes/hiro/gtk/widget/text-edit.cpp

105 lines
3.3 KiB
C++
Raw Normal View History

#if defined(Hiro_TextEdit)
Update to v094r09 release. byuu says: This will easily be the biggest diff in the history of higan. And not in a good way. * target-higan and target-loki have been blown away completely * nall and ruby massively updated * phoenix replaced with hiro (pretty near a total rewrite) * target-higan restarted using hiro (just a window for now) * all emulation cores updated to compile again * installation changed to not require root privileges (installs locally) For the foreseeable future (maybe even permanently?), the new higan UI will only build under Linux/BSD with GTK+ 2.20+. Probably the most likely route for Windows/OS X will be to try and figure out how to build hiro/GTK on those platforms, as awful as that would be. The other alternative would be to produce new UIs for those platforms ... which would actually be a good opportunity to make something much more user friendly. Being that I just started on this a few hours ago, that means that for at least a few weeks, don't expect to be able to actually play any games. Right now, you can pretty much just compile the binary and that's it. It's quite possible that some nall changes didn't produce compilation errors, but will produce runtime errors. So until the UI can actually load games, we won't know if anything is broken. But we should mostly be okay. It was mostly just trim<1> -> trim changes, moving to Hash::SHA256 (much cleaner), and patching some reckless memory copy functions enough to compile. Progress isn't going to be like it was before: I'm now dividing my time much thinner between studying and other hobbies. My aim this time is not to produce a binary for everyone to play games on. Rather, it's to keep the emulator alive. I want to be able to apply critical patches again. And I would also like the base of the emulator to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
namespace hiro {
static auto TextEdit_change(GtkTextBuffer* textBuffer, pTextEdit* p) -> void {
if(!p->locked()) p->self().doChange();
}
static auto TextEdit_move(GObject* object, GParamSpec* spec, pTextEdit* p) -> void {
int position = 0;
g_object_get(p->textBuffer, "cursor-position", &position, nullptr);
if(p->state().cursorPosition != position) {
p->state().cursorPosition = position;
if(!p->locked()) p->self().doMove();
}
}
auto pTextEdit::construct() -> void {
gtkWidget = gtk_scrolled_window_new(0, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN);
subWidget = gtk_text_view_new();
gtk_widget_show(subWidget);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_WORD_CHAR);
gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget);
textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget));
setBackgroundColor(state().backgroundColor);
setEditable(state().editable);
setForegroundColor(state().foregroundColor);
setText(state().text);
setWordWrap(state().wordWrap);
g_signal_connect(G_OBJECT(textBuffer), "changed", G_CALLBACK(TextEdit_change), (gpointer)this);
g_signal_connect(G_OBJECT(textBuffer), "notify::cursor-position", G_CALLBACK(TextEdit_move), (gpointer)this);
pWidget::construct();
}
auto pTextEdit::destruct() -> void {
state().text = text();
gtk_widget_destroy(subWidget);
gtk_widget_destroy(gtkWidget);
}
auto pTextEdit::focused() const -> bool {
return GTK_WIDGET_HAS_FOCUS(subWidget);
}
auto pTextEdit::setBackgroundColor(Color color) -> void {
GdkColor gdkColor = CreateColor(color);
gtk_widget_modify_base(subWidget, GTK_STATE_NORMAL, color ? &gdkColor : nullptr);
}
auto pTextEdit::setCursorPosition(unsigned position) -> void {
lock();
GtkTextMark* mark = gtk_text_buffer_get_mark(textBuffer, "insert");
GtkTextIter iter;
gtk_text_buffer_get_end_iter(textBuffer, &iter);
gtk_text_iter_set_offset(&iter, min(position, gtk_text_iter_get_offset(&iter)));
gtk_text_buffer_place_cursor(textBuffer, &iter);
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(subWidget), mark);
unlock();
}
auto pTextEdit::setEditable(bool editable) -> void {
gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), editable);
}
auto pTextEdit::setForegroundColor(Color color) -> void {
GdkColor gdkColor = CreateColor(color);
gtk_widget_modify_text(subWidget, GTK_STATE_NORMAL, color ? &gdkColor : nullptr);
}
auto pTextEdit::setText(const string& text) -> void {
lock();
textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget));
gtk_text_buffer_set_text(textBuffer, text, -1);
unlock();
}
auto pTextEdit::setWordWrap(bool wordWrap) -> void {
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), wordWrap ? GTK_WRAP_WORD_CHAR : GTK_WRAP_NONE);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget),
wordWrap ? GTK_POLICY_NEVER : GTK_POLICY_ALWAYS,
GTK_POLICY_ALWAYS);
}
auto pTextEdit::text() const -> string {
GtkTextIter start, end;
gtk_text_buffer_get_start_iter(textBuffer, &start);
gtk_text_buffer_get_end_iter(textBuffer, &end);
char* temp = gtk_text_buffer_get_text(textBuffer, &start, &end, true);
string text = temp;
g_free(temp);
return text;
}
}
#endif