Example #1
0
  /* Run a glib GMainLoop which intercepts key and mouse button events from
     |  the top level loop.  When a mouse or key is hit in the Output drawing
     |  area, quit the loop so the top level loop can continue and use the
     |  the mouse pointer coordinates at the time of the mouse button event.
   */
static gboolean
run_get_location_loop (const gchar * message)
{
  GMainLoop *loop;
  gulong button_handler, key_handler;
  gint oldObjState, oldLineState, oldBoxState;

  ghid_status_line_set_text (message);

  oldObjState = Crosshair.AttachedObject.State;
  oldLineState = Crosshair.AttachedLine.State;
  oldBoxState = Crosshair.AttachedBox.State;
  HideCrosshair (true);
  Crosshair.AttachedObject.State = STATE_FIRST;
  Crosshair.AttachedLine.State = STATE_FIRST;
  Crosshair.AttachedBox.State = STATE_FIRST;
  ghid_hand_cursor ();
  RestoreCrosshair (true);

  /* Stop the top level GMainLoop from getting user input from keyboard
     |  and mouse so we can install our own handlers here.  Also set the
     |  control interface insensitive so all the user can do is hit a key
     |  or mouse button in the Output drawing area.
   */
  ghid_interface_input_signals_disconnect ();
  ghid_interface_set_sensitive (FALSE);

  got_location = TRUE;		/* Will be unset by hitting most keys */
  button_handler =
    g_signal_connect (G_OBJECT (gport->drawing_area),
		      "button_press_event",
		      G_CALLBACK (loop_button_press_cb), &loop);
  key_handler =
    g_signal_connect (G_OBJECT (gport->top_window),
		      "key_press_event",
		      G_CALLBACK (loop_key_press_cb), &loop);

  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);

  g_main_loop_unref (loop);

  g_signal_handler_disconnect (gport->drawing_area, button_handler);
  g_signal_handler_disconnect (gport->top_window, key_handler);

  ghid_interface_input_signals_connect ();	/* return to normal */
  ghid_interface_set_sensitive (TRUE);

  HideCrosshair (true);
  Crosshair.AttachedObject.State = oldObjState;
  Crosshair.AttachedLine.State = oldLineState;
  Crosshair.AttachedBox.State = oldBoxState;
  RestoreCrosshair (true);
  ghid_restore_cursor ();

  ghid_set_status_line_label ();

  return got_location;
}
Example #2
0
File: gui-misc.c Project: bert/pcb
  /* Run a glib GMainLoop which intercepts key and mouse button events from
     |  the top level loop.  When a mouse or key is hit in the Output drawing
     |  area, quit the loop so the top level loop can continue and use the
     |  the mouse pointer coordinates at the time of the mouse button event.
   */
