xref: /trunk/main/basctl/source/basicide/objdlg.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_basctl.hxx"
26 
27 #include <ide_pch.hxx>
28 
29 
30 #include <basic/sbx.hxx>
31 #ifndef _SV_CMDEVT_HXX
32 #include <vcl/cmdevt.hxx>
33 #endif
34 #include <vcl/taskpanelist.hxx>
35 #include <vcl/sound.hxx>
36 #include <objdlg.hrc>
37 #include <objdlg.hxx>
38 #include <bastypes.hxx>
39 #include <basidesh.hrc>
40 #include <basidesh.hxx>
41 #include <iderdll.hxx>
42 #include <iderdll2.hxx>
43 #include <sbxitem.hxx>
44 
45 //#ifndef _SFX_HELP_HXX //autogen
46 //#include <sfx2/sfxhelp.hxx>
47 //#endif
48 
49 
ObjectTreeListBox(Window * pParent,const ResId & rRes)50 ObjectTreeListBox::ObjectTreeListBox( Window* pParent, const ResId& rRes )
51     : BasicTreeListBox( pParent, rRes )
52 {
53 }
54 
~ObjectTreeListBox()55 ObjectTreeListBox::~ObjectTreeListBox()
56 {
57 }
58 
Command(const CommandEvent &)59 void ObjectTreeListBox::Command( const CommandEvent& )
60 {
61 }
62 
MouseButtonDown(const MouseEvent & rMEvt)63 void ObjectTreeListBox::MouseButtonDown( const MouseEvent& rMEvt )
64 {
65     BasicTreeListBox::MouseButtonDown( rMEvt );
66 
67     if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) )
68     {
69         OpenCurrent();
70     }
71 }
72 
KeyInput(const KeyEvent & rEvt)73 void ObjectTreeListBox::KeyInput( const KeyEvent& rEvt )
74 {
75     if ( rEvt.GetKeyCode() == KEY_RETURN && OpenCurrent() )
76     {
77         return;
78     }
79     BasicTreeListBox::KeyInput( rEvt );
80 }
81 
OpenCurrent()82 bool ObjectTreeListBox::OpenCurrent()
83 {
84     BasicEntryDescriptor aDesc( GetEntryDescriptor( GetCurEntry() ) );
85 
86     if ( aDesc.GetType() == OBJ_TYPE_METHOD )
87     {
88         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
89         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
90         SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
91         if( pDispatcher )
92         {
93             SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), aDesc.GetName(),
94                               aDesc.GetMethodName(), ConvertType( aDesc.GetType() ) );
95             pDispatcher->Execute( SID_BASICIDE_SHOWSBX,
96                                     SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
97             return true;
98         }
99     }
100     return false;
101 }
102 
103 
ObjectCatalog(Window * pParent)104 ObjectCatalog::ObjectCatalog( Window * pParent )
105     :FloatingWindow( pParent, IDEResId( RID_BASICIDE_OBJCAT ) )
106     ,aMacroTreeList( this, IDEResId( RID_TLB_MACROS ) )
107     ,aToolBox(this, IDEResId(RID_TB_TOOLBOX), IDEResId(RID_IMGLST_TB_HC))
108     ,aMacroDescr( this, IDEResId( RID_FT_MACRODESCR ) )
109 {
110     FreeResource();
111 
112     aToolBox.SetOutStyle( TOOLBOX_STYLE_FLAT );
113     aToolBox.SetSizePixel( aToolBox.CalcWindowSizePixel() );
114     aToolBox.SetSelectHdl( LINK( this, ObjectCatalog, ToolBoxHdl ) );
115 
116     aMacroTreeList.SetStyle( WB_BORDER | WB_TABSTOP |
117                              WB_HASLINES | WB_HASLINESATROOT |
118                              WB_HASBUTTONS | WB_HASBUTTONSATROOT |
119                              WB_HSCROLL );
120 
121     aMacroTreeList.SetSelectHdl( LINK( this, ObjectCatalog, TreeListHighlightHdl ) );
122     aMacroTreeList.SetAccessibleName(String(IDEResId(RID_STR_TLB_MACROS)));
123     aMacroTreeList.ScanAllEntries();
124     aMacroTreeList.GrabFocus();
125 
126     CheckButtons();
127 
128     Point aPos = IDE_DLL()->GetExtraData()->GetObjectCatalogPos();
129     Size aSize = IDE_DLL()->GetExtraData()->GetObjectCatalogSize();
130     if ( aPos.X() == INVPOSITION )
131     {
132         // Zentriert nach AppWin:
133         Window* pWin = GetParent();
134         aPos = pWin->OutputToScreenPixel( Point( 0, 0 ) );
135         Size aAppWinSz = pWin->GetSizePixel();
136         Size aDlgWinSz = GetSizePixel();
137         aPos.X() += aAppWinSz.Width() / 2;
138         aPos.X() -= aDlgWinSz.Width() / 2;
139         aPos.Y() += aAppWinSz.Height() / 2;
140         aPos.Y() -= aDlgWinSz.Height() / 2;
141     }
142     SetPosPixel( aPos );
143     if ( aSize.Width() )
144         SetOutputSizePixel( aSize );
145 
146     Resize();   // damit der Resize-Handler die Controls anordnet
147 
148     // make object catalog keyboard accessible
149     pParent->GetSystemWindow()->GetTaskPaneList()->AddWindow( this );
150 }
151 
~ObjectCatalog()152 ObjectCatalog::~ObjectCatalog()
153 {
154     GetParent()->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( this );
155 }
156 
Move()157 void __EXPORT ObjectCatalog::Move()
158 {
159     IDE_DLL()->GetExtraData()->SetObjectCatalogPos( GetPosPixel() );
160 }
161 
Close()162 sal_Bool __EXPORT ObjectCatalog::Close()
163 {
164     aCancelHdl.Call( this );
165     return sal_True;
166 }
167 
Resize()168 void __EXPORT ObjectCatalog::Resize()
169 {
170     Size aOutSz = GetOutputSizePixel();
171     IDE_DLL()->GetExtraData()->SetObjectCatalogSize( aOutSz );
172 
173     Point aTreePos = aMacroTreeList.GetPosPixel();
174     Size aDescrSz = aMacroDescr.GetSizePixel();
175 
176     Size aTreeSz;
177     long nCtrlWidth = aOutSz.Width() - 2*aTreePos.X();
178     aTreeSz.Width() = nCtrlWidth;
179     aTreeSz.Height() = aOutSz.Height() - aTreePos.Y() -
180                         2*aTreePos.X() - aDescrSz.Height();
181 
182     if ( aTreeSz.Height() > 0 )
183     {
184         aMacroTreeList.SetSizePixel( aTreeSz );
185 
186         Point aDescrPos( aTreePos.X(), aTreePos.Y()+aTreeSz.Height()+aTreePos.X() );
187 
188         aMacroDescr.SetPosSizePixel( aDescrPos, Size( nCtrlWidth, aDescrSz.Height() ) );
189 
190         String aDesc = aMacroDescr.GetText();
191         aMacroDescr.SetText(String());
192         aMacroDescr.SetText(aDesc);
193     }
194 
195     // Die Buttons oben bleiben immer unveraendert stehen...
196 }
197 
IMPL_LINK(ObjectCatalog,ToolBoxHdl,ToolBox *,pToolBox)198 IMPL_LINK( ObjectCatalog, ToolBoxHdl, ToolBox*, pToolBox )
199 {
200     sal_uInt16 nCurItem = pToolBox->GetCurItemId();
201     switch ( nCurItem )
202     {
203         case TBITEM_SHOW:
204         {
205             SfxAllItemSet aArgs( SFX_APP()->GetPool() );
206             SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
207             SFX_APP()->ExecuteSlot( aRequest );
208 
209             SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry();
210             DBG_ASSERT( pCurEntry, "Entry?!" );
211             BasicEntryDescriptor aDesc( aMacroTreeList.GetEntryDescriptor( pCurEntry ) );
212             BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
213             SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
214             SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
215             if ( aDesc.GetType() == OBJ_TYPE_MODULE ||
216                  aDesc.GetType() == OBJ_TYPE_DIALOG ||
217                  aDesc.GetType() == OBJ_TYPE_METHOD )
218             {
219                 if( pDispatcher )
220                 {
221                     SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), aDesc.GetName(),
222                                       aDesc.GetMethodName(), aMacroTreeList.ConvertType( aDesc.GetType() ) );
223                     pDispatcher->Execute( SID_BASICIDE_SHOWSBX,
224                                           SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
225                 }
226             }
227             else
228             {
229                 ErrorBox( this, WB_OK, String( IDEResId( RID_STR_OBJNOTFOUND ) ) ).Execute();
230                 aMacroTreeList.GetModel()->Remove( pCurEntry );
231                 CheckButtons();
232             }
233         }
234         break;
235     }
236 
237     return 0;
238 }
239 
240 
241 
CheckButtons()242 void ObjectCatalog::CheckButtons()
243 {
244     SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry();
245     BasicEntryType eType = pCurEntry ? ((BasicEntry*)pCurEntry->GetUserData())->GetType() : OBJ_TYPE_UNKNOWN;
246     if ( eType == OBJ_TYPE_DIALOG || eType == OBJ_TYPE_MODULE || eType == OBJ_TYPE_METHOD )
247         aToolBox.EnableItem( TBITEM_SHOW, sal_True );
248     else
249         aToolBox.EnableItem( TBITEM_SHOW, sal_False );
250 }
251 
252 
253 
IMPL_LINK_INLINE_START(ObjectCatalog,TreeListHighlightHdl,SvTreeListBox *,pBox)254 IMPL_LINK_INLINE_START( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox )
255 {
256     if ( pBox->IsSelected( pBox->GetHdlEntry() ) )
257         UpdateFields();
258     return 0;
259 }
IMPL_LINK_INLINE_END(ObjectCatalog,TreeListHighlightHdl,SvTreeListBox *,pBox)260 IMPL_LINK_INLINE_END( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox )
261 
262 
263 void ObjectCatalog::UpdateFields()
264 {
265     SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry();
266     if ( pCurEntry )
267     {
268         CheckButtons();
269         aMacroDescr.SetText( String() );
270         SbxVariable* pVar = aMacroTreeList.FindVariable( pCurEntry );
271         if ( pVar )
272         {
273             SbxInfoRef xInfo = pVar->GetInfo();
274             if ( xInfo.Is() )
275                 aMacroDescr.SetText( xInfo->GetComment() );
276         }
277     }
278 }
279 
280 
UpdateEntries()281 void ObjectCatalog::UpdateEntries()
282 {
283     aMacroTreeList.UpdateEntries();
284 }
285 
SetCurrentEntry(BasicEntryDescriptor & rDesc)286 void ObjectCatalog::SetCurrentEntry( BasicEntryDescriptor& rDesc )
287 {
288     aMacroTreeList.SetCurrentEntry( rDesc );
289 }
290 
ObjectCatalogToolBox_Impl(Window * pParent,ResId const & rResId,ResId const & rImagesHighContrastId)291 ObjectCatalogToolBox_Impl::ObjectCatalogToolBox_Impl(
292     Window * pParent, ResId const & rResId,
293     ResId const & rImagesHighContrastId):
294     ToolBox(pParent, rResId),
295     m_aImagesNormal(GetImageList()),
296     m_aImagesHighContrast(rImagesHighContrastId),
297     m_bHighContrast(false)
298 {
299     setImages();
300 }
301 
302 // virtual
DataChanged(DataChangedEvent const & rDCEvt)303 void ObjectCatalogToolBox_Impl::DataChanged(DataChangedEvent const & rDCEvt)
304 {
305     ToolBox::DataChanged(rDCEvt);
306     if ((rDCEvt.GetType() == DATACHANGED_SETTINGS
307          || rDCEvt.GetType() == DATACHANGED_DISPLAY)
308         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
309         setImages();
310 }
311 
setImages()312 void ObjectCatalogToolBox_Impl::setImages()
313 {
314     bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
315     if (bHC != m_bHighContrast)
316     {
317         SetImageList(bHC ? m_aImagesHighContrast : m_aImagesNormal);
318         m_bHighContrast = bHC;
319     }
320 }
321