]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/private/string.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/private/string.h
3 // Purpose: wxGtkString class declaration
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GTK_PRIVATE_STRING_H_
11 #define _WX_GTK_PRIVATE_STRING_H_
13 // ----------------------------------------------------------------------------
14 // Convenience class for g_freeing a gchar* on scope exit automatically
15 // ----------------------------------------------------------------------------
20 explicit wxGtkString(gchar
*s
) : m_str(s
) { }
21 ~wxGtkString() { g_free(m_str
); }
23 const gchar
*c_str() const { return m_str
; }
25 operator gchar
*() const { return m_str
; }
30 wxDECLARE_NO_COPY_CLASS(wxGtkString
);
34 // ----------------------------------------------------------------------------
35 // list for sorting collated strings
36 // ----------------------------------------------------------------------------
38 #include "wx/string.h"
39 #include "wx/vector.h"
40 #include "wx/sharedptr.h"
42 class wxGtkCollatableString
45 wxGtkCollatableString( const wxString
&label
, gchar
*key
)
51 ~wxGtkCollatableString()
61 class wxGtkCollatedArrayString
64 wxGtkCollatedArrayString() { }
66 int Add( const wxString
&new_label
)
70 gchar
*new_key_lower
= g_utf8_casefold( new_label
.utf8_str(), -1);
71 gchar
*new_key
= g_utf8_collate_key( new_key_lower
, -1);
72 g_free( new_key_lower
);
74 wxSharedPtr
<wxGtkCollatableString
> new_ptr( new wxGtkCollatableString( new_label
, new_key
) );
76 wxVector
< wxSharedPtr
<wxGtkCollatableString
> >::iterator iter
;
77 for (iter
= m_list
.begin(); iter
!= m_list
.end(); ++iter
)
79 wxSharedPtr
<wxGtkCollatableString
> ptr
= *iter
;
81 gchar
*key
= ptr
->m_key
;
82 if (strcmp(key
,new_key
) >= 0)
84 m_list
.insert( iter
, new_ptr
);
90 m_list
.push_back( new_ptr
);
99 wxString
At( size_t index
)
101 return m_list
[index
]->m_label
;
109 void RemoveAt( size_t index
)
111 m_list
.erase( m_list
.begin() + index
);
115 wxVector
< wxSharedPtr
<wxGtkCollatableString
> > m_list
;
119 #endif // _WX_GTK_PRIVATE_STRING_H_