static gboolean
run_get_location_loop (const gchar * message)
{
  GMainLoop *loop;
  gulong button_handler, key_handler;
  gint oldObjState, oldLineState, oldBoxState;

  /* Make the text cue bold so it hides less and looks like command prompt  */
  GString *bold_message = g_string_new (message);
  g_string_prepend (bold_message, "<b>");
  g_string_append (bold_message, "</b>");

  ghid_status_line_set_text (bold_message->str);

  g_string_free (bold_message, TRUE);

  oldObjState = Crosshair.AttachedObject.State;
  oldLineState = Crosshair.AttachedLine.State;
  oldBoxState = Crosshair.AttachedBox.State;
  notify_crosshair_change (false);
  Crosshair.AttachedObject.State = STATE_FIRST;
  Crosshair.AttachedLine.State = STATE_FIRST;
  Crosshair.AttachedBox.State = STATE_FIRST;
  ghid_hand_cursor ();
  notify_crosshair_change (true);

  /* Stop the top level GMainLoop from getting user input from keyboard
     |  and mouse so we can install our own handlers here.  Also set the
     |  control interface insensitive so all the user can do is hit a key
     |  or mouse button in the Output drawing area.
   */
  ghid_interface_input_signals_disconnect ();
  ghid_interface_set_sensitive (FALSE);

  got_location = TRUE;		/* Will be unset by hitting most keys */
  button_handler =
    g_signal_connect (G_OBJECT (gport->drawing_area),
		      "button_press_event",
		      G_CALLBACK (loop_button_press_cb), &loop);
  key_handler =
    g_signal_connect (G_OBJECT (gport->top_window),
		      "key_press_event",
		      G_CALLBACK (loop_key_press_cb), &loop);

  loop = g_main_loop_new (NULL, FALSE);

  GDK_THREADS_LEAVE ();
  g_main_loop_run (loop);
  GDK_THREADS_ENTER ();

  g_main_loop_unref (loop);

  g_signal_handler_disconnect (gport->drawing_area, button_handler);
  g_signal_handler_disconnect (gport->top_window, key_handler);

  ghid_interface_input_signals_connect ();	/* return to normal */
  ghid_interface_set_sensitive (TRUE);

  notify_crosshair_change (false);
  Crosshair.AttachedObject.State = oldObjState;
  Crosshair.AttachedLine.State = oldLineState;
  Crosshair.AttachedBox.State = oldBoxState;
  notify_crosshair_change (true);
  ghid_restore_cursor ();

  ghid_set_status_line_label ();

  return got_location;
}
Example #3
0
  /* This is the command entry function called from ActionCommand() when
     |  ghidgui->use_command_window is FALSE.  The command_combo_box is already
     |  packed into the status line label hbox in this case.
   */
gchar *
ghid_command_entry_get (gchar * prompt, gchar * command)
{
  gchar *s;
  gint escape_sig_id;
  GHidPort *out = &ghid_port;

  /* If this is the first user command entry, we have to create the
     |  command_combo_box and pack it into the status_line_hbox.
   */
  if (!ghidgui->command_combo_box)
    {
      command_combo_box_entry_create ();
      gtk_box_pack_start (GTK_BOX (ghidgui->status_line_hbox),
			  ghidgui->command_combo_box, FALSE, FALSE, 0);
    }

  /* Make the prompt bold and set the label before showing the combo to
     |  avoid window resizing wider.
   */
  s = g_strdup_printf ("<b>%s</b>", prompt ? prompt : "");
  ghid_status_line_set_text (s);
  g_free (s);

  /* Flag so output drawing area won't try to get focus away from us and
     |  so resetting the status line label can be blocked when resize
     |  callbacks are invokded from the resize caused by showing the combo box.
   */
  ghidgui->command_entry_status_line_active = TRUE;

  gtk_entry_set_text (ghidgui->command_entry, command ? command : "");
  gtk_widget_show_all (ghidgui->command_combo_box);

  /* Remove the top window accel group so keys intended for the entry
     |  don't get intercepted by the menu system.  Set the interface
     |  insensitive so all the user can do is enter a command, grab focus
     |  and connect a handler to look for the escape key.
   */
  ghid_remove_accel_groups (GTK_WINDOW (gport->top_window), ghidgui);
  ghid_interface_input_signals_disconnect ();
  ghid_interface_set_sensitive (FALSE);
  gtk_widget_grab_focus (GTK_WIDGET (ghidgui->command_entry));
  escape_sig_id = g_signal_connect (G_OBJECT (ghidgui->command_entry),
				    "key_press_event",
				    G_CALLBACK (command_escape_cb), NULL);

  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);

  g_main_loop_unref (loop);
  loop = NULL;

  ghidgui->command_entry_status_line_active = FALSE;

  /* Restore the damage we did before entering the loop.
   */
  g_signal_handler_disconnect (ghidgui->command_entry, escape_sig_id);
  ghid_interface_input_signals_connect ();
  ghid_interface_set_sensitive (TRUE);
  ghid_install_accel_groups (GTK_WINDOW (gport->top_window), ghidgui);

  /* Restore the status line label and give focus back to the drawing area
   */
  gtk_widget_hide (ghidgui->command_combo_box);
  gtk_widget_grab_focus (out->drawing_area);

  return command_entered;
}