]>
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
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GTK_PRIVATE_STRING_H_
12 #define _WX_GTK_PRIVATE_STRING_H_
14 // ----------------------------------------------------------------------------
15 // Convenience class for g_freeing a gchar* on scope exit automatically
16 // ----------------------------------------------------------------------------
21 explicit wxGtkString(gchar
*s
) : m_str(s
) { }
22 ~wxGtkString() { g_free(m_str
); }
24 const gchar
*c_str() const { return m_str
; }
26 operator gchar
*() const { return m_str
; }
31 wxDECLARE_NO_COPY_CLASS(wxGtkString
);
35 // ----------------------------------------------------------------------------
36 // list for sorting collated strings
37 // ----------------------------------------------------------------------------
39 #include "wx/string.h"
40 #include "wx/vector.h"
41 #include "wx/sharedptr.h"
43 class wxGtkCollatableString
46 wxGtkCollatableString( const wxString
&label
, gchar
*key
)
52 ~wxGtkCollatableString()
62 class wxGtkCollatedArrayString
65 wxGtkCollatedArrayString() { }
67 int Add( const wxString
&new_label
)
71 gchar
*new_key_lower
= g_utf8_casefold( new_label
.utf8_str(), -1);
72 gchar
*new_key
= g_utf8_collate_key( new_key_lower
, -1);
73 g_free( new_key_lower
);
75 wxSharedPtr
<wxGtkCollatableString
> new_ptr( new wxGtkCollatableString( new_label
, new_key
) );
77 wxVector
< wxSharedPtr
<wxGtkCollatableString
> >::iterator iter
;
78 for (iter
= m_list
.begin(); iter
!= m_list
.end(); ++iter
)
80 wxSharedPtr
<wxGtkCollatableString
> ptr
= *iter
;
82 gchar
*key
= ptr
->m_key
;
83 if (strcmp(key
,new_key
) >= 0)
85 m_list
.insert( iter
, new_ptr
);
91 m_list
.push_back( new_ptr
);
100 wxString
At( size_t index
)
102 return m_list
[index
]->m_label
;
110 void RemoveAt( size_t index
)
112 m_list
.erase( m_list
.begin() + index
);
116 wxVector
< wxSharedPtr
<wxGtkCollatableString
> > m_list
;
120 #endif // _WX_GTK_PRIVATE_STRING_H_