1 /*****************************************************************
2     ViewKlass - C++ framework library for Motif
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 
18     Copyright (C) 2001 John Lemcke
19     jostle@users.sourceforge.net
20 *****************************************************************/
21 
22 /**
23  *
24  * VkMenuAction.C
25  *
26  *
27  * This file contains the source for the VkMenuAction class.
28  * This class, and its derivatives, account for most of the user
29  * interface acreage that you normally see.  It's a pretty important
30  * class.
31  *
32  * Chris Toshok
33  * Copyright (C) 1994
34  * The Hungry Programmers, Inc
35  *
36  **/
37 
38 static const char* rcsid
39 #ifdef __GNUC__
40 __attribute__ ((unused))
41 #endif
42 	= "$Id: VkMenuAction.C,v 1.12 2009/03/21 11:44:34 jostle Exp $";
43 
44 #include <iostream>
45 
46 using namespace std;
47 
48 #include <Vk/VkMenuItem.h>
49 
VkMenuAction(const char * name,XtCallbackProc callback,XtCallbackProc undoCallback,XtPointer clientData)50 VkMenuAction::VkMenuAction(const char *name,
51 						   XtCallbackProc callback,
52 						   XtCallbackProc undoCallback,
53 						   XtPointer clientData)
54 	: VkMenuItem(name),
55 	  _actionCallback(callback),
56 	  _undoCallback(undoCallback),
57 	  _clientData(clientData)
58 {
59 
60 }
61 
VkMenuAction(const char * name,XtCallbackProc callback,XtPointer clientData)62 VkMenuAction::VkMenuAction(const char *name,
63 						   XtCallbackProc callback,
64 						   XtPointer clientData)
65 	: VkMenuItem(name),
66 	  _actionCallback(callback),
67 	  _undoCallback(0),
68 	  _clientData(clientData)
69 {
70 }
71 
~VkMenuAction()72 VkMenuAction::~VkMenuAction()
73 {
74 	if (_isBuilt) {
75 		XtRemoveAllCallbacks(_baseWidget, XmNactivateCallback);
76 	}
77 }
78 
79 void
undo()80 VkMenuAction::undo()
81 {
82 	if (_undoCallback) {
83 		// Do some undoing!
84 		(*_undoCallback)(_baseWidget, _clientData, 0);
85 	}
86 }
87 
88 void
build(Widget parent)89 VkMenuAction::build(Widget parent)
90 {
91 	Arg args[4];
92 	int n = 0;
93 
94 	short pos = _position == -1 ? XmLAST_POSITION : _position;
95 	XtSetArg(args[n], XmNpositionIndex, pos); ++n;
96 
97 	_baseWidget = XmCreatePushButtonGadget(parent, (char*)name(), args, n);
98 
99 	installDestroyHandler();
100 
101 	XtAddCallback(_baseWidget, XmNactivateCallback,
102 				  &VkMenuAction::actionCallback, this);
103 
104 	XtManageChild(_baseWidget);
105 
106 	XtSetSensitive(_baseWidget, _sensitive);
107 
108 	VkMenuItem::build(parent);
109 }
110 
111 void
actionCallback(Widget w,XtPointer clientData,XtPointer callData)112 VkMenuAction::actionCallback(Widget w, XtPointer clientData,
113 							 XtPointer callData)
114 {
115 	VkMenuAction* me = (VkMenuAction*)clientData;
116 	if (me->_actionCallback) {
117 		(*(me->_actionCallback))(w, me->_clientData, callData);
118 		if (me->_undoCallback) {
119 			theUndoManager->add(me);
120 		}
121 	}
122 }
123