]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/private/string.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / gtk / private / string.h
CommitLineData
b098b621
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/gtk/private/string.h
3// Purpose: wxGtkString class declaration
4// Author: Vadim Zeitlin
5// Created: 2006-10-19
b098b621
VZ
6// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_GTK_PRIVATE_STRING_H_
11#define _WX_GTK_PRIVATE_STRING_H_
12
13// ----------------------------------------------------------------------------
14// Convenience class for g_freeing a gchar* on scope exit automatically
15// ----------------------------------------------------------------------------
16
17class wxGtkString
18{
19public:
20 explicit wxGtkString(gchar *s) : m_str(s) { }
21 ~wxGtkString() { g_free(m_str); }
22
23 const gchar *c_str() const { return m_str; }
24
25 operator gchar *() const { return m_str; }
26
27private:
28 gchar *m_str;
29
c0c133e1 30 wxDECLARE_NO_COPY_CLASS(wxGtkString);
b098b621
VZ
31};
32
c272f12f
RR
33
34// ----------------------------------------------------------------------------
35// list for sorting collated strings
36// ----------------------------------------------------------------------------
37
89083178 38#include "wx/string.h"
c272f12f
RR
39#include "wx/vector.h"
40#include "wx/sharedptr.h"
41
42class wxGtkCollatableString
43{
44public:
45 wxGtkCollatableString( const wxString &label, gchar *key )
46 {
47 m_label = label;
48 m_key = key;
49 }
ce00f59b 50
c272f12f
RR
51 ~wxGtkCollatableString()
52 {
ce00f59b 53 if (m_key)
c272f12f
RR
54 g_free( m_key );
55 }
56
57 wxString m_label;
58 gchar *m_key;
59};
60
61class wxGtkCollatedArrayString
62{
63public:
64 wxGtkCollatedArrayString() { }
ce00f59b 65
c272f12f
RR
66 int Add( const wxString &new_label )
67 {
68 int index = 0;
ce00f59b
VZ
69
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);
c272f12f 72 g_free( new_key_lower );
ce00f59b 73
c272f12f 74 wxSharedPtr<wxGtkCollatableString> new_ptr( new wxGtkCollatableString( new_label, new_key ) );
ce00f59b 75
c272f12f
RR
76 wxVector< wxSharedPtr<wxGtkCollatableString> >::iterator iter;
77 for (iter = m_list.begin(); iter != m_list.end(); ++iter)
78 {
79 wxSharedPtr<wxGtkCollatableString> ptr = *iter;
ce00f59b 80
c272f12f 81 gchar *key = ptr->m_key;
625ed743 82 if (strcmp(key,new_key) >= 0)
c272f12f
RR
83 {
84 m_list.insert( iter, new_ptr );
85 return index;
86 }
87 index ++;
88 }
ce00f59b 89
c272f12f
RR
90 m_list.push_back( new_ptr );
91 return index;
92 }
ce00f59b 93
c272f12f
RR
94 size_t GetCount()
95 {
96 return m_list.size();
97 }
ce00f59b 98
c272f12f
RR
99 wxString At( size_t index )
100 {
101 return m_list[index]->m_label;
102 }
ce00f59b 103
c272f12f
RR
104 void Clear()
105 {
106 m_list.clear();
107 }
ce00f59b 108
c272f12f
RR
109 void RemoveAt( size_t index )
110 {
111 m_list.erase( m_list.begin() + index );
112 }
ce00f59b 113
c272f12f
RR
114private:
115 wxVector< wxSharedPtr<wxGtkCollatableString> > m_list;
116};
117
118
b098b621
VZ
119#endif // _WX_GTK_PRIVATE_STRING_H_
120