]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormToc.C
toc support reorganization; changes to xform_helpers; aspect ratio patch from herbert
[lyx.git] / src / frontends / xforms / FormToc.C
1 /**
2  * \file xforms/FormToc.C
3  * Copyright 2000-2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Angus Leeming, a.leeming@ic.ac.uk
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "FormToc.h"
16 #include "xformsBC.h"
17 #include "xforms_helpers.h"
18 #include "ControlToc.h"
19 #include "forms/form_toc.h"
20 #include "support/lstrings.h" // frontStrip, strip
21 #include "debug.h"
22 #include "gettext.h"
23 #include FORMS_H_LOCATION
24
25 #include <vector>
26
27 using std::endl;
28
29
30 typedef FormCB<ControlToc, FormDB<FD_toc> > base_class;
31
32 FormToc::FormToc(ControlToc & c, Dialogs & d)
33         : base_class(c, d, _("Table of Contents"))
34 {}
35
36
37 void FormToc::build()
38 {
39         dialog_.reset(build_toc(this));
40
41         vector<string> types = controller().getTypes();
42         
43         
44         string const choice =
45                 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
46         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
47
48         // Manage the cancel/close button
49         bc().setCancel(dialog_->button_close);
50 }
51
52
53 void FormToc::update()
54 {
55         updateType();
56         updateContents();
57 }
58
59
60 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
61 {
62         if (ob == dialog_->browser_toc) {
63                 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
64
65                 if (choice - 1 < toc_.size() && choice >= 1) {
66                         controller().goTo(toc_[choice - 1]);
67                 }
68                 return ButtonPolicy::SMI_VALID;
69         }
70
71         if (ob != dialog_->choice_toc_type) {
72                 updateType();
73         }
74
75         updateContents();
76
77         return ButtonPolicy::SMI_VALID;
78 }
79
80
81 void FormToc::updateType()
82 {
83         // Update the choice list from scratch
84         fl_clear_choice(dialog_->choice_toc_type);
85         string const choice = getStringFromVector(controller().getTypes(), "|");
86         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
87
88         // And select the correct one
89         string const type = toc::getType(controller().params().getCmdName());
90         fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
91 }
92
93
94 void FormToc::updateContents()
95 {
96         string const type = getString(dialog_->choice_toc_type);
97         if (type.empty()) {
98                 fl_clear_browser(dialog_->browser_toc);
99                 fl_add_browser_line(dialog_->browser_toc,
100                                     _("*** No Lists ***"));
101                 setEnabled(dialog_->browser_toc, false);
102                 return;
103         }
104
105         toc::Toc const contents = controller().getContents(type);
106
107         // Check if all elements are the same.
108         if (toc_ == contents) {
109                 return;
110         }
111
112         // List has changed. Update browser
113         toc_ = contents;
114
115         if (contents.empty()) {
116                 fl_clear_browser(dialog_->browser_toc);
117                 fl_add_browser_line(dialog_->browser_toc,
118                                     _("*** No Lists ***"));
119                 setEnabled(dialog_->browser_toc, false);
120                 return;
121         }
122
123         unsigned int const topline =
124                 fl_get_browser_topline(dialog_->browser_toc);
125         unsigned int const line = fl_get_browser(dialog_->browser_toc);
126
127         fl_clear_browser(dialog_->browser_toc);
128         setEnabled(dialog_->browser_toc, true);
129
130         toc::Toc::const_iterator cit = contents.begin();
131         toc::Toc::const_iterator end = contents.end();
132         for (; cit != end; ++cit) {
133                 fl_add_browser_line(dialog_->browser_toc,
134                                     cit->asString().c_str());
135         }
136
137         fl_set_browser_topline(dialog_->browser_toc, topline);
138         fl_select_browser_line(dialog_->browser_toc, line);
139 }