ssize_t for wxFile, unsigned char markup for color components, whitespace source cleaning.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30877 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2004-12-06 17:32:42 +00:00
parent 42e88ddb61
commit c8b75e9498
6 changed files with 98 additions and 76 deletions

View File

@@ -40,7 +40,9 @@ PRectangle PRectangleFromwxRect(wxRect rc) {
wxColour wxColourFromCA(const ColourAllocated& ca) { wxColour wxColourFromCA(const ColourAllocated& ca) {
ColourDesired cd(ca.AsLong()); ColourDesired cd(ca.AsLong());
return wxColour(cd.GetRed(), cd.GetGreen(), cd.GetBlue()); return wxColour((unsigned char)cd.GetRed(),
(unsigned char)cd.GetGreen(),
(unsigned char)cd.GetBlue());
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -1015,7 +1017,8 @@ void ListBoxImpl::GetValue(int n, char *value, int len) {
void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { void ListBoxImpl::RegisterImage(int type, const char *xpm_data) {
wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1); wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1);
wxBitmap bmp(wxImage(stream, wxBITMAP_TYPE_XPM)); wxImage img(stream, wxBITMAP_TYPE_XPM);
wxBitmap bmp(img);
if (! imgList) { if (! imgList) {
// assumes all images are the same size // assumes all images are the same size
@@ -1254,7 +1257,7 @@ double ElapsedTime::Duration(bool reset) {
// Convert using Scintilla's functions instead of wx's, Scintilla's are more // Convert using Scintilla's functions instead of wx's, Scintilla's are more
// forgiving and won't assert... // forgiving and won't assert...
wxString stc2wx(const char* str, size_t len) wxString stc2wx(const char* str, size_t len)
{ {
if (!len) if (!len)
@@ -1286,7 +1289,6 @@ const wxWX2MBbuf wx2stc(const wxString& str)
// TODO check NULL termination!! // TODO check NULL termination!!
return buffer; return buffer;
} }

View File

@@ -750,12 +750,12 @@ void ScintillaWX::DoMiddleButtonUp(Point WXUNUSED(pt)) {
void ScintillaWX::DoAddChar(int key) { void ScintillaWX::DoAddChar(int key) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
wxChar wszChars[2]; wxChar wszChars[2];
wszChars[0] = key; wszChars[0] = (wxChar)key;
wszChars[1] = 0; wszChars[1] = 0;
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars); wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars);
AddCharUTF((char*)buf.data(), strlen(buf)); AddCharUTF((char*)buf.data(), strlen(buf));
#else #else
AddChar(key); AddChar((char)key);
#endif #endif
} }

View File

@@ -46,7 +46,9 @@ static long wxColourAsLong(const wxColour& co) {
static wxColour wxColourFromLong(long c) { static wxColour wxColourFromLong(long c) {
wxColour clr; wxColour clr;
clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff); clr.Set((unsigned char)(c & 0xff),
(unsigned char)((c >> 8) & 0xff),
(unsigned char)((c >> 16) & 0xff));
return clr; return clr;
} }
@@ -60,7 +62,9 @@ static wxColour wxColourFromSpec(const wxString& spec) {
spec.Mid(1,2).ToLong(&red, 16); spec.Mid(1,2).ToLong(&red, 16);
spec.Mid(3,2).ToLong(&green, 16); spec.Mid(3,2).ToLong(&green, 16);
spec.Mid(5,2).ToLong(&blue, 16); spec.Mid(5,2).ToLong(&blue, 16);
return wxColour(red, green, blue); return wxColour((unsigned char)red,
(unsigned char)green,
(unsigned char)blue);
} }
else else
return wxColour(spec); return wxColour(spec);
@@ -516,7 +520,6 @@ void wxStyledTextCtrl::MarkerDefineBitmap(int markerNumber, const wxBitmap& bmp)
buff[len] = 0; buff[len] = 0;
SendMsg(2049, markerNumber, (long)buff); SendMsg(2049, markerNumber, (long)buff);
delete [] buff; delete [] buff;
} }
// Set a margin to be either numeric or symbolic. // Set a margin to be either numeric or symbolic.
@@ -900,7 +903,6 @@ void wxStyledTextCtrl::RegisterImage(int type, const wxBitmap& bmp) {
buff[len] = 0; buff[len] = 0;
SendMsg(2405, type, (long)buff); SendMsg(2405, type, (long)buff);
delete [] buff; delete [] buff;
} }
// Clear all the registered images. // Clear all the registered images.
@@ -1071,34 +1073,34 @@ int wxStyledTextCtrl::FindText(int minPos, int maxPos,
} }
// On Windows, will draw the document into a display context such as a printer. // On Windows, will draw the document into a display context such as a printer.
int wxStyledTextCtrl::FormatRange(bool doDraw, int wxStyledTextCtrl::FormatRange(bool doDraw,
int startPos, int startPos,
int endPos, int endPos,
wxDC* draw, wxDC* draw,
wxDC* target, wxDC* target,
wxRect renderRect, wxRect renderRect,
wxRect pageRect) { wxRect pageRect) {
RangeToFormat fr; RangeToFormat fr;
if (endPos < startPos) { if (endPos < startPos) {
int temp = startPos; int temp = startPos;
startPos = endPos; startPos = endPos;
endPos = temp; endPos = temp;
} }
fr.hdc = draw; fr.hdc = draw;
fr.hdcTarget = target; fr.hdcTarget = target;
fr.rc.top = renderRect.GetTop(); fr.rc.top = renderRect.GetTop();
fr.rc.left = renderRect.GetLeft(); fr.rc.left = renderRect.GetLeft();
fr.rc.right = renderRect.GetRight(); fr.rc.right = renderRect.GetRight();
fr.rc.bottom = renderRect.GetBottom(); fr.rc.bottom = renderRect.GetBottom();
fr.rcPage.top = pageRect.GetTop(); fr.rcPage.top = pageRect.GetTop();
fr.rcPage.left = pageRect.GetLeft(); fr.rcPage.left = pageRect.GetLeft();
fr.rcPage.right = pageRect.GetRight(); fr.rcPage.right = pageRect.GetRight();
fr.rcPage.bottom = pageRect.GetBottom(); fr.rcPage.bottom = pageRect.GetBottom();
fr.chrg.cpMin = startPos; fr.chrg.cpMin = startPos;
fr.chrg.cpMax = endPos; fr.chrg.cpMax = endPos;
return SendMsg(2151, doDraw, (long)&fr); return SendMsg(2151, doDraw, (long)&fr);
} }
// Retrieve the display line at the top of the display. // Retrieve the display line at the top of the display.
@@ -2603,7 +2605,9 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
if (file.IsOpened()) if (file.IsOpened())
{ {
wxString contents; wxString contents;
size_t len = (size_t)file.Length(); // get the file size (assume it is not huge file...)
ssize_t len = (ssize_t)file.Length();
if (len > 0) if (len > 0)
{ {
#if wxUSE_UNICODE #if wxUSE_UNICODE
@@ -2620,7 +2624,12 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
#endif #endif
} }
else else
success = true; // empty file is ok {
if (len == 0)
success = true; // empty file is ok
else
success = false; // len == wxInvalidOffset
}
if (success) if (success)
{ {

View File

@@ -40,7 +40,9 @@ PRectangle PRectangleFromwxRect(wxRect rc) {
wxColour wxColourFromCA(const ColourAllocated& ca) { wxColour wxColourFromCA(const ColourAllocated& ca) {
ColourDesired cd(ca.AsLong()); ColourDesired cd(ca.AsLong());
return wxColour(cd.GetRed(), cd.GetGreen(), cd.GetBlue()); return wxColour((unsigned char)cd.GetRed(),
(unsigned char)cd.GetGreen(),
(unsigned char)cd.GetBlue());
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -1015,7 +1017,8 @@ void ListBoxImpl::GetValue(int n, char *value, int len) {
void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { void ListBoxImpl::RegisterImage(int type, const char *xpm_data) {
wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1); wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1);
wxBitmap bmp(wxImage(stream, wxBITMAP_TYPE_XPM)); wxImage img(stream, wxBITMAP_TYPE_XPM);
wxBitmap bmp(img);
if (! imgList) { if (! imgList) {
// assumes all images are the same size // assumes all images are the same size
@@ -1254,7 +1257,7 @@ double ElapsedTime::Duration(bool reset) {
// Convert using Scintilla's functions instead of wx's, Scintilla's are more // Convert using Scintilla's functions instead of wx's, Scintilla's are more
// forgiving and won't assert... // forgiving and won't assert...
wxString stc2wx(const char* str, size_t len) wxString stc2wx(const char* str, size_t len)
{ {
if (!len) if (!len)
@@ -1286,7 +1289,6 @@ const wxWX2MBbuf wx2stc(const wxString& str)
// TODO check NULL termination!! // TODO check NULL termination!!
return buffer; return buffer;
} }

View File

@@ -750,12 +750,12 @@ void ScintillaWX::DoMiddleButtonUp(Point WXUNUSED(pt)) {
void ScintillaWX::DoAddChar(int key) { void ScintillaWX::DoAddChar(int key) {
#if wxUSE_UNICODE #if wxUSE_UNICODE
wxChar wszChars[2]; wxChar wszChars[2];
wszChars[0] = key; wszChars[0] = (wxChar)key;
wszChars[1] = 0; wszChars[1] = 0;
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars); wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars);
AddCharUTF((char*)buf.data(), strlen(buf)); AddCharUTF((char*)buf.data(), strlen(buf));
#else #else
AddChar(key); AddChar((char)key);
#endif #endif
} }

View File

@@ -46,7 +46,9 @@ static long wxColourAsLong(const wxColour& co) {
static wxColour wxColourFromLong(long c) { static wxColour wxColourFromLong(long c) {
wxColour clr; wxColour clr;
clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff); clr.Set((unsigned char)(c & 0xff),
(unsigned char)((c >> 8) & 0xff),
(unsigned char)((c >> 16) & 0xff));
return clr; return clr;
} }
@@ -60,7 +62,9 @@ static wxColour wxColourFromSpec(const wxString& spec) {
spec.Mid(1,2).ToLong(&red, 16); spec.Mid(1,2).ToLong(&red, 16);
spec.Mid(3,2).ToLong(&green, 16); spec.Mid(3,2).ToLong(&green, 16);
spec.Mid(5,2).ToLong(&blue, 16); spec.Mid(5,2).ToLong(&blue, 16);
return wxColour(red, green, blue); return wxColour((unsigned char)red,
(unsigned char)green,
(unsigned char)blue);
} }
else else
return wxColour(spec); return wxColour(spec);
@@ -516,7 +520,6 @@ void wxStyledTextCtrl::MarkerDefineBitmap(int markerNumber, const wxBitmap& bmp)
buff[len] = 0; buff[len] = 0;
SendMsg(2049, markerNumber, (long)buff); SendMsg(2049, markerNumber, (long)buff);
delete [] buff; delete [] buff;
} }
// Set a margin to be either numeric or symbolic. // Set a margin to be either numeric or symbolic.
@@ -900,7 +903,6 @@ void wxStyledTextCtrl::RegisterImage(int type, const wxBitmap& bmp) {
buff[len] = 0; buff[len] = 0;
SendMsg(2405, type, (long)buff); SendMsg(2405, type, (long)buff);
delete [] buff; delete [] buff;
} }
// Clear all the registered images. // Clear all the registered images.
@@ -1071,34 +1073,34 @@ int wxStyledTextCtrl::FindText(int minPos, int maxPos,
} }
// On Windows, will draw the document into a display context such as a printer. // On Windows, will draw the document into a display context such as a printer.
int wxStyledTextCtrl::FormatRange(bool doDraw, int wxStyledTextCtrl::FormatRange(bool doDraw,
int startPos, int startPos,
int endPos, int endPos,
wxDC* draw, wxDC* draw,
wxDC* target, wxDC* target,
wxRect renderRect, wxRect renderRect,
wxRect pageRect) { wxRect pageRect) {
RangeToFormat fr; RangeToFormat fr;
if (endPos < startPos) { if (endPos < startPos) {
int temp = startPos; int temp = startPos;
startPos = endPos; startPos = endPos;
endPos = temp; endPos = temp;
} }
fr.hdc = draw; fr.hdc = draw;
fr.hdcTarget = target; fr.hdcTarget = target;
fr.rc.top = renderRect.GetTop(); fr.rc.top = renderRect.GetTop();
fr.rc.left = renderRect.GetLeft(); fr.rc.left = renderRect.GetLeft();
fr.rc.right = renderRect.GetRight(); fr.rc.right = renderRect.GetRight();
fr.rc.bottom = renderRect.GetBottom(); fr.rc.bottom = renderRect.GetBottom();
fr.rcPage.top = pageRect.GetTop(); fr.rcPage.top = pageRect.GetTop();
fr.rcPage.left = pageRect.GetLeft(); fr.rcPage.left = pageRect.GetLeft();
fr.rcPage.right = pageRect.GetRight(); fr.rcPage.right = pageRect.GetRight();
fr.rcPage.bottom = pageRect.GetBottom(); fr.rcPage.bottom = pageRect.GetBottom();
fr.chrg.cpMin = startPos; fr.chrg.cpMin = startPos;
fr.chrg.cpMax = endPos; fr.chrg.cpMax = endPos;
return SendMsg(2151, doDraw, (long)&fr); return SendMsg(2151, doDraw, (long)&fr);
} }
// Retrieve the display line at the top of the display. // Retrieve the display line at the top of the display.
@@ -2603,7 +2605,9 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
if (file.IsOpened()) if (file.IsOpened())
{ {
wxString contents; wxString contents;
size_t len = (size_t)file.Length(); // get the file size (assume it is not huge file...)
ssize_t len = (ssize_t)file.Length();
if (len > 0) if (len > 0)
{ {
#if wxUSE_UNICODE #if wxUSE_UNICODE
@@ -2620,7 +2624,12 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
#endif #endif
} }
else else
success = true; // empty file is ok {
if (len == 0)
success = true; // empty file is ok
else
success = false; // len == wxInvalidOffset
}
if (success) if (success)
{ {