/[svn]/gigedit/trunk/src/gigedit/scripteditor.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/scripteditor.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3364 by schoenebeck, Tue Nov 14 18:07:25 2017 UTC revision 3450 by schoenebeck, Wed Jan 2 16:39:20 2019 UTC
# Line 248  ScriptEditor::ScriptEditor() : Line 248  ScriptEditor::ScriptEditor() :
248  #endif  #endif
249    
250      m_lineNrBuffer = Gtk::TextBuffer::create(m_tagTable);      m_lineNrBuffer = Gtk::TextBuffer::create(m_tagTable);
251        m_lineNrView.set_size_request(22,14);
252      m_lineNrView.set_buffer(m_lineNrBuffer);      m_lineNrView.set_buffer(m_lineNrBuffer);
253      m_lineNrView.set_left_margin(3);      m_lineNrView.set_left_margin(3);
254      m_lineNrView.set_right_margin(3);      m_lineNrView.set_right_margin(3);
255      m_lineNrTextViewSpacer.set_size_request(5);      m_lineNrView.property_editable() = false;
256        m_lineNrView.property_sensitive() = false;
257        m_lineNrTextViewSpacer.set_size_request(5,14);
258        m_lineNrTextViewSpacer.property_editable() = false;
259        m_lineNrTextViewSpacer.property_sensitive() = false;
260      {      {
261  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if 1 //(GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
262          Gdk::Color color;          Gdk::Color color;
263  #else  #else
264          Gdk::RGBA color;          Gdk::RGBA color;
265  #endif  #endif
266          color.set("#F5F5F5");          color.set("#F5F5F5");
267          GtkWidget* widget = (GtkWidget*) m_lineNrView.gobj();          GtkWidget* widget = (GtkWidget*) m_lineNrView.gobj();
268  #if GTK_MAJOR_VERSION < 3  #if GTK_MAJOR_VERSION < 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION <= 24)
269          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
270          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
271  #endif  #endif
272      }      }
273      {      {
274  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if 1 //(GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
275          Gdk::Color color;          Gdk::Color color;
276  #else  #else
277          Gdk::RGBA color;          Gdk::RGBA color;
278  #endif  #endif
279          color.set("#EEEEEE");          color.set("#EEEEEE");
280          GtkWidget* widget = (GtkWidget*) m_lineNrTextViewSpacer.gobj();          GtkWidget* widget = (GtkWidget*) m_lineNrTextViewSpacer.gobj();
281  #if GTK_MAJOR_VERSION < 3  #if GTK_MAJOR_VERSION < 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION <= 24)
282          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
283          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
284  #endif  #endif
# Line 384  int ScriptEditor::currentFontSize() cons Line 389  int ScriptEditor::currentFontSize() cons
389      return fontSize;      return fontSize;
390  }  }
391    
392  void ScriptEditor::setFontSize(int size, bool save) {  void ScriptEditor::setFontSize(int sizePt, bool save) {
393      //printf("setFontSize(%d,%d)\n", size, save);      //printf("setFontSize(%d,%d)\n", size, save);
394    
395        // make sure the real size on the screen for the editor's font is consistent
396        // on all screens (which otherwise may vary between models and DPI settings)
397        const double referenceDPI = 96;
398        double dpi = Gdk::Screen::get_default()->get_resolution();
399        double sizePx = sizePt * dpi / referenceDPI;
400    
401  #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 20)  #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 20)
402      Pango::FontDescription fdesc;      Pango::FontDescription fdesc;
403      fdesc.set_family("monospace");      fdesc.set_family("monospace");
# Line 394  void ScriptEditor::setFontSize(int size, Line 406  void ScriptEditor::setFontSize(int size,
406      if (macIsMinMac10_6())      if (macIsMinMac10_6())
407          fdesc.set_family("Menlo");          fdesc.set_family("Menlo");
408  # endif  # endif
409      fdesc.set_size(size * PANGO_SCALE);      fdesc.set_size(sizePx * PANGO_SCALE);
410  # if GTKMM_MAJOR_VERSION < 3  # if GTKMM_MAJOR_VERSION < 3
411      m_lineNrView.modify_font(fdesc);      m_lineNrView.modify_font(fdesc);
412      m_textView.modify_font(fdesc);      m_textView.modify_font(fdesc);
# Line 416  void ScriptEditor::setFontSize(int size, Line 428  void ScriptEditor::setFontSize(int size,
428      }      }
429      m_css->load_from_data(      m_css->load_from_data(
430          "* {"          "* {"
431          "  font: " + ToString(size) + " " + family + ";"          "  font: " + ToString(sizePt) + "pt " + family + ";"
432          "}"          "}"
433      );      );
434  #endif  #endif
435      if (save) Settings::singleton()->scriptEditorFontSize = size;      if (save) Settings::singleton()->scriptEditorFontSize = sizePt;
436  }  }
437    
438  void ScriptEditor::setScript(gig::Script* script) {  void ScriptEditor::setScript(gig::Script* script) {
# Line 436  void ScriptEditor::setScript(gig::Script Line 448  void ScriptEditor::setScript(gig::Script
448      //printf("text : '%s'\n", txt.c_str());      //printf("text : '%s'\n", txt.c_str());
449      m_textBuffer->set_text(txt);      m_textBuffer->set_text(txt);
450      m_textBuffer->set_modified(false);      m_textBuffer->set_modified(false);
451    
452        // on Gtk 3 the respective text change callback would not be called, so force this update here
453        if (txt.empty())
454            updateLineNumbers();
455  }  }
456    
457  void ScriptEditor::updateLineNumbers() {  void ScriptEditor::updateLineNumbers() {
458      const int n = m_textBuffer->get_line_count();      int n = m_textBuffer->get_line_count();
459      const int old = m_lineNrBuffer->get_line_count();      int old = m_lineNrBuffer->get_line_count();
460      if (n == old) return;      if (n == old && old > 1) return;
461        if (n < 1) n = 1;
462      const int digits = log10(n) + 1;      const int digits = log10(n) + 1;
463      const int bufSz = digits + 2;      const int bufSz = digits + 2;
464      char* buf = new char[bufSz];      char* buf = new char[bufSz];
# Line 742  bool ScriptEditor::on_motion_notify_even Line 759  bool ScriptEditor::on_motion_notify_even
759      //TODO: event throttling would be a good idea here      //TODO: event throttling would be a good idea here
760      updateIssueTooltip(e);      updateIssueTooltip(e);
761  #endif  #endif
762  #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION <= 22)  #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION <= 24)
763      return ManagedWindow::on_motion_notify_event(e);      return ManagedWindow::on_motion_notify_event(e);
764  #else  #else
765      Gdk::EventMotion em = Glib::wrap(e, true);      Gdk::EventMotion em = Glib::wrap(e, true);

Legend:
Removed from v.3364  
changed lines
  Added in v.3450

  ViewVC Help
Powered by ViewVC