- if (!fn.empty()) {
- string const bb = controller().readBB(fn);
- if (!bb.empty()) {
- lbX->setText(toqstr(token(bb, ' ', 0)));
- lbY->setText(toqstr(token(bb, ' ', 1)));
- rtX->setText(toqstr(token(bb, ' ', 2)));
- rtY->setText(toqstr(token(bb, ' ', 3)));
- // the default units for the bb values when reading
- // it from the file
- lbXunit->setCurrentIndex(0);
- lbYunit->setCurrentIndex(0);
- rtXunit->setCurrentIndex(0);
- rtYunit->setCurrentIndex(0);
+ if (fn.empty())
+ return;
+ string const bb = readBB(fn);
+ bbChanged = false;
+ if (bb.empty())
+ return;
+ lbX->setText(toqstr(token(bb, ' ', 0)));
+ lbY->setText(toqstr(token(bb, ' ', 1)));
+ rtX->setText(toqstr(token(bb, ' ', 2)));
+ rtY->setText(toqstr(token(bb, ' ', 3)));
+ // the default units for the bb values when reading
+ // it from the file
+ lbXunit->setCurrentIndex(0);
+ lbYunit->setCurrentIndex(0);
+ rtXunit->setCurrentIndex(0);
+ rtYunit->setCurrentIndex(0);
+}
+
+
+bool GuiGraphics::isValid()
+{
+ return !filename->text().isEmpty();
+}
+
+
+bool GuiGraphics::initialiseParams(string const & data)
+{
+ InsetGraphicsMailer::string2params(data, buffer(), params_);
+ return true;
+}
+
+
+void GuiGraphics::clearParams()
+{
+ params_ = InsetGraphicsParams();
+}
+
+
+void GuiGraphics::dispatchParams()
+{
+ InsetGraphicsParams tmp_params(params_);
+ string const lfun =
+ InsetGraphicsMailer::params2string(tmp_params, buffer());
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+docstring const GuiGraphics::browse(docstring const & in_name) const
+{
+ docstring const title = _("Select graphics file");
+
+ // Does user clipart directory exist?
+ string clipdir = addName(package().user_support().absFilename(), "clipart");
+ FileName clip(clipdir);
+
+ // bail out to system clipart directory
+ if (!(clip.exists() && clip.isDirectory()))
+ clipdir = addName(package().system_support().absFilename(), "clipart");
+
+ return browseRelFile(in_name, from_utf8(bufferFilepath()),
+ title, FileFilterList(), false,
+ _("Clipart|#C#c"), from_utf8(clipdir),
+ _("Documents|#o#O"), from_utf8(lyxrc.document_path));
+}
+
+
+string const GuiGraphics::readBB(string const & file)
+{
+ FileName const abs_file = makeAbsPath(file, 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->width();
+ height = image->height();