]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormPreamble.C
try this for distinguishing inner and outer tabs
[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
21 #ifdef CXX_WORKING_NAMESPACES
22 using Liason::setMinibuffer;
23 #endif
24
25 FormPreamble::FormPreamble(LyXView * lv, Dialogs * d)
26         : FormBaseBD(lv, d, _("LaTeX preamble"), new NoRepeatedApplyReadOnlyPolicy),
27         dialog_(0)
28 {
29     // let the popup be shown
30     // This is a permanent connection so we won't bother
31     // storing a copy because we won't be disconnecting.
32     d->showPreamble.connect(slot(this, &FormPreamble::show));
33 }
34
35
36 FormPreamble::~FormPreamble()
37 {
38    delete dialog_;
39 }
40
41
42 FL_FORM * FormPreamble::form() const
43 {
44     if (dialog_) return dialog_->form;
45     return 0;
46 }
47
48 void FormPreamble::build()
49 {
50    dialog_ = build_preamble();
51    // Workaround dumb xforms sizing bug
52    minw_ = form()->w;
53    minh_ = form()->h;
54    
55    fl_set_input_return(dialog_->input_preamble, FL_RETURN_CHANGED);
56    // Manage the ok, apply and cancel/close buttons
57    bc_.setOK(dialog_->button_ok);
58    bc_.setApply(dialog_->button_apply);
59    bc_.setCancel(dialog_->button_cancel);
60    bc_.addReadOnly(dialog_->input_preamble);
61    bc_.refresh();
62 }
63
64 void FormPreamble::apply()
65 {
66    if (!lv_->view()->available() || !dialog_)
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_)
81      return;
82
83    fl_set_input(dialog_->input_preamble,lv_->buffer()->params.preamble.c_str());
84    if (lv_->buffer()->isReadonly()) {
85       fl_deactivate_object(dialog_->input_preamble);
86       fl_deactivate_object(dialog_->button_ok);
87       fl_deactivate_object(dialog_->button_apply);
88       fl_set_object_lcol(dialog_->button_ok, FL_INACTIVE);
89       fl_set_object_lcol(dialog_->button_apply, FL_INACTIVE);
90    } else {
91       fl_activate_object(dialog_->input_preamble);
92       fl_activate_object(dialog_->button_ok);
93       fl_activate_object(dialog_->button_apply);
94       fl_set_object_lcol(dialog_->button_ok, FL_BLACK);
95       fl_set_object_lcol(dialog_->button_apply, FL_BLACK);
96    }
97    
98    // need this?
99    // bc_.readOnly(lv_->buffer()->isReadonly());
100 }
101
102