1 /********************************************************************\ 2 * gnc-tree-model-split-reg.h -- GtkTreeView implementation to * 3 * display registers in a GtkTreeView. * 4 * * 5 * Copyright (C) 2006-2007 Chris Shoemaker <c.shoemaker@cox.net> * 6 * Copyright (C) 2012 Robert Fewell * 7 * * 8 * This program is free software; you can redistribute it and/or * 9 * modify it under the terms of the GNU General Public License as * 10 * published by the Free Software Foundation; either version 2 of * 11 * the License, or (at your option) any later version. * 12 * * 13 * This program is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU General Public License* 19 * along with this program; if not, contact: * 20 * * 21 * Free Software Foundation Voice: +1-617-542-5942 * 22 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 23 * Boston, MA 02110-1301, USA gnu@gnu.org * 24 * * 25 \********************************************************************/ 26 27 28 #ifndef __GNC_TREE_MODEL_SPLIT_REG_H 29 #define __GNC_TREE_MODEL_SPLIT_REG_H 30 31 #include <gtk/gtk.h> 32 #include "gnc-tree-model.h" 33 #include "Query.h" 34 35 36 G_BEGIN_DECLS 37 /** @ingroup Register 38 * @addtogroup Register2 39 * @{ 40 */ 41 /** @file gnc-tree-model-split-reg.h 42 */ 43 /* type macros */ 44 #define GNC_TYPE_TREE_MODEL_SPLIT_REG (gnc_tree_model_split_reg_get_type ()) 45 #define GNC_TREE_MODEL_SPLIT_REG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_TREE_MODEL_SPLIT_REG, GncTreeModelSplitReg)) 46 #define GNC_TREE_MODEL_SPLIT_REG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_TREE_MODEL_SPLIT_REG, GncTreeModelSplitRegClass)) 47 #define GNC_IS_TREE_MODEL_SPLIT_REG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_TREE_MODEL_SPLIT_REG)) 48 #define GNC_IS_TREE_MODEL_SPLIT_REG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_TREE_MODEL_SPLIT_REG)) 49 #define GNC_TREE_MODEL_SPLIT_REG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_TREE_MODEL_SPLIT_REG, GncTreeModelSplitRegClass)) 50 #define GNC_TREE_MODEL_SPLIT_REG_NAME "GncTreeModelSplitReg" 51 52 53 /* Define the number of transaction to load */ 54 #define NUM_OF_TRANS 30 55 56 57 /** @brief Register types 58 * 59 * "registers" are single-account display windows. 60 * "ledgers" are multiple-account display windows */ 61 typedef enum 62 { 63 BANK_REGISTER2, //0 64 CASH_REGISTER2, //1 65 ASSET_REGISTER2, //2 66 CREDIT_REGISTER2, //3 67 LIABILITY_REGISTER2, //4 68 INCOME_REGISTER2, //5 69 EXPENSE_REGISTER2, //6 70 EQUITY_REGISTER2, //7 71 STOCK_REGISTER2, //8 72 CURRENCY_REGISTER2, //9 73 RECEIVABLE_REGISTER2, //10 74 PAYABLE_REGISTER2, //11 75 TRADING_REGISTER2, //12 76 NUM_SINGLE_REGISTER_TYPES2, //13 77 78 GENERAL_JOURNAL2 = NUM_SINGLE_REGISTER_TYPES2, //13 79 INCOME_LEDGER2, //14 80 PORTFOLIO_LEDGER2, //15 81 SEARCH_LEDGER2, //16 82 83 NUM_REGISTER_TYPES2 //17 84 } SplitRegisterType2; 85 86 87 /** Register styles */ 88 typedef enum 89 { 90 REG2_STYLE_LEDGER, //0 91 REG2_STYLE_AUTO_LEDGER, //1 92 REG2_STYLE_JOURNAL //2 93 } SplitRegisterStyle2; 94 95 96 typedef enum 97 { 98 GNC_TREE_MODEL_SPLIT_REG_COL_GUID, //0 99 GNC_TREE_MODEL_SPLIT_REG_COL_DATE, //1 100 GNC_TREE_MODEL_SPLIT_REG_COL_DUEDATE, //2 101 GNC_TREE_MODEL_SPLIT_REG_COL_NUMACT, //3 102 GNC_TREE_MODEL_SPLIT_REG_COL_DESCNOTES, //4 103 GNC_TREE_MODEL_SPLIT_REG_COL_TRANSFERVOID, //5 104 GNC_TREE_MODEL_SPLIT_REG_COL_RECN, //6 105 GNC_TREE_MODEL_SPLIT_REG_COL_DEBIT, //7 106 GNC_TREE_MODEL_SPLIT_REG_COL_CREDIT, //8 107 108 GNC_TREE_MODEL_SPLIT_REG_COL_LAST_VISIBLE = GNC_TREE_MODEL_SPLIT_REG_COL_CREDIT, //8 109 110 /* internal hidden columns */ 111 GNC_TREE_MODEL_SPLIT_REG_COL_RO, //9 112 GNC_TREE_MODEL_SPLIT_REG_COL_NUM_VIS, //10 113 GNC_TREE_MODEL_SPLIT_REG_COL_ACT_VIS, //11 114 115 GNC_TREE_MODEL_SPLIT_REG_NUM_COLUMNS //12 116 } GncTreeModelSplitRegColumn; 117 118 119 120 typedef enum 121 { 122 VIEW_HOME, //0 123 VIEW_UP, //1 124 VIEW_PGUP, //2 125 VIEW_GOTO, //3 126 VIEW_PGDOWN, //4 127 VIEW_DOWN, //5 128 VIEW_END, //6 129 } GncTreeModelSplitRegUpdate; 130 131 132 /* typedefs & structures */ 133 typedef struct GncTreeModelSplitRegPrivate GncTreeModelSplitRegPrivate; 134 135 /** The instance data structure for an account tree model. */ 136 typedef struct 137 { 138 GncTreeModel gnc_tree_model; /**< The parent object data. */ 139 GncTreeModelSplitRegPrivate *priv; 140 gint stamp; /**< The state of the model. Any state change increments this number. */ 141 142 SplitRegisterType2 type; /**<FIXME ? This may be the wrong place for these, may be the view ? */ 143 SplitRegisterStyle2 style; /**<FIXME ? This may be the wrong place for these, may be the view ? */ 144 gboolean use_double_line; /**<FIXME ? As above, whether to use two lines per transaction */ 145 146 gboolean is_template; /**< Are we using a template */ 147 gboolean mismatched_commodities; /**< Are there different commodities */ 148 149 gint sort_depth; /**< This is the row the sort direction is based on. */ 150 gint sort_col; /**< This is the column the sort direction is based on. */ 151 GtkSortType sort_direction; /**< This is the direction of sort */ 152 153 gboolean use_accounting_labels; /**< whether to use accounting Labels */ 154 gboolean separator_changed; /**< whether the separator has changed */ 155 gboolean alt_colors_by_txn; /**< whether to use alternative colors by transaction */ 156 gboolean use_gnc_color_theme; /**< whether to use the gnucash built-in color theme */ 157 158 gboolean read_only; /**< register is read only */ 159 160 Transaction *current_trans; /**< Current transaction */ 161 gint current_row; /**< Current row in treeview */ 162 gint number_of_trans_in_full_tlist; /**< The total number of transactions in full_tlist */ 163 gint position_of_trans_in_full_tlist; /**< The position of current transaction in full_tlist */ 164 165 }GncTreeModelSplitReg; 166 167 168 /** The class data structure for an account tree model. */ 169 typedef struct 170 { 171 GncTreeModelClass gnc_tree_model; /**< The parent object data. */ 172 173 /* This signal is emitted to refresh the transaction view, the pointer has 174 the transaction */ 175 void (*refresh_trans) (GncTreeModelSplitReg *model, gpointer item); 176 177 /* This signal is emitted to refresh the model */ 178 void (*refresh_view) (GncTreeModelSplitReg *model, gpointer user_data); 179 180 /* This signal is emitted to keep scrollbar in sync */ 181 void (*scroll_sync) (GncTreeModelSplitReg *model, gpointer user_data); 182 183 /* This signal is emitted to refresh the status bar */ 184 void (*refresh_status_bar) (GncTreeModelSplitReg *model, gpointer user_data); 185 186 /* This signal is emitted before a transaction delete, the pointer has 187 the transaction */ 188 void (*selection_move_delete) (GncTreeModelSplitReg *model, gpointer item); 189 190 } GncTreeModelSplitRegClass; 191 192 193 /** Callback function type - Used to get parent window */ 194 typedef GtkWidget *(*SRGetParentCallback2) (gpointer user_data); 195 196 /** Get the type of split register tree plugin. 197 * 198 * @return A GType. 199 */ 200 GType gnc_tree_model_split_reg_get_type (void); 201 202 /** Create new model and set options for register. */ 203 GncTreeModelSplitReg * 204 gnc_tree_model_split_reg_new (SplitRegisterType2 reg_type, SplitRegisterStyle2 style, 205 gboolean use_double_line, gboolean is_template, gboolean mismatched_commodities); 206 207 /** Load the model from a slist and set default account for register. */ 208 void gnc_tree_model_split_reg_load (GncTreeModelSplitReg *model, GList * slist, Account *default_account); 209 210 /** Sets the template account. */ 211 void gnc_tree_model_split_reg_set_template_account (GncTreeModelSplitReg *model, Account *template_account); 212 213 /** Returns the template account. */ 214 Account * gnc_tree_model_split_reg_get_template_account (GncTreeModelSplitReg *model); 215 216 /** Return TRUE if this is a template register. */ 217 gboolean gnc_tree_model_split_reg_get_template (GncTreeModelSplitReg *model); 218 219 /** Destroy the model. */ 220 void gnc_tree_model_split_reg_destroy (GncTreeModelSplitReg *model); 221 222 /** Sets the user data and callback hooks for the register. */ 223 void gnc_tree_model_split_reg_set_data (GncTreeModelSplitReg *model, gpointer user_data, 224 SRGetParentCallback2 get_parent); 225 226 /** Update the query for the register. */ 227 void gnc_tree_model_split_reg_update_query (GncTreeModelSplitReg *model, Query *query); 228 229 /** Returns the parent Window of the register. */ 230 GtkWidget * gnc_tree_model_split_reg_get_parent (GncTreeModelSplitReg *model); 231 232 /** Set style and type for register. */ 233 void gnc_tree_model_split_reg_config (GncTreeModelSplitReg *model, SplitRegisterType2 newtype, 234 SplitRegisterStyle2 newstyle, gboolean use_double_line); 235 236 /** Return the default account for this register model. */ 237 Account * gnc_tree_model_split_reg_get_anchor (GncTreeModelSplitReg *model); 238 239 /** Commit the blank split. */ 240 void gnc_tree_model_split_reg_commit_blank_split (GncTreeModelSplitReg *model); 241 242 /** Set display general journal and show sub accounts. */ 243 void gnc_tree_model_split_reg_set_display (GncTreeModelSplitReg *model, gboolean subacc, gboolean gl); 244 245 /** Change transactions in the tlist based on view movement. */ 246 void gnc_tree_model_split_reg_move (GncTreeModelSplitReg *model, GncTreeModelSplitRegUpdate model_update); 247 248 /* Sync the vertical scrollbar to position in full_tlist. */ 249 void gnc_tree_model_split_reg_sync_scrollbar (GncTreeModelSplitReg *model); 250 251 /** Return the first transaction, opposite to blank transaction in the full list. */ 252 Transaction * gnc_tree_model_split_reg_get_first_trans (GncTreeModelSplitReg *model); 253 254 /** Return TRUE if transaction is in the view list. */ 255 gboolean gnc_tree_model_split_reg_trans_is_in_view (GncTreeModelSplitReg *model, Transaction *trans); 256 257 /* These are to do with autocompletion */ 258 GtkListStore * gnc_tree_model_split_reg_get_description_list (GncTreeModelSplitReg *model); 259 260 GtkListStore * gnc_tree_model_split_reg_get_notes_list (GncTreeModelSplitReg *model); 261 262 GtkListStore * gnc_tree_model_split_reg_get_memo_list (GncTreeModelSplitReg *model); 263 264 GtkListStore * gnc_tree_model_split_reg_get_action_list (GncTreeModelSplitReg *model); 265 266 GtkListStore * gnc_tree_model_split_reg_get_acct_list (GncTreeModelSplitReg *model); 267 268 void gnc_tree_model_split_reg_update_num_list (GncTreeModelSplitReg *model); 269 270 void gnc_tree_model_split_reg_update_action_list (GncTreeModelSplitReg *model); 271 272 void gnc_tree_model_split_reg_update_account_list (GncTreeModelSplitReg *model); 273 274 void gnc_tree_model_split_reg_update_completion (GncTreeModelSplitReg *model); 275 276 277 /* Get the split and transaction */ 278 gboolean gnc_tree_model_split_reg_get_split_and_trans ( 279 GncTreeModelSplitReg *model, GtkTreeIter *iter, 280 gboolean *is_trow1, gboolean *is_trow2, gboolean *is_split, 281 gboolean *is_blank, Split **split, Transaction **trans); 282 283 /* Return FALSE if failure */ 284 gboolean gnc_tree_model_split_reg_set_blank_split_parent ( 285 GncTreeModelSplitReg *model, Transaction *trans, gboolean remove_only); 286 287 /* Return the blank split */ 288 Split * gnc_tree_model_split_get_blank_split (GncTreeModelSplitReg *model); 289 290 /* Return TRUE if blank_split is on trans */ 291 gboolean gnc_tree_model_split_reg_is_blank_split_parent (GncTreeModelSplitReg *model, Transaction *trans); 292 293 /* Return the blank trans */ 294 Transaction * gnc_tree_model_split_get_blank_trans (GncTreeModelSplitReg *model); 295 296 /* If 'trans' is NULL, use split's parent. If 'split' is NULL, just 297 get the transaction iter. */ 298 gboolean gnc_tree_model_split_reg_get_iter_from_trans_and_split ( 299 GncTreeModelSplitReg *model, Transaction *trans, Split *split, 300 GtkTreeIter *iter1, GtkTreeIter *iter2); 301 302 /* Return the row color for the view */ 303 gchar * gnc_tree_model_split_reg_get_row_color (GncTreeModelSplitReg *model, gboolean is_trow1, 304 gboolean is_trow2, gboolean is_split, gint num); 305 306 /* Return the tooltip for transaction at position in full_tlist. */ 307 gchar * gnc_tree_model_split_reg_get_tooltip (GncTreeModelSplitReg *model, gint position); 308 309 /* Set the current transaction to that at position in full_tlist */ 310 void gnc_tree_model_split_reg_set_current_trans_by_position (GncTreeModelSplitReg *model, gint position); 311 312 /* Return TRUE if this transaction is read only for the view */ 313 gboolean 314 gnc_tree_model_split_reg_get_read_only (GncTreeModelSplitReg *model, Transaction *trans); 315 316 /* Return TRUE if this is a sub account view */ 317 gboolean 318 gnc_tree_model_split_reg_get_sub_account (GncTreeModelSplitReg *model); 319 320 /* Return the tree path, if split and trans are null, last in list returned */ 321 GtkTreePath * gnc_tree_model_split_reg_get_path_to_split_and_trans ( 322 GncTreeModelSplitReg *model, Split *split, Transaction *trans); 323 324 /* Returns TRUE if iter is a blank transaction */ 325 gboolean gnc_tree_model_split_reg_is_blank_trans (GncTreeModelSplitReg *model, GtkTreeIter *iter); 326 327 /* Return the split for which ancestor is it's parent */ 328 Split * gnc_tree_model_split_reg_trans_get_split_equal_to_ancestor (const Transaction *trans, const Account *ancestor); 329 330 /* Dummy Sort function */ 331 gint gnc_tree_model_split_reg_sort_iter_compare_func (GtkTreeModel *tm, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data); 332 333 /*****************************************************************************/ 334 /** @} */ 335 G_END_DECLS 336 337 #endif /* __GNC_TREE_MODEL_SPLIT_REG_H */ 338