]> git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/uuid.cpp
many fixes to wxTextCrtl, wxTreeCrtl, wxListBox,
[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 #define IN_WX_MAIN_CPP
22 #include "wx/wxprec.h"
23
24 #if defined(__BORLANDC__)
25 #pragma hdrstop
26 #endif
27
28 #include <wx/setup.h>
29
30 #if USE_DRAG_AND_DROP
31
32 // standard headers
33 #include <rpc.h> // UUID related functions
34
35 #include <wx/msw/ole/uuid.h>
36
37
38
39 // ============================================================================
40 // Implementation
41 // ============================================================================
42
43 // length of UUID in C format
44 #define UUID_CSTRLEN 100 // real length is 66
45
46 // copy ctor
47 Uuid::Uuid(const Uuid& uuid)
48 {
49 // bitwise copy Ok for UUIDs
50 m_uuid = uuid.m_uuid;
51
52 // force the string to be allocated by RPC
53 // (we free it later with RpcStringFree)
54 UuidToString(&m_uuid, &m_pszUuid);
55
56 // allocate new buffer
57 m_pszCForm = new char[UUID_CSTRLEN];
58 // and fill it
59 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN);
60 }
61
62 // assignment operator
63 Uuid& Uuid::operator=(const Uuid& uuid)
64 {
65 m_uuid = uuid.m_uuid;
66
67 // force the string to be allocated by RPC
68 // (we free it later with RpcStringFree)
69 UuidToString(&m_uuid, &m_pszUuid);
70
71 // allocate new buffer if not done yet
72 if ( !m_pszCForm )
73 m_pszCForm = new char[UUID_CSTRLEN];
74
75 // and fill it
76 memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN);
77
78 return *this;
79 }
80
81 // dtor
82 Uuid::~Uuid()
83 {
84 // this string must be allocated by RPC!
85 // (otherwise you get a debug breakpoint deep inside RPC DLL)
86 if ( m_pszUuid )
87 RpcStringFree(&m_pszUuid);
88
89 // perhaps we should just use a static buffer and not bother
90 // with new and delete?
91 if ( m_pszCForm )
92 delete [] m_pszCForm;
93 }
94
95 // update string representation of new UUID
96 void Uuid::Set(const UUID &uuid)
97 {
98 m_uuid = uuid;
99
100 // get string representation
101 UuidToString(&m_uuid, &m_pszUuid);
102
103 // cache UUID in C format
104 UuidToCForm();
105 }
106
107 // create a new UUID
108 void Uuid::Create()
109 {
110 UUID uuid;
111
112 // can't fail
113 UuidCreate(&uuid);
114
115 Set(uuid);
116 }
117
118 // set the value
119 bool Uuid::Set(const char *pc)
120 {
121 // get UUID from string
122 if ( UuidFromString((uchar *)pc, &m_uuid) != RPC_S_OK)
123 // failed: probably invalid string
124 return FALSE;
125
126 // transform it back to string to normalize it
127 UuidToString(&m_uuid, &m_pszUuid);
128
129 // update m_pszCForm
130 UuidToCForm();
131
132 return TRUE;
133 }
134
135 // stores m_uuid in m_pszCForm in a format required by
136 // DEFINE_GUID macro: i.e. something like
137 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
138 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
139 // 6aadc650-67b0-11d0-bac8-0000c018ba27
140 void Uuid::UuidToCForm()
141 {
142 if ( m_pszCForm == NULL )
143 m_pszCForm = new char[UUID_CSTRLEN];
144
145 wsprintf(m_pszCForm, "0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,"
146 "0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X",
147 m_uuid.Data1, m_uuid.Data2, m_uuid.Data3,
148 m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3], m_uuid.Data4[4],
149 m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7], m_uuid.Data4[8]);
150 }
151
152 #endif
153 // USE_DRAG_AND_DROP