/* 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: Dk4WxFrame.cpt */ /* Copyright (C) 2015-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 Dk4WxFrame.cpp The Dk4WxFrame module. */ #line 136 "Dk4WxFrame.cpt" #include "Dk4WxFrame.h" #line 143 "Dk4WxFrame.cpt" /** Protection for number of instances. */ wxCriticalSection Dk4WxFrame::csInstances; /** Number of instances. */ int Dk4WxFrame::iInstances = 0; /** Keywords to save and restore window size and position. */ static const wxChar * const dk4wxframe_kw_size[] = { /* 0 */ wxT("window.x"), /* 1 */ wxT("window.y"), /* 2 */ wxT("window.w"), /* 3 */ wxT("window.h"), /* 4 */ wxT("window.maximized"), /* 5 */ wxT("window.iconized"), NULL #line 170 "Dk4WxFrame.cpt" }; /** Keywords to restore maximized and iconized state. */ static const wxChar * const dk4wxframe_kw_restore[] = { /* 0 */ wxT("window.restore-maximized"), /* 1 */ wxT("window.restore-iconized"), /* 2 */ wxT("window.restore-size"), NULL #line 182 "Dk4WxFrame.cpt" }; Dk4WxFrame::Dk4WxFrame( const wxString & appName, Dk4WxApplicationHelper *appHelper, Dk4WxHelpController *helpController, int wxid ) : wxFrame(NULL, wxid, appName) { pAppHelp = appHelper; pHelp = helpController; sAppName = appName; { wxCriticalSectionLocker lock(csInstances); iInstances++; } Connect(wxid, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(Dk4WxFrame::OnClose)); } void Dk4WxFrame::OnClose(wxCloseEvent & event) { bool doClose = true; bool isFinal = false; bool savePos = false; { wxCriticalSectionLocker lock(csInstances); if (1 == iInstances) { isFinal = true; } } if (event.CanVeto()) { doClose = CanClose(isFinal); } else { (void)CanClose(isFinal); } if (doClose) { { wxCriticalSectionLocker lock(csInstances); if (1 == iInstances--) { savePos = true; } } if (savePos) { SavePosition(); } event.Skip(); } else { event.Veto(); } } bool Dk4WxFrame::CanClose(bool isFinal) { return true; } void Dk4WxFrame::SavePosition(void) { int iv[6]; if (NULL != pAppHelp) { iv[4] = iv[5] = 0; if (IsIconized()) { iv[5] = 1; Iconize(false); } if (IsMaximized()) { iv[4] = 1; Maximize(false); } GetPosition(&(iv[0]), &(iv[1])); GetSize(&(iv[2]), &(iv[3])); #line 264 "Dk4WxFrame.cpt" #line 265 "Dk4WxFrame.cpt" #line 266 "Dk4WxFrame.cpt" #line 267 "Dk4WxFrame.cpt" #line 268 "Dk4WxFrame.cpt" pAppHelp->SetMultiple(dk4wxframe_kw_size, iv, 6); } } void Dk4WxFrame::RestorePosition(void) { int iv[6]; /* Values stored in config */ bool bv[3]; /* Feature restore */ int x; /* X position */ int y; /* Y position */ int w; /* Width */ int h; /* Height */ #line 285 "Dk4WxFrame.cpt" #if wxCHECK_VERSION(3,0,0) bv[2] = false; #else bv[2] = true; #endif /* Initialize variables. */ iv[0] = iv[1] = -1; iv[2] = iv[3] = iv[4] = iv[5] = 0; bv[0] = bv[1] = false; /* Retrieve stored values if found. */ if (NULL != pAppHelp) { pAppHelp->GetMultiple(dk4wxframe_kw_size, iv, 6); pAppHelp->GetMultiple(dk4wxframe_kw_restore, bv, 3); } /* Find size if not stored. */ GetSize(&w, &h); x = iv[0]; y = iv[1]; /* Correct size if size restoration wanted, increase if necessary. */ if (bv[2]) { #line 314 "Dk4WxFrame.cpt" if (iv[2] > w) { w = iv[2]; } if (iv[3] > h) { h = iv[3]; } } /* Correct values, no parts of window should be outside screen. */ Dk4WxApplicationHelper::CorrectPosition(x, y, w, h); /* Set position and optionally size. */ if (bv[2]) { #line 325 "Dk4WxFrame.cpt" SetSize(x, y, w, h); } else { SetPosition( wxPoint(x,y) ); } /* Restore maximized or iconized state if required. */ if (bv[0]) { #line 333 "Dk4WxFrame.cpt" Maximize(0 != iv[4]); } if (bv[1]) { #line 336 "Dk4WxFrame.cpt" Iconize(0 != iv[5]); } #line 340 "Dk4WxFrame.cpt" } void Dk4WxFrame::DisplayContents(void) { if (NULL != pHelp) { pHelp->DisplayContents(); } } void Dk4WxFrame::DisplaySection(wxString const & name) { if (NULL != pHelp) { pHelp->DisplaySection(name); } } void Dk4WxFrame::DisplaySection(int number) { if (NULL != pHelp) { pHelp->DisplaySection(number); } }