xref: /aoo42x/main/sd/source/ui/dlg/brkdlg.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_sd.hxx"
30 
31 #ifdef SD_DLLIMPLEMENTATION
32 #undef SD_DLLIMPLEMENTATION
33 #endif
34 
35 #include "BreakDlg.hxx"
36 #include <sfx2/progress.hxx>
37 
38 #include <svx/svdedtv.hxx>
39 #include <svx/svdetc.hxx>
40 #include <sfx2/app.hxx>
41 #include <vcl/msgbox.hxx>
42 
43 #include "sdattr.hxx"
44 #include "brkdlg.hrc"
45 #include "sdresid.hxx"
46 #include "View.hxx"
47 #include "drawview.hxx"
48 #include "strings.hrc"
49 #include "DrawDocShell.hxx"
50 
51 namespace sd {
52 
53 /*************************************************************************
54 |*
55 |* Dialog zum aufbrechen von Metafiles
56 |*
57 \************************************************************************/
58 
59 BreakDlg::BreakDlg(
60     ::Window* pWindow,
61     DrawView* _pDrView,
62     DrawDocShell* pShell,
63     sal_uLong nSumActionCount,
64     sal_uLong nObjCount )
65     : SfxModalDialog     ( pWindow, SdResId( DLG_BREAK ) ),
66       aFtObjInfo			( this, SdResId( FT_OBJ_INFO ) ),
67       aFtActInfo			( this, SdResId( FT_ACT_INFO ) ),
68       aFtInsInfo			( this, SdResId( FT_INS_INFO ) ),
69       aFiObjInfo			( this, SdResId( FI_OBJ_INFO ) ),
70       aFiActInfo			( this, SdResId( FI_ACT_INFO ) ),
71       aFiInsInfo			( this, SdResId( FI_INS_INFO ) ),
72       aBtnCancel			( this, SdResId( BTN_CANCEL ) ),
73       aLink				( LINK( this, BreakDlg, UpDate)),
74       mpProgress			( NULL )
75 {
76 	aBtnCancel.SetClickHdl( LINK( this, BreakDlg, CancelButtonHdl));
77 
78 	mpProgress = new SfxProgress( pShell, String(SdResId(STR_BREAK_METAFILE)), nSumActionCount*3 );
79 
80 	pProgrInfo = new SvdProgressInfo( &aLink );
81 	// jede Action wird in DoImport() 3mal bearbeitet
82 	pProgrInfo->Init( nSumActionCount*3, nObjCount );
83 
84 	pDrView = _pDrView;
85 	bCancel = sal_False;
86 
87 	FreeResource();
88 }
89 
90 BreakDlg::~BreakDlg()
91 {
92 	if( mpProgress )
93 		delete mpProgress;
94 
95 	if( pProgrInfo )
96 		delete pProgrInfo;
97 }
98 
99 // Control-Handler fuer den Abbruch Button
100 IMPL_LINK( BreakDlg, CancelButtonHdl, void *, EMPTYARG )
101 {
102   bCancel = sal_True;
103   aBtnCancel.Disable();
104   return( 0L );
105 }
106 
107 // Die UpDate Methode muss regelmaessig von der Arbeitsfunktion
108 // ausgeuehrt werden.
109 // Beim ersten aufruf wird die gesamtanzahl der actions uebergeben.
110 // Jeder weitere sollte die bearbeiteten actions seit dem letzten aufruf von
111 // UpDate erhalten.
112 
113 IMPL_LINK( BreakDlg, UpDate, void*, nInit )
114 {
115 	String aEmptyStr;
116 
117 	if(pProgrInfo == NULL)
118 	  return 1L;
119 
120 	// Statuszeile updaten oder Fehlermeldung?
121 	if(nInit == (void*)1L)
122 	{
123 		ErrorBox aErrBox( this, WB_OK, String( SdResId( STR_BREAK_FAIL ) ) );
124 		aErrBox.Execute();
125 	}
126 	else
127 	{
128 		if(mpProgress)
129 			mpProgress->SetState( pProgrInfo->GetSumCurAction() );
130 	}
131 
132 	// Welches Oject wird gerade angezeigt?
133 	String info = UniString::CreateFromInt32( pProgrInfo->GetCurObj() );
134 	info.Append( sal_Unicode('/') );
135 	info.Append( UniString::CreateFromInt32( pProgrInfo->GetObjCount() ) );
136 	aFiObjInfo.SetText(info);
137 
138 	// Wieviele Actions sind schon aufgebrochen?
139 	if(pProgrInfo->GetActionCount() == 0)
140 	{
141 		aFiActInfo.SetText( aEmptyStr );
142 	}
143 	else
144 	{
145 		info = UniString::CreateFromInt32( pProgrInfo->GetCurAction() );
146 		info.Append( sal_Unicode('/') );
147 		info.Append( UniString::CreateFromInt32( pProgrInfo->GetActionCount() ) );
148 		aFiActInfo.SetText(info);
149 	}
150 
151 	// Und erst eingefuegt????
152 	if(pProgrInfo->GetInsertCount() == 0)
153 	{
154 		aFiInsInfo.SetText( aEmptyStr );
155 	}
156 	else
157 	{
158 		info = UniString::CreateFromInt32( pProgrInfo->GetCurInsert() );
159 		info.Append( sal_Unicode('/') );
160 		info.Append( UniString::CreateFromInt32( pProgrInfo->GetInsertCount() ) );
161 		aFiInsInfo.SetText(info);
162 	}
163 
164 	Application::Reschedule();
165 	return( bCancel?0L:1L );
166 }
167 
168 // Oeffnet den Modalen Dialog und startet einen Timer der die Arbeitsfunktion
169 // nach oeffnen des Dialogs ausfuehrt
170 short BreakDlg::Execute()
171 {
172   aTimer.SetTimeout( 10 );
173   aTimer.SetTimeoutHdl( LINK( this, BreakDlg, InitialUpdate ) );
174   aTimer.Start();
175 
176   return SfxModalDialog::Execute();
177 }
178 
179 // Linkmethode welche die Arbeitsfunktion startet
180 IMPL_LINK( BreakDlg, InitialUpdate, Timer*, EMPTYARG )
181 {
182 	pDrView->DoImportMarkedMtf(pProgrInfo);
183 	EndDialog(sal_True);
184 	return 0L;
185 }
186 
187 } // end of namespace sd
188