tagging release
[dasher.git] / trunk / Src / Gtk2 / dasher_action.cpp
blob454540c02d1610c4456372e808c8a37153a56d45
1 #include "dasher_action.h"
3 struct _DasherActionPrivate {
4 gboolean bActive;
5 };
7 typedef struct _DasherActionPrivate DasherActionPrivate;
9 #define DASHER_ACTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_DASHER_ACTION, DasherActionPrivate))
11 G_DEFINE_ABSTRACT_TYPE(DasherAction, dasher_action, G_TYPE_OBJECT);
13 /* Gobject boilerplate */
14 static void
15 dasher_action_class_init(DasherActionClass *pClass) {
16 g_type_class_add_private(pClass, sizeof(DasherActionPrivate));
18 pClass->execute = 0;
19 pClass->preview = 0;
20 pClass->activate = 0;
21 pClass->deactivate = 0;
22 pClass->get_name = 0;
23 pClass->get_sub_count = 0;
24 pClass->get_sub_name = 0;
27 static void
28 dasher_action_init(DasherAction *pDasherAction) {
29 DasherActionPrivate *pDasherActionPrivate = DASHER_ACTION_GET_PRIVATE(pDasherAction);
31 pDasherActionPrivate->bActive = false;
34 /* Public methods */
35 DasherAction *
36 dasher_action_new() {
37 DasherAction *pDasherControl;
39 pDasherControl = (DasherAction *)(g_object_new(dasher_action_get_type(), NULL));
41 return pDasherControl;
44 gboolean
45 dasher_action_execute(DasherAction *pSelf, DasherEditorInternal *pEditor, int iIdx) {
46 // TODO: Need to make sure that the action is active first
48 if(DASHER_ACTION_GET_CLASS(pSelf)->execute)
49 return DASHER_ACTION_GET_CLASS(pSelf)->execute(pSelf, pEditor, iIdx);
50 else
51 return false;
54 gboolean
55 dasher_action_preview(DasherAction *pSelf, DasherEditorInternal *pEditor) {
56 // TODO: Need to make sure that the action is active first
58 if(DASHER_ACTION_GET_CLASS(pSelf)->preview)
59 return DASHER_ACTION_GET_CLASS(pSelf)->preview(pSelf, pEditor);
60 else
61 return false;
64 const gchar *
65 dasher_action_get_name(DasherAction *pSelf) {
66 if(DASHER_ACTION_GET_CLASS(pSelf)->get_name)
67 return DASHER_ACTION_GET_CLASS(pSelf)->get_name(pSelf);
68 else
69 return 0;
72 int
73 dasher_action_get_sub_count(DasherAction *pSelf) {
74 if(DASHER_ACTION_GET_CLASS(pSelf)->get_sub_count)
75 return DASHER_ACTION_GET_CLASS(pSelf)->get_sub_count(pSelf);
76 else
77 return 0;
80 const gchar *
81 dasher_action_get_sub_name(DasherAction *pSelf, int iIdx) {
82 if(DASHER_ACTION_GET_CLASS(pSelf)->get_sub_name)
83 return DASHER_ACTION_GET_CLASS(pSelf)->get_sub_name(pSelf, iIdx);
84 else
85 return NULL;
88 gboolean
89 dasher_action_activate(DasherAction *pSelf) {
90 DasherActionPrivate *pDasherActionPrivate = DASHER_ACTION_GET_PRIVATE(pSelf);
92 if(pDasherActionPrivate->bActive)
93 return true;
95 if(DASHER_ACTION_GET_CLASS(pSelf)->activate) {
96 pDasherActionPrivate->bActive = DASHER_ACTION_GET_CLASS(pSelf)->activate(pSelf);
97 return pDasherActionPrivate->bActive;
99 else {
100 pDasherActionPrivate->bActive = true;
101 return true;
105 gboolean
106 dasher_action_deactivate(DasherAction *pSelf) {
107 DasherActionPrivate *pDasherActionPrivate = DASHER_ACTION_GET_PRIVATE(pSelf);
109 if(!(pDasherActionPrivate->bActive))
110 return true;
112 if(DASHER_ACTION_GET_CLASS(pSelf)->deactivate) {
113 pDasherActionPrivate->bActive = !DASHER_ACTION_GET_CLASS(pSelf)->deactivate(pSelf);
114 return !(pDasherActionPrivate->bActive);
116 else {
117 pDasherActionPrivate->bActive = false;
118 return true;
122 gboolean
123 dasher_action_get_active(DasherAction *pSelf) {
124 DasherActionPrivate *pDasherActionPrivate = DASHER_ACTION_GET_PRIVATE(pSelf);
126 return pDasherActionPrivate->bActive;