xref: /aoo4110/main/sc/source/ui/miscdlgs/namepast.cxx (revision b1cdbd2c)
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_sc.hxx"
26 
27 #undef SC_DLLIMPLEMENTATION
28 
29 
30 
31 //------------------------------------------------------------------
32 
33 #include "namepast.hxx"
34 #include "scresid.hxx"
35 #include "miscdlgs.hrc"
36 #include "rangenam.hxx"
37 
38 
39 //==================================================================
40 
ScNamePasteDlg(Window * pParent,const ScRangeName * pList,sal_Bool bInsList)41 ScNamePasteDlg::ScNamePasteDlg( Window * pParent, const ScRangeName* pList, sal_Bool bInsList )
42 	: ModalDialog( pParent, ScResId( RID_SCDLG_NAMES_PASTE ) ),
43 	aLabelText		( this, ScResId( FT_LABEL ) ),
44 	aNameList		( this, ScResId( LB_ENTRYLIST ) ),
45 	aOKButton		( this, ScResId( BTN_OK ) ),
46 	aCancelButton	( this, ScResId( BTN_CANCEL ) ),
47 	aHelpButton		( this, ScResId( BTN_HELP ) ),
48 	aInsListButton	( this, ScResId( BTN_ADD ) )
49 {
50 	if( ! bInsList )
51 		aInsListButton.Disable();
52 
53 	aInsListButton.SetClickHdl( LINK( this,ScNamePasteDlg,ButtonHdl) );
54 	aOKButton.SetClickHdl( LINK( this,ScNamePasteDlg,ButtonHdl) );
55 	aNameList.SetSelectHdl( LINK( this,ScNamePasteDlg,ListSelHdl) );
56 	aNameList.SetDoubleClickHdl( LINK( this,ScNamePasteDlg,ListDblClickHdl) );
57 
58 	sal_uInt16	nCnt = pList->GetCount();
59 	String	aText;
60 
61 	for( sal_uInt16 i=0 ; i<nCnt ; i++ )
62 	{
63 		ScRangeData* pData = (*pList)[ i ];
64 
65 		if( pData )
66 		{
67 			if (   !pData->HasType( RT_DATABASE )
68 				&& !pData->HasType( RT_SHARED ) )
69 			{
70 				pData->GetName( aText );
71 				aNameList.InsertEntry( aText );
72 			}
73 		}
74 	}
75 
76 	ListSelHdl( &aNameList );
77 
78 	FreeResource();
79 }
80 
81 //------------------------------------------------------------------
82 
IMPL_LINK(ScNamePasteDlg,ButtonHdl,Button *,pButton)83 IMPL_LINK( ScNamePasteDlg, ButtonHdl, Button *, pButton )
84 {
85 	if( pButton == &aInsListButton )
86 	{
87 		EndDialog( BTN_PASTE_LIST );
88 	}
89 	else if( pButton == &aOKButton )
90 	{
91 		EndDialog( BTN_PASTE_NAME );
92 	}
93 	return 0;
94 }
95 
96 //------------------------------------------------------------------
97 
IMPL_LINK(ScNamePasteDlg,ListSelHdl,ListBox *,pListBox)98 IMPL_LINK( ScNamePasteDlg, ListSelHdl, ListBox *, pListBox )
99 {
100 	if( pListBox == &aNameList )
101 	{
102 		if( aNameList.GetSelectEntryCount() )
103 			aOKButton.Enable();
104 		else
105 			aOKButton.Disable();
106 	}
107 	return 0;
108 }
109 
110 //------------------------------------------------------------------
111 
IMPL_LINK_INLINE_START(ScNamePasteDlg,ListDblClickHdl,ListBox *,pListBox)112 IMPL_LINK_INLINE_START( ScNamePasteDlg, ListDblClickHdl, ListBox *, pListBox )
113 {
114 	if( pListBox == &aNameList )
115 	{
116 		ButtonHdl( &aOKButton );
117 	}
118 	return 0;
119 }
IMPL_LINK_INLINE_END(ScNamePasteDlg,ListDblClickHdl,ListBox *,pListBox)120 IMPL_LINK_INLINE_END( ScNamePasteDlg, ListDblClickHdl, ListBox *, pListBox )
121 
122 //------------------------------------------------------------------
123 
124 String ScNamePasteDlg::GetSelectedName() const
125 {
126 	return aNameList.GetSelectEntry();
127 }
128 
129 
130