]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormToc.C
fix tooltips in toolbar
[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::vector;
28 using std::endl;
29
30
31 typedef FormCB<ControlToc, FormDB<FD_toc> > base_class;
32
33 FormToc::FormToc(ControlToc & c, Dialogs & d)
34         : base_class(c, d, _("Table of Contents"))
35 {}
36
37
38 void FormToc::build()
39 {
40         dialog_.reset(build_toc(this));
41
42         vector<string> types = controller().getTypes();
43         
44         
45         string const choice =
46                 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
47         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
48
49         // Manage the cancel/close button
50         bc().setCancel(dialog_->button_close);
51 }
52
53
54 void FormToc::update()
55 {
56         updateType();
57         updateContents();
58 }
59
60
61 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
62 {
63         if (ob == dialog_->browser_toc) {
64                 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
65
66                 if (choice - 1 < toc_.size() && choice >= 1) {
67                         controller().goTo(toc_[choice - 1]);
68                 }
69                 return ButtonPolicy::SMI_VALID;
70         }
71
72         if (ob != dialog_->choice_toc_type) {
73                 updateType();
74         }
75
76         updateContents();
77
78         return ButtonPolicy::SMI_VALID;
79 }
80
81
82 void FormToc::updateType()
83 {
84         // Update the choice list from scratch
85         fl_clear_choice(dialog_->choice_toc_type);
86         string const choice = getStringFromVector(controller().getTypes(), "|");
87         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
88
89         // And select the correct one
90         string const type = toc::getType(controller().params().getCmdName());
91         fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
92 }
93
94
95 void FormToc::updateContents()
96 {
97         string const type = getString(dialog_->choice_toc_type);
98         if (type.empty()) {
99                 fl_clear_browser(dialog_->browser_toc);
100                 fl_add_browser_line(dialog_->browser_toc,
101                                     _("*** No Lists ***"));
102                 setEnabled(dialog_->browser_toc, false);
103                 return;
104         }
105
106         toc::Toc const contents = controller().getContents(type);
107
108         // Check if all elements are the same.
109         if (toc_ == contents) {
110                 return;
111         }
112
113         // List has changed. Update browser
114         toc_ = contents;
115
116         if (contents.empty()) {
117                 fl_clear_browser(dialog_->browser_toc);
118                 fl_add_browser_line(dialog_->browser_toc,
119                                     _("*** No Lists ***"));
120                 setEnabled(dialog_->browser_toc, false);
121                 return;
122         }
123
124         unsigned int const topline =
125                 fl_get_browser_topline(dialog_->browser_toc);
126         unsigned int const line = fl_get_browser(dialog_->browser_toc);
127
128         fl_clear_browser(dialog_->browser_toc);
129         setEnabled(dialog_->browser_toc, true);
130
131         toc::Toc::const_iterator cit = contents.begin();
132         toc::Toc::const_iterator end = contents.end();
133         for (; cit != end; ++cit) {
134                 fl_add_browser_line(dialog_->browser_toc,
135                                     cit->asString().c_str());
136         }
137
138         fl_set_browser_topline(dialog_->browser_toc, topline);
139         fl_select_browser_line(dialog_->browser_toc, line);
140 }