[Libreoffice-commits] core.git: Branch 'feature/gsoc-basic-ide-completion-and-other-bits' - basctl/source

Gergo Mocsi gmocsi91 at gmail.com
Wed Jul 17 03:49:28 PDT 2013


 basctl/source/basicide/baside2.hxx  |   26 ++++----
 basctl/source/basicide/baside2b.cxx |  109 ++++++++++++++++++++++--------------
 2 files changed, 84 insertions(+), 51 deletions(-)

New commits:
commit fe504de79ba87226a76940cf1670cb1864045cf8
Author: Gergo Mocsi <gmocsi91 at gmail.com>
Date:   Wed Jul 17 12:41:13 2013 +0200

    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

diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx
index 3d8afde..c0d93aa 100644
--- a/basctl/source/basicide/baside2.hxx
+++ b/basctl/source/basicide/baside2.hxx
@@ -51,7 +51,6 @@ class SvxSearchItem;
 #include <set>
 #include <boost/scoped_ptr.hpp>
 
-#include <vcl/floatwin.hxx>
 #include <vcl/textdata.hxx>
 
 namespace com { namespace sun { namespace star { namespace beans {
@@ -63,7 +62,7 @@ namespace basctl
 
 class ObjectCatalog;
 class CodeCompleteListBox;
-class CodeCompleteFloatWindow;
+class CodeCompleteWindow;
 
 DBG_NAMEEX( ModulWindow )
 
@@ -116,7 +115,7 @@ private:
     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
     GetComponentInterface(sal_Bool bCreate = true);
     std::vector< CodeCompleteData > aCodeCompleteCache;
-    CodeCompleteFloatWindow* pCodeCompleteWnd;
+    CodeCompleteWindow* pCodeCompleteWnd;
     //CodeCompleteListBox* aListBox;
     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 );
@@ -474,23 +473,25 @@ private:
     } aSyntaxColors;
 };
 
-class CodeCompleteFloatWindow: public Window
+class CodeCompleteWindow: public Window
 {
+friend class CodeCompleteListBox;
 private:
     EditorWindow* pParent; // parent window
     TextSelection aTextSelection;
-    ListBox* pListBox;
+    CodeCompleteListBox* pListBox;
 
     void InitListBox(); // initialize the ListBox
-    DECL_LINK(ImplDoubleClickHdl, void*);
+    //DECL_LINK(ImplDoubleClickHdl, void*);
 
 public:
-    CodeCompleteFloatWindow( EditorWindow* pPar );
-    virtual ~CodeCompleteFloatWindow();
+    CodeCompleteWindow( EditorWindow* pPar );
+    virtual ~CodeCompleteWindow();
 
     void InsertEntry( const OUString& aStr );
     void ClearListBox();
     void SetTextSelection( const TextSelection& aSel );
+    const TextSelection& GetTextSelection() const;
     void ResizeListBox();
 
 protected:
@@ -500,12 +501,15 @@ protected:
 class CodeCompleteListBox: public ListBox
 {
 private:
-    EditorWindow* pParent; // parent window
+    CodeCompleteWindow* pCodeCompleteWindow; // parent window
 
 public:
-    CodeCompleteListBox(EditorWindow* pPar);
+    CodeCompleteListBox(CodeCompleteWindow* pPar);
     virtual ~CodeCompleteListBox();
-    DECL_LINK(ImplSelectHdl, void*);
+    //DECL_LINK(ImplSelectHdl, void*);
+    DECL_LINK(ImplDoubleClickHdl, void*);
+
+    virtual long PreNotify( NotifyEvent& rNEvt );
 };
 
 } // namespace basctl
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 77db23d..c570be6 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -251,8 +251,8 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) :
     s[1] = OUString( "FontName" );
     n->addPropertiesChangeListener(s, listener_.get());
     //aListBox = new CodeCompleteListBox(this);
-    //pCodeCopleteWnd = new CodeCompleteFloatWindow(this);
-    pCodeCompleteWnd = new CodeCompleteFloatWindow( this );
+    //pCodeCopleteWnd = new CodeCompleteWindow(this);
+    pCodeCompleteWnd = new CodeCompleteWindow( this );
 }
 
 
@@ -585,6 +585,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
                             for(sal_Int32 l = 0; l < aMethods.getLength(); ++l)
                             {
                                 pCodeCompleteWnd->InsertEntry( OUString(aMethods[l]->getName()) );
+                                //std::cerr << aMethods[l]->getName() << std::endl;
                             }
                             pCodeCompleteWnd->ResizeListBox();
                             pCodeCompleteWnd->Show();
