]> git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/uuid.cpp
Don't call busy cursor when creating a message
[wxWidgets.git] / src / msw / ole / uuid.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: ole/uuid.cpp
3 // Purpose: implements Uuid class, see uuid.h for details
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 12.09.96
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // Declarations
14 // ============================================================================
15
16 #ifdef __GNUG__
17 #pragma implementation "uuid.h"
18 #endif
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #if defined(__BORLANDC__)
24 #pragma hdrstop
25 #endif
26
27 #include "wx/setup.h"
28
29 #if wxUSE_DRAG_AND_DROP
30
31 // standard headers
32 #include <rpc.h> // UUID related functions
33
34 #include "wx/msw/ole/uuid.h"
35
36
37
38 // ============================================================================
39 // Implementation
40 // ============================================================================
41
42 // length of UUID in C format
43 #define UUID_CSTRLEN 100 // real length is 66
44
45 // copy ctor
46 Uuid::Uuid(const Uuid& uuid)
47 {
48 // bitwise copy Ok for UUIDs
49 m_uuid = uuid.m_uuid;
50
51 // force the string to be allocated by RPC
52 // (we free it later with RpcStringFree)
53 #ifdef _UNICODE
54 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
55 #else
56 UuidToString(&m_uuid, &m_pszUuid);
57 #endif
58
59 // allocate new buffer
60 m_pszCForm = new wxChar[UUID_CSTRLEN];
61 // and fill it
62 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
63 }
64
65 // assignment operator
66 Uuid& Uuid::operator=(const Uuid& uuid)
67 {
68 m_uuid = uuid.m_uuid;
69
70 // force the string to be allocated by RPC
71 // (we free it later with RpcStringFree)
72 #ifdef _UNICODE
73 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
74 #else
75 UuidToString(&m_uuid, &m_pszUuid);
76 #endif
77
78 // allocate new buffer if not done yet
79 if ( !m_pszCForm )
80 m_pszCForm = new wxChar[UUID_CSTRLEN];
81
82 // and fill it
83 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
84
85 return *this;
86 }
87
88 // dtor
89 Uuid::~Uuid()
90 {
91 // this string must be allocated by RPC!
92 // (otherwise you get a debug breakpoint deep inside RPC DLL)
93 if ( m_pszUuid )
94 #ifdef _UNICODE
95 RpcStringFree((unsigned short **)&m_pszUuid);
96 #else
97 RpcStringFree(&m_pszUuid);
98 #endif
99
100 // perhaps we should just use a static buffer and not bother
101 // with new and delete?
102 if ( m_pszCForm )
103 delete [] m_pszCForm;
104 }
105
106 // update string representation of new UUID
107 void Uuid::Set(const UUID &uuid)
108 {
109 m_uuid = uuid;
110
111 // get string representation
112 #ifdef _UNICODE
113 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
114 #else
115 UuidToString(&m_uuid, &m_pszUuid);
116 #endif
117
118 // cache UUID in C format
119 UuidToCForm();
120 }
121
122 // create a new UUID
123 void Uuid::Create()
124 {
125 UUID uuid;
126
127 // can't fail
128 UuidCreate(&uuid);
129
130 Set(uuid);
131 }
132
133 // set the value
134 bool Uuid::Set(const wxChar *pc)
135 {
136 // get UUID from string
137 #ifdef _UNICODE
138 if ( UuidFromString((unsigned short *)pc, &m_uuid) != RPC_S_OK)
139 #else
140 if ( UuidFromString((wxUChar *)pc, &m_uuid) != RPC_S_OK)
141 #endif
142 // failed: probably invalid string
143 return FALSE;
144
145 // transform it back to string to normalize it
146 #ifdef _UNICODE
147 UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
148 #else
149 UuidToString(&m_uuid, &m_pszUuid);
150 #endif
151
152 // update m_pszCForm
153 UuidToCForm();
154
155 return TRUE;
156 }
157
158 // stores m_uuid in m_pszCForm in a format required by
159 // DEFINE_GUID macro: i.e. something like
160 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
161 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
162 // 6aadc650-67b0-11d0-bac8-0000c018ba27
163 void Uuid::UuidToCForm()
164 {
165 if ( m_pszCForm == NULL )
166 m_pszCForm = new wxChar[UUID_CSTRLEN];
167
168 wsprintf(m_pszCForm, wxT("0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X"),
169 m_uuid.Data1, m_uuid.Data2, m_uuid.Data3,
170 m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3], m_uuid.Data4[4],
171 m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7], m_uuid.Data4[8]);
172 }
173
174 #endif
175 // wxUSE_DRAG_AND_DROP