]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreamble.C
Merging BRANCH_MVC back into HEAD.
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "form_preamble.h"
18 #include "FormPreamble.h"
19 #include "Dialogs.h"
20 #include "Liason.h"
21 #include "LyXView.h"
22 #include "buffer.h"
23 #include "gettext.h"
24 #include "xforms_helpers.h"
25
26 #ifdef CXX_WORKING_NAMESPACES
27 using Liason::setMinibuffer;
28 #endif
29
30 FormPreamble::FormPreamble(LyXView * lv, Dialogs * d)
31         : FormBaseBD(lv, d, _("LaTeX preamble"))
32 {
33     // let the popup be shown
34     // This is a permanent connection so we won't bother
35     // storing a copy because we won't be disconnecting.
36     d->showPreamble.connect(slot(this, &FormPreamble::show));
37 }
38
39
40 FL_FORM * FormPreamble::form() const
41 {
42     if (dialog_.get()) return dialog_->form;
43     return 0;
44 }
45
46
47 void FormPreamble::build()
48 {
49    dialog_.reset(build_preamble());
50    // Workaround dumb xforms sizing bug
51    minw_ = form()->w;
52    minh_ = form()->h;
53    
54    fl_set_input_return(dialog_->input_preamble, FL_RETURN_CHANGED);
55    // Manage the ok, apply and cancel/close buttons
56    bc().setOK(dialog_->button_ok);
57    bc().setApply(dialog_->button_apply);
58    bc().setCancel(dialog_->button_cancel);
59    bc().addReadOnly(dialog_->input_preamble);
60    bc().refresh();
61 }
62
63
64 void FormPreamble::apply()
65 {
66    if (!lv_->view()->available() || !dialog_.get())
67      return;
68    
69    // is this needed?:
70    // lv_->view()->update(BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
71    
72    lv_->buffer()->params.preamble = fl_get_input(dialog_->input_preamble);
73    lv_->buffer()->markDirty();
74    setMinibuffer(lv_, _("LaTeX preamble set"));
75 }
76
77
78 void FormPreamble::update()
79 {
80    if (!dialog_.get())
81      return;
82
83    fl_set_input(dialog_->input_preamble,lv_->buffer()->params.preamble.c_str());
84
85    bool const enable = (! lv_->buffer()->isReadonly());
86    setEnabled(dialog_->input_preamble, enable);
87    setEnabled(dialog_->button_ok,      enable);
88    setEnabled(dialog_->button_apply,   enable);
89    
90    // need this?
91    // bc().readOnly(lv_->buffer()->isReadonly());
92 }
93
94