diff --git a/include/wx/confbase.h b/include/wx/confbase.h index 714e3d0092..7188f50790 100644 --- a/include/wx/confbase.h +++ b/include/wx/confbase.h @@ -211,7 +211,7 @@ public: if ( !found ) { if (IsRecordingDefaults()) - ((wxConfigBase *)this)->Write(key, defVal); + const_cast(this)->Write(key, defVal); *value = defVal; } return found; diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 6558cd05c2..52c2f98cea 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -1218,7 +1218,7 @@ public: { return m_data; } wxDataViewItem GetItem() const - { return wxDataViewItem( (void*) this ); } + { return wxDataViewItem(const_cast(static_cast(this))); } virtual bool IsContainer() { return false; } diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index c5cb138e64..23be3289be 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -391,7 +391,7 @@ public: void Insert(const T* pItem, size_t uiIndex) { - base::insert(this->begin() + uiIndex, (T*)pItem); + base::insert(this->begin() + uiIndex, pItem); } void Empty() { DoEmpty(); base::clear(); } diff --git a/include/wx/generic/dcpsg.h b/include/wx/generic/dcpsg.h index 84f9e6690e..b26cde59f7 100644 --- a/include/wx/generic/dcpsg.h +++ b/include/wx/generic/dcpsg.h @@ -152,8 +152,8 @@ protected: unsigned char m_currentBlue; int m_pageNumber; bool m_clipping; - double m_underlinePosition; - double m_underlineThickness; + mutable double m_underlinePosition; + mutable double m_underlineThickness; wxPrintData m_printData; double m_pageHeight; wxArrayString m_definedPSFonts; diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index 0b96827dd6..60e464c85a 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -68,8 +68,8 @@ protected: void DoSetRange(double min_val, double max_val); void DoSetIncrement(double inc); - void GtkDisableEvents() const; - void GtkEnableEvents() const; + void GtkDisableEvents(); + void GtkEnableEvents(); // Update the number of digits used to match our range (and base). void GtkSetEntryWidth(); diff --git a/include/wx/list.h b/include/wx/list.h index 3c3ddd896e..40f5b79341 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -483,7 +483,8 @@ public: wxDEPRECATED( wxNode *Nth(size_t n) const ); // use Item // kludge for typesafe list migration in core classes. - wxDEPRECATED( operator wxList&() const ); + wxDEPRECATED( operator wxList&() ); + wxDEPRECATED( operator const wxList&() const ); #endif // wxLIST_COMPATIBILITY protected: @@ -1147,7 +1148,6 @@ inline int wxListBase::Number() const { return (int)GetCount(); } inline wxNode *wxListBase::First() const { return (wxNode *)GetFirst(); } inline wxNode *wxListBase::Last() const { return (wxNode *)GetLast(); } inline wxNode *wxListBase::Nth(size_t n) const { return (wxNode *)Item(n); } -inline wxListBase::operator wxList&() const { return *(wxList*)this; } #endif @@ -1200,6 +1200,10 @@ public: #if !wxUSE_STD_CONTAINERS +// wxListBase deprecated methods +inline wxListBase::operator wxList&() { return *static_cast(this); } +inline wxListBase::operator const wxList&() const { return *static_cast(this); } + // ----------------------------------------------------------------------------- // wxStringList class for compatibility with the old code // ----------------------------------------------------------------------------- diff --git a/include/wx/msw/dde.h b/include/wx/msw/dde.h index a7cd04ccda..64ec55677a 100644 --- a/include/wx/msw/dde.h +++ b/include/wx/msw/dde.h @@ -87,10 +87,11 @@ public: // Find/delete wxDDEConnection corresponding to the HCONV wxDDEConnection *FindConnection(WXHCONV conv); bool DeleteConnection(WXHCONV conv); - wxString& GetServiceName() const { return (wxString&) m_serviceName; } + wxString& GetServiceName() { return m_serviceName; } + const wxString& GetServiceName() const { return m_serviceName; } - wxDDEConnectionList& GetConnections() const - { return (wxDDEConnectionList&) m_connections; } + wxDDEConnectionList& GetConnections() { return m_connections; } + const wxDDEConnectionList& GetConnections() const { return m_connections; } protected: int m_lastError; @@ -120,8 +121,8 @@ public: wxDDEConnection *FindConnection(WXHCONV conv); bool DeleteConnection(WXHCONV conv); - wxDDEConnectionList& GetConnections() const - { return (wxDDEConnectionList&) m_connections; } + wxDDEConnectionList& GetConnections() { return m_connections; } + const wxDDEConnectionList& GetConnections() const { return m_connections; } protected: int m_lastError; diff --git a/include/wx/msw/dib.h b/include/wx/msw/dib.h index 6fb4c3eca3..3b068879bc 100644 --- a/include/wx/msw/dib.h +++ b/include/wx/msw/dib.h @@ -122,7 +122,7 @@ public: // non NULL) static HBITMAP ConvertToBitmap(const BITMAPINFO *pbi, HDC hdc = 0, - void *bits = NULL); + const void *bits = NULL); // create a plain DIB (not a DIB section) from a DDB, the caller is // responsable for freeing it using ::GlobalFree() diff --git a/include/wx/msw/registry.h b/include/wx/msw/registry.h index f3925f97bf..783706f4e4 100644 --- a/include/wx/msw/registry.h +++ b/include/wx/msw/registry.h @@ -263,7 +263,7 @@ private: wxString m_strKey; // key name (relative to m_hRootKey) WOW64ViewMode m_viewMode; // which view to select under WOW64 AccessMode m_mode; // valid only if key is opened - long m_dwLastError; // last error (0 if none) + mutable long m_dwLastError; // last error (0 if none) wxDECLARE_NO_COPY_CLASS(wxRegKey); diff --git a/include/wx/msw/winundef.h b/include/wx/msw/winundef.h index aedf4340d3..879a6ef626 100644 --- a/include/wx/msw/winundef.h +++ b/include/wx/msw/winundef.h @@ -263,12 +263,12 @@ #if wxUSE_UNICODE_WINDOWS_H inline int StartDoc(HDC h, CONST DOCINFOW* info) { - return StartDocW(h, (DOCINFOW*) info); + return StartDocW(h, const_cast(info)); } #else inline int StartDoc(HDC h, CONST DOCINFOA* info) { - return StartDocA(h, (DOCINFOA*) info); + return StartDocA(h, const_cast(info); } #endif #endif diff --git a/include/wx/osx/core/cfref.h b/include/wx/osx/core/cfref.h index 56a0697f3f..4a258ba21b 100644 --- a/include/wx/osx/core/cfref.h +++ b/include/wx/osx/core/cfref.h @@ -66,7 +66,7 @@ inline Type* wxCFRetain(Type *r) // Casting r to CFTypeRef ensures we are calling the real C version defined in CFBase.h // and not any possibly templated/overloaded CFRetain. if ( r != NULL ) - r = (Type*)::CFRetain((CFTypeRef)r); + r = const_cast(static_cast(::CFRetain(static_cast(r)))); return r; } diff --git a/include/wx/ownerdrw.h b/include/wx/ownerdrw.h index 7ae3b71cb4..4dfc30b47c 100644 --- a/include/wx/ownerdrw.h +++ b/include/wx/ownerdrw.h @@ -43,21 +43,21 @@ public: void SetFont(const wxFont& font) { m_font = font; m_ownerDrawn = true; } - wxFont& GetFont() const - { return (wxFont&) m_font; } + wxFont& GetFont() { return m_font; } + const wxFont& GetFont() const { return m_font; } void SetTextColour(const wxColour& colText) { m_colText = colText; m_ownerDrawn = true; } - wxColour& GetTextColour() const - { return (wxColour&) m_colText; } + wxColour& GetTextColour() { return m_colText; } + const wxColour& GetTextColour() const { return m_colText; } void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; m_ownerDrawn = true; } - wxColour& GetBackgroundColour() const - { return (wxColour&) m_colBack ; } + wxColour& GetBackgroundColour() { return m_colBack; } + const wxColour& GetBackgroundColour() const { return m_colBack ; } void SetMarginWidth(int width) diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index 2235ff1090..955b935779 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -27,7 +27,7 @@ class WXDLLIMPEXP_PROPGRID wxPGPropArgCls public: wxPGPropArgCls( const wxPGProperty* property ) { - m_ptr.property = (wxPGProperty*) property; + m_ptr.property = const_cast(property); m_flags = IsProperty; } wxPGPropArgCls( const wxString& str ) diff --git a/include/wx/propgrid/propgridpagestate.h b/include/wx/propgrid/propgridpagestate.h index e2b2777eef..7f5f25bb57 100644 --- a/include/wx/propgrid/propgridpagestate.h +++ b/include/wx/propgrid/propgridpagestate.h @@ -571,7 +571,7 @@ protected: // Returns property by its label. wxPGProperty* BaseGetPropertyByLabel( const wxString& label, - wxPGProperty* parent = NULL ) const; + const wxPGProperty* parent = NULL ) const; // Unselect sub-properties. void DoRemoveChildrenFromSelection(wxPGProperty* p, bool recursive, diff --git a/include/wx/stringimpl.h b/include/wx/stringimpl.h index e46bb800de..d10242e7a4 100644 --- a/include/wx/stringimpl.h +++ b/include/wx/stringimpl.h @@ -105,7 +105,8 @@ struct WXDLLIMPEXP_BASE wxStringData nAllocLength; // allocated memory size // mimics declaration 'wxStringCharType data[nAllocLength]' - wxStringCharType* data() const { return (wxStringCharType*)(this + 1); } + wxStringCharType* data() { return reinterpret_cast(this + 1); } + const wxStringCharType* data() const { return reinterpret_cast(this + 1); } // empty string has a special ref count so it's never deleted bool IsEmpty() const { return (nRefs == -1); } @@ -151,9 +152,9 @@ protected: // initializes the string to the empty value (must be called only from // ctors, use Reinit() otherwise) #if wxUSE_UNICODE_UTF8 - void Init() { m_pchData = (wxStringCharType *)wxEmptyStringImpl; } // FIXME-UTF8 + void Init() { m_pchData = const_cast(wxEmptyStringImpl); } // FIXME-UTF8 #else - void Init() { m_pchData = (wxStringCharType *)wxEmptyString; } + void Init() { m_pchData = const_cast(wxEmptyString); } #endif // initializes the string with (a part of) C-string void InitWith(const wxStringCharType *psz, size_t nPos = 0, size_t nLen = npos); diff --git a/include/wx/thread.h b/include/wx/thread.h index 5a0ac27514..872609ca30 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -640,7 +640,7 @@ private: wxThreadInternal *m_internal; // protects access to any methods of wxThreadInternal object - wxCriticalSection m_critsect; + mutable wxCriticalSection m_critsect; // true if the thread is detached, false if it is joinable bool m_isDetached; @@ -731,7 +731,7 @@ public: // returns a pointer to the thread which can be used to call Run() wxThread *GetThread() const { - wxCriticalSectionLocker locker((wxCriticalSection&)m_critSection); + wxCriticalSectionLocker locker(m_critSection); wxThread* thread = m_thread; @@ -741,7 +741,7 @@ public: protected: wxThread *m_thread; wxThreadKind m_kind; - wxCriticalSection m_critSection; // To guard the m_thread variable + mutable wxCriticalSection m_critSection; // To guard the m_thread variable friend class wxThreadHelperThread; }; diff --git a/include/wx/window.h b/include/wx/window.h index 92cd592644..22fc655a4b 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1032,7 +1032,7 @@ public: // does this window have the capture? virtual bool HasCapture() const - { return (wxWindow *)this == GetCapture(); } + { return reinterpret_cast(this) == GetCapture(); } // enable the specified touch events for this window, return false if // the requested events are not supported diff --git a/include/wx/wxcrt.h b/include/wx/wxcrt.h index 9f17dc759b..d239f6cfeb 100644 --- a/include/wx/wxcrt.h +++ b/include/wx/wxcrt.h @@ -110,7 +110,7 @@ WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n); // (notice that these intentionally return "char *" and not "void *" unlike the // standard memxxx() for symmetry with the wide char versions): inline char* wxTmemchr(const char* s, char c, size_t len) - { return (char*)memchr(s, c, len); } + { return const_cast(static_cast(memchr(s, c, len))); } inline int wxTmemcmp(const char* sz1, const char* sz2, size_t len) { return memcmp(sz1, sz2, len); } inline char* wxTmemcpy(char* szOut, const char* szIn, size_t len) @@ -727,7 +727,7 @@ inline char * wxStrchr(char *s, T c) { return const_cast(wxStrchr(const_cast(s), c)); } template inline wchar_t * wxStrchr(wchar_t *s, T c) - { return (wchar_t *)wxStrchr((const wchar_t *)s, c); } + { return const_cast(wxStrchr(const_cast(s), c)); } template inline char * wxStrrchr(char *s, T c) { return const_cast(wxStrrchr(const_cast(s), c)); } diff --git a/samples/artprov/artbrows.cpp b/samples/artprov/artbrows.cpp index ea0b9944da..e9b464bb87 100644 --- a/samples/artprov/artbrows.cpp +++ b/samples/artprov/artbrows.cpp @@ -28,7 +28,7 @@ #include "artbrows.h" #define ART_CLIENT(id) \ - choice->Append(#id, (void*)id); + choice->Append(#id, const_cast(static_cast(id))); #define ART_ICON(id) \ { \ int ind; \ diff --git a/samples/dataview/mymodels.cpp b/samples/dataview/mymodels.cpp index 75f375d817..9c5ee3112b 100644 --- a/samples/dataview/mymodels.cpp +++ b/samples/dataview/mymodels.cpp @@ -292,7 +292,7 @@ unsigned int MyMusicTreeModel::GetChildren( const wxDataViewItem &parent, if (node == m_classical) { - MyMusicTreeModel *model = (MyMusicTreeModel*)(const MyMusicTreeModel*) this; + MyMusicTreeModel* model = const_cast(this); model->m_classicalMusicIsKnownToControl = true; } diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index daa78a4a25..74e2e1ffb6 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -2022,7 +2022,7 @@ void DnDShapeDataObject::CreateBitmap() const m_shape->Draw(dc); dc.SelectObject(wxNullBitmap); - DnDShapeDataObject *self = (DnDShapeDataObject *)this; // const_cast + DnDShapeDataObject* self = const_cast(this); self->m_dobjBitmap.SetBitmap(bitmap); self->m_hasBitmap = true; } diff --git a/samples/dragimag/dragimag.h b/samples/dragimag/dragimag.h index c3ec6aef6b..53036676e1 100644 --- a/samples/dragimag/dragimag.h +++ b/samples/dragimag/dragimag.h @@ -53,7 +53,7 @@ public: bool TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap); //// Accessors - wxBitmap& GetBackgroundBitmap() const { return (wxBitmap&) m_background; } + const wxBitmap& GetBackgroundBitmap() const { return m_background; } bool GetUseScreen() const { return m_useScreen; } void SetUseScreen(bool useScreen) { m_useScreen = useScreen; } @@ -136,7 +136,7 @@ public: wxRect GetRect() const { return wxRect(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight()); } - wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; } + const wxBitmap& GetBitmap() const { return m_bitmap; } void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } int GetDragMethod() const { return m_dragMethod; } diff --git a/samples/propgrid/tests.cpp b/samples/propgrid/tests.cpp index cfdffeb8fd..3edada4d52 100644 --- a/samples/propgrid/tests.cpp +++ b/samples/propgrid/tests.cpp @@ -634,7 +634,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive ) pgman->SetPropertyValue("ArrayStringProperty",test_arrstr_1); wxColour emptyCol; pgman->SetPropertyValue("ColourProperty",emptyCol); - pgman->SetPropertyValue("ColourProperty",(wxObject*)wxBLACK); + pgman->SetPropertyValue("ColourProperty", const_cast(static_cast(wxBLACK))); pgman->SetPropertyValue("Size",WXVARIANT(wxSize(150,150))); pgman->SetPropertyValue("Position",WXVARIANT(wxPoint(150,150))); pgman->SetPropertyValue("MultiChoiceProperty",test_arrint_1); @@ -690,7 +690,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive ) pg->SetPropertyValue("BoolProperty",true); pg->SetPropertyValue("EnumProperty",80); pg->SetPropertyValue("ArrayStringProperty",test_arrstr_2); - pg->SetPropertyValue("ColourProperty",(wxObject*)wxWHITE); + pg->SetPropertyValue("ColourProperty", const_cast(static_cast(wxWHITE))); pg->SetPropertyValue("Size",WXVARIANT(wxSize(300,300))); pg->SetPropertyValue("Position",WXVARIANT(wxPoint(300,300))); pg->SetPropertyValue("MultiChoiceProperty",test_arrint_2); diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 309c505a95..739483fccb 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -1205,11 +1205,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_tab = new MyTextCtrl( this, 100, "Multiline, allow processing.", wxPoint(180,90), wxSize(200,70), wxTE_MULTILINE | wxTE_PROCESS_TAB ); - m_tab->SetClientData((void *)wxS("tab")); + m_tab->SetClientData(const_cast(static_cast(wxS("tab")))); m_enter = new MyTextCtrl( this, 100, "Multiline, allow processing.", wxPoint(180,170), wxSize(200,70), wxTE_MULTILINE | wxTE_PROCESS_ENTER ); - m_enter->SetClientData((void *)wxS("enter")); + m_enter->SetClientData(const_cast(static_cast(wxS("enter")))); m_textrich = new MyTextCtrl(this, wxID_ANY, "Allows more than 30Kb of text\n" "(on all Windows versions)\n" diff --git a/src/common/config.cpp b/src/common/config.cpp index c4382ef656..924ed51c86 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -140,7 +140,7 @@ wxConfigBase *wxConfigBase::Create() { \ if ( IsRecordingDefaults() ) \ { \ - ((wxConfigBase *)this)->DoWrite##name(key, defVal); \ + const_cast(this)->DoWrite##name(key, defVal);\ } \ \ *val = defVal; \ diff --git a/src/common/encconv.cpp b/src/common/encconv.cpp index a95c7f7208..b08b063682 100644 --- a/src/common/encconv.cpp +++ b/src/common/encconv.cpp @@ -80,7 +80,7 @@ extern "C" static int wxCMPFUNC_CONV CompareCharsetItems(const void *i1, const void *i2) { - return ( ((CharsetItem*)i1) -> u - ((CharsetItem*)i2) -> u ); + return static_cast(i1)->u - static_cast(i2)->u; } } diff --git a/src/common/file.cpp b/src/common/file.cpp index 9446bb32d9..717f66f334 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -479,7 +479,8 @@ wxFileOffset wxFile::Length() const wxFileOffset iLen = const_cast(this)->SeekEnd(); if ( iLen != wxInvalidOffset ) { // restore old position - if ( ((wxFile *)this)->Seek(iRc) == wxInvalidOffset ) { + if (const_cast(this)->Seek(iRc) == wxInvalidOffset) + { // error iLen = wxInvalidOffset; } diff --git a/src/common/filename.cpp b/src/common/filename.cpp index ea4597078e..474f7fa1c1 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -945,7 +945,7 @@ static wxString wxCreateTempImpl( wxCharBuffer buf(path.fn_str()); // cast is safe because the string length doesn't change - int fdTemp = mkstemp( (char*)(const char*) buf ); + int fdTemp = mkstemp(const_cast(static_cast(buf))); if ( fdTemp == -1 ) { // this might be not necessary as mkstemp() on most systems should have diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index cadf89b1e5..ab2fa540dc 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -261,7 +261,7 @@ int wxFontBase::GetPointSize() const wxSize wxFontBase::GetPixelSize() const { wxScreenDC dc; - dc.SetFont(*(wxFont *)this); + dc.SetFont(*static_cast(this)); return wxSize(dc.GetCharWidth(), dc.GetCharHeight()); } diff --git a/src/common/image.cpp b/src/common/image.cpp index 2bf29a0864..096f823f0c 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -2641,7 +2641,7 @@ bool wxImage::SaveFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename), #if HAS_FILE_STREAMS wxCHECK_MSG( IsOk(), false, wxT("invalid image") ); - ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename); + const_cast(this)->SetOption(wxIMAGE_OPTION_FILENAME, filename); wxImageFileOutputStream stream(filename); @@ -2661,7 +2661,7 @@ bool wxImage::SaveFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename), #if HAS_FILE_STREAMS wxCHECK_MSG( IsOk(), false, wxT("invalid image") ); - ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename); + const_cast(this)->SetOption(wxIMAGE_OPTION_FILENAME, filename); wxImageFileOutputStream stream(filename); diff --git a/src/common/imagiff.cpp b/src/common/imagiff.cpp index 032e1526a6..32510b799f 100644 --- a/src/common/imagiff.cpp +++ b/src/common/imagiff.cpp @@ -360,7 +360,7 @@ int wxIFFDecoder::ReadIFF() } // check if we really got an IFF file - if (strncmp((char *)dataptr, "FORM", 4) != 0) { + if (strncmp(reinterpret_cast(dataptr), "FORM", 4) != 0) { Destroy(); return wxIFF_INVFORMAT; } @@ -368,7 +368,7 @@ int wxIFFDecoder::ReadIFF() dataptr = dataptr + 8; // skip ID and length of FORM // check if the IFF file is an ILBM (picture) file - if (strncmp((char *) dataptr, "ILBM", 4) != 0) { + if (strncmp(reinterpret_cast(dataptr), "ILBM", 4) != 0) { Destroy(); return wxIFF_INVFORMAT; } @@ -394,7 +394,7 @@ int wxIFFDecoder::ReadIFF() } bool truncated = (dataptr + 8 + chunkLen > dataend); - if (strncmp((char *)dataptr, "BMHD", 4) == 0) { // BMHD chunk? + if (strncmp(reinterpret_cast(dataptr), "BMHD", 4) == 0) { // BMHD chunk? if (chunkLen < 12 + 2 || truncated) { break; } @@ -407,7 +407,7 @@ int wxIFFDecoder::ReadIFF() BMHDok = true; // got BMHD dataptr += 8 + chunkLen; // to next chunk } - else if (strncmp((char *)dataptr, "CMAP", 4) == 0) { // CMAP ? + else if (strncmp(reinterpret_cast(dataptr), "CMAP", 4) == 0) { // CMAP ? if (truncated) { break; } @@ -435,7 +435,7 @@ int wxIFFDecoder::ReadIFF() colors); dataptr += 8 + chunkLen; // to next chunk - } else if (strncmp((char *)dataptr, "CAMG", 4) == 0) { // CAMG ? + } else if (strncmp(reinterpret_cast(dataptr), "CAMG", 4) == 0) { // CAMG ? if (chunkLen < 4 || truncated) { break; } @@ -443,7 +443,7 @@ int wxIFFDecoder::ReadIFF() CAMGok = true; // got CAMG dataptr += 8 + chunkLen; // to next chunk } - else if (strncmp((char *)dataptr, "BODY", 4) == 0) { // BODY ? + else if (strncmp(reinterpret_cast(dataptr), "BODY", 4) == 0) { // BODY ? if (!BMHDok) { // BMHD found? break; } diff --git a/src/common/list.cpp b/src/common/list.cpp index 3b51fce4ff..e5a30cac4a 100644 --- a/src/common/list.cpp +++ b/src/common/list.cpp @@ -689,10 +689,10 @@ static int LINKAGEMODE wx_comparestrings(const void *arg1, const void *arg2) { - wxChar **s1 = (wxChar **) arg1; - wxChar **s2 = (wxChar **) arg2; + const wxChar* s1 = *static_cast(arg1); + const wxChar* s2 = *static_cast(arg2); - return wxStrcmp (*s1, *s2); + return wxStrcmp(s1, s2); } } // end of extern "C" (required because of GCC Bug c++/33078 diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index d665f18c20..f23aa68322 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -537,7 +537,7 @@ wxMenuItem *wxMenuBase::FindItem(int itemId, wxMenu **itemMenu) const if ( item->GetId() == itemId ) { if ( itemMenu ) - *itemMenu = (wxMenu *)this; + *itemMenu = const_cast(static_cast(this)); } else if ( item->IsSubMenu() ) { diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 7ea4d88441..8794308d95 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -349,7 +349,7 @@ void wxPrinterBase::ReportError(wxWindow *parent, wxPrintout *WXUNUSED(printout) wxPrintDialogData& wxPrinterBase::GetPrintDialogData() const { - return (wxPrintDialogData&) m_printDialogData; + return const_cast(m_printDialogData); } //---------------------------------------------------------------------------- diff --git a/src/common/selectdispatcher.cpp b/src/common/selectdispatcher.cpp index 13639392e3..6b1f98536f 100644 --- a/src/common/selectdispatcher.cpp +++ b/src/common/selectdispatcher.cpp @@ -78,7 +78,7 @@ bool wxSelectSets::HasFD(int fd) const { for ( int n = 0; n < Max; n++ ) { - if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) + if ( wxFD_ISSET(fd, const_cast(&m_fds[n])) ) return true; } @@ -113,7 +113,7 @@ bool wxSelectSets::Handle(int fd, wxFDIOHandler& handler) const { for ( int n = 0; n < Max; n++ ) { - if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) + if ( wxFD_ISSET(fd, const_cast(&m_fds[n])) ) { wxLogTrace(wxSelectDispatcher_Trace, wxT("Got %s event on fd %d"), ms_names[n], fd); diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index e839a3a0d3..ba04f3c144 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -2047,7 +2047,7 @@ wxMBConvUTF32swap::FromWChar(char *dst, size_t dstLen, #define ICONV_FAILED(cres, bufLeft) (cres == (size_t)-1) #endif -#define ICONV_CHAR_CAST(x) ((ICONV_CONST char **)(x)) +#define ICONV_CHAR_CAST(x) const_cast(x) #define ICONV_T_INVALID ((iconv_t)-1) @@ -2396,7 +2396,7 @@ size_t wxMBConv_iconv::FromWChar(char *dst, size_t dstLen, src = tmpbuf; } - char* inbuf = (char*)src; + const char* inbuf = reinterpret_cast(src); if ( dst ) { // have destination buffer, convert there @@ -2450,7 +2450,7 @@ size_t wxMBConv_iconv::GetMBNulLen() const char buf[8]; // should be enough for NUL in any encoding size_t inLen = sizeof(wchar_t), outLen = WXSIZEOF(buf); - char *inBuff = (char *)wnul; + const char* inBuff = reinterpret_cast(wnul); char *outBuff = buf; if ( iconv(w2m, ICONV_CHAR_CAST(&inBuff), &inLen, &outBuff, &outLen) == (size_t)-1 ) { diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 97ba7588e7..b5eb381ada 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -511,7 +511,7 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) { PutToBuffer(buffer, left); size -= left; - buffer = (char *)buffer + left; + buffer = static_cast(buffer) + left; if ( !FlushBuffer() ) { diff --git a/src/common/translation.cpp b/src/common/translation.cpp index 97162940ac..ee8b586fa0 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -1065,6 +1065,7 @@ private: // data description size_t32 m_numStrings; // number of strings in this domain + const wxMsgTableEntry *m_pOrigTable, // pointer to original strings *m_pTransTable; // translated @@ -1079,7 +1080,7 @@ private: : ui; } - const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 n) const + const char* StringAtOfs(const wxMsgTableEntry* pTable, size_t32 n) const { const wxMsgTableEntry * const ent = pTable + n; @@ -1155,7 +1156,7 @@ bool wxMsgCatalogFile::LoadData(const DataBuffer& data, // examine header bool bValid = data.length() > sizeof(wxMsgCatalogHeader); - const wxMsgCatalogHeader *pHeader = (wxMsgCatalogHeader *)data.data(); + const wxMsgCatalogHeader* pHeader = reinterpret_cast(data.data()); if ( bValid ) { // we'll have to swap all the integers if it's true m_bSwapped = pHeader->magic == MSGCATALOG_MAGIC_SW; @@ -1174,9 +1175,9 @@ bool wxMsgCatalogFile::LoadData(const DataBuffer& data, // initialize m_numStrings = Swap(pHeader->numStrings); - m_pOrigTable = (wxMsgTableEntry *)(data.data() + + m_pOrigTable = reinterpret_cast(data.data() + Swap(pHeader->ofsOrigTable)); - m_pTransTable = (wxMsgTableEntry *)(data.data() + + m_pTransTable = reinterpret_cast(data.data() + Swap(pHeader->ofsTransTable)); // now parse catalog's header and try to extract catalog charset and diff --git a/src/common/variant.cpp b/src/common/variant.cpp index 0362653cc8..d20e539b28 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -99,7 +99,7 @@ wxObjectRefData *wxVariant::CreateRefData() const wxObjectRefData *wxVariant::CloneRefData(const wxObjectRefData *data) const { - return ((wxVariantData*) data)->Clone(); + return static_cast(data)->Clone(); } // Assignment diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 0b744892fd..9f65f2799b 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -1768,7 +1768,7 @@ void wxWindowBase::SetPalette(const wxPalette& pal) wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const { - wxWindow *win = (wxWindow *)this; + wxWindow* win = const_cast(static_cast(this)); while ( win && !win->HasCustomPalette() ) { win = win->GetParent(); @@ -1858,7 +1858,7 @@ void wxWindowBase::ClearBackground() wxWindow *wxWindowBase::FindWindow(long id) const { if ( id == m_windowId ) - return (wxWindow *)this; + return const_cast(static_cast(this)); wxWindowBase *res = NULL; wxWindowList::compatibility_iterator node; @@ -1874,13 +1874,13 @@ wxWindow *wxWindowBase::FindWindow(long id) const res = child->FindWindow( id ); } - return (wxWindow *)res; + return static_cast(res); } wxWindow *wxWindowBase::FindWindow(const wxString& name) const { if ( name == m_windowName ) - return (wxWindow *)this; + return const_cast(static_cast(this)); wxWindowBase *res = NULL; wxWindowList::compatibility_iterator node; @@ -1895,7 +1895,7 @@ wxWindow *wxWindowBase::FindWindow(const wxString& name) const res = child->FindWindow(name); } - return (wxWindow *)res; + return static_cast(res); } @@ -1939,7 +1939,7 @@ wxWindow *wxFindWindowRecursively(const wxWindow *parent, { // see if this is the one we're looking for if ( (*cmp)(parent, label, id) ) - return (wxWindow *)parent; + return const_cast(parent); // It wasn't, so check all its children for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst(); @@ -1947,7 +1947,7 @@ wxWindow *wxFindWindowRecursively(const wxWindow *parent, node = node->GetNext() ) { // recursively check each child - wxWindow *win = (wxWindow *)node->GetData(); + wxWindow* win = static_cast(node->GetData()); wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); if (retwin) return retwin; @@ -2921,7 +2921,8 @@ wxWindowBase::ToDIP(const wxSize& sz, const wxWindowBase* w) // using them. wxSize wxWindowBase::GetDlgUnitBase() const { - const wxWindowBase* const parent = wxGetTopLevelParent((wxWindow*)this); + const wxWindowBase* const parent = + wxGetTopLevelParent(const_cast(static_cast(this))); wxCHECK_MSG( parent, wxDefaultSize, wxS("Must have TLW parent") ); @@ -3499,7 +3500,7 @@ wxWindow *wxWindowBase::DoGetSibling(WindowOrder order) const wxT("GetPrev/NextSibling() don't work for TLWs!") ); wxWindowList& siblings = GetParent()->GetChildren(); - wxWindowList::compatibility_iterator i = siblings.Find((wxWindow *)this); + wxWindowList::compatibility_iterator i = siblings.Find(this); wxCHECK_MSG( i, NULL, wxT("window not a child of its parent?") ); if ( order == OrderBefore ) diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index d6d2798ab2..f3118375d1 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -908,7 +908,7 @@ wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign) { // Then it's an error. if ( endptr ) - *endptr = (T*) nptr; + *endptr = const_cast(nptr); errno = EINVAL; return sum; } diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index 34ae8e66a4..ff39cba742 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -2639,7 +2639,7 @@ size_t wxZipOutputStream::OnSysWrite(const void *buffer, size_t size) if (m_comp->Write(buffer, size).LastWrite() != size) m_lasterror = wxSTREAM_WRITE_ERROR; - m_crcAccumulator = crc32(m_crcAccumulator, (Byte*)buffer, size); + m_crcAccumulator = crc32(m_crcAccumulator, static_cast(buffer), size); m_entrySize += m_comp->LastWrite(); return m_comp->LastWrite(); diff --git a/src/common/zstream.cpp b/src/common/zstream.cpp index 8ae6c1c466..3b2e4645e6 100644 --- a/src/common/zstream.cpp +++ b/src/common/zstream.cpp @@ -268,7 +268,7 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size) bool wxZlibInputStream::SetDictionary(const char *data, size_t datalen) { - return (inflateSetDictionary(m_inflate, (Bytef*)data, datalen) == Z_OK); + return inflateSetDictionary(m_inflate, reinterpret_cast(data), datalen) == Z_OK; } bool wxZlibInputStream::SetDictionary(const wxMemoryBuffer &buf) @@ -400,7 +400,7 @@ size_t wxZlibOutputStream::OnSysWrite(const void *buffer, size_t size) return 0; int err = Z_OK; - m_deflate->next_in = (unsigned char *)buffer; + m_deflate->next_in = const_cast(static_cast(buffer)); m_deflate->avail_in = size; while (err == Z_OK && m_deflate->avail_in > 0) { @@ -439,7 +439,7 @@ size_t wxZlibOutputStream::OnSysWrite(const void *buffer, size_t size) bool wxZlibOutputStream::SetDictionary(const char *data, size_t datalen) { - return (deflateSetDictionary(m_deflate, (Bytef*)data, datalen) == Z_OK); + return deflateSetDictionary(m_deflate, reinterpret_cast(data), datalen) == Z_OK; } bool wxZlibOutputStream::SetDictionary(const wxMemoryBuffer &buf) diff --git a/src/generic/accel.cpp b/src/generic/accel.cpp index e4382f455d..2174111161 100644 --- a/src/generic/accel.cpp +++ b/src/generic/accel.cpp @@ -213,7 +213,7 @@ wxObjectRefData *wxAcceleratorTable::CreateRefData() const wxObjectRefData *wxAcceleratorTable::CloneRefData(const wxObjectRefData *data) const { - return new wxAccelRefData(*(wxAccelRefData *)data); + return new wxAccelRefData(*static_cast(data)); } #endif // wxUSE_ACCEL diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 042f7216eb..7cf49aefa4 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3913,8 +3913,8 @@ int wxDataViewMainWindow::RecalculateCount() const { if (IsVirtualList()) { - wxDataViewVirtualListModel *list_model = - (wxDataViewVirtualListModel*) GetModel(); + const wxDataViewVirtualListModel* list_model = + static_cast(GetModel()); return list_model->GetCount(); } diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 77b50fbf99..076e535502 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -2253,13 +2253,8 @@ void wxPostScriptDCImpl::DoGetTextExtent(const wxString& string, /* JC: calculate UnderlineThickness/UnderlinePosition */ - // VS: dirty, but is there any better solution? - double *pt; - pt = (double*) &m_underlinePosition; - *pt = YLOG2DEVREL((wxCoord)(UnderlinePosition * fontSize)) / 1000.0f; - pt = (double*) &m_underlineThickness; - *pt = YLOG2DEVREL((wxCoord)(UnderlineThickness * fontSize)) / 1000.0f; - + m_underlinePosition = YLOG2DEVREL(int(UnderlinePosition * fontSize)) / 1000.0; + m_underlineThickness = YLOG2DEVREL(int(UnderlineThickness * fontSize)) / 1000.0; } diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 9899056c50..a5c6f74ca0 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1020,7 +1020,7 @@ void wxCairoPenData::Apply( wxGraphicsContext* context ) cairo_set_line_width(ctext,m_width); cairo_set_line_cap(ctext,m_cap); cairo_set_line_join(ctext,m_join); - cairo_set_dash(ctext,(double*)m_lengths,m_count,0.0); + cairo_set_dash(ctext, m_lengths, m_count, 0); } //----------------------------------------------------------------------------- @@ -1504,7 +1504,7 @@ void wxCairoMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const // returns the native representation void * wxCairoMatrixData::GetNativeMatrix() const { - return (void*) &m_matrix; + return const_cast(&m_matrix); } // ---------------------------------------------------------------------------- @@ -1954,7 +1954,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& cairo_t* cr = static_cast(dc.GetImpl()->GetCairoContext()); Init(cr ? cairo_reference(cr) : NULL); #elif defined __WXGTK20__ - wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); + const wxGTKDCImpl* impldc = static_cast(dc.GetImpl()); Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); // Transfer transformation settings from source DC to Cairo context on our own. @@ -2167,7 +2167,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& cairo_t* cr = static_cast(dc.GetImpl()->GetCairoContext()); Init(cr ? cairo_reference(cr) : NULL); #elif defined __WXGTK20__ - wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); + const wxGTKDCImpl* impldc = static_cast(dc.GetImpl()); Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); // Transfer transformation settings from source DC to Cairo context on our own. diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index c1dbb96548..047c6f95f2 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -7025,7 +7025,7 @@ bool wxGrid::IsCellEditControlShown() const int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); wxGridCellAttr* attr = GetCellAttr(row, col); - wxGridCellEditor* editor = attr->GetEditor((wxGrid*) this, row, col); + wxGridCellEditor* editor = attr->GetEditor(this, row, col); attr->DecRef(); if ( editor ) @@ -8743,7 +8743,7 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const wxGridCellAttr *wxGrid::GetOrCreateCellAttr(int row, int col) const { wxGridCellAttr *attr = NULL; - bool canHave = ((wxGrid*)this)->CanHaveAttributes(); + const bool canHave = CanHaveAttributes(); wxCHECK_MSG( canHave, attr, wxT("Cell attributes not allowed")); wxCHECK_MSG( m_table, attr, wxT("must have a table") ); diff --git a/src/generic/hyperlinkg.cpp b/src/generic/hyperlinkg.cpp index 133a9371d6..9788fc2422 100644 --- a/src/generic/hyperlinkg.cpp +++ b/src/generic/hyperlinkg.cpp @@ -125,7 +125,7 @@ void wxGenericHyperlinkCtrl::ConnectMenuHandlers() wxSize wxGenericHyperlinkCtrl::DoGetBestClientSize() const { - wxClientDC dc((wxWindow *)this); + wxClientDC dc(const_cast(this)); return dc.GetTextExtent(GetLabel()); } diff --git a/src/generic/icon.cpp b/src/generic/icon.cpp index 53b1c80fee..f7aebe6654 100644 --- a/src/generic/icon.cpp +++ b/src/generic/icon.cpp @@ -41,6 +41,6 @@ wxIcon::wxIcon() : wxBitmap() void wxIcon::CopyFromBitmap(const wxBitmap& bmp) { - wxIcon *icon = (wxIcon*)(&bmp); + const wxIcon* icon = static_cast(&bmp); *this = *icon; } diff --git a/src/gtk/assertdlg_gtk.cpp b/src/gtk/assertdlg_gtk.cpp index b7d90a5f93..a2dbadca85 100644 --- a/src/gtk/assertdlg_gtk.cpp +++ b/src/gtk/assertdlg_gtk.cpp @@ -711,7 +711,7 @@ static void gtk_assert_dialog_init(GTypeInstance* instance, void*) /* icon */ wxGCC_WARNING_SUPPRESS(deprecated-declarations) - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); + image = gtk_image_new_from_stock("gtk-dialog-error", GTK_ICON_SIZE_DIALOG); wxGCC_WARNING_RESTORE() gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 12); @@ -768,15 +768,11 @@ static void gtk_assert_dialog_init(GTypeInstance* instance, void*) gtk_button_box_set_layout (GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); /* add the buttons */ - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - button = gtk_assert_dialog_add_button_to (GTK_BOX(hbox), "Save to _file", GTK_STOCK_SAVE); - wxGCC_WARNING_RESTORE() + button = gtk_assert_dialog_add_button_to(GTK_BOX(hbox), "Save to _file", "gtk-save"); g_signal_connect (button, "clicked", G_CALLBACK(gtk_assert_dialog_save_backtrace_callback), dlg); - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - button = gtk_assert_dialog_add_button_to (GTK_BOX(hbox), "Copy to clip_board", GTK_STOCK_COPY); - wxGCC_WARNING_RESTORE() + button = gtk_assert_dialog_add_button_to(GTK_BOX(hbox), "Copy to clip_board", "gtk-copy"); g_signal_connect (button, "clicked", G_CALLBACK(gtk_assert_dialog_copy_callback), dlg); } #endif // wxUSE_STACKWALKER @@ -789,14 +785,10 @@ static void gtk_assert_dialog_init(GTypeInstance* instance, void*) wxGCC_WARNING_RESTORE() /* add the stop button */ - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - gtk_assert_dialog_add_button (dlg, "_Stop", GTK_STOCK_QUIT, GTK_ASSERT_DIALOG_STOP); - wxGCC_WARNING_RESTORE() + gtk_assert_dialog_add_button(dlg, "_Stop", "gtk-quit", GTK_ASSERT_DIALOG_STOP); /* add the continue button */ - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - continuebtn = gtk_assert_dialog_add_button (dlg, "_Continue", GTK_STOCK_YES, GTK_ASSERT_DIALOG_CONTINUE); - wxGCC_WARNING_RESTORE() + continuebtn = gtk_assert_dialog_add_button(dlg, "_Continue", "gtk-yes", GTK_ASSERT_DIALOG_CONTINUE); gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_ASSERT_DIALOG_CONTINUE); g_signal_connect (continuebtn, "clicked", G_CALLBACK(gtk_assert_dialog_continue_callback), dlg); diff --git a/src/gtk/brush.cpp b/src/gtk/brush.cpp index a903929e4d..d4fe907597 100644 --- a/src/gtk/brush.cpp +++ b/src/gtk/brush.cpp @@ -87,7 +87,7 @@ wxGDIRefData *wxBrush::CreateGDIRefData() const wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxBrushRefData(*(wxBrushRefData *)data); + return new wxBrushRefData(*static_cast(data)); } bool wxBrush::operator==(const wxBrush& brush) const diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index 012aa24b44..71e4bd52f9 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -184,7 +184,7 @@ wxSize wxButtonBase::GetDefaultSize(wxWindow* WXUNUSED(win)) GtkWidget *btn = gtk_button_new_with_mnemonic(labelGTK.utf8_str()); #else wxGCC_WARNING_SUPPRESS(deprecated-declarations) - GtkWidget *btn = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + GtkWidget* btn = gtk_button_new_from_stock("gtk-cancel"); wxGCC_WARNING_RESTORE() #endif gtk_container_add(GTK_CONTAINER(box), btn); diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index b1daebc085..6d6aad79f6 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -160,7 +160,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget), clip.GetId().c_str() ); // the atoms we received, holding a list of targets (= formats) - const GdkAtom* const atoms = (GdkAtom*)gtk_selection_data_get_data(selection_data); + const GdkAtom* const atoms = reinterpret_cast(gtk_selection_data_get_data(selection_data)); for (size_t i = 0; i < selection_data_length / sizeof(GdkAtom); i++) { const wxDataFormat format(atoms[i]); @@ -406,7 +406,7 @@ async_targets_selection_received( GtkWidget *WXUNUSED(widget), clip.GetId().c_str() ); // the atoms we received, holding a list of targets (= formats) - const GdkAtom* const atoms = (GdkAtom*)gtk_selection_data_get_data(selection_data); + const GdkAtom* const atoms = reinterpret_cast(gtk_selection_data_get_data(selection_data)); for (size_t i = 0; i < selection_data_length / sizeof(GdkAtom); i++) { const wxDataFormat format(atoms[i]); diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index d879b2f9e0..fed357b468 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -745,7 +745,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset } if (m_gdkwindow) - gdk_draw_lines( m_gdkwindow, m_penGC, (GdkPoint*) gpts, n); + gdk_draw_lines(m_gdkwindow, m_penGC, const_cast(gpts), n); delete[] gpts_alloc; } @@ -791,7 +791,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], bool originChanged; DrawingSetup(gc, originChanged); - gdk_draw_polygon(m_gdkwindow, gc, true, (GdkPoint*) gdkpoints, n); + gdk_draw_polygon(m_gdkwindow, gc, true, const_cast(gdkpoints), n); if (originChanged) gdk_gc_set_ts_origin(gc, 0, 0); @@ -809,7 +809,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], gdkpoints[(i+1)%n].y); } */ - gdk_draw_polygon( m_gdkwindow, m_penGC, FALSE, (GdkPoint*) gdkpoints, n ); + gdk_draw_polygon(m_gdkwindow, m_penGC, false, const_cast(gdkpoints), n); } } diff --git a/src/gtk/dirdlg.cpp b/src/gtk/dirdlg.cpp index 3514cc406e..005771a54e 100644 --- a/src/gtk/dirdlg.cpp +++ b/src/gtk/dirdlg.cpp @@ -85,9 +85,6 @@ bool wxDirDialog::Create(wxWindow* parent, if (parent) gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) ); -#ifndef __WXGTK4__ - wxGCC_WARNING_SUPPRESS(deprecated-declarations) -#endif m_widget = gtk_file_chooser_dialog_new( wxGTK_CONV(m_message), gtk_parent, @@ -95,19 +92,17 @@ bool wxDirDialog::Create(wxWindow* parent, #ifdef __WXGTK4__ static_cast(wxGTK_CONV(wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_CANCEL)))), #else - GTK_STOCK_CANCEL, + "gtk-cancel", #endif GTK_RESPONSE_CANCEL, #ifdef __WXGTK4__ static_cast(wxGTK_CONV(wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_OPEN)))), #else - GTK_STOCK_OPEN, + "gtk-open", #endif GTK_RESPONSE_ACCEPT, NULL); -#ifndef __WXGTK4__ - wxGCC_WARNING_RESTORE() -#endif + g_object_ref(m_widget); gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT); diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index 9f5ae2beb9..9439f4b58a 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -213,9 +213,6 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message, if (parent) gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) ); -#ifndef __WXGTK4__ - wxGCC_WARNING_SUPPRESS(deprecated-declarations) -#endif wxString ok_btn_stock; if ( style & wxFD_SAVE ) { @@ -223,7 +220,7 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message, #ifdef __WXGTK4__ ok_btn_stock = wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_SAVE)); #else - ok_btn_stock = GTK_STOCK_SAVE; + ok_btn_stock = "gtk-save"; #endif } else @@ -232,7 +229,7 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message, #ifdef __WXGTK4__ ok_btn_stock = wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_OPEN)); #else - ok_btn_stock = GTK_STOCK_OPEN; + ok_btn_stock = "gtk-open"; #endif } @@ -243,14 +240,12 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message, #ifdef __WXGTK4__ static_cast(wxGTK_CONV(wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_CANCEL)))), #else - GTK_STOCK_CANCEL, + "gtk-cancel", #endif GTK_RESPONSE_CANCEL, static_cast(wxGTK_CONV(ok_btn_stock)), GTK_RESPONSE_ACCEPT, NULL); -#ifndef __WXGTK4__ - wxGCC_WARNING_RESTORE() -#endif + g_object_ref(m_widget); GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget); diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index fc7ebaa6ba..7fa4a4eee9 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -1349,6 +1349,7 @@ wxGetGtkAccel(const wxMenuItem* item, guint* accel_key, GdkModifierType* accel_m #ifndef __WXGTK4__ wxGCC_WARNING_SUPPRESS(deprecated-declarations) +wxGCC_WARNING_SUPPRESS(cast-qual) const char *wxGetStockGtkID(wxWindowID id) { #define STOCKITEM(wx,gtk) \ @@ -1451,6 +1452,7 @@ const char *wxGetStockGtkID(wxWindowID id) return NULL; } +wxGCC_WARNING_RESTORE(cast-qual) wxGCC_WARNING_RESTORE() #endif // !__WXGTK4__ diff --git a/src/gtk/msgdlg.cpp b/src/gtk/msgdlg.cpp index 25d67009f8..033f857e35 100644 --- a/src/gtk/msgdlg.cpp +++ b/src/gtk/msgdlg.cpp @@ -52,9 +52,7 @@ wxString wxMessageDialog::GetDefaultYesLabel() const #ifdef __WXGTK4__ return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_YES)); #else - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - return GTK_STOCK_YES; - wxGCC_WARNING_RESTORE() + return "gtk-yes"; #endif } @@ -63,9 +61,7 @@ wxString wxMessageDialog::GetDefaultNoLabel() const #ifdef __WXGTK4__ return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_NO)); #else - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - return GTK_STOCK_NO; - wxGCC_WARNING_RESTORE() + return "gtk-no"; #endif } @@ -74,9 +70,7 @@ wxString wxMessageDialog::GetDefaultOKLabel() const #ifdef __WXGTK4__ return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_OK)); #else - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - return GTK_STOCK_OK; - wxGCC_WARNING_RESTORE() + return "gtk-ok"; #endif } @@ -85,9 +79,7 @@ wxString wxMessageDialog::GetDefaultCancelLabel() const #ifdef __WXGTK4__ return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_CANCEL)); #else - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - return GTK_STOCK_CANCEL; - wxGCC_WARNING_RESTORE() + return "gtk-cancel"; #endif } @@ -96,9 +88,7 @@ wxString wxMessageDialog::GetDefaultHelpLabel() const #ifdef __WXGTK4__ return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_HELP)); #else - wxGCC_WARNING_SUPPRESS(deprecated-declarations) - return GTK_STOCK_HELP; - wxGCC_WARNING_RESTORE() + return "gtk-help"; #endif } diff --git a/src/gtk/pen.cpp b/src/gtk/pen.cpp index e47aa44818..1fe4c90fe1 100644 --- a/src/gtk/pen.cpp +++ b/src/gtk/pen.cpp @@ -127,7 +127,7 @@ wxGDIRefData *wxPen::CreateGDIRefData() const wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxPenRefData(*(wxPenRefData *)data); + return new wxPenRefData(*static_cast(data)); } bool wxPen::operator == ( const wxPen& pen ) const @@ -193,7 +193,7 @@ int wxPen::GetDashes( wxDash **ptr ) const { wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") ); - *ptr = (wxDash*)M_PENDATA->m_dash; + *ptr = const_cast(M_PENDATA->m_dash); return M_PENDATA->m_countDashes; } @@ -208,7 +208,7 @@ wxDash* wxPen::GetDash() const { wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") ); - return (wxDash*)M_PENDATA->m_dash; + return const_cast(M_PENDATA->m_dash); } wxPenCap wxPen::GetCap() const diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index 56f86fb1f0..dd0066b449 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -188,13 +188,13 @@ void wxSpinButton::DoEnable(bool enable) void wxSpinButton::GtkDisableEvents() const { g_signal_handlers_block_by_func(m_widget, - (gpointer)gtk_value_changed, (void*) this); + (void*)gtk_value_changed, const_cast(this)); } void wxSpinButton::GtkEnableEvents() const { g_signal_handlers_unblock_by_func(m_widget, - (gpointer)gtk_value_changed, (void*) this); + (void*)gtk_value_changed, const_cast(this)); } GdkWindow *wxSpinButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED_IN_GTK2(windows)) const diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index a341b79752..150a6284ec 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -291,22 +291,16 @@ void wxSpinCtrlGTKBase::DoSetIncrement(double inc) gtk_spin_button_set_increments( GTK_SPIN_BUTTON(m_widget), inc, page); } -void wxSpinCtrlGTKBase::GtkDisableEvents() const +void wxSpinCtrlGTKBase::GtkDisableEvents() { - g_signal_handlers_block_by_func( m_widget, - (gpointer)gtk_value_changed, (void*) this); - - g_signal_handlers_block_by_func(m_widget, - (gpointer)gtk_changed, (void*) this); + g_signal_handlers_block_by_func(m_widget, (void*)gtk_value_changed, this); + g_signal_handlers_block_by_func(m_widget, (void*)gtk_changed, this); } -void wxSpinCtrlGTKBase::GtkEnableEvents() const +void wxSpinCtrlGTKBase::GtkEnableEvents() { - g_signal_handlers_unblock_by_func(m_widget, - (gpointer)gtk_value_changed, (void*) this); - - g_signal_handlers_unblock_by_func(m_widget, - (gpointer)gtk_changed, (void*) this); + g_signal_handlers_unblock_by_func(m_widget, (void*)gtk_value_changed, this); + g_signal_handlers_unblock_by_func(m_widget, (void*)gtk_changed, this); } void wxSpinCtrlGTKBase::OnChar( wxKeyEvent &event ) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 675d597a42..aa1411fb08 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -66,7 +66,7 @@ wxGtkTextRemoveTagsWithPrefix(GtkTextBuffer *text_buffer, text_buffer, "remove_tag", G_CALLBACK(wxGtkOnRemoveTag), - gpointer(prefix) + const_cast(static_cast(prefix)) ); gtk_text_buffer_remove_all_tags(text_buffer, start, end); g_signal_handler_disconnect(text_buffer, remove_handler_id); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index ee6e7db6d6..f771bbad11 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -5182,7 +5182,7 @@ void wxWindowGTK::GTKSendPaintEvents(const GdkRegion* region) GTK_SHADOW_NONE, &rect, parent->m_widget, - (char *)"base", + const_cast("base"), 0, 0, w, h); #endif // !__WXGTK3__ } diff --git a/src/html/helpwnd.cpp b/src/html/helpwnd.cpp index aa1d9d8ed7..1a896be108 100644 --- a/src/html/helpwnd.cpp +++ b/src/html/helpwnd.cpp @@ -877,7 +877,7 @@ bool wxHtmlHelpWindow::KeywordSearch(const wxString& keyword, #if wxUSE_PROGRESSDLG progress.Update(status.GetCurIndex(), foundstr); #endif - m_SearchList->Append(status.GetName(), (void*)status.GetCurItem()); + m_SearchList->Append(status.GetName(), const_cast(status.GetCurItem())); } } diff --git a/src/html/htmlpars.cpp b/src/html/htmlpars.cpp index ac04fcd7b6..84b5971a6b 100644 --- a/src/html/htmlpars.cpp +++ b/src/html/htmlpars.cpp @@ -543,9 +543,9 @@ extern "C" { static int LINKAGEMODE wxHtmlEntityCompare(const void *key, const void *item) { #if wxUSE_UNICODE_UTF8 - return strcmp((char*)key, ((wxHtmlEntityInfo*)item)->name); + return strcmp(static_cast(key), static_cast(item)->name); #else - return wxStrcmp((wxChar*)key, ((wxHtmlEntityInfo*)item)->name); + return wxStrcmp(static_cast(key), static_cast(item)->name); #endif } } diff --git a/src/html/htmltag.cpp b/src/html/htmltag.cpp index 3d17acfee9..6c5fc0b02d 100644 --- a/src/html/htmltag.cpp +++ b/src/html/htmltag.cpp @@ -662,7 +662,7 @@ wxHtmlTag *wxHtmlTag::GetFirstSibling() const return m_Parent->m_FirstChild; else { - wxHtmlTag *cur = (wxHtmlTag*)this; + wxHtmlTag* cur = const_cast(this); while (cur->m_Prev) cur = cur->m_Prev; return cur; @@ -675,7 +675,7 @@ wxHtmlTag *wxHtmlTag::GetLastSibling() const return m_Parent->m_LastChild; else { - wxHtmlTag *cur = (wxHtmlTag*)this; + wxHtmlTag* cur = const_cast(this); while (cur->m_Next) cur = cur->m_Next; return cur; diff --git a/src/html/m_image.cpp b/src/html/m_image.cpp index 2685a80cd4..2d67921074 100644 --- a/src/html/m_image.cpp +++ b/src/html/m_image.cpp @@ -269,7 +269,7 @@ const wxHtmlCell *wxHtmlImageMapCell::Find( int cond, const void *param ) const { if (cond == wxHTML_COND_ISIMAGEMAP) { - if (m_Name == *((wxString*)(param))) + if (m_Name == *static_cast(param)) return this; } return wxHtmlCell::Find(cond, param); @@ -331,8 +331,8 @@ private: size_t m_nCurrFrame; #endif double m_scale; - wxHtmlImageMapCell *m_imageMap; - wxString m_mapName; + mutable const wxHtmlImageMapCell* m_imageMap; + mutable wxString m_mapName; wxString m_alt; wxDECLARE_NO_COPY_CLASS(wxHtmlImageCell); @@ -655,18 +655,14 @@ wxHtmlLinkInfo *wxHtmlImageCell::GetLink( int x, int y ) const p = p->GetParent(); } p = op; - wxHtmlCell *cell = (wxHtmlCell*)p->Find(wxHTML_COND_ISIMAGEMAP, + const wxHtmlCell* cell = p->Find(wxHTML_COND_ISIMAGEMAP, (const void*)(&m_mapName)); if (!cell) { - ((wxString&)m_mapName).Clear(); + m_mapName.Clear(); return wxHtmlCell::GetLink( x, y ); } - { // dirty hack, ask Joel why he fills m_ImageMap in this place - // THE problem is that we're in const method and we can't modify m_ImageMap - wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_imageMap); - *cx = (wxHtmlImageMapCell*)cell; - } + m_imageMap = static_cast(cell); } return m_imageMap->GetLink(x, y); } diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 85be5b4877..6e9209baa1 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -989,7 +989,7 @@ void wxMSWDCImpl::DoDrawPolygon(int n, CalcBoundingBox(points[i].x, points[i].y); int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); - (void)Polygon(GetHdc(), (POINT*) points, n); + Polygon(GetHdc(), reinterpret_cast(points), n); SetPolyFillMode(GetHdc(),prev); } } @@ -1029,7 +1029,7 @@ wxMSWDCImpl::DoDrawPolyPolygon(int n, CalcBoundingBox(points[i].x, points[i].y); int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); - (void)PolyPolygon(GetHdc(), (POINT*) points, count, n); + PolyPolygon(GetHdc(), reinterpret_cast(points), count, n); SetPolyFillMode(GetHdc(),prev); } } @@ -1057,7 +1057,7 @@ void wxMSWDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset, wx for (i = 0; i < n; i++) CalcBoundingBox(points[i].x, points[i].y); - (void)Polyline(GetHdc(), (POINT*) points, n); + Polyline(GetHdc(), reinterpret_cast(points), n); } } diff --git a/src/msw/dde.cpp b/src/msw/dde.cpp index 0b5cc4b287..9382b4c2ce 100644 --- a/src/msw/dde.cpp +++ b/src/msw/dde.cpp @@ -565,7 +565,7 @@ wxDDEConnection::DoExecute(const void *data, size_t size, wxIPCFormat format) } else // no conversion necessary for wxIPC_UNICODETEXT { - realData = (LPBYTE)data; + realData = const_cast(static_cast(data)); realSize = size; } @@ -689,7 +689,7 @@ bool wxDDEConnection::DoPoke(const wxString& item, const void *data, size_t size DWORD result; HSZ item_atom = DDEGetAtom(item); - bool ok = DdeClientTransaction((LPBYTE)data, + bool ok = DdeClientTransaction(const_cast(static_cast(data)), size, GetHConv(), item_atom, format, @@ -952,7 +952,7 @@ _DDECallback(UINT wType, } HDDEDATA handle = DdeCreateDataHandle(DDEIdInst, - (LPBYTE)data, + const_cast(static_cast(data)), user_size, 0, hsz2, @@ -1035,7 +1035,7 @@ _DDECallback(UINT wType, HDDEDATA data = DdeCreateDataHandle ( DDEIdInst, - (LPBYTE)connection->m_sendingData, + const_cast(static_cast(connection->m_sendingData)), connection->m_dataSize, 0, hsz2, diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index 0850c7eca6..3854dcb293 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -348,7 +348,7 @@ HBITMAP wxDIB::CreateDDB(HDC hdc) const } /* static */ -HBITMAP wxDIB::ConvertToBitmap(const BITMAPINFO *pbmi, HDC hdc, void *bits) +HBITMAP wxDIB::ConvertToBitmap(const BITMAPINFO *pbmi, HDC hdc, const void *bits) { wxCHECK_MSG( pbmi, 0, wxT("invalid DIB in ConvertToBitmap") ); @@ -389,7 +389,7 @@ HBITMAP wxDIB::ConvertToBitmap(const BITMAPINFO *pbmi, HDC hdc, void *bits) numColors = 0; } - bits = (char *)pbmih + sizeof(*pbmih) + numColors*sizeof(RGBQUAD); + bits = reinterpret_cast(pbmih + 1) + numColors * sizeof(RGBQUAD); } HBITMAP hbmp = ::CreateDIBitmap diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index b0b9ed84d9..dbd567889b 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -292,7 +292,7 @@ int wxDirDialog::ShowSHBrowseForFolder(WXHWND owner) // do show the dialog wxItemIdList pidl(SHBrowseForFolder(&bi)); - wxItemIdList::Free((LPITEMIDLIST)bi.pidlRoot); + wxItemIdList::Free(const_cast(bi.pidlRoot)); if ( !pidl ) { diff --git a/src/msw/enhmeta.cpp b/src/msw/enhmeta.cpp index bd08a76206..a6a06ccd93 100644 --- a/src/msw/enhmeta.cpp +++ b/src/msw/enhmeta.cpp @@ -480,7 +480,7 @@ bool wxEnhMetaFileDataObject::SetData(const wxDataFormat& format, if ( format == wxDF_ENHMETAFILE ) { - hEMF = *(HENHMETAFILE *)buf; + hEMF = *static_cast(buf); wxCHECK_MSG( hEMF, false, wxT("pasting invalid enh metafile") ); } @@ -555,7 +555,7 @@ bool wxEnhMetaFileSimpleDataObject::GetDataHere(void *buf) const bool wxEnhMetaFileSimpleDataObject::SetData(size_t WXUNUSED(len), const void *buf) { - HENHMETAFILE hEMF = *(HENHMETAFILE *)buf; + HENHMETAFILE hEMF = *static_cast(buf); wxCHECK_MSG( hEMF, false, wxT("pasting invalid enh metafile") ); m_metafile.SetHENHMETAFILE((WXHANDLE)hEMF); diff --git a/src/msw/imaglist.cpp b/src/msw/imaglist.cpp index b710efaac8..12c2705ff1 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -411,7 +411,7 @@ wxBitmap wxImageList::GetBitmap(int index) const if ( ii.hbmMask ) { // draw it the first time to find a suitable mask colour - ((wxImageList*)this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT); + const_cast(this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT); dc.SelectObject(wxNullBitmap); // find the suitable mask colour @@ -426,7 +426,7 @@ wxBitmap wxImageList::GetBitmap(int index) const // redraw icon over the mask colour to actually draw it dc.SelectObject(bitmap); - ((wxImageList*)this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT); + const_cast(this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT); dc.SelectObject(wxNullBitmap); // get the image, set the mask colour and convert back to get transparent bitmap @@ -437,7 +437,7 @@ wxBitmap wxImageList::GetBitmap(int index) const else // no mask { // Just draw it normally. - ((wxImageList*)this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL); + const_cast(this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL); dc.SelectObject(wxNullBitmap); // And adjust its alpha flag as the destination bitmap would get it if diff --git a/src/msw/mediactrl_qt.cpp b/src/msw/mediactrl_qt.cpp index 65948e9635..eaa9b4fe44 100644 --- a/src/msw/mediactrl_qt.cpp +++ b/src/msw/mediactrl_qt.cpp @@ -695,7 +695,7 @@ bool wxQTMediaBackend::Load(const wxString& fileName) FSSpec sfFile; OSErr err = m_lib.NativePathNameToFSSpec( - (char*) (const char*) fileName.mb_str(), + const_cast(static_cast(fileName.mb_str())), &sfFile, 0); bool result = (err == noErr); diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 7f0565225b..40a8ba8b01 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -1225,7 +1225,7 @@ wxColour wxNotebook::GetThemeBackgroundColour() const #if wxUSE_UXTHEME if (wxUxThemeIsActive()) { - wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB"); + wxUxThemeHandle hTheme(this, L"TAB"); if (hTheme) { // This is total guesswork. diff --git a/src/msw/ole/activex.cpp b/src/msw/ole/activex.cpp index ca7ad6bfae..a707456c3f 100644 --- a/src/msw/ole/activex.cpp +++ b/src/msw/ole/activex.cpp @@ -768,7 +768,7 @@ namespace const int invalid_entry_marker = 0; } -wxVariant wxActiveXEvents::ms_invalidEntryMarker((void*)&invalid_entry_marker); +wxVariant wxActiveXEvents::ms_invalidEntryMarker(static_cast(&invalid_entry_marker)); size_t wxActiveXEvent::ParamCount() const { diff --git a/src/msw/ole/automtn.cpp b/src/msw/ole/automtn.cpp index 4d091c5285..1b30be2e88 100644 --- a/src/msw/ole/automtn.cpp +++ b/src/msw/ole/automtn.cpp @@ -567,7 +567,7 @@ bool wxAutomationObject::GetInstance(const wxString& progId, int flags) const return false; } - hr = pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &m_dispatchPtr); + hr = pUnk->QueryInterface(IID_IDispatch, const_cast(&m_dispatchPtr)); if (FAILED(hr)) { wxLogSysError(hr, diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index e052521521..d03d4277c6 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -1114,7 +1114,7 @@ bool wxBitmapDataObject2::GetDataHere(void *pBuf) const bool wxBitmapDataObject2::SetData(size_t WXUNUSED(len), const void *pBuf) { - HBITMAP hbmp = *(HBITMAP *)pBuf; + HBITMAP hbmp = *static_cast(pBuf); BITMAP bmp; if ( !GetObject(hbmp, sizeof(BITMAP), &bmp) ) @@ -1273,7 +1273,7 @@ bool wxFileDataObject::SetData(size_t WXUNUSED(size), // ((char *)&(pDropFiles.pFiles)) + pDropFiles.pFiles. We're also advised // to use DragQueryFile to work with this structure, but not told where and // how to get HDROP. - HDROP hdrop = (HDROP)pData; // NB: it works, but I'm not sure about it + HDROP hdrop = static_cast(const_cast(pData)); // NB: it works, but I'm not sure about it // get number of files (magic value -1) UINT nFiles = ::DragQueryFile(hdrop, (unsigned)-1, NULL, 0u); diff --git a/src/msw/ole/uuid.cpp b/src/msw/ole/uuid.cpp index 3bafbba898..6c08eb4540 100644 --- a/src/msw/ole/uuid.cpp +++ b/src/msw/ole/uuid.cpp @@ -138,7 +138,7 @@ bool Uuid::Set(const wxChar *pc) { // get UUID from string #ifdef _UNICODE - if ( UuidFromString((unsigned short *)pc, &m_uuid) != RPC_S_OK) + if (UuidFromString(reinterpret_cast(const_cast(pc)), &m_uuid) != RPC_S_OK) #else if ( UuidFromString((wxUChar *)pc, &m_uuid) != RPC_S_OK) #endif diff --git a/src/msw/progdlg.cpp b/src/msw/progdlg.cpp index 34b7704e85..d4b4e19634 100644 --- a/src/msw/progdlg.cpp +++ b/src/msw/progdlg.cpp @@ -442,7 +442,7 @@ wxProgressDialog::~wxProgressDialog() DWORD rc = ::MsgWaitForMultipleObjects ( 1, // number of objects to wait for - (HANDLE *)&hThread, // the objects + &hThread, // the objects false, // wait for any objects, not all INFINITE, // no timeout QS_ALLINPUT | // return as soon as there are any events diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 7ef36a9840..b42edb7be8 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -481,11 +481,11 @@ size_t wxRegConfig::GetNumberOfEntries(bool WXUNUSED(bRecursive)) const // dummy vars wxString str; long l; - bool bCont = ((wxRegConfig*)this)->GetFirstEntry(str, l); + bool bCont = GetFirstEntry(str, l); while ( bCont ) { nEntries++; - bCont = ((wxRegConfig*)this)->GetNextEntry(str, l); + bCont = GetNextEntry(str, l); } return nEntries; @@ -498,11 +498,11 @@ size_t wxRegConfig::GetNumberOfGroups(bool WXUNUSED(bRecursive)) const // dummy vars wxString str; long l; - bool bCont = ((wxRegConfig*)this)->GetFirstGroup(str, l); + bool bCont = GetFirstGroup(str, l); while ( bCont ) { nGroups++; - bCont = ((wxRegConfig*)this)->GetNextGroup(str, l); + bCont = GetNextGroup(str, l); } return nGroups; diff --git a/src/msw/region.cpp b/src/msw/region.cpp index 8766364efe..4bd19571cf 100644 --- a/src/msw/region.cpp +++ b/src/msw/region.cpp @@ -135,7 +135,7 @@ wxRegion::wxRegion(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle) m_refData = new wxRegionRefData; M_REGION = ::CreatePolygonRgn ( - (POINT*)points, + reinterpret_cast(points), n, fillStyle == wxODDEVEN_RULE ? ALTERNATE : WINDING ); @@ -153,7 +153,7 @@ wxGDIRefData *wxRegion::CreateGDIRefData() const wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { - return new wxRegionRefData(*(wxRegionRefData *)data); + return new wxRegionRefData(*static_cast(data)); } // ---------------------------------------------------------------------------- diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index bc5e1d273c..b24af19b33 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -87,11 +87,7 @@ aStdKeys[] = // macros // ---------------------------------------------------------------------------- -// const_cast<> is not yet supported by all compilers -#define CONST_CAST ((wxRegKey *)this)-> - -// and neither is mutable which m_dwLastError should be -#define m_dwLastError CONST_CAST m_dwLastError +#define CONST_CAST const_cast(this)-> // ---------------------------------------------------------------------------- // non member functions @@ -1071,7 +1067,7 @@ bool wxRegKey::SetValue(const wxString& szValue, const wxString& strValue) m_dwLastError = RegSetValueEx((HKEY) m_hKey, RegValueStr(szValue), (DWORD) RESERVED, REG_SZ, - (RegString)wxMSW_CONV_LPCTSTR(strValue), + reinterpret_cast(wxMSW_CONV_LPCTSTR(strValue)), (strValue.Len() + 1)*sizeof(wxChar)); if ( m_dwLastError == ERROR_SUCCESS ) return true; diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 0a7de130e2..2ede920e8b 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -401,7 +401,7 @@ bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, m_hWnd = (WXHWND)::CreateDialogIndirect ( wxGetInstance(), - (DLGTEMPLATE*)dlgTemplate, + static_cast(dlgTemplate), parent ? GetHwndOf(parent) : NULL, (DLGPROC)wxDlgProc ); diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 74a3a596c3..4059e6b726 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -812,9 +812,9 @@ bool wxShell(const wxString& command) { wxString cmd; - wxChar *shell = wxGetenv(wxT("COMSPEC")); + const wxChar* shell = wxGetenv(wxT("COMSPEC")); if ( !shell ) - shell = (wxChar*) wxT("\\COMMAND.COM"); + shell = wxT("\\COMMAND.COM"); if ( !command ) { diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp index 60841d8edd..446c16f859 100644 --- a/src/msw/utilsexc.cpp +++ b/src/msw/utilsexc.cpp @@ -520,7 +520,7 @@ size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len) if ( !chunkWritten ) break; - buffer = (char *)buffer + chunkWritten; + buffer = static_cast(buffer) + chunkWritten; totalWritten += chunkWritten; len -= chunkWritten; } diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index 8504b4c609..0797596629 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -638,7 +638,7 @@ wxSize wxFont::GetPixelSize() const #if wxUSE_GRAPHICS_CONTEXT // TODO: consider caching the value wxGraphicsContext* dc = wxGraphicsContext::CreateFromNative((CGContextRef)NULL); - dc->SetFont(*(wxFont*)this, *wxBLACK); + dc->SetFont(*this, *wxBLACK); wxDouble width, height = 0; dc->GetTextExtent(wxT("g"), &width, &height, NULL, NULL); delete dc; diff --git a/src/osx/carbon/metafile.cpp b/src/osx/carbon/metafile.cpp index 685e627124..89b34f0b9c 100644 --- a/src/osx/carbon/metafile.cpp +++ b/src/osx/carbon/metafile.cpp @@ -187,7 +187,8 @@ wxMetaFile::CloneGDIRefData(const wxGDIRefData * WXUNUSED(data)) const WXHMETAFILE wxMetaFile::GetHMETAFILE() const { - return (WXHMETAFILE) (CFDataRef) M_METAFILEDATA->GetData(); + const void* p = M_METAFILEDATA->GetData(); + return static_cast(const_cast(p)); } bool wxMetaFile::SetClipboard(int WXUNUSED(width), int WXUNUSED(height)) @@ -340,7 +341,7 @@ bool wxMetafileDataObject::GetDataHere(void *buf) const bool wxMetafileDataObject::SetData(size_t len, const void *buf) { - wxMetafileRefData* metafiledata = new wxMetafileRefData(wxCFRefFromGet(wxCFDataRef((UInt8*)buf, len).get())); + wxMetafileRefData* metafiledata = new wxMetafileRefData(wxCFRefFromGet(wxCFDataRef(static_cast(buf), len).get())); m_metafile.UnRef(); m_metafile.SetRefData( metafiledata ); return true; diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 550fc9c6d1..127db0e16e 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -173,7 +173,7 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy) : wxGDIRefData() UseAlpha(true); unsigned char* dest = (unsigned char*)GetRawAccess(); - unsigned char* source = (unsigned char*)tocopy.GetRawAccess(); + const unsigned char* source = static_cast(tocopy.GetRawAccess()); size_t numbytes = GetBytesPerRow() * GetHeight(); memcpy( dest, source, numbytes ); } @@ -780,7 +780,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits if ( the_width % 8 ) linesize++; - unsigned char* linestart = (unsigned char*) bits ; + const unsigned char* linestart = reinterpret_cast(bits); unsigned char* destptr = (unsigned char*) GetBitmapData()->BeginRawAccess() ; for ( int y = 0 ; y < the_height ; ++y , linestart += linesize, destptr += GetBitmapData()->GetBytesPerRow() ) @@ -949,7 +949,7 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const int destheight = rect.height*scale ; { - unsigned char *sourcedata = (unsigned char*) GetBitmapData()->GetRawAccess() ; + const unsigned char* sourcedata = static_cast(GetBitmapData()->GetRawAccess()); unsigned char *destdata = (unsigned char*) ret.GetBitmapData()->BeginRawAccess() ; wxASSERT((sourcedata != NULL) && (destdata != NULL)); @@ -957,7 +957,7 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const { int sourcelinesize = GetBitmapData()->GetBytesPerRow() ; int destlinesize = ret.GetBitmapData()->GetBytesPerRow() ; - unsigned char* source = sourcedata + size_t(rect.x * scale) * 4 + size_t(rect.y * scale) * sourcelinesize; + const unsigned char* source = sourcedata + size_t(rect.x * scale) * 4 + size_t(rect.y * scale) * sourcelinesize; unsigned char* dest = destdata; for (int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize) @@ -1199,7 +1199,7 @@ wxImage wxBitmap::ConvertToImage() const // this call may trigger a conversion from platform image to bitmap, issue it // before any measurements are taken, multi-resolution platform images may be // rendered incorrectly otherwise - unsigned char* sourcestart = (unsigned char*) GetBitmapData()->GetRawAccess() ; + const unsigned char* sourcestart = static_cast(GetBitmapData()->GetRawAccess()); // create an wxImage object int width = GetWidth(); @@ -1244,7 +1244,7 @@ wxImage wxBitmap::ConvertToImage() const for (int yy = 0; yy < height; yy++ , sourcestart += GetBitmapData()->GetBytesPerRow() , mask += maskBytesPerRow ) { unsigned char * maskp = mask ; - const wxUint32 * source = (wxUint32*)sourcestart; + const wxUint32* source = reinterpret_cast(sourcestart); for (int xx = 0; xx < width; xx++) { diff --git a/src/osx/core/display.cpp b/src/osx/core/display.cpp index 395ef7a8c2..796a7ef7cb 100644 --- a/src/osx/core/display.cpp +++ b/src/osx/core/display.cpp @@ -292,7 +292,7 @@ wxArrayVideoModes wxDisplayImplMacOSX::GetModes(const wxVideoMode& mode) const for (CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) { - CGDisplayModeRef theValue = (CGDisplayModeRef) CFArrayGetValueAtIndex( theArray, i ); + CGDisplayModeRef theValue = static_cast(const_cast(CFArrayGetValueAtIndex(theArray, i))); wxVideoMode theMode( CGDisplayModeGetWidth(theValue), @@ -336,7 +336,7 @@ bool wxDisplayImplMacOSX::ChangeMode( const wxVideoMode& mode ) for (CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) { - CGDisplayModeRef theValue = (CGDisplayModeRef) CFArrayGetValueAtIndex( theArray, i ); + CGDisplayModeRef theValue = static_cast(const_cast(CFArrayGetValueAtIndex(theArray, i))); wxVideoMode theMode( CGDisplayModeGetWidth(theValue), diff --git a/src/osx/core/printmac.cpp b/src/osx/core/printmac.cpp index 0fe3214fc9..cb4879bc8b 100644 --- a/src/osx/core/printmac.cpp +++ b/src/osx/core/printmac.cpp @@ -130,7 +130,7 @@ void wxOSXPrintData::TransferPrinterNameFrom( const wxPrintData &data ) count = CFArrayGetCount(printerList); for (index = 0; index < count; index++) { - printer = (PMPrinter)CFArrayGetValueAtIndex(printerList, index); + printer = static_cast(const_cast(CFArrayGetValueAtIndex(printerList, index))); if ((data.GetPrinterName().empty()) && (PMPrinterIsDefault(printer))) break; @@ -184,7 +184,7 @@ void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data ) CFIndex top = CFArrayGetCount(paperlist); for ( CFIndex i = 0 ; i < top ; ++ i ) { - PMPaper paper = (PMPaper) CFArrayGetValueAtIndex( paperlist, i ); + PMPaper paper = static_cast(const_cast(CFArrayGetValueAtIndex(paperlist, i))); PMPaperGetHeight(paper, &height); PMPaperGetWidth(paper, &width); if ( fabs( width - papersize.x ) < 5 && diff --git a/src/osx/core/strconv_cf.cpp b/src/osx/core/strconv_cf.cpp index 4870533a50..18f232bdbe 100644 --- a/src/osx/core/strconv_cf.cpp +++ b/src/osx/core/strconv_cf.cpp @@ -183,7 +183,7 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_cf(wxFontEncoding encoding) { theString = wxCFRef(CFStringCreateWithBytes( kCFAllocatorDefault, - (UInt8*)src, + reinterpret_cast(src), srcSize * sizeof(wchar_t), wxCFStringEncodingWcharT, false)); diff --git a/src/osx/fswatcher_fsevents.cpp b/src/osx/fswatcher_fsevents.cpp index dbf6e457bd..2d5573c256 100644 --- a/src/osx/fswatcher_fsevents.cpp +++ b/src/osx/fswatcher_fsevents.cpp @@ -269,7 +269,7 @@ static void wxFSEventCallback(ConstFSEventStreamRef WXUNUSED(streamRef), void *c static void wxDeleteContext(const void* context) { wxFSEventWatcherContext* watcherContext = - (wxFSEventWatcherContext*) context; + static_cast(const_cast(context)); delete watcherContext; } diff --git a/src/osx/pen.cpp b/src/osx/pen.cpp index 3a485a6f9d..171a4263b6 100644 --- a/src/osx/pen.cpp +++ b/src/osx/pen.cpp @@ -274,7 +274,7 @@ void wxPen::SetDashes(int nb_dashes, const wxDash *Dash) Unshare(); M_PENDATA->m_nbDash = nb_dashes; - M_PENDATA->m_dash = (wxDash *)Dash; + M_PENDATA->m_dash = const_cast(Dash); RealizeResource(); } diff --git a/src/osx/utils_osx.cpp b/src/osx/utils_osx.cpp index 0b43c1fef9..4de0607d62 100644 --- a/src/osx/utils_osx.cpp +++ b/src/osx/utils_osx.cpp @@ -195,7 +195,7 @@ void wxMacStringToPascal( const wxString&from , unsigned char * to ) wxString wxMacMakeStringFromPascal( const unsigned char * from ) { - return wxString( (char*) &from[1] , wxConvLocal , from[0] ); + return wxString(&from[1], wxConvLocal, from[0]); } #endif // wxOSX_USE_COCOA_OR_CARBON diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 51686ffd13..4eaa5a907c 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -1853,7 +1853,7 @@ void wxWindowMac::Update() wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const { - wxWindowMac *iter = (wxWindowMac*)this ; + wxWindowMac* iter = const_cast(this); while ( iter ) { diff --git a/src/propgrid/editors.cpp b/src/propgrid/editors.cpp index 4fe4cacceb..4bf316f028 100644 --- a/src/propgrid/editors.cpp +++ b/src/propgrid/editors.cpp @@ -637,7 +637,8 @@ public: } else { - pg->OnComboItemPaint( this, item, &dc, (wxRect&)rect, flags ); + wxRect r(rect); + pg->OnComboItemPaint(this, item, &dc, r, flags); } } diff --git a/src/propgrid/manager.cpp b/src/propgrid/manager.cpp index 60a7613ce6..b0a4c4b366 100644 --- a/src/propgrid/manager.cpp +++ b/src/propgrid/manager.cpp @@ -2201,7 +2201,7 @@ private: wxPGVIterator wxPropertyGridManager::GetVIterator( int flags ) const { - return wxPGVIterator( new wxPGVIteratorBase_Manager( (wxPropertyGridManager*)this, flags ) ); + return wxPGVIterator(new wxPGVIteratorBase_Manager(const_cast(this), flags)); } #endif // wxUSE_PROPGRID diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index f6a9699103..7898c75b7e 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -1936,7 +1936,7 @@ void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect, // Hopefully this does not cause problems. #if (wxPG_USE_RENDERER_NATIVE) wxRendererNative::Get().DrawTreeItemButton( - (wxWindow*)this, + const_cast(this), dc, r, wxCONTROL_EXPANDED @@ -1952,7 +1952,7 @@ void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect, { #if (wxPG_USE_RENDERER_NATIVE) wxRendererNative::Get().DrawTreeItemButton( - (wxWindow*)this, + const_cast(this), dc, r, 0 diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 99bccbefea..e8c937b5aa 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -432,7 +432,7 @@ wxPropertyCategory* wxPropertyGridPageState::GetPropertyCategory( const wxPGProp parent = grandparent; grandparent = parent->GetParent(); if ( parent->IsCategory() && grandparent ) - return (wxPropertyCategory*)parent; + return const_cast(static_cast(parent)); } while ( grandparent ); return NULL; @@ -451,11 +451,11 @@ wxPGProperty* wxPropertyGridPageState::GetPropertyByLabel #endif // WXWIN_COMPATIBILITY_3_0 wxPGProperty* wxPropertyGridPageState::BaseGetPropertyByLabel - ( const wxString& label, wxPGProperty* parent ) const + ( const wxString& label, const wxPGProperty* parent ) const { if ( !parent ) { - parent = (wxPGProperty*) &m_regularArray; + parent = &m_regularArray; } for ( size_t i=0; iGetChildCount(); i++ ) diff --git a/src/ribbon/panel.cpp b/src/ribbon/panel.cpp index dc97dac68c..2f222e8b88 100644 --- a/src/ribbon/panel.cpp +++ b/src/ribbon/panel.cpp @@ -352,7 +352,7 @@ wxSize wxRibbonPanel::GetBestSizeForParentSize(const wxSize& parentSize) const wxRibbonControl* control = wxDynamicCast(win, wxRibbonControl); if (control) { - wxClientDC temp_dc((wxRibbonPanel*) this); + wxClientDC temp_dc(const_cast(this)); wxSize clientParentSize = m_art->GetPanelClientSize(temp_dc, this, parentSize, NULL); wxSize childSize = control->GetBestSizeForParentSize(clientParentSize); wxSize overallSize = m_art->GetPanelSize(temp_dc, this, childSize, NULL); @@ -374,7 +374,7 @@ wxSize wxRibbonPanel::DoGetNextSmallerSize(wxOrientation direction, if(m_art != NULL) { - wxClientDC dc((wxRibbonPanel*) this); + wxClientDC dc(const_cast(this)); wxSize child_relative = m_art->GetPanelClientSize(dc, this, relative_to, NULL); wxSize smaller(-1, -1); bool minimise = false; @@ -495,7 +495,7 @@ wxSize wxRibbonPanel::DoGetNextLargerSize(wxOrientation direction, if(m_art != NULL) { - wxClientDC dc((wxRibbonPanel*) this); + wxClientDC dc(const_cast(this)); wxSize child_relative = m_art->GetPanelClientSize(dc, this, relative_to, NULL); wxSize larger(-1, -1); @@ -587,14 +587,14 @@ wxSize wxRibbonPanel::GetMinNotMinimisedSize() const // Ask sizer if present if(GetSizer()) { - wxClientDC dc((wxRibbonPanel*) this); + wxClientDC dc(const_cast(this)); return m_art->GetPanelSize(dc, this, GetPanelSizerMinSize(), NULL); } else if(GetChildren().GetCount() == 1) { // Common case of single child taking up the entire panel wxWindow* child = GetChildren().Item(0)->GetData(); - wxClientDC dc((wxRibbonPanel*) this); + wxClientDC dc(const_cast(this)); return m_art->GetPanelSize(dc, this, child->GetMinSize(), NULL); } @@ -615,7 +615,7 @@ wxSize wxRibbonPanel::GetPanelSizerMinSize() const return GetSizer()->CalcMin(); } // else use previously calculated m_smallest_unminimised_size - wxClientDC dc((wxRibbonPanel*) this); + wxClientDC dc(const_cast(this)); return m_art->GetPanelClientSize(dc, this, m_smallest_unminimised_size, @@ -636,14 +636,14 @@ wxSize wxRibbonPanel::DoGetBestSize() const // Ask sizer if present if( GetSizer()) { - wxClientDC dc((wxRibbonPanel*) this); + wxClientDC dc(const_cast(this)); return m_art->GetPanelSize(dc, this, GetPanelSizerBestSize(), NULL); } else if(GetChildren().GetCount() == 1) { // Common case of no sizer and single child taking up the entire panel wxWindow* child = GetChildren().Item(0)->GetData(); - wxClientDC dc((wxRibbonPanel*) this); + wxClientDC dc(const_cast(this)); return m_art->GetPanelSize(dc, this, child->GetBestSize(), NULL); } diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 0c77999338..de5e1c982b 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -613,7 +613,7 @@ wxRect wxRichTextObject::GetAvailableContentArea(wxDC& dc, wxRichTextDrawingCont wxRect marginRect, borderRect, contentRect, paddingRect, outlineRect; marginRect = outerRect; wxRichTextAttr attr(GetAttributes()); - ((wxRichTextObject*)this)->AdjustAttributes(attr, context); + const_cast(this)->AdjustAttributes(attr, context); GetBoxRects(dc, GetBuffer(), attr, marginRect, borderRect, contentRect, paddingRect, outlineRect); return contentRect; } @@ -7177,7 +7177,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz int relativeX = position.x - GetParent()->GetPosition().x; wxRichTextAttr textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes()); - ((wxRichTextObject*) this)->AdjustAttributes(textAttr, context); + const_cast(this)->AdjustAttributes(textAttr, context); // Always assume unformatted text, since at this level we have no knowledge // of line breaks - and we don't need it, since we'll calculate size within @@ -7251,7 +7251,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz for (int i = 0; i < tabCount; ++i) { int pos = tabArray[i]; - pos = ((wxRichTextPlainText*) this)->ConvertTenthsMMToPixels(dc, pos); + pos = const_cast(this)->ConvertTenthsMMToPixels(dc, pos); tabArray[i] = pos; } @@ -7305,7 +7305,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz { if (nextTabPos <= absoluteWidth) { - int defaultTabWidth = ((wxRichTextPlainText*) this)->ConvertTenthsMMToPixels(dc, WIDTH_FOR_DEFAULT_TABS); + int defaultTabWidth = const_cast(this)->ConvertTenthsMMToPixels(dc, WIDTH_FOR_DEFAULT_TABS); nextTabPos = absoluteWidth + defaultTabWidth; } @@ -7452,16 +7452,16 @@ bool wxRichTextPlainText::CanMerge(wxRichTextObject* object, wxRichTextDrawingCo // Check if differing virtual attributes makes it impossible to merge // these strings. - bool hasVirtualAttr1 = context.HasVirtualAttributes((wxRichTextObject*) this); - bool hasVirtualAttr2 = context.HasVirtualAttributes((wxRichTextObject*) object); + bool hasVirtualAttr1 = context.HasVirtualAttributes(const_cast(this)); + bool hasVirtualAttr2 = context.HasVirtualAttributes(object); if (!hasVirtualAttr1 && !hasVirtualAttr2) return true; else if (hasVirtualAttr1 != hasVirtualAttr2) return false; else { - wxRichTextAttr virtualAttr1 = context.GetVirtualAttributes((wxRichTextObject*) this); - wxRichTextAttr virtualAttr2 = context.GetVirtualAttributes((wxRichTextObject*) object); + wxRichTextAttr virtualAttr1 = context.GetVirtualAttributes(const_cast(this)); + wxRichTextAttr virtualAttr2 = context.GetVirtualAttributes(object); return virtualAttr1 == virtualAttr2; } } @@ -7489,7 +7489,7 @@ bool wxRichTextPlainText::CanSplit(wxRichTextDrawingContext& context) const // If this object has any virtual attributes at all, whether for the whole object // or individual ones, we should try splitting it by calling Split. // Must be more than one character in order to be able to split. - return m_text.Length() > 1 && context.HasVirtualAttributes((wxRichTextObject*) this); + return m_text.Length() > 1 && context.HasVirtualAttributes(const_cast(this)); } wxRichTextObject* wxRichTextPlainText::Split(wxRichTextDrawingContext& context) @@ -9440,13 +9440,13 @@ bool wxRichTextField::GetRangeSize(const wxRichTextRange& range, wxSize& size, i { wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType()); if (fieldType) - return fieldType->GetRangeSize((wxRichTextField*) this, range, size, descent, dc, context, flags, position, parentSize, partialExtents); + return fieldType->GetRangeSize(const_cast(this), range, size, descent, dc, context, flags, position, parentSize, partialExtents); // Fallback so unknown fields don't become invisible. wxString fieldTypeStr(GetFieldType()); wxRichTextFieldTypeStandard defaultFieldType; defaultFieldType.SetLabel(wxString::Format(wxT("unknown field %s"), fieldTypeStr.c_str())); - return defaultFieldType.GetRangeSize((wxRichTextField*) this, range, size, descent, dc, context, flags, position, parentSize, partialExtents); + return defaultFieldType.GetRangeSize(const_cast(this), range, size, descent, dc, context, flags, position, parentSize, partialExtents); } /// Calculate range @@ -9480,7 +9480,7 @@ bool wxRichTextField::CanEditProperties() const { wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType()); if (fieldType) - return fieldType->CanEditProperties((wxRichTextField*) this); + return fieldType->CanEditProperties(const_cast(this)); return false; } @@ -9489,7 +9489,7 @@ wxString wxRichTextField::GetPropertiesMenuLabel() const { wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType()); if (fieldType) - return fieldType->GetPropertiesMenuLabel((wxRichTextField*) this); + return fieldType->GetPropertiesMenuLabel(const_cast(this)); return wxEmptyString; } @@ -9507,7 +9507,7 @@ bool wxRichTextField::IsTopLevel() const { wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType()); if (fieldType) - return fieldType->IsTopLevel((wxRichTextField*) this); + return fieldType->IsTopLevel(const_cast(this)); return true; } @@ -11130,7 +11130,7 @@ wxRichTextCell* wxRichTextTable::GetCell(int row, int col) const wxRichTextSelection wxRichTextTable::GetSelection(long start, long end) const { wxRichTextSelection selection; - selection.SetContainer((wxRichTextTable*) this); + selection.SetContainer(const_cast(this)); if (start > end) { @@ -12815,7 +12815,7 @@ bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, i return false; wxSize imageSize; - if (!((wxRichTextImage*)this)->LoadImageCache(dc, context, imageSize, false, parentSize)) + if (!const_cast(this)->LoadImageCache(dc, context, imageSize, false, parentSize)) { size.x = 0; size.y = 0; if (partialExtents) @@ -12824,7 +12824,7 @@ bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, i } wxRichTextAttr attr(GetAttributes()); - ((wxRichTextObject*)this)->AdjustAttributes(attr, context); + const_cast(this)->AdjustAttributes(attr, context); wxRect marginRect, borderRect, contentRect, paddingRect, outlineRect; contentRect = wxRect(wxPoint(0,0), imageSize); diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 2af028ed7b..003dd761f3 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -3239,8 +3239,8 @@ wxTextCtrlHitTestResult wxRichTextCtrl::HitTest(const wxPoint& pt, long * pos) const { - wxClientDC dc((wxRichTextCtrl*) this); - ((wxRichTextCtrl*)this)->PrepareDC(dc); + wxClientDC dc(const_cast(this)); + const_cast(this)->PrepareDC(dc); // Buffer uses logical position (relative to start of buffer) // so convert @@ -3248,8 +3248,8 @@ wxRichTextCtrl::HitTest(const wxPoint& pt, wxRichTextObject* hitObj = NULL; wxRichTextObject* contextObj = NULL; - wxRichTextDrawingContext context((wxRichTextBuffer*) & GetBuffer()); - int hit = ((wxRichTextCtrl*)this)->GetFocusObject()->HitTest(dc, context, pt2, *pos, & hitObj, & contextObj, wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS); + wxRichTextDrawingContext context(const_cast(&GetBuffer())); + int hit = const_cast(this)->GetFocusObject()->HitTest(dc, context, pt2, *pos, &hitObj, &contextObj, wxRICHTEXT_HITTEST_NO_NESTED_OBJECTS); if ((hit & wxRICHTEXT_HITTEST_BEFORE) && (hit & wxRICHTEXT_HITTEST_OUTSIDE)) return wxTE_HT_BEFORE; diff --git a/src/richtext/richtextstyles.cpp b/src/richtext/richtextstyles.cpp index 8e8c2a6fc5..80fb8f2a66 100644 --- a/src/richtext/richtextstyles.cpp +++ b/src/richtext/richtextstyles.cpp @@ -71,7 +71,7 @@ wxRichTextAttr wxRichTextStyleDefinition::GetStyleMergedWithBase(const wxRichTex const wxRichTextStyleDefinition* def = this; while (def) { - styles.Insert((wxObject*) def); + styles.Insert(const_cast(def)); styleNames.Add(def->GetName()); wxString baseStyleName = def->GetBaseStyle(); @@ -756,7 +756,7 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons if (attr.GetLeftIndent() > 0) { - wxClientDC dc((wxWindow*) this); + wxClientDC dc(const_cast(this)); str << wxT(""); } diff --git a/src/unix/dialup.cpp b/src/unix/dialup.cpp index 1a00d15463..277c4ff9f9 100644 --- a/src/unix/dialup.cpp +++ b/src/unix/dialup.cpp @@ -420,7 +420,7 @@ void wxDialUpManagerImpl::CheckStatus(bool fromAsync) const // which is OS - specific and then sends the events. NetConnection oldIsOnline = m_IsOnline; - ( /* non-const */ (wxDialUpManagerImpl *)this)->CheckStatusInternal(); + const_cast(this)->CheckStatusInternal(); // now send the events as appropriate: i.e. if the status changed and // if we're in defined state diff --git a/src/unix/fontenum.cpp b/src/unix/fontenum.cpp index a396c94c05..01d4a61a75 100644 --- a/src/unix/fontenum.cpp +++ b/src/unix/fontenum.cpp @@ -50,8 +50,10 @@ extern "C" static int wxCMPFUNC_CONV wxCompareFamilies (const void *a, const void *b) { - const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a); - const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b); + const PangoFontFamily* fam_a = *static_cast(a); + const PangoFontFamily* fam_b = *static_cast(b); + const char* a_name = pango_font_family_get_name(const_cast(fam_a)); + const char* b_name = pango_font_family_get_name(const_cast(fam_b)); return g_utf8_collate (a_name, b_name); } diff --git a/src/unix/glx11.cpp b/src/unix/glx11.cpp index cc6e8c3c8f..e3f87feef8 100644 --- a/src/unix/glx11.cpp +++ b/src/unix/glx11.cpp @@ -502,7 +502,7 @@ wxGLContext::wxGLContext(wxGLCanvas *win, if (fbc) { wx_glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) - glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB"); + glXGetProcAddress(reinterpret_cast("glXCreateContextAttribsARB")); } glXDestroyContext( dpy, tempContext ); diff --git a/src/unix/mediactrl_gstplayer.cpp b/src/unix/mediactrl_gstplayer.cpp index 6566dd4010..d82599e102 100644 --- a/src/unix/mediactrl_gstplayer.cpp +++ b/src/unix/mediactrl_gstplayer.cpp @@ -15,8 +15,6 @@ #include "wx/mediactrl.h" -#include // main gstreamer player header - #ifndef WX_PRECOMP #include "wx/log.h" // wxLogDebug/wxLogSysError/wxLogTrace #include "wx/app.h" // wxTheApp->argc, wxTheApp->argv @@ -32,6 +30,10 @@ #include #endif +wxGCC_WARNING_SUPPRESS(cast-qual) +#include // main gstreamer player header +wxGCC_WARNING_RESTORE() + //============================================================================= // Declarations //============================================================================= diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 7f619f6048..97bcd199cb 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -61,7 +61,7 @@ public: size_t size = file.Length(); wxCharBuffer buffer( size ); - file.Read( (void*) (const char*) buffer, size ); + file.Read(buffer.data(), size); // Check for valid UTF-8 here? wxString all = wxString::FromUTF8( buffer, size ); diff --git a/src/unix/sound.cpp b/src/unix/sound.cpp index 355fc8673d..41825cb284 100644 --- a/src/unix/sound.cpp +++ b/src/unix/sound.cpp @@ -717,7 +717,7 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData) memcpy(m_data->m_dataWithHeader, data, length); } else - m_data->m_dataWithHeader = (wxUint8*)data; + m_data->m_dataWithHeader = const_cast(data); m_data->m_data = (&m_data->m_dataWithHeader[FMT_INDEX + waveformat.uiSize + 8]); diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index 0e54c0a83b..256ef53919 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -1462,7 +1462,7 @@ void wxThread::SetPriority(unsigned int prio) unsigned int wxThread::GetPriority() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + wxCriticalSectionLocker lock(m_critsect); return m_internal->GetPriority(); } @@ -1765,14 +1765,14 @@ wxThread::~wxThread() bool wxThread::IsRunning() const { - wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + wxCriticalSectionLocker lock(m_critsect); return m_internal->GetState() == STATE_RUNNING; } bool wxThread::IsAlive() const { - wxCriticalSectionLocker lock((wxCriticalSection&)m_critsect); + wxCriticalSectionLocker lock(m_critsect); switch ( m_internal->GetState() ) { @@ -1787,7 +1787,7 @@ bool wxThread::IsAlive() const bool wxThread::IsPaused() const { - wxCriticalSectionLocker lock((wxCriticalSection&)m_critsect); + wxCriticalSectionLocker lock(m_critsect); return (m_internal->GetState() == STATE_PAUSED); } diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 9681cc6354..709fcad43b 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -1265,7 +1265,7 @@ bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspace #if defined(HAVE_STATFS) || defined(HAVE_STATVFS) // the case to "char *" is needed for AIX 4.3 wxStatfs_t fs; - if ( wxStatfs((char *)(const char*)path.fn_str(), &fs) != 0 ) + if ( wxStatfs(const_cast(static_cast(path.fn_str())), &fs) != 0 ) { wxLogSysError( wxT("Failed to get file system statistics") ); diff --git a/tests/mbconv/mbconvtest.cpp b/tests/mbconv/mbconvtest.cpp index ae192bf0a4..0b151cd43f 100644 --- a/tests/mbconv/mbconvtest.cpp +++ b/tests/mbconv/mbconvtest.cpp @@ -259,7 +259,7 @@ void MBConvTestCase::WC2CP1250() // it's very useful when debugging a failed test. wxString CByteArrayFormat( const void* data, size_t len, const wxChar* name ) { - const unsigned char* bytes = (unsigned char*)data; + const unsigned char* bytes = static_cast(data); wxString result; result.Printf( wxT("static const unsigned char %s[%i] = \n{"), name, (int)len ); diff --git a/tests/strings/unicode.cpp b/tests/strings/unicode.cpp index 7fb69b4728..79b3092943 100644 --- a/tests/strings/unicode.cpp +++ b/tests/strings/unicode.cpp @@ -199,8 +199,8 @@ void UnicodeTestCase::ConstructorsWithConversion() // the string "Déjà" in UTF-8 and wchar_t: const unsigned char utf8Buf[] = {0x44,0xC3,0xA9,0x6A,0xC3,0xA0,0}; const unsigned char utf8subBuf[] = {0x44,0xC3,0xA9,0x6A,0}; // just "Déj" - const char *utf8 = (char *)utf8Buf; - const char *utf8sub = (char *)utf8subBuf; + const char* utf8 = reinterpret_cast(utf8Buf); + const char* utf8sub = reinterpret_cast(utf8subBuf); wxString s1(utf8, wxConvUTF8);