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 static int32 sNextMethodCookie = 1; 157 158 159 _BMethodAddOn_::_BMethodAddOn_(BInputServerMethod *method, const char *name, 160 const uchar *icon) 161 : fMethod(method), 162 fMenu(NULL), 163 fCookie(sNextMethodCookie++) 164 { 165 fName = strdup(name); 166 if (icon != NULL) 167 memcpy(fIcon, icon, 16*16*1); 168 else 169 memset(fIcon, 0x1d, 16*16*1); 170 } 171 172 173 _BMethodAddOn_::~_BMethodAddOn_() 174 { 175 free(fName); 176 delete fMenu; 177 } 178 179 180 status_t 181 _BMethodAddOn_::SetName(const char* name) 182 { 183 CALLED(); 184 if (fName) 185 free(fName); 186 if (name) 187 fName = strdup(name); 188 189 BMessage msg(IS_UPDATE_NAME); 190 msg.AddInt32("cookie", fCookie); 191 msg.AddString("name", name); 192 if (((InputServer*)be_app)->MethodReplicant()) 193 return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); 194 else 195 return B_ERROR; 196 } 197 198 199 status_t 200 _BMethodAddOn_::SetIcon(const uchar* icon) 201 { 202 CALLED(); 203 204 if (icon != NULL) 205 memcpy(fIcon, icon, 16*16*1); 206 else 207 memset(fIcon, 0x1d, 16*16*1); 208 209 BMessage msg(IS_UPDATE_ICON); 210 msg.AddInt32("cookie", fCookie); 211 msg.AddData("icon", B_RAW_TYPE, icon, 16*16*1); 212 if (((InputServer*)be_app)->MethodReplicant()) 213 return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); 214 else 215 return B_ERROR; 216 } 217 218 219 status_t 220 _BMethodAddOn_::SetMenu(const BMenu *menu, const BMessenger &messenger) 221 { 222 CALLED(); 223 fMenu = menu; 224 fMessenger = messenger; 225 226 BMessage msg(IS_UPDATE_MENU); 227 msg.AddInt32("cookie", fCookie); 228 BMessage menuMsg; 229 if (menu) 230 menu->Archive(&menuMsg); 231 msg.AddMessage("menu", &menuMsg); 232 msg.AddMessenger("target", messenger); 233 if (((InputServer*)be_app)->MethodReplicant()) 234 return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); 235 else 236 return B_ERROR; 237 } 238 239 240 status_t 241 _BMethodAddOn_::MethodActivated(bool activate) 242 { 243 CALLED(); 244 if (fMethod) { 245 PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie)); 246 if (activate && ((InputServer*)be_app)->MethodReplicant()) { 247 BMessage msg(IS_UPDATE_METHOD); 248 msg.AddInt32("cookie", fCookie); 249 ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); 250 } 251 return fMethod->MethodActivated(activate); 252 } 253 return B_ERROR; 254 } 255 256 257 status_t 258 _BMethodAddOn_::AddMethod() 259 { 260 PRINT(("%s cookie %" B_PRId32 "\n", __PRETTY_FUNCTION__, fCookie)); 261 BMessage msg(IS_ADD_METHOD); 262 msg.AddInt32("cookie", fCookie); 263 msg.AddString("name", fName); 264 msg.AddData("icon", B_RAW_TYPE, fIcon, 16*16*1); 265 if (((InputServer*)be_app)->MethodReplicant()) 266 return ((InputServer*)be_app)->MethodReplicant()->SendMessage(&msg); 267 else 268 return B_ERROR; 269 } 270 271 272 KeymapMethod::KeymapMethod() 273 : BInputServerMethod("Roman", kRemoteBits) 274 { 275 276 } 277 278 279 KeymapMethod::~KeymapMethod() 280 { 281 282 } 283 284