Update ooo320-m1
[ooovba.git] / basctl / source / basicide / objdlg.cxx
blobd4eb16624de0b6246273ee41b14ba660207366ab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objdlg.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
34 #include <ide_pch.hxx>
37 #include <basic/sbx.hxx>
38 #ifndef _SV_CMDEVT_HXX
39 #include <vcl/cmdevt.hxx>
40 #endif
41 #include <vcl/taskpanelist.hxx>
42 #include <vcl/sound.hxx>
43 #include <objdlg.hrc>
44 #include <objdlg.hxx>
45 #include <bastypes.hxx>
46 #include <basidesh.hrc>
47 #include <basidesh.hxx>
48 #include <iderdll.hxx>
49 #include <iderdll2.hxx>
50 #include <sbxitem.hxx>
52 //#ifndef _SFX_HELP_HXX //autogen
53 //#include <sfx2/sfxhelp.hxx>
54 //#endif
57 ObjectTreeListBox::ObjectTreeListBox( Window* pParent, const ResId& rRes )
58 : BasicTreeListBox( pParent, rRes )
62 ObjectTreeListBox::~ObjectTreeListBox()
66 void ObjectTreeListBox::Command( const CommandEvent& )
70 void ObjectTreeListBox::MouseButtonDown( const MouseEvent& rMEvt )
72 BasicTreeListBox::MouseButtonDown( rMEvt );
74 if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) )
76 BasicEntryDescriptor aDesc( GetEntryDescriptor( GetCurEntry() ) );
78 if ( aDesc.GetType() == OBJ_TYPE_METHOD )
80 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
81 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
82 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
83 if( pDispatcher )
85 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), aDesc.GetName(),
86 aDesc.GetMethodName(), ConvertType( aDesc.GetType() ) );
87 pDispatcher->Execute( SID_BASICIDE_SHOWSBX,
88 SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
96 ObjectCatalog::ObjectCatalog( Window * pParent )
97 :FloatingWindow( pParent, IDEResId( RID_BASICIDE_OBJCAT ) )
98 ,aMacroTreeList( this, IDEResId( RID_TLB_MACROS ) )
99 ,aToolBox(this, IDEResId(RID_TB_TOOLBOX), IDEResId(RID_IMGLST_TB_HC))
100 ,aMacroDescr( this, IDEResId( RID_FT_MACRODESCR ) )
102 FreeResource();
104 aToolBox.SetOutStyle( TOOLBOX_STYLE_FLAT );
105 aToolBox.SetSizePixel( aToolBox.CalcWindowSizePixel() );
106 aToolBox.SetSelectHdl( LINK( this, ObjectCatalog, ToolBoxHdl ) );
108 aMacroTreeList.SetWindowBits( WB_HASLINES | WB_HASLINESATROOT |
109 WB_HASBUTTONS | WB_HASBUTTONSATROOT |
110 WB_HSCROLL );
112 aMacroTreeList.SetSelectHdl( LINK( this, ObjectCatalog, TreeListHighlightHdl ) );
114 aMacroTreeList.ScanAllEntries();
115 CheckButtons();
117 Point aPos = IDE_DLL()->GetExtraData()->GetObjectCatalogPos();
118 Size aSize = IDE_DLL()->GetExtraData()->GetObjectCatalogSize();
119 if ( aPos.X() == INVPOSITION )
121 // Zentriert nach AppWin:
122 Window* pWin = GetParent();
123 aPos = pWin->OutputToScreenPixel( Point( 0, 0 ) );
124 Size aAppWinSz = pWin->GetSizePixel();
125 Size aDlgWinSz = GetSizePixel();
126 aPos.X() += aAppWinSz.Width() / 2;
127 aPos.X() -= aDlgWinSz.Width() / 2;
128 aPos.Y() += aAppWinSz.Height() / 2;
129 aPos.Y() -= aDlgWinSz.Height() / 2;
131 SetPosPixel( aPos );
132 if ( aSize.Width() )
133 SetOutputSizePixel( aSize );
135 Resize(); // damit der Resize-Handler die Controls anordnet
137 // make object catalog keyboard accessible
138 pParent->GetSystemWindow()->GetTaskPaneList()->AddWindow( this );
141 ObjectCatalog::~ObjectCatalog()
143 GetParent()->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( this );
146 void __EXPORT ObjectCatalog::Move()
148 IDE_DLL()->GetExtraData()->SetObjectCatalogPos( GetPosPixel() );
151 BOOL __EXPORT ObjectCatalog::Close()
153 aCancelHdl.Call( this );
154 return TRUE;
157 void __EXPORT ObjectCatalog::Resize()
159 Size aOutSz = GetOutputSizePixel();
160 IDE_DLL()->GetExtraData()->SetObjectCatalogSize( aOutSz );
162 Point aTreePos = aMacroTreeList.GetPosPixel();
163 Size aDescrSz = aMacroDescr.GetSizePixel();
165 Size aTreeSz;
166 long nCtrlWidth = aOutSz.Width() - 2*aTreePos.X();
167 aTreeSz.Width() = nCtrlWidth;
168 aTreeSz.Height() = aOutSz.Height() - aTreePos.Y() -
169 2*aTreePos.X() - aDescrSz.Height();
171 if ( aTreeSz.Height() > 0 )
173 aMacroTreeList.SetSizePixel( aTreeSz );
175 Point aDescrPos( aTreePos.X(), aTreePos.Y()+aTreeSz.Height()+aTreePos.X() );
177 aMacroDescr.SetPosSizePixel( aDescrPos, Size( nCtrlWidth, aDescrSz.Height() ) );
179 String aDesc = aMacroDescr.GetText();
180 aMacroDescr.SetText(String());
181 aMacroDescr.SetText(aDesc);
184 // Die Buttons oben bleiben immer unveraendert stehen...
187 IMPL_LINK( ObjectCatalog, ToolBoxHdl, ToolBox*, pToolBox )
189 USHORT nCurItem = pToolBox->GetCurItemId();
190 switch ( nCurItem )
192 case TBITEM_SHOW:
194 SfxAllItemSet aArgs( SFX_APP()->GetPool() );
195 SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
196 SFX_APP()->ExecuteSlot( aRequest );
198 SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry();
199 DBG_ASSERT( pCurEntry, "Entry?!" );
200 BasicEntryDescriptor aDesc( aMacroTreeList.GetEntryDescriptor( pCurEntry ) );
201 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
202 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
203 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
204 if ( aDesc.GetType() == OBJ_TYPE_MODULE ||
205 aDesc.GetType() == OBJ_TYPE_DIALOG ||
206 aDesc.GetType() == OBJ_TYPE_METHOD )
208 if( pDispatcher )
210 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), aDesc.GetName(),
211 aDesc.GetMethodName(), aMacroTreeList.ConvertType( aDesc.GetType() ) );
212 pDispatcher->Execute( SID_BASICIDE_SHOWSBX,
213 SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
216 else
218 ErrorBox( this, WB_OK, String( IDEResId( RID_STR_OBJNOTFOUND ) ) ).Execute();
219 aMacroTreeList.GetModel()->Remove( pCurEntry );
220 CheckButtons();
223 break;
226 return 0;
231 void ObjectCatalog::CheckButtons()
233 SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry();
234 BasicEntryType eType = pCurEntry ? ((BasicEntry*)pCurEntry->GetUserData())->GetType() : OBJ_TYPE_UNKNOWN;
235 if ( eType == OBJ_TYPE_DIALOG || eType == OBJ_TYPE_MODULE || eType == OBJ_TYPE_METHOD )
236 aToolBox.EnableItem( TBITEM_SHOW, TRUE );
237 else
238 aToolBox.EnableItem( TBITEM_SHOW, FALSE );
243 IMPL_LINK_INLINE_START( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox )
245 if ( pBox->IsSelected( pBox->GetHdlEntry() ) )
246 UpdateFields();
247 return 0;
249 IMPL_LINK_INLINE_END( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox )
252 void ObjectCatalog::UpdateFields()
254 SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry();
255 if ( pCurEntry )
257 CheckButtons();
258 aMacroDescr.SetText( String() );
259 SbxVariable* pVar = aMacroTreeList.FindVariable( pCurEntry );
260 if ( pVar )
262 SbxInfoRef xInfo = pVar->GetInfo();
263 if ( xInfo.Is() )
264 aMacroDescr.SetText( xInfo->GetComment() );
270 void ObjectCatalog::UpdateEntries()
272 aMacroTreeList.UpdateEntries();
275 void ObjectCatalog::SetCurrentEntry( BasicEntryDescriptor& rDesc )
277 aMacroTreeList.SetCurrentEntry( rDesc );
280 ObjectCatalogToolBox_Impl::ObjectCatalogToolBox_Impl(
281 Window * pParent, ResId const & rResId,
282 ResId const & rImagesHighContrastId):
283 ToolBox(pParent, rResId),
284 m_aImagesNormal(GetImageList()),
285 m_aImagesHighContrast(rImagesHighContrastId),
286 m_bHighContrast(false)
288 setImages();
291 // virtual
292 void ObjectCatalogToolBox_Impl::DataChanged(DataChangedEvent const & rDCEvt)
294 ToolBox::DataChanged(rDCEvt);
295 if ((rDCEvt.GetType() == DATACHANGED_SETTINGS
296 || rDCEvt.GetType() == DATACHANGED_DISPLAY)
297 && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
298 setImages();
301 void ObjectCatalogToolBox_Impl::setImages()
303 bool bHC = GetDisplayBackground().GetColor().IsDark();
304 if (bHC != m_bHighContrast)
306 SetImageList(bHC ? m_aImagesHighContrast : m_aImagesNormal);
307 m_bHighContrast = bHC;