Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2004-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file MFXRecentNetworks.cpp 15 : /// @author Pablo Alvarez Lopez 16 : /// @date Feb 2021 17 : /// 18 : // 19 : /****************************************************************************/ 20 : 21 : 22 : #include "MFXRecentNetworks.h" 23 : 24 : // =========================================================================== 25 : // FOX callback mapping 26 : // =========================================================================== 27 : 28 : FXDEFMAP(MFXRecentNetworks) MFXRecentNetworksMap[] = { 29 : FXMAPFUNC(SEL_UPDATE, MFXRecentNetworks::ID_NOFILES, MFXRecentNetworks::onUpdNoFiles), 30 : FXMAPFUNCS(SEL_UPDATE, FXRecentFiles::ID_FILE_1, FXRecentFiles::ID_FILE_10, MFXRecentNetworks::onUpdFile), 31 : }; 32 : 33 : // Object implementation 34 15505194 : FXIMPLEMENT(MFXRecentNetworks, FXRecentFiles, MFXRecentNetworksMap, ARRAYNUMBER(MFXRecentNetworksMap)) 35 : 36 : // =========================================================================== 37 : // member method definitions 38 : // =========================================================================== 39 : 40 0 : MFXRecentNetworks::MFXRecentNetworks() : 41 0 : FXRecentFiles() { 42 0 : } 43 : 44 : 45 14508 : MFXRecentNetworks::MFXRecentNetworks(FXApp* a, const FXString& gp) : 46 14508 : FXRecentFiles(a, gp) { 47 14508 : } 48 : 49 : 50 : long 51 12619783 : MFXRecentNetworks::onUpdFile(FXObject* obj, FXSelector sel, void*) { 52 : // get filename index 53 12619783 : const FXint which = FXSELID(sel) - ID_FILE_1 + 1; 54 : // get filename 55 : const FXchar* filename; 56 : FXchar key[20]; 57 : sprintf(key, "FILE%d", which); 58 12619783 : filename = getApp()->reg().readStringEntry(getGroupName().text(), key, NULL); 59 : // update myIndexFilenames 60 12619783 : myIndexFilenames[which] = filename; 61 : // check filename 62 12619783 : if (filename) { 63 12619783 : FXString string; 64 12619783 : if (which < 10) { 65 11358124 : string.format("&%d %s", which, filename); 66 : } else { 67 1261659 : string.format("1&0 %s", filename); 68 : } 69 12619783 : obj->handle(this, FXSEL(SEL_COMMAND, FXWindow::ID_SETSTRINGVALUE), (void*)&string); 70 12619783 : obj->handle(this, FXSEL(SEL_COMMAND, FXWindow::ID_SHOW), NULL); 71 12619783 : } else { 72 0 : obj->handle(this, FXSEL(SEL_COMMAND, FXWindow::ID_HIDE), NULL); 73 : } 74 12619783 : return 1; 75 : } 76 : 77 : 78 : long 79 1261507 : MFXRecentNetworks::onUpdNoFiles(FXObject* obj, FXSelector, void*) { 80 : // first disable object 81 1261507 : obj->handle(obj, FXSEL(SEL_COMMAND, FXWindow::ID_DISABLE), NULL); 82 : // iterate over myIndexFilenames 83 1261507 : for (const auto& indexFilename : myIndexFilenames) { 84 : // if filename isn't empty, then hide object and stop 85 1261507 : if (!indexFilename.second.empty()) { 86 1261507 : obj->handle(obj, FXSEL(SEL_COMMAND, FXWindow::ID_HIDE), NULL); 87 : return 1; 88 : } 89 : } 90 : //show object 91 0 : obj->handle(obj, FXSEL(SEL_COMMAND, FXWindow::ID_SHOW), NULL); 92 0 : return 1; 93 : }