1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
/* File: gui_sketch_nav_tree.h; Copyright and License: see below */
#ifndef GUI_SKETCH_NAV_TREE_H
#define GUI_SKETCH_NAV_TREE_H
/* public file for the doxygen documentation: */
/*! \file
* \brief Shows a tree view
*/
#include "sketch/gui_sketch_marker.h"
#include "sketch/gui_sketch_action.h"
#include "sketch/gui_sketch_style.h"
#include "gui_marked_set.h"
#include "gui_resources.h"
#include "gui_error.h"
#include "shape/shape_int_rectangle.h"
#include "pos/pos_nav_tree_node.h"
#include "pos/pos_nav_tree_gap.h"
#include "storage/data_database.h"
#include "ctrl_controller.h"
#include "layout/layout_order.h"
#include <pango/pangocairo.h>
#include <cairo.h>
#include <gtk/gtk.h>
#include <stdbool.h>
#include <stdint.h>
/*!
* \brief constants of gui_sketch_nav_tree_t
*/
enum gui_sketch_nav_tree_const_enum {
GUI_SKETCH_NAV_TREE_CONST_MAX_ANCESTORS = 16, /*!< maximum number of parents/grand-partents/grand-grand-parents */
GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS = 96, /*!< maximum number of sisters/brothers */
GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN = 96, /*!< maximum number of daughters/sons */
GUI_SKETCH_NAV_TREE_CONST_MAX_NODES = ( GUI_SKETCH_NAV_TREE_CONST_MAX_ANCESTORS
+ GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS
+ GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN
+ 1), /*!< max diagrams, minus 1 for duplicate self plus 2 for new buttons */
GUI_SKETCH_NAV_TREE_CONST_MAX_GAPS = GUI_SKETCH_NAV_TREE_CONST_MAX_NODES, /* same as nodes, see do_layout */
};
/*!
* \brief attributes of the nav tree
*
* The nav tree is a subwidget to the gui_sketch_area:
* - it knows its data to draw (tree-parts of diagrams)
* - it layouts the data to show
* - it draws the data
* - it answers which data-object is layouted to which position
* This subwidget does not get or respond-to user actions or listens to events of other widgets;
* also it does not trigger events to other widgets
*/
struct gui_sketch_nav_tree_struct {
bool visible; /*!< is the nav tree visible */
shape_int_rectangle_t bounds; /*!< bounding box of the nav tree */
/* diagram data to be shown */
uint32_t ancestors_count; /*!< number of ancestors, incuding self */
data_diagram_t ancestor_diagrams[GUI_SKETCH_NAV_TREE_CONST_MAX_ANCESTORS]; /*!< current diagram is at index 0 */
uint32_t siblings_count;
data_diagram_t sibling_diagrams[GUI_SKETCH_NAV_TREE_CONST_MAX_SIBLINGS];
int32_t siblings_self_index; /*!< index of current diagram in list of siblings, -1 in case of error */
uint32_t children_count;
data_diagram_t child_diagrams[GUI_SKETCH_NAV_TREE_CONST_MAX_CHILDREN];
/* layout information */
pos_nav_tree_node_t node_pos[GUI_SKETCH_NAV_TREE_CONST_MAX_NODES]; /*!< layout positions of diagrams and create-buttons */
uint32_t node_count; /*!< number of layout positions in node_pos list */
pos_nav_tree_gap_t gap_pos[GUI_SKETCH_NAV_TREE_CONST_MAX_GAPS]; /*!< logical positions of gaps between diagrams */
uint32_t gap_count; /*!< number of logical positions in gap_pos list */
/* helper classes to perform drawing */
gui_sketch_style_t sketch_style;
gui_sketch_marker_t sketch_marker;
gui_resources_t *resources; /*!< pointer to external resources */
};
typedef struct gui_sketch_nav_tree_struct gui_sketch_nav_tree_t;
/*!
* \brief initializes the gui_sketch_nav_tree_t struct
*
* \param this_ pointer to own object attributes
* \param resources pointer to a graphics resource provider
*/
void gui_sketch_nav_tree_init ( gui_sketch_nav_tree_t *this_, gui_resources_t *resources );
/*!
* \brief destroys the gui_sketch_nav_tree_t struct
*
* \param this_ pointer to own object attributes
*/
void gui_sketch_nav_tree_destroy ( gui_sketch_nav_tree_t *this_ );
/*!
* \brief fetches the diagram data from the database
*
* and calls gui_sketch_nav_tree_private_do_layout to ensure consistency of own attributes
*
* \param this_ pointer to own object attributes
* \param diagram_id id of the diagram to load, DATA_ROW_ID_VOID to set empty data
* \param db_reader pointer to a database reader object
*/
void gui_sketch_nav_tree_load_data( gui_sketch_nav_tree_t *this_, data_row_id_t diagram_id, data_database_reader_t *db_reader );
/*!
* \brief gets the id of the root diagram
*
* \param this_ pointer to own object attributes
* \return the id of the root diagram, DATA_ROW_ID_VOID if no diagrams exist
*/
static inline data_row_id_t gui_sketch_nav_tree_get_root_diagram_id ( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief gets the highest list order of the sibling diagrams
*
* \param this_ pointer to own object attributes
* \return the highest list order of the siblings diagrams, 0 if no sibling diagrams exist
*/
static inline int32_t gui_sketch_nav_tree_get_siblings_highest_order ( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief gets the highest list order of the children diagrams
*
* \param this_ pointer to own object attributes
* \return the highest list order of the children diagrams, 0 if no children diagrams exist
*/
static inline int32_t gui_sketch_nav_tree_get_children_highest_order ( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief checks if one diagram is a direct child or indirect descendant of the other
*
* \param this_ pointer to own object attributes
* \param probe_ancestor_id the id of the possible parent/ancestor diagram.
* \param probe_descendant_id the id of the possible child/descendant diagram.
* \param out_is_descendant true if probe_ancestor_id is an ancestor of probe_descendant_id.
* \return GUI_ERROR_NONE if both ids are in the cache, GUI_ERROR_UNKNOWN_OBJECT otherwise
*/
static inline gui_error_t gui_sketch_nav_tree_is_descendant ( const gui_sketch_nav_tree_t *this_,
data_row_id_t probe_ancestor_id,
data_row_id_t probe_descendant_id,
bool *out_is_descendant
);
/*!
* \brief calculates the layout-line indices / layouts the tree nodes
*
* \param this_ pointer to own object attributes
* \param cr cairo drawing context
*/
void gui_sketch_nav_tree_do_layout( gui_sketch_nav_tree_t *this_, cairo_t *cr );
/*!
* \brief layouts icon and label of a tree node
*
* \param this_ pointer to own object attributes
* \param node the pos_nav_tree_node_t to layout
* \param tree_depth the depth in the tree / used for the indentation width
* \param[in,out] io_y_pos top position of the current node to be layouted; out: pos of next node
* \param font_layout the pango font rendering object
*/
void gui_sketch_nav_tree_private_layout_node ( gui_sketch_nav_tree_t *this_,
pos_nav_tree_node_t *node,
uint32_t tree_depth,
int32_t *io_y_pos,
PangoLayout *font_layout
);
/*!
* \brief marks the diagram data as invalid
*
* \param this_ pointer to own object attributes
*/
void gui_sketch_nav_tree_invalidate_data( gui_sketch_nav_tree_t *this_ );
/*!
* \brief gets the bounds rectangle
*
* \param this_ pointer to own object attributes
* \return returns the bounding box of this sketch card
*/
static inline shape_int_rectangle_t gui_sketch_nav_tree_get_bounds( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief sets the bounds rectangle
*
* \param this_ pointer to own object attributes
* \param bounds bounding box of this sketch card
*/
static inline void gui_sketch_nav_tree_set_bounds( gui_sketch_nav_tree_t *this_, shape_int_rectangle_t bounds );
/*!
* \brief gets the visible flag
*
* \param this_ pointer to own object attributes
* \return true if this sketch card is currently visible
*/
static inline bool gui_sketch_nav_tree_is_visible( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief sets the visible flag
*
* \param this_ pointer to own object attributes
* \param visible true if this card is currently visible, false otherwise
*/
static inline void gui_sketch_nav_tree_set_visible( gui_sketch_nav_tree_t *this_, bool visible );
/*!
* \brief gets the address of the diagram data of gui_sketch_nav_tree_t
*
* \param this_ pointer to own object attributes
* \return pointer to diagram
*/
static inline const data_diagram_t *gui_sketch_nav_tree_get_diagram_ptr ( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief gets the action-id of the button at a given position.
*
* \param this_ pointer to own object attributes
* \param x x-position
* \param y y-position
* \param out_action_id the action id ofthe button at the given location. GUI_SKETCH_ACTION_NONE if there is no button at the given location.
*/
static inline void gui_sketch_nav_tree_get_button_at_pos ( const gui_sketch_nav_tree_t *this_,
int32_t x,
int32_t y,
gui_sketch_action_t *out_action_id
);
/*!
* \brief gets the diagram-id of the diagram_t at a given position.
*
* \param this_ pointer to own object attributes
* \param x x-position
* \param y y-position
* \param out_selected_id the object id at the given location. The id is invalid if there is no object at the given location.
*/
void gui_sketch_nav_tree_get_object_id_at_pos ( const gui_sketch_nav_tree_t *this_,
int32_t x,
int32_t y,
data_id_t *out_selected_id
);
/*!
* \brief gets the gap information at a given position.
*
* Either it gets the real, de-referenced object at a given position, e.g. a diagram_t or a classifier_t,
* or the visible object at a given position, e.g. a diagram_t or a diagramelement_t.
*
* \param this_ pointer to own object attributes
* \param x x-position
* \param y y-position
* \param out_parent_id the parent object id at the given location. The id is invalid if the root location was chosen.
* \param out_list_order the list_order at the given location.
* \param out_gap_line the line coordinates to show a gap cursor bar.
* \return GUI_ERROR_NONE if x/y points to a valid gap, GUI_ERROR_OUT_OF_BOUNDS in case of out of bounds error
*/
gui_error_t gui_sketch_nav_tree_get_gap_info_at_pos ( const gui_sketch_nav_tree_t *this_,
int32_t x,
int32_t y,
data_id_t *out_parent_id,
int32_t *out_list_order,
shape_int_rectangle_t *out_gap_line
);
/*!
* \brief gets the pos_nav_tree_node_t position object at index
*
* \param this_ pointer to own object attributes
* \param index 0 <= index < node_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_NODES
* \return pointer to const pos_nav_tree_node_t
*/
static inline const pos_nav_tree_node_t *gui_sketch_nav_tree_get_node_pos_const ( const gui_sketch_nav_tree_t *this_,
uint32_t index
);
/*!
* \brief gets the number of node position objects
*
* \param this_ pointer to own object attributes
* \return node_count
*/
static inline uint32_t gui_sketch_nav_tree_get_node_count ( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief gets the pos_nav_tree_gap_t position object at index
*
* \param this_ pointer to own object attributes
* \param index 0 <= index < gap_count <= GUI_SKETCH_NAV_TREE_CONST_MAX_GAPS
* \return pointer to const pos_nav_tree_gap_t
*/
static inline const pos_nav_tree_gap_t *gui_sketch_nav_tree_get_gap_pos_const ( const gui_sketch_nav_tree_t *this_,
uint32_t index
);
/*!
* \brief gets the number of gap position objects
*
* \param this_ pointer to own object attributes
* \return gap_count
*/
static inline uint32_t gui_sketch_nav_tree_get_gap_count ( const gui_sketch_nav_tree_t *this_ );
/*!
* \brief draws a single diagram
*
* \param this_ pointer to own object attributes
* \param marker set of all objects to be marked
* \param cr cairo drawing context
*/
void gui_sketch_nav_tree_draw ( gui_sketch_nav_tree_t *this_, gui_marked_set_t *marker, cairo_t *cr );
/*!
* \brief draws an icon and a label
*
* \param this_ pointer to own object attributes
* \param node the pos_nav_tree_node_t to draw
* \param marker set of all objects to be marked
* \param font_layout the pango font rendering object for i18n suppoprt
* \param cr the cairo drawing engine
*/
void gui_sketch_nav_tree_private_draw_node( gui_sketch_nav_tree_t *this_,
const pos_nav_tree_node_t *node,
const gui_marked_set_t *marker,
PangoLayout *font_layout,
cairo_t *cr
);
#include "gui_sketch_nav_tree.inl"
#endif /* GUI_SKETCH_NAV_TREE_H */
/*
Copyright 2018-2023 Andreas Warnke
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
|