summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-08-15 11:21:20 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-08-15 11:21:20 +0200
commitc9b1cd888c8605b4241bceb72ec16d8c64eaaf4b (patch)
treec788582bb320c33dfdf02101724963dec56e459d
parentd06f0e9d39b76dde469a670b9075fcb9c8bb791e (diff)
GSOC work, simplify CodeCompleteWindow::ResizeListBox
Now all calculations are done in this function, plus the initial TextSelection is passed as a parameter (it it needed to determine the location of the ListBox). Some local variables were made constant. Change-Id: I36942ded72cc988c8fd5114e0d666f447b80d396
-rw-r--r--basctl/source/basicide/baside2.hxx2
-rw-r--r--basctl/source/basicide/baside2b.cxx62
2 files changed, 32 insertions, 32 deletions
diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 4c4ac343095d..df6b45167de8 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -529,7 +529,7 @@ public:
void ClearListBox();
void SetTextSelection( const TextSelection& aSel );
const TextSelection& GetTextSelection() const;
- void ResizeListBox();
+ void ResizeListBox( const TextSelection& aSel );
void SelectFirstEntry(); //selects first entry in ListBox
void ClearAndHide();
/*
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 9221e4415355..7e01b52d1fb4 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -802,25 +802,22 @@ void EditorWindow::HandleCodeCompletition()
void EditorWindow::SetupAndShowCodeCompleteWnd( const std::vector< OUString >& aEntryVect, TextSelection aSel )
{
- // calculate position
- Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
- long nViewYOffset = pEditView->GetStartDocPos().Y();
- Point aPoint = aRect.BottomRight();
- aPoint.Y() = (aPoint.Y() - nViewYOffset) + 2;
- aSel.GetStart().GetIndex() += 1;
- aSel.GetEnd().GetIndex() += 1;
+ // clear the listbox
pCodeCompleteWnd->ClearListBox();
- pCodeCompleteWnd->SetTextSelection(aSel);
- //fill the listbox
+ // fill the listbox
for(unsigned int l = 0; l < aEntryVect.size(); ++l)
{
pCodeCompleteWnd->InsertEntry( aEntryVect[l] );
}
- //show it
- pCodeCompleteWnd->SetPosPixel( aPoint );
+ // show it
pCodeCompleteWnd->Show();
- pCodeCompleteWnd->ResizeListBox();
+ pCodeCompleteWnd->ResizeListBox( aSel );
pCodeCompleteWnd->SelectFirstEntry();
+ // correct text selection, and set it
+ aSel.GetStart().GetIndex() += 1;
+ aSel.GetEnd().GetIndex() += 1;
+ pCodeCompleteWnd->SetTextSelection( aSel );
+ //give the focus to the EditView
pEditView->GetWindow()->GrabFocus();
}
@@ -2764,26 +2761,30 @@ const TextSelection& CodeCompleteWindow::GetTextSelection() const
return aTextSelection;
}
-void CodeCompleteWindow::ResizeListBox()
+void CodeCompleteWindow::ResizeListBox( const TextSelection& aSel )
{
- if( pListBox->GetEntryCount() > 0 )
+ if( pListBox->GetEntryCount() >= 1 )
{// if there is at least one element inside
- OUString aLongestEntry = pListBox->GetEntry( 0 );//grab the longest one: max search
- if( pListBox->GetEntryCount() > 0 )
+ // calculate basic position: under the current line
+ Rectangle aRect = ( (TextEngine*) pParent->GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
+ long nViewYOffset = pParent->GetEditView()->GetStartDocPos().Y();
+ Point aPos = aRect.BottomRight();// this variable will be used later (if needed)
+ aPos.Y() = (aPos.Y() - nViewYOffset) + 2;
+
+ OUString aLongestEntry = pListBox->GetEntry( 0 );// grab the longest one: max search
+ for( sal_uInt16 i=1; i< pListBox->GetEntryCount(); ++i )
{
- for( sal_uInt16 i=1; i< pListBox->GetEntryCount(); ++i )
- {
- if( ((OUString) pListBox->GetEntry( i )).getLength() > aLongestEntry.getLength() )
- aLongestEntry = pListBox->GetEntry( i );
- }
+ if( ((OUString) pListBox->GetEntry( i )).getLength() > aLongestEntry.getLength() )
+ aLongestEntry = pListBox->GetEntry( i );
}
- sal_uInt16 nColumns = aLongestEntry.getLength();
- sal_uInt16 nLines = std::min( (sal_uInt16) 6, pListBox->GetEntryCount() );
- const Font& aFont = pListBox->GetUnzoomedControlPointFont();
+ // get column/line count
+ const sal_uInt16& nColumns = aLongestEntry.getLength();
+ const sal_uInt16& nLines = std::min( (sal_uInt16) 6, pListBox->GetEntryCount() );
+ const Font& aFont = pListBox->GetFont();// listbox's font: height is needed
Rectangle aVisArea( pParent->GetEditView()->GetStartDocPos(), pParent->GetOutputSizePixel() );
- Size aSize = pListBox->GetOptimalSize();//this sets the correct width
- aSize.setHeight( pListBox->CalcSize( nColumns, nLines ).getHeight() );
+ Size aSize = pListBox->GetOptimalSize();// this sets the correct width
+ aSize.setHeight( pListBox->CalcSize( nColumns, nLines ).getHeight() );// correct height
Point aBottomPoint = aVisArea.BottomRight();
Point aTopPoint = aVisArea.TopRight();
@@ -2791,23 +2792,22 @@ void CodeCompleteWindow::ResizeListBox()
if( (nYDiff + aFont.GetSize().getHeight()) < aSize.Height() )
{//bottom part is clipped, fix the visibility by placing it over the line (not under)
- Point aPos = GetPosPixel();
- Font aParFont = pParent->GetEditEngine()->GetFont();
+ const Font& aParFont = pParent->GetEditEngine()->GetFont();//parent's font (in the IDE): needed for height
aPos.Y() = aPos.Y() - (aSize.getHeight() + aParFont.GetSize().getHeight()+5);
- SetPosPixel(aPos);
}
long nXDiff = std::abs(aTopPoint.X() - GetPosPixel().X());
if( nXDiff < aSize.Width() )
{//clipped at the right side, move it a bit left
- Point aPos = GetPosPixel();
aPos.X() = aPos.X() - aSize.Width() + nXDiff;
- SetPosPixel(aPos);
}
+
pListBox->SetSizePixel( aSize );
aSize.setWidth( aSize.getWidth() + 1 );
aSize.setHeight( aSize.getHeight() + 1 );
+ // set the size and the position of the window
SetSizePixel( aSize );
+ SetPosPixel( aPos );
}
}