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