xref: /aoo41x/main/cui/source/dialogs/dlgname.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 #include <tools/ref.hxx>
32 #include <tools/list.hxx>
33 #include <tools/shl.hxx>
34 #include <tools/debug.hxx>
35 #include <vcl/msgbox.hxx>
36 
37 #include <cuires.hrc>
38 
39 #include "dlgname.hxx"
40 #include "defdlgname.hxx" //CHINA001
41 #include "dlgname.hrc"
42 #include <dialmgr.hxx>
43 
44 #define MAX_DESCRIPTION_LINES   ((long)5)
45 
46 /*************************************************************************
47 |*
48 |* Dialog zum Editieren eines Namens
49 |*
50 \************************************************************************/
51 
52 SvxNameDialog::SvxNameDialog( Window* pWindow, const String& rName, const String& rDesc ) :
53 	ModalDialog		( pWindow, CUI_RES( RID_SVXDLG_NAME ) ),
54 	aFtDescription		( this, CUI_RES( FT_DESCRIPTION ) ),
55 	aEdtName			( this, CUI_RES( EDT_STRING ) ),
56 	aBtnOK				( this, CUI_RES( BTN_OK ) ),
57 	aBtnCancel			( this, CUI_RES( BTN_CANCEL ) ),
58 	aBtnHelp			( this, CUI_RES( BTN_HELP ) )
59 {
60 	FreeResource();
61 
62 	aFtDescription.SetText( rDesc );
63 	aEdtName.SetText( rName );
64     aEdtName.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
65     ModifyHdl(&aEdtName);
66     aEdtName.SetModifyHdl(LINK(this, SvxNameDialog, ModifyHdl));
67 
68     // dynamic height of the description field
69     Size aSize = aFtDescription.GetSizePixel();
70     long nTxtWidth = aFtDescription.GetCtrlTextWidth( rDesc );
71     if ( nTxtWidth > aSize.Width() )
72     {
73         long nLines = Min( ( nTxtWidth / aSize.Width() + 1 ), MAX_DESCRIPTION_LINES );
74         long nHeight = aSize.Height();
75         aSize.Height() = nHeight * nLines;
76         aFtDescription.SetSizePixel( aSize );
77         Point aPnt = aEdtName.GetPosPixel();
78         aPnt.Y() += ( aSize.Height() - nHeight );
79         aEdtName.SetPosPixel( aPnt );
80     }
81 }
82 
83 /* -----------------------------27.02.2002 15:22------------------------------
84 
85  ---------------------------------------------------------------------------*/
86 IMPL_LINK(SvxNameDialog, ModifyHdl, Edit*, EMPTYARG)
87 {
88     if(aCheckNameHdl.IsSet())
89         aBtnOK.Enable(aCheckNameHdl.Call(this) > 0);
90     return 0;
91 }
92 
93 ///////////////////////////////////////////////////////////////////////////////////////////////
94 // #i68101#
95 // Dialog for editing Object Name
96 // plus uniqueness-callback-linkHandler
97 
98 SvxObjectNameDialog::SvxObjectNameDialog(
99 	Window* pWindow,
100 	const String& rName)
101 :	ModalDialog(pWindow, CUI_RES(RID_SVXDLG_OBJECT_NAME)),
102 	aFtName(this, CUI_RES(NTD_FT_NAME)),
103 	aEdtName(this, CUI_RES(NTD_EDT_NAME)),
104 	aFlSeparator(this, CUI_RES(FL_SEPARATOR_A)),
105 	aBtnHelp(this, CUI_RES(BTN_HELP)),
106 	aBtnOK(this, CUI_RES(BTN_OK)),
107 	aBtnCancel(this, CUI_RES(BTN_CANCEL))
108 {
109 	FreeResource();
110 
111 	// set name
112 	aEdtName.SetText(rName);
113 
114 	// activate name
115     aEdtName.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
116     ModifyHdl(&aEdtName);
117     aEdtName.SetModifyHdl(LINK(this, SvxObjectNameDialog, ModifyHdl));
118 }
119 
120 IMPL_LINK(SvxObjectNameDialog, ModifyHdl, Edit*, EMPTYARG)
121 {
122     if(aCheckNameHdl.IsSet())
123 	{
124         aBtnOK.Enable(aCheckNameHdl.Call(this) > 0);
125 	}
126 
127     return 0;
128 }
129 
130 ///////////////////////////////////////////////////////////////////////////////////////////////
131 // #i68101#
132 // Dialog for editing Object Title and Description
133 
134 SvxObjectTitleDescDialog::SvxObjectTitleDescDialog(
135 	Window* pWindow,
136 	const String& rTitle,
137 	const String& rDescription)
138 :	ModalDialog(pWindow, CUI_RES(RID_SVXDLG_OBJECT_TITLE_DESC)),
139 	aFtTitle(this, CUI_RES(NTD_FT_TITLE)),
140 	aEdtTitle(this, CUI_RES(NTD_EDT_TITLE)),
141 	aFtDescription(this, CUI_RES(NTD_FT_DESC)),
142 	aEdtDescription(this, CUI_RES(NTD_EDT_DESC)),
143 	aFlSeparator(this, CUI_RES(FL_SEPARATOR_B)),
144 	aBtnHelp(this, CUI_RES(BTN_HELP)),
145 	aBtnOK(this, CUI_RES(BTN_OK)),
146 	aBtnCancel(this, CUI_RES(BTN_CANCEL))
147 {
148 	FreeResource();
149 
150 	// set title & desc
151 	aEdtTitle.SetText(rTitle);
152 	aEdtDescription.SetText(rDescription);
153 
154 	// activate title
155     aEdtTitle.SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
156 }
157 
158 ///////////////////////////////////////////////////////////////////////////////////////////////
159 
160 /*************************************************************************
161 |*
162 |* Dialog zum Abbrechen, Speichern oder Hinzufuegen
163 |*
164 \************************************************************************/
165 
166 SvxMessDialog::SvxMessDialog( Window* pWindow, const String& rText, const String& rDesc, Image* pImg ) :
167 	ModalDialog		( pWindow, CUI_RES( RID_SVXDLG_MESSBOX ) ),
168 	aFtDescription		( this, CUI_RES( FT_DESCRIPTION ) ),
169 	aBtn1				( this, CUI_RES( BTN_1 ) ),
170 	aBtn2				( this, CUI_RES( BTN_2 ) ),
171 	aBtnCancel			( this, CUI_RES( BTN_CANCEL ) ),
172 	aFtImage			( this )
173 {
174 	FreeResource();
175 
176 	if( pImg )
177 	{
178 		pImage = new Image( *pImg );
179 		aFtImage.SetImage( *pImage );
180 		aFtImage.SetStyle( ( aFtImage.GetStyle()/* | WB_NOTABSTOP */) & ~WB_3DLOOK );
181 		aFtImage.SetPosSizePixel( LogicToPixel( Point( 3, 6 ), MAP_APPFONT ),
182 			                      aFtImage.GetImage().GetSizePixel() );
183 		aFtImage.Show();
184 	}
185 
186 	SetText( rText );
187 	aFtDescription.SetText( rDesc );
188 
189 	aBtn1.SetClickHdl( LINK( this, SvxMessDialog, Button1Hdl ) );
190 	aBtn2.SetClickHdl( LINK( this, SvxMessDialog, Button2Hdl ) );
191 }
192 
193 SvxMessDialog::~SvxMessDialog()
194 {
195 	if( pImage )
196 		delete pImage;
197 }
198 
199 /*************************************************************************/
200 
201 IMPL_LINK_INLINE_START( SvxMessDialog, Button1Hdl, Button *, EMPTYARG )
202 {
203 	EndDialog( RET_BTN_1 );
204 	return 0;
205 }
206 IMPL_LINK_INLINE_END( SvxMessDialog, Button1Hdl, Button *, EMPTYARG )
207 
208 /*************************************************************************/
209 
210 IMPL_LINK_INLINE_START( SvxMessDialog, Button2Hdl, Button *, EMPTYARG )
211 {
212 	EndDialog( RET_BTN_2 );
213 	return 0;
214 }
215 IMPL_LINK_INLINE_END( SvxMessDialog, Button2Hdl, Button *, EMPTYARG )
216 
217 /*************************************************************************/
218 
219 void SvxMessDialog::SetButtonText( sal_uInt16 nBtnId, const String& rNewTxt )
220 {
221 	switch ( nBtnId )
222 	{
223 		case MESS_BTN_1:
224 			aBtn1.SetText( rNewTxt );
225 			break;
226 
227 		case MESS_BTN_2:
228 			aBtn2.SetText( rNewTxt );
229 			break;
230 
231 		default:
232 			DBG_ERROR( "Falsche Button-Nummer!!!" );
233 	}
234 }
235 
236 
237