1 2 /** 3 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 4 * This file is dual licensed under LGPL v2.1 and the Scintilla license (http://www.scintilla.org/License.txt). 5 */ 6 7 #ifndef PLATCOCOA_H 8 #define PLATCOCOA_H 9 10 #include <assert.h> 11 12 #include <sys/time.h> 13 14 #include <cstdlib> 15 #include <cstring> 16 #include <cstdio> 17 18 #include <Cocoa/Cocoa.h> 19 #include "QuartzTextLayout.h" 20 21 #include "Platform.h" 22 #include "Scintilla.h" 23 24 NSRect PRectangleToNSRect(Scintilla::PRectangle& rc); 25 Scintilla::PRectangle NSRectToPRectangle(NSRect& rc); 26 CFStringEncoding EncodingFromCharacterSet(bool unicode, int characterSet); 27 28 @interface ScintillaContextMenu : NSMenu 29 { 30 Scintilla::ScintillaCocoa* owner; 31 } 32 - (void) handleCommand: (NSMenuItem*) sender; 33 - (void) setOwner: (Scintilla::ScintillaCocoa*) newOwner; 34 35 @end 36 37 namespace Scintilla { 38 39 // A class to do the actual text rendering for us using Quartz 2D. 40 class SurfaceImpl : public Surface 41 { 42 private: 43 bool unicodeMode; 44 float x; 45 float y; 46 47 CGContextRef gc; 48 49 /** The text layout instance */ 50 QuartzTextLayout* textLayout; 51 int codePage; 52 int verticalDeviceResolution; 53 54 /** If the surface is a bitmap context, contains a reference to the bitmap data. */ 55 uint8_t* bitmapData; 56 /** If the surface is a bitmap context, stores the dimensions of the bitmap. */ 57 int bitmapWidth; 58 int bitmapHeight; 59 60 /** Set the CGContext's fill colour to the specified desired colour. */ 61 void FillColour( const ColourDesired& back ); 62 63 64 // 24-bit RGB+A bitmap data constants 65 static const int BITS_PER_COMPONENT = 8; 66 static const int BITS_PER_PIXEL = BITS_PER_COMPONENT * 4; 67 static const int BYTES_PER_PIXEL = BITS_PER_PIXEL / 8; 68 public: 69 SurfaceImpl(); 70 ~SurfaceImpl(); 71 72 void Init(WindowID wid); 73 void Init(SurfaceID sid, WindowID wid); 74 void InitPixMap(int width, int height, Surface *surface_, WindowID wid); GetContext()75 CGContextRef GetContext() { return gc; } 76 77 void Release(); 78 bool Initialised(); 79 void PenColour(ColourDesired fore); 80 81 /** Returns a CGImageRef that represents the surface. Returns NULL if this is not possible. */ 82 CGImageRef GetImage(); 83 void CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect, PRectangle dstRect); 84 85 int LogPixelsY(); 86 int DeviceHeightFont(int points); 87 void MoveTo(int x_, int y_); 88 void LineTo(int x_, int y_); 89 void Polygon(Scintilla::Point *pts, int npts, ColourDesired fore, ColourDesired back); 90 void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back); 91 void FillRectangle(PRectangle rc, ColourDesired back); 92 void FillRectangle(PRectangle rc, Surface &surfacePattern); 93 void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back); 94 void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, 95 ColourDesired outline, int alphaOutline, int flags); 96 void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage); 97 void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back); 98 void Copy(PRectangle rc, Scintilla::Point from, Surface &surfaceSource); 99 void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, 100 ColourDesired back); 101 void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, 102 ColourDesired back); 103 void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore); 104 void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions); 105 XYPOSITION WidthText(Font &font_, const char *s, int len); 106 XYPOSITION WidthChar(Font &font_, char ch); 107 XYPOSITION Ascent(Font &font_); 108 XYPOSITION Descent(Font &font_); 109 XYPOSITION InternalLeading(Font &font_); 110 XYPOSITION ExternalLeading(Font &font_); 111 XYPOSITION Height(Font &font_); 112 XYPOSITION AverageCharWidth(Font &font_); 113 114 void SetClip(PRectangle rc); 115 void FlushCachedState(); 116 117 void SetUnicodeMode(bool unicodeMode_); 118 void SetDBCSMode(int codePage_); 119 }; // SurfaceImpl class 120 121 } // Scintilla namespace 122 123 #endif 124