objc2_input_method_kit/generated/
IMKInputController.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7use objc2_app_kit::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12mod private_NSObjectIMKServerInput {
13    pub trait Sealed {}
14}
15
16/// Category "IMKServerInput" on [`NSObject`].
17/// Informal protocol which is used to send user events to an input method.
18///
19/// This is not a formal protocol by choice.  The reason for that is that there are three ways to receive events here. An input method should choose one of those ways and  implement the appropriate methods.
20///
21/// Here are the three approaches:
22///
23/// 1.  Support keybinding.
24/// In this approach the system takes each keydown and trys to map the keydown to an action method that the input method has implemented.  If an action is found the system calls didCommandBySelector:client:.  If no action method is found inputText:client: is called.  An input method choosing this approach should implement
25/// -(BOOL)inputText:(NSString*)string client:(id)sender;
26/// -(BOOL)didCommandBySelector:(SEL)aSelector client:(id)sender;
27///
28/// 2. Receive all key events without the keybinding, but do "unpack" the relevant text data.
29/// Key events are broken down into the Unicodes, the key code that generated them, and modifier flags.  This data is then sent to the input method's inputText:key:modifiers:client: method.  For this approach implement:
30/// -(BOOL)inputText:(NSString*)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender;
31///
32/// 3. Receive events directly from the Text Services Manager as NSEvent objects.  For this approach implement:
33/// -(BOOL)handleEvent:(NSEvent*)event client:(id)sender;
34#[doc(alias = "IMKServerInput")]
35pub unsafe trait NSObjectIMKServerInput:
36    ClassType + Sized + private_NSObjectIMKServerInput::Sealed
37{
38    extern_methods!(
39        /// Receive the Unicodes, the key code that generated them and modifier flags.
40        ///
41        /// Input methods implementing this method should return YES if the input was excepted, and NO if not excepted.
42        #[unsafe(method(inputText:key:modifiers:client:))]
43        #[unsafe(method_family = none)]
44        unsafe fn inputText_key_modifiers_client(
45            &self,
46            string: Option<&NSString>,
47            key_code: NSInteger,
48            flags: NSUInteger,
49            sender: Option<&AnyObject>,
50        ) -> bool;
51
52        /// Each keydown that does not map to an action method is delivered to the input method as an NSString.
53        ///
54        /// If the input string is not excepted the input method should return NO.  When text is accepted return YES.  Input methods should implement this method when they are using keybinding (i.e. have implemented didCommandBySelector:client:).
55        #[unsafe(method(inputText:client:))]
56        #[unsafe(method_family = none)]
57        unsafe fn inputText_client(
58            &self,
59            string: Option<&NSString>,
60            sender: Option<&AnyObject>,
61        ) -> bool;
62
63        #[cfg(feature = "objc2-app-kit")]
64        /// Receive all keydown and mouse events as an NSEvent (i.e. the event is simply forwarded onto the input method).
65        ///
66        /// Return YES if the event was handled. NO if not handled.
67        #[unsafe(method(handleEvent:client:))]
68        #[unsafe(method_family = none)]
69        unsafe fn handleEvent_client(
70            &self,
71            event: Option<&NSEvent>,
72            sender: Option<&AnyObject>,
73        ) -> bool;
74
75        /// Called when system binds a keyDown event to an action method.
76        ///
77        /// This method is designed to return YES if the command is handled and NO if the command is not handled. It is called to process a command that was generated by user action such as typing certain keys or mousing down. It is necessary for this method to return YES or NO so the  event can be passed through to the client if it is not handled.  The selector can be an action specified in the input method's dictionary of keys and actions (i.e. an action specific to the input method) or one of the NSResponder action methods such as insertNewline: or deleteBackward:.  By definition such action methods do not return a value.  For that reason if you implement this method you should test if it is appropriate to call the action method before calling it since calling the action method is agreeing to handle the command
78        ///
79        /// For example.  Suppose you have implemented a version of insertNewline: that terminates the conversion session and sends the fully converted text to the client.  However, if you conversion buffer is empty you want the application to receive the return key that triggered the call to insertNewline:.  In that case when didCommandBySelector:client: is called you should test your buffer before calling your implementation of insertNewline:.  If the buffer is empty you would return NO indicating that the return key should be passed on to the application.  If the buffer is not empty you would call insertNewline: and then return YES as the result of didCommandBySelector:client:.
80        #[unsafe(method(didCommandBySelector:client:))]
81        #[unsafe(method_family = none)]
82        unsafe fn didCommandBySelector_client(
83            &self,
84            a_selector: Option<Sel>,
85            sender: Option<&AnyObject>,
86        ) -> bool;
87
88        /// Return the current composed string.  This may be an NSString or NSAttributedString.
89        ///
90        /// A composed string refers to the buffer that an input method typically maintains to mirror the text contained in the active inline area.  It is called the composed string to reflect the fact that the input method composed the string by converting the characters input by the user.  In addition, using the term composed string makes it easier to differentiate between an input method's buffer and the text in the active inline area that the user sees. The returned object should be an autoreleased object.
91        #[unsafe(method(composedString:))]
92        #[unsafe(method_family = none)]
93        unsafe fn composedString(&self, sender: Option<&AnyObject>) -> Option<Retained<AnyObject>>;
94
95        /// Return the a string consisting of the original pre-composition unicodes.
96        ///
97        /// If an input method stores the original input text it should return that text here.  The return value is an attributed string so that input method's can potentially restore changes they may have made to the font, etc.  The returned object should be an autoreleased object.
98        #[unsafe(method(originalString:))]
99        #[unsafe(method_family = none)]
100        unsafe fn originalString(
101            &self,
102            sender: Option<&AnyObject>,
103        ) -> Option<Retained<NSAttributedString>>;
104
105        /// Called to inform the controller that the composition should be committed.
106        ///
107        /// If an input method implements this method it will be called when the client wishes to end the composition session immediately. A typical response would be to call the client's insertText method and then clean up any per-session buffers and variables.  After receiving this message an input method should consider the given composition session finished.
108        #[unsafe(method(commitComposition:))]
109        #[unsafe(method_family = none)]
110        unsafe fn commitComposition(&self, sender: Option<&AnyObject>);
111
112        /// Called to get an array of candidates.
113        ///
114        /// An input method would look up its currently composed string and return a list of candidate strings that that string might map to. The returned NSArray should be an autoreleased object.
115        #[unsafe(method(candidates:))]
116        #[unsafe(method_family = none)]
117        unsafe fn candidates(&self, sender: Option<&AnyObject>) -> Option<Retained<NSArray>>;
118    );
119}
120
121impl private_NSObjectIMKServerInput::Sealed for NSObject {}
122unsafe impl NSObjectIMKServerInput for NSObject {}
123
124extern_protocol!(
125    /// This protocol sets or accesses values that indicate the state of an input method.
126    ///
127    /// See also [Apple's documentation](https://developer.apple.com/documentation/inputmethodkit/imkstatesetting?language=objc)
128    pub unsafe trait IMKStateSetting {
129        /// Activates the input method.
130        #[unsafe(method(activateServer:))]
131        #[unsafe(method_family = none)]
132        unsafe fn activateServer(&self, sender: Option<&AnyObject>);
133
134        /// Deactivate the input method.
135        #[unsafe(method(deactivateServer:))]
136        #[unsafe(method_family = none)]
137        unsafe fn deactivateServer(&self, sender: Option<&AnyObject>);
138
139        /// Return a object value whose key is tag.  The returned object should be autoreleased.
140        #[unsafe(method(valueForTag:client:))]
141        #[unsafe(method_family = none)]
142        unsafe fn valueForTag_client(
143            &self,
144            tag: c_long,
145            sender: Option<&AnyObject>,
146        ) -> Option<Retained<AnyObject>>;
147
148        /// Set the tagged value to the object specified by value.
149        #[unsafe(method(setValue:forTag:client:))]
150        #[unsafe(method_family = none)]
151        unsafe fn setValue_forTag_client(
152            &self,
153            value: Option<&AnyObject>,
154            tag: c_long,
155            sender: Option<&AnyObject>,
156        );
157
158        /// This is called to obtain the input method's modes dictionary.
159        ///
160        /// Typically this is called to to build the text input menu.  By calling the input method rather than reading the modes from the info.plist the input method can dynamically modify he modes supported. The returned NSDictionary should be an autoreleased object.
161        #[unsafe(method(modes:))]
162        #[unsafe(method_family = none)]
163        unsafe fn modes(&self, sender: Option<&AnyObject>) -> Option<Retained<NSDictionary>>;
164
165        /// Returns an unsigned integer containing a union of event masks (see NSEvent.h)
166        ///
167        /// A client will check with an input method to see if an event is supported by calling the method.  The default implementation returns NSKeyDownMask.
168        /// If your input method only handles key downs the InputMethodKit provides default mouse handling.  The default mousedown handling behavior is as follows: if there is an active composition area and the user clicks in the text but outside of the composition area the InputMethodKit will send your input method a commitComposition: message. Note that this will only happen for input methods that return just NSKeyDownMask (i.e. the default value) as the result of recognizedEvents.
169        #[unsafe(method(recognizedEvents:))]
170        #[unsafe(method_family = none)]
171        unsafe fn recognizedEvents(&self, sender: Option<&AnyObject>) -> NSUInteger;
172
173        /// Looks for a nib file containing a windowController class and a preferences utility. If found the panel is displayed.
174        ///
175        /// To use this method include a menu item whose action is showPreferences: in your input method's menu.  If that is done the method will be called automatically when a user selects the item in the Text Input Menu.
176        /// The default implementation looks for a nib file called preferences.nib.  If found a windowController class is allocated and the nib is loaded.  You can provide a custom windowController class by naming the class in your input methods info.plist file.  To do that provide a string value that names the custom class with a key of InputMethodServerPreferencesWindowControllerClass.
177        #[unsafe(method(showPreferences:))]
178        #[unsafe(method_family = none)]
179        unsafe fn showPreferences(&self, sender: Option<&AnyObject>);
180    }
181);
182
183extern_protocol!(
184    /// This protocol receives mouse events.
185    ///
186    /// See also [Apple's documentation](https://developer.apple.com/documentation/inputmethodkit/imkmousehandling?language=objc)
187    pub unsafe trait IMKMouseHandling {
188        /// Sends a mouseDown to an input method.
189        ///
190        /// A mouse down event happened at given index within the sender�s text storage, at the given point, and with modifier keys identified in flags. Return YES if handled.  Set keepTracking to YES if you want to receive subsequent mouseMoved and mouseUp events.
191        #[unsafe(method(mouseDownOnCharacterIndex:coordinate:withModifier:continueTracking:client:))]
192        #[unsafe(method_family = none)]
193        unsafe fn mouseDownOnCharacterIndex_coordinate_withModifier_continueTracking_client(
194            &self,
195            index: NSUInteger,
196            point: NSPoint,
197            flags: NSUInteger,
198            keep_tracking: *mut Bool,
199            sender: Option<&AnyObject>,
200        ) -> bool;
201
202        /// Sends a mouseUp to an input method.
203        ///
204        /// A mouse up event happened at given index within the sender text view�s text storage, at the given point, with modifier keys identified in flags. Return YES if handled.
205        #[unsafe(method(mouseUpOnCharacterIndex:coordinate:withModifier:client:))]
206        #[unsafe(method_family = none)]
207        unsafe fn mouseUpOnCharacterIndex_coordinate_withModifier_client(
208            &self,
209            index: NSUInteger,
210            point: NSPoint,
211            flags: NSUInteger,
212            sender: Option<&AnyObject>,
213        ) -> bool;
214
215        /// Passes a mouseMoved event to the input method.
216        ///
217        /// A mouse moved event happened at given index within the sender text view�s text storage, at the given point, with modifier keys identified in flags. Return YES if handled.
218        #[unsafe(method(mouseMovedOnCharacterIndex:coordinate:withModifier:client:))]
219        #[unsafe(method_family = none)]
220        unsafe fn mouseMovedOnCharacterIndex_coordinate_withModifier_client(
221            &self,
222            index: NSUInteger,
223            point: NSPoint,
224            flags: NSUInteger,
225            sender: Option<&AnyObject>,
226        ) -> bool;
227    }
228);
229
230extern_class!(
231    /// The basic class that controls input on the input method side.
232    ///
233    /// IMKInputController implements fully implements the protocols defined above.  Typically a developer does not override this class, but provides a delegate object that implements the methods that developer is interested in.  The IMKInputController versions of the protocol methods check if the delegate object implements a method, and  call the delegate version if it exists.
234    ///
235    /// The IMKServer class which is allocated in an input method's main function creates a controller class for each input session created by a client application. Therefore for every input session there is a corresponding IMKInputController.
236    ///
237    /// See also [Apple's documentation](https://developer.apple.com/documentation/inputmethodkit/imkinputcontroller?language=objc)
238    #[unsafe(super(NSObject))]
239    #[derive(Debug, PartialEq, Eq, Hash)]
240    pub struct IMKInputController;
241);
242
243extern_conformance!(
244    unsafe impl IMKMouseHandling for IMKInputController {}
245);
246
247extern_conformance!(
248    unsafe impl IMKStateSetting for IMKInputController {}
249);
250
251extern_conformance!(
252    unsafe impl NSObjectProtocol for IMKInputController {}
253);
254
255impl IMKInputController {
256    extern_methods!(
257        #[cfg(feature = "IMKServer")]
258        /// Initializes the controller class setting the delegate.
259        ///
260        /// The inputClient parameter is the client side object that will be sending messages to the controller via the IMKServer.  The client object always conforms to the IMKTextInput protocol.
261        ///
262        /// Methods in the protocols that are implemented by the delegate object always include a client parameter.  Methods in the IMKInputController class do not take a client.  This is because the client is stored as an ivar in the IMKInputController.
263        #[unsafe(method(initWithServer:delegate:client:))]
264        #[unsafe(method_family = init)]
265        pub unsafe fn initWithServer_delegate_client(
266            this: Allocated<Self>,
267            server: Option<&IMKServer>,
268            delegate: Option<&AnyObject>,
269            input_client: Option<&AnyObject>,
270        ) -> Option<Retained<Self>>;
271
272        /// Called to inform the controller that the composition has changed.
273        ///
274        /// This method will call the protocol method composedString: to obtain the current composition. The current composition will be sent to the client by a call to the method setMarkedText:
275        #[unsafe(method(updateComposition))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn updateComposition(&self);
278
279        /// Stops the current composition and replaces marked text with the original text.
280        ///
281        /// Calls the method originalString to obtain the original text and sends that to the client via a call to IMKInputSession protocol method insertText:
282        #[unsafe(method(cancelComposition))]
283        #[unsafe(method_family = none)]
284        pub unsafe fn cancelComposition(&self);
285
286        /// Called to obtain a dictionary of text attributes.
287        ///
288        /// The default implementation returns an empty dictionary.  You should override this method if your input method wants to provide font or glyphInformation. The returned object should be an autoreleased object.
289        #[unsafe(method(compositionAttributesAtRange:))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn compositionAttributesAtRange(
292            &self,
293            range: NSRange,
294        ) -> Option<Retained<NSMutableDictionary>>;
295
296        /// Returns where the selection should be placed inside markedText.
297        ///
298        /// This method is called by updateComposition: to obtain the selection range for markedText.  The default implementation sets the selection range at the end of the marked text.
299        #[unsafe(method(selectionRange))]
300        #[unsafe(method_family = none)]
301        pub unsafe fn selectionRange(&self) -> NSRange;
302
303        /// Returns the range in the client document that text should replace.
304        ///
305        /// This method is called by updateComposition to obtain the range in the client's document where markedText should be placed.  The default implementation returns an NSRange whose location and length are NSNotFound.  That indicates that the marked text should be placed at the current insertion point.  Input methods that wish to insert marked text somewhere other than at the current insertion point should override this method.
306        ///
307        /// An example of an input method that might override this method would be one replaced words with synonyms.  That input method would watch for certain words and when one of those words was seen it would be replaced by marked text that was a synonym of the word.
308        #[unsafe(method(replacementRange))]
309        #[unsafe(method_family = none)]
310        pub unsafe fn replacementRange(&self) -> NSRange;
311
312        /// Returns a dictionary of text attributes that can be used to mark a range of an attributed string that is going to be sent to a client.
313        ///
314        /// This utility function can be called by input methods to mark each range (i.e. clause ) of marked text.  The style parameter should be one of the following values: kTSMHiliteSelectedRawText, kTSMHiliteConvertedText or kTSMHiliteSelectedConvertedText. See AERegistry.h for the definition of these values.
315        ///
316        /// The default implementation begins by calling compositionAttributesAtRange: to obtain extra attributes that an input method wants to include such as font or  glyph information.  Then the appropriate underline and underline color information is added to the attributes dictionary for the style parameter.
317        ///
318        /// Finally the style value is added as dictionary value.  The key for the style value is NSMarkedClauseSegment. The returned object should be an autoreleased object.
319        #[unsafe(method(markForStyle:atRange:))]
320        #[unsafe(method_family = none)]
321        pub unsafe fn markForStyle_atRange(
322            &self,
323            style: NSInteger,
324            range: NSRange,
325        ) -> Option<Retained<NSDictionary>>;
326
327        /// Called to pass commands that are not generated as part of the text input.
328        ///
329        /// The default implementation checks if the controller object (i.e. self) responds to the selector.  If that is true the message performSelector:withObject  is sent to the controller class.  The object parameter in that case is the infoDictionary.
330        ///
331        /// This method is called when a user selects a command item from the text input menu.  To support this an input method merely needs to provide actions for each menu item that will be placed in the menu.
332        ///
333        /// i.e. -(void)menuAction:(id)sender
334        ///
335        /// Note that the sender in this instance will be the infoDictionary.  The dictionary contains two values:
336        ///
337        /// kIMKCommandMenuItemName            NSMenuItem  -- the NSMenuItem that was selected
338        /// kIMKCommandClientName            id
339        /// <IMKTextInput
340        /// , NSObject> - the current client
341        #[unsafe(method(doCommandBySelector:commandDictionary:))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn doCommandBySelector_commandDictionary(
344            &self,
345            a_selector: Option<Sel>,
346            info_dictionary: Option<&NSDictionary>,
347        );
348
349        /// Called to inform an input method that any visible UI should be closed.
350        #[unsafe(method(hidePalettes))]
351        #[unsafe(method_family = none)]
352        pub unsafe fn hidePalettes(&self);
353
354        #[cfg(feature = "objc2-app-kit")]
355        /// Returns a menu of input method specific commands.
356        ///
357        /// This method is called whenever the menu needs to be drawn so that input methods can update the menu to reflect their current state. The returned NSMenu is an autoreleased object.
358        #[unsafe(method(menu))]
359        #[unsafe(method_family = none)]
360        pub unsafe fn menu(&self, mtm: MainThreadMarker) -> Option<Retained<NSMenu>>;
361
362        /// Returns the input controller's delegate object. The returned id is an autoreleased object.
363        #[unsafe(method(delegate))]
364        #[unsafe(method_family = none)]
365        pub unsafe fn delegate(&self) -> Option<Retained<AnyObject>>;
366
367        /// Set the input controller's delegate object.
368        #[unsafe(method(setDelegate:))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn setDelegate(&self, new_delegate: Option<&AnyObject>);
371
372        #[cfg(feature = "IMKServer")]
373        /// Return the server object which is managing this input controller. The returned IMKServer is an autoreleased object.
374        #[unsafe(method(server))]
375        #[unsafe(method_family = none)]
376        pub unsafe fn server(&self) -> Option<Retained<IMKServer>>;
377
378        /// Called to notify an input controller that it is about to be closed.
379        #[unsafe(method(inputControllerWillClose))]
380        #[unsafe(method_family = none)]
381        pub unsafe fn inputControllerWillClose(&self);
382
383        /// Called when a user has selected a annotation in a candidate window.
384        ///
385        /// When a candidate window is displayed and the user selects an annotation the selected annotation is sent to the input controller via this method.  The currently selected candidateString is also sent to the input method.
386        #[unsafe(method(annotationSelected:forCandidate:))]
387        #[unsafe(method_family = none)]
388        pub unsafe fn annotationSelected_forCandidate(
389            &self,
390            annotation_string: Option<&NSAttributedString>,
391            candidate_string: Option<&NSAttributedString>,
392        );
393
394        /// Informs an input controller that the current candidate selection in the candidate window has changed.
395        ///
396        /// The candidate parameter is the candidate string that the selection changed to.  Note this method is called to indicate that the user is moving around in the candidate window.  The candidate object is not a final selection.
397        #[unsafe(method(candidateSelectionChanged:))]
398        #[unsafe(method_family = none)]
399        pub unsafe fn candidateSelectionChanged(
400            &self,
401            candidate_string: Option<&NSAttributedString>,
402        );
403
404        /// Called when a new candidate has been finally selected.
405        ///
406        /// The candidate parameter is the users final choice from the candidate window. The candidate window will have been closed before this method is called.
407        #[unsafe(method(candidateSelected:))]
408        #[unsafe(method_family = none)]
409        pub unsafe fn candidateSelected(&self, candidate_string: Option<&NSAttributedString>);
410    );
411}
412
413/// Methods declared on superclass `NSObject`.
414impl IMKInputController {
415    extern_methods!(
416        #[unsafe(method(init))]
417        #[unsafe(method_family = init)]
418        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
419
420        #[unsafe(method(new))]
421        #[unsafe(method_family = new)]
422        pub unsafe fn new() -> Retained<Self>;
423    );
424}