]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormIndex.C
FormBase extends its reach into the codebase and gains a ButtonController
[lyx.git] / src / frontends / xforms / FormIndex.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20
21 #include "Dialogs.h"
22 #include "FormIndex.h"
23 #include "LyXView.h"
24 #include "buffer.h"
25 #include "form_index.h"
26 #include "lyxfunc.h"
27
28 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
29         : FormCommand(lv, d, _("Index")), minh(0), minw(0), dialog_(0)
30 {
31         // let the dialog be shown
32         // These are permanent connections so we won't bother
33         // storing a copy because we won't be disconnecting.
34         d->showIndex.connect(slot(this, &FormIndex::showInset));
35         d->createIndex.connect(slot(this, &FormIndex::createInset));
36 }
37
38
39 FormIndex::~FormIndex()
40 {
41         delete dialog_;
42 }
43
44
45 void FormIndex::build()
46 {
47         dialog_ = build_index();
48
49         // XFORMS bug workaround
50         // Define the min/max dimensions. Actually applied in update()
51         minw = form()->w; minh = form()->h;
52 }
53
54
55 FL_FORM * const FormIndex::form() const
56 {
57         if( dialog_ ) // no need to test for dialog_->form
58                 return dialog_->form;
59         else
60                 return 0;
61 }
62
63
64 void FormIndex::update()
65 {
66         fl_set_form_minsize(form(), minw, minh);
67         fl_set_form_maxsize(form(), 2*minw, minh);
68
69         fl_set_input(dialog_->key, params.getContents().c_str());
70
71         if( lv_->buffer()->isReadonly() ) {
72                 fl_deactivate_object( dialog_->key );
73                 fl_deactivate_object( dialog_->ok );
74                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
75         } else {
76                 fl_activate_object( dialog_->key );
77                 fl_activate_object( dialog_->ok );
78                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
79         }
80 }
81
82
83 void FormIndex::apply()
84 {
85         if(lv_->buffer()->isReadonly()) return;
86
87         params.setContents(fl_get_input(dialog_->key));
88
89         if (inset_ != 0) {
90                 // Only update if contents have changed
91                 if (params != inset_->params()) {
92                         inset_->setParams(params);
93                         lv_->view()->updateInset(inset_, true);
94                 }
95         } else {
96                 lv_->getLyXFunc()->Dispatch(LFUN_INDEX_INSERT,
97                                             params.getAsString());
98         }
99 }