Kaydet (Commit) 5d954483 authored tarafından Gergo Mocsi's avatar Gergo Mocsi

GSOC work, Window instead a FloatingWindow

Changed CodeCompleteListBox into a Window which contains a single ListBox.
Navigation with arrows is enabled, window closes on ESC key.
Double click inserts the selected method into the source code.
Visible line count in ListBox is set to 8 lines, width is adopted from the
longest entry.

Change-Id: I6b6ceb0ce78f9fc727aed53952dc6ee24cba47df
üst 5dc05ade
...@@ -51,6 +51,9 @@ class SvxSearchItem; ...@@ -51,6 +51,9 @@ class SvxSearchItem;
#include <set> #include <set>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <vcl/floatwin.hxx>
#include <vcl/textdata.hxx>
namespace com { namespace sun { namespace star { namespace beans { namespace com { namespace sun { namespace star { namespace beans {
class XMultiPropertySet; class XMultiPropertySet;
} } } } } } } }
...@@ -60,6 +63,7 @@ namespace basctl ...@@ -60,6 +63,7 @@ namespace basctl
class ObjectCatalog; class ObjectCatalog;
class CodeCompleteListBox; class CodeCompleteListBox;
class CodeCompleteFloatWindow;
DBG_NAMEEX( ModulWindow ) DBG_NAMEEX( ModulWindow )
...@@ -112,7 +116,8 @@ private: ...@@ -112,7 +116,8 @@ private:
::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
GetComponentInterface(sal_Bool bCreate = true); GetComponentInterface(sal_Bool bCreate = true);
std::vector< CodeCompleteData > aCodeCompleteCache; std::vector< CodeCompleteData > aCodeCompleteCache;
CodeCompleteListBox* aListBox; CodeCompleteFloatWindow* pCodeCompleteWnd;
//CodeCompleteListBox* aListBox;
OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
std::vector< OUString > Split( const OUString& sStr, const sal_Unicode& aChar ); std::vector< OUString > Split( const OUString& sStr, const sal_Unicode& aChar );
...@@ -469,6 +474,29 @@ private: ...@@ -469,6 +474,29 @@ private:
} aSyntaxColors; } aSyntaxColors;
}; };
class CodeCompleteFloatWindow: public Window
{
private:
EditorWindow* pParent; // parent window
TextSelection aTextSelection;
ListBox* pListBox;
void InitListBox(); // initialize the ListBox
DECL_LINK(ImplDoubleClickHdl, void*);
public:
CodeCompleteFloatWindow( EditorWindow* pPar );
virtual ~CodeCompleteFloatWindow();
void InsertEntry( const OUString& aStr );
void ClearListBox();
void SetTextSelection( const TextSelection& aSel );
void ResizeListBox();
protected:
virtual void KeyInput( const KeyEvent& rKeyEvt );
};
class CodeCompleteListBox: public ListBox class CodeCompleteListBox: public ListBox
{ {
private: private:
......
...@@ -250,7 +250,9 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) : ...@@ -250,7 +250,9 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) :
s[0] = OUString( "FontHeight" ); s[0] = OUString( "FontHeight" );
s[1] = OUString( "FontName" ); s[1] = OUString( "FontName" );
n->addPropertiesChangeListener(s, listener_.get()); n->addPropertiesChangeListener(s, listener_.get());
aListBox = new CodeCompleteListBox(this); //aListBox = new CodeCompleteListBox(this);
//pCodeCopleteWnd = new CodeCompleteFloatWindow(this);
pCodeCompleteWnd = new CodeCompleteFloatWindow( this );
} }
...@@ -272,7 +274,9 @@ EditorWindow::~EditorWindow() ...@@ -272,7 +274,9 @@ EditorWindow::~EditorWindow()
EndListening( *pEditEngine ); EndListening( *pEditEngine );
pEditEngine->RemoveView(pEditView.get()); pEditEngine->RemoveView(pEditView.get());
} }
delete aListBox;
//delete aListBox;
delete pCodeCompleteWnd;
} }
OUString EditorWindow::GetWordAtCursor() OUString EditorWindow::GetWordAtCursor()
...@@ -576,17 +580,21 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) ...@@ -576,17 +580,21 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
if( aMethods.getLength() != 0 ) if( aMethods.getLength() != 0 )
{ {
Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false ); Rectangle aRect = ( (TextEngine*) GetEditEngine() )->PaMtoEditCursor( aSel.GetEnd() , false );
aListBox->SetPosPixel( aRect.TopLeft() ); GetEditView()->EnableCursor( false );
aListBox->SetSizePixel( Size(150,150) );
aSel.GetStart().GetIndex() += 1;
aSel.GetEnd().GetIndex() += 1;
pCodeCompleteWnd->ClearListBox();
pCodeCompleteWnd->SetTextSelection(aSel);
pCodeCompleteWnd->SetPosPixel( aRect.BottomRight() );
for(sal_Int32 l = 0; l < aMethods.getLength(); ++l) for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
{ {
aListBox->InsertEntry( OUString(aMethods[l]->getName()) ); pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) );
std::cerr << aMethods[l]->getName() << std::endl;
} }
pCodeCompleteWnd->ResizeListBox();
aListBox->GetFocus(); pCodeCompleteWnd->Show();
aListBox->ToggleDropDown(); pCodeCompleteWnd->GrabFocus();
} }
} }
} }
...@@ -2377,10 +2385,11 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped ) ...@@ -2377,10 +2385,11 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped )
} }
CodeCompleteListBox::CodeCompleteListBox(EditorWindow* pPar) CodeCompleteListBox::CodeCompleteListBox(EditorWindow* pPar)
: ListBox(pPar, WB_DROPDOWN), : ListBox(pPar, WB_DROPDOWN | WB_BORDER),
pParent(pPar) pParent(pPar)
{ {
SetSelectHdl( LINK(this, CodeCompleteListBox, ImplSelectHdl) ); SetSelectHdl( LINK(this, CodeCompleteListBox, ImplSelectHdl) );
SetDropDownLineCount( 8 );
} }
CodeCompleteListBox::~CodeCompleteListBox() CodeCompleteListBox::~CodeCompleteListBox()
...@@ -2395,6 +2404,73 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl) ...@@ -2395,6 +2404,73 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl)
return 0; return 0;
} }
CodeCompleteFloatWindow::CodeCompleteFloatWindow( EditorWindow* pPar )
: Window( pPar, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW ),
pParent(pPar)
{
InitListBox();
SetSizePixel( Size(150,150) );
}
void CodeCompleteFloatWindow::InitListBox()
{
pListBox = new ListBox( this );
pListBox->SetSizePixel( Size(150,150) ); //default, this will adopt the line length
pListBox->SetDoubleClickHdl(LINK(this, CodeCompleteFloatWindow, ImplDoubleClickHdl));
pListBox->Show();
}
CodeCompleteFloatWindow::~CodeCompleteFloatWindow()
{
delete pListBox;
}
void CodeCompleteFloatWindow::InsertEntry( const OUString& aStr )
{
pListBox->InsertEntry( aStr );
}
void CodeCompleteFloatWindow::ClearListBox()
{
pListBox->Clear();
}
IMPL_LINK_NOARG(CodeCompleteFloatWindow, ImplDoubleClickHdl)
{
if( pListBox->GetEntry( pListBox->GetSelectEntryPos() ) != OUString("") )
{
pParent->GetEditView()->SetSelection( aTextSelection );
pParent->GetEditView()->InsertText( (OUString) pListBox->GetEntry(pListBox->GetSelectEntryPos()) );
pParent->GetEditView()->EnableCursor( true );
LoseFocus();
Hide();
}
return 0;
}
void CodeCompleteFloatWindow::KeyInput( const KeyEvent& rKeyEvt )
{
if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE )
{// ESC key closes the window: does not modify anything
pParent->GetEditView()->EnableCursor( true );
Hide();
}
}
void CodeCompleteFloatWindow::SetTextSelection( const TextSelection& aSel )
{
aTextSelection = aSel;
}
void CodeCompleteFloatWindow::ResizeListBox()
{
Size aSize = pListBox->CalcMinimumSize();
const Font& aFont = pListBox->GetUnzoomedControlPointFont();
aSize.setHeight( aFont.GetSize().getHeight() * 16 );
pListBox->SetSizePixel( aSize );
SetSizePixel( aSize );
}
} // namespace basctl } // namespace basctl
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment