]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTexinfo.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormTexinfo.C
1 /**
2  * \file FormTexinfo.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Herbert Voss <voss@lyx.org>
7  * \date 2001-10-01
8  */
9
10 #include <config.h>
11 #include <fstream>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "xformsBC.h"
18 #include "FormTexinfo.h"
19 #include "form_texinfo.h"
20 #include "gettext.h"
21 #include "debug.h"
22 #include "xforms_helpers.h"
23 #include "support/LAssert.h"
24     
25 namespace {
26
27 // C function wrapper, required by xforms.
28 extern "C"
29 int C_FormTexinfoFeedbackCB(FL_OBJECT * ob, int event,
30                             FL_Coord, FL_Coord, int, void *)
31 {
32         // Note that the return value is important in the pre-emptive handler.
33         // Don't return anything other than 0.
34
35         lyx::Assert(ob);
36         // Don't Assert this one, as it can happen quite reasonably when things
37         // are being deleted in the d-tor.
38         //Assert(ob->form);
39         if (!ob->form) return 0;
40
41         FormTexinfo * pre =
42                 static_cast<FormTexinfo*>(ob->form->u_vdata);
43         pre->feedbackCB(ob, event);
44         return 0;
45 }
46         
47 void setPreHandler(FL_OBJECT * ob)
48 {
49         lyx::Assert(ob);
50         fl_set_object_prehandler(ob, C_FormTexinfoFeedbackCB);
51 }
52  
53 } // namespace anon
54
55
56 typedef FormCB<ControlTexinfo, FormDB<FD_form_texinfo> > base_class;
57 FormTexinfo::FormTexinfo(ControlTexinfo & c)
58         : base_class(c, _("TeX Infos")),
59           warningPosted(false), activeStyle(ControlTexinfo::cls)
60 {}
61
62
63 void FormTexinfo::build() {
64         dialog_.reset(build_texinfo());
65         // courier medium
66         fl_set_browser_fontstyle(dialog_->browser,FL_FIXED_STYLE);
67         // with Path is default
68         fl_set_button(dialog_->button_fullPath, 1);
69         updateStyles(ControlTexinfo::cls);
70
71         setPreHandler(dialog_->button_rescan);
72         setPreHandler(dialog_->button_view);
73         setPreHandler(dialog_->button_texhash);
74         setPreHandler(dialog_->button_fullPath);
75         setPreHandler(dialog_->browser);
76         setPreHandler(dialog_->radio_cls);
77         setPreHandler(dialog_->radio_sty);
78         setPreHandler(dialog_->radio_bst);
79         setPreHandler(dialog_->message);
80         setPreHandler(dialog_->help);
81 }
82
83
84 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long) {
85         if (ob == dialog_->help) {
86                 controller().help();
87
88         } else if (ob == dialog_->radio_cls) {
89                 updateStyles(ControlTexinfo::cls); 
90
91         } else if (ob == dialog_->radio_sty) {
92                 updateStyles(ControlTexinfo::sty); 
93
94         } else if (ob == dialog_->radio_bst) {
95                 updateStyles(ControlTexinfo::bst); 
96
97         } else if (ob == dialog_->button_rescan) {
98                 // build new *Files.lst
99                 controller().rescanStyles();
100                 updateStyles(activeStyle);
101
102         } else if (ob == dialog_->button_fullPath) {
103                 setEnabled(dialog_->button_view,
104                            fl_get_button(dialog_->button_fullPath));
105                 updateStyles(activeStyle);
106
107         } else if (ob == dialog_->button_texhash) {
108                 // makes only sense if the rights are set well for
109                 // users (/var/lib/texmf/ls-R)
110                 controller().runTexhash();
111                 // update files in fact of texhash
112                 controller().rescanStyles();
113
114         } else if (ob == dialog_->button_view) {
115                 unsigned int selection = fl_get_browser(dialog_->browser);
116                 // a valid entry?
117                 if (selection > 0) {
118                         controller().viewFile( 
119                                 fl_get_browser_line(dialog_->browser,
120                                                     selection));
121                 }
122         }
123
124         return ButtonPolicy::SMI_VALID;
125 }
126
127 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
128 {
129         fl_clear_browser(dialog_->browser); 
130
131         bool const withFullPath = fl_get_button(dialog_->button_fullPath);
132
133         string const str = 
134                 controller().getContents(whichStyle, withFullPath);
135         fl_add_browser_line(dialog_->browser, str.c_str());
136
137         activeStyle = whichStyle;
138 }
139
140
141 // preemptive handler for feedback messages
142 void FormTexinfo::feedbackCB(FL_OBJECT * ob, int event)
143 {
144         lyx::Assert(ob);
145
146         switch (event) {
147         case FL_ENTER:
148                 warningPosted = false;
149                 feedback(ob);
150                 break;
151
152         case FL_LEAVE:
153                 if (!warningPosted) {
154                         fl_set_object_label(dialog_->message, "");
155                         fl_redraw_object(dialog_->message);
156                 }
157                 break;
158
159         default:
160                 break;
161         }
162 }
163
164
165 void FormTexinfo::feedback(FL_OBJECT * ob)
166 {
167         lyx::Assert(ob);
168
169         string str;
170
171         if (ob == dialog_->button_rescan) {
172                 str = _("starts rescan ...");
173
174         } else if (ob == dialog_->button_fullPath) {
175                 str = _("View full path or only file name");
176
177         } else if (ob == dialog_->button_texhash) {
178                 str = _("starts texhash and rescan...");
179
180         } else if (ob == dialog_->button_view) {
181                 str = _("views a selected file");
182
183         }
184         
185         fl_set_object_label(dialog_->message, str.c_str());
186         fl_redraw_object(dialog_->message);
187 }