OpenTTD Source 20260208-master-g43af8e94d0
OTTD_CocoaView Class Reference

Subclass of NSView to support mouse awareness and text input. More...

#include <cocoa_wnd.h>

Inheritance diagram for OTTD_CocoaView:

Instance Methods

(NSRect) - getRealRect:
(NSRect) - getVirtualRect:
(CGFloat) - getContentsScale
(NSPoint) - mousePositionFromEvent:
 Return the mouse location.
(instancetype) - initWithFrame: [implementation]
(BOOL) - acceptsFirstResponder [implementation]
 Allow to handle events.
(void) - setNeedsDisplayInRect: [implementation]
(void) - cursorUpdate: [implementation]
 Update mouse cursor to use for this view.
(void) - viewWillMoveToWindow: [implementation]
(void) - viewDidMoveToWindow [implementation]
(void) - mouseEntered: [implementation]
 Make OpenTTD aware that it has control over the mouse.
(void) - mouseExited: [implementation]
 Make OpenTTD aware that it has NO control over the mouse.
(void) - internalMouseMoveEvent: [implementation]
 Internal handler of mouse movement.
(void) - internalMouseButtonEvent [implementation]
 Internal handler of mouse buttons.
(BOOL) - emulateRightButton: [implementation]
 Check if right mouse button should be emulated when left button is pressed.
(void) - mouseMoved: [implementation]
 Handler of mouse movement.
(void) - mouseDragged: [implementation]
 Handler of mouse movement while left button is down.
(void) - mouseDown: [implementation]
 Handler of left mouse button pressing.
(void) - mouseUp: [implementation]
 Handler of left mouse button releasing.
(void) - rightMouseDragged: [implementation]
 Handler of mouse movement when right button is down.
(void) - rightMouseDown: [implementation]
 Handler of right mouse button pressing.
(void) - rightMouseUp: [implementation]
 Handler of right mouse button releasing.
(void) - scrollWheel: [implementation]
 Handler of mouse wheel scrolling.
(void) - magnifyWithEvent: [implementation]
 Handler of magnification events.
(void) - endGestureWithEvent: [implementation]
 Handler of gesture to end magnification.
(BOOL) - internalHandleKeycode:unicode:pressed:modifiers: [implementation]
 Internal handler of keyboard keys.
(void) - keyDown: [implementation]
 Handler of keyboard key pressing.
(void) - keyUp: [implementation]
 Handler of keyboard key releasing.
(void) - flagsChanged: [implementation]
 Handler of modifiers.
(void) - insertText:replacementRange: [implementation]
 Insert the given text at the given range.
(void) - insertText: [implementation]
 Insert the given text at the caret.
(void) - setMarkedText:selectedRange:replacementRange: [implementation]
 Set a new marked text and reposition the caret.
(void) - setMarkedText:selectedRange: [implementation]
 Set a new marked text and reposition the caret.
(void) - unmarkText [implementation]
 Unmark the current marked text.
(NSRange) - selectedRange [implementation]
 Get the caret position.
(NSRange) - markedRange [implementation]
 Get the currently marked range.
(BOOL) - hasMarkedText [implementation]
 Is any text marked?
(NSAttributedString *) - attributedSubstringForProposedRange:actualRange: [implementation]
 Get a string corresponding to the given range.
(NSAttributedString *) - attributedSubstringFromRange: [implementation]
 Get a string corresponding to the given range.
(NSAttributedString *) - attributedString [implementation]
 Get the current edit box string.
(NSUInteger) - characterIndexForPoint: [implementation]
 Get the character that is rendered at the given point.
(NSRect) - firstRectForCharacterRange: [implementation]
 Get the bounding rect for the given range.
(NSRect) - firstRectForCharacterRange:actualRange: [implementation]
 Get the bounding rect for the given range.
(NSArray *) - validAttributesForMarkedText [implementation]
 Get all string attributes that we can process for marked text.
(void) - deleteBackward: [implementation]
 Delete single character left of the cursor.
(void) - deleteWordBackward: [implementation]
 Delete word left of the cursor.
(void) - deleteForward: [implementation]
 Delete single character right of the cursor.
(void) - deleteWordForward: [implementation]
 Delete word right of the cursor.
(void) - moveLeft: [implementation]
 Move cursor one character left.
(void) - moveWordLeft: [implementation]
 Move cursor one word left.
(void) - moveRight: [implementation]
 Move cursor one character right.
(void) - moveWordRight: [implementation]
 Move cursor one word right.
