]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormIndex.C
Fix crash on exit (angus)
[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 "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)
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
52
53 FL_FORM * const FormIndex::form() const
54 {
55         if( dialog_ && dialog_->form_index )
56                 return dialog_->form_index;
57         else
58                 return 0;
59 }
60
61
62 void FormIndex::update()
63 {
64         static int ow = -1, oh;
65
66         if (ow < 0) {
67                 ow = dialog_->form_index->w;
68                 oh = dialog_->form_index->h;
69
70                 fl_set_form_minsize(dialog_->form_index, ow, oh);
71                 fl_set_form_maxsize(dialog_->form_index, 2*ow, oh);
72         }
73
74         fl_freeze_form( dialog_->form_index );
75
76         fl_set_input(dialog_->key, params.getContents().c_str());
77
78         if( lv_->buffer()->isReadonly() ) {
79                 fl_deactivate_object( dialog_->key );
80                 fl_deactivate_object( dialog_->ok );
81                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
82         } else {
83                 fl_activate_object( dialog_->key );
84                 fl_activate_object( dialog_->ok );
85                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
86         }
87
88         fl_unfreeze_form( dialog_->form_index );
89 }
90
91
92 void FormIndex::apply()
93 {
94         if( lv_->buffer()->isReadonly() ) return;
95
96         params.setContents( fl_get_input(dialog_->key) );
97
98         if( inset_ != 0 )
99         {
100                 // Only update if contents have changed
101                 if( params.getContents() != inset_->getContents() ) {
102                         inset_->setParams( params );
103                         lv_->view()->updateInset( inset_, true );
104                 }
105         } else {
106                 lv_->getLyXFunc()->Dispatch( LFUN_INDEX_INSERT,
107                                              params.getAsString().c_str() );
108         }
109 }