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
This commit is contained in:
@@ -529,7 +529,7 @@ public:
|
|||||||
void ClearListBox();
|
void ClearListBox();
|
||||||
void SetTextSelection( const TextSelection& aSel );
|
void SetTextSelection( const TextSelection& aSel );
|
||||||
const TextSelection& GetTextSelection() const;
|
const TextSelection& GetTextSelection() const;
|
||||||
void ResizeListBox();
|
void ResizeListBox( const TextSelection& aSel );
|
||||||
void SelectFirstEntry(); //selects first entry in ListBox
|
void SelectFirstEntry(); //selects first entry in ListBox
|
||||||
void ClearAndHide();
|
void ClearAndHide();
|
||||||
/*
|
/*
|
||||||
|
@@ -808,25 +808,22 @@ void EditorWindow::HandleCodeCompletition()
|
|||||||
|
|
||||||
void EditorWindow::SetupAndShowCodeCompleteWnd( const std::vector< OUString >& aEntryVect, TextSelection aSel )
|
void EditorWindow::SetupAndShowCodeCompleteWnd( const std::vector< OUString >& aEntryVect, TextSelection aSel )
|
||||||
{
|
{
|
||||||
// calculate position
|
// clear the listbox
|
||||||
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;
|
|
||||||
pCodeCompleteWnd->ClearListBox();
|
pCodeCompleteWnd->ClearListBox();
|
||||||
pCodeCompleteWnd->SetTextSelection(aSel);
|
// fill the listbox
|
||||||
//fill the listbox
|
|
||||||
for(unsigned int l = 0; l < aEntryVect.size(); ++l)
|
for(unsigned int l = 0; l < aEntryVect.size(); ++l)
|
||||||
{
|
{
|
||||||
pCodeCompleteWnd->InsertEntry( aEntryVect[l] );
|
pCodeCompleteWnd->InsertEntry( aEntryVect[l] );
|
||||||
}
|
}
|
||||||
//show it
|
// show it
|
||||||
pCodeCompleteWnd->SetPosPixel( aPoint );
|
|
||||||
pCodeCompleteWnd->Show();
|
pCodeCompleteWnd->Show();
|
||||||
pCodeCompleteWnd->ResizeListBox();
|
pCodeCompleteWnd->ResizeListBox( aSel );
|
||||||
pCodeCompleteWnd->SelectFirstEntry();
|
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();
|
pEditView->GetWindow()->GrabFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2770,26 +2767,30 @@ const TextSelection& CodeCompleteWindow::GetTextSelection() const
|
|||||||
return aTextSelection;
|
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
|
{// if there is at least one element inside
|
||||||
OUString aLongestEntry = pListBox->GetEntry( 0 );//grab the longest one: max search
|
// calculate basic position: under the current line
|
||||||
if( pListBox->GetEntryCount() > 0 )
|
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();
|
// get column/line count
|
||||||
sal_uInt16 nLines = std::min( (sal_uInt16) 6, pListBox->GetEntryCount() );
|
const sal_uInt16& nColumns = aLongestEntry.getLength();
|
||||||
const Font& aFont = pListBox->GetUnzoomedControlPointFont();
|
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() );
|
Rectangle aVisArea( pParent->GetEditView()->GetStartDocPos(), pParent->GetOutputSizePixel() );
|
||||||
Size aSize = pListBox->GetOptimalSize();//this sets the correct width
|
Size aSize = pListBox->GetOptimalSize();// this sets the correct width
|
||||||
aSize.setHeight( pListBox->CalcSize( nColumns, nLines ).getHeight() );
|
aSize.setHeight( pListBox->CalcSize( nColumns, nLines ).getHeight() );// correct height
|
||||||
|
|
||||||
Point aBottomPoint = aVisArea.BottomRight();
|
Point aBottomPoint = aVisArea.BottomRight();
|
||||||
Point aTopPoint = aVisArea.TopRight();
|
Point aTopPoint = aVisArea.TopRight();
|
||||||
@@ -2797,23 +2798,22 @@ void CodeCompleteWindow::ResizeListBox()
|
|||||||
|
|
||||||
if( (nYDiff + aFont.GetSize().getHeight()) < aSize.Height() )
|
if( (nYDiff + aFont.GetSize().getHeight()) < aSize.Height() )
|
||||||
{//bottom part is clipped, fix the visibility by placing it over the line (not under)
|
{//bottom part is clipped, fix the visibility by placing it over the line (not under)
|
||||||
Point aPos = GetPosPixel();
|
const Font& aParFont = pParent->GetEditEngine()->GetFont();//parent's font (in the IDE): needed for height
|
||||||
Font aParFont = pParent->GetEditEngine()->GetFont();
|
|
||||||
aPos.Y() = aPos.Y() - (aSize.getHeight() + aParFont.GetSize().getHeight()+5);
|
aPos.Y() = aPos.Y() - (aSize.getHeight() + aParFont.GetSize().getHeight()+5);
|
||||||
SetPosPixel(aPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long nXDiff = std::abs(aTopPoint.X() - GetPosPixel().X());
|
long nXDiff = std::abs(aTopPoint.X() - GetPosPixel().X());
|
||||||
if( nXDiff < aSize.Width() )
|
if( nXDiff < aSize.Width() )
|
||||||
{//clipped at the right side, move it a bit left
|
{//clipped at the right side, move it a bit left
|
||||||
Point aPos = GetPosPixel();
|
|
||||||
aPos.X() = aPos.X() - aSize.Width() + nXDiff;
|
aPos.X() = aPos.X() - aSize.Width() + nXDiff;
|
||||||
SetPosPixel(aPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pListBox->SetSizePixel( aSize );
|
pListBox->SetSizePixel( aSize );
|
||||||
aSize.setWidth( aSize.getWidth() + 1 );
|
aSize.setWidth( aSize.getWidth() + 1 );
|
||||||
aSize.setHeight( aSize.getHeight() + 1 );
|
aSize.setHeight( aSize.getHeight() + 1 );
|
||||||
|
// set the size and the position of the window
|
||||||
SetSizePixel( aSize );
|
SetSizePixel( aSize );
|
||||||
|
SetPosPixel( aPos );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user