(void) - moveUp: [implementation]
 Move cursor one line up.
(void) - moveDown: [implementation]
 Move cursor one line down.
(void) - moveUpAndModifySelection: [implementation]
 MScroll one line up.
(void) - moveDownAndModifySelection: [implementation]
 Scroll one line down.
(void) - moveToBeginningOfLine: [implementation]
 Move cursor to the start of the line.
(void) - moveToEndOfLine: [implementation]
 Move cursor to the end of the line.
(void) - scrollPageUp: [implementation]
 Scroll one page up.
(void) - scrollPageDown: [implementation]
 Scroll one page down.
(void) - pageUpAndModifySelection: [implementation]
 Move cursor (and selection) one page up.
(void) - pageDownAndModifySelection: [implementation]
 Move cursor (and selection) one page down.
(void) - scrollToBeginningOfDocument: [implementation]
 Scroll to the beginning of the document.
(void) - scrollToEndOfDocument: [implementation]
 Scroll to the end of the document.
(void) - insertNewline: [implementation]
 Return was pressed.
(void) - cancelOperation: [implementation]
 Escape was pressed.
(void) - doCommandBySelector: [implementation]
 Invoke the selector if we implement it.

Detailed Description

Subclass of NSView to support mouse awareness and text input.

Definition at line 43 of file cocoa_wnd.h.

Method Documentation

◆ acceptsFirstResponder

- (BOOL) acceptsFirstResponder
implementation

Allow to handle events.

Definition at line 572 of file cocoa_wnd.mm.

References acceptsFirstResponder.

Referenced by acceptsFirstResponder.

◆ attributedString

- (NSAttributedString *) attributedString
implementation

Get the current edit box string.

Definition at line 1112 of file cocoa_wnd.mm.

References attributedString, and EditBoxInGlobalFocus().

Referenced by attributedString.

◆ attributedSubstringForProposedRange:actualRange:

- (NSAttributedString *) attributedSubstringForProposedRange: (NSRange) theRange
actualRange: (NSRangePointer) actualRange 
implementation

Get a string corresponding to the given range.

Definition at line 1091 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus().

Referenced by attributedSubstringFromRange:.

◆ attributedSubstringFromRange:

