]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlExternal.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlExternal.C
index adb866aa5789e24ab2ab6e5ee269354f19d9a699..556363ac50d1a6600b24391bb57a8275e2e4e98e 100644 (file)
 #include <config.h>
 
 #include "ControlExternal.h"
+
 #include "funcrequest.h"
 #include "gettext.h"
 #include "helper_funcs.h"
 #include "lyxrc.h"
 
+#include "graphics/GraphicsCache.h"
+#include "graphics/GraphicsCacheItem.h"
+#include "graphics/GraphicsImage.h"
+
 #include "insets/insetexternal.h"
 #include "insets/ExternalSupport.h"
 #include "insets/ExternalTemplate.h"
 
+#include "support/filefilterlist.h"
+#include "support/filetools.h"
+#include "support/convert.h"
 
-namespace external = lyx::external;
-
+using std::advance;
 using std::vector;
 using std::string;
 
+namespace lyx {
+
+using support::FileFilterList;
+using support::MakeAbsPath;
+using support::readBB_from_PSFile;
+
+namespace frontend {
+
 
 ControlExternal::ControlExternal(Dialog & parent)
-       : Dialog::Controller(parent)
+       : Dialog::Controller(parent),
+         bb_changed_(false)
 {}
 
 
@@ -52,7 +68,8 @@ void ControlExternal::dispatchParams()
 {
        string const lfun = InsetExternalMailer::params2string(params(),
                                                               kernel().buffer());
-       kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
+
+       kernel().dispatch(FuncRequest(getLfun(), lfun));
 }
 
 
@@ -117,30 +134,113 @@ external::Template ControlExternal::getTemplate(int i) const
        external::TemplateManager::Templates::const_iterator i1
                = external::TemplateManager::get().getTemplates().begin();
 
-       std::advance(i1, i);
+       advance(i1, i);
 
        return i1->second;
 }
 
 
-string const ControlExternal::Browse(string const & input) const
+string const ControlExternal::browse(string const & input,
+                                    string const & template_name) const
 {
        string const title =  _("Select external file");
 
        string const bufpath = kernel().bufferFilepath();
 
        /// Determine the template file extension
-       string pattern = "*";
+       external::TemplateManager const & etm =
+               external::TemplateManager::get();
        external::Template const * const et_ptr =
-               external::getTemplatePtr(params());
-       if (et_ptr)
-               pattern = et_ptr->fileRegExp;
+               etm.getTemplateByName(template_name);
 
-       // FIXME: a temporary hack until the FileDialog interface is updated
-       pattern += '|';
+       FileFilterList const filter = et_ptr ?
+               FileFilterList(et_ptr->fileRegExp) :
+               FileFilterList();
 
        std::pair<string, string> dir1(N_("Documents|#o#O"),
-                                 string(lyxrc.document_path));
+                                      string(lyxrc.document_path));
+
+       return browseRelFile(input, bufpath, title, filter, false, dir1);
+}
+
+
+string const ControlExternal::readBB(string const & file)
+{
+       string const abs_file =
+               MakeAbsPath(file, kernel().bufferFilepath());
+
+       // try to get it from the file, if possible. Zipped files are
+       // unzipped in the readBB_from_PSFile-Function
+       string const bb = readBB_from_PSFile(abs_file);
+       if (!bb.empty())
+               return bb;
+
+       // we don't, so ask the Graphics Cache if it has loaded the file
+       int width = 0;
+       int height = 0;
+
+       graphics::Cache & gc = graphics::Cache::get();
+       if (gc.inCache(abs_file)) {
+               graphics::Image const * image = gc.item(abs_file)->image();
+
+               if (image) {
+                       width  = image->getWidth();
+                       height = image->getHeight();
+               }
+       }
 
-       return browseRelFile(input, bufpath, title, pattern, false, dir1);
+       return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
 }
+
+} // namespace frontend
+
+
+namespace external {
+
+namespace {
+
+RotationDataType origins_array[] = {
+       RotationData::DEFAULT,
+       RotationData::TOPLEFT,
+       RotationData::BOTTOMLEFT,
+       RotationData::BASELINELEFT,
+       RotationData::CENTER,
+       RotationData::TOPCENTER,
+       RotationData::BOTTOMCENTER,
+       RotationData::BASELINECENTER,
+       RotationData::TOPRIGHT,
+       RotationData::BOTTOMRIGHT,
+       RotationData::BASELINERIGHT
+};
+
+
+size_type const origins_array_size =
+sizeof(origins_array) / sizeof(origins_array[0]);
+
+vector<RotationDataType> const
+origins(origins_array, origins_array + origins_array_size);
+
+// These are the strings, corresponding to the above, that the GUI should
+// use. Note that they can/should be translated.
+char const * const origin_gui_strs[] = {
+       N_("Default"),
+       N_("Top left"), N_("Bottom left"), N_("Baseline left"),
+       N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
+       N_("Top right"), N_("Bottom right"), N_("Baseline right")
+};
+
+} // namespace anon
+
+
+vector<RotationDataType> const & all_origins()
+{
+       return origins;
+}
+
+string const origin_gui_str(size_type i)
+{
+       return _(origin_gui_strs[i]);
+}
+
+} // namespace external
+} // namespace lyx