2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995-2000 The LyX Team.
8 * =================================================
10 * \author Michael Koziarski <michael@koziarski.org>
14 #pragma implementation
22 #include "FormCredits.h"
23 #include "gnome_helpers.h"
25 #include <gtk--/button.h>
26 #include <gtk--/text.h>
27 #include <gtk--/style.h>
29 FormCredits::FormCredits(ControlCredits & c)
30 : FormCB<ControlCredits>(c, "diahelpcredits.glade", "DiaHelpCredits")
35 void FormCredits::build()
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));
41 // Do not update the dialog when we insert the text
44 // Get the credits into the string stream
46 string credits = controller().getCredits(ss).str();
48 // Create the strings that we need to detect.
49 string const bold("@b");
50 string const italic("@i");
52 // Create the drawing contexts.
53 Gtk::Text_Helpers::Context c_italic;
54 Gtk::Text_Helpers::Context c_bold;
57 string bold = get_font_name(text()->get_style()->get_font());
58 //lyxerr << "Font name: " << bold << std::endl;
61 string const medium("Medium-");
62 std::string::size_type index = bold.find(medium);
63 bold.replace(index, medium.size()-1, "bold");
66 index = italic.find(r);
67 italic.replace(index, r.size()-1, "i");
69 //lyxerr << "Bold: " << bold << "\nItalic: " << italic << std::endl;
70 c_bold.set_font(Gdk_Font(bold));
71 c_italic.set_font(Gdk_Font(italic));
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);
80 // lyxerr << "Line got: '" << line << "'\nend = " << end << std::endl;
82 string const prefix = line.substr(0, 2);
84 text()->insert(c_bold, line.substr(2));
85 } else if (prefix == italic) {
86 text()->insert(c_italic, line.substr(2));
92 // Allow the text area to be drawn.
97 Gtk::Text * FormCredits::text()
99 return getWidget<Gtk::Text>("credits_text");
102 Gtk::Button * FormCredits::ok()
104 return getWidget<Gtk::Button>("credits_button_ok");