aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cocoa/PlatCocoa.mm38
-rw-r--r--cocoa/ScintillaCocoa.mm28
-rw-r--r--win32/PlatWin.cxx57
3 files changed, 64 insertions, 59 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index fce8fad3e..6905a8009 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -70,20 +70,6 @@ inline CGRect PRectangleToCGRect(PRectangle &rc) {
return CGRectMake(rc.left, rc.top, rc.Width(), rc.Height());
}
-//--------------------------------------------------------------------------------------------------
-
-/**
- * Converts a Quartz-style rectangle to a PRectangle structure as used by Scintilla.
- */
-inline PRectangle CGRectToPRectangle(const CGRect &rect) {
- PRectangle rc;
- rc.left = (int)(rect.origin.x + 0.5);
- rc.top = (int)(rect.origin.y + 0.5);
- rc.right = (int)(rect.origin.x + rect.size.width + 0.5);
- rc.bottom = (int)(rect.origin.y + rect.size.height + 0.5);
- return rc;
-}
-
//----------------- Font ---------------------------------------------------------------------------
Font::Font(): fid(0) {
@@ -293,7 +279,7 @@ void SurfaceImpl::FillColour(const ColourDesired &back) {
CGImageRef SurfaceImpl::GetImage() {
// For now, assume that GetImage can only be called on PixMap surfaces.
if (!bitmapData)
- return nullptr;
+ return NULL;
CGContextFlush(gc);
@@ -302,8 +288,8 @@ CGImageRef SurfaceImpl::GetImage() {
if (colorSpace == NULL)
return NULL;
- const int bitmapBytesPerRow = ((int) bitmapWidth * BYTES_PER_PIXEL);
- const int bitmapByteCount = (bitmapBytesPerRow * (int) bitmapHeight);
+ const int bitmapBytesPerRow = bitmapWidth * BYTES_PER_PIXEL;
+ const int bitmapByteCount = bitmapBytesPerRow * bitmapHeight;
// Make a copy of the bitmap data for the image creation and divorce it
// From the SurfaceImpl lifetime
@@ -668,8 +654,8 @@ static CGImageRef ImageCreateFromRGBA(int width, int height, const unsigned char
// Create an RGB color space.
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
if (colorSpace) {
- const int bitmapBytesPerRow = ((int) width * 4);
- const int bitmapByteCount = (bitmapBytesPerRow * (int) height);
+ const int bitmapBytesPerRow = width * 4;
+ const int bitmapByteCount = bitmapBytesPerRow * height;
// Create a data provider.
CGDataProviderRef dataProvider = 0;
@@ -739,8 +725,8 @@ void SurfaceImpl::CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect,
CGRect dst = PRectangleToCGRect(dstRect);
/* source from QuickDrawToQuartz2D.pdf on developer.apple.com */
- float w = (float) CGImageGetWidth(image);
- float h = (float) CGImageGetHeight(image);
+ const float w = static_cast<float>(CGImageGetWidth(image));
+ const float h = static_cast<float>(CGImageGetHeight(image));
CGRect drawRect = CGRectMake(0, 0, w, h);
if (!CGRectEqualToRect(src, dst)) {
CGFloat sx = CGRectGetWidth(dst) / CGRectGetWidth(src);
@@ -988,7 +974,7 @@ XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) {
const int sizeStringLength = ELEMENTS(sizeString);
XYPOSITION width = WidthText(font_, sizeString, sizeStringLength);
- return (int)((width / (float) sizeStringLength) + 0.5);
+ return round(width / sizeStringLength);
}
void SurfaceImpl::SetClip(PRectangle rc) {
@@ -1596,7 +1582,7 @@ void ListBoxImpl::SetList(const char *list, char separator, char typesep) {
size_t count = strlen(list) + 1;
std::vector<char> words(list, list+count);
char *startword = words.data();
- char *numword = NULL;
+ char *numword = nullptr;
int i = 0;
for (; words[i]; i++) {
if (words[i] == separator) {
@@ -1605,7 +1591,7 @@ void ListBoxImpl::SetList(const char *list, char separator, char typesep) {
*numword = '\0';
Append(startword, numword?atoi(numword + 1):-1);
startword = words.data() + i + 1;
- numword = NULL;
+ numword = nullptr;
} else if (words[i] == typesep) {
numword = words.data() + i;
}
@@ -1887,11 +1873,11 @@ void Platform::Assert(const char *c, const char *file, int line) {
* Implements the platform specific part of library loading.
*
* @param modulePath The path to the module to load.
- * @return A library instance or NULL if the module could not be found or another problem occurred.
+ * @return A library instance or nullptr if the module could not be found or another problem occurred.
*/
DynamicLibrary *DynamicLibrary::Load(const char * /* modulePath */) {
// Not implemented.
- return NULL;
+ return nullptr;
}
//--------------------------------------------------------------------------------------------------
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index a7e2cff65..1572d53ed 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -2267,6 +2267,20 @@ void ScintillaCocoa::SetDocPointer(Document *document) {
//--------------------------------------------------------------------------------------------------
/**
+ * Convert NSEvent timestamp NSTimeInterval into unsigned int milliseconds wanted by Editor methods.
+ */
+
+namespace {
+
+unsigned int TimeOfEvent(NSEvent *event) {
+ return static_cast<unsigned int>(event.timestamp * 1000);
+}
+
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
* Called by the owning view when the mouse pointer enters the control.
*/
void ScintillaCocoa::MouseEntered(NSEvent *event) {
@@ -2276,7 +2290,7 @@ void ScintillaCocoa::MouseEntered(NSEvent *event) {
// Mouse location is given in screen coordinates and might also be outside of our bounds.
Point location = ConvertPoint(event.locationInWindow);
ButtonMoveWithModifiers(location,
- (int)(event.timestamp * 1000),
+ TimeOfEvent(event),
TranslateModifierFlags(event.modifierFlags));
}
}
@@ -2292,14 +2306,14 @@ void ScintillaCocoa::MouseExited(NSEvent * /* event */) {
void ScintillaCocoa::MouseDown(NSEvent *event) {
Point location = ConvertPoint(event.locationInWindow);
ButtonDownWithModifiers(location,
- (int)(event.timestamp * 1000),
+ TimeOfEvent(event),
TranslateModifierFlags(event.modifierFlags));
}
void ScintillaCocoa::RightMouseDown(NSEvent *event) {
Point location = ConvertPoint(event.locationInWindow);
RightButtonDownWithModifiers(location,
- (int)(event.timestamp * 1000),
+ TimeOfEvent(event),
TranslateModifierFlags(event.modifierFlags));
}
@@ -2309,7 +2323,7 @@ void ScintillaCocoa::MouseMove(NSEvent *event) {
lastMouseEvent = event;
ButtonMoveWithModifiers(ConvertPoint(event.locationInWindow),
- (int)(event.timestamp * 1000),
+ TimeOfEvent(event),
TranslateModifierFlags(event.modifierFlags));
}
@@ -2317,7 +2331,7 @@ void ScintillaCocoa::MouseMove(NSEvent *event) {
void ScintillaCocoa::MouseUp(NSEvent *event) {
ButtonUpWithModifiers(ConvertPoint(event.locationInWindow),
- (int)(event.timestamp * 1000),
+ TimeOfEvent(event),
TranslateModifierFlags(event.modifierFlags));
}
@@ -2330,9 +2344,9 @@ void ScintillaCocoa::MouseWheel(NSEvent *event) {
// In order to make scrolling with larger offset smoother we scroll less lines the larger the
// delta value is.
if (event.deltaY < 0)
- dY = -(int) sqrt(-10.0 * event.deltaY);
+ dY = -static_cast<int>(sqrt(-10.0 * event.deltaY));
else
- dY = (int) sqrt(10.0 * event.deltaY);
+ dY = static_cast<int>(sqrt(10.0 * event.deltaY));
if (command) {
// Zoom! We play with the font sizes in the styles.
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 71e31e59d..57ef26e6c 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -1787,23 +1787,31 @@ Surface *Surface::Allocate(int technology) {
#endif
}
+namespace {
+
+HWND HwndFromWindowID(WindowID wid) {
+ return static_cast<HWND>(wid);
+}
+
+}
+
Window::~Window() {
}
void Window::Destroy() {
if (wid)
- ::DestroyWindow(static_cast<HWND>(wid));
- wid = 0;
+ ::DestroyWindow(HwndFromWindowID(wid));
+ wid = nullptr;
}
PRectangle Window::GetPosition() {
RECT rc;
- ::GetWindowRect(static_cast<HWND>(wid), &rc);
+ ::GetWindowRect(HwndFromWindowID(wid), &rc);
return PRectangle::FromInts(rc.left, rc.top, rc.right, rc.bottom);
}
void Window::SetPosition(PRectangle rc) {
- ::SetWindowPos(static_cast<HWND>(wid),
+ ::SetWindowPos(HwndFromWindowID(wid),
0, static_cast<int>(rc.left), static_cast<int>(rc.top),
static_cast<int>(rc.Width()), static_cast<int>(rc.Height()), SWP_NOZORDER | SWP_NOACTIVATE);
}
@@ -1829,10 +1837,10 @@ static RECT RectFromMonitor(HMONITOR hMonitor) {
}
void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
- const LONG style = ::GetWindowLong(static_cast<HWND>(wid), GWL_STYLE);
+ const LONG style = ::GetWindowLong(HwndFromWindowID(wid), GWL_STYLE);
if (style & WS_POPUP) {
POINT ptOther = {0, 0};
- ::ClientToScreen(static_cast<HWND>(relativeTo.GetID()), &ptOther);
+ ::ClientToScreen(HwndFromWindowID(relativeTo.GetID()), &ptOther);
rc.Move(static_cast<XYPOSITION>(ptOther.x), static_cast<XYPOSITION>(ptOther.y));
const RECT rcMonitor = RectFromPRectangle(rc);
@@ -1862,28 +1870,28 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
PRectangle Window::GetClientPosition() {
RECT rc={0,0,0,0};
if (wid)
- ::GetClientRect(static_cast<HWND>(wid), &rc);
+ ::GetClientRect(HwndFromWindowID(wid), &rc);
return PRectangle::FromInts(rc.left, rc.top, rc.right, rc.bottom);
}
void Window::Show(bool show) {
if (show)
- ::ShowWindow(static_cast<HWND>(wid), SW_SHOWNOACTIVATE);
+ ::ShowWindow(HwndFromWindowID(wid), SW_SHOWNOACTIVATE);
else
- ::ShowWindow(static_cast<HWND>(wid), SW_HIDE);
+ ::ShowWindow(HwndFromWindowID(wid), SW_HIDE);
}
void Window::InvalidateAll() {
- ::InvalidateRect(static_cast<HWND>(wid), NULL, FALSE);
+ ::InvalidateRect(HwndFromWindowID(wid), NULL, FALSE);
}
void Window::InvalidateRectangle(PRectangle rc) {
const RECT rcw = RectFromPRectangle(rc);
- ::InvalidateRect(static_cast<HWND>(wid), &rcw, FALSE);
+ ::InvalidateRect(HwndFromWindowID(wid), &rcw, FALSE);
}
void Window::SetFont(Font &font) {
- ::SendMessage(static_cast<HWND>(wid), WM_SETFONT,
+ ::SendMessage(HwndFromWindowID(wid), WM_SETFONT,
reinterpret_cast<WPARAM>(font.GetID()), 0);
}
@@ -2128,7 +2136,7 @@ void ListBoxX::Create(Window &parent_, int ctrlID_, Point location_, int lineHei
lineHeight = lineHeight_;
unicodeMode = unicodeMode_;
technology = technology_;
- HWND hwndParent = static_cast<HWND>(parent->GetID());
+ HWND hwndParent = HwndFromWindowID(parent->GetID());
HINSTANCE hinstanceParent = GetWindowInstance(hwndParent);
// Window created as popup so not clipped within parent client area
wid = ::CreateWindowEx(
@@ -2169,7 +2177,7 @@ int ListBoxX::GetVisibleRows() const {
}
HWND ListBoxX::GetHWND() const {
- return static_cast<HWND>(GetID());
+ return HwndFromWindowID(GetID());
}
PRectangle ListBoxX::GetDesiredRect() {
@@ -2610,11 +2618,9 @@ void ListBoxX::OnSelChange() {
}
POINT ListBoxX::GetClientExtent() const {
- Window win = *this; // Copy HWND to avoid const problems
- const PRectangle rc = win.GetPosition();
- POINT ret;
- ret.x = static_cast<LONG>(rc.Width());
- ret.y = static_cast<LONG>(rc.Height());
+ RECT rc;
+ ::GetWindowRect(HwndFromWindowID(wid), &rc);
+ POINT ret { rc.right - rc.left, rc.bottom - rc.top };
return ret;
}
@@ -2655,6 +2661,7 @@ void ListBoxX::Paint(HDC hDC) {
LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
try {
+ ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd)));
switch (iMessage) {
case WM_ERASEBKGND:
return TRUE;
@@ -2662,9 +2669,9 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam,
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hDC = ::BeginPaint(hWnd, &ps);
- ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd)));
- if (lbx)
+ if (lbx) {
lbx->Paint(hDC);
+ }
::EndPaint(hWnd, &ps);
}
return 0;
@@ -2680,7 +2687,6 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam,
const int item = LOWORD(lResult);
if (HIWORD(lResult) == 0 && item >= 0) {
::SendMessage(hWnd, LB_SETCURSEL, item, 0);
- ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd)));
if (lbx) {
lbx->OnSelChange();
}
@@ -2692,7 +2698,6 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam,
return 0;
case WM_LBUTTONDBLCLK: {
- ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd)));
if (lbx) {
lbx->OnDoubleClick();
}
@@ -2718,7 +2723,7 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam,
LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
switch (iMessage) {
case WM_CREATE: {
- HINSTANCE hinstanceParent = GetWindowInstance(static_cast<HWND>(parent->GetID()));
+ HINSTANCE hinstanceParent = GetWindowInstance(HwndFromWindowID(parent->GetID()));
// Note that LBS_NOINTEGRALHEIGHT is specified to fix cosmetic issue when resizing the list
// but has useful side effect of speeding up list population significantly
lb = ::CreateWindowEx(
@@ -2754,7 +2759,7 @@ LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam
case WM_COMMAND:
// This is not actually needed now - the registered double click action is used
// directly to action a choice from the list.
- ::SendMessage(static_cast<HWND>(parent->GetID()), iMessage, wParam, lParam);
+ ::SendMessage(HwndFromWindowID(parent->GetID()), iMessage, wParam, lParam);
break;
case WM_MEASUREITEM: {
@@ -2905,7 +2910,7 @@ void Menu::Destroy() {
void Menu::Show(Point pt, Window &w) {
::TrackPopupMenu(static_cast<HMENU>(mid),
TPM_RIGHTBUTTON, static_cast<int>(pt.x - 4), static_cast<int>(pt.y), 0,
- static_cast<HWND>(w.GetID()), NULL);
+ HwndFromWindowID(w.GetID()), NULL);
Destroy();
}