aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2018-05-14 13:42:24 +1000
committerNeil <nyamatongwe@gmail.com>2018-05-14 13:42:24 +1000
commit8e94953b2d9f7d946445759fe31d169879b680c8 (patch)
treea5f38b198b2c82cec50b3bbe8def5907e6358ac2
parent13c4548805a2a5ef718fc5dfa6f77bb60c6bed2b (diff)
downloadscintilla-mirror-8e94953b2d9f7d946445759fe31d169879b680c8.tar.gz
Backport: Modernize Platform.h (1) - noexcept, const, standard methods.
Changes made to FontParameters, Font, Window, ListBoxEvent, ListBox, Menu, DynamicLibrary, and Platform. Backport of changeset 6938:a42c7cc3254b.
-rw-r--r--cocoa/PlatCocoa.mm14
-rw-r--r--curses/ScintillaCurses.cxx18
-rw-r--r--gtk/PlatGTK.cxx16
-rw-r--r--gtk/ScintillaGTK.cxx3
-rw-r--r--include/Platform.h70
-rw-r--r--qt/ScintillaEditBase/PlatQt.cpp16
-rw-r--r--src/Editor.cxx3
-rw-r--r--src/ScintillaBase.cxx10
-rw-r--r--win32/PlatWin.cxx18
-rw-r--r--win32/ScintillaWin.cxx5
10 files changed, 83 insertions, 90 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 3de8139ea..73d528d00 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -75,7 +75,7 @@ inline CGRect PRectangleToCGRect(PRectangle& rc)
//----------------- Font ---------------------------------------------------------------------------
-Font::Font(): fid(0)
+Font::Font() noexcept : fid(0)
{
}
@@ -1082,7 +1082,7 @@ static CGFloat ScreenMax()
//--------------------------------------------------------------------------------------------------
-PRectangle Window::GetPosition()
+PRectangle Window::GetPosition() const
{
if (wid)
{
@@ -1146,9 +1146,9 @@ void Window::SetPosition(PRectangle rc)
//--------------------------------------------------------------------------------------------------
-void Window::SetPositionRelative(PRectangle rc, Window window)
+void Window::SetPositionRelative(PRectangle rc, const Window *window)
{
- PRectangle rcOther = window.GetPosition();
+ PRectangle rcOther = window->GetPosition();
rc.left += rcOther.left;
rc.right += rcOther.left;
rc.top += rcOther.top;
@@ -1158,7 +1158,7 @@ void Window::SetPositionRelative(PRectangle rc, Window window)
//--------------------------------------------------------------------------------------------------
-PRectangle Window::GetClientPosition()
+PRectangle Window::GetClientPosition() const
{
// This means, in MacOS X terms, get the "frame bounds". Call GetPosition, just like on Win32.
return GetPosition();
@@ -1868,7 +1868,7 @@ void ListBoxImpl::SelectionChange() {
// ListBox is implemented by the ListBoxImpl class.
-ListBox::ListBox()
+ListBox::ListBox() noexcept
{
}
@@ -1926,7 +1926,7 @@ void Window::Destroy()
//----------------- Menu ---------------------------------------------------------------------------
-Menu::Menu()
+Menu::Menu() noexcept
: mid(0)
{
}
diff --git a/curses/ScintillaCurses.cxx b/curses/ScintillaCurses.cxx
index b5be8bb70..21c7a8c02 100644
--- a/curses/ScintillaCurses.cxx
+++ b/curses/ScintillaCurses.cxx
@@ -72,7 +72,7 @@ using namespace Scintilla;
* done in `Font::Create()`.
* @see Font::Create
*/
-Font::Font() : fid(0) {}
+Font::Font() noexcept : fid(0) {}
/** Deletes the font. Currently empty. */
Font::~Font() {}
/**
@@ -620,7 +620,7 @@ void Window::Destroy() {
* bounds to ensure all of it is painted.
* @return PRectangle with the window's boundaries.
*/
-PRectangle Window::GetPosition() {
+PRectangle Window::GetPosition() const {
int maxx = wid ? getmaxx(_WINDOW(wid)) : 0;
int maxy = wid ? getmaxy(_WINDOW(wid)) : 0;
return PRectangle(0, 0, maxx, maxy);
@@ -631,10 +631,10 @@ PRectangle Window::GetPosition() {
* @param rc The position relative to the parent window.
* @param relativeTo The parent window.
*/
-void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
+void Window::SetPositionRelative(PRectangle rc, const Window *relativeTo) {
int begx = 0, begy = 0, x = 0, y = 0;
// Determine the relative position.
- getbegyx(_WINDOW(relativeTo.GetID()), begy, begx);
+ getbegyx(_WINDOW(relativeTo->GetID()), begy, begx);
x = begx + rc.left;
if (x < begx) x = begx;
y = begy + rc.top;
@@ -642,8 +642,8 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
// Correct to fit the parent if necessary.
int sizex = rc.right - rc.left;
int sizey = rc.bottom - rc.top;
- int screen_width = getmaxx(_WINDOW(relativeTo.GetID()));
- int screen_height = getmaxy(_WINDOW(relativeTo.GetID()));
+ int screen_width = getmaxx(_WINDOW(relativeTo->GetID()));
+ int screen_height = getmaxy(_WINDOW(relativeTo->GetID()));
if (sizex > screen_width)
x = begx; // align left
else if (x + sizex > begx + screen_width)
@@ -657,7 +657,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
mvwin(_WINDOW(wid), y, x);
}
/** Identical to `Window::GetPosition()`. */
-PRectangle Window::GetClientPosition() { return GetPosition(); }
+PRectangle Window::GetClientPosition() const { return GetPosition(); }
void Window::Show(bool show) { /* TODO: */ }
void Window::InvalidateAll() { /* notify repaint */ }
void Window::InvalidateRectangle(PRectangle rc) { /* notify repaint*/ }
@@ -840,14 +840,14 @@ public:
};
/** Creates a new Scintilla ListBox. */
-ListBox::ListBox() {}
+ListBox::ListBox() noexcept {}
/** Deletes the ListBox. */
ListBox::~ListBox() {}
/** Creates a new curses ListBox. */
ListBox *ListBox::Allocate() { return new ListBoxImpl(); }
// Menus are not implemented.
-Menu::Menu() : mid(0) {}
+Menu::Menu() noexcept : mid(0) {}
void Menu::CreatePopUp() {}
void Menu::Destroy() {}
void Menu::Show(Point pt, Window &w) {}
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index f9ee02bfc..6c0432198 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -105,7 +105,7 @@ static GtkWidget *PWidget(WindowID wid) {
return static_cast<GtkWidget *>(wid);
}
-Font::Font() : fid(0) {}
+Font::Font() noexcept : fid(0) {}
Font::~Font() {}
@@ -961,7 +961,7 @@ void Window::Destroy() {
}
}
-PRectangle Window::GetPosition() {
+PRectangle Window::GetPosition() const {
// Before any size allocated pretend its 1000 wide so not scrolled
PRectangle rc(0, 0, 1000, 1000);
if (wid) {
@@ -1005,15 +1005,15 @@ GdkRectangle MonitorRectangleForWidget(GtkWidget *wid) {
}
-void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
+void Window::SetPositionRelative(PRectangle rc, const Window *relativeTo) {
int ox = 0;
int oy = 0;
- GdkWindow *wndRelativeTo = WindowFromWidget(PWidget(relativeTo.wid));
+ GdkWindow *wndRelativeTo = WindowFromWidget(PWidget(relativeTo->wid));
gdk_window_get_origin(wndRelativeTo, &ox, &oy);
ox += rc.left;
oy += rc.top;
- GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(relativeTo.wid));
+ GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(relativeTo->wid));
/* do some corrections to fit into screen */
int sizex = rc.right - rc.left;
@@ -1032,7 +1032,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
gtk_window_resize(GTK_WINDOW(wid), sizex, sizey);
}
-PRectangle Window::GetClientPosition() {
+PRectangle Window::GetClientPosition() const {
// On GTK+, the client position is the window position
return GetPosition();
}
@@ -1143,7 +1143,7 @@ static void list_image_free(gpointer, gpointer value, gpointer) {
g_free(list_image);
}
-ListBox::ListBox() {
+ListBox::ListBox() noexcept {
}
ListBox::~ListBox() {
@@ -1866,7 +1866,7 @@ void ListBoxX::SetList(const char *listText, char separator, char typesep) {
}
}
-Menu::Menu() : mid(0) {}
+Menu::Menu() noexcept : mid(0) {}
void Menu::CreatePopUp() {
Destroy();
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index 704d7163b..6a115994b 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -979,8 +979,7 @@ void ScintillaGTK::FullPaint() {
}
PRectangle ScintillaGTK::GetClientRectangle() const {
- Window win = wMain;
- PRectangle rc = win.GetClientPosition();
+ PRectangle rc = wMain.GetClientPosition();
if (verticalScrollBarVisible)
rc.right -= verticalScrollBarWidth;
if (horizontalScrollBarVisible && !Wrapping())
diff --git a/include/Platform.h b/include/Platform.h
index b9f33fccd..c5f3256ee 100644
--- a/include/Platform.h
+++ b/include/Platform.h
@@ -250,7 +250,7 @@ struct FontParameters {
bool italic_=false,
int extraFontFlag_=0,
int technology_=0,
- int characterSet_=0) :
+ int characterSet_=0) noexcept :
faceName(faceName_),
size(size_),
@@ -267,19 +267,21 @@ struct FontParameters {
class Font {
protected:
FontID fid;
- // Private so Font objects can not be copied
- Font(const Font &);
- Font &operator=(const Font &);
public:
- Font();
+ Font() noexcept;
+ // Deleted so Font objects can not be copied
+ Font(const Font &) = delete;
+ Font(Font &&) = delete;
+ Font &operator=(const Font &) = delete;
+ Font &operator=(Font &&) = delete;
virtual ~Font();
virtual void Create(const FontParameters &fp);
virtual void Release();
- FontID GetID() { return fid; }
+ FontID GetID() const noexcept { return fid; }
// Alias another font - caller guarantees not to Release
- void SetID(FontID fid_) { fid = fid_; }
+ void SetID(FontID fid_) noexcept { fid = fid_; }
friend class Surface;
friend class SurfaceImpl;
};
@@ -346,30 +348,25 @@ class Window {
protected:
WindowID wid;
public:
- Window() : wid(0), cursorLast(cursorInvalid) {
+ Window() noexcept : wid(0), cursorLast(cursorInvalid) {
}
- Window(const Window &source) : wid(source.wid), cursorLast(cursorInvalid) {
- }
- virtual ~Window();
- Window &operator=(WindowID wid_) {
+ Window(const Window &source) = delete;
+ Window(Window &&) = delete;
+ Window &operator=(WindowID wid_) noexcept {
wid = wid_;
cursorLast = cursorInvalid;
return *this;
}
- Window &operator=(const Window &other) {
- if (this != &other) {
- wid = other.wid;
- cursorLast = other.cursorLast;
- }
- return *this;
- }
- WindowID GetID() const { return wid; }
- bool Created() const { return wid != 0; }
+ Window &operator=(const Window &) = delete;
+ Window &operator=(Window &&) = delete;
+ virtual ~Window();
+ WindowID GetID() const noexcept { return wid; }
+ bool Created() const noexcept { return wid != 0; }
void Destroy();
- PRectangle GetPosition();
+ PRectangle GetPosition() const;
void SetPosition(PRectangle rc);
- void SetPositionRelative(PRectangle rc, Window relativeTo);
- PRectangle GetClientPosition();
+ void SetPositionRelative(PRectangle rc, const Window *relativeTo);
+ PRectangle GetClientPosition() const;
void Show(bool show=true);
void InvalidateAll();
void InvalidateRectangle(PRectangle rc);
@@ -389,7 +386,7 @@ private:
struct ListBoxEvent {
enum class EventType { selectionChange, doubleClick } event;
- ListBoxEvent(EventType event_) : event(event_) {
+ ListBoxEvent(EventType event_) noexcept : event(event_) {
}
};
@@ -400,7 +397,7 @@ public:
class ListBox : public Window {
public:
- ListBox();
+ ListBox() noexcept;
~ListBox() override;
static ListBox *Allocate();
@@ -431,8 +428,8 @@ public:
class Menu {
MenuID mid;
public:
- Menu();
- MenuID GetID() { return mid; }
+ Menu() noexcept;
+ MenuID GetID() const noexcept { return mid; }
void CreatePopUp();
void Destroy();
void Show(Point pt, Window &w);
@@ -443,7 +440,7 @@ public:
*/
class DynamicLibrary {
public:
- virtual ~DynamicLibrary() {}
+ virtual ~DynamicLibrary() = default;
/// @return Pointer to function "name", or NULL on failure.
virtual Function FindFunction(const char *name) = 0;
@@ -470,21 +467,20 @@ public:
* and chrome colour. Not a creatable object, more of a module with several functions.
*/
class Platform {
- // Private so Platform objects can not be copied
- Platform(const Platform &) {}
- Platform &operator=(const Platform &) { return *this; }
public:
- // Should be private because no new Platforms are ever created
- // but gcc warns about this
- Platform() {}
- ~Platform() {}
+ Platform() = default;
+ Platform(const Platform &) = delete;
+ Platform(Platform &&) = delete;
+ Platform &operator=(const Platform &) = delete;
+ Platform &operator=(Platform &&) = delete;
+ ~Platform() = default;
static ColourDesired Chrome();
static ColourDesired ChromeHighlight();
static const char *DefaultFont();
static int DefaultFontSize();
static unsigned int DoubleClickTime();
static void DebugDisplay(const char *s);
- static long LongFromTwoShorts(short a,short b) {
+ static long LongFromTwoShorts(short a,short b) noexcept {
return (a) | ((b) << 16);
}
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp
index fd8974fdf..ac8fbc9cc 100644
--- a/qt/ScintillaEditBase/PlatQt.cpp
+++ b/qt/ScintillaEditBase/PlatQt.cpp
@@ -113,7 +113,7 @@ static QFont *FontPointer(Font &f)
{
return reinterpret_cast<FontAndCharacterSet *>(f.GetID())->pfont;
}
-Font::Font() : fid(nullptr) {}
+Font::Font() noexcept : fid(nullptr) {}
Font::~Font()
{
delete reinterpret_cast<FontAndCharacterSet *>(fid);
@@ -584,7 +584,7 @@ Surface *Surface::Allocate(int)
//----------------------------------------------------------------------
namespace {
-QWidget *window(WindowID wid)
+QWidget *window(WindowID wid) noexcept
{
return static_cast<QWidget *>(wid);
}
@@ -598,7 +598,7 @@ void Window::Destroy()
delete window(wid);
wid = nullptr;
}
-PRectangle Window::GetPosition()
+PRectangle Window::GetPosition() const
{
// Before any size allocated pretend its 1000 wide so not scrolled
return wid ? PRectFromQRect(window(wid)->frameGeometry()) : PRectangle(0, 0, 1000, 1000);
@@ -610,9 +610,9 @@ void Window::SetPosition(PRectangle rc)
window(wid)->setGeometry(QRectFromPRect(rc));
}
-void Window::SetPositionRelative(PRectangle rc, Window relativeTo)
+void Window::SetPositionRelative(PRectangle rc, const Window *relativeTo)
{
- QPoint oPos = window(relativeTo.wid)->mapToGlobal(QPoint(0,0));
+ QPoint oPos = window(relativeTo->wid)->mapToGlobal(QPoint(0,0));
int ox = oPos.x();
int oy = oPos.y();
ox += rc.left;
@@ -638,7 +638,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo)
window(wid)->resize(sizex, sizey);
}
-PRectangle Window::GetClientPosition()
+PRectangle Window::GetClientPosition() const
{
// The client position is the window position
return GetPosition();
@@ -996,7 +996,7 @@ ListWidget *ListBoxImpl::GetWidget() const
return static_cast<ListWidget *>(wid);
}
-ListBox::ListBox() {}
+ListBox::ListBox() noexcept {}
ListBox::~ListBox() {}
ListBox *ListBox::Allocate()
@@ -1040,7 +1040,7 @@ QStyleOptionViewItem ListWidget::viewOptions() const
return result;
}
//----------------------------------------------------------------------
-Menu::Menu() : mid(nullptr) {}
+Menu::Menu() noexcept : mid(nullptr) {}
void Menu::CreatePopUp()
{
Destroy();
diff --git a/src/Editor.cxx b/src/Editor.cxx
index f30c08a59..abbb95917 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -307,8 +307,7 @@ Sci::Line Editor::TopLineOfMain() const {
}
PRectangle Editor::GetClientRectangle() const {
- Window win = wMain;
- return win.GetClientPosition();
+ return wMain.GetClientPosition();
}
PRectangle Editor::GetClientDrawingRectangle() {
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index 10a70bd72..2dbca55d7 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -274,7 +274,7 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list
Redraw();
pt = PointMainCaret();
}
- if (wMargin.GetID()) {
+ if (wMargin.Created()) {
const Point ptOrigin = GetVisibleOriginInMain();
pt.x += ptOrigin.x;
pt.y += ptOrigin.y;
@@ -293,7 +293,7 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list
}
rcac.right = rcac.left + widthLB;
rcac.bottom = static_cast<XYPOSITION>(std::min(static_cast<int>(rcac.top) + heightLB, static_cast<int>(rcPopupBounds.bottom)));
- ac.lb->SetPositionRelative(rcac, wMain);
+ ac.lb->SetPositionRelative(rcac, &wMain);
ac.lb->SetFont(vs.styles[STYLE_DEFAULT].font);
const unsigned int aveCharWidth = static_cast<unsigned int>(vs.styles[STYLE_DEFAULT].aveCharWidth);
ac.lb->SetAverageCharWidth(aveCharWidth);
@@ -317,7 +317,7 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list
rcList.top = pt.y + vs.lineHeight;
}
rcList.bottom = rcList.top + heightAlloced;
- ac.lb->SetPositionRelative(rcList, wMain);
+ ac.lb->SetPositionRelative(rcList, &wMain);
ac.Show(true);
if (lenEntered != 0) {
AutoCompleteMoveToCurrentWord();
@@ -461,7 +461,7 @@ void ScintillaBase::CallTipShow(Point pt, const char *defn) {
if (ct.UseStyleCallTip()) {
ct.SetForeBack(vs.styles[STYLE_CALLTIP].fore, vs.styles[STYLE_CALLTIP].back);
}
- if (wMargin.GetID()) {
+ if (wMargin.Created()) {
const Point ptOrigin = GetVisibleOriginInMain();
pt.x += ptOrigin.x;
pt.y += ptOrigin.y;
@@ -491,7 +491,7 @@ void ScintillaBase::CallTipShow(Point pt, const char *defn) {
}
// Now display the window.
CreateCallTipWindow(rc);
- ct.wCallTip.SetPositionRelative(rc, wMain);
+ ct.wCallTip.SetPositionRelative(rc, &wMain);
ct.wCallTip.Show();
}
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 58ae06f97..1e3c73114 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -447,8 +447,7 @@ void FontCached::ReleaseId(FontID fid_) {
::LeaveCriticalSection(&crPlatformLock);
}
-Font::Font() {
- fid = 0;
+Font::Font() noexcept : fid(0) {
}
Font::~Font() {
@@ -1805,7 +1804,7 @@ void Window::Destroy() {
wid = nullptr;
}
-PRectangle Window::GetPosition() {
+PRectangle Window::GetPosition() const {
RECT rc;
::GetWindowRect(HwndFromWindowID(wid), &rc);
return PRectangle::FromInts(rc.left, rc.top, rc.right, rc.bottom);
@@ -1837,11 +1836,11 @@ static RECT RectFromMonitor(HMONITOR hMonitor) {
}
-void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
+void Window::SetPositionRelative(PRectangle rc, const Window *relativeTo) {
const LONG style = ::GetWindowLong(HwndFromWindowID(wid), GWL_STYLE);
if (style & WS_POPUP) {
POINT ptOther = {0, 0};
- ::ClientToScreen(HwndFromWindowID(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);
@@ -1868,7 +1867,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
SetPosition(rc);
}
-PRectangle Window::GetClientPosition() {
+PRectangle Window::GetClientPosition() const {
RECT rc={0,0,0,0};
if (wid)
::GetClientRect(HwndFromWindowID(wid), &rc);
@@ -2033,7 +2032,7 @@ public:
const TCHAR ListBoxX_ClassName[] = TEXT("ListBoxX");
-ListBox::ListBox() {
+ListBox::ListBox() noexcept {
}
ListBox::~ListBox() {
@@ -2559,8 +2558,7 @@ void ListBoxX::StartResize(WPARAM hitCode) {
}
LRESULT ListBoxX::NcHitTest(WPARAM wParam, LPARAM lParam) const {
- Window win = *this; // Copy HWND to avoid const problems
- const PRectangle rc = win.GetPosition();
+ const PRectangle rc = GetPosition();
LRESULT hit = ::DefWindowProc(GetHWND(), WM_NCHITTEST, wParam, lParam);
// There is an apparent bug in the DefWindowProc hit test code whereby it will
@@ -2894,7 +2892,7 @@ bool ListBoxX_Unregister() {
}
-Menu::Menu() : mid(0) {
+Menu::Menu() noexcept : mid(0) {
}
void Menu::CreatePopUp() {
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 655d99464..541065d31 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -2306,12 +2306,13 @@ void ScintillaWin::Paste() {
void ScintillaWin::CreateCallTipWindow(PRectangle) {
if (!ct.wCallTip.Created()) {
- ct.wCallTip = ::CreateWindow(callClassName, TEXT("ACallTip"),
+ HWND wnd = ::CreateWindow(callClassName, TEXT("ACallTip"),
WS_POPUP, 100, 100, 150, 20,
MainHWND(), 0,
GetWindowInstance(MainHWND()),
this);
- ct.wDraw = ct.wCallTip;
+ ct.wCallTip = wnd;
+ ct.wDraw = wnd;
}
}