aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorsimonb <simonb>2006-05-20 15:08:14 (GMT)
committersimonb <simonb>2006-05-20 15:08:14 (GMT)
commit0861f3a9073ccd016302af26ff992fa19331a02d (patch)
treef1a2276449a5fc9b27f2d1afa5ffff4410141345 /src/FbTk
parent5ddabb0f390f69db793b5a6e40be9f94b8f83136 (diff)
downloadfluxbox_paul-0861f3a9073ccd016302af26ff992fa19331a02d.zip
fluxbox_paul-0861f3a9073ccd016302af26ff992fa19331a02d.tar.bz2
improve native language handling, move messages and menu labels to
FbTk::FbString
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/I18n.cc17
-rw-r--r--src/FbTk/I18n.hh4
-rw-r--r--src/FbTk/Menu.cc23
-rw-r--r--src/FbTk/Menu.hh9
-rw-r--r--src/FbTk/MenuIcon.cc4
-rw-r--r--src/FbTk/MenuIcon.hh2
-rw-r--r--src/FbTk/MenuItem.cc2
-rw-r--r--src/FbTk/MenuItem.hh21
-rw-r--r--src/FbTk/MultiButtonMenuItem.cc4
-rw-r--r--src/FbTk/MultiButtonMenuItem.hh4
-rw-r--r--src/FbTk/Transparent.cc4
11 files changed, 51 insertions, 43 deletions
diff --git a/src/FbTk/I18n.cc b/src/FbTk/I18n.cc
index c41f98c..62fda06 100644
--- a/src/FbTk/I18n.cc
+++ b/src/FbTk/I18n.cc
@@ -75,7 +75,7 @@ I18n::I18n():m_multibyte(false), m_catalog_fd((nl_catd)(-1)) {
75#ifdef HAVE_SETLOCALE 75#ifdef HAVE_SETLOCALE
76 //make sure we don't get 0 to m_locale string 76 //make sure we don't get 0 to m_locale string
77 char *temp = setlocale(LC_MESSAGES, ""); 77 char *temp = setlocale(LC_MESSAGES, "");
78 m_locale = ( temp ? temp : ""); 78 m_locale = ( temp ? temp : "");
79 if (m_locale.empty()) { 79 if (m_locale.empty()) {
80 cerr<<"Warning: Failed to set locale, reverting to \"C\""<<endl; 80 cerr<<"Warning: Failed to set locale, reverting to \"C\""<<endl;
81#endif // HAVE_SETLOCALE 81#endif // HAVE_SETLOCALE
@@ -90,9 +90,9 @@ I18n::I18n():m_multibyte(false), m_catalog_fd((nl_catd)(-1)) {
90 // MB_CUR_MAX returns the size of a char in the current locale 90 // MB_CUR_MAX returns the size of a char in the current locale
91 if (MB_CUR_MAX > 1) 91 if (MB_CUR_MAX > 1)
92 m_multibyte = true; 92 m_multibyte = true;
93 93
94 // truncate any encoding off the end of the locale 94 // truncate any encoding off the end of the locale
95 95
96 // remove everything after @ 96 // remove everything after @
97 string::size_type index = m_locale.find('@'); 97 string::size_type index = m_locale.find('@');
98 if (index != string::npos) 98 if (index != string::npos)
@@ -150,12 +150,17 @@ void I18n::openCatalog(const char *catalog) {
150} 150}
151 151
152 152
153const char *I18n::getMessage(int set_number, int message_number, 153FbString I18n::getMessage(int set_number, int message_number,
154 const char *default_message) const { 154 const char *default_message) const {
155 155
156#if defined(NLS) && defined(HAVE_CATGETS) 156#if defined(NLS) && defined(HAVE_CATGETS)
157 if (m_catalog_fd != (nl_catd)-1) 157 if (m_catalog_fd != (nl_catd)-1) {
158 return (const char *) catgets(m_catalog_fd, set_number, message_number, default_message); 158 const char *ret = catgets(m_catalog_fd, set_number, message_number, default_message);
159 if (ret == default_message || ret == NULL)
160 return default_message; // don't recode the default
161
162 return FbStringUtil::LocaleStrToFb(ret);
163 }
159 else 164 else
160#endif // NLS && HAVE_CATGETS 165#endif // NLS && HAVE_CATGETS
161 return default_message; 166 return default_message;
diff --git a/src/FbTk/I18n.hh b/src/FbTk/I18n.hh
index 7891961..b8fef0f 100644
--- a/src/FbTk/I18n.hh
+++ b/src/FbTk/I18n.hh
@@ -30,6 +30,8 @@
30// TODO: FIXME 30// TODO: FIXME
31#include "../../nls/fluxbox-nls.hh" 31#include "../../nls/fluxbox-nls.hh"
32 32
33#include "FbString.hh"
34
33#ifdef HAVE_CONFIG_H 35#ifdef HAVE_CONFIG_H
34#include "config.h" 36#include "config.h"
35#endif // HAVE_CONFIG_H 37#endif // HAVE_CONFIG_H
@@ -93,7 +95,7 @@ public:
93 inline bool multibyte() const { return m_multibyte; } 95 inline bool multibyte() const { return m_multibyte; }
94 inline const nl_catd &getCatalogFd() const { return m_catalog_fd; } 96 inline const nl_catd &getCatalogFd() const { return m_catalog_fd; }
95 97
96 const char *getMessage(int set_number, int message_number, 98 FbString getMessage(int set_number, int message_number,
97 const char *default_messsage = 0) const; 99 const char *default_messsage = 0) const;
98 void openCatalog(const char *catalog); 100 void openCatalog(const char *catalog);
99private: 101private:
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc
index d99c9ba..63f3958 100644
--- a/src/FbTk/Menu.cc
+++ b/src/FbTk/Menu.cc
@@ -193,15 +193,15 @@ Menu::~Menu() {
193 s_focused = 0; 193 s_focused = 0;
194} 194}
195 195
196int Menu::insert(const char *label, RefCount<Command> &cmd, int pos) { 196int Menu::insert(const FbString &label, RefCount<Command> &cmd, int pos) {
197 return insert(new MenuItem(label, cmd), pos); 197 return insert(new MenuItem(label, cmd), pos);
198} 198}
199 199
200int Menu::insert(const char *label, int pos) { 200int Menu::insert(const FbString &label, int pos) {
201 return insert(new MenuItem(label), pos); 201 return insert(new MenuItem(label), pos);
202} 202}
203 203
204int Menu::insert(const char *label, Menu *submenu, int pos) { 204int Menu::insert(const FbString &label, Menu *submenu, int pos) {
205 submenu->m_parent = this; 205 submenu->m_parent = this;
206 return insert(new MenuItem(label, submenu), pos); 206 return insert(new MenuItem(label, submenu), pos);
207} 207}
@@ -392,7 +392,7 @@ void Menu::enableTitle() {
392 392
393void Menu::updateMenu(int active_index) { 393void Menu::updateMenu(int active_index) {
394 if (m_title_vis) { 394 if (m_title_vis) {
395 menu.item_w = theme().titleFont().textWidth(menu.label.c_str(), 395 menu.item_w = theme().titleFont().textWidth(menu.label,
396 menu.label.size()); 396 menu.label.size());
397 menu.item_w += (theme().bevelWidth() * 2); 397 menu.item_w += (theme().bevelWidth() * 2);
398 } else 398 } else
@@ -427,14 +427,14 @@ void Menu::updateMenu(int active_index) {
427 int itmp = (theme().itemHeight() * menu.persub); 427 int itmp = (theme().itemHeight() * menu.persub);
428 menu.frame_h = itmp < 1 ? 1 : itmp; 428 menu.frame_h = itmp < 1 ? 1 : itmp;
429 429
430 int new_width = (menu.sublevels * menu.item_w); 430 unsigned int new_width = (menu.sublevels * menu.item_w);
431 int new_height = menu.frame_h; 431 unsigned int new_height = menu.frame_h;
432 432
433 if (m_title_vis) 433 if (m_title_vis)
434 new_height += theme().titleHeight() + ((menu.frame_h > 0)?menu.title.borderWidth():0); 434 new_height += theme().titleHeight() + ((menu.frame_h > 0)?menu.title.borderWidth():0);
435 435
436 436
437 if (new_width < 1) { 437 if (new_width == 0) {
438 if (menu.item_w > 0) 438 if (menu.item_w > 0)
439 new_width = menu.item_w; 439 new_width = menu.item_w;
440 else 440 else
@@ -638,12 +638,11 @@ void Menu::move(int x, int y) {
638 638
639 639
640void Menu::redrawTitle(FbDrawable &drawable) { 640void Menu::redrawTitle(FbDrawable &drawable) {
641 const char *text = menu.label.c_str();
642 641
643 const FbTk::Font &font = theme().titleFont(); 642 const FbTk::Font &font = theme().titleFont();
644 int dx = theme().bevelWidth(); 643 int dx = theme().bevelWidth();
645 size_t len = menu.label.size(); 644 size_t len = menu.label.size();
646 unsigned int l = font.textWidth(text, len) + theme().bevelWidth()*2; 645 unsigned int l = font.textWidth(menu.label, len) + theme().bevelWidth()*2;
647 646
648 switch (theme().titleFontJustify()) { 647 switch (theme().titleFontJustify()) {
649 case FbTk::RIGHT: 648 case FbTk::RIGHT:
@@ -662,7 +661,7 @@ void Menu::redrawTitle(FbDrawable &drawable) {
662 font.drawText(drawable, // drawable 661 font.drawText(drawable, // drawable
663 screenNumber(), 662 screenNumber(),
664 theme().titleTextGC().gc(), // graphic context 663 theme().titleTextGC().gc(), // graphic context
665 text, len, // text string with length 664 menu.label, len, // text string with length
666 dx, font.ascent() + theme().bevelWidth() + height_offset/2); // position 665 dx, font.ascent() + theme().bevelWidth() + height_offset/2); // position
667} 666}
668 667
@@ -784,9 +783,9 @@ int Menu::drawItem(FbDrawable &drawable, unsigned int index,
784 return item_y; 783 return item_y;
785} 784}
786 785
787void Menu::setLabel(const char *labelstr) { 786void Menu::setLabel(const FbString &labelstr) {
788 //make sure we don't send 0 to std::string 787 //make sure we don't send 0 to std::string
789 menu.label = (labelstr ? labelstr : ""); 788 menu.label = labelstr;
790 reconfigure(); 789 reconfigure();
791} 790}
792 791
diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh
index 2f098d7..26262f2 100644
--- a/src/FbTk/Menu.hh
+++ b/src/FbTk/Menu.hh
@@ -40,6 +40,7 @@
40#include "FbPixmap.hh" 40#include "FbPixmap.hh"
41#include "MenuTheme.hh" 41#include "MenuTheme.hh"
42#include "Timer.hh" 42#include "Timer.hh"
43#include "FbString.hh"
43 44
44namespace FbTk { 45namespace FbTk {
45 46
@@ -65,11 +66,11 @@ public:
65 */ 66 */
66 //@{ 67 //@{
67 /// add a menu item with a label and a command 68 /// add a menu item with a label and a command
68 int insert(const char *label, RefCount<Command> &cmd, int pos=-1); 69 int insert(const FbString &label, RefCount<Command> &cmd, int pos=-1);
69 /// add empty menu item 70 /// add empty menu item
70 int insert(const char *label, int pos=-1); 71 int insert(const FbString &label, int pos=-1);
71 /// add submenu 72 /// add submenu
72 int insert(const char *label, Menu *submenu, int pos= -1); 73 int insert(const FbString &label, Menu *submenu, int pos= -1);
73 /// add menu item 74 /// add menu item
74 int insert(MenuItem *item, int pos=-1); 75 int insert(MenuItem *item, int pos=-1);
75 /// remove an item 76 /// remove an item
@@ -113,7 +114,7 @@ public:
113 void grabInputFocus(); 114 void grabInputFocus();
114 virtual void reconfigure(); 115 virtual void reconfigure();
115 /// set label string 116 /// set label string
116 void setLabel(const char *labelstr); 117 void setLabel(const FbString &labelstr);
117 /// move menu to x,y 118 /// move menu to x,y
118 void move(int x, int y); 119 void move(int x, int y);
119 virtual void updateMenu(int active_index = -1); 120 virtual void updateMenu(int active_index = -1);
diff --git a/src/FbTk/MenuIcon.cc b/src/FbTk/MenuIcon.cc
index aa71b5d..d64d876 100644
--- a/src/FbTk/MenuIcon.cc
+++ b/src/FbTk/MenuIcon.cc
@@ -30,8 +30,8 @@
30 30
31namespace FbTk { 31namespace FbTk {
32 32
33MenuIcon::MenuIcon(const std::string &filename, const std::string &label, int screen_num): 33MenuIcon::MenuIcon(const std::string &filename, FbString &label, int screen_num):
34 MenuItem(label.c_str()), 34 MenuItem(label),
35 m_filename(filename) { 35 m_filename(filename) {
36 FbTk::PixmapWithMask *pm = Image::load(filename.c_str(), screen_num); 36 FbTk::PixmapWithMask *pm = Image::load(filename.c_str(), screen_num);
37 if (pm != 0) { 37 if (pm != 0) {
diff --git a/src/FbTk/MenuIcon.hh b/src/FbTk/MenuIcon.hh
index 7fbd12a..90cf320 100644
--- a/src/FbTk/MenuIcon.hh
+++ b/src/FbTk/MenuIcon.hh
@@ -34,7 +34,7 @@ namespace FbTk {
34 34
35class MenuIcon: public MenuItem { 35class MenuIcon: public MenuItem {
36public: 36public:
37 MenuIcon(const std::string &filename, const std::string &label, int screen_num); 37 MenuIcon(const std::string &filename, FbString &label, int screen_num);
38 void draw(FbDrawable &drawable, 38 void draw(FbDrawable &drawable,
39 const MenuTheme &theme, 39 const MenuTheme &theme,
40 bool highlight, 40 bool highlight,
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc
index f8ec4e9..fafedc0 100644
--- a/src/FbTk/MenuItem.cc
+++ b/src/FbTk/MenuItem.cc
@@ -284,7 +284,7 @@ unsigned int MenuItem::height(const MenuTheme &theme) const {
284unsigned int MenuItem::width(const MenuTheme &theme) const { 284unsigned int MenuItem::width(const MenuTheme &theme) const {
285 // textwidth + bevel width on each side of the text 285 // textwidth + bevel width on each side of the text
286 const unsigned int icon_width = height(theme); 286 const unsigned int icon_width = height(theme);
287 const unsigned int normal = theme.frameFont().textWidth(label().c_str(), label().size()) + 287 const unsigned int normal = theme.frameFont().textWidth(label(), label().size()) +
288 2 * (theme.bevelWidth() + icon_width); 288 2 * (theme.bevelWidth() + icon_width);
289 return m_icon.get() == 0 ? normal : normal + icon_width; 289 return m_icon.get() == 0 ? normal : normal + icon_width;
290} 290}
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh
index 0bf66be..94f0775 100644
--- a/src/FbTk/MenuItem.hh
+++ b/src/FbTk/MenuItem.hh
@@ -27,6 +27,7 @@
27#include "RefCount.hh" 27#include "RefCount.hh"
28#include "Command.hh" 28#include "Command.hh"
29#include "PixmapWithMask.hh" 29#include "PixmapWithMask.hh"
30#include "FbString.hh"
30 31
31#include <string> 32#include <string>
32#include <memory> 33#include <memory>
@@ -49,8 +50,8 @@ public:
49 m_toggle_item(false) 50 m_toggle_item(false)
50 { } 51 { }
51 explicit MenuItem( 52 explicit MenuItem(
52 const char *label) 53 const FbString &label)
53 : m_label(label ? label : ""), 54 : m_label(label),
54 m_menu(0), 55 m_menu(0),
55 m_submenu(0), 56 m_submenu(0),
56 m_enabled(true), 57 m_enabled(true),
@@ -58,8 +59,8 @@ public:
58 m_toggle_item(false) 59 m_toggle_item(false)
59 { } 60 { }
60 61
61 MenuItem(const char *label, Menu &host_menu) 62 MenuItem(const FbString &label, Menu &host_menu)
62 : m_label(label ? label : ""), 63 : m_label(label),
63 m_menu(&host_menu), 64 m_menu(&host_menu),
64 m_submenu(0), 65 m_submenu(0),
65 m_enabled(true), 66 m_enabled(true),
@@ -67,8 +68,8 @@ public:
67 m_toggle_item(false) 68 m_toggle_item(false)
68 { } 69 { }
69 /// create a menu item with a specific command to be executed on click 70 /// create a menu item with a specific command to be executed on click
70 MenuItem(const char *label, RefCount<Command> &cmd, Menu *menu = 0): 71 MenuItem(const FbString &label, RefCount<Command> &cmd, Menu *menu = 0):
71 m_label(label ? label : ""), 72 m_label(label),
72 m_menu(menu), 73 m_menu(menu),
73 m_submenu(0), 74 m_submenu(0),
74 m_command(cmd), 75 m_command(cmd),
@@ -78,8 +79,8 @@ public:
78 79
79 } 80 }
80 81
81 MenuItem(const char *label, Menu *submenu, Menu *host_menu = 0) 82 MenuItem(const FbString &label, Menu *submenu, Menu *host_menu = 0)
82 : m_label(label ? label : "") 83 : m_label(label)
83 , m_menu(host_menu) 84 , m_menu(host_menu)
84 , m_submenu(submenu) 85 , m_submenu(submenu)
85 , m_enabled(true) 86 , m_enabled(true)
@@ -91,7 +92,7 @@ public:
91 inline void setCommand(RefCount<Command> &cmd) { m_command = cmd; } 92 inline void setCommand(RefCount<Command> &cmd) { m_command = cmd; }
92 virtual inline void setSelected(bool selected) { m_selected = selected; } 93 virtual inline void setSelected(bool selected) { m_selected = selected; }
93 virtual inline void setEnabled(bool enabled) { m_enabled = enabled; } 94 virtual inline void setEnabled(bool enabled) { m_enabled = enabled; }
94 virtual inline void setLabel(const char *label) { m_label = (label ? label : ""); } 95 virtual inline void setLabel(const FbString &label) { m_label = label; }
95 virtual inline void setToggleItem(bool val) { m_toggle_item = val; } 96 virtual inline void setToggleItem(bool val) { m_toggle_item = val; }
96 void setIcon(const std::string &filename, int screen_num); 97 void setIcon(const std::string &filename, int screen_num);
97 virtual Menu *submenu() { return m_submenu; } 98 virtual Menu *submenu() { return m_submenu; }
@@ -130,7 +131,7 @@ public:
130 Menu *menu() { return m_menu; } 131 Menu *menu() { return m_menu; }
131 132
132private: 133private:
133 std::string m_label; ///< label of this item 134 FbString m_label; ///< label of this item
134 Menu *m_menu; ///< the menu we live in 135 Menu *m_menu; ///< the menu we live in
135 Menu *m_submenu; ///< a submenu, 0 if we don't have one 136 Menu *m_submenu; ///< a submenu, 0 if we don't have one
136 RefCount<Command> m_command; ///< command to be executed 137 RefCount<Command> m_command; ///< command to be executed
diff --git a/src/FbTk/MultiButtonMenuItem.cc b/src/FbTk/MultiButtonMenuItem.cc
index 964668f..b3fa1aa 100644
--- a/src/FbTk/MultiButtonMenuItem.cc
+++ b/src/FbTk/MultiButtonMenuItem.cc
@@ -27,14 +27,14 @@
27 27
28namespace FbTk { 28namespace FbTk {
29 29
30MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const char *label): 30MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbString &label):
31 MenuItem(label), 31 MenuItem(label),
32 m_button_exe(0), 32 m_button_exe(0),
33 m_buttons(buttons) { 33 m_buttons(buttons) {
34 init(buttons); 34 init(buttons);
35} 35}
36 36
37MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const char *label, Menu *submenu): 37MultiButtonMenuItem::MultiButtonMenuItem(int buttons, const FbString &label, Menu *submenu):
38 MenuItem(label, submenu), 38 MenuItem(label, submenu),
39 m_button_exe(0), 39 m_button_exe(0),
40 m_buttons(buttons) { 40 m_buttons(buttons) {
diff --git a/src/FbTk/MultiButtonMenuItem.hh b/src/FbTk/MultiButtonMenuItem.hh
index ccefff9..3e82d67 100644
--- a/src/FbTk/MultiButtonMenuItem.hh
+++ b/src/FbTk/MultiButtonMenuItem.hh
@@ -32,8 +32,8 @@ namespace FbTk {
32/// Handles commands for the specified numbers of buttons 32/// Handles commands for the specified numbers of buttons
33class MultiButtonMenuItem: public FbTk::MenuItem { 33class MultiButtonMenuItem: public FbTk::MenuItem {
34public: 34public:
35 MultiButtonMenuItem(int buttons, const char *label); 35 MultiButtonMenuItem(int buttons, const FbString &label);
36 MultiButtonMenuItem(int buttons, const char *label, Menu *submenu); 36 MultiButtonMenuItem(int buttons, const FbString &label, Menu *submenu);
37 virtual ~MultiButtonMenuItem(); 37 virtual ~MultiButtonMenuItem();
38 /// sets command to specified button 38 /// sets command to specified button
39 void setCommand(int button, FbTk::RefCount<FbTk::Command> &cmd); 39 void setCommand(int button, FbTk::RefCount<FbTk::Command> &cmd);
diff --git a/src/FbTk/Transparent.cc b/src/FbTk/Transparent.cc
index 8b248b8..edbab62 100644
--- a/src/FbTk/Transparent.cc
+++ b/src/FbTk/Transparent.cc
@@ -234,7 +234,7 @@ void Transparent::setDest(Drawable dest, int screen_num) {
234 if (format == 0) { 234 if (format == 0) {
235 _FB_USES_NLS; 235 _FB_USES_NLS;
236 cerr<<"FbTk::Transparent: "; 236 cerr<<"FbTk::Transparent: ";
237 fprintf(stderr, _FBTKTEXT(Error, NoRenderVisualFormat, "Failed to find format for screen(%d)", "XRenderFindVisualFormat failed... include %d for screen number"), screen_num); 237 fprintf(stderr, _FBTKTEXT(Error, NoRenderVisualFormat, "Failed to find format for screen(%d)", "XRenderFindVisualFormat failed... include %d for screen number").c_str(), screen_num);
238 cerr<<endl; 238 cerr<<endl;
239 } 239 }
240 m_dest_pic = XRenderCreatePicture(disp, dest, format, 0, 0); 240 m_dest_pic = XRenderCreatePicture(disp, dest, format, 0, 0);
@@ -273,7 +273,7 @@ void Transparent::setSource(Drawable source, int screen_num) {
273 if (format == 0) { 273 if (format == 0) {
274 _FB_USES_NLS; 274 _FB_USES_NLS;
275 cerr<<"FbTk::Transparent: "; 275 cerr<<"FbTk::Transparent: ";
276 fprintf(stderr, _FBTKTEXT(Error, NoRenderVisualFormat, "Failed to find format for screen(%d)", "XRenderFindVisualFormat failed... include %d for screen number"), screen_num); 276 fprintf(stderr, _FBTKTEXT(Error, NoRenderVisualFormat, "Failed to find format for screen(%d)", "XRenderFindVisualFormat failed... include %d for screen number").c_str(), screen_num);
277 cerr<<endl; 277 cerr<<endl;
278 } 278 }
279 m_src_pic = XRenderCreatePicture(disp, m_source, format, 279 m_src_pic = XRenderCreatePicture(disp, m_source, format,