summaryrefslogtreecommitdiff
path: root/support/dktools/DkWxCommunicator.cpp
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/dktools/DkWxCommunicator.cpp
Initial commit
Diffstat (limited to 'support/dktools/DkWxCommunicator.cpp')
-rw-r--r--support/dktools/DkWxCommunicator.cpp529
1 files changed, 529 insertions, 0 deletions
diff --git a/support/dktools/DkWxCommunicator.cpp b/support/dktools/DkWxCommunicator.cpp
new file mode 100644
index 0000000000..582f9c5bc2
--- /dev/null
+++ b/support/dktools/DkWxCommunicator.cpp
@@ -0,0 +1,529 @@
+/*
+ WARNING: This file was generated by dkct.
+ 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
+*/
+
+/*
+Copyright (C) 2011-2017, Dirk Krause
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above opyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+* Neither the name of the author nor the names of contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/** @file DkWxCommunicator.cpp The DkWxCommunicator module.
+*/
+
+
+#line 271 "DkWxCommunicator.cpt"
+
+
+#include "dk3wxs.h"
+#include <dk3mem.h>
+#include "DkWxCommunicator.h"
+
+
+
+
+#line 279 "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 294 "DkWxCommunicator.cpt"
+ wxe = we;
+ dke = de;
+ iRunning = 0;
+ iAutostart = DK3_WX_AUTOSTART_NORMAL;
+
+#line 298 "DkWxCommunicator.cpt"
+ sMessages = NULL;
+ sFilename = NULL;
+ iGauge = 0;
+ iUpdated = 0;
+ iCanContinue = 1;
+ iLogLevelMax = DK3_LL_IGNORE;
+ sMessages = new wxString(dkwx_communicator_empty_text);
+
+
+#line 306 "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 *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 486 "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 496 "DkWxCommunicator.cpt"
+ if(iAutostart == DK3_WX_AUTOSTART_RUNNING) {
+
+#line 497 "DkWxCommunicator.cpt"
+ iAutostart = DK3_WX_AUTOSTART_FINISHED;
+
+#line 498 "DkWxCommunicator.cpt"
+ }
+ }
+
+#line 500 "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 534 "DkWxCommunicator.cpt"
+ if(sMessages) {
+
+#line 535 "DkWxCommunicator.cpt"
+ if(t) {
+
+#line 536 "DkWxCommunicator.cpt"
+ wxCriticalSectionLocker lock(csProtect);
+
+
+#line 538 "DkWxCommunicator.cpt"
+ sMessages->Append(t);
+
+
+#line 540 "DkWxCommunicator.cpt"
+ }
+ }
+
+#line 542 "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 595 "DkWxCommunicator.cpt"
+ {
+ wxCriticalSectionLocker lock(csProtect);
+ if(iAutostart == DK3_WX_AUTOSTART_START) {
+
+#line 598 "DkWxCommunicator.cpt"
+ iAutostart = DK3_WX_AUTOSTART_RUNNING;
+
+#line 599 "DkWxCommunicator.cpt"
+ back = 1;
+ }
+ }
+
+#line 602 "DkWxCommunicator.cpt"
+ return back;
+}
+
+
+
+void
+DkWxCommunicator::autostartSetFinished()
+{
+
+
+#line 611 "DkWxCommunicator.cpt"
+ wxCriticalSectionLocker lock(csProtect);
+ if(iAutostart == DK3_WX_AUTOSTART_RUNNING) {
+ iAutostart = DK3_WX_AUTOSTART_FINISHED;
+
+#line 614 "DkWxCommunicator.cpt"
+ }
+
+#line 615 "DkWxCommunicator.cpt"
+}
+
+
+
+int
+DkWxCommunicator::autostartIsFinished()
+{
+ int back = 0;
+
+
+#line 624 "DkWxCommunicator.cpt"
+ {
+ wxCriticalSectionLocker lock(csProtect);
+ if(iAutostart == DK3_WX_AUTOSTART_FINISHED) {
+ iAutostart = DK3_WX_AUTOSTART_WAIT_FOR_EXIT;
+
+#line 628 "DkWxCommunicator.cpt"
+ back = 1;
+ }
+ }
+
+#line 631 "DkWxCommunicator.cpt"
+ return back;
+}
+
+
+
+int
+DkWxCommunicator::autostartGet()
+{
+ int back;
+
+
+#line 641 "DkWxCommunicator.cpt"
+ {
+ wxCriticalSectionLocker lock(csProtect);
+ back = iAutostart;
+ }
+
+#line 645 "DkWxCommunicator.cpt"
+ return back;
+}
+
+
+
+void
+DkWxCommunicator::autostartEnable(bool nv)
+{
+
+
+#line 654 "DkWxCommunicator.cpt"
+ wxCriticalSectionLocker lock(csProtect);
+ if(nv) {
+ iAutostart = DK3_WX_AUTOSTART_START;
+
+#line 657 "DkWxCommunicator.cpt"
+ } else {
+ iAutostart = DK3_WX_AUTOSTART_NORMAL;
+
+#line 659 "DkWxCommunicator.cpt"
+ }
+
+#line 660 "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;
+}
+
+