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