xref: /aoo42x/main/cui/source/dialogs/dlgname.cxx (revision 2ee96f1c)
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_cui.hxx"
26 
27 #include <tools/ref.hxx>
28 #include <tools/list.hxx>
29 #include <tools/shl.hxx>
30 #include <tools/debug.hxx>
31 #include <vcl/msgbox.hxx>
32 
33 #include <cuires.hrc>
34 
35 #include "dlgname.hxx"
36 #include "defdlgname.hxx" //CHINA001
37 #include "dlgname.hrc"
38 #include <dialmgr.hxx>
39 
40 #define MAX_DESCRIPTION_LINES   ((long)5)
41 
42 /*************************************************************************
43 |*
44 |* Dialog zum Editieren eines Namens
45 |*
46 \************************************************************************/
47 
48 SvxNameDialog::SvxNameDialog( Window* pWindow, const String& rName, const String& rDesc ) :
49 	ModalDialog		( pWindow, CUI_RES( RID_SVXDLG_NAME ) ),
50 	aFtDescription		( this, CUI_RES( FT_DESCRIPTION ) ),
51 	aEdtName			( this, CUI_RES( EDT_STRING ) ),
52 	aBtnOK				( this, CUI_RES( BTN_OK ) ),
53 	aBtnCancel			( this, CUI_RES( BTN_CANCEL ) ),
54 	aBtnHelp			( this, CUI_RES( BTN_HELP ) )
55 {
56 	FreeResource();
57 
58 	aFtDescription.SetText( rDesc );
59 	aEdtName.SetText( rName );
60     aEdtName.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
61     ModifyHdl(&aEdtName);
62     aEdtName.SetModifyHdl(LINK(this, SvxNameDialog, ModifyHdl));
63 
64     // dynamic height of the description field
65     Size aSize = aFtDescription.GetSizePixel();
66     long nTxtWidth = aFtDescription.GetCtrlTextWidth( rDesc );
67     if ( nTxtWidth > aSize.Width() )
68     {
69         long nLines = Min( ( nTxtWidth / aSize.Width() + 1 ), MAX_DESCRIPTION_LINES );
70         long nHeight = aSize.Height();
71         aSize.Height() = nHeight * nLines;
72         aFtDescription.SetSizePixel( aSize );
73         Point aPnt = aEdtName.GetPosPixel();
74         aPnt.Y() += ( aSize.Height() - nHeight );
75         aEdtName.SetPosPixel( aPnt );
76     }
77 }
78 
79 /* -----------------------------27.02.2002 15:22------------------------------
80 
81  ---------------------------------------------------------------------------*/
82 IMPL_LINK(SvxNameDialog, ModifyHdl, Edit*, EMPTYARG)
83 {
84     if(aCheckNameHdl.IsSet())
85         aBtnOK.Enable(aCheckNameHdl.Call(this) > 0);
86     return 0;
87 }
88 
89 ///////////////////////////////////////////////////////////////////////////////////////////////
90 // #i68101#
91 // Dialog for editing Object Name
92 // plus uniqueness-callback-linkHandler
93 
94 SvxObjectNameDialog::SvxObjectNameDialog(
95 	Window* pWindow,
96 	const String& rName)
97 :	ModalDialog(pWindow, CUI_RES(RID_SVXDLG_OBJECT_NAME)),
98 	aFtName(this, CUI_RES(NTD_FT_NAME)),
99 	aEdtName(this, CUI_RES(NTD_EDT_NAME)),
100 	aFlSeparator(this, CUI_RES(FL_SEPARATOR_A)),
101 	aBtnHelp(this, CUI_RES(BTN_HELP)),
102 	aBtnOK(this, CUI_RES(BTN_OK)),
103 	aBtnCancel(this, CUI_RES(BTN_CANCEL))
104 {
105 	FreeResource();
106 
107 	// set name
108 	aEdtName.SetText(rName);
109 
110 	// activate name
111     aEdtName.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
112     ModifyHdl(&aEdtName);
113     aEdtName.SetModifyHdl(LINK(this, SvxObjectNameDialog, ModifyHdl));
114 }
115 
116 IMPL_LINK(SvxObjectNameDialog, ModifyHdl, Edit*, EMPTYARG)
117 {
118     if(aCheckNameHdl.IsSet())
119 	{
120         aBtnOK.Enable(aCheckNameHdl.Call(this) > 0);
121 	}
122 
123     return 0;
124 }
125 
126 ///////////////////////////////////////////////////////////////////////////////////////////////
127 // #i68101#
128 // Dialog for editing Object Title and Description
129 
130 SvxObjectTitleDescDialog::SvxObjectTitleDescDialog(
131 	Window* pWindow,
132 	const String& rTitle,
133 	const String& rDescription)
134 :	ModalDialog(pWindow, CUI_RES(RID_SVXDLG_OBJECT_TITLE_DESC)),
135 	aFtTitle(this, CUI_RES(NTD_FT_TITLE)),
136 	aEdtTitle(this, CUI_RES(NTD_EDT_TITLE)),
137 	aFtDescription(this, CUI_RES(NTD_FT_DESC)),
138 	aEdtDescription(this, CUI_RES(NTD_EDT_DESC)),
139 	aFlSeparator(this, CUI_RES(FL_SEPARATOR_B)),
140 	aBtnHelp(this, CUI_RES(BTN_HELP)),
141 	aBtnOK(this, CUI_RES(BTN_OK)),
142 	aBtnCancel(this, CUI_RES(BTN_CANCEL))
143 {
144 	FreeResource();
145 
146 	// set title & desc
147 	aEdtTitle.SetText(rTitle);
148 	aEdtDescription.SetText(rDescription);
149 
150 	// activate title
151     aEdtTitle.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
152 }
153 
154 ///////////////////////////////////////////////////////////////////////////////////////////////
155 
156 /*************************************************************************
157 |*
158 |* Dialog zum Abbrechen, Speichern oder Hinzufuegen
159 |*
160 \************************************************************************/
161 
162 SvxMessDialog::SvxMessDialog( Window* pWindow, const String& rText, const String& rDesc, Image* pImg ) :
163 	ModalDialog		( pWindow, CUI_RES( RID_SVXDLG_MESSBOX ) ),
164 	aFtDescription		( this, CUI_RES( FT_DESCRIPTION ) ),
165 	aBtn1				( this, CUI_RES( BTN_1 ) ),
166 	aBtn2				( this, CUI_RES( BTN_2 ) ),
167 	aBtnCancel			( this, CUI_RES( BTN_CANCEL ) ),
168 	aFtImage			( this )
169 {
170 	FreeResource();
171 
172 	if( pImg )
173 	{
174 		pImage = new Image( *pImg );
175 		aFtImage.SetImage( *pImage );
176 		aFtImage.SetStyle( ( aFtImage.GetStyle()/* | WB_NOTABSTOP */) & ~WB_3DLOOK );
177 		aFtImage.SetPosSizePixel( LogicToPixel( Point( 3, 6 ), MAP_APPFONT ),
178 			                      aFtImage.GetImage().GetSizePixel() );
179 		aFtImage.Show();
180 	}
181 
182 	SetText( rText );
183 	aFtDescription.SetText( rDesc );
184 
185 	aBtn1.SetClickHdl( LINK( this, SvxMessDialog, Button1Hdl ) );
186 	aBtn2.SetClickHdl( LINK( this, SvxMessDialog, Button2Hdl ) );
187 }
188 
189 SvxMessDialog::~SvxMessDialog()
190 {
191 	if( pImage )
192 		delete pImage;
193 }
194 
195 /*************************************************************************/
196 
197 IMPL_LINK_INLINE_START( SvxMessDialog, Button1Hdl, Button *, EMPTYARG )
198 {
199 	EndDialog( RET_BTN_1 );
200 	return 0;
201 }
202 IMPL_LINK_INLINE_END( SvxMessDialog, Button1Hdl, Button *, EMPTYARG )
203 
204 /*************************************************************************/
205 
206 IMPL_LINK_INLINE_START( SvxMessDialog, Button2Hdl, Button *, EMPTYARG )
207 {
208 	EndDialog( RET_BTN_2 );
209 	return 0;
210 }
211 IMPL_LINK_INLINE_END( SvxMessDialog, Button2Hdl, Button *, EMPTYARG )
212 
213 /*************************************************************************/
214 
215 void SvxMessDialog::SetButtonText( sal_uInt16 nBtnId, const String& rNewTxt )
216 {
217 	switch ( nBtnId )
218 	{
219 		case MESS_BTN_1:
220 			aBtn1.SetText( rNewTxt );
221 			break;
222 
223 		case MESS_BTN_2:
224 			aBtn2.SetText( rNewTxt );
225 			break;
226 
227 		default:
228 			DBG_ERROR( "Falsche Button-Nummer!!!" );
229 	}
230 }
231 
232 
233