[Libreoffice-commits] core.git: Branch 'feature/vclref' - 2 commits - compilerplugins/clang dbaccess/source extensions/source include/vcl sd/source vcl/source
Noel Grandin
noel at peralex.com
Wed Jan 7 00:43:59 PST 2015
compilerplugins/clang/vclwidgets.cxx | 87 ++++++++++++++++++----
dbaccess/source/ui/control/curledit.cxx | 4 -
extensions/source/propctrlr/standardcontrol.cxx | 2
include/vcl/spinfld.hxx | 4 -
include/vcl/vclptr.hxx | 7 +
sd/source/ui/animations/CustomAnimationDialog.cxx | 18 ++--
vcl/source/control/combobox.cxx | 4 -
vcl/source/control/spinfld.cxx | 14 ++-
vcl/source/window/builder.cxx | 4 -
vcl/source/window/dialog.cxx | 4 -
vcl/source/window/layout.cxx | 20 ++---
11 files changed, 122 insertions(+), 46 deletions(-)
New commits:
commit db1f038526dc4b448d8b3d00290b395faeb9e56e
Author: Noel Grandin <noel at peralex.com>
Date: Wed Jan 7 10:42:07 2015 +0200
vcl: make VclPtr<T>(T*) constructor explicit
to make it obvious in the code when we are translating between the
reference-counted type and raw pointers, since that is the danger-point
Change-Id: I32822432325fa34969e78cccf937e2ccbe1bfb70
diff --git a/dbaccess/source/ui/control/curledit.cxx b/dbaccess/source/ui/control/curledit.cxx
index 4924df6..446f0f9 100644
--- a/dbaccess/source/ui/control/curledit.cxx
+++ b/dbaccess/source/ui/control/curledit.cxx
@@ -40,7 +40,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeConnectionURLEdit(vcl:
OConnectionURLEdit::~OConnectionURLEdit()
{
- SetSubEdit(NULL);
+ SetSubEdit(VclPtr<Edit>());
delete m_pForcedPrefix;
}
@@ -68,7 +68,7 @@ void OConnectionURLEdit::SetText(const OUString& _rStr, const Selection& /*_rNew
{
// create new sub controls, if necessary
if (!GetSubEdit())
- SetSubEdit(EditRef(new Edit(this, 0)));
+ SetSubEdit(VclPtr<Edit>(new Edit(this, 0)));
if ( !m_pForcedPrefix )
{
m_pForcedPrefix = new FixedText(this, WB_VCENTER);
diff --git a/extensions/source/propctrlr/standardcontrol.cxx b/extensions/source/propctrlr/standardcontrol.cxx
index 071ea12..cf3e753 100644
--- a/extensions/source/propctrlr/standardcontrol.cxx
+++ b/extensions/source/propctrlr/standardcontrol.cxx
@@ -1032,7 +1032,7 @@ namespace pcr
SetCompoundControl( true );
m_pImplEdit = VclPtr<MultiLineEdit>( new MultiLineEdit( this, WB_TABSTOP | WB_IGNORETAB | WB_NOBORDER | (_nStyle & WB_READONLY) ) );
- SetSubEdit( m_pImplEdit.get() );
+ SetSubEdit( m_pImplEdit );
m_pImplEdit->Show();
if ( _nStyle & WB_DROPDOWN )
diff --git a/include/vcl/spinfld.hxx b/include/vcl/spinfld.hxx
index fe5431b..493dcf8 100644
--- a/include/vcl/spinfld.hxx
+++ b/include/vcl/spinfld.hxx
@@ -32,7 +32,7 @@
class VCL_DLLPUBLIC SpinField : public Edit
{
protected:
- Edit* mpEdit;
+ VclPtr<Edit> mpEdit;
AutoTimer maRepeatTimer;
Rectangle maUpperRect;
Rectangle maLowerRect;
@@ -69,6 +69,8 @@ protected:
virtual void FillLayoutData() const SAL_OVERRIDE;
Rectangle * ImplFindPartRect( const Point& rPt );
+ virtual void dispose() SAL_OVERRIDE;
+
public:
explicit SpinField( vcl::Window* pParent, WinBits nWinStyle = 0 );
explicit SpinField( vcl::Window* pParent, const ResId& );
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx
index 5aa0c69..c32dbcc 100644
--- a/include/vcl/vclptr.hxx
+++ b/include/vcl/vclptr.hxx
@@ -88,7 +88,7 @@ public:
/** Constructor...
*/
- inline VclPtr (reference_type * pBody)
+ explicit inline VclPtr (reference_type * pBody)
: m_rInnerRef(pBody)
{}
@@ -131,6 +131,11 @@ public:
return m_rInnerRef.get();
}
+ inline void SAL_CALL set(reference_type *pBody)
+ {
+ m_rInnerRef.set(pBody);
+ }
+
inline SAL_CALL operator reference_type * () const
{
return m_rInnerRef.get();
diff --git a/sd/source/ui/animations/CustomAnimationDialog.cxx b/sd/source/ui/animations/CustomAnimationDialog.cxx
index a96334a..1feeba4 100644
--- a/sd/source/ui/animations/CustomAnimationDialog.cxx
+++ b/sd/source/ui/animations/CustomAnimationDialog.cxx
@@ -412,13 +412,13 @@ private:
CharHeightPropertyBox::CharHeightPropertyBox( sal_Int32 nControlType, vcl::Window* pParent, const Any& rValue, const Link& rModifyHdl )
: PropertySubControl( nControlType )
{
- mpMetric = new MetricField( pParent, WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER);
+ mpMetric.set( new MetricField( pParent, WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER) );
mpMetric->SetUnit( FUNIT_PERCENT );
mpMetric->SetMin( 0 );
mpMetric->SetMax( 1000 );
mpMenu = new PopupMenu(SdResId( RID_CUSTOMANIMATION_FONTSIZE_POPUP ) );
- mpControl = new DropdownMenuBox( pParent, mpMetric.get(), mpMenu );
+ mpControl = new DropdownMenuBox( pParent, mpMetric, mpMenu );
mpControl->SetMenuSelectHdl( LINK( this, CharHeightPropertyBox, implMenuSelectHdl ));
mpControl->SetModifyHdl( rModifyHdl );
mpControl->SetHelpId( HID_SD_CUSTOMANIMATIONPANE_CHARHEIGHTPROPERTYBOX );
@@ -494,7 +494,7 @@ TransparencyPropertyBox::TransparencyPropertyBox( sal_Int32 nControlType, vcl::W
: PropertySubControl( nControlType )
, maModifyHdl( rModifyHdl )
{
- mpMetric = new MetricField( pParent ,WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER);
+ mpMetric.set( new MetricField( pParent ,WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER) );
mpMetric->SetUnit( FUNIT_PERCENT );
mpMetric->SetMin( 0 );
mpMetric->SetMax( 100 );
@@ -507,7 +507,7 @@ TransparencyPropertyBox::TransparencyPropertyBox( sal_Int32 nControlType, vcl::W
mpMenu->InsertItem( i, aStr );
}
- mpControl = new DropdownMenuBox( pParent, mpMetric.get(), mpMenu );
+ mpControl = new DropdownMenuBox( pParent, mpMetric, mpMenu );
mpControl->SetMenuSelectHdl( LINK( this, TransparencyPropertyBox, implMenuSelectHdl ));
mpControl->SetHelpId( HID_SD_CUSTOMANIMATIONPANE_TRANSPARENCYPROPERTYBOX );
@@ -598,14 +598,14 @@ RotationPropertyBox::RotationPropertyBox( sal_Int32 nControlType, vcl::Window* p
: PropertySubControl( nControlType )
, maModifyHdl( rModifyHdl )
{
- mpMetric = new MetricField( pParent ,WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER);
+ mpMetric.set( new MetricField( pParent ,WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER) );
mpMetric->SetUnit( FUNIT_CUSTOM );
mpMetric->SetCustomUnitText( OUString( sal_Unicode(0xb0)) ); // degree sign
mpMetric->SetMin( -10000 );
mpMetric->SetMax( 10000 );
mpMenu = new PopupMenu(SdResId( RID_CUSTOMANIMATION_ROTATION_POPUP ) );
- mpControl = new DropdownMenuBox( pParent, mpMetric.get(), mpMenu );
+ mpControl = new DropdownMenuBox( pParent, mpMetric, mpMenu );
mpControl->SetMenuSelectHdl( LINK( this, RotationPropertyBox, implMenuSelectHdl ));
mpControl->SetHelpId( HID_SD_CUSTOMANIMATIONPANE_ROTATIONPROPERTYBOX );
@@ -724,13 +724,13 @@ ScalePropertyBox::ScalePropertyBox( sal_Int32 nControlType, vcl::Window* pParent
: PropertySubControl( nControlType )
, maModifyHdl( rModifyHdl )
{
- mpMetric = new MetricField( pParent ,WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER);
+ mpMetric.set( new MetricField( pParent ,WB_TABSTOP|WB_IGNORETAB| WB_NOBORDER) );
mpMetric->SetUnit( FUNIT_PERCENT );
mpMetric->SetMin( 0 );
mpMetric->SetMax( 10000 );
mpMenu = new PopupMenu(SdResId( RID_CUSTOMANIMATION_SCALE_POPUP ) );
- mpControl = new DropdownMenuBox( pParent, mpMetric.get(), mpMenu );
+ mpControl = new DropdownMenuBox( pParent, mpMetric, mpMenu );
mpControl->SetMenuSelectHdl( LINK( this, ScalePropertyBox, implMenuSelectHdl ));
mpControl->SetHelpId( HID_SD_CUSTOMANIMATIONPANE_SCALEPROPERTYBOX );
@@ -889,7 +889,7 @@ FontStylePropertyBox::FontStylePropertyBox( sal_Int32 nControlType, vcl::Window*
: PropertySubControl( nControlType )
, maModifyHdl( rModifyHdl )
{
- mpEdit = new Edit( pParent, WB_TABSTOP|WB_IGNORETAB|WB_NOBORDER|WB_READONLY);
+ mpEdit.set( new Edit( pParent, WB_TABSTOP|WB_IGNORETAB|WB_NOBORDER|WB_READONLY) );
mpEdit->SetText( SD_RESSTR(STR_CUSTOMANIMATION_SAMPLE) );
mpMenu = new PopupMenu(SdResId( RID_CUSTOMANIMATION_FONTSTYLE_POPUP ) );
diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx
index 0a1674f..bba84b6 100644
--- a/vcl/source/control/combobox.cxx
+++ b/vcl/source/control/combobox.cxx
@@ -80,7 +80,7 @@ ComboBox::~ComboBox()
void ComboBox::ImplInitComboBoxData()
{
- mpSubEdit = NULL;
+ mpSubEdit.disposeAndClear();
mpBtn = NULL;
mpImplLB = NULL;
mpFloatWin = NULL;
@@ -164,7 +164,7 @@ void ComboBox::ImplInit( vcl::Window* pParent, WinBits nStyle )
}
}
- mpSubEdit = new Edit( this, nEditStyle );
+ mpSubEdit.set( new Edit( this, nEditStyle ) );
mpSubEdit->EnableRTL( false );
SetSubEdit( mpSubEdit );
mpSubEdit->SetPosPixel( Point() );
diff --git a/vcl/source/control/spinfld.cxx b/vcl/source/control/spinfld.cxx
index 0ab79c9..23573b1 100644
--- a/vcl/source/control/spinfld.cxx
+++ b/vcl/source/control/spinfld.cxx
@@ -286,7 +286,7 @@ void ImplDrawSpinButton( OutputDevice* pOutDev,
void SpinField::ImplInitSpinFieldData()
{
- mpEdit = NULL;
+ mpEdit.disposeAndClear();
mbSpin = false;
mbRepeat = false;
mbUpperIn = false;
@@ -311,11 +311,11 @@ void SpinField::ImplInit( vcl::Window* pParent, WinBits nWinStyle )
if ( (nWinStyle & WB_SPIN) && ImplUseNativeBorder( nWinStyle ) )
{
SetBackground();
- mpEdit = new Edit( this, WB_NOBORDER );
+ mpEdit.set( new Edit( this, WB_NOBORDER ) );
mpEdit->SetBackground();
}
else
- mpEdit = new Edit( this, WB_NOBORDER );
+ mpEdit.set( new Edit( this, WB_NOBORDER ) );
mpEdit->EnableRTL( false );
mpEdit->SetPosPixel( Point() );
@@ -359,7 +359,13 @@ SpinField::SpinField( vcl::Window* pParent, const ResId& rResId ) :
SpinField::~SpinField()
{
- delete mpEdit;
+ dispose();
+}
+
+void SpinField::dispose()
+{
+ mpEdit.disposeAndClear();
+ Edit::dispose();
}
void SpinField::Up()
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 6cf5df8..28c38f9 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -2027,7 +2027,7 @@ void VclBuilder::handleChild(vcl::Window *pParent, xmlreader::XmlReader &reader)
if (sInternalChild.startsWith("vbox") || sInternalChild.startsWith("messagedialog-vbox"))
{
if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pParent))
- pBoxParent->set_content_area(static_cast<VclBox*>(pCurrentChild));
+ pBoxParent->set_content_area(VclPtr<VclBox>(static_cast<VclBox*>(pCurrentChild))); // FIXME-VCLPTR
}
else if (sInternalChild.startsWith("action_area") || sInternalChild.startsWith("messagedialog-action_area"))
{
@@ -2035,7 +2035,7 @@ void VclBuilder::handleChild(vcl::Window *pParent, xmlreader::XmlReader &reader)
assert(pContentArea && pContentArea->GetType() == WINDOW_CONTAINER);
if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pContentArea ? pContentArea->GetParent() : NULL))
{
- pBoxParent->set_action_area(static_cast<VclButtonBox*>(pCurrentChild));
+ pBoxParent->set_action_area(VclPtr<VclButtonBox>(static_cast<VclButtonBox*>(pCurrentChild))); // FIXME-VCLPTR
}
}
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 62f612f..6375621 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -351,8 +351,8 @@ void Dialog::ImplInitDialogData()
mbOldSaveBack = false;
mbInClose = false;
mbModalMode = false;
- mpContentArea = NULL;
- mpActionArea = NULL;
+ mpContentArea.disposeAndClear();
+ mpActionArea.disposeAndClear();
mnMousePositioned = 0;
mpDialogImpl = new DialogImpl;
}
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index 820ad29..107c6a2 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -1939,10 +1939,10 @@ bool VclSizeGroup::set_property(const OString &rKey, const OString &rValue)
void MessageDialog::create_owned_areas()
{
set_border_width(12);
- m_pOwnedContentArea = new VclVBox(this, false, 24);
+ m_pOwnedContentArea.set(new VclVBox(this, false, 24));
set_content_area(m_pOwnedContentArea);
m_pOwnedContentArea->Show();
- m_pOwnedActionArea = new VclHButtonBox(m_pOwnedContentArea);
+ m_pOwnedActionArea.set( new VclHButtonBox(m_pOwnedContentArea) );
set_action_area(m_pOwnedActionArea);
m_pOwnedActionArea->Show();
}
@@ -2105,7 +2105,7 @@ short MessageDialog::Execute()
VclContainer *pContainer = get_content_area();
assert(pContainer);
- m_pGrid = new VclGrid(pContainer);
+ m_pGrid.set( new VclGrid(pContainer) );
m_pGrid->reorderWithinParent(0);
m_pGrid->set_column_spacing(12);
m_pGrid->set_row_spacing(GetTextHeight());
@@ -2165,33 +2165,33 @@ short MessageDialog::Execute()
case VCL_BUTTONS_NONE:
break;
case VCL_BUTTONS_OK:
- pBtn = new OKButton(pButtonBox);
+ pBtn.set( new OKButton(pButtonBox) );
pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON);
pBtn->Show();
m_aOwnedButtons.push_back(pBtn);
m_aResponses[pBtn] = RET_OK;
break;
case VCL_BUTTONS_CLOSE:
- pBtn = new CloseButton(pButtonBox);
+ pBtn.set( new CloseButton(pButtonBox) );
pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON);
pBtn->Show();
m_aOwnedButtons.push_back(pBtn);
m_aResponses[pBtn] = RET_CLOSE;
break;
case VCL_BUTTONS_CANCEL:
- pBtn = new CancelButton(pButtonBox);
+ pBtn.set( new CancelButton(pButtonBox) );
pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON);
m_aOwnedButtons.push_back(pBtn);
m_aResponses[pBtn] = RET_CANCEL;
break;
case VCL_BUTTONS_YES_NO:
- pBtn = new PushButton(pButtonBox);
+ pBtn.set( new PushButton(pButtonBox) );
pBtn->SetText(Button::GetStandardText(BUTTON_YES));
pBtn->Show();
m_aOwnedButtons.push_back(pBtn);
m_aResponses[pBtn] = RET_YES;
- pBtn = new PushButton(pButtonBox);
+ pBtn.set( new PushButton(pButtonBox) );
pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON);
pBtn->SetText(Button::GetStandardText(BUTTON_NO));
pBtn->Show();
@@ -2199,12 +2199,12 @@ short MessageDialog::Execute()
m_aResponses[pBtn] = RET_NO;
break;
case VCL_BUTTONS_OK_CANCEL:
- pBtn = new OKButton(pButtonBox);
+ pBtn.set( new OKButton(pButtonBox) );
pBtn->Show();
m_aOwnedButtons.push_back(pBtn);
m_aResponses[pBtn] = RET_OK;
- pBtn = new CancelButton(pButtonBox);
+ pBtn.set( new CancelButton(pButtonBox) );
pBtn->SetStyle(pBtn->GetStyle() & WB_DEFBUTTON);
pBtn->Show();
m_aOwnedButtons.push_back(pBtn);
commit 7a79126e74d430cad16cb9c04c41450e193ae692
Author: Noel Grandin <noel at peralex.com>
Date: Wed Jan 7 10:40:53 2015 +0200
vcl: vclwidget plugin should look for raw vcl::Window usage
teach the vclwidget plugin to look for places where we need to use
VclPtr<T> instead of raw pointers
Change-Id: I444836bf8e3d05fca0f30380c91a8ce24d1e9d1c
diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx
index faffbad..db4093f 100644
--- a/compilerplugins/clang/vclwidgets.cxx
+++ b/compilerplugins/clang/vclwidgets.cxx
@@ -33,16 +33,29 @@ public:
bool VisitFieldDecl(const FieldDecl * decl);
- bool mbFoundWindow;
+ bool VisitParmVarDecl(ParmVarDecl const * decl);
+
+ bool VisitVarDecl( const VarDecl* var );
+
};
-bool forallBasesCallback(const CXXBaseSpecifier *Specifier, CXXBasePath &, void *UserData) {
- VCLWidgets* ro = (VCLWidgets*) UserData;
- QualType qt = Specifier->getType();
- std::string name = qt.getUnqualifiedType().getCanonicalType().getAsString();
- if (name == "class Window") {
- ro->mbFoundWindow = true;
- return true;
+bool BaseCheckNotWindowSubclass(const CXXRecordDecl *BaseDefinition, void *) {
+ if (BaseDefinition->getQualifiedNameAsString().compare("vcl::Window") == 0) {
+ return false;
+ }
+ return true;
+}
+
+bool isDerivedFromWindow(const CXXRecordDecl *decl) {
+ if (!decl->hasDefinition())
+ return false;
+ if (decl->getQualifiedNameAsString().compare("vcl::Window") == 0)
+ return true;
+ if (// not sure what hasAnyDependentBases() does,
+ // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
+ !decl->hasAnyDependentBases() &&
+ !decl->forallBases(BaseCheckNotWindowSubclass, nullptr, true)) {
+ return true;
}
return false;
}
@@ -63,10 +76,7 @@ bool VCLWidgets::VisitFieldDecl(const FieldDecl * fieldDecl) {
return true;
}
// check if this field is derived from Window
- mbFoundWindow = false;
- CXXBasePaths paths;
- recordDecl->lookupInBases(forallBasesCallback, this, paths);
- if (!mbFoundWindow) {
+ if (!isDerivedFromWindow(recordDecl)) {
return true;
}
@@ -78,6 +88,59 @@ bool VCLWidgets::VisitFieldDecl(const FieldDecl * fieldDecl) {
return true;
}
+bool VCLWidgets::VisitParmVarDecl(ParmVarDecl const * pvDecl) {
+ if (ignoreLocation(pvDecl)) {
+ return true;
+ }
+ if (!pvDecl->getType()->isPointerType())
+ return true;
+ QualType pointeeType = pvDecl->getType()->getPointeeType();
+ const RecordType *recordType = pointeeType->getAs<RecordType>();
+ if (recordType == nullptr)
+ return true;
+ const CXXRecordDecl *recordDecl = dyn_cast<CXXRecordDecl>(recordType->getDecl());
+ if (recordDecl == nullptr)
+ return true;
+
+ // check if this parameter is derived from Window
+ if (isDerivedFromWindow(recordDecl)) {
+ report(
+ DiagnosticsEngine::Remark,
+ "vcl::Window subclass passed as a pointer parameter, should be wrapped in VclPtr.",
+ pvDecl->getLocation())
+ << pvDecl->getSourceRange();
+ }
+ return true;
+}
+
+bool VCLWidgets::VisitVarDecl( const VarDecl* varDecl )
+{
+ if (ignoreLocation(varDecl)) {
+ return true;
+ }
+ if (!varDecl->isLocalVarDecl())
+ return true;
+ if (!varDecl->getType()->isPointerType())
+ return true;
+ QualType pointeeType = varDecl->getType()->getPointeeType();
+ const RecordType *recordType = pointeeType->getAs<RecordType>();
+ if (recordType == nullptr)
+ return true;
+ const CXXRecordDecl *recordDecl = dyn_cast<CXXRecordDecl>(recordType->getDecl());
+ if (recordDecl == nullptr)
+ return true;
+
+ // check if this variables type is derived from Window
+ if (isDerivedFromWindow(recordDecl)) {
+ report(
+ DiagnosticsEngine::Remark,
+ "vcl::Window subclass declared as a pointer var, should be wrapped in VclPtr.",
+ varDecl->getLocation())
+ << varDecl->getSourceRange();
+ }
+
+ return true;
+}
loplugin::Plugin::Registration< VCLWidgets > X("vclwidgets");
More information about the Libreoffice-commits
mailing list