#include "debug.h"
-/*=======================================================================================*/
-/* Private macros and constants. */
-/*=======================================================================================*/
+/*==========================================================================*/
+/* Private macros and constants. */
+/*==========================================================================*/
#define GLABELS_UI_XML GLABELS_UI_DIR "glabels-ui.xml"
-/*=======================================================================================*/
-/* Private types. */
-/*=======================================================================================*/
+/*==========================================================================*/
+/* Private types. */
+/*==========================================================================*/
-/*=======================================================================================*/
-/* Private globals */
-/*=======================================================================================*/
+/*==========================================================================*/
+/* Private globals */
+/*==========================================================================*/
static BonoboUIVerb gl_ui_verbs [] = {
- BONOBO_UI_VERB ("FileNew", gl_cmd_file_new),
- BONOBO_UI_VERB ("FileOpen", gl_cmd_file_open),
- BONOBO_UI_VERB ("FileSave", gl_cmd_file_save),
- BONOBO_UI_VERB ("FileSaveAs", gl_cmd_file_save_as),
- BONOBO_UI_VERB ("FilePrint", gl_cmd_file_print),
- BONOBO_UI_VERB ("FileClose", gl_cmd_file_close),
- BONOBO_UI_VERB ("FileExit", gl_cmd_file_exit),
- BONOBO_UI_VERB ("EditCut", gl_cmd_edit_cut),
- BONOBO_UI_VERB ("EditCopy", gl_cmd_edit_copy),
- BONOBO_UI_VERB ("EditPaste", gl_cmd_edit_paste),
- BONOBO_UI_VERB ("EditDelete", gl_cmd_edit_delete),
- BONOBO_UI_VERB ("EditSelectAll", gl_cmd_edit_select_all),
- BONOBO_UI_VERB ("EditUnSelectAll", gl_cmd_edit_unselect_all),
- BONOBO_UI_VERB ("ToolsArrow", gl_tools_arrow),
- BONOBO_UI_VERB ("ToolsText", gl_tools_text),
- BONOBO_UI_VERB ("ToolsBox", gl_tools_box),
- BONOBO_UI_VERB ("ToolsLine", gl_tools_line),
- BONOBO_UI_VERB ("ToolsEllipse", gl_tools_ellipse),
- BONOBO_UI_VERB ("ToolsImage", gl_tools_image),
- BONOBO_UI_VERB ("ToolsBarcode", gl_tools_barcode),
- BONOBO_UI_VERB ("ToolsZoomIn", gl_tools_zoomin),
- BONOBO_UI_VERB ("ToolsZoomOut", gl_tools_zoomout),
- BONOBO_UI_VERB ("ToolsZoom1to1", gl_tools_zoom1to1),
- BONOBO_UI_VERB ("ToolsMergeProperties", gl_tools_merge_properties),
+ BONOBO_UI_VERB ("FileNew", gl_cmd_file_new),
+ BONOBO_UI_VERB ("FileOpen", gl_cmd_file_open),
+ BONOBO_UI_VERB ("FileSave", gl_cmd_file_save),
+ BONOBO_UI_VERB ("FileSaveAs", gl_cmd_file_save_as),
+ BONOBO_UI_VERB ("FilePrint", gl_cmd_file_print),
+ BONOBO_UI_VERB ("FileClose", gl_cmd_file_close),
+ BONOBO_UI_VERB ("FileExit", gl_cmd_file_exit),
+ BONOBO_UI_VERB ("EditCut", gl_cmd_edit_cut),
+ BONOBO_UI_VERB ("EditCopy", gl_cmd_edit_copy),
+ BONOBO_UI_VERB ("EditPaste", gl_cmd_edit_paste),
+ BONOBO_UI_VERB ("EditDelete", gl_cmd_edit_delete),
+ BONOBO_UI_VERB ("EditSelectAll", gl_cmd_edit_select_all),
+ BONOBO_UI_VERB ("EditUnSelectAll", gl_cmd_edit_unselect_all),
+ BONOBO_UI_VERB ("ToolsArrow", gl_tools_arrow),
+ BONOBO_UI_VERB ("ToolsText", gl_tools_text),
+ BONOBO_UI_VERB ("ToolsBox", gl_tools_box),
+ BONOBO_UI_VERB ("ToolsLine", gl_tools_line),
+ BONOBO_UI_VERB ("ToolsEllipse", gl_tools_ellipse),
+ BONOBO_UI_VERB ("ToolsImage", gl_tools_image),
+ BONOBO_UI_VERB ("ToolsBarcode", gl_tools_barcode),
+ BONOBO_UI_VERB ("ToolsZoomIn", gl_tools_zoomin),
+ BONOBO_UI_VERB ("ToolsZoomOut", gl_tools_zoomout),
+ BONOBO_UI_VERB ("ToolsZoom1to1", gl_tools_zoom1to1),
+ BONOBO_UI_VERB ("ToolsMergeProperties", gl_tools_merge_properties),
BONOBO_UI_VERB ("ToolsObjectProperties", gl_tools_object_properties),
- BONOBO_UI_VERB ("ToolsRaiseObjects", gl_tools_raise_objects),
- BONOBO_UI_VERB ("ToolsLowerObjects", gl_tools_lower_objects),
- BONOBO_UI_VERB ("ToolsRotateLeft", gl_tools_rotate_objects_left),
- BONOBO_UI_VERB ("ToolsRotateRight", gl_tools_rotate_objects_right),
- BONOBO_UI_VERB ("ToolsFlipHorizontal", gl_tools_flip_objects_horiz),
- BONOBO_UI_VERB ("ToolsFlipVertical", gl_tools_flip_objects_vert),
- BONOBO_UI_VERB ("SettingsPreferences", gl_cmd_settings_preferences),
- BONOBO_UI_VERB ("HelpContents", gl_cmd_help_contents),
- BONOBO_UI_VERB ("About", gl_cmd_help_about),
+ BONOBO_UI_VERB ("ToolsRaiseObjects", gl_tools_raise_objects),
+ BONOBO_UI_VERB ("ToolsLowerObjects", gl_tools_lower_objects),
+ BONOBO_UI_VERB ("ToolsRotateLeft", gl_tools_rotate_objects_left),
+ BONOBO_UI_VERB ("ToolsRotateRight", gl_tools_rotate_objects_right),
+ BONOBO_UI_VERB ("ToolsFlipHorizontal", gl_tools_flip_objects_horiz),
+ BONOBO_UI_VERB ("ToolsFlipVertical", gl_tools_flip_objects_vert),
+ BONOBO_UI_VERB ("ToolsAlignLeft", gl_tools_align_objects_left),
+ BONOBO_UI_VERB ("ToolsAlignRight", gl_tools_align_objects_right),
+ BONOBO_UI_VERB ("ToolsAlignHCenter", gl_tools_align_objects_hcenter),
+ BONOBO_UI_VERB ("ToolsAlignTop", gl_tools_align_objects_top),
+ BONOBO_UI_VERB ("ToolsAlignBottom", gl_tools_align_objects_bottom),
+ BONOBO_UI_VERB ("ToolsAlignVCenter", gl_tools_align_objects_vcenter),
+ BONOBO_UI_VERB ("SettingsPreferences", gl_cmd_settings_preferences),
+ BONOBO_UI_VERB ("HelpContents", gl_cmd_help_contents),
+ BONOBO_UI_VERB ("About", gl_cmd_help_about),
BONOBO_UI_VERB_END
};
"/commands/ToolsRotateRight",
"/commands/ToolsFlipHorizontal",
"/commands/ToolsFlipVertical",
+ "/commands/ToolsAlignLeft",
+ "/commands/ToolsAlignRight",
+ "/commands/ToolsAlignHCenter",
+ "/commands/ToolsAlignTop",
+ "/commands/ToolsAlignBottom",
+ "/commands/ToolsAlignVCenter",
"/menu/Objects/CreateObjects",
"/menu/Objects/Order",
"/menu/Objects/RotateFlip",
+ "/menu/Objects/Align",
"/commands/ViewGrid",
"/commands/ViewMarkup",
NULL
};
+static gchar* multi_selection_verbs [] = {
+ "/commands/ToolsAlignLeft",
+ "/commands/ToolsAlignRight",
+ "/commands/ToolsAlignHCenter",
+ "/commands/ToolsAlignTop",
+ "/commands/ToolsAlignBottom",
+ "/commands/ToolsAlignVCenter",
+ "/menu/Objects/Align",
-/*=======================================================================================*/
-/* Local function prototypes */
-/*=======================================================================================*/
+ NULL
+};
+
+
+/*==========================================================================*/
+/* Local function prototypes */
+/*==========================================================================*/
static void view_menu_item_toggled_cb (BonoboUIComponent *ui_component,
const char *path,
atomic_selection_verbs,
gl_view_is_selection_atomic (view));
+ set_verb_list_sensitive (ui_component,
+ multi_selection_verbs,
+ !gl_view_is_selection_empty (view)
+ && !gl_view_is_selection_atomic (view));
+
bonobo_ui_component_thaw (ui_component, NULL);
gl_debug (DEBUG_UI, "END");
atomic_selection_verbs,
gl_view_is_selection_atomic (view));
+ set_verb_list_sensitive (ui_component,
+ multi_selection_verbs,
+ !gl_view_is_selection_empty (view)
+ && !gl_view_is_selection_atomic (view));
+
bonobo_ui_component_thaw (ui_component, NULL);
gl_debug (DEBUG_UI, "END");
void
gl_view_raise_selection (glView *view)
{
- GList *p;
- glViewObject *view_object;
- glLabelObject *label_object;
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
gl_debug (DEBUG_VIEW, "START");
for (p = view->selected_object_list; p != NULL; p = p->next) {
view_object = GL_VIEW_OBJECT (p->data);
- label_object = gl_view_object_get_object (view_object);
- gl_label_object_raise_to_top (label_object);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_raise_to_top (object);
}
gl_debug (DEBUG_VIEW, "END");
void
gl_view_lower_selection (glView *view)
{
- GList *p;
- glViewObject *view_object;
- glLabelObject *label_object;
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
gl_debug (DEBUG_VIEW, "START");
for (p = view->selected_object_list; p != NULL; p = p->next) {
view_object = GL_VIEW_OBJECT (p->data);
- label_object = gl_view_object_get_object (view_object);
- gl_label_object_lower_to_bottom (label_object);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_lower_to_bottom (object);
}
gl_debug (DEBUG_VIEW, "END");
gl_view_rotate_selection (glView *view,
gdouble theta_degs)
{
- GList *p;
- glViewObject *view_object;
- glLabelObject *label_object;
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
gl_debug (DEBUG_VIEW, "START");
for (p = view->selected_object_list; p != NULL; p = p->next) {
view_object = GL_VIEW_OBJECT (p->data);
- label_object = gl_view_object_get_object (view_object);
- gl_label_object_rotate (label_object, theta_degs);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_rotate (object, theta_degs);
}
gl_debug (DEBUG_VIEW, "END");
void
gl_view_flip_selection_horiz (glView *view)
{
- GList *p;
- glViewObject *view_object;
- glLabelObject *label_object;
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
gl_debug (DEBUG_VIEW, "START");
for (p = view->selected_object_list; p != NULL; p = p->next) {
view_object = GL_VIEW_OBJECT (p->data);
- label_object = gl_view_object_get_object (view_object);
- gl_label_object_flip_horiz (label_object);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_flip_horiz (object);
}
gl_debug (DEBUG_VIEW, "END");
void
gl_view_flip_selection_vert (glView *view)
{
- GList *p;
- glViewObject *view_object;
- glLabelObject *label_object;
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ g_return_if_fail (GL_IS_VIEW (view));
+
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_flip_vert (object);
+ }
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+/*****************************************************************************/
+/* Align selected objects to left most edge. */
+/*****************************************************************************/
+void
+gl_view_align_selection_left (glView *view)
+{
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
+ gdouble dx, x1min, x1, y1, x2, y2;
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ g_return_if_fail (GL_IS_VIEW (view));
+
+ g_return_if_fail (!gl_view_is_selection_empty (view) &&
+ !gl_view_is_selection_atomic (view));
+
+ /* find left most edge */
+ p = view->selected_object_list;
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1min, &y1, &x2, &y2);
+ for (p = p->next; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ if ( x1 < x1min ) x1min = x1;
+ }
+
+ /* now adjust the object positions to line up the left edges */
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dx = x1min - x1;
+ gl_label_object_set_position_relative (object, dx, 0.0);
+ }
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+
+/*****************************************************************************/
+/* Align selected objects to right most edge. */
+/*****************************************************************************/
+void
+gl_view_align_selection_right (glView *view)
+{
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
+ gdouble dx, x2max, x1, y1, x2, y2;
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ g_return_if_fail (GL_IS_VIEW (view));
+
+ g_return_if_fail (!gl_view_is_selection_empty (view) &&
+ !gl_view_is_selection_atomic (view));
+
+ /* find right most edge */
+ p = view->selected_object_list;
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2max, &y2);
+ for (p = p->next; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ if ( x2 > x2max ) x2max = x2;
+ }
+
+ /* now adjust the object positions to line up the right edges */
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dx = x2max - x2;
+ gl_label_object_set_position_relative (object, dx, 0.0);
+ }
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+/*****************************************************************************/
+/* Align selected objects to horizontal center of objects. */
+/*****************************************************************************/
+void
+gl_view_align_selection_hcenter (glView *view)
+{
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
+ gdouble dx, dxmin, xsum, xavg, xcenter, x1, y1, x2, y2;
+ gint n;
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (GL_IS_VIEW (view));
+ g_return_if_fail (!gl_view_is_selection_empty (view) &&
+ !gl_view_is_selection_atomic (view));
+
+ /* find average center of objects */
+ xsum = 0.0;
+ n = 0;
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ xsum += (x1 + x2) / 2.0;
+ n++;
+ }
+ xavg = xsum / n;
+
+ /* find center of object closest to average center */
+ p = view->selected_object_list;
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dxmin = fabs (xavg - (x1 + x2)/2.0);
+ xcenter = (x1 + x2)/2.0;
+ for (p = p->next; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dx = fabs (xavg - (x1 + x2)/2.0);
+ if ( dx < dxmin ) {
+ dxmin = dx;
+ xcenter = (x1 + x2)/2.0;
+ }
+ }
+
+ /* now adjust the object positions to line up this center */
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dx = xcenter - (x1 + x2)/2.0;
+ gl_label_object_set_position_relative (object, dx, 0.0);
+ }
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+/*****************************************************************************/
+/* Align selected objects to top most edge. */
+/*****************************************************************************/
+void
+gl_view_align_selection_top (glView *view)
+{
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
+ gdouble dy, y1min, x1, y1, x2, y2;
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ g_return_if_fail (GL_IS_VIEW (view));
+
+ g_return_if_fail (!gl_view_is_selection_empty (view) &&
+ !gl_view_is_selection_atomic (view));
+
+ /* find top most edge */
+ p = view->selected_object_list;
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1min, &x2, &y2);
+ for (p = p->next; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ if ( y1 < y1min ) y1min = y1;
+ }
+
+ /* now adjust the object positions to line up the top edges */
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dy = y1min - y1;
+ gl_label_object_set_position_relative (object, 0.0, dy);
+ }
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+/*****************************************************************************/
+/* Align selected objects to bottom most edge. */
+/*****************************************************************************/
+void
+gl_view_align_selection_bottom (glView *view)
+{
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
+ gdouble dy, y2max, x1, y1, x2, y2;
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ g_return_if_fail (GL_IS_VIEW (view));
+
+ g_return_if_fail (!gl_view_is_selection_empty (view) &&
+ !gl_view_is_selection_atomic (view));
+
+ /* find bottom most edge */
+ p = view->selected_object_list;
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2max);
+ for (p = p->next; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ if ( y2 > y2max ) y2max = y2;
+ }
+
+ /* now adjust the object positions to line up the bottom edges */
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dy = y2max - y2;
+ gl_label_object_set_position_relative (object, 0.0, dy);
+ }
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+/*****************************************************************************/
+/* Align selected objects to viertical center of objects. */
+/*****************************************************************************/
+void
+gl_view_align_selection_vcenter (glView *view)
+{
+ GList *p;
+ glViewObject *view_object;
+ glLabelObject *object;
+ gdouble dy, dymin, ysum, yavg, ycenter, x1, y1, x2, y2;
+ gint n;
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ g_return_if_fail (GL_IS_VIEW (view));
+
+ g_return_if_fail (!gl_view_is_selection_empty (view) &&
+ !gl_view_is_selection_atomic (view));
+
+ /* find average center of objects */
+ ysum = 0.0;
+ n = 0;
+ for (p = view->selected_object_list; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ ysum += (y1 + y2) / 2.0;
+ n++;
+ }
+ yavg = ysum / n;
+
+ /* find center of object closest to average center */
+ p = view->selected_object_list;
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dymin = fabs (yavg - (y1 + y2)/2.0);
+ ycenter = (y1 + y2)/2.0;
+ for (p = p->next; p != NULL; p = p->next) {
+ view_object = GL_VIEW_OBJECT (p->data);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dy = fabs (yavg - (y1 + y2)/2.0);
+ if ( dy < dymin ) {
+ dymin = dy;
+ ycenter = (y1 + y2)/2.0;
+ }
+ }
+
+ /* now adjust the object positions to line up this center */
for (p = view->selected_object_list; p != NULL; p = p->next) {
view_object = GL_VIEW_OBJECT (p->data);
- label_object = gl_view_object_get_object (view_object);
- gl_label_object_flip_vert (label_object);
+ object = gl_view_object_get_object (view_object);
+ gl_label_object_get_extent (object, &x1, &y1, &x2, &y2);
+ dy = ycenter - (y1 + y2)/2.0;
+ gl_label_object_set_position_relative (object, 0.0, dy);
}
gl_debug (DEBUG_VIEW, "END");