-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlisting1.html
executable file
·971 lines (814 loc) · 36.3 KB
/
listing1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>BasicInputMethod - /BasicInputMethod/BIM.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/Carbon/index.html">Carbon</a> > <a href="../../samplecode/Carbon/idxTextFonts-date.html">Text & Fonts</a> > <A HREF="javascript:location.replace('index.html');">BasicInputMethod</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">BasicInputMethod</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/BasicInputMethod/BIM.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/BasicInputMethod/BIM.c</option>
<option value="listing2.html">/BasicInputMethod/BIM.h</option>
<option value="listing3.html">/BasicInputMethod/BIM.r</option>
<option value="listing4.html">/BasicInputMethod/BIMClientServer.h</option>
<option value="listing5.html">/BasicInputMethod/BIMComponent.c</option>
<option value="listing6.html">/BasicInputMethod/BIMComponent.h</option>
<option value="listing7.html">/BasicInputMethod/BIMInputEvents.c</option>
<option value="listing8.html">/BasicInputMethod/BIMInputEvents.h</option>
<option value="listing9.html">/BasicInputMethod/BIMLaunchServer.c</option>
<option value="listing10.html">/BasicInputMethod/BIMLaunchServer.h</option>
<option value="listing11.html">/BasicInputMethod/BIMMessageReceive.c</option>
<option value="listing12.html">/BasicInputMethod/BIMMessageReceive.h</option>
<option value="listing13.html">/BasicInputMethod/BIMMessageSend.c</option>
<option value="listing14.html">/BasicInputMethod/BIMMessageSend.h</option>
<option value="listing15.html">/BasicInputMethod/BIMScript.h</option>
<option value="listing16.html">/BasicInputMethod/BS.c</option>
<option value="listing17.html">/BasicInputMethod/BSKeyboardPalette.c</option>
<option value="listing18.html">/BasicInputMethod/BSKeyboardPalette.h</option>
<option value="listing19.html">/BasicInputMethod/BSMessageReceive.c</option>
<option value="listing20.html">/BasicInputMethod/BSMessageReceive.h</option>
<option value="listing21.html">/BasicInputMethod/BSMessages.h</option>
<option value="listing22.html">/BasicInputMethod/BSMessageSend.c</option>
<option value="listing23.html">/BasicInputMethod/BSMessageSend.h</option>
<option value="listing24.html">/BasicInputMethod/BSPreferences.c</option>
<option value="listing25.html">/BasicInputMethod/BSPreferences.h</option>
<option value="listing26.html">/BasicInputMethod/BSSendEventPalette.c</option>
<option value="listing27.html">/BasicInputMethod/BSSendEventPalette.h</option></select>
</p>
</form>
<p><strong><a href="BasicInputMethod.zip">Download Sample</a></strong> (“BasicInputMethod.zip”, 157.5K)<BR>
<strong><a href="BasicInputMethod.dmg">Download Sample</a></strong> (“BasicInputMethod.dmg”, 200.1K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/* File: BIM.c Description: Core implementation of our text service. Author: SC Copyright: © Copyright 2000-2001 Apple Computer, Inc. All rights reserved. Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Change History (most recent first): 2001/03/28 SC Removed code that disabled the Show/Hide Debug Palette menu item. 2001/03/09 SC Added a change to the menu attributes so that a pencil glyph will be substituted for the standard control key glyph in the pencil menu (this is for JIS keyboards that feature a pencil glyph on the control key). Implemented the Show/Hide Debug Palette menu item. 2000/07/28 SC Changed to include Carbon.h 2000/06/01 SC Created*/#define TARGET_API_MAC_CARBON 1#include <Carbon/Carbon.h>#include "BIM.h"#include "BIMInputEvents.h"#include "BIMLaunchServer.h"#include "BIMMessageReceive.h"#include "BIMMessageSend.h"#include "BIMClientServer.h"#include "BIMScript.h"// Constantsconst short kMENU_Pencil = kBaseResourceID + 1;const short kICNx_Pencil = kBaseResourceID + 1;enum { kShowHideKeyboardPaletteMenuItem = 1, // Menu item indices. kShowHideSendEventPaletteMenuItem = 2, kConvertToLowercaseMenuItem = 4, kConvertToUppercaseMenuItem = 5};enum { kShowHideKeyboardPaletteMenuCommand = 'SHKP', // Command IDs for our pencil menu items. kShowHideSendEventPaletteMenuCommand = 'SHDP', kConvertToLowercaseMenuCommand = 'CLOW', kConvertToUppercaseMenuCommand = 'CUPP'};const short kSTRx_MenuItems = kBaseResourceID + 1;enum { kShowKeyboardPaletteMenuItemString = 1, // String indices for menu item text. kHideKeyboardPaletteMenuItemString = 2, kShowSendEventPaletteMenuItemString = 3, kHideSendEventPaletteMenuItemString = 4};// Global variablesstatic BIMSessionHandle gActiveSession;static MenuRef gPencilMenu;static CFStringRef gShowKeyboardPaletteMenuItemString;static CFStringRef gHideKeyboardPaletteMenuItemString;static CFStringRef gShowSendEventPaletteMenuItemString;static CFStringRef gHideSendEventPaletteMenuItemString;// Local functionsstatic OSStatus BIMConvertToLowercase( BIMSessionHandle inSessionHandle );static OSStatus BIMConvertToUppercase( BIMSessionHandle inSessionHandle );static pascal OSStatus BIMPencilMenuEventHandler( EventHandlerCallRef inEventHandlerCallRef, EventRef inEventRef, void *inUserData );/************************************************************************************************** BIMInitialize** This routine is called the first time our text service component is instantiated. It is* called via NewTSMDocument.** In this routine we initialize our global state (initialize global variables, launch the* server process, and set up the text service pencil menu). We only initialize global data* here. All per-session context initialization is handled in BIMSessionOpen().** In inComponentInstance The component instance.** Out outTextServiceMenu Our text service menu ref.* ComponentResult A toolbox error code.*************************************************************************************************/ComponentResult BIMInitialize( ComponentInstance inComponentInstance, MenuRef *outTextServiceMenu ){ ComponentResult result; short refNum; EventTypeSpec menuEventSpec; Handle iconData; Handle menuIconSuite; Str255 menuText; result = noErr; refNum = -1; // Initialize our global variables. gActiveSession = NULL; gPencilMenu = NULL; // Initialize the server, launching it if necessary. result = BIMLaunchServer(); // Open our component's resource fork. if( result == noErr ) { refNum = OpenComponentResFile( (Component) inComponentInstance ); result = ResError(); if( ( result == noErr ) && ( refNum == -1 ) ) result = resFNotFound; } // Load the pencil menu. if( result == noErr ) { gPencilMenu = GetMenu( kMENU_Pencil ); if( gPencilMenu ) *outTextServiceMenu = gPencilMenu; else result = resNotFound; } // Indicate that a pencil glyph should be substituted for the standard control key glyph // (for JIS keyboards which have a pencil icon on the control key). if( result == noErr ) ChangeMenuAttributes( gPencilMenu, kMenuAttrUsePencilGlyph, 0 ); // Install an event handler to receive menu commands. if( result == noErr ) { menuEventSpec.eventClass = kEventClassCommand; menuEventSpec.eventKind = kEventProcessCommand; result = InstallMenuEventHandler( gPencilMenu, NewEventHandlerUPP( BIMPencilMenuEventHandler ), 1, &menuEventSpec, nil, nil ); } // Create the pencil icon suite, then load and detach the resources. if( result == noErr ) result = NewIconSuite( &menuIconSuite ); if( result == noErr ) { iconData = GetResource( 'ics8', kICNx_Pencil ); if( iconData == nil ) result = resNotFound; else DetachResource( iconData ); } if( result == noErr ) result = AddIconToSuite( iconData, menuIconSuite, 'ics8' ); if( result == noErr ) { iconData = GetResource( 'ics4', kICNx_Pencil ); if( iconData == nil ) result = resNotFound; else DetachResource( iconData ); } if( result == noErr ) result = AddIconToSuite( iconData, menuIconSuite, 'ics4' ); if( result == noErr ) { iconData = GetResource( 'ics#', kICNx_Pencil ); if( iconData == nil ) result = resNotFound; else DetachResource( iconData ); } if( result == noErr ) result = AddIconToSuite( iconData, menuIconSuite, 'ics#' ); // Set the menu title to the pencil icon. if( result == noErr ) { menuText[0] = 5; menuText[1] = 1; *(Handle *)( &menuText[2] ) = menuIconSuite; SetMenuTitle( gPencilMenu, menuText ); } // Load the menu item strings. if( result == noErr ) { GetIndString( menuText, kSTRx_MenuItems, kShowKeyboardPaletteMenuItemString ); gShowKeyboardPaletteMenuItemString = CFStringCreateWithPascalString( NULL, menuText, kTextEncodingMacRoman ); GetIndString( menuText, kSTRx_MenuItems, kHideKeyboardPaletteMenuItemString ); gHideKeyboardPaletteMenuItemString = CFStringCreateWithPascalString( NULL, menuText, kTextEncodingMacRoman ); GetIndString( menuText, kSTRx_MenuItems, kShowSendEventPaletteMenuItemString ); gShowSendEventPaletteMenuItemString = CFStringCreateWithPascalString( NULL, menuText, kTextEncodingMacRoman ); GetIndString( menuText, kSTRx_MenuItems, kHideSendEventPaletteMenuItemString ); gHideSendEventPaletteMenuItemString = CFStringCreateWithPascalString( NULL, menuText, kTextEncodingMacRoman ); } // Close our component's resource fork. if( refNum != -1 ) CloseComponentResFile( refNum ); // Initialize everything needed to receive messages. if( result == noErr ) result = BIMInitializeMessageReceiving(); // Return to caller. return result;}/************************************************************************************************** BIMTerminate** This routine is called when the last instance of our component is terminated. It is called* via DeleteTSMDocument.** In this routine we dispose of our global state. We do not handle per-session stuff in this* routine.** In inComponentInstance The component instance.*************************************************************************************************/void BIMTerminate( ComponentInstance inComponentInstance ){ // Clear our global variables. gActiveSession = NULL; gPencilMenu = NULL;}#pragma mark -/************************************************************************************************** BIMSessionOpen** This routine is called via NewTSMDocument.** In this routine, we initialize a new session context. We create a session handle to store all* of the information pertinent to the session and initialize all its data structures. We do not* handle initialize global data (data that is shared across sessions); that is taken care of by* BIMInitialize().** In inComponentInstance The component instance.** Out outSessionHandle The new session context.* ComponentResult A toolbox error code.*************************************************************************************************/ComponentResult BIMSessionOpen( ComponentInstance inComponentInstance, BIMSessionHandle *outSessionHandle ){ ComponentResult result; result = noErr; // If per-session storage is not set up yet, do so now. if( result == noErr ) { if( *outSessionHandle == nil ) *outSessionHandle =( BIMSessionHandle ) NewHandle( sizeof( BIMSessionRecord ) ); if( *outSessionHandle ) { // Initialize the contents. ( **outSessionHandle )->fComponentInstance = inComponentInstance; ( **outSessionHandle )->fLastUpdateLength = 0; ( **outSessionHandle )->fInputBufferCount = 0; ( **outSessionHandle )->fInputBuffer = nil; } else result = memFullErr; } // Initialize the input buffer. if( result == noErr ) { ( **outSessionHandle )->fInputBuffer = (UniCharPtr) NewPtr( 1024 ); result = MemError(); } // Return result. return result;}/************************************************************************************************** BIMSessionClose** This routine is called via DeleteTSMDocument.** In this routine, we destroy the current session context. This includes all per-session data* that is stored in the session handle and the session handle itself.** In inSessionHandle The session context to destroy.*************************************************************************************************/void BIMSessionClose( BIMSessionHandle inSessionHandle ){ if( inSessionHandle ) { // Dispose of our input buffer. if( ( *inSessionHandle )->fInputBuffer ) DisposePtr( (Ptr) ( *inSessionHandle )->fInputBuffer ); // Dispose if the session handle itself. DisposeHandle( (Handle) inSessionHandle ); }}/************************************************************************************************** BIMSessionActivate** This routine is called by the Text Services Manager whenever an application calls* NewTSMDocument or ActivateTSMDocument. The appropriate response to ActivateTextService is to* restore our active state, including displaying all floating windows if they have been hidden,* and redisplaying any inconfirmed text in the currently active input area.** In inSessionHandle The session context.** Out ComponentResult A toolbox error code.*************************************************************************************************/ComponentResult BIMSessionActivate( BIMSessionHandle inSessionHandle ){ OSStatus result; Boolean isHidden; gActiveSession = inSessionHandle; // When we are activated, we register ourselves with the server process. result = BIMSendActivatedMessage(); // Update the menu items. if( result == noErr ) result = BIMIsKeyboardPaletteHidden( &isHidden ); if( result == noErr ) BIMUpdateShowHideKeyboardPaletteMenuItem( isHidden ); if( result == noErr ) result = BIMIsSendEventPaletteHidden( &isHidden ); if( result == noErr ) BIMUpdateShowHideSendEventPaletteMenuItem( isHidden ); return result;}/************************************************************************************************** BIMSessionDeactivate** This routine is called by the Text Services Manager whenever an application calls* DeactivateTSMDocument. We are responsible for saving whatever state information we need to* save so that we can restore it again when we are reactivated. We should not confirm any* unconfirmed text in the active input area, but save it until reactivation. We should not hide* our floating windows either.** In inSessionHandle The session context.** Out ComponentResult A toolbox error code.*************************************************************************************************/ComponentResult BIMSessionDeactivate( BIMSessionHandle inSessionHandle ){ gActiveSession = nil; // We have been deactivated, so deregister ourselves with the server process. return BIMSendDeactivatedMessage();}/************************************************************************************************** BIMSessionEvent** This routine is called by the Text Services Manager in response to mouse and keyboard events.* The events are passed in via eventRef. We use the standard Carbon Event Manager calls* (GetEventClass, GetEventKind, and GetEventParameter) to extract information from the event.** In inSessionHandle The session context.* inEventRef An eventRef describing the user event.** Out ComponentResult True if we handled the event, otherwise false.*************************************************************************************************/ComponentResult BIMSessionEvent( BIMSessionHandle inSessionHandle, EventRef inEventRef ){ Boolean handled; UInt32 eventClass; UInt32 eventKind; handled = FALSE; // Extract the event class and kind. eventClass = GetEventClass( inEventRef ); eventKind = GetEventKind( inEventRef ); // For now, we're only interested in the 2 raw keyboard events kEventRawKeyDown and // kEventRawKeyRepeat. // // kEventClassKeyboard: // kEventRawKeyDown - A key was pressed // kEventRawKeyRepeat - Sent periodically as a key is held down by the user // kEventRawKeyUp - A key was released // kEventRawKeyModifiersChanged - The keyboard modifiers (bucky bits) have changed if( eventClass == kEventClassKeyboard && ( eventKind == kEventRawKeyDown || eventKind == kEventRawKeyRepeat ) ) { UInt32 keyCode; unsigned char charCode; UInt32 modifiers; // Extract the key code parameter (kEventParamKeyCode). GetEventParameter( inEventRef, kEventParamKeyCode, typeUInt32, nil, sizeof (keyCode), nil, &keyCode ); // Extract the character code parameter (kEventParamKeyMacCharCodes). GetEventParameter( inEventRef, kEventParamKeyMacCharCodes, typeChar, nil, sizeof( charCode ), nil, &charCode ); // Extract the modifiers parameter (kEventParamKeyModifiers). GetEventParameter( inEventRef, kEventParamKeyModifiers, typeUInt32, nil, sizeof( modifiers ), nil, &modifiers ); // Handle the key. handled = BIMHandleInput( inSessionHandle, charCode ); } return handled;}/************************************************************************************************** BIMSessionFix** This routine is called via FixTSMDocument.** In this routine we fix all the active text (send any remaining text in the currently active* inline area to the application).** In inSessionHandle The session context.** Out ComponentResult A toolbox error code.*************************************************************************************************/ComponentResult BIMSessionFix( BIMSessionHandle inSessionHandle ){ ComponentResult result; if( ( *inSessionHandle )->fInputBufferCount ) { result = BIMUpdateActiveInputArea( inSessionHandle, true ); ( *inSessionHandle )->fLastUpdateLength = 0; ( *inSessionHandle )->fInputBufferCount = 0; } return result;}/************************************************************************************************** BIMSessionHidePalettes** Handles requests from the Text Services Manager or the applicatin to hide our palette windows.* The palettes are managed by the server, so here we send a message to the server process,* telling it to hide any open palette windows.** In inSessionHandle The current session.** Out ComponentResult A toolbox error code.*************************************************************************************************/ComponentResult BIMSessionHidePalettes( BIMSessionHandle inSessionHandle ){ return BIMSendHidePalettesMessage();}#pragma mark -/************************************************************************************************** BIMGetActiveSession** Returns the current active session, or NULL if there is no active session.** Out BIMSessionHandle The current active session.*************************************************************************************************/BIMSessionHandle BIMGetActiveSession( void ){ return gActiveSession;}/************************************************************************************************** BIMHandleInput** Handles input from the keyboard or via a message from the server process.** In inSessionHandle The current session.* inCharCode The character code of the keypress.** Out Boolean TRUE if the input was handled, FALSE otherwise.*************************************************************************************************/Boolean BIMHandleInput( BIMSessionHandle inSessionHandle, unsigned char inCharCode ){ Boolean handled; handled = FALSE; switch( inCharCode ) { // Handle the delete key. Here we do the most simple processing -- removing the last // character from the input buffer. case 0x08: if( ( *inSessionHandle )->fInputBufferCount ) { (( *inSessionHandle )->fInputBufferCount)--; BIMUpdateActiveInputArea( inSessionHandle, FALSE ); handled = TRUE; } break; // Handle the enter and return keys by fixing the current inline session. case 0x03: case 0x0D: if( ( *inSessionHandle )->fInputBufferCount ) { BIMSessionFix( inSessionHandle ); handled = TRUE; } break; // Handle all other keys. default: ( *inSessionHandle )->fInputBuffer [ ( *inSessionHandle )->fInputBufferCount ] = inCharCode; (( *inSessionHandle )->fInputBufferCount)++; BIMUpdateActiveInputArea( inSessionHandle, FALSE ); handled = TRUE; break; } return handled;}/************************************************************************************************** BIMUpdateShowHideKeyboardPaletteMenuItem** Updates the "Show Keyboard Palette"/"Hide Keyboard Palette" menu item text as appropriate.** In inIsHidden The current visible status of the keyboard palette.*************************************************************************************************/void BIMUpdateShowHideKeyboardPaletteMenuItem( Boolean inIsHidden ){ if( inIsHidden ) SetMenuItemTextWithCFString( gPencilMenu, kShowHideKeyboardPaletteMenuItem, gShowKeyboardPaletteMenuItemString ); else SetMenuItemTextWithCFString( gPencilMenu, kShowHideKeyboardPaletteMenuItem, gHideKeyboardPaletteMenuItemString );}/************************************************************************************************** BIMUpdateShowHideSendEventPaletteMenuItem** Updates the "Show Send Event Palette"/"Hide Send Event Palette" menu item text as appropriate.** In inIsHidden The current visible status of the send event palette.*************************************************************************************************/void BIMUpdateShowHideSendEventPaletteMenuItem( Boolean inIsHidden ){ if( inIsHidden ) SetMenuItemTextWithCFString( gPencilMenu, kShowHideSendEventPaletteMenuItem, gShowSendEventPaletteMenuItemString ); else SetMenuItemTextWithCFString( gPencilMenu, kShowHideSendEventPaletteMenuItem, gHideSendEventPaletteMenuItemString );}#pragma mark -/************************************************************************************************** BIMConvertToLowercase** Converts the currently active text in the inline hole to lowercase. Called when the user* selects the "Convert to Lowercase" menu item from our text service (pencil) menu.** In inSessionHandle Our session context.** Out OSStatus A toolbox result code.*************************************************************************************************/static OSStatus BIMConvertToLowercase( BIMSessionHandle inSessionHandle ){ UInt32 index; UniChar character; for( index = 0; index < ( *inSessionHandle )->fInputBufferCount; index++ ) { character = ( *inSessionHandle )->fInputBuffer [index]; if( character >= 'A' && character <= 'Z' ) character += 0x20; ( *inSessionHandle )->fInputBuffer [index] = character; } return BIMUpdateActiveInputArea( gActiveSession, false );}/************************************************************************************************** BIMConvertToUppercase** Converts the currently active text in the inline hole to uppercase. Called when the user* selects the "Convert to Uppercase" menu item from our text service (pencil) menu.** In inSessionHandle Our session context.** Out OSStatus A toolbox result code.*************************************************************************************************/static OSStatus BIMConvertToUppercase( BIMSessionHandle inSessionHandle ){ UInt32 index; UniChar character; for( index = 0; index < ( *inSessionHandle )->fInputBufferCount; index++ ) { character = ( *inSessionHandle )->fInputBuffer [index]; if( character >= 'a' && character <= 'z' ) character -= 0x20; ( *inSessionHandle )->fInputBuffer [index] = character; } return BIMUpdateActiveInputArea( gActiveSession, false );}/************************************************************************************************** BIMPencilMenuEventHandler** Handles menu selection events in the pencil menu.** In inEventHandlerCallRef A reference to this event handler.* inEventRef A reference to this event.* inUserData Contains our BIMSessionHandle that we passed as part of* InstallMenuEventHandler().** Out OSStatus eventNotHandledErr if the event was not handled, or* noErr if the event was handled.*************************************************************************************************/static pascal OSStatus BIMPencilMenuEventHandler( EventHandlerCallRef inEventHandlerCallRef, EventRef inEventRef, void *inUserData ){ OSStatus result; Boolean isHidden; HICommand command; // Get the selected menu command. result = GetEventParameter( inEventRef, kEventParamDirectObject, typeHICommand, nil, sizeof( command ), nil, &command); if( result == noErr ) { switch( command.commandID ) { // Handle the "Show Keyboard Palette" or "Hide Keyboard Palette" menu item. case kShowHideKeyboardPaletteMenuCommand: result = BIMIsKeyboardPaletteHidden( &isHidden ); if( result == noErr ) { if( isHidden ) result = BIMShowKeyboardPalette(); else result = BIMHideKeyboardPalette(); } if( result == noErr ) result = BIMIsKeyboardPaletteHidden( &isHidden ); if( result == noErr ) BIMUpdateShowHideKeyboardPaletteMenuItem( isHidden ); break; // Handle the "Show Send Event Palette" or "Hide Send Event Palette" menu item. case kShowHideSendEventPaletteMenuCommand: result = BIMIsSendEventPaletteHidden( &isHidden ); if( result == noErr ) { if( isHidden ) result = BIMShowSendEventPalette(); else result = BIMHideSendEventPalette(); } if( result == noErr ) result = BIMIsSendEventPaletteHidden( &isHidden ); if( result == noErr ) BIMUpdateShowHideSendEventPaletteMenuItem( isHidden ); break; // Handle the "Convert to Lowercase" menu item. case kConvertToLowercaseMenuCommand: if( gActiveSession ) result = BIMConvertToLowercase( gActiveSession ); break; // Handle the "Convert to Uppercase" menu item. case kConvertToUppercaseMenuCommand: if( gActiveSession ) result = BIMConvertToUppercase ( gActiveSession ); break; default: result = eventNotHandledErr; break; } } else result = eventNotHandledErr; return result;}/************************************************************************************************** BIMLog** Log the given message to stderr. Uncomment the following to enable logging.*************************************************************************************************/void BIMLog( unsigned char *message ){/* fprintf( stderr, message );*/}</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/BasicInputMethod/listing1.html%3Fid%3DDTS10000662-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/BasicInputMethod/listing1.html%3Fid%3DDTS10000662-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/BasicInputMethod/listing1.html%3Fid%3DDTS10000662-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>