1 /*
2  * Copyright (C) 2002 - David W. Durham
3  *
4  * This file is part of ReZound, an audio editing application.
5  *
6  * ReZound is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License,
9  * or (at your option) any later version.
10  *
11  * ReZound is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19  */
20 
21 #include "CActionMenuCommand.h"
22 
23 #include <stdexcept>
24 
25 #include "CSoundFileManager.h"
26 
27 #include "../backend/CActionParameters.h"
28 #include "../backend/AAction.h"
29 #include "CFOXIcons.h"
30 #include "CMainWindow.h" // for CMainWindow::actionMenuCommandTriggered()
31 
32 FXDEFMAP(CActionMenuCommand) CActionMenuCommandMap[]=
33 {
34 	//Message_Type				ID				Message_Handler
35 
36 	FXMAPFUNC(SEL_LEFTBUTTONRELEASE,	0,				CActionMenuCommand::onMouseClick),
37 	FXMAPFUNC(SEL_RIGHTBUTTONRELEASE,	0,				CActionMenuCommand::onMouseClick),
38 
39 	FXMAPFUNC(SEL_KEYRELEASE,		0,				CActionMenuCommand::onKeyClick),
40 
41 	FXMAPFUNC(SEL_COMMAND,			CActionMenuCommand::ID_HOTKEY,	CActionMenuCommand::onCommand),
42 
43 #if REZ_FOX_VERSION<10304
44 	FXMAPFUNC(SEL_UPDATE,			FXWindow::ID_QUERY_TIP,		CActionMenuCommand::onQueryTip)
45 #else
46 	FXMAPFUNC(SEL_QUERY_TIP,		0,				CActionMenuCommand::onQueryTip)
47 #endif
48 };
49 
FXIMPLEMENT(CActionMenuCommand,FXMenuCommand,CActionMenuCommandMap,ARRAYNUMBER (CActionMenuCommandMap))50 FXIMPLEMENT(CActionMenuCommand,FXMenuCommand,CActionMenuCommandMap,ARRAYNUMBER(CActionMenuCommandMap))
51 
52 CActionMenuCommand::CActionMenuCommand(AActionFactory *_actionFactory,FXComposite* p, FXIcon* ic, FXuint opts) :
53 	FXMenuCommand(
54 		p,
55 		// i18n/translate the action's name, append '...' if it has a dialog
56 		(string(gettext(_actionFactory->getName().c_str()))+(_actionFactory->hasDialog() ? "..." : "")).c_str(),
57 		(ic==NULL ? FOXIcons->normal_action_buff : ic),
58 		this,
59 		ID_HOTKEY,
60 		opts
61 		),
62 	actionFactory(_actionFactory)
63 {
64 	tip=actionFactory->getDescription().c_str();
65 
66 	prevEvent.state=0;
67 	prevEvent.click_button=0;
68 }
69 
CActionMenuCommand(FXComposite * p,const CActionMenuCommand & src)70 CActionMenuCommand::CActionMenuCommand(FXComposite *p,const CActionMenuCommand &src) :
71 	FXMenuCommand(
72 		p,
73 		src.getText(),
74 		src.getIcon(),
75 		this,
76 		src.getSelector(),
77 		src.getLayoutHints() /* I can't get the original options from src */
78 		),
79 	actionFactory(src.actionFactory),
80 	tip(src.tip),
81 	prevEvent(src.prevEvent)
82 {
83 }
84 
~CActionMenuCommand()85 CActionMenuCommand::~CActionMenuCommand()
86 {
87 }
88 
getUntranslatedText() const89 const string CActionMenuCommand::getUntranslatedText() const
90 {
91 	return actionFactory->getName()+(actionFactory->hasDialog() ? "..." : "");
92 }
93 
onMouseClick(FXObject * sender,FXSelector sel,void * ptr)94 long CActionMenuCommand::onMouseClick(FXObject *sender,FXSelector sel,void *ptr)
95 {
96 	prevEvent=*((FXEvent *)ptr);
97 	return FXMenuCommand::handle(sender,sel,ptr);
98 }
99 
onKeyClick(FXObject * sender,FXSelector sel,void * ptr)100 long CActionMenuCommand::onKeyClick(FXObject *sender,FXSelector sel,void *ptr)
101 {
102 	prevEvent=*((FXEvent *)ptr);
103 	return FXMenuCommand::handle(sender,sel,ptr);
104 }
105 
onCommand(FXObject * sender,FXSelector sel,void * ptr)106 long CActionMenuCommand::onCommand(FXObject *sender,FXSelector sel,void *ptr)
107 {
108 	CLoadedSound *activeSound=gSoundFileManager->getActive();
109 	if(activeSound!=NULL || !actionFactory->requiresALoadedSound)
110 	{
111 		gSoundFileManager->getMainWindow()->actionMenuCommandTriggered(this);
112 
113 			// ??? let action parameters contain actionSound and the two bool parameters
114 			// they should have some flag which says that they would not be streamed to disk (if that were ever something I do with action parameters)
115 		CActionParameters actionParameters(gSoundFileManager);
116 		actionFactory->performAction(activeSound,&actionParameters,prevEvent.state&SHIFTMASK);
117 
118 		// necessary if say a new file was opened, and it needs to be update (because AAction::performAction() didn't know about the new one that exists now)
119 		if(gSoundFileManager->getActive()!=activeSound)
120 			gSoundFileManager->updateAfterEdit();
121 
122 		// done in AActionFactory::performAction() now
123 		/*
124 		// now, in case a newly created window has taken the place of the previously active window, it still may be necessary to update the previous active sound window
125 		if(gSoundFileManager->getActive()!=activeSound && gSoundFileManager->isValidLoadedSound(activeSound))
126 			gSoundFileManager->updateAfterEdit(activeSound);
127 		*/
128 
129 		prevEvent.state=0;
130 		prevEvent.click_button=0;
131 	}
132 	else
133 		getApp()->beep();
134 
135 	return 1;
136 }
137 
onQueryTip(FXObject * sender,FXSelector sel,void * ptr)138 long CActionMenuCommand::onQueryTip(FXObject* sender,FXSelector sel,void *ptr)
139 {
140 	if(!tip.empty() && (flags&FLAG_TIP))
141 	{
142 		sender->handle(this,MKUINT(ID_SETSTRINGVALUE,SEL_COMMAND),(void*)&tip);
143 		return 1;
144 	}
145 	return 0;
146 }
147 
148