]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormIndex.C
Angus's insetref-patch and a small fix.
[features.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 "gettext.h"
22 #include "Dialogs.h"
23 #include "FormIndex.h"
24 #include "LyXView.h"
25 #include "buffer.h"
26 #include "form_index.h"
27 #include "lyxfunc.h"
28
29 FormIndex::FormIndex(LyXView * lv, Dialogs * d)
30         : FormCommand(lv, d, _("Index")), dialog_(0), minh(0), minw(0)
31 {
32         // let the dialog be shown
33         // These are permanent connections so we won't bother
34         // storing a copy because we won't be disconnecting.
35         d->showIndex.connect(slot(this, &FormIndex::showInset));
36         d->createIndex.connect(slot(this, &FormIndex::createInset));
37 }
38
39
40 FormIndex::~FormIndex()
41 {
42         free();
43         delete dialog_;
44 }
45
46
47 void FormIndex::build()
48 {
49         dialog_ = build_index();
50
51         // XFORMS bug workaround
52         // Define the min/max dimensions. Actually applied in update()
53         minw = form()->w; minh = form()->h;
54 }
55
56
57 FL_FORM * const FormIndex::form() const
58 {
59         if( dialog_ ) // no need to test for dialog_->form_index
60                 return dialog_->form_index;
61         else
62                 return 0;
63 }
64
65
66 void FormIndex::update()
67 {
68         fl_set_form_minsize(form(), minw, minh);
69         fl_set_form_maxsize(form(), 2*minw, minh);
70
71         fl_set_input(dialog_->key, params.getContents().c_str());
72
73         if( lv_->buffer()->isReadonly() ) {
74                 fl_deactivate_object( dialog_->key );
75                 fl_deactivate_object( dialog_->ok );
76                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
77         } else {
78                 fl_activate_object( dialog_->key );
79                 fl_activate_object( dialog_->ok );
80                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
81         }
82 }
83
84
85 void FormIndex::apply()
86 {
87         if( lv_->buffer()->isReadonly() ) return;
88
89         params.setContents( fl_get_input(dialog_->key) );
90
91         if( inset_ != 0 )
92         {
93                 // Only update if contents have changed
94                 if( params != inset_->params() ) {
95                         inset_->setParams( params );
96                         lv_->view()->updateInset( inset_, true );
97                 }
98         } else {
99                 lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
100                                              params.getAsString().c_str() );
101         }
102 }