lyx_mirror/src/frontends/gnome/FormUrl.C

181 lines
3.5 KiB
C++
Raw Normal View History

// -*- C++ -*-
/* This file is part of
* =================================================
*
* LyX, The Document Processor
* Copyright 1995-2000 The LyX Team.
*
* =================================================
*
* \author Baruch Even
*/
#ifdef __GNUG__
#pragma implementation
#endif
#include <config.h>
#include "gnomeBC.h"
#include "FormUrl.h"
#include <gnome--/dialog.h>
#include <gtk--/entry.h>
#include <gtk--/checkbutton.h>
FormUrl::FormUrl(ControlUrl & c)
: FormCB<ControlUrl>(c, "diainserturl.glade", "DiaInsertUrl")
, dialog_(0)
{}
FormUrl::~FormUrl()
{
// Note that there is no need to destroy the class itself, it seems
// like everything is managed inside it. Deleting the class itself will
// a crash at the end of the program.
dialog_->destroy();
}
void FormUrl::build()
{
// Make sure the dialog is loaded.
dialog_ = dialog();
// Connect the buttons.
ok_btn()->clicked.connect(SigC::slot(this, &FormUrl::OKClicked));
cancel_btn()->clicked.connect(SigC::slot(this, &FormUrl::CancelClicked));
apply_btn()->clicked.connect(SigC::slot(this, &FormUrl::ApplyClicked));
restore_btn()->clicked.connect(SigC::slot(this, &FormUrl::RestoreClicked));
// Manage the buttons state
bc().setOK(ok_btn());
bc().setCancel(cancel_btn());
bc().setApply(apply_btn());
bc().setUndoAll(restore_btn());
// Make sure everything is in the correct state.
bc().refresh();
// Manage the read-only aware widgets.
bc().addReadOnly(html());
bc().addReadOnly(name());
bc().addReadOnly(url());
}
void FormUrl::connect_signals()
{
// Get notifications on input change
slot_url_ = url()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
slot_name_ = name()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
slot_html_ = html()->toggled.connect(SigC::slot(this, &FormUrl::InputChanged));
}
void FormUrl::disconnect_signals()
{
slot_url_.disconnect();
slot_name_.disconnect();
slot_html_.disconnect();
}
void FormUrl::show()
{
if (!dialog_)
build();
update();
dialog_->show();
}
void FormUrl::hide()
{
dialog_->hide();
}
void FormUrl::apply()
{
controller().params().setContents(url()->get_text());
controller().params().setOptions(name()->get_text());
string cmdname("url");
if (html()->get_active())
cmdname = "htmlurl";
controller().params().setCmdName(cmdname);
}
void FormUrl::update()
{
// Disconnect signals so we dont trigger the input changed state.
// This avoids the problem of having the buttons enabled when the dialog
// starts.
disconnect_signals();
url()->set_text(controller().params().getContents());
name()->set_text(controller().params().getOptions());
html()->set_active("url" != controller().params().getCmdName());
// Reconnect the signals.
connect_signals();
}
bool FormUrl::validate() const
{
// Always valid! (not really so, needs fixing).
return true;
}
Gnome::Dialog * FormUrl::dialog()
{
return getWidget<Gnome::Dialog>("DiaInsertUrl");
}
Gtk::Entry * FormUrl::url() const
{
return getWidget<Gtk::Entry>("url");
}
Gtk::Entry * FormUrl::name() const
{
return getWidget<Gtk::Entry>("name");
}
Gtk::CheckButton * FormUrl::html() const
{
return getWidget<Gtk::CheckButton>("html_type");
}
Gtk::Button * FormUrl::ok_btn() const
{
return getWidget<Gtk::Button>("button_ok");
}
Gtk::Button * FormUrl::cancel_btn() const
{
return getWidget<Gtk::Button>("button_cancel");
}
Gtk::Button * FormUrl::apply_btn() const
{
return getWidget<Gtk::Button>("button_apply");
}
Gtk::Button * FormUrl::restore_btn() const
{
return getWidget<Gtk::Button>("button_restore");
}