xref: /aoo42x/main/basctl/source/basicide/objdlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basctl.hxx"
30 
31 #include <ide_pch.hxx>
32 
33 
34 #include <basic/sbx.hxx>
35 #ifndef _SV_CMDEVT_HXX
36 #include <vcl/cmdevt.hxx>
37 #endif
38 #include <vcl/taskpanelist.hxx>
39 #include <vcl/sound.hxx>
40 #include <objdlg.hrc>
41 #include <objdlg.hxx>
42 #include <bastypes.hxx>
43 #include <basidesh.hrc>
44 #include <basidesh.hxx>
45 #include <iderdll.hxx>
46 #include <iderdll2.hxx>
47 #include <sbxitem.hxx>
48 
49 //#ifndef _SFX_HELP_HXX //autogen
50 //#include <sfx2/sfxhelp.hxx>
51 //#endif
52 
53 
54 ObjectTreeListBox::ObjectTreeListBox( Window* pParent, const ResId& rRes )
55 	: BasicTreeListBox( pParent, rRes )
56 {
57 }
58 
59 ObjectTreeListBox::~ObjectTreeListBox()
60 {
61 }
62 
63 void ObjectTreeListBox::Command( const CommandEvent& )
64 {
65 }
66 
67 void ObjectTreeListBox::MouseButtonDown( const MouseEvent& rMEvt )
68 {
69 	BasicTreeListBox::MouseButtonDown( rMEvt );
70 
71 	if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) )
72 	{
73         BasicEntryDescriptor aDesc( GetEntryDescriptor( GetCurEntry() ) );
74 
75 		if ( aDesc.GetType() == OBJ_TYPE_METHOD )
76 		{
77             BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
78             SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
79 	        SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
80             if( pDispatcher )
81 			{
82                 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), aDesc.GetName(),
83                                   aDesc.GetMethodName(), ConvertType( aDesc.GetType() ) );
84 				pDispatcher->Execute( SID_BASICIDE_SHOWSBX,
85 										SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
86 			}
87 		}
88 	}
89 }
90 
91 
92 
93 ObjectCatalog::ObjectCatalog( Window * pParent )
94     :FloatingWindow( pParent, IDEResId( RID_BASICIDE_OBJCAT ) )
95     ,aMacroTreeList( this, IDEResId( RID_TLB_MACROS ) )
96     ,aToolBox(this, IDEResId(RID_TB_TOOLBOX), IDEResId(RID_IMGLST_TB_HC))
97     ,aMacroDescr( this, IDEResId( RID_FT_MACRODESCR ) )
98 {
99 	FreeResource();
100 
101     aToolBox.SetOutStyle( TOOLBOX_STYLE_FLAT );
102 	aToolBox.SetSizePixel( aToolBox.CalcWindowSizePixel() );
103 	aToolBox.SetSelectHdl( LINK( this, ObjectCatalog, ToolBoxHdl ) );
104 
105     aMacroTreeList.SetStyle( WB_BORDER | WB_TABSTOP |
106                              WB_HASLINES | WB_HASLINESATROOT |
107                              WB_HASBUTTONS | WB_HASBUTTONSATROOT |
108                              WB_HSCROLL );
109 
110 	aMacroTreeList.SetSelectHdl( LINK( this, ObjectCatalog, TreeListHighlightHdl ) );
111 	aMacroTreeList.SetAccessibleName(String(IDEResId(RID_STR_TLB_MACROS)));
112 	aMacroTreeList.ScanAllEntries();
113 	aMacroTreeList.GrabFocus();
114 
115 	CheckButtons();
116 
117 	Point aPos = IDE_DLL()->GetExtraData()->GetObjectCatalogPos();
118 	Size aSize = IDE_DLL()->GetExtraData()->GetObjectCatalogSize();
119 	if ( aPos.X() == INVPOSITION )
120 	{
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;
130 	}
131 	SetPosPixel( aPos );
132 	if ( aSize.Width() )
133 		SetOutputSizePixel( aSize );
134 
135 	Resize();	// damit der Resize-Handler die Controls anordnet
136 
137 	// make object catalog keyboard accessible
138 	pParent->GetSystemWindow()->GetTaskPaneList()->AddWindow( this );
139 }
140 
141 ObjectCatalog::~ObjectCatalog()
142 {
143 	GetParent()->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( this );
144 }
145 
146 void __EXPORT ObjectCatalog::Move()
147 {
148 	IDE_DLL()->GetExtraData()->SetObjectCatalogPos( GetPosPixel() );
149 }
150 
151 sal_Bool __EXPORT ObjectCatalog::Close()
152 {
153 	aCancelHdl.Call( this );
154 	return sal_True;
155 }
156 
157 void __EXPORT ObjectCatalog::Resize()
158 {
159 	Size aOutSz = GetOutputSizePixel();
160 	IDE_DLL()->GetExtraData()->SetObjectCatalogSize( aOutSz );
161 
162 	Point aTreePos = aMacroTreeList.GetPosPixel();
163 	Size aDescrSz = aMacroDescr.GetSizePixel();
164 
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();
170 
171 	if ( aTreeSz.Height() > 0 )
172 	{
173 		aMacroTreeList.SetSizePixel( aTreeSz );
174 
175 		Point aDescrPos( aTreePos.X(), aTreePos.Y()+aTreeSz.Height()+aTreePos.X() );
176 
177 		aMacroDescr.SetPosSizePixel( aDescrPos, Size( nCtrlWidth, aDescrSz.Height() ) );
178 
179 		String aDesc = aMacroDescr.GetText();
180 		aMacroDescr.SetText(String());
181 		aMacroDescr.SetText(aDesc);
182 	}
183 
184 	// Die Buttons oben bleiben immer unveraendert stehen...
185 }
186 
187 IMPL_LINK( ObjectCatalog, ToolBoxHdl, ToolBox*, pToolBox )
188 {
189 	sal_uInt16 nCurItem = pToolBox->GetCurItemId();
190 	switch ( nCurItem )
191 	{
192 		case TBITEM_SHOW:
193 		{
194             SfxAllItemSet aArgs( SFX_APP()->GetPool() );
195             SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
196             SFX_APP()->ExecuteSlot( aRequest );
197 
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 )
207 			{
208 				if( pDispatcher )
209 				{
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 );
214 				}
215 			}
216 			else
217 			{
218 				ErrorBox( this, WB_OK, String( IDEResId( RID_STR_OBJNOTFOUND ) ) ).Execute();
219 				aMacroTreeList.GetModel()->Remove( pCurEntry );
220 				CheckButtons();
221 			}
222 		}
223 		break;
224 	}
225 
226 	return 0;
227 }
228 
229 
230 
231 void ObjectCatalog::CheckButtons()
232 {
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, sal_True );
237 	else
238 		aToolBox.EnableItem( TBITEM_SHOW, sal_False );
239 }
240 
241 
242 
243 IMPL_LINK_INLINE_START( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox )
244 {
245 	if ( pBox->IsSelected( pBox->GetHdlEntry() ) )
246 		UpdateFields();
247 	return 0;
248 }
249 IMPL_LINK_INLINE_END( ObjectCatalog, TreeListHighlightHdl, SvTreeListBox *, pBox )
250 
251 
252 void ObjectCatalog::UpdateFields()
253 {
254 	SvLBoxEntry* pCurEntry = aMacroTreeList.GetCurEntry();
255 	if ( pCurEntry )
256 	{
257 		CheckButtons();
258 		aMacroDescr.SetText( String() );
259 		SbxVariable* pVar = aMacroTreeList.FindVariable( pCurEntry );
260 		if ( pVar )
261 		{
262 			SbxInfoRef xInfo = pVar->GetInfo();
263 			if ( xInfo.Is() )
264 				aMacroDescr.SetText( xInfo->GetComment() );
265 		}
266     }
267 }
268 
269 
270 void ObjectCatalog::UpdateEntries()
271 {
272 	aMacroTreeList.UpdateEntries();
273 }
274 
275 void ObjectCatalog::SetCurrentEntry( BasicEntryDescriptor& rDesc )
276 {
277     aMacroTreeList.SetCurrentEntry( rDesc );
278 }
279 
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)
287 {
288     setImages();
289 }
290 
291 // virtual
292 void ObjectCatalogToolBox_Impl::DataChanged(DataChangedEvent const & rDCEvt)
293 {
294     ToolBox::DataChanged(rDCEvt);
295     if ((rDCEvt.GetType() == DATACHANGED_SETTINGS
296          || rDCEvt.GetType() == DATACHANGED_DISPLAY)
297         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
298         setImages();
299 }
300 
301 void ObjectCatalogToolBox_Impl::setImages()
302 {
303     bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
304     if (bHC != m_bHighContrast)
305     {
306         SetImageList(bHC ? m_aImagesHighContrast : m_aImagesNormal);
307         m_bHighContrast = bHC;
308     }
309 }
310