@@ -2378,72 +2379,82 @@ void WatchTreeListBox::UpdateWatches( bool bBasicStopped )
     setBasicWatchMode( false );
 }
 
-CodeCompleteListBox::CodeCompleteListBox(EditorWindow* pPar)
-: ListBox(pPar, WB_DROPDOWN | WB_BORDER),
-pParent(pPar)
+CodeCompleteListBox::CodeCompleteListBox( CodeCompleteWindow* pPar )
+: ListBox(pPar, WB_SORT | WB_BORDER),
+pCodeCompleteWindow(pPar)
 {
-    SetSelectHdl( LINK(this, CodeCompleteListBox, ImplSelectHdl) );
-    SetDropDownLineCount( 8 );
+    SetDoubleClickHdl(LINK(this, CodeCompleteListBox, ImplDoubleClickHdl));
 }
 
 CodeCompleteListBox::~CodeCompleteListBox()
 {
+    delete pCodeCompleteWindow;
 }
 
-IMPL_LINK_NOARG(CodeCompleteListBox, ImplSelectHdl)
+IMPL_LINK_NOARG(CodeCompleteListBox, ImplDoubleClickHdl)
 {
-    TextSelection aSel = this->pParent->GetEditView()->GetSelection();
-    pParent->GetEditEngine()->ReplaceText(aSel, (OUString) GetEntry(GetSelectEntryPos()) );
-    Clear();
+    if( GetEntry( GetSelectEntryPos() ) != OUString("") )
+    {
+        pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->GetTextSelection() );
+        pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()) );
+        pCodeCompleteWindow->pParent->GetEditView()->EnableCursor( true );
+        pCodeCompleteWindow->LoseFocus();
+        pCodeCompleteWindow->Hide();
+    }
     return 0;
 }
 
-CodeCompleteFloatWindow::CodeCompleteFloatWindow( EditorWindow* pPar )
-: Window( pPar, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW  ),
+long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt )
+{
+    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)
 {
     InitListBox();
     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->SetDoubleClickHdl(LINK(this, CodeCompleteFloatWindow, ImplDoubleClickHdl));
     pListBox->Show();
+    pListBox->GrabFocus();
 }
 
-CodeCompleteFloatWindow::~CodeCompleteFloatWindow()
+CodeCompleteWindow::~CodeCompleteWindow()
 {
     delete pListBox;
 }
 
-void CodeCompleteFloatWindow::InsertEntry( const OUString& aStr )
+void CodeCompleteWindow::InsertEntry( const OUString& aStr )
 {
     pListBox->InsertEntry( aStr );
 }
 
-void CodeCompleteFloatWindow::ClearListBox()
+void CodeCompleteWindow::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 )
+void CodeCompleteWindow::KeyInput( const KeyEvent& rKeyEvt )
 {
+    std::cerr << "CodeCompleteWindow::KeyInput" << std::endl;
     if( rKeyEvt.GetKeyCode().GetCode() == KEY_ESCAPE )
     {// ESC key closes the window: does not modify anything
         pParent->GetEditView()->EnableCursor( true );
@@ -2451,18 +2462,36 @@ void CodeCompleteFloatWindow::KeyInput( const KeyEvent& rKeyEvt )
     }
 }
 
-void CodeCompleteFloatWindow::SetTextSelection( const TextSelection& aSel )
+void CodeCompleteWindow::SetTextSelection( const TextSelection& aSel )
 {
     aTextSelection = aSel;
 }
 
-void CodeCompleteFloatWindow::ResizeListBox()
+const TextSelection& CodeCompleteWindow::GetTextSelection() const
+{
+    return aTextSelection;
+}
+
+void CodeCompleteWindow::ResizeListBox()
 {
-    Size aSize = pListBox->CalcMinimumSize();
-    const Font& aFont = pListBox->GetUnzoomedControlPointFont();
-    aSize.setHeight( aFont.GetSize().getHeight() * 16 );
-    pListBox->SetSizePixel( aSize );
-    SetSizePixel( aSize );
+    if( pListBox->GetEntryCount() > 0 )
+    {// if there is at least one element inside
+        OUString aLongestEntry = pListBox->GetEntry( 0 );//grab the longest one: max search
+        for( sal_uInt16 i=0; i< pListBox->GetEntryCount(); ++i )
+        {
+            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


More information about the Libreoffice-commits mailing list