pcb 4.1.1
An interactive printed circuit board layout editor.

ghid-layer-selector.c File Reference

#include <glib.h>
#include <glib-object.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "gtkhid.h"
#include "gui.h"
#include "pcb-printf.h"
#include "ghid-layer-selector.h"
#include "ghid-cell-renderer-visibility.h"
Include dependency graph for ghid-layer-selector.c:

Go to the source code of this file.

Data Structures

struct  _GHidLayerSelector
struct  _GHidLayerSelectorClass
struct  _layer
struct  layer_data

Defines

#define INITIAL_ACTION_MAX   40

Enumerations

enum  { SELECT_LAYER_SIGNAL, TOGGLE_LAYER_SIGNAL, RENAME_LAYER_SIGNAL, LAST_SIGNAL }
 

Signals exposed by the widget.

More...
enum  {
  STRUCT_COL, USER_ID_COL, VISIBLE_COL, COLOR_COL,
  TEXT_COL, FONT_COL, EDITABLE_COL, SELECTABLE_COL,
  SEPARATOR_COL, N_COLS
}
 

Columns used for internal data store.

More...

Functions

static void ghid_layer_selector_finalize (GObject *object)
 Clean up object before garbage collection.
static void menu_pick_cb (GtkRadioAction *action, struct _layer *ldata)
 Callback for menu actions: sync layer selection list, emit signal.
static void g_cclosure_user_marshal_VOID__INT_STRING (GClosure *closure, GValue *return_value G_GNUC_UNUSED, guint n_param_values, const GValue *param_values, gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
static void free_ldata (GHidLayerSelector *ls, struct _layer *ldata)
 Deletes the action and accelerator from a layer.
static void set_visibility (GHidLayerSelector *ls, GtkTreeIter *iter, struct _layer *ldata, gboolean state)
 internal set-visibility function -- emits no signals
static void toggle_visibility (GHidLayerSelector *ls, GtkTreeIter *iter, gboolean emit)
 Flip the visibility state of a given layer.
static gboolean tree_view_separator_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 Decide if a GtkListStore entry is a layer or separator.
static gboolean tree_selection_func (GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean selected, gpointer data)
 Decide if a GtkListStore entry may be selected.
static gboolean button_press_cb (GHidLayerSelector *ls, GdkEventButton *event)
 Callback for mouse-click: toggle visibility.
static void selection_changed_cb (GtkTreeSelection *selection, GHidLayerSelector *ls)
 Callback for layer selection change: sync menu, emit signal.
static void layer_name_editing_started_cb (GtkCellRenderer *renderer, GtkCellEditable *editable, gchar *path, gpointer user_data)
 Callback for when a layer name has been edited.
static void layer_name_editing_canceled_cb (GtkCellRenderer *renderer, gpointer user_data)
 Callback for when layer name editing has been canceled.
static void layer_name_edited_cb (GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer user_data)
 Callback for when a layer name has been edited.
static void menu_view_cb (GtkToggleAction *action, struct _layer *ldata)
 Callback for menu actions: sync layer selection list, emit signal.
static void ghid_layer_selector_init (GHidLayerSelector *ls)
static void ghid_layer_selector_class_init (GHidLayerSelectorClass *klass)
GType ghid_layer_selector_get_type (void)
GtkWidget * ghid_layer_selector_new (void)
 Create a new GHidLayerSelector.
void ghid_layer_selector_add_layer (GHidLayerSelector *ls, gint user_id, const gchar *name, const gchar *color_string, gboolean visible, gboolean selectable, gboolean renameable)
 Add a layer to a GHidLayerSelector.
gint ghid_layer_selector_install_pick_items (GHidLayerSelector *ls, GtkMenuShell *shell, gint pos)
 Install the "Current Layer" menu items for a layer selector.
gint ghid_layer_selector_install_view_items (GHidLayerSelector *ls, GtkMenuShell *shell, gint pos)
 Install the "Shown Layers" menu items for a layer selector.
GtkAccelGroup * ghid_layer_selector_get_accel_group (GHidLayerSelector *ls)
 Returns the GtkAccelGroup of a layer selector.
static gboolean toggle_foreach_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
 used internally
void ghid_layer_selector_toggle_layer (GHidLayerSelector *ls, gint user_id)
 Toggle a layer's visibility.
static gboolean select_foreach_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
 used internally
void ghid_layer_selector_select_layer (GHidLayerSelector *ls, gint user_id)
 Select a layer.
gboolean ghid_layer_selector_select_next_visible (GHidLayerSelector *ls)
 Selects the next visible layer.
void ghid_layer_selector_make_selected_visible (GHidLayerSelector *ls)
 Makes the selected layer visible.
void ghid_layer_selector_update_colors (GHidLayerSelector *ls, const gchar *(*callback)(int user_id))
 Sets the colors of all layers in a layer-selector.
void ghid_layer_selector_delete_layers (GHidLayerSelector *ls, gboolean(*callback)(int user_id))
 Deletes layers from a layer selector.
void ghid_layer_selector_show_layers (GHidLayerSelector *ls, gboolean(*callback)(int user_id))
 Sets the visibility toggle-state of all layers.

Variables

static GtkTreeView * ghid_layer_selector_parent_class
static guint ghid_layer_selector_signals [LAST_SIGNAL] = { 0 }

Define Documentation

#define INITIAL_ACTION_MAX   40

Definition at line 21 of file ghid-layer-selector.c.


Enumeration Type Documentation

anonymous enum

Signals exposed by the widget.

Enumerator:
SELECT_LAYER_SIGNAL 
TOGGLE_LAYER_SIGNAL 
RENAME_LAYER_SIGNAL 
LAST_SIGNAL 

Definition at line 29 of file ghid-layer-selector.c.

anonymous enum

Columns used for internal data store.

Enumerator:
STRUCT_COL 
USER_ID_COL 
VISIBLE_COL 
COLOR_COL 
TEXT_COL 
FONT_COL 
EDITABLE_COL 
SELECTABLE_COL 
SEPARATOR_COL 
N_COLS 

Definition at line 37 of file ghid-layer-selector.c.


Function Documentation

static gboolean button_press_cb ( GHidLayerSelector ls,
GdkEventButton *  event 
) [static]

Callback for mouse-click: toggle visibility.

Definition at line 226 of file ghid-layer-selector.c.

References FALSE, _GHidLayerSelector::list_store, SELECTABLE_COL, SEPARATOR_COL, toggle_visibility(), TRUE, and _GHidLayerSelector::visibility_column.

Referenced by ghid_layer_selector_init().

Here is the call graph for this function:

static void free_ldata ( GHidLayerSelector ls,
struct _layer ldata 
) [static]
static void g_cclosure_user_marshal_VOID__INT_STRING ( GClosure *  closure,
GValue *return_value  G_GNUC_UNUSED,
guint  n_param_values,
const GValue *  param_values,
gpointer invocation_hint  G_GNUC_UNUSED,
gpointer  marshal_data 
) [static]

Definition at line 92 of file ghid-layer-selector.c.

References callback().

Referenced by ghid_layer_selector_class_init().

Here is the call graph for this function:

void ghid_layer_selector_add_layer ( GHidLayerSelector ls,
gint  user_id,
const gchar *  name,
const gchar *  color_string,
gboolean  visible,
gboolean  selectable,
gboolean  renameable 
)

Add a layer to a GHidLayerSelector.

Function Description
This function adds an entry to a GHidLayerSelector, which will appear in the layer-selection list as well as visibility and selection menus (assuming this is a selectable layer). For the first 20 layers, keyboard accelerators will be added for selection/visibility toggling.

If the user_id passed already exists in the layer selector, that layer will have its data overwritten with the new stuff.

Parameters:
[in]lsThe selector to be acted on
[in]user_idAn ID used to identify the layer; will be passed to selection/visibility callbacks
[in]nameThe name of the layer; will be used on selector and menus
[in]color_stringThe color of the layer on selector
[in]visibileWhether the layer is visible
[in]selectableWhether the layer appears in menus and can be selected
[in]renameableWhether the layer is renameable

Definition at line 582 of file ghid-layer-selector.c.

References _GHidLayerSelector::accel_available, _GHidLayerSelector::accel_group, _layer::accel_index, action, _GHidLayerSelector::action_group, COLOR_COL, EDITABLE_COL, FALSE, FONT_COL, free_ldata(), _GHidLayerSelector::list_store, menu_pick_cb(), menu_view_cb(), _GHidLayerSelector::n_actions, _layer::pick_action, _layer::pick_item, _GHidLayerSelector::radio_group, _layer::rref, SELECTABLE_COL, SEPARATOR_COL, STRUCT_COL, TEXT_COL, TRUE, USER_ID_COL, _layer::view_action, _layer::view_item, and VISIBLE_COL.

Referenced by make_layer_buttons(), and make_virtual_layer_buttons().

Here is the call graph for this function:

static void ghid_layer_selector_class_init ( GHidLayerSelectorClass klass) [static]
void ghid_layer_selector_delete_layers ( GHidLayerSelector ls,
gboolean(*)(int user_id)  callback 
)

Deletes layers from a layer selector.

Function Description
Deletes layers according to a callback function: a return value of TRUE means delete, FALSE means leave it alone. Do not try to delete all layers using this function; with nothing left to select, pcb will likely go into an infinite recursion between hid_action() and g_signal().

Separators will be deleted if the layer AFTER them is deleted.

Parameters:
[in]lsThe selector to be acted on
[in]callbackTakes the user_id of the layer and returns a boolean

Definition at line 1022 of file ghid-layer-selector.c.

References callback(), FALSE, free_ldata(), _GHidLayerSelector::list_store, SEPARATOR_COL, STRUCT_COL, and USER_ID_COL.

Referenced by ghid_layer_buttons_update().

Here is the call graph for this function:

static void ghid_layer_selector_finalize ( GObject *  object) [static]

Clean up object before garbage collection.

Definition at line 502 of file ghid-layer-selector.c.

References _GHidLayerSelector::accel_group, _GHidLayerSelector::action_group, free_ldata(), ghid_layer_selector_parent_class, _GHidLayerSelector::list_store, and STRUCT_COL.

Referenced by ghid_layer_selector_class_init().

Here is the call graph for this function:

GtkAccelGroup* ghid_layer_selector_get_accel_group ( GHidLayerSelector ls)

Returns the GtkAccelGroup of a layer selector.

Function Description
Parameters:
[in]lsThe selector to be acted on
Returns:
the accel group of the selector

Definition at line 820 of file ghid-layer-selector.c.

References _GHidLayerSelector::accel_group.

Referenced by ghid_install_accel_groups(), and ghid_remove_accel_groups().

GType ghid_layer_selector_get_type ( void  )

Definition at line 525 of file ghid-layer-selector.c.

References ghid_layer_selector_class_init(), and ghid_layer_selector_init().

Here is the call graph for this function:

gint ghid_layer_selector_install_pick_items ( GHidLayerSelector ls,
GtkMenuShell *  shell,
gint  pos 
)

Install the "Current Layer" menu items for a layer selector.

Function Description
Takes a menu shell and installs menu items for layer selection in the shell, at the given position.
Parameters:
[in]lsThe selector to be acted on
[in]shellThe menu to install the items in
[in]posThe position in the menu to install items
Returns:
the number of items installed

Definition at line 750 of file ghid-layer-selector.c.

References action, _GHidLayerSelector::list_store, n, _layer::pick_action, _layer::pick_item, and STRUCT_COL.

Referenced by ghid_main_menu_install_layer_selector().

gint ghid_layer_selector_install_view_items ( GHidLayerSelector ls,
GtkMenuShell *  shell,
gint  pos 
)

Install the "Shown Layers" menu items for a layer selector.

Function Description
Takes a menu shell and installs menu items for layer selection in the shell, at the given position.
Parameters:
[in]lsThe selector to be acted on
[in]shellThe menu to install the items in
[in]posThe position in the menu to install items
Returns:
the number of items installed

Definition at line 787 of file ghid-layer-selector.c.

References action, _GHidLayerSelector::list_store, n, STRUCT_COL, _layer::view_action, and _layer::view_item.

Referenced by ghid_main_menu_install_layer_selector().

void ghid_layer_selector_make_selected_visible ( GHidLayerSelector ls)

Makes the selected layer visible.

Function Description
Used to ensure hidden layers are not active; un-hides the currently selected layer.
Parameters:
[in]lsThe selector to be acted on

Definition at line 967 of file ghid-layer-selector.c.

References FALSE, _GHidLayerSelector::list_store, _GHidLayerSelector::selection, toggle_visibility(), and VISIBLE_COL.

Here is the call graph for this function:

GtkWidget* ghid_layer_selector_new ( void  )

Create a new GHidLayerSelector.

Returns:
a freshly-allocated GHidLayerSelector.

Definition at line 558 of file ghid-layer-selector.c.

References GHID_LAYER_SELECTOR_TYPE.

Referenced by ghid_build_pcb_top_window().

void ghid_layer_selector_select_layer ( GHidLayerSelector ls,
gint  user_id 
)

Select a layer.

Function Description
Select the layer indicated by user_id, emitting a layer-select signal.
Parameters:
[in]lsThe selector to be acted on
[in]user_idThe ID of the layer to be affected

Definition at line 891 of file ghid-layer-selector.c.

References _GHidLayerSelector::list_store, layer_data::ls, select_foreach_func(), and layer_data::user_id.

Referenced by ghid_layer_buttons_update(), and SelectLayer().

Here is the call graph for this function:

gboolean ghid_layer_selector_select_next_visible ( GHidLayerSelector ls)

Selects the next visible layer.

Function Description
Used to ensure hidden layers are not active; if the active layer is visible, this function is a noop. Otherwise, it will look for the next layer that IS visible, and select that. Failing that, it will return FALSE.
Parameters:
[in]lsThe selector to be acted on
Returns:
TRUE on success, FALSE if all selectable layers are hidden

Definition at line 914 of file ghid-layer-selector.c.

References FALSE, _GHidLayerSelector::list_store, SELECTABLE_COL, _GHidLayerSelector::selection, selection_changed_cb(), TRUE, and VISIBLE_COL.

Referenced by layer_selector_toggle_callback().

Here is the call graph for this function:

void ghid_layer_selector_show_layers ( GHidLayerSelector ls,
gboolean(*)(int user_id)  callback 
)

Sets the visibility toggle-state of all layers.

Function Description
Shows layers according to a callback function: a return value of TRUE means show, FALSE means hide.
Parameters:
[in]lsThe selector to be acted on
[in]callbackTakes the user_id of the layer and returns a boolean

Definition at line 1075 of file ghid-layer-selector.c.

References callback(), _GHidLayerSelector::list_store, SEPARATOR_COL, set_visibility(), STRUCT_COL, and USER_ID_COL.

Referenced by LayersChanged().

Here is the call graph for this function:

void ghid_layer_selector_toggle_layer ( GHidLayerSelector ls,
gint  user_id 
)

Toggle a layer's visibility.

Function Description
Toggle the layer indicated by user_id, emitting a layer-toggle signal.
Parameters:
[in]lsThe selector to be acted on
[in]user_idThe ID of the layer to be affected

Definition at line 855 of file ghid-layer-selector.c.

References _GHidLayerSelector::list_store, layer_data::ls, toggle_foreach_func(), and layer_data::user_id.

Referenced by ToggleView().

Here is the call graph for this function:

void ghid_layer_selector_update_colors ( GHidLayerSelector ls,
const gchar *(*)(int user_id)  callback 
)

Sets the colors of all layers in a layer-selector.

Function Description
Updates the colors of a layer selector via a callback mechanism: the user_id of each layer is passed to the callback function, which returns a color string to update the layer's color, or NULL to leave it alone.
Parameters:
[in]lsThe selector to be acted on
[in]callbackTakes the user_id of the layer and returns a color string

Definition at line 991 of file ghid-layer-selector.c.

References callback(), COLOR_COL, _GHidLayerSelector::list_store, layer_data::user_id, and USER_ID_COL.

Referenced by ghid_layer_buttons_color_update().

Here is the call graph for this function:

static void layer_name_edited_cb ( GtkCellRendererText *  renderer,
gchar *  path,
gchar *  new_text,
gpointer  user_data 
) [static]

Callback for when a layer name has been edited.

Definition at line 319 of file ghid-layer-selector.c.

References ghid_install_accel_groups(), ghid_layer_selector_signals, ghidgui, gport, _GHidLayerSelector::list_store, RENAME_LAYER_SIGNAL, GHidPort::top_window, and USER_ID_COL.

Referenced by ghid_layer_selector_init().

Here is the call graph for this function:

static void layer_name_editing_canceled_cb ( GtkCellRenderer *  renderer,
gpointer  user_data 
) [static]

Callback for when layer name editing has been canceled.

Definition at line 305 of file ghid-layer-selector.c.

References ghid_install_accel_groups(), ghidgui, gport, and GHidPort::top_window.

Referenced by ghid_layer_selector_init().

Here is the call graph for this function:

static void layer_name_editing_started_cb ( GtkCellRenderer *  renderer,
GtkCellEditable *  editable,
gchar *  path,
gpointer  user_data 
) [static]

Callback for when a layer name has been edited.

Definition at line 287 of file ghid-layer-selector.c.

References ghid_remove_accel_groups(), ghidgui, gport, and GHidPort::top_window.

Referenced by ghid_layer_selector_init().

Here is the call graph for this function:

static void menu_pick_cb ( GtkRadioAction *  action,
struct _layer ldata 
) [static]

Callback for menu actions: sync layer selection list, emit signal.

Definition at line 371 of file ghid-layer-selector.c.

References ghid_layer_selector_signals, _layer::rref, SELECT_LAYER_SIGNAL, _GHidLayerSelector::selection, _GHidLayerSelector::selection_changed_sig_id, and USER_ID_COL.

Referenced by ghid_layer_selector_add_layer().

static void menu_view_cb ( GtkToggleAction *  action,
struct _layer ldata 
) [static]

Callback for menu actions: sync layer selection list, emit signal.

Definition at line 351 of file ghid-layer-selector.c.

References ghid_layer_selector_signals, _layer::rref, TOGGLE_LAYER_SIGNAL, USER_ID_COL, and VISIBLE_COL.

Referenced by ghid_layer_selector_add_layer().

static gboolean select_foreach_func ( GtkTreeModel *  model,
GtkTreePath *  path,
GtkTreeIter *  iter,
gpointer  user_data 
) [static]
static void selection_changed_cb ( GtkTreeSelection *  selection,
GHidLayerSelector ls 
) [static]

Callback for layer selection change: sync menu, emit signal.

Definition at line 264 of file ghid-layer-selector.c.

References ghid_layer_selector_signals, _GHidLayerSelector::list_store, _layer::pick_action, SELECT_LAYER_SIGNAL, STRUCT_COL, and USER_ID_COL.

Referenced by ghid_layer_selector_init(), and ghid_layer_selector_select_next_visible().

static void set_visibility ( GHidLayerSelector ls,
GtkTreeIter *  iter,
struct _layer ldata,
gboolean  state 
) [static]

internal set-visibility function -- emits no signals

Definition at line 158 of file ghid-layer-selector.c.

References _GHidLayerSelector::list_store, _layer::view_action, _layer::view_item, and VISIBLE_COL.

Referenced by ghid_layer_selector_show_layers(), and toggle_visibility().

static gboolean toggle_foreach_func ( GtkTreeModel *  model,
GtkTreePath *  path,
GtkTreeIter *  iter,
gpointer  user_data 
) [static]

used internally

Definition at line 832 of file ghid-layer-selector.c.

References FALSE, layer_data::ls, toggle_visibility(), TRUE, layer_data::user_id, and USER_ID_COL.

Referenced by ghid_layer_selector_toggle_layer().

Here is the call graph for this function:

static void toggle_visibility ( GHidLayerSelector ls,
GtkTreeIter *  iter,
gboolean  emit 
) [static]

Flip the visibility state of a given layer.

Function Description
Changes the internal toggle state and menu checkbox state of the layer pointed to by iter. Emits a toggle-layer signal.
Parameters:
[in]lsThe selector to be acted on
[in]iterA GtkTreeIter pointed at the relevant layer
[in]emitWhether or not to emit a signal

Definition at line 182 of file ghid-layer-selector.c.

References ghid_layer_selector_signals, _GHidLayerSelector::list_store, set_visibility(), STRUCT_COL, TOGGLE_LAYER_SIGNAL, USER_ID_COL, and VISIBLE_COL.

Referenced by button_press_cb(), ghid_layer_selector_make_selected_visible(), and toggle_foreach_func().

Here is the call graph for this function:

static gboolean tree_selection_func ( GtkTreeSelection *  selection,
GtkTreeModel *  model,
GtkTreePath *  path,
gboolean  selected,
gpointer  data 
) [static]

Decide if a GtkListStore entry may be selected.

Definition at line 208 of file ghid-layer-selector.c.

References FALSE, and SELECTABLE_COL.

Referenced by ghid_layer_selector_init().

static gboolean tree_view_separator_func ( GtkTreeModel *  model,
GtkTreeIter *  iter,
gpointer  data 
) [static]

Decide if a GtkListStore entry is a layer or separator.

Definition at line 198 of file ghid-layer-selector.c.

References SEPARATOR_COL.

Referenced by ghid_layer_selector_init().


Variable Documentation

GtkTreeView* ghid_layer_selector_parent_class [static]

Definition at line 50 of file ghid-layer-selector.c.

Referenced by ghid_layer_selector_finalize().