OSDN Git Service

Handling key and mouse events in listctrl is improved
[molby/Molby.git] / wxSources / MyClipboardData.cpp
1 /*
2  *  MyClipboardData.cpp
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 08/11/26.
6  *  Copyright 2008 Toshi Nagata. All rights reserved.
7  *
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation version 2 of the License.
11  
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16  */
17
18 #include "MyClipboardData.h"
19 #include "MyMBConv.h"
20
21 MyClipboardData::MyClipboardData(const char *type):
22         wxDataObjectSimple()
23 {
24         wxString ftype(type, WX_DEFAULT_CONV);
25         wxDataFormat customFormat((const wxChar *)ftype);
26         buffer = NULL;
27         length = 0;
28         SetFormat(customFormat);
29 }
30
31 MyClipboardData::~MyClipboardData()
32 {
33         if (buffer != NULL)
34                 free(buffer);
35 }
36
37 size_t
38 MyClipboardData::GetDataSize() const
39 {
40         return length;
41 }
42
43 bool
44 MyClipboardData::GetDataHere(void *buf) const
45 {
46         if (buffer != NULL) {
47                 memmove(buf, buffer, length);
48                 return true;
49         } else return false;
50 }
51
52 bool
53 MyClipboardData::SetData(size_t len, const void *buf)
54 {
55         char *p;
56         if (buffer == NULL)
57                 p = (char *)malloc(len);
58         else
59                 p = (char *)realloc(buffer, len);
60         if (p == NULL)
61                 return false;
62         memmove(p, buf, len);
63         buffer = p;
64         length = len;
65         return true;
66 }