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