|
GnuCash 2.4.99
|
00001 /* 00002 * gnc-tree-model-account-types.h -- GtkTreeModel implementation 00003 * to display account types in a GtkTreeView. 00004 * 00005 * Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de> 00006 * Copyright (C) 2005, 2006 Chris Shoemaker <c.shoemaker@cox.net> 00007 * Copyright (C) 2006 Eskil Bylund <eskil.bylund@gmail.com> 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License as 00011 * published by the Free Software Foundation; either version 2 of 00012 * the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, contact: 00021 * 00022 * Free Software Foundation Voice: +1-617-542-5942 00023 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00024 * Boston, MA 02110-1301, USA gnu@gnu.org 00025 */ 00038 #ifndef __GNC_TREE_MODEL_ACCOUNT_TYPES_H 00039 #define __GNC_TREE_MODEL_ACCOUNT_TYPES_H 00040 00041 #include "Account.h" 00042 00043 G_BEGIN_DECLS 00044 00045 /* type macros */ 00046 #define GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES (gnc_tree_model_account_types_get_type ()) 00047 #define GNC_TREE_MODEL_ACCOUNT_TYPES(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, GncTreeModelAccountTypes)) 00048 #define GNC_TREE_MODEL_ACCOUNT_TYPES_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, GncTreeModelAccountTypesClass)) 00049 #define GNC_IS_TREE_MODEL_ACCOUNT_TYPES(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES)) 00050 #define GNC_IS_TREE_MODEL_ACCOUNT_TYPES_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES)) 00051 #define GNC_TREE_MODEL_ACCOUNT_TYPES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, GncTreeModelAccountTypesClass)) 00052 00053 typedef enum 00054 { 00055 GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE, 00056 GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME, 00057 GNC_TREE_MODEL_ACCOUNT_TYPES_COL_SELECTED, 00058 GNC_TREE_MODEL_ACCOUNT_TYPES_NUM_COLUMNS 00059 } GncTreeModelAccountTypesColumn; 00060 00061 /* typedefs & structures */ 00062 typedef struct 00063 { 00064 GObject gobject; 00065 int stamp; 00066 } GncTreeModelAccountTypes; 00067 00068 typedef struct 00069 { 00070 GObjectClass gobject; 00071 } GncTreeModelAccountTypesClass; 00072 00073 /* function prototypes */ 00074 GType gnc_tree_model_account_types_get_type (void); 00075 00076 /* Choose one of two methods to use the GncTreeModelAccountTypes 00077 objects defined here, depending on how you want to deal with 00078 selection state. Method 1 is simpler and light-weight, but Method 00079 2 is more flexible. 00080 00081 Method 1: If you just want to allow selection of a subset of all 00082 account types while showing all account types, use 00083 gnc_tree_model_account_types_master() to get the treemodel. 00084 Connect it to your tree view and use 00085 gnc_tree_model_account_types_{sg}et_selection() to convert between 00086 bitmasks and GtkTreeView states. No need to free the treemodel. 00087 00088 Method 2: If you must store selection state in the model for some 00089 reason (maybe you want to use a checkbox column to indicate 00090 selection?) then you need your own instance from 00091 gnc_tree_model_account_types_new(). Use 00092 gnc_tree_model_account_types_{gs}et_selected() to get and set the 00093 models "SELECTED" column values. You must free the model when 00094 you're done with it. 00095 00096 */ 00097 00098 /*************** Method 1 functions ***************/ 00099 00100 /* Returns a GtkTreeModelFilter that wraps the model. Only account 00101 types specified by the 'types' bitmask are visible. To force the 00102 visibility of deprecated account types, pass 00103 (xaccAccountTypesValid() | (1 << xaccAccountGetType(acct))). 00104 00105 To get the GtkTreeModel that shows all account types, including 00106 deprecated account types, pass (-1). 00107 00108 To get the GtkTreeModel that only shows non-deprecated account types, 00109 use gnc_tree_model_account_types_valid(). 00110 00111 Caller is responsible for ref/unref. */ 00112 GtkTreeModel * gnc_tree_model_account_types_filter_using_mask (guint32 types); 00113 00114 /* Update the set of the visibible account types in 'f_model' to 'types'. */ 00115 void gnc_tree_model_account_types_set_mask (GtkTreeModel *f_model, 00116 guint32 types); 00117 00118 /* Return the current set of the visibible account types. */ 00119 guint32 gnc_tree_model_account_types_get_mask (GtkTreeModel *f_model); 00120 00121 /* Return the bitmask of the account type enums reflecting the state 00122 of the tree selection. If your view allows the selection of 00123 multiple account types, use must use this function to get the 00124 selection. */ 00125 guint32 gnc_tree_model_account_types_get_selection(GtkTreeSelection *sel); 00126 00127 /* Gets the selected account type. Use the function if your view 00128 allows the selection of only one account type. If no types are 00129 selected, returns ACCT_TYPE_NONE. If more than one type is 00130 selected, arbitrarily returns one of the selected types. */ 00131 GNCAccountType 00132 gnc_tree_model_account_types_get_selection_single(GtkTreeSelection *sel); 00133 00134 /* Set the selection state of the tree selection to match the bitmask 00135 of account-type enums in 'selected'. This will also scroll to a 00136 selected row in the TreeView.*/ 00137 void gnc_tree_model_account_types_set_selection(GtkTreeSelection *sel, 00138 guint32 selected); 00139 00140 00141 /**************** Method 2 functions **************/ 00142 00143 GtkTreeModel *gnc_tree_model_account_types_new(guint32 selected); 00144 00145 00146 G_END_DECLS 00147 00148 #endif /* __GNC_TREE_MODEL_ACCOUNT_H */ 00149
1.7.4