xref: /haiku/src/servers/input/InputServerMethod.cpp (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /*****************************************************************************/
2 // Haiku InputServer
3 //
4 // This is the InputServerMethod implementation
5 //
6 // This application and all source files used in its construction, except
7 // where noted, are licensed under the MIT License, and have been written
8 // and are:
9 //
10 // Copyright (c) 2002-2004 Haiku Project
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a
13 // copy of this software and associated documentation files (the "Software"),
14 // to deal in the Software without restriction, including without limitation
15 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 // and/or sell copies of the Software, and to permit persons to whom the
17 // Software is furnished to do so, subject to the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be included
20 // in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 // DEALINGS IN THE SOFTWARE.
29 /*****************************************************************************/
30 
31 #include <InputServerMethod.h>
32 #include <Menu.h>
33 #include <Messenger.h>
34 #include "InputServer.h"
35 #include "InputServerTypes.h"
36 #include "remote_icon.h"
37 /**
38  *  Method: BInputServerMethod::BInputServerMethod()
39  *   Descr:
40  */
41 BInputServerMethod::BInputServerMethod(const char *name,
42                                        const uchar *icon)
43 {
44 	CALLED();
45 	fOwner = new _BMethodAddOn_(this, name, icon);
46 }
47 
48 
49 /**
50  *  Method: BInputServerMethod::~BInputServerMethod()
51  *   Descr:
52  */
53 BInputServerMethod::~BInputServerMethod()
54 {
55 	CALLED();
56 	delete fOwner;
57 }
58 
59 
60 /**
61  *  Method: BInputServerMethod::MethodActivated()
62  *   Descr:
63  */
64 status_t
65 BInputServerMethod::MethodActivated(bool active)
66 {
67     return B_OK;
68 }
69 
70 
71 /**
72  *  Method: BInputServerMethod::EnqueueMessage()
73  *   Descr:
74  */
75 status_t
76 BInputServerMethod::EnqueueMessage(BMessage *message)
77 {
78 	return ((InputServer*)be_app)->EnqueueMethodMessage(message);
79 }
80 
81 
82 /**
83  *  Method: BInputServerMethod::SetName()
84  *   Descr:
85  */
86 status_t
87 BInputServerMethod::SetName(const char *name)
88 {
89     return fOwner->SetName(name);
90 }
91 
92 
93 /**
94  *  Method: BInputServerMethod::SetIcon()
95  *   Descr:
96  */
97 status_t
98 BInputServerMethod::SetIcon(const uchar *icon)
99 {
100     return fOwner->SetIcon(icon);
101 }
102 
103 
104 /**
105  *  Method: BInputServerMethod::SetMenu()
106  *   Descr:
107  */
108 status_t
109 BInputServerMethod::SetMenu(const BMenu *menu,
110                             const BMessenger target)
111 {
112     return fOwner->SetMenu(menu, target);
113 }
114 
115 
116 /**
117  *  Method: BInputServerMethod::_ReservedInputServerMethod1()
118  *   Descr:
119  */
120 void
121 BInputServerMethod::_ReservedInputServerMethod1()
122 {
123 }
124 
125 
126 /**
127  *  Method: BInputServerMethod::_ReservedInputServerMethod2()
128  *   Descr:
129  */
130 void
131 BInputServerMethod::_ReservedInputServerMethod2()
132 {
133 }
134 
135 
136 /**
137  *  Method: BInputServerMethod::_ReservedInputServerMethod3()
138  *   Descr:
139  */
140 void
141 BInputServerMethod::_ReservedInputServerMethod3()
142 {
143 }
144 
145 
146 /**
147  *  Method: BInputServerMethod::_ReservedInputServerMethod4()
148  *   Descr:
149  */
150 void
151 BInputServerMethod::_ReservedInputServerMethod4()
152 {
153 }
154 
155 
156 _BMethodAddOn_::_BMethodAddOn_(BInputServerMethod *method, const char *name,
157 	const uchar *icon)
158 	: fMethod(method),
159 	fMenu(NULL)
160 {
161 	fName = strdup(name);
162 	memcpy(fIcon, icon, 16*16*1);
163 }
164 
165 
166 _BMethodAddOn_::~_BMethodAddOn_()
167 {
168 	free(fName);
169 	delete fMenu;
170 }
171 
172 
173 status_t
174 _BMethodAddOn_::SetName(const char* name)
175 {
176 	CALLED();
177 	if (fName)
178 		free(fName);
179 	if (name)
180 		fName = strdup(name);
181 
182 	BMessage msg(IS_UPDATE_NAME);
183 	msg.AddInt32("cookie", (uint32)fMethod);
184 	msg.AddString("name", name);
185 	if (((InputServer*)be_app)->MethodReplicant())
186 		return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
187 	else
188 		return B_ERROR;
189 }
190 
191 
192 status_t
193 _BMethodAddOn_::SetIcon(const uchar* icon)
194 {
195 	CALLED();
196 	memcpy(fIcon, icon, 16*16*1);
197 
198 	BMessage msg(IS_UPDATE_ICON);
199 	msg.AddInt32("cookie", (uint32)fMethod);
200 	msg.AddData("icon", B_RAW_TYPE, icon, 16*16*1);
201 	if (((InputServer*)be_app)->MethodReplicant())
202 		return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
203 	else
204 		return B_ERROR;
205 }
206 
207 
208 status_t
209 _BMethodAddOn_::SetMenu(const BMenu *menu, const BMessenger &messenger)
210 {
211 	CALLED();
212 	fMenu = menu;
213 	fMessenger = messenger;
214 
215 	BMessage msg(IS_UPDATE_MENU);
216 	msg.AddInt32("cookie", (uint32)fMethod);
217 	BMessage menuMsg;
218 	if (menu)
219 		menu->Archive(&menuMsg);
220 	msg.AddMessage("menu", &menuMsg);
221 	msg.AddMessenger("target", messenger);
222 	if (((InputServer*)be_app)->MethodReplicant())
223 		return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
224 	else
225 		return B_ERROR;
226 }
227 
228 
229 status_t
230 _BMethodAddOn_::MethodActivated(bool activate)
231 {
232 	CALLED();
233 	if (fMethod) {
234 		PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod));
235 		if (activate && ((InputServer*)be_app)->MethodReplicant()) {
236 			BMessage msg(IS_UPDATE_METHOD);
237         		msg.AddInt32("cookie", (uint32)fMethod);
238                 	((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
239 		}
240 		return fMethod->MethodActivated(activate);
241 	}
242 	return B_ERROR;
243 }
244 
245 
246 status_t
247 _BMethodAddOn_::AddMethod()
248 {
249 	PRINT(("%s cookie %p\n", __PRETTY_FUNCTION__, fMethod));
250 	BMessage msg(IS_ADD_METHOD);
251 	msg.AddInt32("cookie", (uint32)fMethod);
252 	msg.AddString("name", fName);
253 	msg.AddData("icon", B_RAW_TYPE, fIcon, 16*16*1);
254 	if (((InputServer*)be_app)->MethodReplicant())
255 		return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg);
256 	else
257 		return B_ERROR;
258 }
259 
260 
261 KeymapMethod::KeymapMethod()
262         : BInputServerMethod("Roman", kRemoteBits)
263 {
264 
265 }
266 
267 
268 KeymapMethod::~KeymapMethod()
269 {
270 
271 }
272 
273