Commit 71758aa9 authored by Davis King's avatar Davis King
Browse files

Merging in the unicode branch. The change log for that branch is as follows:

	------------------------------------------------------------------------
	r2331 | davisking | 2008-06-15 15:03:05 -0400 (Sun, 15 Jun 2008) | 1 line
	Changed paths:
	   M /branches/unicode/dlib/CMakeLists.txt

	Added another link library to the windows part of the cmake file
	------------------------------------------------------------------------
	r2330 | davisking | 2008-06-15 14:11:47 -0400 (Sun, 15 Jun 2008) | 3 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.h
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.h
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_abstract.h
	   M /branches/unicode/dlib/gui_widgets/base_widgets.cpp
	   M /branches/unicode/dlib/gui_widgets/base_widgets.h
	   M /branches/unicode/dlib/gui_widgets/base_widgets_abstract.h
	   M /branches/unicode/dlib/gui_widgets/drawable.cpp
	   M /branches/unicode/dlib/gui_widgets/drawable.h
	   M /branches/unicode/dlib/gui_widgets/fonts.cpp
	   M /branches/unicode/dlib/gui_widgets/fonts.h
	   M /branches/unicode/dlib/gui_widgets/widgets.cpp
	   M /branches/unicode/dlib/gui_widgets/widgets.h
	   M /branches/unicode/dlib/gui_widgets/widgets_abstract.h

	Added Keita Mochizuki's name to a bunch of files.  Also added a missing
	prototype for the get_native_font() function in fonts.h

	------------------------------------------------------------------------
	r2329 | davisking | 2008-06-15 14:05:17 -0400 (Sun, 15 Jun 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_widgets/fonts.cpp
	   M /branches/unicode/dlib/gui_widgets/fonts_abstract.h
	   A /branches/unicode/dlib/gui_widgets/nativefont.h

	Added the nativefont object from Keita Mochizuki

	------------------------------------------------------------------------
	r2328 | davisking | 2008-06-15 14:04:44 -0400 (Sun, 15 Jun 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp

	Removed an unused variable

	------------------------------------------------------------------------
	r2327 | davisking | 2008-06-15 13:33:31 -0400 (Sun, 15 Jun 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.h
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.h
	   M /branches/unicode/dlib/gui_widgets/base_widgets.h
	   M /branches/unicode/dlib/gui_widgets/base_widgets_abstract.h
	   M /branches/unicode/dlib/gui_widgets/drawable.cpp
	   M /branches/unicode/dlib/gui_widgets/drawable.h
	   M /branches/unicode/dlib/gui_widgets/drawable_abstract.h
	   M /branches/unicode/dlib/gui_widgets/widgets.cpp
	   M /branches/unicode/dlib/gui_widgets/widgets.h

	Converted tabs to spaces

	------------------------------------------------------------------------
	r2326 | davisking | 2008-06-15 13:31:32 -0400 (Sun, 15 Jun 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.h
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.h
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_abstract.h
	   M /branches/unicode/dlib/gui_widgets/drawable.cpp
	   M /branches/unicode/dlib/gui_widgets/drawable.h
	   M /branches/unicode/dlib/gui_widgets/drawable_abstract.h
	   M /branches/unicode/dlib/gui_widgets/widgets.cpp
	   M /branches/unicode/dlib/gui_widgets/widgets.h

	Checking in the on_string_put() event patch from Keita Mochizuki.

	------------------------------------------------------------------------
	r2325 | davisking | 2008-06-15 13:13:49 -0400 (Sun, 15 Jun 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_widgets/base_widgets.h
	   M /branches/unicode/dlib/gui_widgets/base_widgets_abstract.h
	   M /branches/unicode/dlib/gui_widgets/style.cpp
	   M /branches/unicode/dlib/gui_widgets/style.h
	   M /branches/unicode/dlib/gui_widgets/style_abstract.h
	   M /branches/unicode/dlib/gui_widgets/widgets.cpp
	   M /branches/unicode/dlib/gui_widgets/widgets.h
	   M /branches/unicode/dlib/gui_widgets/widgets_abstract.h
	   M /branches/unicode/dlib/serialize.h

	Added the first part of the UNICODE patch from Keita Mochizuki

	------------------------------------------------------------------------
	r2324 | davisking | 2008-06-15 13:05:17 -0400 (Sun, 15 Jun 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_widgets/fonts_abstract.h

	Fixed a typo in a comment

	------------------------------------------------------------------------
	r2244 | davisking | 2008-05-15 17:40:47 -0400 (Thu, 15 May 2008) | 3 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp
	   M /branches/unicode/dlib/unicode/unicode.cpp
	   M /branches/unicode/dlib/unicode/unicode.h
	   M /branches/unicode/dlib/unicode/unicode_abstract.h

	Put the convert_wstring_to_mbstring() function back in but in a way that
	works with mingw.

	------------------------------------------------------------------------
	r2219 | davisking | 2008-05-04 11:13:23 -0400 (Sun, 04 May 2008) | 1 line
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp

	changed to be the same as the windows version
	------------------------------------------------------------------------
	r2218 | davisking | 2008-05-04 10:42:28 -0400 (Sun, 04 May 2008) | 4 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp
	   M /branches/unicode/dlib/unicode/unicode.cpp
	   M /branches/unicode/dlib/unicode/unicode.h
	   M /branches/unicode/dlib/unicode/unicode_abstract.h

	Moved some more stuff around and cleaned up the code.  The wcstombs got
	moved into the gui_core_kernel_2.cpp file since I removed it from the
	unicode.cpp file.  This was because mingw doesn't seem to support it.

	------------------------------------------------------------------------
	r2216 | davisking | 2008-05-03 16:03:40 -0400 (Sat, 03 May 2008) | 1 line
	Changed paths:
	   M /branches/unicode/dlib/algs.h
	   M /branches/unicode/dlib/string/string.h
	   M /branches/unicode/dlib/unicode/unicode.h

	Changed code to avoid compiler trouble in mingw and inane warnings in
	visual studio.
	------------------------------------------------------------------------
	r2215 | davisking | 2008-05-03 10:22:35 -0400 (Sat, 03 May 2008) | 3 lines
	Changed paths:
	   M /branches/unicode/dlib/unicode/unicode.h

	Added a char_traits for dlib::unichar since gcc 3.3 (and probably others)
	won't compile without it.

	------------------------------------------------------------------------
	r2214 | davisking | 2008-05-03 10:21:32 -0400 (Sat, 03 May 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_widgets/style.h

	Added a missing #include

	------------------------------------------------------------------------
	r2213 | davisking | 2008-05-02 15:11:23 -0400 (Fri, 02 May 2008) | 3 lines
	Changed paths:
	   M /branches/unicode/dlib/string/string.h
	   M /branches/unicode/dlib/unicode/unicode.cpp

	mingw doesn't have a std::wcstombs so I replaced calls to it with calls to
	dlib::narrow.  Also changed dlib::narrow so it works in mingw as well since
	the previous version ended up calling something that mingw doesn't have as
	well.
	------------------------------------------------------------------------
	r2212 | davisking | 2008-05-02 11:23:41 -0400 (Fri, 02 May 2008) | 3 lines
	Changed paths:
	   M /branches/unicode/dlib/all/source.cpp

	Applying more of Keita Mochizuki's unicode patch.


	------------------------------------------------------------------------
	r2211 | davisking | 2008-05-02 11:22:58 -0400 (Fri, 02 May 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/unicode/unicode.h
	   M /branches/unicode/dlib/unicode/unicode_abstract.h

	updated specs a little

	------------------------------------------------------------------------
	r2210 | davisking | 2008-05-02 11:16:33 -0400 (Fri, 02 May 2008) | 2 lines
	Changed paths:
	   A /branches/unicode/dlib/unicode/unicode.cpp
	   M /branches/unicode/dlib/unicode/unicode.h

	Applying more of the unicode patch from Keita Mochizuki

	------------------------------------------------------------------------
	r2209 | davisking | 2008-05-02 11:10:19 -0400 (Fri, 02 May 2008) | 2 lines
	Changed paths:
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_1.h
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.cpp
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_2.h
	   M /branches/unicode/dlib/gui_core/gui_core_kernel_abstract.h

	Applying the first part of the unicode patch from Keita Mochizuki

	------------------------------------------------------------------------
	r2208 | davisking | 2008-05-02 10:49:15 -0400 (Fri, 02 May 2008) | 3 lines
	Changed paths:
	   A /branches/unicode (from /trunk:2207)

	Adding a branch to deal with the unicode patch from Keita Mochizuki.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402333
parent 8dda77b5
......@@ -6,6 +6,7 @@
#include "../algs.h"
#include "../gui_core.h"
#include "widgets_abstract.h"
#include "../unicode/unicode_abstract.h"
namespace dlib
{
......@@ -42,7 +43,7 @@ namespace dlib
!*/
virtual rectangle get_min_size (
const std::string& name,
const ustring& name,
const font& mfont
) const = 0;
/*!
......@@ -61,7 +62,7 @@ namespace dlib
const font& mfont,
const long lastx,
const long lasty,
const std::string& name,
const ustring& name,
const bool is_depressed
) const = 0;
/*!
......@@ -153,7 +154,7 @@ namespace dlib
!*/
virtual rectangle get_min_size (
const std::string& name,
const ustring& name,
const font& mfont
) const = 0;
/*!
......@@ -172,7 +173,7 @@ namespace dlib
const font& mfont,
const long lastx,
const long lasty,
const std::string& name,
const ustring& name,
const bool is_depressed,
const bool is_checked
) const = 0;
......
This diff is collapsed.
// Copyright (C) 2005 Davis E. King (davisking@users.sourceforge.net)
// Copyright (C) 2005 Davis E. King (davisking@users.sourceforge.net), Keita Mochizuki
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_WIDGETs_
......@@ -63,9 +63,23 @@ namespace dlib
const std::string& text
);
void set_text (
const std::wstring& text
);
void set_text (
const dlib::ustring& text
);
const std::string text (
) const;
const std::wstring wtext (
) const;
const dlib::ustring utext (
) const;
void set_text_color (
const rgb_pixel color
);
......@@ -78,7 +92,7 @@ namespace dlib
);
private:
std::string text_;
dlib::ustring text_;
rgb_pixel text_color_;
......@@ -124,13 +138,35 @@ namespace dlib
const std::string& name_
);
void set_name (
const std::wstring& name_
);
void set_name (
const dlib::ustring& name_
);
const std::string name (
) const;
const std::wstring wname (
) const;
const dlib::ustring uname (
) const;
void set_tooltip_text (
const std::string& text
);
void set_tooltip_text (
const std::wstring& text
);
void set_tooltip_text (
const dlib::ustring& text
);
void set_pos(
long x,
long y
......@@ -139,6 +175,12 @@ namespace dlib
const std::string tooltip_text (
) const;
const std::wstring tooltip_wtext (
) const;
const dlib::ustring tooltip_utext (
) const;
void set_main_font (
const font* f
);
......@@ -200,7 +242,7 @@ namespace dlib
button(button&); // copy constructor
button& operator=(button&); // assignment operator
std::string name_;
dlib::ustring name_;
tooltip btn_tooltip;
member_function_pointer<>::kernel_1a event_handler;
......@@ -260,6 +302,14 @@ namespace dlib
const std::string& name
);
void set_name (
const std::wstring& name
);
void set_name (
const dlib::ustring& name
);
void set_size (
unsigned long width_,
unsigned long height_
......@@ -269,15 +319,35 @@ namespace dlib
const std::string& text
);
void set_tooltip_text (
const std::wstring& text
);
void set_tooltip_text (
const ustring& text
);
const std::string tooltip_text (
) const;
const std::wstring tooltip_wtext (
) const;
const dlib::ustring tooltip_utext (
) const;
bool is_checked (
) const;
const std::string name (
) const;
const std::wstring wname (
) const;
const dlib::ustring uname (
) const;
void set_checked (
);
......@@ -350,7 +420,7 @@ namespace dlib
toggle_button(toggle_button&); // copy constructor
toggle_button& operator=(toggle_button&); // assignment operator
std::string name_;
dlib::ustring name_;
tooltip btn_tooltip;
bool checked;
......@@ -436,7 +506,7 @@ namespace dlib
text_field(
drawable_window& w
) :
drawable(w,MOUSE_CLICK | KEYBOARD_EVENTS | MOUSE_MOVE),
drawable(w,MOUSE_CLICK | KEYBOARD_EVENTS | MOUSE_MOVE | STRING_PUT),
text_color_(0,0,0),
bg_color_(255,255,255),
text_width(0),
......@@ -470,9 +540,23 @@ namespace dlib
const std::string& text_
);
void set_text (
const std::wstring& text_
);
void set_text (
const dlib::ustring& text_
);
const std::string text (
) const;
const std::wstring wtext (
) const;
const dlib::ustring utext (
) const;
void set_text_color (
const rgb_pixel color
);
......@@ -596,7 +680,7 @@ namespace dlib
- returns the rectangle that should contain the text in this widget
!*/
std::string text_;
dlib::ustring text_;
rgb_pixel text_color_;
rgb_pixel bg_color_;
......@@ -659,6 +743,10 @@ namespace dlib
bool is_printable,
unsigned long state
);
void on_string_put (
const std::wstring &str
);
};
// ----------------------------------------------------------------------------------------
......@@ -753,7 +841,15 @@ namespace dlib
unsigned long number_of_tabs (
) const;
const std::string& tab_name (
const std::string tab_name (
unsigned long idx
) const;
const std::wstring tab_wname (
unsigned long idx
) const;
const dlib::ustring& tab_uname (
unsigned long idx
) const;
......@@ -762,6 +858,16 @@ namespace dlib
const std::string& new_name
);
void set_tab_name (
unsigned long idx,
const std::wstring& new_name
);
void set_tab_name (
unsigned long idx,
const dlib::ustring& new_name
);
void set_pos (
long x,
long y
......@@ -838,7 +944,7 @@ namespace dlib
{
tab_data() : width(0), group(0) {}
std::string name;
dlib::ustring name;
unsigned long width;
rectangle rect;
widget_group* group;
......@@ -894,9 +1000,23 @@ namespace dlib
const std::string& name
);
void set_name (
const std::wstring& name
);
void set_name (
const dlib::ustring& name
);
const std::string name (
) const;
const std::wstring wname (
) const;
const dlib::ustring uname (
) const;
void wrap_around (
const rectangle& rect
);
......@@ -916,7 +1036,7 @@ namespace dlib
void make_name_fit_in_rect (
);
std::string name_;
dlib::ustring name_;
unsigned long name_width;
unsigned long name_height;
......@@ -1013,16 +1133,8 @@ namespace dlib
{
class box_win : public drawable_window
{
public:
box_win (
const std::string& title_,
const std::string& message_
) :
drawable_window(false),
title(title_),
message(message_),
msg(*this),
btn_ok(*this)
void initialize (
)
{
msg.set_pos(20,20);
msg.set_text(message);
......@@ -1040,7 +1152,44 @@ namespace dlib
show();
set_title(title_);
set_title(title);
}
public:
box_win (
const std::string& title_,
const std::string& message_
) :
drawable_window(false),
title(convert_mbstring_to_wstring(title_)),
message(convert_mbstring_to_wstring(message_)),
msg(*this),
btn_ok(*this)
{
initialize();
}
box_win (
const std::wstring& title_,
const std::wstring& message_
) :
drawable_window(false),
title(title_),
message(message_),
msg(*this),
btn_ok(*this)
{
initialize();
}
box_win (
const dlib::ustring& title_,
const dlib::ustring& message_
) :
drawable_window(false),
title(convert_utf32_to_wstring(title_)),
message(convert_utf32_to_wstring(message_)),
msg(*this),
btn_ok(*this)
{
initialize();
}
~box_win (
......@@ -1098,8 +1247,8 @@ namespace dlib
return CLOSE_WINDOW;
}
const std::string title;
const std::string message;
const std::wstring title;
const std::wstring message;
label msg;
button btn_ok;
......@@ -1108,16 +1257,8 @@ namespace dlib
class blocking_box_win : public drawable_window
{
public:
blocking_box_win (
const std::string& title_,
const std::string& message_
) :
drawable_window(false),
title(title_),
message(message_),
msg(*this),
btn_ok(*this)
void initialize (
)
{
msg.set_pos(20,20);
msg.set_text(message);
......@@ -1134,9 +1275,48 @@ namespace dlib
set_size(size.right()+20,size.bottom()+20);
set_title(title_);
set_title(title);
show();
}
public:
blocking_box_win (
const std::string& title_,
const std::string& message_
) :
drawable_window(false),
title(convert_mbstring_to_wstring(title_)),
message(convert_mbstring_to_wstring(message_)),
msg(*this),
btn_ok(*this)
{
initialize();
}
blocking_box_win (
const std::wstring& title_,
const std::wstring& message_
) :
drawable_window(false),
title(title_),
message(message_),
msg(*this),
btn_ok(*this)
{
initialize();
}
blocking_box_win (
const dlib::ustring& title_,
const dlib::ustring& message_
) :
drawable_window(false),
title(convert_utf32_to_wstring(title_)),
message(convert_utf32_to_wstring(message_)),
msg(*this),
btn_ok(*this)
{
initialize();
}
~blocking_box_win (
)
......@@ -1152,8 +1332,8 @@ namespace dlib
close_window();
}
const std::string title;
const std::string message;
const std::wstring title;
const std::wstring message;
label msg;
button btn_ok;
};
......@@ -1199,8 +1379,10 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
namespace list_box_helper{
template <typename S = std::string>
class list_box : public drawable,
public enumerable<const std::string>
public enumerable<const S>
{
/*!
INITIAL VALUE
......@@ -1302,7 +1484,7 @@ namespace dlib
last_selected = 0;
}
const std::string& operator[] (
const S& operator[] (
unsigned long index
) const;
......@@ -1340,10 +1522,10 @@ namespace dlib
bool current_element_valid (
) const;
const std::string& element (
const S& element (
) const;
const std::string& element (
const S& element (
);
bool move_next (
......@@ -1410,9 +1592,10 @@ namespace dlib
const canvas& c
) const;
template <typename SS>
struct data
{
std::string name;
SS name;
bool is_selected;
unsigned long width;
unsigned long height;
......@@ -1421,7 +1604,7 @@ namespace dlib
const static long pad = 2;
bool ms_enabled;
array<data>::kernel_2a_c items;
typename array<data<S> >::kernel_2a_c items;
member_function_pointer<unsigned long>::kernel_1a event_handler;
member_function_pointer<unsigned long>::kernel_1a single_click_event_handler;
unsigned long pos;
......@@ -1436,7 +1619,10 @@ namespace dlib
list_box(list_box&); // copy constructor
list_box& operator=(list_box&); // assignment operator
};
}
typedef list_box_helper::list_box<std::string> list_box;
typedef list_box_helper::list_box<std::wstring> wlist_box;
typedef list_box_helper::list_box<dlib::ustring> ulist_box;
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// function open_file_box()
......@@ -1989,6 +2175,24 @@ namespace dlib
const std::string name,
char underline_ch = '\0'
)
{
set_menu_name(idx, convert_mbstring_to_wstring(name), underline_ch);
}
void set_menu_name (
unsigned long idx,
const std::wstring name,
char underline_ch = '\0'
)
{
set_menu_name(idx, convert_wstring_to_utf32(name), underline_ch);
}
void set_menu_name (
unsigned long idx,
const dlib::ustring name,
char underline_ch = '\0'
)
{
DLIB_ASSERT ( idx < number_of_menus() ,
"\tvoid menu_bar::set_menu_name()"
......@@ -2005,6 +2209,20 @@ namespace dlib
const std::string menu_name (
unsigned long idx
) const
{
return convert_wstring_to_mbstring(menu_wname(idx));
}
const std::wstring menu_wname (
unsigned long idx
) const
{
return convert_utf32_to_wstring(menu_uname(idx));
}
const dlib::ustring menu_uname (
unsigned long idx
) const
{
DLIB_ASSERT ( idx < number_of_menus() ,
"\tstd::string menu_bar::menu_name()"
......@@ -2262,8 +2480,8 @@ namespace dlib
struct menu_data
{
std::string name;
std::string::size_type underline_pos;
dlib::ustring name;
dlib::ustring::size_type underline_pos;
popup_menu menu;
rectangle rect;
rectangle bgrect;
......@@ -2498,12 +2716,28 @@ namespace dlib
unsigned long i,
const std::string& label
)
{
set_node_label(i, convert_mbstring_to_wstring(label));
}
void set_node_label (
unsigned long i,
const std::wstring& label
)
{
set_node_label(i, convert_wstring_to_utf32(label));
}
void set_node_label (
unsigned long i,
const dlib::ustring& label
)
{
auto_mutex M(m);
DLIB_ASSERT ( i < number_of_nodes() ,
"\tvoid directed_graph_drawer::set_node_label(i,label)"
<< "\n\ti: " << i
<< "\n\tlabel: " << label
<< "\n\tlabel: " << narrow(label)
<< "\n\tnumber_of_nodes(): " << number_of_nodes()
);
graph_.node(i).data.name = label.c_str();
......@@ -2547,7 +2781,27 @@ namespace dlib
{
auto_mutex M(m);
DLIB_ASSERT ( i < number_of_nodes() ,
"\tconst std::string directed_graph_drawer::node_label(i)"
"\tconst std::ustring directed_graph_drawer::node_label(i)"
<< "\n\ti: " << i
<< "\n\tnumber_of_nodes(): " << number_of_nodes()
);
return narrow(graph_.node(i).data.name);
}
const std::wstring node_wlabel (
unsigned long i
) const
{
return convert_utf32_to_wstring(node_ulabel(i));
}
const dlib::ustring node_ulabel (
unsigned long i
) const
{
auto_mutex M(m);
DLIB_ASSERT ( i < number_of_nodes() ,
"\tconst std::ustring directed_graph_drawer::node_label(i)"
<< "\n\ti: " << i
<< "\n\tnumber_of_nodes(): " << number_of_nodes()
);
......@@ -3005,7 +3259,7 @@ namespace dlib
{
data() : color(0,0,0) {}
vector<double> p;
std::string name;
dlib::ustring name;
rectangle str_rect;
rgb_pixel color;
};
......@@ -3175,6 +3429,22 @@ namespace dlib
unsigned long row,
unsigned long col
) const
{
return convert_wstring_to_mbstring(wtext(row, col));
}
const std::wstring wtext (
unsigned long row,
unsigned long col
) const
{
return convert_utf32_to_wstring(utext(row, col));
}
const dlib::ustring utext (
unsigned long row,
unsigned long col
) const
{
auto_mutex M(m);
DLIB_ASSERT ( row < number_of_rows() && col < number_of_columns(),
......@@ -3193,6 +3463,24 @@ namespace dlib
unsigned long col,
const std::string& str
)
{
set_text(row, col, convert_mbstring_to_wstring(str));
}
void set_text (
unsigned long row,
unsigned long col,
const std::wstring& str
)
{
set_text(row, col, convert_wstring_to_utf32(str));
}
void set_text (
unsigned long row,
unsigned long col,
const dlib::ustring& str
)
{
auto_mutex M(m);
DLIB_ASSERT ( row < number_of_rows() && col < number_of_columns(),
......@@ -3771,11 +4059,11 @@ namespace dlib
first(0), is_editable(true)
{}
std::string text;
dlib::ustring text;
rgb_pixel text_color;
rgb_pixel bg_color;
rectangle bg_rect;
std::string::size_type first;
dlib::ustring::size_type first;
bool is_editable;
};
......
// Copyright (C) 2005 Davis E. King (davisking@users.sourceforge.net)
// Copyright (C) 2005 Davis E. King (davisking@users.sourceforge.net), Keita Mochizuki
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_WIDGETs_ABSTRACT_
......@@ -204,6 +204,26 @@ namespace dlib
- std::bad_alloc
!*/
void set_text (
const std::wstring& text
);
/*!
ensures
- #text() == text
throws
- std::bad_alloc
!*/
void set_text (
const dlib::ustring& text
);
/*!
ensures
- #text() == text
throws
- std::bad_alloc
!*/
const std::string text (
) const;
/*!
......@@ -213,6 +233,24 @@ namespace dlib
- std::bad_alloc
!*/
const std::wstring wtext (
) const;
/*!
ensures
- returns the text of this label
throws
- std::bad_alloc
!*/
const dlib::ustring utext (
) const;
/*!
ensures
- returns the text of this label
throws
- std::bad_alloc
!*/
void set_text_color (
const rgb_pixel color
);
......@@ -303,6 +341,30 @@ namespace dlib
- std::bad_alloc
!*/
void set_name (
const std::wstring& name
);
/*!
ensures
- #name() == name
- this button has been resized such that it is big enough to contain
the new name.
throws
- std::bad_alloc
!*/
void set_name (
const dlib::ustring& name
);
/*!
ensures
- #name() == name
- this button has been resized such that it is big enough to contain
the new name.
throws
- std::bad_alloc
!*/
const std::string name (
) const;
/*!
......@@ -312,6 +374,24 @@ namespace dlib
- std::bad_alloc
!*/
const std::wstring wname (
) const;
/*!
ensures
- returns the name of this button
throws
- std::bad_alloc
!*/
const dlib::string uname (
) const;
/*!
ensures
- returns the name of this button
throws
- std::bad_alloc
!*/
void set_tooltip_text (
const std::string& text
);
......@@ -328,6 +408,20 @@ namespace dlib
- returns the text that is displayed in the tooltip for this button
!*/
const std::wstring tooltip_wtext (
) const;
/*!
ensures
- returns the text that is displayed in the tooltip for this button
!*/
const dlib::ustring tooltip_utext (
) const;
/*!
ensures
- returns the text that is displayed in the tooltip for this button
!*/
template <
typename style_type
>
......@@ -445,6 +539,30 @@ namespace dlib
- std::bad_alloc
!*/
void set_name (
const std::wstring& name
);
/*!
ensures
- #name() == name
- this toggle_button has been resized such that it is big enough to contain
the new name.
throws
- std::bad_alloc
!*/
void set_name (
const dlib::ustring& name
);
/*!
ensures
- #name() == name
- this toggle_button has been resized such that it is big enough to contain
the new name.
throws
- std::bad_alloc
!*/
void set_size (
unsigned long width_,
unsigned long height_
......@@ -469,6 +587,24 @@ namespace dlib
- enables the tooltip for this toggle_button
!*/
void set_tooltip_text (
const std::wstring& text
);
/*!
ensures
- #tooltip_text() == text
- enables the tooltip for this toggle_button
!*/
void set_tooltip_text (
const dlib::ustring& text
);
/*!
ensures
- #tooltip_text() == text
- enables the tooltip for this toggle_button
!*/
const std::string tooltip_text (
) const;
/*!
......@@ -510,6 +646,26 @@ namespace dlib
- std::bad_alloc
!*/
const std::wstring wname (
) const;
/*!
ensures
- returns the name of this toggle_button. The name is a string
that appears to the right of the actual check box.
throws
- std::bad_alloc
!*/
const dlib::ustring uname (
) const;
/*!
ensures
- returns the name of this toggle_button. The name is a string
that appears to the right of the actual check box.
throws
- std::bad_alloc
!*/
void set_checked (
);
/*!
......@@ -628,6 +784,32 @@ namespace dlib
- std::bad_alloc
!*/
void set_text (
const std::wstring& text
);
/*!
requires
- text.find_first_of('\n') == std::wstring::npos
(i.e. there aren't any new lines in text)
ensures
- #text() == text
throws
- std::bad_alloc
!*/
void set_text (
const dlib::ustring& text
);
/*!
requires
- text.find_first_of('\n') == dlib::ustring::npos
(i.e. there aren't any new lines in text)
ensures
- #text() == text
throws
- std::bad_alloc
!*/
const std::string text (
) const;
/*!
......@@ -637,6 +819,24 @@ namespace dlib
- std::bad_alloc
!*/
const std::wstring wtext (
) const;
/*!
ensures
- returns the text of this text_field
throws
- std::bad_alloc
!*/
const dlib::ustring utext (
) const;
/*!
ensures
- returns the text of this text_field
throws
- std::bad_alloc
!*/
void set_width (
unsigned long width_
);
......@@ -871,6 +1071,26 @@ namespace dlib
- returns a const reference to the name of the tab given by idx
!*/
const std::wstring& tab_wname (
unsigned long idx
) const;
/*!
requires
- idx < number_of_tabs()
ensures
- returns a const reference to the name of the tab given by idx
!*/
const dlib::ustring& tab_uname (
unsigned long idx
) const;
/*!
requires
- idx < number_of_tabs()
ensures
- returns a const reference to the name of the tab given by idx
!*/
void set_tab_name (
unsigned long idx,
const std::string& new_name
......@@ -884,6 +1104,32 @@ namespace dlib
- std::bad_alloc
!*/
void set_tab_name (
unsigned long idx,
const std::wstring& new_name
);
/*!
requires
- idx < number_of_tabs()
ensures
- #tab_name(idx) == new_name
throws
- std::bad_alloc
!*/
void set_tab_name (
unsigned long idx,
const dlib::ustring& new_name
);
/*!
requires
- idx < number_of_tabs()
ensures
- #tab_name(idx) == new_name
throws
- std::bad_alloc
!*/
void set_tab_group (
unsigned long idx,
widget_group& group
......@@ -1015,6 +1261,26 @@ namespace dlib
- std::bad_alloc
!*/
void set_name (
const std::wstring& name
);
/*!
ensures
- #name() == name
throws
- std::bad_alloc
!*/
void set_name (
const dlib::ustring& name
);
/*!
ensures
- #name() == name
throws
- std::bad_alloc
!*/
const std::string name (
) const;
/*!
......@@ -1024,6 +1290,24 @@ namespace dlib
- std::bad_alloc
!*/
const std::wstring wname (
) const;
/*!
ensures
- returns the name of this named_rectangle
throws
- std::bad_alloc
!*/
const dlib::ustring uname (
) const;
/*!
ensures
- returns the name of this named_rectangle
throws
- std::bad_alloc
!*/
private:
// restricted functions
......@@ -1296,6 +1580,18 @@ namespace dlib
list_box& operator=(list_box&); // assignment operator
};
class wlist_box : public drawable,
public enumerable<const std::wstring>;
/*!
same as list_box except for std::wstring instead of std::string
!*/
class ulist_box : public drawable,
public enumerable<const dlib::ustring>;
/*!
same as list_box except for dlib::ustring instead of std::string
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// class menu_bar
......@@ -1376,6 +1672,26 @@ namespace dlib
- returns the name of the menu with index idx
!*/
const std::wstring menu_wname (
unsigned long idx
) const;
/*!
requires
- idx < number_of_menus()
ensures
- returns the name of the menu with index idx
!*/
const dlib::ustring menu_uname (
unsigned long idx
) const;
/*!
requires
- idx < number_of_menus()
ensures
- returns the name of the menu with index idx
!*/
popup_menu& menu (
unsigned long idx
);
......@@ -1530,6 +1846,28 @@ namespace dlib
- #node_label(i) == label
!*/
void set_node_label (
unsigned long i,
const std::wstring& label
);
/*!
requires
- i < number_of_nodes()
ensures
- #node_label(i) == label
!*/
void set_node_label (
unsigned long i,
const dlib::ustring& label
);
/*!
requires
- i < number_of_nodes()
ensures
- #node_label(i) == label
!*/
void set_node_color (
unsigned long i,
rgb_pixel color
......@@ -1561,6 +1899,26 @@ namespace dlib
- returns the text label for node graph_node(i)
!*/
const std::wstring node_wlabel (
unsigned long i
) const;
/*!
requires
- i < number_of_nodes()
ensures
- returns the text label for node graph_node(i)
!*/
const dlib::ustring node_ulabel (
unsigned long i
) const;
/*!
requires
- i < number_of_nodes()
ensures
- returns the text label for node graph_node(i)
!*/
template <
typename T
>
......@@ -1749,6 +2107,30 @@ namespace dlib
- returns the text in the given grid location
!*/
const std::wstring wtext (
unsigned long row,
unsigned long col
) const;
/*!
requires
- row < number_of_rows()
- col < number_of_columns()
ensures
- returns the text in the given grid location
!*/
const dlib::ustring utext (
unsigned long row,
unsigned long col
) const;
/*!
requires
- row < number_of_rows()
- col < number_of_columns()
ensures
- returns the text in the given grid location
!*/
void set_text (
unsigned long row,
unsigned long col,
......@@ -1762,6 +2144,32 @@ namespace dlib
- #text(row,col) == str
!*/
void set_text (
unsigned long row,
unsigned long col,
const std::wstring& str
);
/*!
requires
- row < number_of_rows()
- col < number_of_columns()
ensures
- #text(row,col) == str
!*/
void set_text (
unsigned long row,
unsigned long col,
const dlib::ustring& str
);
/*!
requires
- row < number_of_rows()
- col < number_of_columns()
ensures
- #text(row,col) == str
!*/
const rgb_pixel text_color (
unsigned long row,
unsigned long col
......
......@@ -118,6 +118,7 @@
#include "interfaces/enumerable.h"
#include "interfaces/map_pair.h"
#include "enable_if.h"
#include "unicode.h"
namespace dlib
{
......@@ -765,6 +766,40 @@ namespace dlib
if (!in) throw serialization_error("Error deserializing object of type std::wstring");
}
// ----------------------------------------------------------------------------------------
inline void serialize (
const ustring& item,
std::ostream& out
)
{
const unsigned long size = static_cast<unsigned long>(item.size());
try{ serialize(size,out); }
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while serializing object of type ustring"); }
for (unsigned long i = 0; i < item.size(); ++i)
serialize(item[i], out);
if (!out) throw serialization_error("Error serializing object of type ustring");
}
inline void deserialize (
ustring& item,
std::istream& in
)
{
unsigned long size;
try { deserialize(size,in); }
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while deserializing object of type ustring"); }
item.resize(size);
for (unsigned long i = 0; i < item.size(); ++i)
deserialize(item[i],in);
if (!in) throw serialization_error("Error deserializing object of type ustring");
}
// ----------------------------------------------------------------------------------------
template <
......
......@@ -3,9 +3,9 @@
#ifndef DLIB_STRINg_
#define DLIB_STRINg_
#include "../algs.h"
#include <string>
#include <iostream>
#include "../algs.h"
#include "../error.h"
#include "../assert.h"
#include "string_abstract.h"
......@@ -227,10 +227,12 @@ namespace dlib
std::string temp;
temp.reserve(str.size());
std::string::size_type i;
std::basic_ostringstream<charT,traits,alloc> sout;
for (i = 0; i < str.size(); ++i)
{
temp += sout.narrow(str[i],' ');
if (zero_extend_cast<unsigned long>(str[i]) > 255)
temp += ' ';
else
temp += zero_extend_cast<char>(str[i]);
}
return temp;
}
......
// Copyright (C) 2008 Keita Mochizuki, Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_UNICODe_CPp_
#define DLIB_UNICODe_CPp_
#include "unicode.h"
#include <cwchar>
#include "../string.h"
#include <vector>
namespace dlib
{
// ----------------------------------------------------------------------------------------
static const unichar SURROGATE_FIRST_TOP = 0xD800;
static const unichar SURROGATE_SECOND_TOP = 0xDC00;
static const unichar SURROGATE_CLEARING_MASK = 0x03FF;
static const unichar &SURROGATE_TOP = SURROGATE_FIRST_TOP;
static const unichar SURROGATE_END = 0xE000;
static const unichar SMP_TOP = 0x10000;
static const int VALID_BITS = 10;
// ----------------------------------------------------------------------------------------
template <typename T> bool is_surrogate(T ch)
{
return (zero_extend_cast<unichar>(ch) >= SURROGATE_TOP &&
zero_extend_cast<unichar>(ch) < SURROGATE_END);
}
// ----------------------------------------------------------------------------------------
template <typename T> unichar surrogate_pair_to_unichar(T first, T second)
{
return ((first & SURROGATE_CLEARING_MASK) << VALID_BITS) | (second & SURROGATE_CLEARING_MASK) + SMP_TOP;
}
//110110 0000000000
//110111 0000000000
// ----------------------------------------------------------------------------------------
void unichar_to_surrogate_pair(unichar input, unichar &first, unichar &second)
{
first = ((input - SMP_TOP) >> VALID_BITS) | SURROGATE_FIRST_TOP;
second = (input & SURROGATE_CLEARING_MASK) | SURROGATE_SECOND_TOP;
}
// ----------------------------------------------------------------------------------------
template <int N> void wstr2ustring_t(const wchar_t *src, size_t src_len, ustring &dest);
template <> void wstr2ustring_t<4>(const wchar_t *src, size_t src_len, ustring &dest)
{
dest.assign((const unichar *)(src));
}
template <> void wstr2ustring_t<2>(const wchar_t *src, size_t src_len, ustring &dest)
{
size_t wlen = 0;
for (size_t i = 0; i < src_len; i++)
{
is_surrogate(src[i]) ? i++, wlen++ : wlen++;
}
dest.resize(wlen);
for (size_t i = 0, ii = 0; ii < src_len; ++i)
{
if (is_surrogate(src[ii]))
{
dest[i] = surrogate_pair_to_unichar(src[ii], src[ii+1]);
ii += 2;
}else
{
dest[i] = zero_extend_cast<unichar>(src[ii]);
ii++;
}
}
}
// ----------------------------------------------------------------------------------------
const ustring convert_wstring_to_utf32(const std::wstring &src)
{
ustring dest;
wstr2ustring_t<sizeof(wchar_t)>(src.c_str(), src.size(), dest);
return dest;
}
// ----------------------------------------------------------------------------------------
template <int N> struct ustring2wstr
{
};
// for the environment of sizeof(wchar_t) == 2 (i.e. Win32)
template <> struct ustring2wstr<2>
{
wchar_t *wstr;
size_t wlen;
ustring2wstr(const ustring &src){
wlen = 0;
for (size_t i = 0; i < src.length(); ++i)
{
if (src[i] < SMP_TOP) wlen++;
else wlen += 2;
}
wstr = new wchar_t[wlen+1];
wstr[wlen] = L'\0';
size_t wi = 0;
for (size_t i = 0; i < src.length(); ++i)
{
if (src[i] < SMP_TOP)
{
wstr[wi++] = (wchar_t)src[i];
}else
{
unichar high, low;
unichar_to_surrogate_pair(src[i], high, low);
wstr[wi++] = (wchar_t)high;
wstr[wi++] = (wchar_t)low;
}
}
}
~ustring2wstr()
{
delete[] wstr;
}
};
// for the environment of sizeof(wchar_t) == 4 (i.e. Unix gcc)
template <> struct ustring2wstr<4>
{
const wchar_t *wstr;
size_t wlen;
ustring2wstr(const ustring &src){
wstr = (const wchar_t *)(src.c_str());
wlen = src.size();
}
};
// ----------------------------------------------------------------------------------------
const std::wstring convert_utf32_to_wstring(const ustring &src)
{
ustring2wstr<sizeof(wchar_t)> conv(src);
std::wstring dest(conv.wstr);
return dest;
}
// ----------------------------------------------------------------------------------------
const std::wstring convert_mbstring_to_wstring(const std::string &src)
{
std::vector<wchar_t> wstr(src.length()+1);
std::mbstowcs(&wstr.front(), src.c_str(), src.length()+1);
return std::wstring(&wstr.front());
}
// ----------------------------------------------------------------------------------------
const std::string convert_wstring_to_mbstring(const std::wstring &src)
{
using namespace std;
std::string str;
str.resize((src.length() + 1) * MB_CUR_MAX);
wcstombs(&str[0], src.c_str(), str.size());
return std::string(&str[0]);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_UNICODe_CPp_
......@@ -7,6 +7,8 @@
#include "../algs.h"
#include "unicode_abstract.h"
#include <string>
#include <cstring>
#include <fstream>
namespace dlib
......@@ -15,7 +17,94 @@ namespace dlib
// ----------------------------------------------------------------------------------------
typedef uint32 unichar;
#if defined(__GNUC__) && __GNUC__ < 4 && __GNUC_MINOR__ < 4
struct unichar_traits
{
typedef dlib::unichar char_type;
typedef dlib::unichar int_type;
typedef std::streamoff off_type;
typedef std::streampos pos_type;
typedef std::mbstate_t state_type;
static void assign(char_type& c1, const char_type& c2) { c1 = c2; }
static bool eq(const char_type& c1, const char_type& c2) { return c1 == c2; }
static bool lt(const char_type& c1, const char_type& c2) { return c1 < c2; }
static int compare(const char_type* s1, const char_type* s2, size_t n)
{
for (size_t i = 0; i < n; ++i)
{
if (s1[i] < s2[i])
return -1;
else if (s1[i] > s2[i])
return 1;
}
return 0;
}
static size_t length(const char_type* s)
{
size_t i = 0;
while (s[i] != 0)
++i;
return i;
}
static const char_type* find(const char_type* s, size_t n,
const char_type& a)
{
for (size_t i = 0; i < n; ++i)
{
if (s[i] == a)
{
return s+i;
}
}
return 0;
}
static char_type* move(char_type* s1, const char_type* s2, size_t n)
{
return static_cast<char_type*>(std::memmove(s1, s2, sizeof(char_type)*n));
}
static char_type* copy(char_type* s1, const char_type* s2, size_t n)
{
for (size_t i = 0; i < n; ++i)
s1[i] = s2[i];
return s1;
}
static char_type* assign(char_type* s, size_t n, char_type a)
{
for (size_t i = 0; i < n; ++i)
s[i] = a;
return s;
}
static int_type not_eof(const int_type& c)
{
if (!eq_int_type(c,eof()))
return to_int_type(c);
else
return 0;
}
static char_type to_char_type(const int_type& c) { return static_cast<char_type>(c); }
static int_type to_int_type(const char_type& c) { return zero_extend_cast<int_type>(c); }
static bool eq_int_type(const int_type& c1, const int_type& c2) { return c1 == c2; }
static int_type eof() { return static_cast<int_type>(EOF); }
};
typedef std::basic_string<unichar, unichar_traits> ustring;
#else
typedef std::basic_string<unichar> ustring;
#endif
// ----------------------------------------------------------------------------------------
......@@ -419,6 +508,31 @@ namespace dlib
return temp;
}
// ----------------------------------------------------------------------------------------
bool is_surrogate(unichar ch);
unichar surrogate_pair_to_unichar(unichar first, unichar second);
void unichar_to_surrogate_pair(unichar unicode, unichar &first, unichar &second);
const ustring convert_wstring_to_utf32 (
const std::wstring &wstr
);
const std::wstring convert_utf32_to_wstring (
const ustring &src
);
const std::wstring convert_mbstring_to_wstring (
const std::string &src
);
const std::string convert_wstring_to_mbstring(
const std::wstring &src
);
// ----------------------------------------------------------------------------------------
template <typename charT>
......@@ -490,5 +604,9 @@ namespace dlib
}
#ifdef NO_MAKEFILE
#include "unicode.cpp"
#endif
#endif // DLIB_UNICODe_H_
......@@ -33,6 +33,44 @@ namespace dlib
- returns false
!*/
bool is_surrogate(
unichar ch
);
/*!
ensures
- if (ch is a unicode surrogate character) then
- returns true
- else
- returns false
!*/
unichar surrogate_pair_to_unichar(
unichar first,
unichar second
);
/*!
requires
- 0xD800 <= first < 0xDC00
- 0xDC00 <= second < 0xE000
- is_surrogate(first) == true
- is_surrogate(second) == true
ensures
- converts two surrogates into one unicode character
!*/
void unichar_to_surrogate_pair(
unichar ch,
unichar& first,
unichar& second
);
/*!
requires
- ch >= 0x10000 (i.e. is not in Basic Multilingual Plane)
ensures
- surrogate_pair_to_unichar(#first,#second) == ch
(i.e. converts ch into two surrogate characters)
!*/
// ----------------------------------------------------------------------------------------
class invalid_utf8_error : public error
......@@ -53,6 +91,58 @@ namespace dlib
- throws invalid_utf8_error
!*/
// ----------------------------------------------------------------------------------------
const ustring convert_wstring_to_utf32 (
const std::wstring &wstr
);
/*!
requires
- wstr is a valid UTF-16 string when sizeof(wchar_t) == 2
- wstr is a valid UTF-32 string when sizeof(wchar_t) == 4
ensures
- converts wstr into UTF-32 string
!*/
// ----------------------------------------------------------------------------------------
const std::wstring convert_utf32_to_wstring (
const ustring &str
);
/*!
requires
- str is a valid UTF-32 encoded string
ensures
- converts str into wstring whose encoding is UTF-16 when sizeof(wchar_t) == 2
- converts str into wstring whose encoding is UTF-32 when sizeof(wchar_t) == 4
!*/
// ----------------------------------------------------------------------------------------
const std::wstring convert_mbstring_to_wstring (
const std::string &str
);
/*!
requires
- str is a valid multibyte string whose encoding is same as current locale setting
ensures
- converts str into wstring whose encoding is UTF-16 when sizeof(wchar_t) == 2
- converts str into wstring whose encoding is UTF-32 when sizeof(wchar_t) == 4
!*/
// ----------------------------------------------------------------------------------------
const std::string convert_wstring_to_mbstring (
const std::wstring &src
);
/*!
requires
- str is a valid wide character string string whose encoding is same as current
locale setting
ensures
- returns a multibyte encoded version of the given string
!*/
// ----------------------------------------------------------------------------------------
template <
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment