[dia] element: fix warnings



commit d89a67e0546d2470ca97bcd649a3c5d76c9ca1a9
Author: Zander Brown <zbrown gnome org>
Date:   Fri Mar 27 19:46:45 2020 +0000

    element: fix warnings

 lib/element.c | 469 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 275 insertions(+), 194 deletions(-)
---
diff --git a/lib/element.c b/lib/element.c
index 35053824..35fb6b42 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -102,7 +102,10 @@ element_update_connections_rectangle(Element *elem,
   cps[8].directions = DIR_ALL;
 }
 
+
 /**
+ * element_update_connections_directions:
+ *
  * More elaborate variant to calculate connection point directions
  *
  * It works for any number of connection points.
@@ -130,12 +133,16 @@ element_update_connections_directions (Element         *elem,
   }
 }
 
-/** Update the corner and edge handles of an element to reflect its position
- *  and size.
- * @param elem An element to update.
+
+/**
+ * element_update_handles:
+ * @elem: An element to update.
+ *
+ * Update the corner and edge handles of an element to reflect its position
+ * and size.
  */
 void
-element_update_handles(Element *elem)
+element_update_handles (Element *elem)
 {
   Point *corner = &elem->corner;
 
@@ -172,102 +179,133 @@ element_update_handles(Element *elem)
   elem->resize_handles[7].pos.y = corner->y + elem->height;
 }
 
-/** Handle the moving of one of the elements handles.
- *  This function is suitable for use as the move_handle object operation.
- * @param elem The element whose handle is being moved.
- * @param id The id of the handle.
- * @param to Where it's being moved to.
- * @param cp Ignored
- * @param reason What is causing this handle to be moved (creation, movement..)
- * @param modifiers Any modifier keys (shift, control...) that the user is
- *                  pressing.
- * @return Undo information for this change.
+
+/**
+ * element_move_handle:
+ * @elem: The element whose handle is being moved.
+ * @id: The id of the handle.
+ * @to: Where it's being moved to.
+ * @cp: Ignored
+ * @reason: What is causing this handle to be moved (creation, movement..)
+ * @modifiers: Any modifier keys (shift, control...) that the user is
+ *             pressing.
+ *
+ * Handle the moving of one of the elements handles.
+ * This function is suitable for use as the move_handle object operation.
+ *
+ * Returns: Undo information for this change.
  */
