1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <cerrno>
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_gui_misc.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "gettext.h"
|
2001-03-28 14:51:25 +00:00
|
|
|
#include "figure_form.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_cb.h"
|
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "print_form.h"
|
|
|
|
#include "sp_form.h"
|
1999-12-19 22:35:36 +00:00
|
|
|
#include "LyXView.h"
|
2000-04-12 14:20:08 +00:00
|
|
|
#include "bufferview_funcs.h"
|
2000-05-31 14:47:46 +00:00
|
|
|
#include "support/filetools.h"
|
2000-10-03 18:38:10 +00:00
|
|
|
#include "lyxrc.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::pair;
|
2000-01-04 14:11:01 +00:00
|
|
|
using std::make_pair;
|
2000-10-02 14:35:11 +00:00
|
|
|
using std::endl;
|
2000-01-04 14:11:01 +00:00
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
extern BufferView * current_view;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-11-28 06:46:06 +00:00
|
|
|
extern FD_form_figure * fd_form_figure;
|
1999-09-27 18:44:28 +00:00
|
|
|
extern FD_form_sendto * fd_form_sendto;
|
|
|
|
extern FD_form_spell_check * fd_form_spell_check;
|
|
|
|
|
|
|
|
extern void HideFiguresPopups();
|
|
|
|
|
|
|
|
// Prevents LyX from being killed when the close box is pressed in a popup.
|
1999-10-19 15:06:30 +00:00
|
|
|
extern "C" int CancelCloseBoxCB(FL_FORM *, void *)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return FL_CANCEL;
|
|
|
|
}
|
2000-11-28 06:46:06 +00:00
|
|
|
// Redraw the form (on receipt of a Signal indicating, for example,
|
|
|
|
// that the xform colors have been re-mapped).
|
|
|
|
void RedrawAllBufferRelatedDialogs()
|
|
|
|
{
|
|
|
|
if (fd_form_figure->form_figure->visible) {
|
|
|
|
fl_redraw_form(fd_form_figure->form_figure);
|
|
|
|
}
|
|
|
|
if (fd_form_sendto->form_sendto->visible) {
|
|
|
|
fl_redraw_form(fd_form_sendto->form_sendto);
|
|
|
|
}
|
|
|
|
if (fd_form_spell_check &&
|
|
|
|
fd_form_spell_check->form_spell_check->visible) {
|
|
|
|
fl_redraw_form(fd_form_spell_check->form_spell_check);
|
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Prevents LyX from crashing when no buffers available
|
|
|
|
// This is also one of the functions that we _really_ dont want
|
|
|
|
// we should try to finds way to help us with that.
|
|
|
|
// The signal/slot mechanism can probably help.
|
2000-06-12 11:27:15 +00:00
|
|
|
void CloseAllBufferRelatedDialogs()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// don't forget to check that dynamically created forms
|
|
|
|
// have been created otherwise hiding one could cause a crash
|
|
|
|
// need the visible check otherwise XForms prints a warning
|
|
|
|
// if hiding an invisible form
|
|
|
|
if (fd_form_figure->form_figure->visible) {
|
|
|
|
fl_hide_form(fd_form_figure->form_figure);
|
|
|
|
}
|
|
|
|
if (fd_form_sendto->form_sendto->visible) {
|
|
|
|
fl_hide_form(fd_form_sendto->form_sendto);
|
|
|
|
}
|
|
|
|
if (fd_form_spell_check) {
|
|
|
|
if (fd_form_spell_check->form_spell_check->visible) {
|
|
|
|
fl_trigger_object(fd_form_spell_check->done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HideFiguresPopups();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is another function we really don't want.
|
|
|
|
// Again the Signal/Slot mechanism is tailor made for this task.
|
2000-10-13 05:57:05 +00:00
|
|
|
void updateAllVisibleBufferRelatedDialogs(bool)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
HideFiguresPopups();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract shortcut from <ident>|<shortcut> string
|
1999-12-21 06:10:21 +00:00
|
|
|
char const * flyx_shortcut_extract(char const * sc)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// Find '|' in the sc and return the string after that.
|
1999-12-21 06:10:21 +00:00
|
|
|
register char const * sd = sc;
|
|
|
|
while(sd[0]!= 0 && sd[0] != '|') ++sd;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
if (sd[0] == '|') {
|
1999-12-21 06:10:21 +00:00
|
|
|
++sd;
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr << sd << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return sd;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Extract identifier from <ident>|<shortcut> string
|
1999-12-21 06:10:21 +00:00
|
|
|
char const * flyx_ident_extract(char const * sc)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-21 06:10:21 +00:00
|
|
|
register char const * se = sc;
|
|
|
|
while(se[0]!= 0 && se[0] != '|') ++se;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
if (se[0] == 0) return sc;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
char * sb = new char[se - sc + 1];
|
1999-09-27 18:44:28 +00:00
|
|
|
int index = 0;
|
1999-12-21 06:10:21 +00:00
|
|
|
register char const * sd = sc;
|
1999-09-27 18:44:28 +00:00
|
|
|
while (sd != se) {
|
|
|
|
sb[index] = sd[0];
|
1999-12-21 06:10:21 +00:00
|
|
|
++index; ++sd;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
sb[index] = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
//
|
1999-10-02 16:21:10 +00:00
|
|
|
void WriteAlert(string const & s1, string const & s2, string const & s3)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-24 17:33:01 +00:00
|
|
|
LyXView * lview = 0;
|
1999-12-19 22:35:36 +00:00
|
|
|
if (current_view && current_view->owner())
|
2001-04-24 17:33:01 +00:00
|
|
|
lview = current_view->owner();
|
|
|
|
if (lview) {
|
2000-10-02 04:21:44 +00:00
|
|
|
/// Write to minibuffer
|
2001-07-03 15:19:04 +00:00
|
|
|
lview->prohibitInput();
|
2001-04-17 15:15:59 +00:00
|
|
|
string const msg = s1 + ' ' + s2 + ' ' + s3;
|
2001-04-24 17:33:01 +00:00
|
|
|
lview->message(msg);
|
2000-10-02 04:21:44 +00:00
|
|
|
fl_set_resource("flAlert.dismiss.label", _("Dismiss"));
|
|
|
|
fl_show_alert(s1.c_str(), s2.c_str(), s3.c_str(), 0);
|
2001-07-03 15:19:04 +00:00
|
|
|
lview->allowInput();
|
2000-10-02 04:21:44 +00:00
|
|
|
} else {
|
|
|
|
/// Write to lyxerr
|
|
|
|
lyxerr << "----------------------------------------" << endl
|
|
|
|
<< s1 << endl << s2 << endl << s3 << endl
|
|
|
|
<< "----------------------------------------" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Alarms user of something related to files
|
1999-10-02 16:21:10 +00:00
|
|
|
void WriteFSAlert(string const & s1, string const & s2)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
WriteAlert(s1, s2, strerror(errno));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-03 18:38:10 +00:00
|
|
|
bool AskQuestion(string const & s1, string const & s2, string const & s3,
|
|
|
|
bool default_value)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-10-03 18:38:10 +00:00
|
|
|
if (!lyxrc.use_gui) {
|
|
|
|
lyxerr << "----------------------------------------" << endl
|
|
|
|
<< s1 << endl;
|
|
|
|
if (!s2.empty())
|
|
|
|
lyxerr << s2 << endl;
|
|
|
|
if (!s3.empty())
|
|
|
|
lyxerr << s3 << endl;
|
|
|
|
lyxerr << "Assuming answer is "
|
|
|
|
<< (default_value ? "yes" : "no")
|
|
|
|
<< endl
|
|
|
|
<< "----------------------------------------" << endl;
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_resource("flQuestion.yes.label", idex(_("Yes|Yy#y")));
|
|
|
|
fl_set_resource("flQuestion.no.label", idex(_("No|Nn#n")));
|
|
|
|
return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
|
|
|
|
}
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Returns 1 for yes, 2 for no, 3 for cancel.
|
2000-10-03 18:38:10 +00:00
|
|
|
int AskConfirmation(string const & s1, string const & s2, string const & s3,
|
|
|
|
int default_value)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-10-03 18:38:10 +00:00
|
|
|
if (!lyxrc.use_gui) {
|
|
|
|
lyxerr << "----------------------------------------" << endl
|
|
|
|
<< s1 << endl;
|
|
|
|
if (!s2.empty())
|
|
|
|
lyxerr << s2 << endl;
|
|
|
|
if (!s3.empty())
|
|
|
|
lyxerr << s3 << endl;
|
|
|
|
lyxerr << "Assuming answer is ";
|
|
|
|
if (default_value == 1)
|
|
|
|
lyxerr << "yes";
|
|
|
|
else if (default_value == 2)
|
|
|
|
lyxerr << "no";
|
|
|
|
else
|
|
|
|
lyxerr << "cancel";
|
|
|
|
lyxerr << endl
|
|
|
|
<< "----------------------------------------" << endl;
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_choices_shortcut(scex(_("Yes|Yy#y")),
|
|
|
|
scex(_("No|Nn#n")),
|
|
|
|
scex(_("Cancel|^[")));
|
|
|
|
return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
|
|
|
|
3, idex(_("Yes|Yy#y")),
|
|
|
|
idex(_("No|Nn#n")),
|
|
|
|
idex(_("Cancel|^[")), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Asks for a text
|
2000-08-05 05:17:18 +00:00
|
|
|
pair<bool, string> const
|
|
|
|
askForText(string const & msg, string const & dflt)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-10-03 18:38:10 +00:00
|
|
|
if (!lyxrc.use_gui) {
|
|
|
|
lyxerr << "----------------------------------------" << endl
|
|
|
|
<< msg << endl
|
|
|
|
<< "Assuming answer is " << dflt
|
|
|
|
<< "----------------------------------------" << endl;
|
|
|
|
return make_pair<bool, string>(true, dflt);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
|
|
|
|
fl_set_resource("flInput.ok.label", idex(_("OK|#O")));
|
|
|
|
fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
|
2000-05-19 19:46:23 +00:00
|
|
|
char const * tmp = fl_show_input(msg.c_str(), dflt.c_str());
|
1999-11-15 10:44:32 +00:00
|
|
|
if (tmp != 0)
|
2000-05-19 19:46:23 +00:00
|
|
|
return make_pair<bool, string>(true, string(tmp));
|
1999-11-15 10:44:32 +00:00
|
|
|
else
|
1999-12-30 02:35:43 +00:00
|
|
|
return make_pair<bool, string>(false, string());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Inform the user that the buffer is read-only, and that changes in the
|
|
|
|
// dialog box that is to appear will be ignored.
|
1999-12-21 06:10:21 +00:00
|
|
|
void WarnReadonly(string const & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
WriteAlert(_("Any changes will be ignored"),
|
|
|
|
_("The document is read-only:"),
|
2000-05-31 14:47:46 +00:00
|
|
|
MakeDisplayPath(file));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-04-11 16:57:16 +00:00
|
|
|
|
|
|
|
/// Get the dpi setting of the current screen
|
|
|
|
float getScreenDPI()
|
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
|
2000-04-11 16:57:16 +00:00
|
|
|
return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
|
|
|
|
(WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
|
|
|
|
}
|