コード例 #1
0
ファイル: numerical_entry.cpp プロジェクト: Coderik/104P
void NumericalEntry::get_preferred_width_vfunc(int &minimum_width, int &natural_width) const
{
	Glib::RefPtr<Gtk::StyleContext> style_context = get_style_context();
	Glib::RefPtr<const Pango::Layout> layout = get_layout();
	Glib::RefPtr<Pango::Layout> layout_copy = Pango::Layout::create(layout->get_context());

	// measure width of a string containing the upper value
	string upper_str = format_for_value(_adjustment->get_upper());
	int upper_width = measure_string_width(layout_copy, upper_str);

	int width = max(upper_width, MIN_WIDTH);

	// measure width of a string containing the lower value
	string lower_str = format_for_value(_adjustment->get_lower());
	int lower_width = measure_string_width(layout_copy, lower_str);

	width = max(width, lower_width);

	// add borders
	Gtk::Border border = style_context->get_border();
	width += border.get_left() + border.get_right();

	// add paddings
	Gtk::Border padding = style_context->get_padding();
	width += padding.get_left() + padding.get_right();

	minimum_width = width;
	natural_width = width;
}
コード例 #2
0
static void
bt_sighandler (int sig, siginfo_t *info, gpointer data)
{
  void *trace[35];
  char **messages = (char **) NULL;
  int i, trace_size = 0;

  g_print ("Got signal %d\n", sig);

  /* Do something useful with siginfo_t */
  if (sig == SIGSEGV) {
    g_printerr ("Got signal %d, faulty address is %p\n", sig,
                (gpointer) info->si_addr);
  } else if (sig == SIGKILL || sig == SIGINT) {
    /* since we connect to a signal handler, asynchronous management might */
    /* might happen so we need to set an idle handler to exit the main loop */
    /* in the mainloop context. */
    Glib::RefPtr<Glib::IdleSource> idle_source = Glib::IdleSource::create ();
    idle_source->connect (sigc::ptr_fun (&quit_loop) );
    idle_source->attach (loop->get_context() );
    return;
  }

  trace_size = backtrace (trace, 35);
  /* overwrite sigaction with caller's address */
  messages = backtrace_symbols (trace, trace_size);
  /* skip first stack frame (points here) */
  g_print ("\t[bt] Execution path:\n");

  for (i = 1; i < trace_size; ++i) {
    g_print ("\t[bt] #%d %s\n", i, messages[i]);
    char syscom[256];
    gchar **strs;
    const gchar *exe;
    strs = g_strsplit (messages[i], "(", 2);

    if (strs[1] == NULL) {
      exe = getExecutableName ();
    } else {
      exe = strs[0];
    }

    sprintf (syscom, "echo -n \"\t[bt]\t\t\"; addr2line %p -s -e %s",
             trace[i], exe);
    g_strfreev (strs);

    if (system (syscom) == -1) {
      g_printerr ("Error calling addr2line\n");
    }
  }

  if (sig == SIGPIPE) {
    GST_DEBUG ("Ignore sigpipe");
  } else {
    exit (sig);
  }
}