1 #include "dasher_action.h"
3 struct _DasherActionPrivate
{
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 */
15 dasher_action_class_init(DasherActionClass
*pClass
) {
16 g_type_class_add_private(pClass
, sizeof(DasherActionPrivate
));
21 pClass
->deactivate
= 0;
23 pClass
->get_sub_count
= 0;
24 pClass
->get_sub_name
= 0;
28 dasher_action_init(DasherAction
*pDasherAction
) {
29 DasherActionPrivate
*pDasherActionPrivate
= DASHER_ACTION_GET_PRIVATE(pDasherAction
);
31 pDasherActionPrivate
->bActive
= false;
37 DasherAction
*pDasherControl
;
39 pDasherControl
= (DasherAction
*)(g_object_new(dasher_action_get_type(), NULL
));
41 return pDasherControl
;
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
);
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
);
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
);
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
);
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
);
89 dasher_action_activate(DasherAction
*pSelf
) {
90 DasherActionPrivate
*pDasherActionPrivate
= DASHER_ACTION_GET_PRIVATE(pSelf
);
92 if(pDasherActionPrivate
->bActive
)
95 if(DASHER_ACTION_GET_CLASS(pSelf
)->activate
) {
96 pDasherActionPrivate
->bActive
= DASHER_ACTION_GET_CLASS(pSelf
)->activate(pSelf
);
97 return pDasherActionPrivate
->bActive
;
100 pDasherActionPrivate
->bActive
= true;
106 dasher_action_deactivate(DasherAction
*pSelf
) {
107 DasherActionPrivate
*pDasherActionPrivate
= DASHER_ACTION_GET_PRIVATE(pSelf
);
109 if(!(pDasherActionPrivate
->bActive
))
112 if(DASHER_ACTION_GET_CLASS(pSelf
)->deactivate
) {
113 pDasherActionPrivate
->bActive
= !DASHER_ACTION_GET_CLASS(pSelf
)->deactivate(pSelf
);
114 return !(pDasherActionPrivate
->bActive
);
117 pDasherActionPrivate
->bActive
= false;
123 dasher_action_get_active(DasherAction
*pSelf
) {
124 DasherActionPrivate
*pDasherActionPrivate
= DASHER_ACTION_GET_PRIVATE(pSelf
);
126 return pDasherActionPrivate
->bActive
;