-ObjectChange*
-element_move_handle(Element *elem, HandleId id,
-                   Point *to, ConnectionPoint *cp,
-                   HandleMoveReason reason, ModifierKeys modifiers)
+ObjectChange *
+element_move_handle (Element          *elem,
+                     HandleId          id,
+                     Point            *to,
+                     ConnectionPoint  *cp,
+                     HandleMoveReason  reason,
+                     ModifierKeys      modifiers)
 {
   Point p;
   Point *corner;
 
-  assert(id>=HANDLE_RESIZE_NW);
-  assert(id<=HANDLE_RESIZE_SE);
+  g_return_val_if_fail (id >= HANDLE_RESIZE_NW, NULL);
+  g_return_val_if_fail (id <= HANDLE_RESIZE_SE, NULL);
 
   corner = &elem->corner;
 
   p = *to;
-  point_sub(&p, &elem->corner);
-
-  switch(id) {
-  case HANDLE_RESIZE_NW:
-    if ( to->x < (corner->x+elem->width)) {
-      corner->x += p.x;
-      elem->width -= p.x;
-    }
-    if ( to->y < (corner->y+elem->height)) {
-      corner->y += p.y;
-      elem->height -= p.y;
-    }
-    break;
-  case HANDLE_RESIZE_N:
-    if ( to->y < (corner->y+elem->height)) {
-      corner->y += p.y;
-      elem->height -= p.y;
-    }
-    break;
-  case HANDLE_RESIZE_NE:
-    if (p.x>0.0)
-      elem->width = p.x;
-    if ( to->y < (corner->y+elem->height)) {
-      corner->y += p.y;
-      elem->height -= p.y;
-    }
-    break;
-  case HANDLE_RESIZE_W:
-    if ( to->x < (corner->x+elem->width)) {
-      corner->x += p.x;
-      elem->width -= p.x;
-    }
-    break;
-  case HANDLE_RESIZE_E:
-    if (p.x>0.0)
-      elem->width = p.x;
-    break;
-  case HANDLE_RESIZE_SW:
-    if ( to->x < (corner->x+elem->width)) {
-      corner->x += p.x;
-      elem->width -= p.x;
-    }
-    if (p.y>0.0)
-      elem->height = p.y;
-    break;
-  case HANDLE_RESIZE_S:
-    if (p.y>0.0)
-      elem->height = p.y;
-    break;
-  case HANDLE_RESIZE_SE:
-    if (p.x>0.0)
-      elem->width = p.x;
-    if (p.y>0.0)
-      elem->height = p.y;
-    break;
-  default:
-    g_warning("element_move_handle() called with wrong handle-id\n");
+  point_sub (&p, &elem->corner);
+
+  switch (id) {
+    case HANDLE_RESIZE_NW:
+      if ( to->x < (corner->x+elem->width)) {
+        corner->x += p.x;
+        elem->width -= p.x;
+      }
+      if ( to->y < (corner->y+elem->height)) {
+        corner->y += p.y;
+        elem->height -= p.y;
+      }
+      break;
+    case HANDLE_RESIZE_N:
+      if ( to->y < (corner->y+elem->height)) {
+        corner->y += p.y;
+        elem->height -= p.y;
+      }
+      break;
+    case HANDLE_RESIZE_NE:
+      if (p.x>0.0)
+        elem->width = p.x;
+      if ( to->y < (corner->y+elem->height)) {
+        corner->y += p.y;
+        elem->height -= p.y;
+      }
+      break;
+    case HANDLE_RESIZE_W:
+      if ( to->x < (corner->x+elem->width)) {
+        corner->x += p.x;
+        elem->width -= p.x;
+      }
+      break;
+    case HANDLE_RESIZE_E:
+      if (p.x>0.0) {
+        elem->width = p.x;
+      }
+      break;
+    case HANDLE_RESIZE_SW:
+      if ( to->x < (corner->x+elem->width)) {
+        corner->x += p.x;
+        elem->width -= p.x;
+      }
+      if (p.y>0.0) {
+        elem->height = p.y;
+      }
+      break;
+    case HANDLE_RESIZE_S:
+      if (p.y>0.0) {
+        elem->height = p.y;
+      }
+      break;
+    case HANDLE_RESIZE_SE:
+      if (p.x>0.0) {
+        elem->width = p.x;
+      }
+      if (p.y>0.0) {
+        elem->height = p.y;
+      }
+      break;
+    case HANDLE_MOVE_STARTPOINT:
+    case HANDLE_MOVE_ENDPOINT:
+    case HANDLE_CUSTOM1:
+    case HANDLE_CUSTOM2:
+    case HANDLE_CUSTOM3:
+    case HANDLE_CUSTOM4:
+    case HANDLE_CUSTOM5:
+    case HANDLE_CUSTOM6:
+    case HANDLE_CUSTOM7:
+    case HANDLE_CUSTOM8:
+    case HANDLE_CUSTOM9:
+    default:
+      g_warning ("element_move_handle() called with wrong handle-id\n");
   }
+
   return NULL;
 }
 
-/** Move the handle of an element restricted to a certain aspect ration.
- * @param elem The element to update on
- * @param id The id of the handle being moved
- * @param to Where the handle is being moved to
- * @param aspect_ratio The aspect ratio (width:height) to obey.
- *                     The aspect ratio must not be 0.
+
+/**
+ * element_move_handle_aspect:
+ * @elem: The element to update on
+ * @id: The id of the handle being moved
+ * @to: Where the handle is being moved to
+ * @aspect_ratio: The aspect ratio (width:height) to obey.
+ *                The aspect ratio must not be 0.
+ *
+ * Move the handle of an element restricted to a certain aspect ration.
  */
 void
-element_move_handle_aspect(Element *elem, HandleId id,
-                          Point *to, real aspect_ratio)
+element_move_handle_aspect (Element  *elem,
+                            HandleId  id,
+                            Point    *to,
+                            real      aspect_ratio)
 {
   Point p;
   Point *corner;
@@ -276,13 +314,13 @@ element_move_handle_aspect(Element *elem, HandleId id,
   real move_x=0;
   real move_y=0;
 
-  assert(id>=HANDLE_RESIZE_NW);
-  assert(id<=HANDLE_RESIZE_SE);
+  g_return_if_fail (id >= HANDLE_RESIZE_NW);
+  g_return_if_fail (id <= HANDLE_RESIZE_SE);
 
   corner = &elem->corner;
 
   p = *to;
-  point_sub(&p, &elem->corner);
+  point_sub (&p, &elem->corner);
 
   width = elem->width;
   height = elem->height;
@@ -291,53 +329,64 @@ element_move_handle_aspect(Element *elem, HandleId id,
   new_height = 0.0;
 
 
-  switch(id) {
-  case HANDLE_RESIZE_NW:
-    new_width = width - p.x;
-    new_height = height - p.y;
-    move_x = 1.0;
-    move_y = 1.0;
-    break;
-  case HANDLE_RESIZE_N:
-    new_height = height - p.y;
-    move_y = 1.0;
-    move_x = 0.5;
-    break;
-  case HANDLE_RESIZE_NE:
-    new_width = p.x;
-    new_height = height - p.y;
-    move_x = 0.0;
-    move_y = 1.0;
-    break;
-  case HANDLE_RESIZE_W:
-    new_width = width - p.x;
-    move_x = 1.0;
-    move_y = 0.5;
-    break;
-  case HANDLE_RESIZE_E:
-    new_width = p.x;
-    move_x = 0.0;
-    move_y = 0.5;
-    break;
-  case HANDLE_RESIZE_SW:
-    new_width = width - p.x;
-    new_height = p.y;
-    move_x = 1.0;
-    move_y = 0.0;
-    break;
-  case HANDLE_RESIZE_S:
-    new_height = p.y;
-    move_x = 0.5;
-    move_y = 0.0;
-    break;
-  case HANDLE_RESIZE_SE:
-    new_width = p.x;
-    new_height = p.y;
-    move_x = 0.0;
-    move_y = 0.0;
-    break;
-  default:
-    g_warning("element_move_handle() called with wrong handle-id\n");
+  switch (id) {
+    case HANDLE_RESIZE_NW:
+      new_width = width - p.x;
+      new_height = height - p.y;
+      move_x = 1.0;
+      move_y = 1.0;
+      break;
+    case HANDLE_RESIZE_N:
+      new_height = height - p.y;
+      move_y = 1.0;
+      move_x = 0.5;
+      break;
+    case HANDLE_RESIZE_NE:
+      new_width = p.x;
+      new_height = height - p.y;
+      move_x = 0.0;
+      move_y = 1.0;
+      break;
+    case HANDLE_RESIZE_W:
+      new_width = width - p.x;
+      move_x = 1.0;
+      move_y = 0.5;
+      break;
+    case HANDLE_RESIZE_E:
+      new_width = p.x;
+      move_x = 0.0;
+      move_y = 0.5;
+      break;
+    case HANDLE_RESIZE_SW:
+      new_width = width - p.x;
+      new_height = p.y;
+      move_x = 1.0;
+      move_y = 0.0;
+      break;
+    case HANDLE_RESIZE_S:
+      new_height = p.y;
+      move_x = 0.5;
+      move_y = 0.0;
+      break;
+    case HANDLE_RESIZE_SE:
+      new_width = p.x;
+      new_height = p.y;
+      move_x = 0.0;
+      move_y = 0.0;
+      break;
+    case HANDLE_MOVE_STARTPOINT:
+    case HANDLE_MOVE_ENDPOINT:
+    case HANDLE_CUSTOM1:
+    case HANDLE_CUSTOM2:
+    case HANDLE_CUSTOM3:
+    case HANDLE_CUSTOM4:
+    case HANDLE_CUSTOM5:
+    case HANDLE_CUSTOM6:
+    case HANDLE_CUSTOM7:
+    case HANDLE_CUSTOM8:
+    case HANDLE_CUSTOM9:
+    default:
+      g_warning ("element_move_handle() called with wrong handle-id\n");
   }
 
   /* Which of the two versions to use: */
@@ -359,29 +408,34 @@ element_move_handle_aspect(Element *elem, HandleId id,
   elem->height = new_height;
 }
 
-/** Initialization function for element objects.
- *  An element must have at least 8 handles and 9 connectionpoints.
- * @param elem The element to initialize.  This function will call
- *             object_init() on the element.
- * @param num_handles The number of handles to set up (>= 8).  The handles
- *                    will be initialized by this function.
- * @param num_connections The number of connectionpoints to set up (>= 9).
- *                        The connectionpoints will <em>not</em> be
- *                        initialized by this function.
+
+/**
+ * element_init:
+ * @elem: The element to initialize. This function will call
+ *        object_init() on the element.
+ * @num_handles: The number of handles to set up (>= 8). The handles
+ *               will be initialized by this function.
+ * @num_connections: The number of connectionpoints to set up (>= 9).
+ *                   The connectionpoints will <em>not</em> be
+ *                   initialized by this function.
+ *
+ * Initialization function for element objects.
+ *
+ * An element must have at least 8 handles and 9 connectionpoints.
  */
 void
-element_init(Element *elem, int num_handles, int num_connections)
+element_init (Element *elem, int num_handles, int num_connections)
 {
   DiaObject *obj;
   int i;
 
   obj = &elem->object;
 
-  assert(num_handles>=8);
+  g_return_if_fail (num_handles >= 8);
 
-  object_init(obj, num_handles, num_connections);
+  object_init (obj, num_handles, num_connections);
 
-  for (i=0;i<8;i++) {
+  for (i = 0; i < 8;i ++) {
     obj->handles[i] = &elem->resize_handles[i];
     obj->handles[i]->connect_type = HANDLE_NONCONNECTABLE;
     obj->handles[i]->connected_to = NULL;
@@ -389,13 +443,18 @@ element_init(Element *elem, int num_handles, int num_connections)
   }
 }
 
-/** Copy an element, initializing the handles.
- *  This function will in turn copy the underlying object.
- * @paramm from An element to copy from.
- * @param to An element (already allocated) to copy to.
+
+/**
+ * element_copy:
+ * @from: An element to copy from.
+ * @to: An element (already allocated) to copy to.
+ *
+ * Copy an element, initializing the handles.
+ *
+ * This function will in turn copy the underlying object.
  */
 void
-element_copy(Element *from, Element *to)
+element_copy (Element *from, Element *to)
 {
   DiaObject *toobj, *fromobj;
   int i;
@@ -403,73 +462,89 @@ element_copy(Element *from, Element *to)
   fromobj = &from->object;
   toobj = &to->object;
 
-  object_copy(fromobj, toobj);
+  object_copy (fromobj, toobj);
 
   to->corner = from->corner;
   to->width = from->width;
   to->height = from->height;
 
-  for (i=0;i<8;i++) {
+  for (i = 0; i < 8; i++) {
     to->resize_handles[i] = from->resize_handles[i];
     to->resize_handles[i].connected_to = NULL;
     toobj->handles[i] = &to->resize_handles[i];
   }
-  memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
+
+  memcpy (&to->extra_spacing,
+          &from->extra_spacing,
+          sizeof (to->extra_spacing));
 }
 
-/** Destroy an elements private information.
- *  This function will in turn call object_destroy.
- * @param elem The element to destroy.  It will <em>not</em> be deallocated
- *             by this call, but will not be valid afterwards.
+
+/**
+ * element_destroy:
+ * @elem: The element to destroy.  It will <em>not</em> be deallocated
+ *        by this call, but will not be valid afterwards.
+ *
+ * Destroy an elements private information.
+ *
+ * This function will in turn call object_destroy().
  */
 void
-element_destroy(Element *elem)
+element_destroy (Element *elem)
 {
-  object_destroy(&elem->object);
+  object_destroy (&elem->object);
 }
 
-/** Save the element-specific parts of this element to XML.
- * @param elem
- * @param obj_node
+
+/**
+ * element_save:
+ * @elem:
+ * @obj_node:
+ *
+ * Save the element-specific parts of this element to XML.
  */
 void
-element_save(Element *elem, ObjectNode obj_node, DiaContext *ctx)
+element_save (Element *elem, ObjectNode obj_node, DiaContext *ctx)
 {
-  object_save(&elem->object, obj_node, ctx);
-
-  data_add_point(new_attribute(obj_node, "elem_corner"),
-                &elem->corner, ctx);
-  data_add_real(new_attribute(obj_node, "elem_width"),
-                elem->width, ctx);
-  data_add_real(new_attribute(obj_node, "elem_height"),
-                elem->height, ctx);
+  object_save (DIA_OBJECT (elem), obj_node, ctx);
+
+  data_add_point (new_attribute (obj_node, "elem_corner"),
+                  &elem->corner, ctx);
+  data_add_real (new_attribute (obj_node, "elem_width"),
+                 elem->width, ctx);
+  data_add_real (new_attribute (obj_node, "elem_height"),
+                 elem->height, ctx);
 }
 
+
 void
-element_load(Element *elem, ObjectNode obj_node, DiaContext *ctx)
+element_load (Element *elem, ObjectNode obj_node, DiaContext *ctx)
 {
   AttributeNode attr;
 
-  object_load(&elem->object, obj_node, ctx);
+  object_load (&elem->object, obj_node, ctx);
 
   elem->corner.x = 0.0;
   elem->corner.y = 0.0;
-  attr = object_find_attribute(obj_node, "elem_corner");
-  if (attr != NULL)
-    data_point(attribute_first_data(attr), &elem->corner, ctx);
+  attr = object_find_attribute (obj_node, "elem_corner");
+  if (attr != NULL) {
+    data_point (attribute_first_data (attr), &elem->corner, ctx);
+  }
 
   elem->width = 1.0;
-  attr = object_find_attribute(obj_node, "elem_width");
-  if (attr != NULL)
-    elem->width = data_real(attribute_first_data(attr), ctx);
+  attr = object_find_attribute (obj_node, "elem_width");
+  if (attr != NULL) {
+    elem->width = data_real (attribute_first_data (attr), ctx);
+  }
 
   elem->height = 1.0;
-  attr = object_find_attribute(obj_node, "elem_height");
-  if (attr != NULL)
-    elem->height = data_real( attribute_first_data(attr), ctx);
-
+  attr = object_find_attribute (obj_node, "elem_height");
+  if (attr != NULL) {
+    elem->height = data_real (attribute_first_data (attr), ctx);
+  }
 }
 
+
 typedef struct _ElementChange {
   ObjectChange object_change;
 
@@ -478,28 +553,32 @@ typedef struct _ElementChange {
   real     width;
   real     height;
 } ElementChange;
+
+
 static void
 _element_change_swap (ObjectChange *self,
-                     DiaObject *obj)
+                      DiaObject    *obj)
 {
-  ElementChange *ec = (ElementChange *)self;
+  ElementChange *ec = (ElementChange *) self;
   Element *elem = ec->element;
   Point tmppt;
   real  tmp;
 
-  g_assert(!obj || obj == &(ec->element->object));
+  g_return_if_fail (!obj || obj == &(ec->element->object));
 
   tmppt = ec->corner; ec->corner = elem->object.position; elem->object.position = tmppt;
   tmp = ec->width; ec->width = elem->width; elem->width = tmp;
   tmp = ec->height; ec->height = elem->height; elem->height = tmp;
 }
+
+
 ObjectChange *
 element_change_new (const Point *corner,
-                   real width,
-                   real height,
-                   Element *elem)
+                    real         width,
+                    real         height,
+                    Element     *elem)
 {
-  ElementChange *ec = g_new (ElementChange, 1);
+  ElementChange *ec = g_new0 (ElementChange, 1);
 
   ec->object_change.apply  = _element_change_swap;
   ec->object_change.revert = _element_change_swap;
@@ -513,6 +592,7 @@ element_change_new (const Point *corner,
   return &ec->object_change;
 }
 
+
 void
 element_get_poly (const Element *elem, real angle, Point corners[4])
 {
@@ -533,7 +613,8 @@ element_get_poly (const Element *elem, real angle, Point corners[4])
 
     dia_matrix_set_angle_and_scales (&m, G_PI*angle/180, 1.0, 1.0);
     dia_matrix_multiply (&m, &t, &m);
-    for (i = 0; i < 4; ++i)
+    for (i = 0; i < 4; ++i) {
       transform_point (&corners[i], &m);
+    }
   }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]