aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cocoa/PlatCocoa.mm84
-rw-r--r--cocoa/ScintillaCocoa.mm16
-rw-r--r--cocoa/ScintillaView.mm20
3 files changed, 49 insertions, 71 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index fa05bb658..69eb160eb 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -234,26 +234,23 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface* /* surface_ */, Win
// Create the bitmap.
bitmapData = new uint8_t[bitmapByteCount];
- if (bitmapData != NULL)
- {
- // create the context
- gc = CGBitmapContextCreate(bitmapData,
- width,
- height,
- BITS_PER_COMPONENT,
- bitmapBytesPerRow,
- colorSpace,
- kCGImageAlphaPremultipliedLast);
+ // create the context
+ gc = CGBitmapContextCreate(bitmapData,
+ width,
+ height,
+ BITS_PER_COMPONENT,
+ bitmapBytesPerRow,
+ colorSpace,
+ kCGImageAlphaPremultipliedLast);
- if (gc == NULL)
- {
- // the context couldn't be created for some reason,
- // and we have no use for the bitmap without the context
- delete[] bitmapData;
- bitmapData = NULL;
- }
- textLayout->setContext (gc);
+ if (gc == NULL)
+ {
+ // the context couldn't be created for some reason,
+ // and we have no use for the bitmap without the context
+ delete[] bitmapData;
+ bitmapData = NULL;
}
+ textLayout->setContext (gc);
// the context retains the color space, so we can release it
CGColorSpaceRelease(colorSpace);
@@ -406,7 +403,7 @@ void SurfaceImpl::Polygon(Scintilla::Point *pts, int npts, ColourDesired fore,
ColourDesired back)
{
// Allocate memory for the array of points.
- CGPoint *points = new CGPoint[npts];
+ std::vector<CGPoint> points(npts);
for (int i = 0;i < npts;i++)
{
@@ -422,15 +419,11 @@ void SurfaceImpl::Polygon(Scintilla::Point *pts, int npts, ColourDesired fore,
PenColour(fore);
// Draw the polygon
- CGContextAddLines(gc, points, npts);
+ CGContextAddLines(gc, points.data(), npts);
// Explicitly close the path, so it is closed for stroking AND filling (implicit close = filling only)
CGContextClosePath( gc );
CGContextDrawPath( gc, kCGPathFillStroke );
-
- // Deallocate memory.
- delete points;
- points = NULL;
}
//--------------------------------------------------------------------------------------------------
@@ -1695,36 +1688,31 @@ void ListBoxImpl::SetList(const char* list, char separator, char typesep)
{
Clear();
size_t count = strlen(list) + 1;
- char* words = new char[count];
- if (words)
+ std::vector<char> words(list, list+count);
+ char* startword = words.data();
+ char* numword = NULL;
+ int i = 0;
+ for (; words[i]; i++)
{
- memcpy(words, list, count);
- char* startword = words;
- char* numword = NULL;
- int i = 0;
- for (; words[i]; i++)
- {
- if (words[i] == separator)
- {
- words[i] = '\0';
- if (numword)
- *numword = '\0';
- Append(startword, numword?atoi(numword + 1):-1);
- startword = words + i + 1;
- numword = NULL;
- }
- else if (words[i] == typesep)
- {
- numword = words + i;
- }
- }
- if (startword)
+ if (words[i] == separator)
{
+ words[i] = '\0';
if (numword)
*numword = '\0';
Append(startword, numword?atoi(numword + 1):-1);
+ startword = words.data() + i + 1;
+ numword = NULL;
}
- delete []words;
+ else if (words[i] == typesep)
+ {
+ numword = words.data() + i;
+ }
+ }
+ if (startword)
+ {
+ if (numword)
+ *numword = '\0';
+ Append(startword, numword?atoi(numword + 1):-1);
}
[table reloadData];
}
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index f018aa351..01310e9aa 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -1476,19 +1476,18 @@ bool ScintillaCocoa::GetPasteboardData(NSPasteboard* board, SelectionText* selec
CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?',
false, NULL, 0, &usedLen);
- UInt8 *buffer = new UInt8[usedLen];
+ std::vector<UInt8> buffer(usedLen);
CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?',
- false, buffer,usedLen, NULL);
+ false, buffer.data(),usedLen, NULL);
bool rectangular = bestType == ScintillaRecPboardType;
int len = static_cast<int>(usedLen);
- char *dest = Document::TransformLineEnds(&len, (char *)buffer, len, pdoc->eolMode);
+ std::string dest = Document::TransformLineEnds((char *)buffer.data(), len, pdoc->eolMode);
- selectedText->Set(dest, len+1, pdoc->dbcsCodePage,
+ selectedText->Copy(dest.c_str(), dest.length()+1, pdoc->dbcsCodePage,
vs.styles[STYLE_DEFAULT].characterSet , rectangular, false);
- delete []buffer;
}
return true;
}
@@ -1912,13 +1911,12 @@ int ScintillaCocoa::InsertText(NSString* input)
CFStringGetBytes((CFStringRef)input, rangeAll, encoding, '?',
false, NULL, 0, &usedLen);
- UInt8 *buffer = new UInt8[usedLen];
+ std::vector<UInt8> buffer(usedLen);
CFStringGetBytes((CFStringRef)input, rangeAll, encoding, '?',
- false, buffer,usedLen, NULL);
+ false, buffer.data(),usedLen, NULL);
- AddCharUTF((char*) buffer, static_cast<unsigned int>(usedLen), false);
- delete []buffer;
+ AddCharUTF((char*) buffer.data(), static_cast<unsigned int>(usedLen), false);
return static_cast<int>(usedLen);
}
diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm
index 7f6b4991e..30cc614f4 100644
--- a/cocoa/ScintillaView.mm
+++ b/cocoa/ScintillaView.mm
@@ -1223,22 +1223,18 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
{
NSString *result = @"";
- char *buffer(0);
const long length = mBackend->WndProc(SCI_GETSELTEXT, 0, 0);
if (length > 0)
{
- buffer = new char[length + 1];
+ std::string buffer(length + 1, '\0');
try
{
- mBackend->WndProc(SCI_GETSELTEXT, length + 1, (sptr_t) buffer);
+ mBackend->WndProc(SCI_GETSELTEXT, length + 1, (sptr_t) &buffer[0]);
- result = [NSString stringWithUTF8String: buffer];
- delete[] buffer;
+ result = [NSString stringWithUTF8String: buffer.c_str()];
}
catch (...)
{
- delete[] buffer;
- buffer = 0;
}
}
@@ -1255,22 +1251,18 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
{
NSString *result = @"";
- char *buffer(0);
const long length = mBackend->WndProc(SCI_GETLENGTH, 0, 0);
if (length > 0)
{
- buffer = new char[length + 1];
+ std::string buffer(length + 1, '\0');
try
{
- mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) buffer);
+ mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) &buffer[0]);
- result = [NSString stringWithUTF8String: buffer];
- delete[] buffer;
+ result = [NSString stringWithUTF8String: buffer.c_str()];
}
catch (...)
{
- delete[] buffer;
- buffer = 0;
}
}