1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir #ifndef DBAUI_APPICONCONTROL_HXX
31*cdf0e10cSrcweir #include "AppIconControl.hxx"
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
34*cdf0e10cSrcweir #include <tools/debug.hxx>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
37*cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_
40*cdf0e10cSrcweir #include "moduledbu.hxx"
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #ifndef _DBU_APP_HRC_
43*cdf0e10cSrcweir #include "dbu_app.hrc"
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef _IMAGE_HXX //autogen
46*cdf0e10cSrcweir #include <vcl/image.hxx>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #ifndef _DBACCESS_UI_CALLBACKS_HXX_
49*cdf0e10cSrcweir #include "callbacks.hxx"
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir #ifndef DBAUI_APPELEMENTTYPE_HXX
52*cdf0e10cSrcweir #include "AppElementType.hxx"
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir #include <memory>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace ::dbaui;
57*cdf0e10cSrcweir //==================================================================
58*cdf0e10cSrcweir // class OApplicationIconControl
59*cdf0e10cSrcweir DBG_NAME(OApplicationIconControl)
60*cdf0e10cSrcweir //==================================================================
61*cdf0e10cSrcweir OApplicationIconControl::OApplicationIconControl(Window* _pParent)
62*cdf0e10cSrcweir 	: SvtIconChoiceCtrl(_pParent,WB_ICON | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /*!WB_NOSELECTION |*/
63*cdf0e10cSrcweir 								WB_TABSTOP | WB_CLIPCHILDREN | WB_NOVSCROLL | WB_SMART_ARRANGE | WB_NOHSCROLL | WB_CENTER)
64*cdf0e10cSrcweir 	,DropTargetHelper(this)
65*cdf0e10cSrcweir 	,m_pActionListener(NULL)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     DBG_CTOR(OApplicationIconControl,NULL);
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     struct CategoryDescriptor
70*cdf0e10cSrcweir     {
71*cdf0e10cSrcweir         sal_uInt16      nLabelResId;
72*cdf0e10cSrcweir         ElementType eType;
73*cdf0e10cSrcweir         sal_uInt16      nImageResId;
74*cdf0e10cSrcweir         sal_uInt16      nImageResIdHC;
75*cdf0e10cSrcweir     }   aCategories[] = {
76*cdf0e10cSrcweir         { RID_STR_TABLES_CONTAINER,     E_TABLE,    IMG_TABLEFOLDER_TREE_L, IMG_TABLEFOLDER_TREE_LHC    },
77*cdf0e10cSrcweir         { RID_STR_QUERIES_CONTAINER,    E_QUERY,    IMG_QUERYFOLDER_TREE_L, IMG_QUERYFOLDER_TREE_LHC    },
78*cdf0e10cSrcweir 		{ RID_STR_FORMS_CONTAINER,      E_FORM,     IMG_FORMFOLDER_TREE_L,  IMG_FORMFOLDER_TREE_LHC     },
79*cdf0e10cSrcweir         { RID_STR_REPORTS_CONTAINER,    E_REPORT,   IMG_REPORTFOLDER_TREE_L,IMG_REPORTFOLDER_TREE_LHC   }
80*cdf0e10cSrcweir     };
81*cdf0e10cSrcweir     for ( size_t i=0; i < sizeof(aCategories)/sizeof(aCategories[0]); ++i)
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir         SvxIconChoiceCtrlEntry* pEntry = InsertEntry(
84*cdf0e10cSrcweir             String( ModuleRes( aCategories[i].nLabelResId ) ),
85*cdf0e10cSrcweir             Image( ModuleRes( aCategories[i].nImageResId ) ),
86*cdf0e10cSrcweir             Image( ModuleRes( aCategories[i].nImageResIdHC ) ) );
87*cdf0e10cSrcweir         if ( pEntry )
88*cdf0e10cSrcweir             pEntry->SetUserData( new ElementType( aCategories[i].eType ) );
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	SetChoiceWithCursor( sal_True );
92*cdf0e10cSrcweir 	SetSelectionMode(SINGLE_SELECTION);
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir // -----------------------------------------------------------------------------
95*cdf0e10cSrcweir OApplicationIconControl::~OApplicationIconControl()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir 	sal_uLong nCount = GetEntryCount();
98*cdf0e10cSrcweir 	for ( sal_uLong i = 0; i < nCount; ++i )
99*cdf0e10cSrcweir 	{
100*cdf0e10cSrcweir 		SvxIconChoiceCtrlEntry* pEntry = GetEntry( i );
101*cdf0e10cSrcweir 		if ( pEntry )
102*cdf0e10cSrcweir 		{
103*cdf0e10cSrcweir 			::std::auto_ptr<ElementType> aType(static_cast<ElementType*>(pEntry->GetUserData()));
104*cdf0e10cSrcweir 			pEntry->SetUserData(NULL);
105*cdf0e10cSrcweir 		}
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     DBG_DTOR(OApplicationIconControl,NULL);
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir // -----------------------------------------------------------------------------
111*cdf0e10cSrcweir sal_Int8 OApplicationIconControl::AcceptDrop( const AcceptDropEvent& _rEvt )
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	sal_Int8 nDropOption = DND_ACTION_NONE;
114*cdf0e10cSrcweir 	if ( m_pActionListener )
115*cdf0e10cSrcweir 	{
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 		SvxIconChoiceCtrlEntry*	pEntry = GetEntry(_rEvt.maPosPixel);
118*cdf0e10cSrcweir 		if ( pEntry )
119*cdf0e10cSrcweir 		{
120*cdf0e10cSrcweir 			SetCursor(pEntry);
121*cdf0e10cSrcweir 			nDropOption = m_pActionListener->queryDrop( _rEvt, GetDataFlavorExVector() );
122*cdf0e10cSrcweir 			m_aMousePos = _rEvt.maPosPixel;
123*cdf0e10cSrcweir 		}
124*cdf0e10cSrcweir 	}
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	return nDropOption;
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir // -----------------------------------------------------------------------------
129*cdf0e10cSrcweir sal_Int8 OApplicationIconControl::ExecuteDrop( const ExecuteDropEvent& _rEvt )
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir 	if ( m_pActionListener )
132*cdf0e10cSrcweir 		return m_pActionListener->executeDrop( _rEvt );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	return DND_ACTION_NONE;
135*cdf0e10cSrcweir }
136