Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
// -*- C++ -*-
//
// Package:     Core
// Class  :     FWViewBase
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Thu Feb 21 14:43:19 EST 2008
//

// system include files
#include <stdexcept>
#include <iostream>
#include "TGFileDialog.h"

// user include files
#include "Fireworks/Core/interface/FWViewBase.h"

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
FWViewBase::FWViewBase(FWViewType::EType type, unsigned int iVersion)
    : FWConfigurableParameterizable(iVersion), m_type(type) {}

// FWViewBase::FWViewBase(const FWViewBase& rhs)
// {
//    // do actual copying here;
// }

FWViewBase::~FWViewBase() {}

//
// assignment operators
//
// const FWViewBase& FWViewBase::operator=(const FWViewBase& rhs)
// {
//   //An exception safe implementation is
//   FWViewBase temp(rhs);
//   swap(rhs);
//
//   return *this;
// }

//
// member functions
//
void FWViewBase::destroy() { beingDestroyed_(this); }

//
// const member functions
//
void FWViewBase::promptForSaveImageTo(TGFrame* iParent) const {
  if (typeId() < FWViewType::kTable) {
    try {
      static TString dir(".");
      const char* kImageExportTypes[] = {"PNG",
                                         "*.png",
                                         "GIF",
                                         "*.gif",
                                         "JPEG",
                                         "*.jpg",
                                         "PDF",
                                         "*.pdf",
                                         "Encapsulated PostScript",
                                         "*.eps",
                                         nullptr,
                                         nullptr};

      TGFileInfo fi;
      fi.fFileTypes = kImageExportTypes;
      fi.fIniDir = StrDup(dir);
      new TGFileDialog(gClient->GetDefaultRoot(), iParent, kFDSave, &fi);
      dir = fi.fIniDir;
      if (fi.fFilename != nullptr) {
        std::string name = fi.fFilename;
        // fi.fFileTypeIdx points to the name of the file type
        // selected in the drop-down menu, so fi.fFileTypeIdx gives us
        // the extension
        std::string ext = kImageExportTypes[fi.fFileTypeIdx + 1] + 1;
        if (name.find(ext) == name.npos)
          name += ext;
        saveImageTo(name);
      }
    } catch (std::runtime_error& e) {
      std::cout << e.what() << std::endl;
    }
  } else {
    saveImageTo("dummy");
  }
}

FWViewContextMenuHandlerBase* FWViewBase::contextMenuHandler() const { return nullptr; }

//
// static member functions
//
const std::string& FWViewBase::typeName() const { return m_type.name(); }