diff options
Diffstat (limited to 'cocoa')
-rw-r--r-- | cocoa/InfoBar.mm | 8 | ||||
-rw-r--r-- | cocoa/PlatCocoa.mm | 60 | ||||
-rw-r--r-- | cocoa/QuartzTextLayout.h | 2 | ||||
-rw-r--r-- | cocoa/QuartzTextStyle.h | 6 | ||||
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 30 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 36 |
6 files changed, 72 insertions, 70 deletions
diff --git a/cocoa/InfoBar.mm b/cocoa/InfoBar.mm index 3ea0fce5d..01e2ce49c 100644 --- a/cocoa/InfoBar.mm +++ b/cocoa/InfoBar.mm @@ -32,7 +32,7 @@ NSSize textSize = [self cellSizeForBounds: theRect]; // Center that in the proposed rect - float heightDelta = newRect.size.height - textSize.height; + CGFloat heightDelta = newRect.size.height - textSize.height; if (heightDelta > 0) { newRect.size.height -= heightDelta; @@ -143,7 +143,7 @@ static NSString *DefaultScaleMenuLabels[] = { @"20%", @"30%", @"50%", @"75%", @"100%", @"130%", @"160%", @"200%", @"250%", @"300%" }; static float DefaultScaleMenuFactors[] = { - 0.2, 0.3, 0.5, 0.75, 1.0, 1.3, 1.6, 2.0, 2.5, 3.0 + 0.2f, 0.3f, 0.5f, 0.75f, 1.0f, 1.3f, 1.6f, 2.0f, 2.5f, 3.0f }; static unsigned DefaultScaleMenuSelectedItemIndex = 4; static float BarFontSize = 10.0; @@ -251,7 +251,7 @@ static float BarFontSize = 10.0; // Draw separator lines between items. NSRect verticalLineRect; - float component = 190.0 / 255.0; + CGFloat component = 190.0 / 255.0; NSColor* lineColor = [NSColor colorWithDeviceRed: component green: component blue: component alpha: 1]; if (mDisplayMask & IBShowZoom) @@ -301,7 +301,7 @@ static float BarFontSize = 10.0; - (void) positionSubViews { - NSRect currentBounds = {0, 0, 0, [self frame].size.height}; + NSRect currentBounds = {{0, 0}, {0, [self frame].size.height}}; if (mDisplayMask & IBShowZoom) { [mZoomPopup setHidden: NO]; diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 77dfc83e2..711b91e42 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -54,7 +54,7 @@ NSRect PRectangleToNSRect(PRectangle& rc) */ PRectangle NSRectToPRectangle(NSRect& rc) { - return PRectangle(rc.origin.x, rc.origin.y, + return PRectangle(static_cast<XYPOSITION>(rc.origin.x), static_cast<XYPOSITION>(rc.origin.y), static_cast<XYPOSITION>(NSMaxX(rc)), static_cast<XYPOSITION>(NSMaxY(rc))); } @@ -541,8 +541,7 @@ void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesi // Create a rectangle with semicircles at the corners const int MAX_RADIUS = 4; - int radius = Platform::Minimum( MAX_RADIUS, rc.Height()/2 ); - radius = Platform::Minimum( radius, rc.Width()/2 ); + const int radius = std::min(MAX_RADIUS, static_cast<int>(std::min(rc.Height()/2, rc.Width()/2))); // Points go clockwise, starting from just below the top left // Corners are kept together, so we can easily create arcs to connect them @@ -784,10 +783,10 @@ void SurfaceImpl::CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect, CGRect drawRect = CGRectMake (0, 0, w, h); if (!CGRectEqualToRect (src, dst)) { - float sx = CGRectGetWidth(dst) / CGRectGetWidth(src); - float sy = CGRectGetHeight(dst) / CGRectGetHeight(src); - float dx = CGRectGetMinX(dst) - (CGRectGetMinX(src) * sx); - float dy = CGRectGetMinY(dst) - (CGRectGetMinY(src) * sy); + CGFloat sx = CGRectGetWidth(dst) / CGRectGetWidth(src); + CGFloat sy = CGRectGetHeight(dst) / CGRectGetHeight(src); + CGFloat dx = CGRectGetMinX(dst) - (CGRectGetMinX(src) * sx); + CGFloat dy = CGRectGetMinY(dst) - (CGRectGetMinY(src) * sy); drawRect = CGRectMake (dx, dy, w*sx, h*sy); } CGContextSaveGState (gc); @@ -959,11 +958,11 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION size_t codeUnits = (lenChar < 4) ? 1 : 2; CGFloat xPosition = CTLineGetOffsetForStringIndex(mLine, ui+codeUnits, NULL); for (unsigned int bytePos=0; (bytePos<lenChar) && (i<len); bytePos++) { - positions[i++] = xPosition; + positions[i++] = static_cast<XYPOSITION>(xPosition); } ui += codeUnits; } - int lastPos = 0; + XYPOSITION lastPos = 0.0f; if (i > 0) lastPos = positions[i-1]; while (i<len) { @@ -975,14 +974,14 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION size_t lenChar = Platform::IsDBCSLeadByte(codePage, s[i]) ? 2 : 1; CGFloat xPosition = CTLineGetOffsetForStringIndex(mLine, ui+1, NULL); for (unsigned int bytePos=0; (bytePos<lenChar) && (i<len); bytePos++) { - positions[i++] = xPosition; + positions[i++] = static_cast<XYPOSITION>(xPosition); } ui++; } } else { // Single byte encoding for (int i=0;i<len;i++) { CGFloat xPosition = CTLineGetOffsetForStringIndex(mLine, i+1, NULL); - positions[i] = xPosition; + positions[i] = static_cast<XYPOSITION>(xPosition); } } @@ -994,7 +993,7 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) { CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, FontCharacterSet(font_)); textLayout->setText (reinterpret_cast<const UInt8*>(s), len, encoding, *reinterpret_cast<QuartzTextStyle*>(font_.GetID())); - return textLayout->MeasureStringWidth(); + return static_cast<XYPOSITION>(textLayout->MeasureStringWidth()); } return 1; } @@ -1021,7 +1020,7 @@ XYPOSITION SurfaceImpl::Ascent(Font &font_) { return 1; float ascent = reinterpret_cast<QuartzTextStyle*>( font_.GetID() )->getAscent(); - return ascent + 0.5; + return ascent + 0.5f; } @@ -1030,7 +1029,7 @@ XYPOSITION SurfaceImpl::Descent(Font &font_) { return 1; float descent = reinterpret_cast<QuartzTextStyle*>( font_.GetID() )->getDescent(); - return descent + 0.5; + return descent + 0.5f; } @@ -1043,14 +1042,13 @@ XYPOSITION SurfaceImpl::ExternalLeading(Font &font_) { return 1; float leading = reinterpret_cast<QuartzTextStyle*>( font_.GetID() )->getLeading(); - return leading + 0.5; + return leading + 0.5f; } XYPOSITION SurfaceImpl::Height(Font &font_) { - int ht = Ascent(font_) + Descent(font_); - return ht; + return Ascent(font_) + Descent(font_); } XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) { @@ -1059,7 +1057,7 @@ XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) { return 1; const int sizeStringLength = ELEMENTS( sizeString ); - int width = WidthText( font_, sizeString, sizeStringLength ); + XYPOSITION width = WidthText( font_, sizeString, sizeStringLength ); return (int) ((width / (float) sizeStringLength) + 0.5); } @@ -1122,7 +1120,7 @@ bool Window::HasFocus() //-------------------------------------------------------------------------------------------------- -static int ScreenMax(NSWindow* win) +static CGFloat ScreenMax(NSWindow* win) { NSScreen* screen = [win screen]; if (!screen) @@ -1155,8 +1153,8 @@ PRectangle Window::GetPosition() CGFloat screenHeight = ScreenMax(win); // Invert screen positions to match Scintilla return PRectangle( - NSMinX(rect), static_cast<XYPOSITION>(screenHeight - NSMaxY(rect)), - NSMaxX(rect), static_cast<XYPOSITION>(screenHeight - NSMinY(rect))); + static_cast<XYPOSITION>(NSMinX(rect)), static_cast<XYPOSITION>(screenHeight - NSMaxY(rect)), + static_cast<XYPOSITION>(NSMaxX(rect)), static_cast<XYPOSITION>(screenHeight - NSMinY(rect))); } else { @@ -1185,7 +1183,7 @@ void Window::SetPosition(PRectangle rc) // NSWindow PLATFORM_ASSERT([idWin isKindOfClass: [NSWindow class]]); NSWindow* win = reinterpret_cast<NSWindow*>(idWin); - int screenHeight = ScreenMax(win); + CGFloat screenHeight = ScreenMax(win); NSRect nsrc = NSMakeRect(rc.left, screenHeight - rc.bottom, rc.Width(), rc.Height()); [win setFrame: nsrc display:YES]; @@ -1343,8 +1341,8 @@ PRectangle Window::GetMonitorRect(Point) CGFloat screenHeight = rect.origin.y + rect.size.height; // Invert screen positions to match Scintilla return PRectangle( - NSMinX(rect), static_cast<XYPOSITION>(screenHeight - NSMaxY(rect)), - NSMaxX(rect), static_cast<XYPOSITION>(screenHeight - NSMinY(rect))); + static_cast<XYPOSITION>(NSMinX(rect)), static_cast<XYPOSITION>(screenHeight - NSMaxY(rect)), + static_cast<XYPOSITION>(NSMaxX(rect)), static_cast<XYPOSITION>(screenHeight - NSMinY(rect))); } } return PRectangle(); @@ -1527,9 +1525,9 @@ private: int lineHeight; bool unicodeMode; int desiredVisibleRows; - unsigned int maxItemWidth; + XYPOSITION maxItemWidth; unsigned int aveCharWidth; - unsigned int maxIconWidth; + XYPOSITION maxIconWidth; Font font; int maxWidth; @@ -1660,13 +1658,13 @@ PRectangle ListBoxImpl::GetDesiredRect() rcDesired = GetPosition(); // There appears to be an extra pixel above and below the row contents - int itemHeight = [table rowHeight] + 2; + CGFloat itemHeight = [table rowHeight] + 2; int rows = Length(); if ((rows == 0) || (rows > desiredVisibleRows)) rows = desiredVisibleRows; - rcDesired.bottom = rcDesired.top + itemHeight * rows; + rcDesired.bottom = rcDesired.top + static_cast<XYPOSITION>(itemHeight * rows); rcDesired.right = rcDesired.left + maxItemWidth + aveCharWidth; if (Length() > rows) @@ -1690,7 +1688,7 @@ int ListBoxImpl::CaretFromEdge() if ([colIcon isHidden]) return 3; else - return 6 + [colIcon width]; + return 6 + static_cast<int>([colIcon width]); } void ListBoxImpl::Clear() @@ -1706,7 +1704,7 @@ void ListBoxImpl::Append(char* s, int type) ld.Add(count, type, s); Scintilla::SurfaceImpl surface; - unsigned int width = surface.WidthText(font, s, static_cast<int>(strlen(s))); + XYPOSITION width = surface.WidthText(font, s, static_cast<int>(strlen(s))); if (width > maxItemWidth) { maxItemWidth = width; @@ -1718,7 +1716,7 @@ void ListBoxImpl::Append(char* s, int type) NSImage* img = it->second; if (img) { - unsigned int widthIcon = img.size.width; + XYPOSITION widthIcon = static_cast<XYPOSITION>(img.size.width); if (widthIcon > maxIconWidth) { [colIcon setHidden: NO]; diff --git a/cocoa/QuartzTextLayout.h b/cocoa/QuartzTextLayout.h index 1e2fbce50..33869ae6e 100644 --- a/cocoa/QuartzTextLayout.h +++ b/cocoa/QuartzTextLayout.h @@ -85,7 +85,7 @@ public: if (mLine == NULL) return 0.0f; - return ::CTLineGetTypographicBounds(mLine, NULL, NULL, NULL); + return static_cast<float>(::CTLineGetTypographicBounds(mLine, NULL, NULL, NULL)); } CTLineRef getCTLine() { diff --git a/cocoa/QuartzTextStyle.h b/cocoa/QuartzTextStyle.h index df5add75c..12cc0e0b2 100644 --- a/cocoa/QuartzTextStyle.h +++ b/cocoa/QuartzTextStyle.h @@ -61,17 +61,17 @@ public: float getAscent() const { - return ::CTFontGetAscent(fontRef); + return static_cast<float>(::CTFontGetAscent(fontRef)); } float getDescent() const { - return ::CTFontGetDescent(fontRef); + return static_cast<float>(::CTFontGetDescent(fontRef)); } float getLeading() const { - return ::CTFontGetLeading(fontRef); + return static_cast<float>(::CTFontGetLeading(fontRef)); } void setFontRef(CTFontRef inRef, int characterSet_) diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index d2d9c0f5a..490953eef 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -578,7 +578,7 @@ CaseFolder *ScintillaCocoa::CaseFolderForEncoding() { // Only for single byte encodings for (int i=0x80; i<0x100; i++) { char sCharacter[2] = "A"; - sCharacter[0] = i; + sCharacter[0] = static_cast<char>(i); CFStringRef cfsVal = CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(sCharacter), 1, encoding, false); @@ -705,7 +705,8 @@ PRectangle ScintillaCocoa::GetClientRectangle() const NSScrollView *scrollView = ScrollContainer(); NSSize size = [[scrollView contentView] bounds].size; Point origin = GetVisibleOriginInMain(); - return PRectangle(origin.x, origin.y, origin.x+size.width, origin.y + size.height); + return PRectangle(origin.x, origin.y, static_cast<XYPOSITION>(origin.x+size.width), + static_cast<XYPOSITION>(origin.y + size.height)); } //-------------------------------------------------------------------------------------------------- @@ -1100,7 +1101,8 @@ void ScintillaCocoa::CTPaint(void* gc, NSRect rc) { void ScintillaCocoa::CallTipMouseDown(NSPoint pt) { NSRect rectBounds = [(NSView *)(ct.wDraw.GetID()) bounds]; - Point location(pt.x, static_cast<XYPOSITION>(rectBounds.size.height - pt.y)); + Point location(static_cast<XYPOSITION>(pt.x), + static_cast<XYPOSITION>(rectBounds.size.height - pt.y)); ct.MouseClick(location); CallTipClick(); } @@ -1161,10 +1163,11 @@ void ScintillaCocoa::ClaimSelection() */ NSPoint ScintillaCocoa::GetCaretPosition() { + const int line = pdoc->LineFromPosition(sel.RangeMain().caret.Position()); NSPoint result; - result.y = pdoc->LineFromPosition(sel.RangeMain().caret.Position()); - result.x = sel.RangeMain().caret.Position() - pdoc->LineStart(result.y); + result.y = line; + result.x = sel.RangeMain().caret.Position() - pdoc->LineStart(line); return result; } @@ -1323,7 +1326,7 @@ void ScintillaCocoa::StartDrag() { PRectangle imageRect = rcSel; paintState = painting; - sw->InitPixMap(client.Width(), client.Height(), NULL, NULL); + sw->InitPixMap(static_cast<int>(client.Width()), static_cast<int>(client.Height()), NULL, NULL); paintingAllText = true; // Have to create a new context and make current as text drawing goes // to the current context, not a passed context. @@ -1335,7 +1338,7 @@ void ScintillaCocoa::StartDrag() Paint(sw, client); paintState = notPainting; - pixmap->InitPixMap(imageRect.Width(), imageRect.Height(), NULL, NULL); + pixmap->InitPixMap(static_cast<int>(imageRect.Width()), static_cast<int>(imageRect.Height()), NULL, NULL); CGContextRef gc = pixmap->GetContext(); // To make Paint() work on a bitmap, we have to flip our coordinates and translate the origin @@ -1683,7 +1686,7 @@ void ScintillaCocoa::SetHorizontalScrollPos() { PRectangle textRect = GetTextRectangle(); - int maxXOffset = scrollWidth - textRect.Width(); + int maxXOffset = scrollWidth - static_cast<int>(textRect.Width()); if (maxXOffset < 0) maxXOffset = 0; if (xOffset > maxXOffset) @@ -1736,7 +1739,7 @@ bool ScintillaCocoa::SetScrollingSize(void) { !Wrapping(); if (!showHorizontalScroll) docWidth = clipRect.size.width; - NSRect contentRect = {0, 0, docWidth, docHeight}; + NSRect contentRect = {{0, 0}, {docWidth, docHeight}}; NSRect contentRectNow = [inner frame]; changes = (contentRect.size.width != contentRectNow.size.width) || (contentRect.size.height != contentRectNow.size.height); @@ -1767,8 +1770,8 @@ void ScintillaCocoa::Resize() */ void ScintillaCocoa::UpdateForScroll() { Point ptOrigin = GetVisibleOriginInMain(); - xOffset = ptOrigin.x; - int newTop = Platform::Minimum(ptOrigin.y / vs.lineHeight, MaxScrollPos()); + xOffset = static_cast<int>(ptOrigin.x); + int newTop = Platform::Minimum(static_cast<int>(ptOrigin.y / vs.lineHeight), MaxScrollPos()); SetTopLine(newTop); } @@ -1809,7 +1812,7 @@ void ScintillaCocoa::RegisterNotifyCallback(intptr_t windowid, SciNotifyFunc cal void ScintillaCocoa::NotifyChange() { if (notifyProc != NULL) - notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(GetCtrlID(), SCEN_CHANGE), + notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(static_cast<short>(GetCtrlID()), SCEN_CHANGE), (uintptr_t) this); } @@ -1818,7 +1821,8 @@ void ScintillaCocoa::NotifyChange() void ScintillaCocoa::NotifyFocus(bool focus) { if (notifyProc != NULL) - notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(GetCtrlID(), (focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS)), + notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(static_cast<short>(GetCtrlID()), + (focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS)), (uintptr_t) this); Editor::NotifyFocus(focus); diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 87a17cebe..a7430f181 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -667,7 +667,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) // Only snap for positions inside the document - allow outside // for overshoot. long lineHeight = mOwner.backend->WndProc(SCI_TEXTHEIGHT, 0, 0); - rc.origin.y = roundf(rc.origin.y / lineHeight) * lineHeight; + rc.origin.y = roundf(static_cast<XYPOSITION>(rc.origin.y) / lineHeight) * lineHeight; } return rc; } @@ -922,8 +922,8 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 zoomDelta += event.magnification * 10.0; - if (fabsf(zoomDelta)>=1.0) { - long zoomFactor = [self getGeneralProperty: SCI_GETZOOM] + zoomDelta; + if (fabs(zoomDelta)>=1.0) { + long zoomFactor = static_cast<long>([self getGeneralProperty: SCI_GETZOOM] + zoomDelta); [self setGeneralProperty: SCI_SETZOOM parameter: zoomFactor value:0]; zoomDelta = 0.0; } @@ -1175,17 +1175,17 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) */ - (void) positionSubViews { - int scrollerWidth = [NSScroller scrollerWidthForControlSize:NSRegularControlSize + CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:NSRegularControlSize scrollerStyle:NSScrollerStyleLegacy]; NSSize size = [self frame].size; - NSRect barFrame = {0, size.height - scrollerWidth, size.width, static_cast<CGFloat>(scrollerWidth)}; + NSRect barFrame = {{0, size.height - scrollerWidth}, {size.width, scrollerWidth}}; BOOL infoBarVisible = mInfoBar != nil && ![mInfoBar isHidden]; // Horizontal offset of the content. Almost always 0 unless the vertical scroller // is on the left side. CGFloat contentX = 0; - NSRect scrollRect = {contentX, 0, size.width, size.height}; + NSRect scrollRect = {{contentX, 0}, {size.width, size.height}}; // Info bar frame. if (infoBarVisible) @@ -1472,9 +1472,9 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) { if ([value colorSpaceName] != NSDeviceRGBColorSpace) value = [value colorUsingColorSpaceName: NSDeviceRGBColorSpace]; - long red = [value redComponent] * 255; - long green = [value greenComponent] * 255; - long blue = [value blueComponent] * 255; + long red = static_cast<long>([value redComponent] * 255); + long green = static_cast<long>([value greenComponent] * 255); + long blue = static_cast<long>([value blueComponent] * 255); long color = (blue << 16) + (green << 8) + red; mBackend->WndProc(property, parameter, color); @@ -1494,27 +1494,27 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) int index = 1; char value[3] = {0, 0, 0}; - value[0] = [fromHTML characterAtIndex: index++]; + value[0] = static_cast<char>([fromHTML characterAtIndex: index++]); if (longVersion) - value[1] = [fromHTML characterAtIndex: index++]; + value[1] = static_cast<char>([fromHTML characterAtIndex: index++]); else value[1] = value[0]; unsigned rawRed; [[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawRed]; - value[0] = [fromHTML characterAtIndex: index++]; + value[0] = static_cast<char>([fromHTML characterAtIndex: index++]); if (longVersion) - value[1] = [fromHTML characterAtIndex: index++]; + value[1] = static_cast<char>([fromHTML characterAtIndex: index++]); else value[1] = value[0]; unsigned rawGreen; [[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawGreen]; - value[0] = [fromHTML characterAtIndex: index++]; + value[0] = static_cast<char>([fromHTML characterAtIndex: index++]); if (longVersion) - value[1] = [fromHTML characterAtIndex: index++]; + value[1] = static_cast<char>([fromHTML characterAtIndex: index++]); else value[1] = value[0]; @@ -1534,9 +1534,9 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) - (NSColor*) getColorProperty: (int) property parameter: (long) parameter { long color = mBackend->WndProc(property, parameter, 0); - float red = (color & 0xFF) / 255.0; - float green = ((color >> 8) & 0xFF) / 255.0; - float blue = ((color >> 16) & 0xFF) / 255.0; + CGFloat red = (color & 0xFF) / 255.0; + CGFloat green = ((color >> 8) & 0xFF) / 255.0; + CGFloat blue = ((color >> 16) & 0xFF) / 255.0; NSColor* result = [NSColor colorWithDeviceRed: red green: green blue: blue alpha: 1]; return result; } |