]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormCredits.C
implement getLabelList
[lyx.git] / src / frontends / gnome / FormCredits.C
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995-2000 The LyX Team.
7  *
8  * ================================================= 
9  *
10  * \author Michael Koziarski <michael@koziarski.org>
11  */
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <config.h>
18
19 #include "debug.h"
20
21 #include "gnomeBC.h"
22 #include "FormCredits.h"
23 #include "gnome_helpers.h"
24
25 #include <gtk--/button.h>
26 #include <gtk--/text.h>
27 #include <gtk--/style.h>
28
29 FormCredits::FormCredits(ControlCredits & c)
30         : FormCB<ControlCredits>(c, "diahelpcredits.glade", "DiaHelpCredits")
31 {
32 }
33
34
35 void FormCredits::build()
36 {
37         // It is better to show an OK button, but the policy require that we
38         // get a click on "Cancel"
39         ok()->clicked.connect(SigC::slot(this, &FormCredits::CancelClicked));
40
41         // Do not update the dialog when we insert the text
42         text()->freeze();
43         
44         // Get the credits into the string stream
45         std::stringstream ss;
46         string credits = controller().getCredits(ss).str();
47
48         // Create the strings that we need to detect.
49         string const bold("@b");
50         string const italic("@i");
51
52         // Create the drawing contexts.
53         Gtk::Text_Helpers::Context c_italic;
54         Gtk::Text_Helpers::Context c_bold;
55
56         {
57                 string bold = get_font_name(text()->get_style()->get_font());
58                 //lyxerr << "Font name: " << bold << std::endl;
59                 string italic(bold);
60
61                 string const medium("Medium-");
62                 std::string::size_type index = bold.find(medium);
63                 bold.replace(index, medium.size()-1, "bold");
64
65                 string const r("R-");
66                 index = italic.find(r);
67                 italic.replace(index, r.size()-1, "i");
68                 
69                 //lyxerr << "Bold: " << bold << "\nItalic: " << italic << std::endl;
70                 c_bold.set_font(Gdk_Font(bold));
71                 c_italic.set_font(Gdk_Font(italic));
72         }
73
74         // Insert it into the text and parse the attributes.
75         while (!credits.empty()) {
76                 std::string::size_type end = credits.find('\n');
77                 string const line = credits.substr(0, ++end);
78                 credits = credits.substr(end);
79                 
80 //              lyxerr << "Line got: '" << line << "'\nend = " << end << std::endl;
81                 
82                 string const prefix = line.substr(0, 2);
83                 if (prefix == bold) {
84                         text()->insert(c_bold, line.substr(2));
85                 } else if (prefix == italic) {
86                         text()->insert(c_italic, line.substr(2));
87                 } else {
88                         text()->insert(line);
89                 }
90         }
91         
92         // Allow the text area to be drawn.
93         text()->thaw();
94 }
95
96
97 Gtk::Text * FormCredits::text()
98 {
99         return getWidget<Gtk::Text>("credits_text");
100 }
101
102 Gtk::Button * FormCredits::ok()
103 {
104         return getWidget<Gtk::Button>("credits_button_ok");
105 }