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