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