xref: /aoo41x/main/vcl/source/window/btndlg.cxx (revision 4d7c9de0)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/ref.hxx>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <tools/rc.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svdata.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vcl/button.hxx>
34cdf0e10cSrcweir #include <vcl/btndlg.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // =======================================================================
39cdf0e10cSrcweir 
40cdf0e10cSrcweir struct ImplBtnDlgItem
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	sal_uInt16				mnId;
43cdf0e10cSrcweir 	sal_Bool				mbOwnButton;
44cdf0e10cSrcweir 	sal_Bool				mbDummyAlign;
45cdf0e10cSrcweir 	long				mnSepSize;
46cdf0e10cSrcweir 	PushButton* 		mpPushButton;
47cdf0e10cSrcweir };
48cdf0e10cSrcweir 
DECLARE_LIST(ImplBtnDlgItemList,ImplBtnDlgItem *)49cdf0e10cSrcweir DECLARE_LIST( ImplBtnDlgItemList, ImplBtnDlgItem* )
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // =======================================================================
52cdf0e10cSrcweir 
53cdf0e10cSrcweir void ButtonDialog::ImplInitButtonDialogData()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	mpItemList				= new ImplBtnDlgItemList( 8, 8 );
56cdf0e10cSrcweir 	mnButtonSize			= 0;
57cdf0e10cSrcweir 	mnCurButtonId			= 0;
58cdf0e10cSrcweir 	mnFocusButtonId 		= BUTTONDIALOG_BUTTON_NOTFOUND;
59cdf0e10cSrcweir 	mbFormat				= sal_True;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir // -----------------------------------------------------------------------
63cdf0e10cSrcweir 
ButtonDialog(WindowType nType)64cdf0e10cSrcweir ButtonDialog::ButtonDialog( WindowType nType ) :
65cdf0e10cSrcweir 	Dialog( nType )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	ImplInitButtonDialogData();
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // -----------------------------------------------------------------------
71cdf0e10cSrcweir 
ButtonDialog(Window * pParent,WinBits nStyle)72cdf0e10cSrcweir ButtonDialog::ButtonDialog( Window* pParent, WinBits nStyle ) :
73cdf0e10cSrcweir 	Dialog( WINDOW_BUTTONDIALOG )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	ImplInitButtonDialogData();
76cdf0e10cSrcweir 	ImplInit( pParent, nStyle );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir // -----------------------------------------------------------------------
80cdf0e10cSrcweir 
ButtonDialog(Window * pParent,const ResId & rResId)81cdf0e10cSrcweir ButtonDialog::ButtonDialog( Window* pParent, const ResId& rResId ) :
82cdf0e10cSrcweir 	Dialog( WINDOW_BUTTONDIALOG )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	ImplInitButtonDialogData();
85cdf0e10cSrcweir 	rResId.SetRT( RSC_DIALOG ); 	// !!!!!!!!!! RSC_BUTTONDIALOG !!!!!!!!
86cdf0e10cSrcweir 	ImplInit( pParent, ImplInitRes( rResId ) );
87cdf0e10cSrcweir 	ImplLoadRes( rResId );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // -----------------------------------------------------------------------
91cdf0e10cSrcweir 
~ButtonDialog()92cdf0e10cSrcweir ButtonDialog::~ButtonDialog()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = mpItemList->First();
95cdf0e10cSrcweir 	while ( pItem )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		if ( pItem->mpPushButton && pItem->mbOwnButton )
98cdf0e10cSrcweir 			delete pItem->mpPushButton;
99cdf0e10cSrcweir 		delete pItem;
100cdf0e10cSrcweir 		pItem = mpItemList->Next();
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	delete mpItemList;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir // -----------------------------------------------------------------------
107cdf0e10cSrcweir 
ImplCreatePushButton(sal_uInt16 nBtnFlags)108cdf0e10cSrcweir PushButton* ButtonDialog::ImplCreatePushButton( sal_uInt16 nBtnFlags )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	PushButton* pBtn;
111cdf0e10cSrcweir 	WinBits 	nStyle = 0;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	if ( nBtnFlags & BUTTONDIALOG_DEFBUTTON )
114cdf0e10cSrcweir 		nStyle |= WB_DEFBUTTON;
115cdf0e10cSrcweir 	if ( nBtnFlags & BUTTONDIALOG_CANCELBUTTON )
116cdf0e10cSrcweir 		pBtn = new CancelButton( this, nStyle );
117cdf0e10cSrcweir 	else if ( nBtnFlags & BUTTONDIALOG_OKBUTTON )
118cdf0e10cSrcweir 		pBtn = new OKButton( this, nStyle );
119cdf0e10cSrcweir 	else if ( nBtnFlags & BUTTONDIALOG_HELPBUTTON )
120cdf0e10cSrcweir 		pBtn = new HelpButton( this, nStyle );
121cdf0e10cSrcweir 	else
122cdf0e10cSrcweir 		pBtn = new PushButton( this, nStyle );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	if ( !(nBtnFlags & BUTTONDIALOG_HELPBUTTON) )
125cdf0e10cSrcweir 		pBtn->SetClickHdl( LINK( this, ButtonDialog, ImplClickHdl ) );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	return pBtn;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir // -----------------------------------------------------------------------
131cdf0e10cSrcweir 
ImplGetItem(sal_uInt16 nId) const132cdf0e10cSrcweir ImplBtnDlgItem* ButtonDialog::ImplGetItem( sal_uInt16 nId ) const
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = mpItemList->First();
135cdf0e10cSrcweir 	while ( pItem )
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		if ( pItem->mnId == nId )
138cdf0e10cSrcweir 			return pItem;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		pItem = mpItemList->Next();
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	return NULL;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir // -----------------------------------------------------------------------
147cdf0e10cSrcweir 
ImplGetButtonSize()148cdf0e10cSrcweir long ButtonDialog::ImplGetButtonSize()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	if ( !mbFormat )
151cdf0e10cSrcweir 		return mnButtonSize;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	// Calculate ButtonSize
154cdf0e10cSrcweir 	long	nLastSepSize = 0;
155cdf0e10cSrcweir 	long	nSepSize = 0;
156cdf0e10cSrcweir 	long	nButtonCount = 0;
157cdf0e10cSrcweir 	maCtrlSize = Size( IMPL_MINSIZE_BUTTON_WIDTH, IMPL_MINSIZE_BUTTON_HEIGHT );
158cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = mpItemList->First();
159cdf0e10cSrcweir 	while ( pItem )
160cdf0e10cSrcweir 	{
161cdf0e10cSrcweir 		nSepSize += nLastSepSize;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		long nTxtWidth = pItem->mpPushButton->GetCtrlTextWidth( pItem->mpPushButton->GetText() );
164cdf0e10cSrcweir 		nTxtWidth += IMPL_EXTRA_BUTTON_WIDTH;
165cdf0e10cSrcweir 		if ( nTxtWidth > maCtrlSize.Width() )
166cdf0e10cSrcweir 			maCtrlSize.Width() = nTxtWidth;
167cdf0e10cSrcweir 		long nTxtHeight = pItem->mpPushButton->GetTextHeight();
168cdf0e10cSrcweir 		nTxtHeight += IMPL_EXTRA_BUTTON_HEIGHT;
169cdf0e10cSrcweir 		if ( nTxtHeight > maCtrlSize.Height() )
170cdf0e10cSrcweir 			maCtrlSize.Height() = nTxtHeight;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 		nSepSize += pItem->mnSepSize;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
175cdf0e10cSrcweir 			nLastSepSize = IMPL_SEP_BUTTON_X;
176cdf0e10cSrcweir 		else
177cdf0e10cSrcweir 			nLastSepSize = IMPL_SEP_BUTTON_Y;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 		nButtonCount++;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 		pItem = mpItemList->Next();
182cdf0e10cSrcweir 	}
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	if ( GetStyle() & WB_HORZ )
185cdf0e10cSrcweir 		mnButtonSize  = nSepSize + (nButtonCount*maCtrlSize.Width());
186cdf0e10cSrcweir 	else
187cdf0e10cSrcweir 		mnButtonSize = nSepSize + (nButtonCount*maCtrlSize.Height());
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	return mnButtonSize;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir // -----------------------------------------------------------------------
193cdf0e10cSrcweir 
ImplPosControls()194cdf0e10cSrcweir void ButtonDialog::ImplPosControls()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	if ( !mbFormat )
197cdf0e10cSrcweir 		return;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	// Create PushButtons and determine Sizes
200cdf0e10cSrcweir 	ImplGetButtonSize();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	// determine dialog size
203cdf0e10cSrcweir 	ImplBtnDlgItem* pItem;
204cdf0e10cSrcweir 	Size			aDlgSize = maPageSize;
205cdf0e10cSrcweir 	long			nX;
206cdf0e10cSrcweir 	long			nY;
207cdf0e10cSrcweir 	if ( GetStyle() & WB_HORZ )
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		if ( mnButtonSize+(IMPL_DIALOG_OFFSET*2) > aDlgSize.Width() )
210cdf0e10cSrcweir 			aDlgSize.Width() = mnButtonSize+(IMPL_DIALOG_OFFSET*2);
211cdf0e10cSrcweir 		if ( GetStyle() & WB_LEFT )
212cdf0e10cSrcweir 			nX = IMPL_DIALOG_OFFSET;
213cdf0e10cSrcweir 		else if ( GetStyle() & WB_RIGHT )
214cdf0e10cSrcweir 			nX = aDlgSize.Width()-mnButtonSize-IMPL_DIALOG_OFFSET;
215cdf0e10cSrcweir 		else
216cdf0e10cSrcweir 			nX = (aDlgSize.Width()-mnButtonSize)/2;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 		aDlgSize.Height() += IMPL_DIALOG_OFFSET+maCtrlSize.Height();
219cdf0e10cSrcweir 		nY = aDlgSize.Height()-maCtrlSize.Height()-IMPL_DIALOG_OFFSET;
220cdf0e10cSrcweir 	}
221cdf0e10cSrcweir 	else
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		if ( mnButtonSize+(IMPL_DIALOG_OFFSET*2) > aDlgSize.Height() )
224cdf0e10cSrcweir 			aDlgSize.Height() = mnButtonSize+(IMPL_DIALOG_OFFSET*2);
225cdf0e10cSrcweir 		if ( GetStyle() & WB_BOTTOM )
226cdf0e10cSrcweir 			nY = aDlgSize.Height()-mnButtonSize-IMPL_DIALOG_OFFSET;
227cdf0e10cSrcweir 		else if ( GetStyle() & WB_VCENTER )
228cdf0e10cSrcweir 			nY = (aDlgSize.Height()-mnButtonSize)/2;
229cdf0e10cSrcweir 		else
230cdf0e10cSrcweir 			nY = IMPL_DIALOG_OFFSET;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 		aDlgSize.Width() += IMPL_DIALOG_OFFSET+maCtrlSize.Width();
233cdf0e10cSrcweir 		nX = aDlgSize.Width()-maCtrlSize.Width()-IMPL_DIALOG_OFFSET;
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	// Arrange PushButtons
237cdf0e10cSrcweir 	pItem = mpItemList->First();
238cdf0e10cSrcweir 	while ( pItem )
239cdf0e10cSrcweir 	{
240cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
241cdf0e10cSrcweir 			nX += pItem->mnSepSize;
242cdf0e10cSrcweir 		else
243cdf0e10cSrcweir 			nY += pItem->mnSepSize;
244cdf0e10cSrcweir 		pItem->mpPushButton->SetPosSizePixel( Point( nX, nY ), maCtrlSize );
245cdf0e10cSrcweir 		pItem->mpPushButton->Show();
246cdf0e10cSrcweir 		if ( GetStyle() & WB_HORZ )
247cdf0e10cSrcweir 			nX += maCtrlSize.Width()+IMPL_SEP_BUTTON_X;
248cdf0e10cSrcweir 		else
249cdf0e10cSrcweir 			nY += maCtrlSize.Height()+IMPL_SEP_BUTTON_Y;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 		pItem = mpItemList->Next();
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	SetOutputSizePixel( aDlgSize );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	mbFormat = sal_False;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // -----------------------------------------------------------------------
260cdf0e10cSrcweir 
IMPL_LINK(ButtonDialog,ImplClickHdl,PushButton *,pBtn)261cdf0e10cSrcweir IMPL_LINK( ButtonDialog, ImplClickHdl, PushButton*, pBtn )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = mpItemList->First();
264cdf0e10cSrcweir 	while ( pItem )
265cdf0e10cSrcweir 	{
266cdf0e10cSrcweir 		if ( pItem->mpPushButton == pBtn )
267cdf0e10cSrcweir 		{
268cdf0e10cSrcweir 			mnCurButtonId = pItem->mnId;
269cdf0e10cSrcweir 			Click();
270cdf0e10cSrcweir 			break;
271cdf0e10cSrcweir 		}
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 		pItem = mpItemList->Next();
274cdf0e10cSrcweir 	}
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	return 0;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir // -----------------------------------------------------------------------
280cdf0e10cSrcweir 
Resize()281cdf0e10cSrcweir void ButtonDialog::Resize()
282cdf0e10cSrcweir {
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir // -----------------------------------------------------------------------
286cdf0e10cSrcweir 
StateChanged(StateChangedType nType)287cdf0e10cSrcweir void ButtonDialog::StateChanged( StateChangedType nType )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	if ( nType == STATE_CHANGE_INITSHOW )
290cdf0e10cSrcweir 	{
291cdf0e10cSrcweir 		ImplPosControls();
292*ad3a95a3SSteve Yin 		ImplBtnDlgItem* pItem = mpItemList->First();
293*ad3a95a3SSteve Yin 		while ( pItem )
294*ad3a95a3SSteve Yin 		{
295*ad3a95a3SSteve Yin 			if ( pItem->mpPushButton && pItem->mbOwnButton )
296*ad3a95a3SSteve Yin 				pItem->mpPushButton->SetZOrder(0, WINDOW_ZORDER_LAST);
297*ad3a95a3SSteve Yin 			pItem = mpItemList->Next();
298*ad3a95a3SSteve Yin 		}
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 		// Focus evt. auf den entsprechenden Button setzen
301cdf0e10cSrcweir 		if ( mnFocusButtonId != BUTTONDIALOG_BUTTON_NOTFOUND )
302cdf0e10cSrcweir 		{
303cdf0e10cSrcweir 			ImplBtnDlgItem* pItem = mpItemList->First();
304cdf0e10cSrcweir 			while ( pItem )
305cdf0e10cSrcweir 			{
306cdf0e10cSrcweir 				if ( pItem->mnId == mnFocusButtonId )
307cdf0e10cSrcweir 				{
308cdf0e10cSrcweir 					if ( pItem->mpPushButton->IsVisible() )
309cdf0e10cSrcweir 						pItem->mpPushButton->GrabFocus();
310cdf0e10cSrcweir 					break;
311cdf0e10cSrcweir 				}
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 				pItem = mpItemList->Next();
314cdf0e10cSrcweir 			}
315cdf0e10cSrcweir 		}
316cdf0e10cSrcweir 	}
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 	Dialog::StateChanged( nType );
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir // -----------------------------------------------------------------------
322cdf0e10cSrcweir 
Click()323cdf0e10cSrcweir void ButtonDialog::Click()
324cdf0e10cSrcweir {
325cdf0e10cSrcweir 	if ( !maClickHdl )
326cdf0e10cSrcweir 	{
327cdf0e10cSrcweir 		if ( IsInExecute() )
328cdf0e10cSrcweir 			EndDialog( GetCurButtonId() );
329cdf0e10cSrcweir 	}
330cdf0e10cSrcweir 	else
331cdf0e10cSrcweir 		maClickHdl.Call( this );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir // -----------------------------------------------------------------------
335cdf0e10cSrcweir 
AddButton(const XubString & rText,sal_uInt16 nId,sal_uInt16 nBtnFlags,long nSepPixel)336cdf0e10cSrcweir void ButtonDialog::AddButton( const XubString& rText, sal_uInt16 nId,
337cdf0e10cSrcweir 							  sal_uInt16 nBtnFlags, long nSepPixel )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	// PageItem anlegen
340cdf0e10cSrcweir 	ImplBtnDlgItem* pItem	= new ImplBtnDlgItem;
341cdf0e10cSrcweir 	pItem->mnId 			= nId;
342cdf0e10cSrcweir 	pItem->mbOwnButton		= sal_True;
343cdf0e10cSrcweir 	pItem->mnSepSize		= nSepPixel;
344cdf0e10cSrcweir 	pItem->mpPushButton 	= ImplCreatePushButton( nBtnFlags );
345cdf0e10cSrcweir 	if ( rText.Len() )
346cdf0e10cSrcweir 		pItem->mpPushButton->SetText( rText );
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 	// In die Liste eintragen
349cdf0e10cSrcweir 	mpItemList->Insert( pItem, LIST_APPEND );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 	if ( nBtnFlags & BUTTONDIALOG_FOCUSBUTTON )
352cdf0e10cSrcweir 		mnFocusButtonId = nId;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 	mbFormat = sal_True;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir // -----------------------------------------------------------------------
358cdf0e10cSrcweir 
AddButton(StandardButtonType eType,sal_uInt16 nId,sal_uInt16 nBtnFlags,long nSepPixel)359cdf0e10cSrcweir void ButtonDialog::AddButton( StandardButtonType eType, sal_uInt16 nId,
360cdf0e10cSrcweir 							  sal_uInt16 nBtnFlags, long nSepPixel )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir 	// PageItem anlegen
363cdf0e10cSrcweir 	ImplBtnDlgItem* pItem	= new ImplBtnDlgItem;
364cdf0e10cSrcweir 	pItem->mnId 			= nId;
365cdf0e10cSrcweir 	pItem->mbOwnButton		= sal_True;
366cdf0e10cSrcweir 	pItem->mnSepSize		= nSepPixel;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 	if ( eType == BUTTON_OK )
369cdf0e10cSrcweir 		nBtnFlags |= BUTTONDIALOG_OKBUTTON;
370cdf0e10cSrcweir 	else if ( eType == BUTTON_HELP )
371cdf0e10cSrcweir 		nBtnFlags |= BUTTONDIALOG_HELPBUTTON;
372cdf0e10cSrcweir 	else if ( (eType == BUTTON_CANCEL) || (eType == BUTTON_CLOSE) )
373cdf0e10cSrcweir 		nBtnFlags |= BUTTONDIALOG_CANCELBUTTON;
374cdf0e10cSrcweir 	pItem->mpPushButton = ImplCreatePushButton( nBtnFlags );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 	// Standard-Buttons have the right text already
377cdf0e10cSrcweir 	if ( !((eType == BUTTON_OK) 	&& (pItem->mpPushButton->GetType() == WINDOW_OKBUTTON)) ||
378cdf0e10cSrcweir 		 !((eType == BUTTON_CANCEL) && (pItem->mpPushButton->GetType() == WINDOW_CANCELBUTTON)) ||
379cdf0e10cSrcweir 		 !((eType == BUTTON_HELP)	&& (pItem->mpPushButton->GetType() == WINDOW_HELPBUTTON)) )
380cdf0e10cSrcweir 	{
381cdf0e10cSrcweir 		pItem->mpPushButton->SetText( Button::GetStandardText( eType ) );
382cdf0e10cSrcweir 		pItem->mpPushButton->SetHelpText( Button::GetStandardHelpText( eType ) );
383cdf0e10cSrcweir 	}
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	if ( nBtnFlags & BUTTONDIALOG_FOCUSBUTTON )
386cdf0e10cSrcweir 		mnFocusButtonId = nId;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 	// In die Liste eintragen
389cdf0e10cSrcweir 	mpItemList->Insert( pItem, LIST_APPEND );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	mbFormat = sal_True;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir // -----------------------------------------------------------------------
395cdf0e10cSrcweir 
AddButton(PushButton * pBtn,sal_uInt16 nId,sal_uInt16 nBtnFlags,long nSepPixel)396cdf0e10cSrcweir void ButtonDialog::AddButton( PushButton* pBtn, sal_uInt16 nId,
397cdf0e10cSrcweir 							  sal_uInt16 nBtnFlags, long nSepPixel )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir 	// PageItem anlegen
400cdf0e10cSrcweir 	ImplBtnDlgItem* pItem	= new ImplBtnDlgItem;
401cdf0e10cSrcweir 	pItem->mnId 			= nId;
402cdf0e10cSrcweir 	pItem->mbOwnButton		= sal_False;
403cdf0e10cSrcweir 	pItem->mnSepSize		= nSepPixel;
404cdf0e10cSrcweir 	pItem->mpPushButton 	= pBtn;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 	if ( nBtnFlags & BUTTONDIALOG_FOCUSBUTTON )
407cdf0e10cSrcweir 		mnFocusButtonId = nId;
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 	// In die View-Liste eintragen
410cdf0e10cSrcweir 	mpItemList->Insert( pItem, LIST_APPEND );
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 	mbFormat = sal_True;
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir // -----------------------------------------------------------------------
416cdf0e10cSrcweir 
RemoveButton(sal_uInt16 nId)417cdf0e10cSrcweir void ButtonDialog::RemoveButton( sal_uInt16 nId )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = mpItemList->First();
420cdf0e10cSrcweir 	while ( pItem )
421cdf0e10cSrcweir 	{
422cdf0e10cSrcweir 		if ( pItem->mnId == nId )
423cdf0e10cSrcweir 		{
424cdf0e10cSrcweir 			pItem->mpPushButton->Hide();
425cdf0e10cSrcweir 			if ( pItem->mbOwnButton )
426cdf0e10cSrcweir 				delete pItem->mpPushButton;
427cdf0e10cSrcweir 			delete pItem;
428cdf0e10cSrcweir 			mpItemList->Remove();
429cdf0e10cSrcweir 			mbFormat = sal_True;
430cdf0e10cSrcweir 			break;
431cdf0e10cSrcweir 		}
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 		pItem = mpItemList->Next();
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	DBG_ERRORFILE( "ButtonDialog::RemoveButton(): ButtonId invalid" );
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir // -----------------------------------------------------------------------
440cdf0e10cSrcweir 
Clear()441cdf0e10cSrcweir void ButtonDialog::Clear()
442cdf0e10cSrcweir {
443cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = mpItemList->First();
444cdf0e10cSrcweir 	while ( pItem )
445cdf0e10cSrcweir 	{
446cdf0e10cSrcweir 		pItem->mpPushButton->Hide();
447cdf0e10cSrcweir 		if ( pItem->mbOwnButton )
448cdf0e10cSrcweir 			delete pItem->mpPushButton;
449cdf0e10cSrcweir 		delete pItem;
450cdf0e10cSrcweir 		pItem = mpItemList->Next();
451cdf0e10cSrcweir 	}
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 	mpItemList->Clear();
454cdf0e10cSrcweir 	mbFormat = sal_True;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir // -----------------------------------------------------------------------
458cdf0e10cSrcweir 
GetButtonCount() const459cdf0e10cSrcweir sal_uInt16 ButtonDialog::GetButtonCount() const
460cdf0e10cSrcweir {
461cdf0e10cSrcweir 	return (sal_uInt16)mpItemList->Count();
462cdf0e10cSrcweir }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir // -----------------------------------------------------------------------
465cdf0e10cSrcweir 
GetButtonId(sal_uInt16 nButton) const466cdf0e10cSrcweir sal_uInt16 ButtonDialog::GetButtonId( sal_uInt16 nButton ) const
467cdf0e10cSrcweir {
468cdf0e10cSrcweir 	if ( nButton < mpItemList->Count() )
469cdf0e10cSrcweir 		return (sal_uInt16)mpItemList->GetObject( nButton )->mnId;
470cdf0e10cSrcweir 	else
471cdf0e10cSrcweir 		return BUTTONDIALOG_BUTTON_NOTFOUND;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir // -----------------------------------------------------------------------
475cdf0e10cSrcweir 
GetPushButton(sal_uInt16 nId) const476cdf0e10cSrcweir PushButton* ButtonDialog::GetPushButton( sal_uInt16 nId ) const
477cdf0e10cSrcweir {
478cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = ImplGetItem( nId );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	if ( pItem )
481cdf0e10cSrcweir 		return pItem->mpPushButton;
482cdf0e10cSrcweir 	else
483cdf0e10cSrcweir 		return NULL;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir // -----------------------------------------------------------------------
487cdf0e10cSrcweir 
SetButtonText(sal_uInt16 nId,const XubString & rText)488cdf0e10cSrcweir void ButtonDialog::SetButtonText( sal_uInt16 nId, const XubString& rText )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = ImplGetItem( nId );
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	if ( pItem )
493cdf0e10cSrcweir 	{
494cdf0e10cSrcweir 		pItem->mpPushButton->SetText( rText );
495cdf0e10cSrcweir 		mbFormat = sal_True;
496cdf0e10cSrcweir 	}
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir // -----------------------------------------------------------------------
500cdf0e10cSrcweir 
GetButtonText(sal_uInt16 nId) const501cdf0e10cSrcweir XubString ButtonDialog::GetButtonText( sal_uInt16 nId ) const
502cdf0e10cSrcweir {
503cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = ImplGetItem( nId );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 	if ( pItem )
506cdf0e10cSrcweir 		return pItem->mpPushButton->GetText();
507cdf0e10cSrcweir 	else
508cdf0e10cSrcweir 		return ImplGetSVEmptyStr();
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir // -----------------------------------------------------------------------
512cdf0e10cSrcweir 
SetButtonHelpText(sal_uInt16 nId,const XubString & rText)513cdf0e10cSrcweir void ButtonDialog::SetButtonHelpText( sal_uInt16 nId, const XubString& rText )
514cdf0e10cSrcweir {
515cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = ImplGetItem( nId );
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 	if ( pItem )
518cdf0e10cSrcweir 		pItem->mpPushButton->SetHelpText( rText );
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir // -----------------------------------------------------------------------
522cdf0e10cSrcweir 
GetButtonHelpText(sal_uInt16 nId) const523cdf0e10cSrcweir XubString ButtonDialog::GetButtonHelpText( sal_uInt16 nId ) const
524cdf0e10cSrcweir {
525cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = ImplGetItem( nId );
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 	if ( pItem )
528cdf0e10cSrcweir 		return pItem->mpPushButton->GetHelpText();
529cdf0e10cSrcweir 	else
530cdf0e10cSrcweir 		return ImplGetSVEmptyStr();
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir // -----------------------------------------------------------------------
534cdf0e10cSrcweir 
SetButtonHelpId(sal_uInt16 nId,const rtl::OString & rHelpId)535cdf0e10cSrcweir void ButtonDialog::SetButtonHelpId( sal_uInt16 nId, const rtl::OString& rHelpId )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = ImplGetItem( nId );
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 	if ( pItem )
540cdf0e10cSrcweir 		pItem->mpPushButton->SetHelpId( rHelpId );
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir // -----------------------------------------------------------------------
544cdf0e10cSrcweir 
GetButtonHelpId(sal_uInt16 nId) const545cdf0e10cSrcweir rtl::OString ButtonDialog::GetButtonHelpId( sal_uInt16 nId ) const
546cdf0e10cSrcweir {
547cdf0e10cSrcweir 	ImplBtnDlgItem* pItem = ImplGetItem( nId );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 	return pItem ? rtl::OString( pItem->mpPushButton->GetHelpId() ) : rtl::OString();
550cdf0e10cSrcweir }
551