]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormToc.C
doxygen fixes
[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 "ControlToc.h"
18 #include "form_toc.h"
19 #include "helper_funcs.h" // getStringFromVector
20 #include "support/lstrings.h" // frontStrip, strip
21 #include "debug.h"
22 #include "gettext.h"
23
24 #include <vector>
25
26 using std::endl;
27
28
29 typedef FormCB<ControlToc, FormDB<FD_form_toc> > base_class;
30
31 FormToc::FormToc(ControlToc & c)
32         : base_class(c, _("Table of Contents"))
33 {}
34
35
36 void FormToc::build()
37 {
38         dialog_.reset(build_toc());
39
40         string const choice =
41                 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
42         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
43
44         // Manage the cancel/close button
45         bc().setCancel(dialog_->button_cancel);
46 }
47
48
49 void FormToc::update()
50 {
51         updateType();
52         updateContents();
53 }
54
55
56 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
57 {
58         if (ob == dialog_->browser_toc) {
59                 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
60
61                 if (choice - 1 < toclist_.size() && choice >= 1) {
62                         controller().Goto(toclist_[choice - 1].par->id());
63                 }
64                 return ButtonPolicy::SMI_VALID;
65         }
66
67         if (ob != dialog_->choice_toc_type) {
68                 updateType();
69         }
70  
71         updateContents();
72
73         return ButtonPolicy::SMI_VALID;
74 }
75
76
77 void FormToc::updateType()
78 {
79         // Update the choice list from scratch
80         fl_clear_choice(dialog_->choice_toc_type);
81         string const choice = getStringFromVector(controller().getTypes(), "|");
82         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
83
84         // And select the correct one
85         string const type = toc::getType(controller().params().getCmdName());
86         
87         fl_set_choice(dialog_->choice_toc_type, 1);
88         for (int i = 1;
89              i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
90                 string const choice =
91                         fl_get_choice_item_text(dialog_->choice_toc_type, i);
92
93                 if (choice == type) {
94                         fl_set_choice(dialog_->choice_toc_type, i);
95                         break;
96                 }
97         }
98 }
99
100
101 void FormToc::updateContents()
102 {
103         char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
104  
105         if (!tmp) {
106                 fl_clear_browser(dialog_->browser_toc);
107                 fl_add_browser_line(dialog_->browser_toc,
108                                     _("*** No Lists ***"));
109                 return;
110         }
111  
112         string const type = frontStrip(strip(tmp));
113
114         Buffer::SingleList const contents = controller().getContents(type);
115
116         if (contents.empty()) {
117                 fl_clear_browser(dialog_->browser_toc);
118                 fl_add_browser_line(dialog_->browser_toc,
119                                     _("*** No Lists ***"));
120         }
121         
122         // Check if all elements are the same.
123         if (toclist_ == contents) {
124                 return;
125         }
126         
127         // List has changed. Update browser
128         toclist_ = contents;
129
130         unsigned int const topline =
131                 fl_get_browser_topline(dialog_->browser_toc);
132         unsigned int const line = fl_get_browser(dialog_->browser_toc);
133
134         fl_clear_browser(dialog_->browser_toc);
135
136         Buffer::SingleList::const_iterator cit = toclist_.begin();
137         Buffer::SingleList::const_iterator end = toclist_.end();
138         
139         for (; cit != end; ++cit) {
140                 string const line = string(4 * cit->depth, ' ') + cit->str;
141                 fl_add_browser_line(dialog_->browser_toc, line.c_str());
142         }
143         
144         fl_set_browser_topline(dialog_->browser_toc, topline);
145         fl_select_browser_line(dialog_->browser_toc, line);
146 }