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