]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreamble.C
create and use a little setEnabled() xforms wrapper function.
[lyx.git] / src / frontends / xforms / FormPreamble.C
1 /**
2  * \file FormPreamble.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Edwin Leuven, leuven@fee.uva.nl
7  */
8
9 #include <config.h>
10
11 #include FORMS_H_LOCATION
12
13 #include "form_preamble.h"
14 #include "FormPreamble.h"
15 #include "Dialogs.h"
16 #include "Liason.h"
17 #include "LyXView.h"
18 #include "buffer.h"
19 #include "gettext.h"
20 #include "xforms_helpers.h"
21
22 #ifdef CXX_WORKING_NAMESPACES
23 using Liason::setMinibuffer;
24 #endif
25
26 FormPreamble::FormPreamble(LyXView * lv, Dialogs * d)
27         : FormBaseBD(lv, d, _("LaTeX preamble"), new NoRepeatedApplyReadOnlyPolicy),
28         dialog_(0)
29 {
30     // let the popup be shown
31     // This is a permanent connection so we won't bother
32     // storing a copy because we won't be disconnecting.
33     d->showPreamble.connect(slot(this, &FormPreamble::show));
34 }
35
36
37 FormPreamble::~FormPreamble()
38 {
39    delete dialog_;
40 }
41
42
43 FL_FORM * FormPreamble::form() const
44 {
45     if (dialog_) return dialog_->form;
46     return 0;
47 }
48
49 void FormPreamble::build()
50 {
51    dialog_ = build_preamble();
52    // Workaround dumb xforms sizing bug
53    minw_ = form()->w;
54    minh_ = form()->h;
55    
56    fl_set_input_return(dialog_->input_preamble, FL_RETURN_CHANGED);
57    // Manage the ok, apply and cancel/close buttons
58    bc_.setOK(dialog_->button_ok);
59    bc_.setApply(dialog_->button_apply);
60    bc_.setCancel(dialog_->button_cancel);
61    bc_.addReadOnly(dialog_->input_preamble);
62    bc_.refresh();
63 }
64
65 void FormPreamble::apply()
66 {
67    if (!lv_->view()->available() || !dialog_)
68      return;
69    
70    // is this needed?:
71    // lv_->view()->update(BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
72    
73    lv_->buffer()->params.preamble = fl_get_input(dialog_->input_preamble);
74    lv_->buffer()->markDirty();
75    setMinibuffer(lv_, _("LaTeX preamble set"));
76 }
77
78
79 void FormPreamble::update()
80 {
81    if (!dialog_)
82      return;
83
84    fl_set_input(dialog_->input_preamble,lv_->buffer()->params.preamble.c_str());
85
86    bool const enable = (! lv_->buffer()->isReadonly());
87    setEnabled(dialog_->input_preamble, enable);
88    setEnabled(dialog_->button_ok,      enable);
89    setEnabled(dialog_->button_apply,   enable);
90    
91    // need this?
92    // bc_.readOnly(lv_->buffer()->isReadonly());
93 }
94
95