4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996 Thomas Nau
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* FIXME - rename this file to ghid.h */
25 #ifndef PCB_HID_GTK_GHID_H
26 #define PCB_HID_GTK_GHID_H
31 #include "hid/common/hid_resource.h"
38 #include "ghid-coord-entry.h"
39 #include "ghid-main-menu.h"
40 #include "gui-pinout-preview.h"
43 /* Silk and rats lines are the two additional selectable to draw on.
44 | gui code in gui-top-window.c and group code in misc.c must agree
45 | on what layer is what!
47 #define LAYER_BUTTON_SILK MAX_LAYER
48 #define LAYER_BUTTON_RATS (MAX_LAYER + 1)
49 #define N_SELECTABLE_LAYER_BUTTONS (LAYER_BUTTON_RATS + 1)
51 #define LAYER_BUTTON_PINS (MAX_LAYER + 2)
52 #define LAYER_BUTTON_VIAS (MAX_LAYER + 3)
53 #define LAYER_BUTTON_FARSIDE (MAX_LAYER + 4)
54 #define LAYER_BUTTON_MASK (MAX_LAYER + 5)
55 #define N_LAYER_BUTTONS (MAX_LAYER + 6)
57 /* Go from from the grid units in use (millimeters or mils) to PCB units
59 | PCB keeps values internally higher precision, but gui
60 | widgets (spin buttons, labels, etc) need mils or millimeters.
62 #define FROM_PCB_UNITS(v) coord_to_unit (Settings.grid_unit, v)
63 #define TO_PCB_UNITS(v) unit_to_coord (Settings.grid_unit, v)
65 #define SIDE_X(x) ((gport->view.flip_x ? PCB->MaxWidth - (x) : (x)))
66 #define SIDE_Y(y) ((gport->view.flip_y ? PCB->MaxHeight - (y) : (y)))
68 #define DRAW_X(x) (gint)((SIDE_X(x) - gport->view.x0) / gport->view.coord_per_px)
69 #define DRAW_Y(y) (gint)((SIDE_Y(y) - gport->view.y0) / gport->view.coord_per_px)
71 #define EVENT_TO_PCB_X(x) SIDE_X((gint)((x) * gport->view.coord_per_px + gport->view.x0))
72 #define EVENT_TO_PCB_Y(y) SIDE_Y((gint)((y) * gport->view.coord_per_px + gport->view.y0))
75 * Used to intercept "special" hotkeys that gtk doesn't usually pass
76 * on to the menu hotkeys. We catch them and put them back where we
80 /* The modifier keys */
82 #define GHID_KEY_ALT 0x80
83 #define GHID_KEY_CONTROL 0x40
84 #define GHID_KEY_SHIFT 0x20
87 #define GHID_KEY_TAB 0x01
88 #define GHID_KEY_UP 0x02
89 #define GHID_KEY_DOWN 0x03
90 #define GHID_KEY_LEFT 0x04
91 #define GHID_KEY_RIGHT 0x05
95 GtkActionGroup
*main_actions
,
96 *change_selected_actions
, *displayed_name_actions
;
100 *cursor_position_relative_label
,
101 *cursor_position_absolute_label
,
102 *grid_units_label
, *status_line_hbox
, *command_combo_box
;
103 GtkEntry
*command_entry
;
107 *menu_hbox
, *position_hbox
,
108 *menubar_toolbar_vbox
,
110 GtkWidget
*left_toolbar
;
111 GtkWidget
*grid_units_button
;
112 GtkWidget
*menu_bar
, *layer_selector
, *route_style_selector
;
113 GtkWidget
*mode_toolbar
;
114 GtkWidget
*vbox_middle
;
118 GTimeVal last_seen_mtime
;
120 GtkWidget
*h_range
, *v_range
;
121 GtkObject
*h_adjustment
, *v_adjustment
;
123 GdkPixbuf
*bg_pixbuf
;
125 gchar
*name_label_string
;
127 gboolean adjustment_changed_holdoff
,
128 command_entry_status_line_active
,
131 gboolean config_modified
,
138 gint n_mode_button_columns
,
146 keyref_window_height
,
147 library_window_width
,
148 library_window_height
,
149 netlist_window_height
, history_size
, settings_mode
;
155 extern GhidGui _ghidgui
, *ghidgui
;
159 double coord_per_px
; /* Zoom level described as PCB units per screen pixel */
171 /* The output viewport
175 GtkWidget
*top_window
, /* toplevel widget */
176 *drawing_area
; /* and its drawing area */
177 GdkPixmap
*pixmap
, *mask
;
178 GdkDrawable
*drawable
; /* Current drawable for drawing routines */
181 struct render_priv
*render_priv
;
183 GdkColor bg_color
, offlimits_color
, grid_color
;
185 GdkColormap
*colormap
;
187 GdkCursor
*X_cursor
; /* used X cursor */
188 GdkCursorType X_cursor_shape
; /* and its shape */
190 gboolean has_entered
;
194 Coord pcb_x
, pcb_y
; /* PCB coordinates of the mouse pointer */
195 Coord crosshair_x
, crosshair_y
; /* PCB coordinates of the crosshair */
199 extern GHidPort ghid_port
, *gport
;
204 SHIFT_PRESSED
= M_Shift
,
205 CONTROL_PRESSED
= M_Ctrl
,
206 MOD1_PRESSED
= M_Mod(1),
207 SHIFT_CONTROL_PRESSED
= M_Shift
| M_Ctrl
,
208 SHIFT_MOD1_PRESSED
= M_Shift
| M_Mod(1),
209 CONTROL_MOD1_PRESSED
= M_Ctrl
| M_Mod(1),
210 SHIFT_CONTROL_MOD1_PRESSED
= M_Shift
| M_Ctrl
| M_Mod(1),
223 /* Function prototypes
225 void ghid_parse_arguments (gint
* argc
, gchar
*** argv
);
226 void ghid_do_export (HID_Attr_Val
* options
);
228 void ghid_create_pcb_widgets (void);
229 void ghid_window_set_name_label (gchar
* name
);
230 void ghid_interface_set_sensitive (gboolean sensitive
);
231 void ghid_interface_input_signals_connect (void);
232 void ghid_interface_input_signals_disconnect (void);
234 void ghid_pcb_saved_toggle_states_set (void);
235 void ghid_sync_with_new_layout (void);
237 void ghid_change_selected_update_menu_actions (void);
239 void ghid_config_window_show ();
240 void ghid_config_handle_units_changed (void);
241 void ghid_config_start_backup_timer (void);
242 void ghid_config_text_scale_update (void);
243 void ghid_config_layer_name_update (gchar
* name
, gint layer
);
244 void ghid_config_groups_changed(void);
246 void ghid_config_init (void);
247 void ghid_config_files_write (void);
248 void ghid_config_files_read (gint
* argc
, gchar
*** argv
);
250 void ghid_mode_buttons_update (void);
251 void ghid_pack_mode_buttons(void);
252 void ghid_layer_buttons_update (void);
253 void ghid_layer_buttons_color_update (void);
256 /* gui-misc.c function prototypes
258 void ghid_status_line_set_text (const gchar
* text
);
259 void ghid_cursor_position_label_set_text (gchar
* text
);
260 void ghid_cursor_position_relative_label_set_text (gchar
* text
);
262 void ghid_hand_cursor (void);
263 void ghid_point_cursor (void);
264 void ghid_watch_cursor (void);
265 void ghid_mode_cursor (gint mode
);
266 void ghid_corner_cursor (void);
267 void ghid_restore_cursor (void);
268 void ghid_get_user_xy (const gchar
* msg
);
269 void ghid_create_abort_dialog (gchar
*);
270 gboolean
ghid_check_abort (void);
271 void ghid_end_abort (void);
272 void ghid_get_pointer (gint
*, gint
*);
275 /* gui-output-events.c function prototypes.
277 void ghid_port_ranges_changed (void);
278 void ghid_port_ranges_scale (void);
280 gboolean
ghid_note_event_location (GdkEventButton
* ev
);
281 gboolean
ghid_port_key_press_cb (GtkWidget
* drawing_area
,
282 GdkEventKey
* kev
, gpointer data
);
283 gboolean
ghid_port_key_release_cb (GtkWidget
* drawing_area
,
284 GdkEventKey
* kev
, gpointer data
);
285 gboolean
ghid_port_button_press_cb (GtkWidget
* drawing_area
,
286 GdkEventButton
* ev
, gpointer data
);
287 gboolean
ghid_port_button_release_cb (GtkWidget
* drawing_area
,
288 GdkEventButton
* ev
, gpointer data
);
291 gint
ghid_port_window_enter_cb (GtkWidget
* widget
,
292 GdkEventCrossing
* ev
, GHidPort
* out
);
293 gint
ghid_port_window_leave_cb (GtkWidget
* widget
,
294 GdkEventCrossing
* ev
, GHidPort
* out
);
295 gint
ghid_port_window_motion_cb (GtkWidget
* widget
,
296 GdkEventMotion
* ev
, GHidPort
* out
);
297 gint
ghid_port_window_mouse_scroll_cb (GtkWidget
* widget
,
298 GdkEventScroll
* ev
, GHidPort
* out
);
300 gint
ghid_port_drawing_area_configure_event_cb (GtkWidget
* widget
,
301 GdkEventConfigure
* ev
,
305 /* gui-dialog.c function prototypes.
307 #define GUI_DIALOG_RESPONSE_ALL 1
309 gchar
*ghid_dialog_file_select_open (gchar
* title
, gchar
** path
,
311 GSList
*ghid_dialog_file_select_multiple (gchar
* title
, gchar
** path
,
313 gchar
*ghid_dialog_file_select_save (gchar
* title
, gchar
** path
,
314 gchar
* file
, gchar
* shortcuts
);
315 void ghid_dialog_message (gchar
* message
);
316 gboolean
ghid_dialog_confirm (gchar
* message
, gchar
*cancelmsg
, gchar
*okmsg
);
317 int ghid_dialog_close_confirm (void);
318 #define GUI_DIALOG_CLOSE_CONFIRM_CANCEL 0
319 #define GUI_DIALOG_CLOSE_CONFIRM_NOSAVE 1
320 #define GUI_DIALOG_CLOSE_CONFIRM_SAVE 2
321 gint
ghid_dialog_confirm_all (gchar
* message
);
322 gchar
*ghid_dialog_input (const char * prompt
, const char * initial
);
323 void ghid_dialog_about (void);
325 char * ghid_fileselect (const char *, const char *, char *, char *, const char *, int);
328 /* gui-dialog-print.c */
329 void ghid_dialog_export (void);
330 void ghid_dialog_print (HID
*);
332 int ghid_attribute_dialog (HID_Attribute
*, int, HID_Attr_Val
*, const char *, const char *);
334 /* gui-drc-window.c */
335 void ghid_drc_window_show (gboolean raise
);
336 void ghid_drc_window_reset_message (void);
337 void ghid_drc_window_append_violation (DrcViolationType
*violation
);
338 void ghid_drc_window_append_messagev (const char *fmt
, va_list va
);
339 int ghid_drc_window_throw_dialog (void);
341 /* In gui-top-window.c */
342 void ghid_update_toggle_flags (void);
343 void ghid_notify_save_pcb (const char *file
, bool done
);
344 void ghid_notify_filename_changed (void);
345 void ghid_install_accel_groups (GtkWindow
*window
, GhidGui
*gui
);
346 void ghid_remove_accel_groups (GtkWindow
*window
, GhidGui
*gui
);
347 void make_route_style_buttons (GHidRouteStyleSelector
*rss
);
351 gboolean
dup_string (gchar
** dst
, const gchar
* src
);
352 void free_glist_and_data (GList
** list_head
);
354 ModifierKeysState
ghid_modifier_keys_state (GdkModifierType
*state
);
355 ButtonState
ghid_button_state (GdkModifierType
*state
);
356 gboolean
ghid_is_modifier_key_sym (gint ksym
);
357 gboolean
ghid_control_is_pressed (void);
358 gboolean
ghid_mod1_is_pressed (void);
359 gboolean
ghid_shift_is_pressed (void);
361 void ghid_draw_area_update (GHidPort
* out
, GdkRectangle
* rect
);
362 gchar
*ghid_get_color_name (GdkColor
* color
);
363 void ghid_map_color_string (gchar
* color_string
, GdkColor
* color
);
364 gchar
*ghid_entry_get_text (GtkWidget
* entry
);
365 void ghid_check_button_connected (GtkWidget
* box
, GtkWidget
** button
,
366 gboolean active
, gboolean pack_start
,
367 gboolean expand
, gboolean fill
, gint pad
,
368 void (*cb_func
) (GtkToggleButton
*, gpointer
), gpointer data
,
370 void ghid_button_connected (GtkWidget
* box
, GtkWidget
** button
,
371 gboolean pack_start
, gboolean expand
,
372 gboolean fill
, gint pad
, void (*cb_func
) (gpointer
),
373 gpointer data
, gchar
* string
);
374 void ghid_coord_entry (GtkWidget
* box
, GtkWidget
** coord_entry
, Coord value
,
375 Coord low
, Coord high
, enum ce_step_size step_size
,
376 gint width
, void (*cb_func
) (GHidCoordEntry
*, gpointer
),
377 gpointer data
, gboolean right_align
, gchar
* string
);
378 void ghid_spin_button (GtkWidget
* box
, GtkWidget
** spin_button
,
379 gfloat value
, gfloat low
, gfloat high
, gfloat step0
,
380 gfloat step1
, gint digits
, gint width
,
381 void (*cb_func
) (GtkSpinButton
*, gpointer
), gpointer data
,
382 gboolean right_align
, gchar
* string
);
383 void ghid_table_coord_entry (GtkWidget
* table
, gint row
, gint column
,
384 GtkWidget
** coord_entry
, Coord value
,
385 Coord low
, Coord high
, enum ce_step_size
, gint width
,
386 void (*cb_func
) (GHidCoordEntry
*, gpointer
), gpointer data
,
387 gboolean right_align
, gchar
* string
);
388 void ghid_table_spin_button (GtkWidget
* box
, gint row
, gint column
,
389 GtkWidget
** spin_button
, gfloat value
,
390 gfloat low
, gfloat high
, gfloat step0
,
391 gfloat step1
, gint digits
, gint width
,
392 void (*cb_func
) (GtkSpinButton
*, gpointer
), gpointer data
,
393 gboolean right_align
, gchar
* string
);
395 void ghid_range_control (GtkWidget
* box
, GtkWidget
** scale_res
,
396 gboolean horizontal
, GtkPositionType pos
,
397 gboolean set_draw_value
, gint digits
,
398 gboolean pack_start
, gboolean expand
, gboolean fill
,
399 guint pad
, gfloat value
, gfloat low
, gfloat high
,
400 gfloat step0
, gfloat step1
, void (*cb_func
) (),
402 GtkWidget
*ghid_scrolled_vbox (GtkWidget
* box
, GtkWidget
** scr
,
403 GtkPolicyType h_policy
,
404 GtkPolicyType v_policy
);
405 GtkWidget
*ghid_framed_vbox (GtkWidget
* box
, gchar
* label
,
406 gint frame_border_width
, gboolean frame_expand
,
407 gint vbox_pad
, gint vbox_border_width
);
408 GtkWidget
*ghid_framed_vbox_end (GtkWidget
* box
, gchar
* label
,
409 gint frame_border_width
,
410 gboolean frame_expand
, gint vbox_pad
,
411 gint vbox_border_width
);
412 GtkWidget
*ghid_category_vbox (GtkWidget
* box
, const gchar
* category_header
,
413 gint header_pad
, gint box_pad
,
414 gboolean pack_start
, gboolean bottom_pad
);
415 GtkWidget
*ghid_notebook_page (GtkWidget
* tabs
, char *name
, gint pad
,
417 GtkWidget
*ghid_framed_notebook_page (GtkWidget
* tabs
, char *name
,
418 gint border
, gint frame_border
,
419 gint vbox_pad
, gint vbox_border
);
420 GtkWidget
*ghid_scrolled_text_view (GtkWidget
* box
, GtkWidget
** scr
,
421 GtkPolicyType h_policy
,
422 GtkPolicyType v_policy
);
423 void ghid_text_view_append (GtkWidget
* view
, gchar
* string
);
424 void ghid_text_view_append_strings (GtkWidget
* view
, gchar
** string
,
426 GtkTreeSelection
*ghid_scrolled_selection (GtkTreeView
* treeview
,
428 GtkSelectionMode s_mode
,
429 GtkPolicyType h_policy
,
430 GtkPolicyType v_policy
,
431 void (*func_cb
) (GtkTreeSelection
*, gpointer
), gpointer data
);
433 void ghid_dialog_report (gchar
* title
, gchar
* message
);
434 void ghid_label_set_markup (GtkWidget
* label
, const gchar
* text
);
436 void ghid_set_cursor_position_labels (void);
437 void ghid_set_status_line_label (void);
440 /* gui-netlist-window.c */
441 void ghid_netlist_window_create (GHidPort
* out
);
442 void ghid_netlist_window_show (GHidPort
* out
, gboolean raise
);
443 void ghid_netlist_window_update (gboolean init_nodes
);
445 LibraryMenuType
*ghid_get_net_from_node_name (gchar
* name
, gboolean
);
446 void ghid_netlist_highlight_node (gchar
* name
);
449 /* gui-command-window.c */
450 void ghid_handle_user_command (gboolean raise
);
451 void ghid_command_window_show (gboolean raise
);
452 gchar
*ghid_command_entry_get (gchar
* prompt
, gchar
* command
);
453 void ghid_command_use_command_window_sync (void);
455 /* gui-keyref-window.c */
456 void ghid_keyref_window_show (gboolean raise
);
458 /* gui-library-window.c */
459 void ghid_library_window_create (GHidPort
* out
);
460 void ghid_library_window_show (GHidPort
* out
, gboolean raise
);
463 /* gui-log-window.c */
464 void ghid_log_window_create ();
465 void ghid_log_window_show (gboolean raise
);
466 void ghid_log (const char *fmt
, ...);
467 void ghid_logv (const char *fmt
, va_list args
);
469 /* gui-pinout-window.c */
470 void ghid_pinout_window_show (GHidPort
*out
, ElementType
*Element
);
472 /* gtkhid-gdk.c AND gtkhid-gl.c */
473 int ghid_set_layer (const char *name
, int group
, int empty
);
474 hidGC
ghid_make_gc (void);
475 void ghid_destroy_gc (hidGC
);
476 void ghid_use_mask (enum mask_mode mode
);
477 void ghid_set_color (hidGC gc
, const char *name
);
478 void ghid_set_line_cap (hidGC gc
, EndCapStyle style
);
479 void ghid_set_line_width (hidGC gc
, Coord width
);
480 void ghid_set_draw_xor (hidGC gc
, int _xor
);
481 void ghid_draw_line (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
);
482 void ghid_draw_arc (hidGC gc
, Coord cx
, Coord cy
, Coord xradius
, Coord yradius
,
483 Angle start_angle
, Angle delta_angle
);
484 void ghid_draw_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
);
485 void ghid_fill_circle (hidGC gc
, Coord cx
, Coord cy
, Coord radius
);
486 void ghid_fill_polygon (hidGC gc
, int n_coords
, Coord
*x
, Coord
*y
);
487 void ghid_fill_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
);
488 void ghid_invalidate_lr (int left
, int right
, int top
, int bottom
);
489 void ghid_invalidate_all ();
490 void ghid_notify_crosshair_change (bool changes_complete
);
491 void ghid_notify_mark_change (bool changes_complete
);
492 void ghid_init_renderer (int *, char ***, GHidPort
*);
493 void ghid_shutdown_renderer (GHidPort
*);
494 void ghid_init_drawing_widget (GtkWidget
*widget
, GHidPort
*);
495 void ghid_drawing_area_configure_hook (GHidPort
*port
);
496 void ghid_screen_update (void);
497 gboolean
ghid_drawing_area_expose_cb (GtkWidget
*, GdkEventExpose
*,
499 void ghid_port_drawing_realize_cb (GtkWidget
*, gpointer
);
500 gboolean
ghid_pinout_preview_expose (GtkWidget
* widget
, GdkEventExpose
* ev
);
501 GdkPixmap
*ghid_render_pixmap (int cx
, int cy
, double zoom
,
502 int width
, int height
, int depth
);
503 HID
*ghid_request_debug_draw (void);
504 void ghid_flush_debug_draw (void);
505 void ghid_finish_debug_draw (void);
506 bool ghid_event_to_pcb_coords (int event_x
, int event_y
, Coord
*pcb_x
, Coord
*pcb_y
);
507 bool ghid_pcb_to_event_coords (Coord pcb_x
, Coord pcb_y
, int *event_x
, int *event_y
);
508 void ghid_port_rotate (void *ball
, float *quarternion
, gpointer userdata
);
509 void ghid_view_2d (void *ball
, gboolean view_2d
, gpointer userdata
);
511 void ghid_lead_user_to_location (Coord x
, Coord y
);
512 void ghid_cancel_lead_user (void);
515 void ghid_pan_view_rel (Coord dx
, Coord dy
);
516 void ghid_get_coords (const char *msg
, Coord
*x
, Coord
*y
);
517 gint
PCBChanged (int argc
, char **argv
, Coord x
, Coord y
);
522 extern GdkPixmap
*XC_hand_source
, *XC_hand_mask
;
523 extern GdkPixmap
*XC_lock_source
, *XC_lock_mask
;
524 extern GdkPixmap
*XC_clock_source
, *XC_clock_mask
;
527 /* Coordinate conversions */
528 /* Px converts view->pcb, Vx converts pcb->view */
533 if (gport
->view
.flip_x
)
534 rv
= (PCB
->MaxWidth
- x
- gport
->view
.x0
) / gport
->view
.coord_per_px
+ 0.5;
536 rv
= (x
- gport
->view
.x0
) / gport
->view
.coord_per_px
+ 0.5;
544 if (gport
->view
.flip_y
)
545 rv
= (PCB
->MaxHeight
- y
- gport
->view
.y0
) / gport
->view
.coord_per_px
+ 0.5;
547 rv
= (y
- gport
->view
.y0
) / gport
->view
.coord_per_px
+ 0.5;
554 return z
/ gport
->view
.coord_per_px
+ 0.5;
560 Coord rv
= x
* gport
->view
.coord_per_px
+ gport
->view
.x0
;
561 if (gport
->view
.flip_x
)
562 rv
= PCB
->MaxWidth
- (x
* gport
->view
.coord_per_px
+ gport
->view
.x0
);
569 Coord rv
= y
* gport
->view
.coord_per_px
+ gport
->view
.y0
;
570 if (gport
->view
.flip_y
)
571 rv
= PCB
->MaxHeight
- (y
* gport
->view
.coord_per_px
+ gport
->view
.y0
);
578 return (z
* gport
->view
.coord_per_px
);
581 #endif /* PCB_HID_GTK_GHID_H */