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_dbaccess.hxx"
30 #ifndef DBAUI_APPICONCONTROL_HXX
31 #include "AppIconControl.hxx"
32 #endif
33 #ifndef _TOOLS_DEBUG_HXX
34 #include <tools/debug.hxx>
35 #endif
36 #ifndef _DBA_DBACCESS_HELPID_HRC_
37 #include "dbaccess_helpid.hrc"
38 #endif
39 #ifndef _DBAUI_MODULE_DBU_HXX_
40 #include "moduledbu.hxx"
41 #endif
42 #ifndef _DBU_APP_HRC_
43 #include "dbu_app.hrc"
44 #endif
45 #ifndef _IMAGE_HXX //autogen
46 #include <vcl/image.hxx>
47 #endif
48 #ifndef _DBACCESS_UI_CALLBACKS_HXX_
49 #include "callbacks.hxx"
50 #endif
51 #ifndef DBAUI_APPELEMENTTYPE_HXX
52 #include "AppElementType.hxx"
53 #endif
54 #include <memory>
55 
56 using namespace ::dbaui;
57 //==================================================================
58 // class OApplicationIconControl
59 DBG_NAME(OApplicationIconControl)
60 //==================================================================
61 OApplicationIconControl::OApplicationIconControl(Window* _pParent)
62 	: SvtIconChoiceCtrl(_pParent,WB_ICON | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /*!WB_NOSELECTION |*/
63 								WB_TABSTOP | WB_CLIPCHILDREN | WB_NOVSCROLL | WB_SMART_ARRANGE | WB_NOHSCROLL | WB_CENTER)
64 	,DropTargetHelper(this)
65 	,m_pActionListener(NULL)
66 {
67     DBG_CTOR(OApplicationIconControl,NULL);
68 
69     struct CategoryDescriptor
70     {
71         sal_uInt16      nLabelResId;
72         ElementType eType;
73         sal_uInt16      nImageResId;
74         sal_uInt16      nImageResIdHC;
75     }   aCategories[] = {
76         { RID_STR_TABLES_CONTAINER,     E_TABLE,    IMG_TABLEFOLDER_TREE_L, IMG_TABLEFOLDER_TREE_LHC    },
77         { RID_STR_QUERIES_CONTAINER,    E_QUERY,    IMG_QUERYFOLDER_TREE_L, IMG_QUERYFOLDER_TREE_LHC    },
78 		{ RID_STR_FORMS_CONTAINER,      E_FORM,     IMG_FORMFOLDER_TREE_L,  IMG_FORMFOLDER_TREE_LHC     },
79         { RID_STR_REPORTS_CONTAINER,    E_REPORT,   IMG_REPORTFOLDER_TREE_L,IMG_REPORTFOLDER_TREE_LHC   }
80     };
81     for ( size_t i=0; i < sizeof(aCategories)/sizeof(aCategories[0]); ++i)
82     {
83         SvxIconChoiceCtrlEntry* pEntry = InsertEntry(
84             String( ModuleRes( aCategories[i].nLabelResId ) ),
85             Image( ModuleRes( aCategories[i].nImageResId ) ),
86             Image( ModuleRes( aCategories[i].nImageResIdHC ) ) );
87         if ( pEntry )
88             pEntry->SetUserData( new ElementType( aCategories[i].eType ) );
89     }
90 
91 	SetChoiceWithCursor( sal_True );
92 	SetSelectionMode(SINGLE_SELECTION);
93 }
94 // -----------------------------------------------------------------------------
95 OApplicationIconControl::~OApplicationIconControl()
96 {
97 	sal_uLong nCount = GetEntryCount();
98 	for ( sal_uLong i = 0; i < nCount; ++i )
99 	{
100 		SvxIconChoiceCtrlEntry* pEntry = GetEntry( i );
101 		if ( pEntry )
102 		{
103 			::std::auto_ptr<ElementType> aType(static_cast<ElementType*>(pEntry->GetUserData()));
104 			pEntry->SetUserData(NULL);
105 		}
106 	}
107 
108     DBG_DTOR(OApplicationIconControl,NULL);
109 }
110 // -----------------------------------------------------------------------------
111 sal_Int8 OApplicationIconControl::AcceptDrop( const AcceptDropEvent& _rEvt )
112 {
113 	sal_Int8 nDropOption = DND_ACTION_NONE;
114 	if ( m_pActionListener )
115 	{
116 
117 		SvxIconChoiceCtrlEntry*	pEntry = GetEntry(_rEvt.maPosPixel);
118 		if ( pEntry )
119 		{
120 			SetCursor(pEntry);
121 			nDropOption = m_pActionListener->queryDrop( _rEvt, GetDataFlavorExVector() );
122 			m_aMousePos = _rEvt.maPosPixel;
123 		}
124 	}
125 
126 	return nDropOption;
127 }
128 // -----------------------------------------------------------------------------
129 sal_Int8 OApplicationIconControl::ExecuteDrop( const ExecuteDropEvent& _rEvt )
130 {
131 	if ( m_pActionListener )
132 		return m_pActionListener->executeDrop( _rEvt );
133 
134 	return DND_ACTION_NONE;
135 }
136