1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/*
* Copyright © 2004-2008 Jens Oknelid, paskharen@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* In addition, as a special exception, compiling, linking, and/or
* using OpenSSL with this program is allowed.
*/
#include "bookentry.hh"
#include "wulformanager.hh"
using namespace std;
GSList* BookEntry::group = NULL;
BookEntry::BookEntry(const EntryType type, const string &text, const string &glade, const string &id):
Entry(type, glade, id),
bold(FALSE),
urgent(FALSE)
{
labelBox = gtk_hbox_new(FALSE, 5);
eventBox = gtk_event_box_new();
gtk_event_box_set_above_child(GTK_EVENT_BOX(eventBox), TRUE);
gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventBox), FALSE);
// Make the eventbox fill to all left-over space.
gtk_box_pack_start(GTK_BOX(labelBox), GTK_WIDGET(eventBox), TRUE, TRUE, 0);
label = GTK_LABEL(gtk_label_new(text.c_str()));
gtk_container_add(GTK_CONTAINER(eventBox), GTK_WIDGET(label));
// Align text to the left (x = 0) and in the vertical center (0.5)
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
closeButton = gtk_button_new();
gtk_button_set_relief(GTK_BUTTON(closeButton), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click(GTK_BUTTON(closeButton), FALSE);
// Shrink the padding around the close button
GtkRcStyle *rcstyle = gtk_rc_style_new();
rcstyle->xthickness = rcstyle->ythickness = 0;
gtk_widget_modify_style(closeButton, rcstyle);
gtk_rc_style_unref(rcstyle);
// Add the stock icon to the close button
GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
gtk_container_add(GTK_CONTAINER(closeButton), image);
gtk_box_pack_start(GTK_BOX(labelBox), closeButton, FALSE, FALSE, 0);
tips = gtk_tooltips_new();
gtk_tooltips_enable(tips);
gtk_tooltips_set_tip(tips, closeButton, _("Close tab"), NULL);
gtk_widget_show_all(labelBox);
tabMenuItem = gtk_radio_menu_item_new_with_label(group, text.c_str());
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(tabMenuItem));
setLabel_gui(text);
// Associates entry to the widget for later retrieval in MainWindow::switchPage_gui()
g_object_set_data(G_OBJECT(getContainer()), "entry", (gpointer)this);
}
GtkWidget* BookEntry::getContainer()
{
return getWidget("mainBox");
}
void BookEntry::setLabel_gui(string text)
{
// Update the tab menu item label
GtkWidget *child = gtk_bin_get_child(GTK_BIN(tabMenuItem));
if (child && GTK_IS_LABEL(child))
gtk_label_set_text(GTK_LABEL(child), text.c_str());
// Update the notebook tab label
gtk_tooltips_set_tip(tips, eventBox, text.c_str(), text.c_str());
glong len = g_utf8_strlen(text.c_str(), -1);
// Truncate the label text
if (len > labelSize)
{
gchar truncatedText[text.size()];
const string clipText = _("...");
len = labelSize - g_utf8_strlen(clipText.c_str(), -1);
g_utf8_strncpy(truncatedText, text.c_str(), len);
truncatedLabelText = truncatedText + clipText;
}
else
{
truncatedLabelText = text;
}
labelText = text;
updateLabel_gui();
// Update the main window title if the current tab is selected.
if (isActive_gui())
WulforManager::get()->getMainWindow()->setTitle(getLabelText());
}
void BookEntry::setBold_gui()
{
if (!bold && !isActive_gui())
{
bold = TRUE;
updateLabel_gui();
}
}
void BookEntry::setUrgent_gui()
{
if (!isActive_gui())
{
MainWindow *mw = WulforManager::get()->getMainWindow();
if (!urgent)
{
bold = TRUE;
urgent = TRUE;
updateLabel_gui();
}
if (!mw->isActive_gui())
mw->setUrgent_gui();
}
}
void BookEntry::setActive_gui()
{
if (bold || urgent)
{
bold = FALSE;
urgent = FALSE;
updateLabel_gui();
}
}
bool BookEntry::isActive_gui()
{
MainWindow *mw = WulforManager::get()->getMainWindow();
return mw->isActive_gui() && mw->currentPage_gui() == getContainer();
}
void BookEntry::updateLabel_gui()
{
const char *format = "%s";
if (urgent)
format = "<i><b>%s</b></i>";
else if (bold)
format = "<b>%s</b>";
char *markup = g_markup_printf_escaped(format, truncatedLabelText.c_str());
gtk_label_set_markup(label, markup);
g_free(markup);
}
const string& BookEntry::getLabelText()
{
return labelText;
}
|