* FormGraphics Interface Class Implementation
*/
-/* TODO:
- * * Handle the case when the buffer is read-only.
- * Initial work is done, if we are read-only the ok/cancel are
- * disabled. Probably we need to find a better way to deal with it.
- *
- */
-
#include <config.h>
#ifdef __GNUG__
#endif
#include "lyx_gui_misc.h"
-#include "gettext.h"
-#include FORMS_H_LOCATION
-
-#include "xform_macros.h"
#include "input_validators.h"
#include "FormGraphics.h"
#include "form_graphics.h"
#include "debug.h" // for lyxerr
-#include "support/lstrings.h" // for strToDbl & tostr
-#include "support/FileInfo.h" // for FileInfo
-#include "filedlg.h" // for LyXFileDlg
+#include "support/lstrings.h" // for strToDbl & tostr
+#include "support/FileInfo.h" // for FileInfo
+#include "xform_helpers.h" // for browseFile
#include "support/filetools.h" // for AddName
#include "insets/insetgraphics.h"
#include "insets/insetgraphicsParams.h"
#include "support/LAssert.h"
using std::endl;
-
-C_RETURNCB(FormGraphics, WMHideCB)
-C_GENERICCB(FormGraphics, OKCB)
-C_GENERICCB(FormGraphics, ApplyCB)
-C_GENERICCB(FormGraphics, CancelCB)
-C_GENERICCB(FormGraphics, BrowseCB)
-C_GENERICCB(FormGraphics, AdvancedOptionsCB)
-C_GENERICCB(FormGraphics, InputCB)
-
+using std::make_pair;
FormGraphics::FormGraphics(LyXView * lv, Dialogs * d)
- : dialog_(0), lv_(lv), d_(d), inset_(0),
- // The buttons c-tor values are the number of buttons we use
- // This is only to reduce memory waste.
- widthButtons(5), heightButtons(4), displayButtons(4),
- ih_(0), h_(0), u_(0),
- last_image_path(".")
+ : FormInset(lv, d, _("Graphics"), new NoRepeatedApplyReadOnlyPolicy),
+ dialog_(0), inset_(0),
+ // The buttons c-tor values are the number of buttons we use
+ // This is only to reduce memory waste.
+ widthButtons(5), heightButtons(4), displayButtons(4),
+ last_image_path(".")
{
// let the dialog be shown
// This is a permanent connection so we won't bother
FormGraphics::~FormGraphics()
{
- free();
+ // Remove all associations for the radio buttons
+ widthButtons.reset();
+ heightButtons.reset();
+ displayButtons.reset();
+
+ // Free the form.
+ // delete dialog_;
}
{
dialog_ = build_graphics();
Assert(dialog_ != 0);
- if (!dialog_)
+ if (!dialog_) {
+ lyxerr << "ERROR: Failed to create the Graphics Inset dialog." << endl;
return ;
+ }
+
+ // Workaround dumb xforms sizing bug
+ minw_ = form()->w;
+ minh_ = form()->h;
// This is the place to add settings of the dialog that did not go
// to the .fd file.
displayButtons.registerRadioButton(dialog_->radio_no_display,
InsetGraphicsParams::NONE);
- // Connect a signal to hide the window when the window manager orders it.
- fl_set_form_atclose(dialog_->form,
- C_FormGraphicsWMHideCB, 0);
+ // Manage the ok, apply, restore and cancel/close buttons
+ bc_.setOK(dialog_->button_ok);
+ bc_.setApply(dialog_->button_apply);
+ bc_.setCancel(dialog_->button_cancel);
+ bc_.setUndoAll(dialog_->button_restore);
+ bc_.refresh();
+
+ bc_.addReadOnly(dialog_->input_filename);
+ bc_.addReadOnly(dialog_->button_browse);
+ bc_.addReadOnly(dialog_->input_width);
+ bc_.addReadOnly(dialog_->input_height);
+ bc_.addReadOnly(dialog_->radio_button_group_width);
+ bc_.addReadOnly(dialog_->radio_button_group_height);
+ bc_.addReadOnly(dialog_->radio_button_group_display);
+ bc_.addReadOnly(dialog_->input_rotate_angle);
+ bc_.addReadOnly(dialog_->check_inline);
+ bc_.addReadOnly(dialog_->input_subcaption);
+ bc_.addReadOnly(dialog_->check_subcaption);
}
-void FormGraphics::show()
-{
- // If the dialog doesn't exist yet, build it.
- if (!dialog_) {
- build();
- }
- // Update the form with the data from the inset.
- update();
-
- // If the form is visible
- if (dialog_->form->visible) {
- // Raise it.
- fl_raise_form(dialog_->form);
- } else {
- // Otherwise (invisible), show it.
- fl_show_form(dialog_->form,
- FL_PLACE_MOUSE,
- FL_FULLBORDER,
- _("Graphics"));
-
- // And connect the signals 'updateBufferDependent',
- // 'hideBufferDependent' and 'hideGraphics'.
- u_ = d_->updateBufferDependent.connect(slot(this,
- &FormGraphics::update));
- h_ = d_->hideBufferDependent.connect(slot(this,
- &FormGraphics::hide));
- }
+FL_FORM * FormGraphics::form() const
+{
+ if (dialog_ ) return dialog_->form;
+ return 0;
}
-void FormGraphics::showDialog(InsetGraphics* inset)
+
+void FormGraphics::disconnect()
{
- Assert(inset != 0);
+ inset_ = 0;
+ FormInset::disconnect();
+}
+
+void FormGraphics::showDialog(InsetGraphics * inset)
+{
// If we are connected to another inset, disconnect.
if (inset_)
ih_.disconnect();
inset_ = inset;
- if (inset_) {
- ih_ = inset_->hide.connect(slot(this, &FormGraphics::hide));
- show();
- }
-}
-
-
-void FormGraphics::hide()
-{
- // If the dialog exists, and the form is allocated and visible.
- if (dialog_
- && dialog_->form
- && dialog_->form->visible) {
- // Hide the form
- fl_hide_form(dialog_->form);
-
- // And disconnect the signals.
- u_.disconnect();
- h_.disconnect();
- ih_.disconnect();
-
- // Forget the inset.
- inset_ = 0;
- }
- // Most of the time, the dialog is not needed anymore, we'll free it
- // now to save memory.
- free();
+ ih_ = inset_->hideDialog.connect(slot(this, &FormGraphics::hide));
+ show();
}
-void FormGraphics::free()
-{
- // Remove all associations for the radio buttons
- widthButtons.reset();
- heightButtons.reset();
- displayButtons.reset();
-
- // Free the form.
- delete dialog_;
- dialog_ = 0;
-}
-
void FormGraphics::apply()
{
Assert(inset_ != 0);
lv_->view()->updateInset(inset_, changed);
}
+
void FormGraphics::update()
{
Assert(inset_ != 0);
fl_set_button(dialog_->check_inline,
igp.inlineFigure);
+ // update the dialog's read only / read-write status
+ bc_.readOnly(lv_->buffer()->isReadonly());
+
// Now make sure that the buttons are set correctly.
- input();
+ input(0, 0);
}
-void FormGraphics::input()
+
+bool FormGraphics::input(FL_OBJECT *, long data )
+{
+ State cb = static_cast<State>( data );
+
+ bool inputOK = true;
+
+ switch (cb) {
+ case CHECKINPUT:
+ inputOK = checkInput();
+ break;
+ case BROWSE:
+ browse();
+ break;
+ case ADVANCEDINPUT:
+ lyxerr << "Advanced Options button depressed, "
+ << "show advanced options dialog"
+ << endl;
+ break;
+ default:
+ break;
+ }
+
+ return inputOK;
+}
+
+
+bool FormGraphics::checkInput()
{
// Put verifications that the dialog shows some sane values,
// if not disallow clicking on ok/apply.
inputOK = false;
}
-
- // Now set the buttons to the correct state.
- if (inputOK && ! lv_->buffer()->isReadonly()) {
- fl_activate_object(dialog_->button_ok);
- fl_activate_object(dialog_->button_apply);
- fl_set_object_lcol(dialog_->button_ok, FL_BLACK);
- fl_set_object_lcol(dialog_->button_apply, FL_BLACK);
- } else {
- fl_deactivate_object(dialog_->button_ok);
- fl_deactivate_object(dialog_->button_apply);
- fl_set_object_lcol(dialog_->button_ok, FL_INACTIVE);
- fl_set_object_lcol(dialog_->button_apply, FL_INACTIVE);
- }
+ return inputOK;
}
// We need these in the file browser.
extern string system_lyxdir;
extern string user_lyxdir;
-//extern string system_tempdir;
-
-// Need to move this to the form_graphics
-string FormGraphics::browseFile(string const & filename)
-{
- if (! filename.empty() )
- last_image_path = OnlyPath(filename);
-
- // Does user clipart directory exist?
- string bufclip = AddName (user_lyxdir, "clipart");
- FileInfo fileInfo(bufclip);
- if (!(fileInfo.isOK() && fileInfo.isDir()))
- // No - bail out to system clipart directory
- bufclip = AddName (system_lyxdir, "clipart");
-
- LyXFileDlg fileDlg;
- fileDlg.SetButton(0, _("Clipart"), bufclip);
-
- bool error = false;
- string buf;
- do {
- string p = fileDlg.Select(_("Graphics"),
- last_image_path,
- "*(ps|png)", filename);
-
- if (p.empty()) return p;
-
- last_image_path = OnlyPath(p);
-
- if (p.find_first_of("#~$% ") != string::npos) {
- WriteAlert(_("Filename can't contain any "
- "of these characters:"),
- // xgettext:no-c-format
- _("space, '#', '~', '$' or '%'."));
- error = true;
- } else {
- error = false;
- buf = p;
- }
- } while (error);
-
- return buf;
-}
void FormGraphics::browse()
{
// Get the filename from the dialog
- string filename = fl_get_input(dialog_->input_filename);
-
+ string const filename = fl_get_input(dialog_->input_filename);
+
+ string const title = N_("Graphics");
+ string const pattern = "*(ps|png)";
+
+ // Does user clipart directory exist?
+ string clipdir = AddName (user_lyxdir, "clipart");
+ FileInfo fileInfo(clipdir);
+ if (!(fileInfo.isOK() && fileInfo.isDir()))
+ // No - bail out to system clipart directory
+ clipdir = AddName (system_lyxdir, "clipart");
+ pair<string, string> dir1(N_("Clipart"), clipdir);
+
// Show the file browser dialog
- string new_filename = browseFile(filename);
+ string const new_filename =
+ browseFile(filename, title, pattern, dir1,
+ make_pair(string(), string()));
// Save the filename to the dialog
- if (new_filename != filename && ! new_filename.empty()) {
- fl_set_input(dialog_->input_filename,
- new_filename.c_str());
- // The above set input doesn't cause an input event so we do
- // it manually. Otherwise the user needs to cause an input event
- // to get the ok/apply buttons to be activated.
- input();
+ if (new_filename != filename && !new_filename.empty()) {
+ fl_set_input(dialog_->input_filename, new_filename.c_str());
+ input(0, 0);
}
-
-}
-
-int FormGraphics::WMHideCB(FL_FORM * form, void *)
-{
- // Ensure that the signal h is disconnected even if the
- // window manager is used to close the dialog.
- FormGraphics * pre = static_cast < FormGraphics* > (form->u_vdata);
- pre->hide();
- return FL_CANCEL;
}
-
-
-void FormGraphics::OKCB(FL_OBJECT * ob, long)
-{
- FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
- pre->apply();
- pre->hide();
-}
-
-void FormGraphics::ApplyCB(FL_OBJECT * ob, long)
-{
- FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
- pre->apply();
-}
-
-void FormGraphics::CancelCB(FL_OBJECT * ob, long)
-{
- FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
- pre->hide();
-}
-
-void FormGraphics::BrowseCB(FL_OBJECT * ob, long)
-{
- FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
- pre->browse();
-}
-
-void FormGraphics::AdvancedOptionsCB(FL_OBJECT * /* ob */, long)
-{
- // FormGraphics * pre = static_cast<FormGraphics*>(ob->form->u_vdata);
- // pre->showAdvancedOptions();
- lyxerr << "Advanced Options button depressed, "
- "show advanced options dialog"
- << endl;
-}
-
-void FormGraphics::InputCB(FL_OBJECT * ob, long)
-{
- FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
- pre->input();
-}
-