- (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
implementation

Get a string corresponding to the given range.

Definition at line 1106 of file cocoa_wnd.mm.

References attributedSubstringForProposedRange:actualRange:.

◆ cancelOperation:

- (void) cancelOperation: (id) sender
implementation

Escape was pressed.

Parameters
senderWhere the event comes from.

Definition at line 1360 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ characterIndexForPoint:

- (NSUInteger) characterIndexForPoint: (NSPoint) thePoint
implementation

Get the character that is rendered at the given point.

Definition at line 1121 of file cocoa_wnd.mm.

References CountUtf16Units(), EditBoxInGlobalFocus(), and Point.

◆ cursorUpdate:

- (void) cursorUpdate: (NSEvent *) event
implementation

Update mouse cursor to use for this view.

Definition at line 586 of file cocoa_wnd.mm.

◆ deleteBackward:

- (void) deleteBackward: (id) sender
implementation

Delete single character left of the cursor.

Parameters
senderWhere the event comes from.

Definition at line 1169 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ deleteForward:

- (void) deleteForward: (id) sender
implementation

Delete single character right of the cursor.

Parameters
senderWhere the event comes from.

Definition at line 1187 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ deleteWordBackward:

- (void) deleteWordBackward: (id) sender
implementation

Delete word left of the cursor.

Parameters
senderWhere the event comes from.

Definition at line 1178 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ deleteWordForward:

- (void) deleteWordForward: (id) sender
implementation

Delete word right of the cursor.

Parameters
senderWhere the event comes from.

Definition at line 1196 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ doCommandBySelector:

- (void) doCommandBySelector: (SEL) aSelector
implementation

Invoke the selector if we implement it.

Parameters
aSelectorThe selector to invoke.

Definition at line 1369 of file cocoa_wnd.mm.

◆ emulateRightButton:

- (BOOL) emulateRightButton: (NSEvent *) event
implementation

Check if right mouse button should be emulated when left button is pressed.

Parameters
eventInformation about occurred event.
Returns
True iff right button should be emulated instead of left one.

Definition at line 671 of file cocoa_wnd.mm.

References _settings_client.

◆ endGestureWithEvent:

- (void) endGestureWithEvent: (NSEvent *) event
implementation

Handler of gesture to end magnification.

Parameters
eventInformation about occurred event.

Definition at line 817 of file cocoa_wnd.mm.

◆ firstRectForCharacterRange:

- (NSRect) firstRectForCharacterRange: (NSRange) aRange
implementation

Get the bounding rect for the given range.

Definition at line 1137 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and Utf8AdvanceByUtf16Units().

Referenced by firstRectForCharacterRange:actualRange:.

◆ firstRectForCharacterRange:actualRange:

- (NSRect) firstRectForCharacterRange: (NSRange) aRange
actualRange: (NSRangePointer) actualRange 
implementation

Get the bounding rect for the given range.

Definition at line 1154 of file cocoa_wnd.mm.

References firstRectForCharacterRange:.

◆ flagsChanged:

- (void) flagsChanged: (NSEvent *) event
implementation

Handler of modifiers.

Parameters
eventInformation about occurred event.

Definition at line 965 of file cocoa_wnd.mm.

References _current_mods, and internalHandleKeycode:unicode:pressed:modifiers:.

◆ getContentsScale

- (CGFloat) getContentsScale

Definition at line 564 of file cocoa_wnd.mm.

◆ getRealRect:

- (NSRect) getRealRect: (NSRect) rect

Definition at line 554 of file cocoa_wnd.mm.

◆ getVirtualRect:

- (NSRect) getVirtualRect: (NSRect) rect

Definition at line 559 of file cocoa_wnd.mm.

◆ hasMarkedText

- (BOOL) hasMarkedText
implementation

Is any text marked?

Definition at line 1083 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and hasMarkedText.

Referenced by hasMarkedText.

◆ initWithFrame:

- (instancetype) initWithFrame: (NSRect) frameRect
implementation

Definition at line 546 of file cocoa_wnd.mm.

◆ insertNewline:

- (void) insertNewline: (id) sender
implementation

Return was pressed.

Parameters
senderWhere the event comes from.

Definition at line 1351 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ insertText:

- (void) insertText: (id) aString
implementation

Insert the given text at the caret.

Definition at line 1011 of file cocoa_wnd.mm.

References insertText:replacementRange:.

◆ insertText:replacementRange:

- (void) insertText: (id) aString
replacementRange: (NSRange) replacementRange 
implementation

Insert the given text at the given range.

Definition at line 991 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), HandleTextInput(), and Utf8AdvanceByUtf16Units().

Referenced by insertText:.

◆ internalHandleKeycode:unicode:pressed:modifiers:

- (BOOL) internalHandleKeycode: (unsigned short) keycode
unicode: (char32_t) unicode
pressed: (BOOL) down
modifiers: (NSUInteger) modifiers 
implementation

Internal handler of keyboard keys.

Parameters
keycodeThe raw keycode of the key press.
unicodeThe unicode character of the key press.
downWhether pressing or releasing the key.
modifiersFlags to denote other (special) keys that might have been pressed.
Returns
Whether event should be interpreted.

Definition at line 832 of file cocoa_wnd.mm.

References _dirkeys, _settings_client, _tab_is_down, Debug, EditBoxInGlobalFocus(), VideoDriver::GetInstance(), HandleKeypress(), IsInsideMM(), SB(), and VideoDriver::ToggleFullscreen().

Referenced by flagsChanged:, keyDown:, and keyUp:.

◆ internalMouseButtonEvent

- (void) internalMouseButtonEvent
implementation

Internal handler of mouse buttons.

Definition at line 657 of file cocoa_wnd.mm.

References HandleMouseEvents(), and internalMouseButtonEvent.

Referenced by internalMouseButtonEvent, mouseDown:, mouseUp:, rightMouseDown:, and rightMouseUp:.

◆ internalMouseMoveEvent:

- (void) internalMouseMoveEvent: (NSEvent *) event
implementation

Internal handler of mouse movement.

Parameters
eventInformation about occurred event.

Definition at line 642 of file cocoa_wnd.mm.

References HandleMouseEvents(), and mousePositionFromEvent:.

Referenced by mouseDragged:, mouseMoved:, and rightMouseDragged:.

◆ keyDown:

- (void) keyDown: (NSEvent *) event
implementation

Handler of keyboard key pressing.

Parameters
eventInformation about occurred event.

Definition at line 908 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), internalHandleKeycode:unicode:pressed:modifiers:, and NSStringToUTF32().

◆ keyUp:

- (void) keyUp: (NSEvent *) event
implementation

Handler of keyboard key releasing.

Parameters
eventInformation about occurred event.

Definition at line 941 of file cocoa_wnd.mm.

References internalHandleKeycode:unicode:pressed:modifiers:, and NSStringToUTF32().

◆ magnifyWithEvent:

- (void) magnifyWithEvent: (NSEvent *) event
implementation

Handler of magnification events.

Parameters
eventInformation about occurred event.

Definition at line 796 of file cocoa_wnd.mm.

References HandleMouseEvents().

◆ markedRange

- (NSRange) markedRange
implementation

◆ mouseDown:

- (void) mouseDown: (NSEvent *) event
implementation

Handler of left mouse button pressing.

Parameters
eventInformation about occurred event.

Definition at line 702 of file cocoa_wnd.mm.

References _left_button_down, internalMouseButtonEvent, and rightMouseDown:.

◆ mouseDragged:

- (void) mouseDragged: (NSEvent *) event
implementation

Handler of mouse movement while left button is down.

Parameters
eventInformation about occurred event.

Definition at line 693 of file cocoa_wnd.mm.

References internalMouseMoveEvent:.

◆ mouseEntered:

- (void) mouseEntered: (NSEvent *) theEvent
implementation

Make OpenTTD aware that it has control over the mouse.

Parameters
theEventInformation about occurred event.

Definition at line 610 of file cocoa_wnd.mm.

◆ mouseExited:

- (void) mouseExited: (NSEvent *) theEvent
implementation

Make OpenTTD aware that it has NO control over the mouse.

Parameters
theEventInformation about occurred event.

Definition at line 618 of file cocoa_wnd.mm.

◆ mouseMoved:

- (void) mouseMoved: (NSEvent *) event
implementation

Handler of mouse movement.

Parameters
eventInformation about occurred event.

Definition at line 684 of file cocoa_wnd.mm.

References internalMouseMoveEvent:.

◆ mousePositionFromEvent:

- (NSPoint) mousePositionFromEvent: (NSEvent *) e

Return the mouse location.

Parameters
eInformation about occurred event.
Returns
Mouse location as NSPoint.

Definition at line 629 of file cocoa_wnd.mm.

Referenced by internalMouseMoveEvent:.

◆ mouseUp:

- (void) mouseUp: (NSEvent *) event
implementation

Handler of left mouse button releasing.

Parameters
eventInformation about occurred event.

Definition at line 717 of file cocoa_wnd.mm.

References _left_button_clicked, _left_button_down, internalMouseButtonEvent, and rightMouseUp:.

◆ moveDown:

- (void) moveDown: (id) sender
implementation

Move cursor one line down.

Parameters
senderWhere the event comes from.

Definition at line 1250 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ moveDownAndModifySelection:

- (void) moveDownAndModifySelection: (id) sender
implementation

Scroll one line down.

Parameters
senderWhere the event comes from.

Definition at line 1268 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ moveLeft:

- (void) moveLeft: (id) sender
implementation

Move cursor one character left.

Parameters
senderWhere the event comes from.

Definition at line 1205 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ moveRight:

- (void) moveRight: (id) sender
implementation

Move cursor one character right.

Parameters
senderWhere the event comes from.

Definition at line 1223 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ moveToBeginningOfLine:

- (void) moveToBeginningOfLine: (id) sender
implementation

Move cursor to the start of the line.

Parameters
senderWhere the event comes from.

Definition at line 1277 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

Referenced by scrollToBeginningOfDocument:.

◆ moveToEndOfLine:

- (void) moveToEndOfLine: (id) sender
implementation

Move cursor to the end of the line.

Parameters
senderWhere the event comes from.

Definition at line 1286 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

Referenced by scrollToEndOfDocument:.

◆ moveUp:

- (void) moveUp: (id) sender
implementation

Move cursor one line up.

Parameters
senderWhere the event comes from.

Definition at line 1241 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ moveUpAndModifySelection:

- (void) moveUpAndModifySelection: (id) sender
implementation

MScroll one line up.

Parameters
senderWhere the event comes from.

Definition at line 1259 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ moveWordLeft:

- (void) moveWordLeft: (id) sender
implementation

Move cursor one word left.

Parameters
senderWhere the event comes from.

Definition at line 1214 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ moveWordRight:

- (void) moveWordRight: (id) sender
implementation

Move cursor one word right.

Parameters
senderWhere the event comes from.

Definition at line 1232 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ pageDownAndModifySelection:

- (void) pageDownAndModifySelection: (id) sender
implementation

Move cursor (and selection) one page down.

Parameters
senderWhere the event comes from.

