// ask the MLTE object how many pixels equal view rect width UInt32 TextViewGetWidth( WindowRef window, OSType key ) { Rect viewRect = { 0,0,0,0 }; TXNGetViewRect( WindowGetTXNObj( window, key ), &viewRect ); return viewRect.right-viewRect.left; }
// ask the MLTE object how many pixels equal view rect height UInt32 TextViewGetHeight( WindowRef window, OSType key ) { Rect viewRect = { 0,0,0,0 }; TXNGetViewRect( WindowGetTXNObj( window, key ), &viewRect ); return viewRect.bottom-viewRect.top; }
OSStatus TextViewInvalidate( WindowRef window, OSType key ) { OSStatus status = eventNotHandledErr; Rect viewRect; require_action( window != NULL, BadWindow, status = eventNotHandledErr ); TXNGetViewRect( WindowGetTXNObj( window, key ), &viewRect ); status = InvalWindowRect( window, &viewRect ); BadWindow: return status; }
// static pascal OSStatus IGraphicsCarbon::TextEntryHandler(EventHandlerCallRef pHandlerCall, EventRef pEvent, void* pGraphicsCarbon) { IGraphicsCarbon* _this = (IGraphicsCarbon*) pGraphicsCarbon; UInt32 eventClass = GetEventClass(pEvent); UInt32 eventKind = GetEventKind(pEvent); switch (eventClass) { case kEventClassKeyboard: switch (eventKind) { case kEventRawKeyDown: case kEventRawKeyRepeat: { // Get the keys and modifiers char c; UInt32 k; UInt32 modifiers; GetEventParameter(pEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &c); GetEventParameter(pEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &k); GetEventParameter(pEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); // paste if (c == 118 && modifiers == 256) { if (TXNIsScrapPastable()) { TXNPaste(_this->mTextEntryView); return eventNotHandledErr; } } // trap enter keys if (c == 3 || c == 13) { _this->EndUserInput(true); return noErr; } // trap escape key if (c == 27) { _this->EndUserInput(false); return noErr; } // pass arrow keys if (k == 125 || k == 126 || k == 123 || k == 124) return eventNotHandledErr; // pass delete keys if (c == 8 || c == 127) return eventNotHandledErr; if (_this->mEdParam) { switch ( _this->mEdParam->Type() ) { case IParam::kTypeEnum: case IParam::kTypeInt: case IParam::kTypeBool: if (c >= '0' && c <= '9') break; else if (c == '-') break; else if (c == '+') break; else return noErr; case IParam::kTypeDouble: if (c >= '0' && c <= '9') break; else if (c == '.') break; else if (c == '-') break; else if (c == '+') break; else return noErr; default: break; } } // Get the text CharsHandle textHandle; long textLength = 0; TXNGetDataEncoded(_this->mTextEntryView, kTXNStartOffset, kTXNEndOffset, &textHandle, kTXNTextData); // Check that we have some worthwhile data if (textHandle != NULL && GetHandleSize(textHandle) > 0) { textLength = GetHandleSize(textHandle); } if(textLength >= _this->mEdControl->GetTextEntryLength()) { return noErr; } else { EventRecord eventRecord; if (ConvertEventRefToEventRecord(pEvent, &eventRecord)) { TXNKeyDown(_this->mTextEntryView, &eventRecord); return noErr; } } } break; } break; case kEventClassMouse: { switch (eventKind) { case kEventMouseDown: case kEventMouseUp: { // Get the window handle WindowRef window; GetEventParameter(pEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); // Determine the point HIPoint p; GetEventParameter(pEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &p); Point point = { (short)p.y, (short)p.x }; QDGlobalToLocalPoint(GetWindowPort (window), &point); // Get the viewable area Rect rect; TXNGetViewRect (_this->mTextEntryView, &rect); //swell collision #undef PtInRect #define MacPtInRect PtInRect // Handle the click as necessary if (PtInRect(point, &rect)) { #define PtInRect(r,p) SWELL_PtInRect(r,p) EventRecord eventRecord; if (eventKind == kEventMouseDown && ConvertEventRefToEventRecord(pEvent, &eventRecord)) { TXNClick(_this->mTextEntryView, &eventRecord); } return noErr; } else { CallNextEventHandler(pHandlerCall, pEvent); ClearKeyboardFocus(window); _this->EndUserInput(false); return noErr; } } break; case kEventMouseMoved: TXNAdjustCursor(_this->mTextEntryView, NULL); return noErr; case kEventMouseWheelMoved: return noErr; } break; } case kEventClassWindow: { WindowRef window; GetEventParameter (pEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); switch (eventKind) { case kEventWindowFocusRelinquish: case kEventWindowClosed: case kEventWindowDeactivated: CallNextEventHandler(pHandlerCall, pEvent); ClearKeyboardFocus(window); _this->EndUserInput(false); return noErr; } break; } } return eventNotHandledErr; }