Back to index

im-sdk  12.3.91
IMProtocol.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include "IMProtocol.hh"
00043 #include "IMProtoHandler.hh"
00044 #include "IMArg.h"
00045 
00046 int
00047 IMProtocol::countOnKeys() const {
00048   return on_keys.count();
00049 }
00050 
00051 int
00052 IMProtocol::countOffKeys() const {
00053   return off_keys.count();
00054 }
00055 
00056 IMTriggerKey&
00057 IMProtocol::getOnKey(unsigned int index) const {
00058   return on_keys.getKey(index);
00059 }
00060 
00061 IMTriggerKey&
00062 IMProtocol::getOffKey(unsigned int index) const {
00063   return off_keys.getKey(index);
00064 }
00065 
00066 int
00067 IMProtocol::countLanguages() const {
00068   return lang_list.count();
00069 }
00070 
00071 CompoundString&
00072 IMProtocol::getLang(unsigned int index) const {
00073   return lang_list.getLang(index);
00074 }
00075 
00076 int
00077 IMProtocol::countObjectDescriptors() const {
00078   return od_list.count();
00079 }
00080 
00081 IMObjectDescriptorStruct&
00082 IMProtocol::getObjectDescriptor(unsigned int index) const {
00083   return od_list.getObjectDescriptor(index);
00084 }
00085 
00086 IMObjectDescriptorStruct&
00087 IMProtocol::getFirstObjectDescriptor() {
00088   return od_list.getFirstObjectDescriptor();
00089 }
00090 
00091 IMObjectDescriptorStruct&
00092 IMProtocol::getNextObjectDescriptor() {
00093   return od_list.getNextObjectDescriptor();
00094 }
00095 
00096 int
00097 IMProtocol::countIME() const {
00098   return ime_list.count();
00099 }
00100 
00101 IMEditorStruct&
00102 IMProtocol::getIME(unsigned int index) const {
00103   return ime_list.getIME(index);
00104 }
00105 
00106 IMEditorStruct&
00107 IMProtocol::getFirstIME() {
00108   return ime_list.getFirstIME();
00109 }
00110 
00111 IMEditorStruct&
00112 IMProtocol::getNextIME() {
00113   return ime_list.getNextIME();
00114 }
00115 
00116 const CompoundString&
00117 IMProtocol::getPrimaryLocale() const {
00118   return input_locale;
00119 }
00120 
00121 int
00122 IMProtocol::parseArgs(int mode, IMArg *args, int n) {
00123   if (n == 0) return 0;
00124   if (mode == IMProtocol::OPEN || mode == IMProtocol::SET) {
00125     for (IMArg *argp = args; argp < &args[n]; argp++) {
00126       switch (argp->id) {
00127       case ServerName:
00128        im_name = argp->value;
00129        break;
00130       case TransportAddress:
00131        im_address = argp->value;
00132        break;
00133       case VendorName:
00134        vendor_name = argp->value;
00135        break;
00136       case PrimaryInputLocale:
00137        input_locale = argp->value;
00138        break;
00139       case LanguageList:
00140        lang_list = *(IMLanguageList*)argp->value;
00141        break;
00142       case ConversionOnKeys:
00143        on_keys = *(IMTriggerKeyList*)argp->value;
00144        break;
00145       case ConversionOffKeys:
00146        off_keys = *(IMTriggerKeyList*)argp->value;
00147        break;
00148       case ProtocolHandler:
00149        proto_handler = (IMProtoHandler*)argp->value;
00150        break;
00151       case ObjectDescriptors:
00152        od_list = *(IMObjectDescriptorList*)argp->value;
00153        break;
00154       case IMEDescriptors:
00155        ime_list = *(IMEditorDescriptorList*)argp->value;
00156        break;
00157       default:
00158        break;
00159       }
00160     }
00161   } else if (mode == IMProtocol::GET) {
00162     for (IMArg *argp = args; argp < &args[n]; argp++) {
00163       switch (argp->id) {
00164       case ServerName:
00165        {
00166          char **pp = (char**)argp->value;
00167          *pp = im_name;
00168          break;
00169        }
00170       case TransportAddress:
00171        {
00172          char **pp = (char**)argp->value;
00173          *pp = im_address;
00174          break;
00175        }
00176       }
00177     }
00178     return 0;
00179   }
00180   return 0;
00181 }
00182 
00183 IMProtocol::IMProtocol(IMArg *args, int n) {
00184   proto_handler = 0;
00185   parseArgs(IMProtocol::OPEN, args, n);
00186 }
00187 
00188 IMProtocol::~IMProtocol() {}
00189 
00190 int
00191 IMProtocol::set_values(IMArg *args, int n) {
00192   return parseArgs(IMProtocol::SET, args, n);
00193 }
00194 
00195 int
00196 IMProtocol::get_values(IMArg *args, int n) {
00197   return parseArgs(IMProtocol::GET, args, n);
00198 }
00199 
00200 IMTransAccept*
00201 IMProtocol::getIMTransAccept(IMTransListen *trans_listen) const
00202 {
00203   return proto_handler->getIMTransAccept(trans_listen);
00204 }