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

GSOC work, Window appearance fix

Fixed the window width to adopt size by longest entry.
Window height is set to display 8 lines, plus the scrollbar.
When selected, window can be close by the ESC key( done by PreNotify() ).
Also, renamed it to CodeCompleteWindow for consistency.

Change-Id: I9cd53c3d868cdaeb8d391547f16da7038278154b
üst 5d954483
...@@ -51,7 +51,6 @@ class SvxSearchItem; ...@@ -51,7 +51,6 @@ class SvxSearchItem;
#include <set> #include <set>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <vcl/floatwin.hxx>
#include <vcl/textdata.hxx> #include <vcl/textdata.hxx>
namespace com { namespace sun { namespace star { namespace beans { namespace com { namespace sun { namespace star { namespace beans {
...@@ -63,7 +62,7 @@ namespace basctl ...@@ -63,7 +62,7 @@ namespace basctl
class ObjectCatalog; class ObjectCatalog;
class CodeCompleteListBox; class CodeCompleteListBox;
class CodeCompleteFloatWindow; class CodeCompleteWindow;
DBG_NAMEEX( ModulWindow ) DBG_NAMEEX( ModulWindow )
...@@ -116,7 +115,7 @@ private: ...@@ -116,7 +115,7 @@ 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;
CodeCompleteFloatWindow* pCodeCompleteWnd; CodeCompleteWindow* pCodeCompleteWnd;
//CodeCompleteListBox* aListBox; //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 );
...@@ -474,23 +473,25 @@ private: ...@@ -474,23 +473,25 @@ private:
} aSyntaxColors; } aSyntaxColors;
}; };
class CodeCompleteFloatWindow: public Window class CodeCompleteWindow: public Window
{ {
friend class CodeCompleteListBox;
private: private:
EditorWindow* pParent; // parent window EditorWindow* pParent; // parent window
TextSelection aTextSelection; TextSelection aTextSelection;
ListBox* pListBox; CodeCompleteListBox* pListBox;
void InitListBox(); // initialize the ListBox void InitListBox(); // initialize the ListBox
DECL_LINK(ImplDoubleClickHdl, void*); //DECL_LINK(ImplDoubleClickHdl, void*);
public: public:
CodeCompleteFloatWindow( EditorWindow* pPar ); CodeCompleteWindow( EditorWindow* pPar );
virtual ~CodeCompleteFloatWindow(); virtual ~CodeCompleteWindow();
void InsertEntry( const OUString& aStr ); void InsertEntry( const OUString& aStr );
void ClearListBox(); void ClearListBox();
void SetTextSelection( const TextSelection& aSel ); void SetTextSelection( const TextSelection& aSel );
const TextSelection& GetTextSelection() const;
void ResizeListBox(); void ResizeListBox();
protected: protected:
...@@ -500,12 +501,15 @@ protected: ...@@ -500,12 +501,15 @@ protected:
class CodeCompleteListBox: public ListBox class CodeCompleteListBox: public ListBox
{ {
private: private:
EditorWindow* pParent; // parent window CodeCompleteWindow* pCodeCompleteWindow; // parent window
public: public:
CodeCompleteListBox(EditorWindow* pPar); CodeCompleteListBox(CodeCompleteWindow* pPar);
virtual ~CodeCompleteListBox(); virtual ~CodeCompleteListBox();
DECL_LINK(ImplSelectHdl, void*); //DECL_LINK(ImplSelectHdl, void*);
DECL_LINK(ImplDoubleClickHdl, void*);
virtual long PreNotify( NotifyEvent& rNEvt );
}; };
} // namespace basctl } // namespace basctl
......
...@@ -251,8 +251,8 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) : ...@@ -251,8 +251,8 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) :
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); //pCodeCopleteWnd = new CodeCompleteWindow(this);
pCodeCompleteWnd = new CodeCompleteFloatWindow( this ); pCodeCompleteWnd = new CodeCompleteWindow( this );
} }
...@@ -591,6 +591,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) ...@@ -591,6 +591,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
for(sal_Int32 l = 0; l < aMethods.getLength(); ++l) for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
{ {
pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) ); pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) );
//std::cerr << aMethods[l]->getName() << std::endl;
} }
pCodeCompleteWnd->ResizeListBox(); pCodeCompleteWnd->ResizeListBox();
pCodeCompleteWnd->Show(); pCodeCompleteWnd->Show();
...@@ -2384,72 +2385,82 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped ) ...@@ -2384,72 +2385,82 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped )
setBasicWatchMode( false ); setBasicWatchMode( false );
} }
CodeCompleteListBox::CodeCompleteListBox(EditorWindow* pPar) CodeCompleteListBox::CodeCompleteListBox( CodeCompleteWindow* pPar )
: ListBox(pPar, WB_DROPDOWN | WB_BORDER), : ListBox(pPar, WB_SORT | WB_BORDER),
pParent(pPar) pCodeCompleteWindow(pPar)
{ {
SetSelectHdl( LINK(this, CodeCompleteListBox, ImplSelectHdl) ); SetDoubleClickHdl(LINK(this, CodeCompleteListBox, ImplDoubleClickHdl));
SetDropDownLineCount( 8 );
} }
CodeCompleteListBox::~CodeCompleteListBox() CodeCompleteListBox::~CodeCompleteListBox()
{ {
delete pCodeCompleteWindow;
} }
IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl) IMPL_LINK_NOARG(CodeCompleteListBox, ImplDoubleClickHdl)
{ {
TextSelection aSel = this->pParent->GetEditView()->GetSelection(); if( GetEntry( GetSelectEntryPos() ) != OUString("") )
pParent->GetEditEngine()->ReplaceText(aSel, (OUString) GetEntry(GetSelectEntryPos()) ); {
Clear(); pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->GetTextSelection() );
pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()) );
pCodeCompleteWindow->pParent->GetEditView()->EnableCursor( true );
pCodeCompleteWindow->LoseFocus();
pCodeCompleteWindow->Hide();
}
return 0; return 0;
} }
CodeCompleteFloatWindow::CodeCompleteFloatWindow( EditorWindow* pPar ) long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt )
: Window( pPar, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW ), {
if( ( rNEvt.GetType() == EVENT_KEYINPUT ) )
{
KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
switch( aKeyEvt.GetKeyCode().GetCode() )
{
case KEY_ESCAPE:
pCodeCompleteWindow->pParent->GetEditView()->EnableCursor( true );
pCodeCompleteWindow->Hide();
return 0;
default:
return ListBox::PreNotify( rNEvt );
}
}
}
CodeCompleteWindow::CodeCompleteWindow( EditorWindow* pPar )
: Window( pPar, WB_BORDER ),
pParent(pPar) pParent(pPar)
{ {
InitListBox(); InitListBox();
SetSizePixel( Size(150,150) ); SetSizePixel( Size(150,150) );
} }
void CodeCompleteFloatWindow::InitListBox() void CodeCompleteWindow::InitListBox()
{ {
pListBox = new ListBox( this ); pListBox = new CodeCompleteListBox( this );
pListBox->SetSizePixel( Size(150,150) ); //default, this will adopt the line length pListBox->SetSizePixel( Size(150,150) ); //default, this will adopt the line length
pListBox->SetDoubleClickHdl(LINK(this, CodeCompleteFloatWindow, ImplDoubleClickHdl));
pListBox->Show(); pListBox->Show();
pListBox->GrabFocus();
} }
CodeCompleteFloatWindow::~CodeCompleteFloatWindow() CodeCompleteWindow::~CodeCompleteWindow()
{ {
delete pListBox; delete pListBox;
} }
void CodeCompleteFloatWindow::InsertEntry( const OUString& aStr ) void CodeCompleteWindow::InsertEntry( const OUString& aStr )
{ {
pListBox->InsertEntry( aStr ); pListBox->InsertEntry( aStr );
} }
void CodeCompleteFloatWindow::ClearListBox() void CodeCompleteWindow::ClearListBox()
{ {
pListBox->Clear(); pListBox->Clear();
} }
IMPL_LINK_NOARG(CodeCompleteFloatWindow, ImplDoubleClickHdl) void CodeCompleteWindow::KeyInput( const KeyEvent& rKeyEvt )
{
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 )
{ {
std::cerr << "CodeCompleteWindow::KeyInput" << std::endl;
if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE ) if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE )
{// ESC key closes the window: does not modify anything {// ESC key closes the window: does not modify anything
pParent->GetEditView()->EnableCursor( true ); pParent->GetEditView()->EnableCursor( true );
...@@ -2457,18 +2468,36 @@ void CodeCompleteFloatWindow::KeyInput( const KeyEvent& rKeyEvt ) ...@@ -2457,18 +2468,36 @@ void CodeCompleteFloatWindow::KeyInput( const KeyEvent& rKeyEvt )
} }
} }
void CodeCompleteFloatWindow::SetTextSelection( const TextSelection& aSel ) void CodeCompleteWindow::SetTextSelection( const TextSelection& aSel )
{ {
aTextSelection = aSel; aTextSelection = aSel;
} }
void CodeCompleteFloatWindow::ResizeListBox() const TextSelection& CodeCompleteWindow::GetTextSelection() const
{
return aTextSelection;
}
void CodeCompleteWindow::ResizeListBox()
{ {
Size aSize = pListBox->CalcMinimumSize(); if( pListBox->GetEntryCount() > 0 )
const Font& aFont = pListBox->GetUnzoomedControlPointFont(); {// if there is at least one element inside
aSize.setHeight( aFont.GetSize().getHeight() * 16 ); OUString aLongestEntry = pListBox->GetEntry( 0 );//grab the longest one: max search
pListBox->SetSizePixel( aSize ); for( sal_uInt16 i=0; i< pListBox->GetEntryCount(); ++i )
SetSizePixel( aSize ); {
if( ((OUString) pListBox->GetEntry( i )).getLength() > aLongestEntry.getLength() )
aLongestEntry = pListBox->GetEntry( i );
}
Size aSize = pListBox->GetOptimalSize();
const Font& aFont = pListBox->GetUnzoomedControlPointFont();
aSize.setHeight( aFont.GetSize().getHeight() * 16 );
aSize.setWidth( pListBox->CalcSize(aLongestEntry.getLength(),pListBox->GetEntryCount()).getWidth() );
pListBox->SetSizePixel( aSize );
SetSizePixel( aSize );
}
} }
} // namespace basctl } // namespace basctl
......
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