Definition at line 1322 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ pageUpAndModifySelection:

- (void) pageUpAndModifySelection: (id) sender
implementation

Move cursor (and selection) one page up.

Parameters
senderWhere the event comes from.

Definition at line 1313 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ rightMouseDown:

- (void) rightMouseDown: (NSEvent *) event
implementation

Handler of right mouse button pressing.

Parameters
eventInformation about occurred event.

Definition at line 742 of file cocoa_wnd.mm.

References _right_button_clicked, _right_button_down, and internalMouseButtonEvent.

Referenced by mouseDown:.

◆ rightMouseDragged:

- (void) rightMouseDragged: (NSEvent *) event
implementation

Handler of mouse movement when right button is down.

Parameters
eventInformation about occurred event.

Definition at line 733 of file cocoa_wnd.mm.

References internalMouseMoveEvent:.

◆ rightMouseUp:

- (void) rightMouseUp: (NSEvent *) event
implementation

Handler of right mouse button releasing.

Parameters
eventInformation about occurred event.

Definition at line 753 of file cocoa_wnd.mm.

References _right_button_down, and internalMouseButtonEvent.

Referenced by mouseUp:.

◆ scrollPageDown:

- (void) scrollPageDown: (id) sender
implementation

Scroll one page down.

Parameters
senderWhere the event comes from.

Definition at line 1304 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ scrollPageUp:

- (void) scrollPageUp: (id) sender
implementation

Scroll one page up.

Parameters
senderWhere the event comes from.

Definition at line 1295 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), and HandleKeypress().

◆ scrollToBeginningOfDocument:

- (void) scrollToBeginningOfDocument: (id) sender
implementation

Scroll to the beginning of the document.

Parameters
senderWhere the event comes from.

Definition at line 1331 of file cocoa_wnd.mm.

References moveToBeginningOfLine:.

◆ scrollToEndOfDocument:

- (void) scrollToEndOfDocument: (id) sender
implementation

Scroll to the end of the document.

Parameters
senderWhere the event comes from.

Definition at line 1341 of file cocoa_wnd.mm.

References moveToEndOfLine:.

◆ scrollWheel:

- (void) scrollWheel: (NSEvent *) event
implementation

Handler of mouse wheel scrolling.

Parameters
eventInformation about occurred event.

Definition at line 763 of file cocoa_wnd.mm.

References _settings_client.

◆ selectedRange

- (NSRange) selectedRange
implementation

Get the caret position.

Definition at line 1055 of file cocoa_wnd.mm.

References Textbuf::caretpos, CountUtf16Units(), EditBoxInGlobalFocus(), Textbuf::GetText(), and selectedRange.

Referenced by selectedRange.

◆ setMarkedText:selectedRange:

- (void) setMarkedText: (id) aString
selectedRange: (NSRange) selRange 
implementation

Set a new marked text and reposition the caret.

Definition at line 1043 of file cocoa_wnd.mm.

References setMarkedText:selectedRange:replacementRange:.

◆ setMarkedText:selectedRange:replacementRange:

- (void) setMarkedText: (id) aString
selectedRange: (NSRange) selRange
replacementRange: (NSRange) replacementRange 
implementation

Set a new marked text and reposition the caret.

Definition at line 1017 of file cocoa_wnd.mm.

References EditBoxInGlobalFocus(), HandleTextInput(), markedRange, and Utf8AdvanceByUtf16Units().

Referenced by setMarkedText:selectedRange:.

◆ setNeedsDisplayInRect:

- (void) setNeedsDisplayInRect: (NSRect) invalidRect
implementation

Definition at line 577 of file cocoa_wnd.mm.

◆ unmarkText

- (void) unmarkText
implementation

Unmark the current marked text.

Definition at line 1049 of file cocoa_wnd.mm.

References HandleTextInput(), and unmarkText.

Referenced by unmarkText.

◆ validAttributesForMarkedText

- (NSArray *) validAttributesForMarkedText
implementation

Get all string attributes that we can process for marked text.

Definition at line 1160 of file cocoa_wnd.mm.

References validAttributesForMarkedText.

Referenced by validAttributesForMarkedText.

◆ viewDidMoveToWindow

- (void) viewDidMoveToWindow
implementation

Definition at line 598 of file cocoa_wnd.mm.

◆ viewWillMoveToWindow:

- (void) viewWillMoveToWindow: (NSWindow *) win
implementation

Definition at line 591 of file cocoa_wnd.mm.


The documentation for this class was generated from the following files: