1 /* This file is part of
2 * =================================================
4 * LyX, The Document Processor
5 * Copyright 1995-2000 The LyX Team.
7 * =================================================
9 * \author Michael Koziarski <michael@koziarski.org>
13 #pragma implementation
21 #include "FormCredits.h"
22 #include "gnome_helpers.h"
24 #include <gtk--/button.h>
25 #include <gtk--/text.h>
26 #include <gtk--/style.h>
28 FormCredits::FormCredits(ControlCredits & c)
29 : FormCB<ControlCredits>(c, "diahelpcredits.glade", "DiaHelpCredits")
34 void FormCredits::build()
36 // It is better to show an OK button, but the policy require that we
37 // get a click on "Cancel"
38 ok()->clicked.connect(SigC::slot(this, &FormCredits::CancelClicked));
40 // Do not update the dialog when we insert the text
43 // Get the credits into the string stream
45 string credits = controller().getCredits(ss).str();
47 // Create the strings that we need to detect.
48 string const bold("@b");
49 string const italic("@i");
51 // Create the drawing contexts.
52 Gtk::Text_Helpers::Context c_italic;
53 Gtk::Text_Helpers::Context c_bold;
56 string bold = get_font_name(text()->get_style()->get_font());
57 //lyxerr << "Font name: " << bold << std::endl;
60 string const medium("Medium-");
61 std::string::size_type index = bold.find(medium);
62 bold.replace(index, medium.size()-1, "bold");
65 index = italic.find(r);
66 italic.replace(index, r.size()-1, "i");
68 //lyxerr << "Bold: " << bold << "\nItalic: " << italic << std::endl;
69 c_bold.set_font(Gdk_Font(bold));
70 c_italic.set_font(Gdk_Font(italic));
73 // Insert it into the text and parse the attributes.
74 while (!credits.empty()) {
75 std::string::size_type end = credits.find('\n');
76 string const line = credits.substr(0, ++end);
77 credits = credits.substr(end);
79 // lyxerr << "Line got: '" << line << "'\nend = " << end << std::endl;
81 string const prefix = line.substr(0, 2);
83 text()->insert(c_bold, line.substr(2));
84 } else if (prefix == italic) {
85 text()->insert(c_italic, line.substr(2));
91 // Allow the text area to be drawn.
96 Gtk::Text * FormCredits::text()
98 return getWidget<Gtk::Text>("credits_text");
101 Gtk::Button * FormCredits::ok()
103 return getWidget<Gtk::Button>("credits_button_ok");