1%% options 2 3copyright owner = Dirk Krause 4copyright year = 2011-xxxx 5SPDX-License-Identifier: BSD-3-Clause 6 7 8%% wx-gui 9 10type = dialog 11contents = sDialog 12# status bar = 1 dkwx_pd_def_texts[0] 13# title = ((title) ? title : dkwx_pd_def_texts[1]) 14 15[wxBoxSizer sDialog] 16direction = horizontal 17contents = $space(10) 18contents = verticalSizer 19contents = $space(10) 20 21[wxBoxSizer verticalSizer] 22direction = vertical 23grow = yes 24proportion = 1 25contents = $space(10) 26contents = sttFilename left 27contents = $space(10) 28contents = gaugeProgress centered-x 29contents = $space(10) 30contents = sttWait left 31contents = $space(10) 32contents = bCancel centered-x 33contents = $space(10) 34 35[wxStaticText sttFilename] 36text = ((firstFileName) ? firstFileName : dkwx_pd_def_texts[0]) 37text style = centered 38grow = yes 39proportion = 1 40 41[wxGauge gaugeProgress] 42range = 1000 43value = 0 44grow = yes 45 46[wxButton bCancel] 47text = ((buttonText) ? buttonText : dkwx_pd_def_texts[2]) 48tip = ((buttonTip) ? buttonTip : dkwx_pd_def_texts[3]) 49id = wxID_CANCEL 50 51[wxStaticText sttWait] 52text = ((waitText) ? waitText : dkwx_pd_def_texts[4]) 53text style = left no-auto-resize 54 55 56 57%% header start 58 59#ifndef DK3CONF_H_INCLUDED 60#include "dk3conf.h" 61#endif 62#ifndef DK3TYPES_H_INCLUDED 63#include <libdk3c/dk3types.h> 64#endif 65#ifndef DKWXFRAME_H_INCLUDED 66#include <libdk3wx/DkWxFrame.h> 67#endif 68#ifndef DKWXCOMMUNICATOR_H_INCLUDED 69#include <libdk3wx/DkWxCommunicator.h> 70#endif 71 72 73 74%% class start 75 76/** Progress dialog showing currently process file, progress bar 77 and a button to abort operation. 78*/ 79class DkWxProgressDialog : public wxDialog 80{ 81 private: 82 /** Event table. 83 */ 84#if wxCHECK_VERSION(3,0,0) 85 wxDECLARE_EVENT_TABLE(); 86#else 87 DECLARE_EVENT_TABLE() 88#endif 89 90 protected: 91 92 /** Communicator object delivering the file name and progress bar 93 value. 94 */ 95 DkWxCommunicator *pComm; 96 97 /** String: Cancel operation scheduled. Please wait. 98 */ 99 wxChar const *sWaitPlease; 100 101 /** Parent frame. 102 */ 103 DkWxFrame *pParent; 104 105 /** Log text field to receive the messages. 106 */ 107 wxTextCtrl *pLogTextField; 108 109%% class end 110 public: 111 112 /** Constructor. 113 @param parent Parent window. 114 @param comm Communicator object. 115 @param tc Text control to show messages. 116 @param title Title text. 117 @param firstFileName First file name to show. 118 @param buttonText Text for "Cancel" button. 119 @param buttonTip Tooltip text for button. 120 @param waitText Button to show while waiting for thread exit. 121 */ 122 DkWxProgressDialog( 123 DkWxFrame *parent, 124 DkWxCommunicator *comm, 125 wxTextCtrl *tc, 126 wxChar const *title, 127 wxChar const *firstFileName, 128 wxChar const *buttonText, 129 wxChar const *buttonTip, 130 wxChar const *waitText 131 ); 132 133 /** Handler for idle events. 134 We request the current file name and progress bar from 135 the communicator object and update the information shown 136 in the dialog. 137 */ 138 void 139 OnIdle(wxIdleEvent & event); 140 141 /** Handler for cancel button. 142 */ 143 void 144 OnCancel(wxCommandEvent & event); 145 146 /** Choose a modal position centered on the parent. 147 */ 148 void chooseModalPosition(); 149 150}; 151 152 153 154%% header end 155 156%% module start 157 158 159#include "dk3conf.h" 160#if 0 161#include <winprint/winprint.h> 162#endif 163 164#include <libdk3wx/DkWxProgressDialog.h> 165 166 167$!trace-include 168 169#if wxCHECK_VERSION(3,0,0) 170wxBEGIN_EVENT_TABLE(DkWxProgressDialog,wxDialog) 171#else 172BEGIN_EVENT_TABLE(DkWxProgressDialog,wxDialog) 173#endif 174 EVT_IDLE(DkWxProgressDialog::OnIdle) 175 EVT_BUTTON(wxID_CANCEL, DkWxProgressDialog::OnCancel) 176#if wxCHECK_VERSION(3,0,0) 177wxEND_EVENT_TABLE() 178#else 179END_EVENT_TABLE() 180#endif 181 182 183 184/** Default texts to use if the constructor has NULL pointer arguments. 185*/ 186wxChar const * const dkwx_pd_def_texts[] = { 187$!string-table macro=wxT 188# 189# 0: Empty string 190# 191 192# 193# 1: Default title. 194# 195Progress 196# 197# 2: Button text. 198# 199Cancel 200# 201# 3: Button tool tip. 202# 203Push button to interrupt processing. 204# 205# 4: Notification, user should wait. 206# 207Cancel command scheduled... Wait, please! 208$!end 209}; 210 211 212 213%% constructor start 214DkWxProgressDialog::DkWxProgressDialog( 215 DkWxFrame *parent, 216 DkWxCommunicator *comm, 217 wxTextCtrl *tc, 218 wxChar const *title, 219 wxChar const *firstFileName, 220 wxChar const *buttonText, 221 wxChar const *buttonTip, 222 wxChar const *waitText 223) : wxDialog( 224 parent, 225 wxID_ANY, 226 ((title) ? title : dkwx_pd_def_texts[1]), 227 wxDefaultPosition, 228 wxDefaultSize, 229 wxDEFAULT_DIALOG_STYLE 230) 231{ 232 $? "+ DkWxProgressDialog::DkWxProgressDialog" 233 pParent = parent; 234 pLogTextField = tc; 235 pComm = comm; 236 sWaitPlease = ((waitText) ? waitText : dkwx_pd_def_texts[4]); 237%% constructor end 238 if(dkctGUILayoutOK) { 239 if(sttWait) { 240 sttWait->SetLabel(dkwx_pd_def_texts[0]); 241 } 242 } 243 $? "- DkWxProgressDialog::DkWxProgressDialog" 244} 245 246 247 248%% module end 249 250 251void 252DkWxProgressDialog::OnIdle(wxIdleEvent & event) 253{ 254 int canContinue = 1; 255 int res; 256 $? "+ DkWxProgressDialog::OnIdle" 257 if(pComm) { $? ". pComm ok" 258 res = pComm->getUpdates(this, sttFilename, gaugeProgress); 259 $? ". res = %d", res 260 if(res & DK_WX_COMMUNICATOR_STATUS_UPDATE) { $? ". must update" 261 Refresh(); 262 Update(); 263 } else { $? ". no update" 264 } 265 if(res & DK_WX_COMMUNICATOR_STATUS_RUNNING) { $? ". can continue" 266 canContinue = 1; 267 } else { $? ". finished, end indicated" 268 canContinue = 0; 269 } 270 } else { $? "! no pComm" 271 canContinue = 0; 272 } 273 if(canContinue) { $? ". can continue" 274 event.RequestMore(); 275 } else { $? ". finished" 276 canContinue = 1; 277 if(pComm) { 278 canContinue = pComm->getCanContinue(); 279 if(pLogTextField) { $? ". transfer text" 280 pComm->getText(pLogTextField); 281 if(pParent) { $? ". refresh win" 282 pParent->Refresh(); 283 } else { $? ". refresh text" 284 pLogTextField->Refresh(); 285 } 286 } 287 } 288 if(IsModal()) { $? ". end modal" 289 EndModal((canContinue) ? wxID_OK : wxID_CANCEL); 290 } else { $? ". show false" 291 SetReturnCode((canContinue) ? wxID_OK : wxID_CANCEL); 292 Show(false); 293 } 294 } 295 event.Skip(); $? "- DkWxProgressDialog::OnIdle" 296} 297 298 299 300void 301DkWxProgressDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) 302{ 303 $? "+ DkWxProgressDialog::OnCancel" 304 if(pComm) { 305 pComm->setCanContinue(0); 306 } 307 if(sttWait) { 308 sttWait->SetLabel(sWaitPlease); 309 } 310 if(bCancel) { 311 bCancel->Enable(false); 312 bCancel->SetToolTip(sWaitPlease); 313 } 314 Refresh(); 315 Update(); 316 $? "- DkWxProgressDialog::OnCancel" 317} 318 319 320 321void 322DkWxProgressDialog::chooseModalPosition() 323{ 324 int px = 0; /* Parent x position. */ 325 int py = 0; /* Parent y position. */ 326 int pw = 0; /* Parent width. */ 327 int ph = 0; /* Parent height. */ 328 int x = 0; /* X position. */ 329 int y = 0; /* Y position. */ 330 int w = 0; /* Width. */ 331 int h = 0; /* Height. */ 332 $? "+ DkWxProgressDialog::chooseModalPosition" 333 /* Sceen size */ 334 wxSize scsz = wxGetDisplaySize(); 335 pParent->GetPosition(&px, &py); 336 pParent->GetSize(&pw, &ph); 337 GetSize(&w, &h); 338 x = px + (pw - w) / 2; 339 y = py + (ph - h) / 2; 340 if((x + w) > scsz.x) { x = scsz.x - w; } 341 if((y + h) > scsz.y) { y = scsz.y - h; } 342 if(x < 0) { x = 0; } 343 if(y < 0) { y = 0; } 344 SetSize(x, y, w, h); 345 $? "- DkWxProgressDialog::chooseModalPosition" 346} 347 348 349