?? main.m
字號:
rectCount:&rectCount]; [[NSColor blackColor] set]; for (unsigned i = 0; i < rectCount; i++) { NSRect rect = rectArray[i]; rect.origin.x += obj->textFieldRect.origin.x; rect.origin.y += obj->textFieldRect.origin.y; [NSBezierPath strokeRect:rect]; } } [NSGraphicsContext setCurrentContext:oldContext];}static void invalidatePlugin(PluginObject *obj){ NPRect rect; rect.left = 0; rect.top = 0; rect.right = obj->window.width; rect.bottom = obj->window.height; browser->invalidaterect(obj->npp, &rect); }static void handleFocusChanged(NPCocoaEvent *cocoaEvent, PluginObject *obj){ obj->pluginHasFocus = cocoaEvent->event.focus.hasFocus; invalidatePlugin(obj);}static void handleMouseMoved(NPCocoaEvent *cocoaEvent, PluginObject *obj){ NSPoint point = NSMakePoint(cocoaEvent->event.mouse.pluginX, cocoaEvent->event.mouse.pluginY); if (NSPointInRect(point, obj->textFieldRect)) [[NSCursor IBeamCursor] set]; else [[NSCursor arrowCursor] set];}static void handleMouseDown(NPCocoaEvent *cocoaEvent, PluginObject *obj) { NSPoint point = NSMakePoint(cocoaEvent->event.mouse.pluginX, cocoaEvent->event.mouse.pluginY); obj->textFieldHasFocus = NSPointInRect(point, obj->textFieldRect); invalidatePlugin(obj);}int16 NPP_HandleEvent(NPP instance, void* event){ PluginObject *obj = instance->pdata; NPCocoaEvent *cocoaEvent = event; switch (cocoaEvent->type) { case NPCocoaEventDrawRect: handleDraw(obj); return 1; case NPCocoaEventFocusChanged: handleFocusChanged(cocoaEvent, obj); return 1; case NPCocoaEventMouseMoved: handleMouseMoved(cocoaEvent, obj); return 1; case NPCocoaEventMouseDown: handleMouseDown(cocoaEvent, obj); return 1; case NPCocoaEventKeyDown: // If the text field has focus we ignore the event, causing it // to be sent to the input manager. if (obj->textFieldHasFocus) return 0; else return 1; } return 0;}void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData){}static NSRange selectionRange(PluginObject *obj){ if (obj->markedRange.location != NSNotFound) return obj->markedRange; else return obj->selectedRange;}/* Text Input */void NPP_InsertText(NPP npp, id aString){ PluginObject *obj = npp->pdata; NSRange range = selectionRange(obj); // Get rid of the marked text if (NPP_HasMarkedText(npp)) { [obj->textStorage deleteCharactersInRange:obj->markedRange]; range.length = 0; } [obj->textStorage replaceCharactersInRange:range withString:aString]; obj->selectedRange.location = range.location + [aString length]; obj->selectedRange.length = 0; obj->markedRange = NSMakeRange(NSNotFound, 0); invalidatePlugin(obj);}void NPP_DoCommandBySelector(NPP npp, SEL aSelector){ PluginObject *obj = npp->pdata; if (aSelector == @selector(moveRight:)) { if (obj->selectedRange.location == [obj->textStorage length]) return; obj->selectedRange.location++; invalidatePlugin(obj); } else if (aSelector == @selector(moveLeft:)) { if (obj->selectedRange.location == 0) return; obj->selectedRange.location--; invalidatePlugin(obj); }}static NSDictionary *markedTextAttributes(){ static NSDictionary *markedTextAttributes = nil; if (!markedTextAttributes) { NSTextView *tv = [[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; markedTextAttributes = [[tv markedTextAttributes] retain]; [tv release]; } return markedTextAttributes;}void NPP_SetMarkedText(NPP npp, id aString, NSRange selRange){ PluginObject *obj = npp->pdata; BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]]; NSRange range = selectionRange(obj); if (!isAttributedString) aString = [[[NSAttributedString alloc] initWithString:aString attributes:markedTextAttributes()] autorelease]; [obj->textStorage replaceCharactersInRange:range withAttributedString:aString]; obj->selectedRange.location = range.location + selRange.location; obj->selectedRange.length = selRange.length; obj->markedRange = NSMakeRange(range.location, [aString length]); invalidatePlugin(obj);}void NPP_UnmarkText(NPP npp){}BOOL NPP_HasMarkedText(NPP npp){ PluginObject *obj = npp->pdata; return obj->markedRange.location != NSNotFound;}NSAttributedString *NPP_AttributedSubstringFromRange(NPP npp, NSRange theRange){ return nil;}NSRange NPP_MarkedRange(NPP npp){ PluginObject *obj = npp->pdata; return obj->markedRange;}NSRange NPP_SelectedRange(NPP npp){ PluginObject *obj = npp->pdata; return obj->selectedRange;}NSRect NPP_FirstRectForCharacterRange(NPP npp, NSRange theRange){ PluginObject *obj = npp->pdata; NSUInteger rectCount; NSRect *rectArray = [obj->layoutManager rectArrayForCharacterRange:theRange withinSelectedCharacterRange:theRange inTextContainer:obj->textContainer rectCount:&rectCount]; return rectArray[0];}static NPPluginTextInputFuncs* pluginTextInputFuncs(){ static NPPluginTextInputFuncs textInputFuncs; static bool initialized = false; if (!initialized) { textInputFuncs.version = 0; textInputFuncs.size = sizeof(textInputFuncs); textInputFuncs.insertText = NPP_InsertText; textInputFuncs.doCommandBySelector = NPP_DoCommandBySelector; textInputFuncs.setMarkedText = NPP_SetMarkedText; textInputFuncs.unmarkText = NPP_UnmarkText; textInputFuncs.hasMarkedText = NPP_HasMarkedText; textInputFuncs.attributedSubstringFromRange = NPP_AttributedSubstringFromRange; textInputFuncs.markedRange = NPP_MarkedRange; textInputFuncs.selectedRange = NPP_SelectedRange; textInputFuncs.firstRectForCharacterRange = NPP_FirstRectForCharacterRange; initialized = true; } return &textInputFuncs;}NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value){ switch (variable) { case NPPVpluginTextInputFuncs: *(NPPluginTextInputFuncs**)value = pluginTextInputFuncs(); return NPERR_NO_ERROR; } return NPERR_GENERIC_ERROR;}NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value){ return NPERR_GENERIC_ERROR;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -