/* Copyright (C) 2011-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: DkWxCommunicator.cpt */ /** @file DkWxCommunicator.cpp The DkWxCommunicator module. */ #line 277 "DkWxCommunicator.cpt" #include "dk3wxs.h" #include #include "DkWxCommunicator.h" #line 285 "DkWxCommunicator.cpt" /** Empty text to use if no file name is specified. */ static wxChar const dkwx_communicator_empty_text[] = { wxT("") } ; /** Newline. */ static wxChar const dkwx_communicator_newline[] = { wxT("\n") } ; DkWxCommunicator::DkWxCommunicator(int we, int de) { #line 300 "DkWxCommunicator.cpt" wxe = we; dke = de; iRunning = 0; iAutostart = DK3_WX_AUTOSTART_NORMAL; #line 304 "DkWxCommunicator.cpt" sMessages = NULL; sFilename = NULL; iGauge = 0; iUpdated = 0; iCanContinue = 1; iLogLevelMax = DK3_LL_IGNORE; sMessages = new wxString(dkwx_communicator_empty_text); #line 312 "DkWxCommunicator.cpt" } DkWxCommunicator::~DkWxCommunicator() { { wxCriticalSectionLocker lock(csProtect); } if(sMessages) { delete sMessages; } if(sFilename) { dk3_release(sFilename); } iRunning = 0; iGauge = 0; iUpdated = 0; iCanContinue = 0; } int DkWxCommunicator::checkSetup() const { int back = 0; if(sMessages) { back = 1; } return back; } int DkWxCommunicator::getUpdates( wxWindow * WXUNUSED(wDialog), wxStaticText *tFilename, wxGauge *gProgress ) { int back = 0; wxCriticalSectionLocker lock(csProtect); if(iUpdated) { back |= DK_WX_COMMUNICATOR_STATUS_UPDATE; if(tFilename) { if(sFilename) { tFilename->SetLabel(sFilename); } else { tFilename->SetLabel(dkwx_communicator_empty_text); } } if(gProgress) { gProgress->SetValue(iGauge); } iUpdated = 0; } if(iRunning) { back |= DK_WX_COMMUNICATOR_STATUS_RUNNING; } return back; } void DkWxCommunicator::internalSetGauge(int newValue) { int nv; nv = newValue; if(nv < 0) nv = 0; if(nv > 1000) nv = 1000; if(iRunning) { if(nv == 1000) nv = 999; } if(nv != iGauge) { iGauge = nv; iUpdated = 1; } } int DkWxCommunicator::internalSetFilename(wxChar const *newFileName) { int back = 0; if(newFileName) { if(sFilename) { if(dk3wxs_cmp(newFileName, sFilename)) { dk3_release(sFilename); sFilename = dk3wxs_dup(newFileName); if(sFilename) { back = 1; } iUpdated = 1; } else { back = 1; } } else { sFilename = dk3wxs_dup(newFileName); if(sFilename) { iUpdated = 1; back = 1; } } } else { if(sFilename) { dk3_release(sFilename); sFilename = NULL; iUpdated = 1; } back = 1; } return back; } int DkWxCommunicator::setUpdates(wxChar const *fn, int nv) { int back = 0; wxCriticalSectionLocker lock(csProtect); if(internalSetFilename(fn)) { back = 1; } internalSetGauge(nv); return back; } void DkWxCommunicator::updateGauge(int nv) { wxCriticalSectionLocker lock(csProtect); internalSetGauge(nv); } void DkWxCommunicator::prepareRun() { wxCriticalSectionLocker lock(csProtect); internalSetFilename(NULL); internalSetGauge(0); iRunning = 1; iCanContinue = 1; sMessages->Empty(); iUpdated = 1; iLogLevelMax = DK3_LL_IGNORE; } void DkWxCommunicator::setCanContinue(int nv) { wxCriticalSectionLocker lock(csProtect); iCanContinue = nv; } int DkWxCommunicator::getCanContinue() { int back = 0; wxCriticalSectionLocker lock(csProtect); back = iCanContinue; return back; } void DkWxCommunicator::setRunning(int nv) { #line 492 "DkWxCommunicator.cpt" wxCriticalSectionLocker lock(csProtect); /* Set new value. */ iRunning = nv; /* If we are no longer running we have finished the autostart job. */ if(nv == 0) { #line 502 "DkWxCommunicator.cpt" if(iAutostart == DK3_WX_AUTOSTART_RUNNING) { #line 503 "DkWxCommunicator.cpt" iAutostart = DK3_WX_AUTOSTART_FINISHED; #line 504 "DkWxCommunicator.cpt" } } #line 506 "DkWxCommunicator.cpt" } int DkWxCommunicator::getRunning() { int back = 1; { wxCriticalSectionLocker lock(csProtect); back = iRunning; } return back; } void DkWxCommunicator::getText( wxTextCtrl *tc) { wxCriticalSectionLocker lock(csProtect); if(tc) { if(sMessages) { tc->ChangeValue(*sMessages); } } } void DkWxCommunicator::addWxText(wxChar const *t) { #line 540 "DkWxCommunicator.cpt" if(sMessages) { #line 541 "DkWxCommunicator.cpt" if(t) { #line 542 "DkWxCommunicator.cpt" wxCriticalSectionLocker lock(csProtect); #line 544 "DkWxCommunicator.cpt" sMessages->Append(t); #line 546 "DkWxCommunicator.cpt" } } #line 548 "DkWxCommunicator.cpt" } void DkWxCommunicator::addDkText(dkChar const *t) { wxChar bu[2 * DK3_MAX_PATH]; if(sMessages) { if(t) { if(dk3wxs_from_dkstr(bu, DK3_SIZEOF(bu,wxChar), wxe, t, dke)) { wxCriticalSectionLocker lock(csProtect); sMessages->Append(bu); } } } } void DkWxCommunicator::addCharText(char const *t) { wxChar bu[2 * DK3_MAX_PATH]; if(sMessages) { if(t) { if(dk3wxs_from_plain(bu, DK3_SIZEOF(bu,wxChar), t)) { wxCriticalSectionLocker lock(csProtect); sMessages->Append(bu); } } } } void DkWxCommunicator::nl() { if(sMessages) { wxCriticalSectionLocker lock(csProtect); sMessages->Append(dkwx_communicator_newline); } } int DkWxCommunicator::autostartCanRun() { int back = 0; #line 601 "DkWxCommunicator.cpt" { wxCriticalSectionLocker lock(csProtect); if(iAutostart == DK3_WX_AUTOSTART_START) { #line 604 "DkWxCommunicator.cpt" iAutostart = DK3_WX_AUTOSTART_RUNNING; #line 605 "DkWxCommunicator.cpt" back = 1; } } #line 608 "DkWxCommunicator.cpt" return back; } void DkWxCommunicator::autostartSetFinished() { #line 617 "DkWxCommunicator.cpt" wxCriticalSectionLocker lock(csProtect); if(iAutostart == DK3_WX_AUTOSTART_RUNNING) { iAutostart = DK3_WX_AUTOSTART_FINISHED; #line 620 "DkWxCommunicator.cpt" } #line 621 "DkWxCommunicator.cpt" } int DkWxCommunicator::autostartIsFinished() { int back = 0; #line 630 "DkWxCommunicator.cpt" { wxCriticalSectionLocker lock(csProtect); if(iAutostart == DK3_WX_AUTOSTART_FINISHED) { iAutostart = DK3_WX_AUTOSTART_WAIT_FOR_EXIT; #line 634 "DkWxCommunicator.cpt" back = 1; } } #line 637 "DkWxCommunicator.cpt" return back; } int DkWxCommunicator::autostartGet() { int back; #line 647 "DkWxCommunicator.cpt" { wxCriticalSectionLocker lock(csProtect); back = iAutostart; } #line 651 "DkWxCommunicator.cpt" return back; } void DkWxCommunicator::autostartEnable(bool nv) { #line 660 "DkWxCommunicator.cpt" wxCriticalSectionLocker lock(csProtect); if(nv) { iAutostart = DK3_WX_AUTOSTART_START; #line 663 "DkWxCommunicator.cpt" } else { iAutostart = DK3_WX_AUTOSTART_NORMAL; #line 665 "DkWxCommunicator.cpt" } #line 666 "DkWxCommunicator.cpt" } void DkWxCommunicator::setLogLevel(int nv) { wxCriticalSectionLocker lock(csProtect); if(nv < iLogLevelMax) { iLogLevelMax = nv; } } int DkWxCommunicator::getLogLevel() { int back = DK3_LL_IGNORE; { wxCriticalSectionLocker lock(csProtect); back = iLogLevelMax; } return back; } wxString DkWxCommunicator::getText() { wxString back(wxT("")); if(sMessages) { back = *sMessages; } return back; }