MFXUtils.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Some helper functions for FOX
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include "MFXUtils.h"
00031 
00032 #ifdef CHECK_MEMORY_LEAKS
00033 #include <foreign/nvwa/debug_new.h>
00034 #endif // CHECK_MEMORY_LEAKS
00035 
00036 
00037 // ===========================================================================
00038 // method definitions
00039 // ===========================================================================
00040 void
00041 MFXUtils::deleteChildren(FXWindow *w) throw() {
00042     while (w->numChildren()!=0) {
00043         FXWindow *child = w->childAtIndex(0);
00044         delete child;
00045     }
00046 }
00047 
00048 
00049 FXbool
00050 MFXUtils::userPermitsOverwritingWhenFileExists(FXWindow * const parent,
00051         const FXString &file) throw() {
00052     if (!FXStat::exists(file)) {
00053         return TRUE;
00054     }
00055     int answer =
00056         FXMessageBox::question(parent, MBOX_YES_NO, "File Exists", "Overwrite '%s'?", file.text());
00057     if (answer==MBOX_CLICKED_NO) {
00058         return FALSE;
00059     }
00060     return TRUE;
00061 }
00062 
00063 
00064 FXString
00065 MFXUtils::getDocumentName(const FXString &filename) throw() {
00066     FXString file = FXPath::name(filename);
00067     return file.before('.');
00068 }
00069 
00070 
00071 FXString
00072 MFXUtils::getTitleText(const FXString &appname, FXString filename) throw() {
00073     if (filename.length()==0) {
00074         return appname;
00075     }
00076     return getDocumentName(filename) + " - " + appname;
00077 }
00078 
00079 
00080 FXString
00081 MFXUtils::assureExtension(const FXString &filename, const FXString &defaultExtension) throw() {
00082     FXString ext = FXPath::extension(filename);
00083     if (ext=="") {
00084         if (filename.rfind('.')==filename.length()-1) {
00085             return filename + defaultExtension;
00086         }
00087         return filename + "." + defaultExtension;
00088     }
00089     return filename;
00090 }
00091 
00092 
00093 FXString
00094 MFXUtils::getFilename2Write(FXWindow *parent,
00095                             const FXString &header, const FXString &extension,
00096                             FXIcon *icon, FXString &currentFolder) throw() {
00097     // get the new file name
00098     FXFileDialog opendialog(parent, header);
00099     opendialog.setIcon(icon);
00100     opendialog.setSelectMode(SELECTFILE_ANY);
00101     opendialog.setPatternList("*" + extension);
00102     if (currentFolder.length()!=0) {
00103         opendialog.setDirectory(currentFolder);
00104     }
00105     if (!opendialog.execute()) {
00106         return "";
00107     }
00108     FXString file = assureExtension(opendialog.getFilename(), extension.after('.')).text();
00109     if (!userPermitsOverwritingWhenFileExists(parent, file)) {
00110         return "";
00111     }
00112     currentFolder = opendialog.getDirectory();
00113     return file;
00114 }
00115 
00116 
00117 
00118 
00119 /****************************************************************************/
00120 

Generated on Wed May 5 00:06:30 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6