source: trunk/Lucide/SOURCE/gui/clipbrd.cpp @ 35

Last change on this file since 35 was 35, checked in by Eugene Romanenko, 16 years ago

added licence block to source files

File size: 3.6 KB
RevLine 
[35]1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: CDDL 1.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the COMMON DEVELOPMENT AND
5 * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
6 * this file except in compliance with the License. You may obtain a copy of
7 * the License at http://www.sun.com/cddl/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Initial Developer of the Original Code is
15 * Eugene Romanenko, netlabs.org.
16 * Portions created by the Initial Developer are Copyright (C) 2006
17 * the Initial Developer. All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * Alternatively, the contents of this file may be used under the terms of
22 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
23 * in which case the provisions of the LGPL are applicable instead of those
24 * above. If you wish to allow use of your version of this file only under the
25 * terms of the LGPL, and not to allow others to use your version of this file
26 * under the terms of the CDDL, indicate your decision by deleting the
27 * provisions above and replace them with the notice and other provisions
28 * required by the LGPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under the terms of any one of the CDDL
30 * or the LGPL.
31 *
32 * ***** END LICENSE BLOCK ***** */
33
34
[2]35#define INCL_WIN
36#define INCL_DOS
37#include <os2.h>
38
39#include <string.h>
40#include <malloc.h>
41#include "cpconv.h"
42
43
44#define kUnicodeMime "text/unicode"
45
46inline ULONG RegisterClipboardFormat(PCSZ pcszFormat)
47{
48    ATOM atom = WinFindAtom(WinQuerySystemAtomTable(), pcszFormat);
49    if (!atom) {
50        atom = WinAddAtom(WinQuerySystemAtomTable(), pcszFormat);
51    }
52    return atom;
53}
54
55void initClipbrd()
56{
57    RegisterClipboardFormat( kUnicodeMime );
58}
59
60void textToClipbrd( HAB hab, const char *text )
61{
62    size_t len = 0;
63    size_t olen = 0;
64    const char *tsav = text;
65
66    if ( WinOpenClipbrd( hab ) )
67    {
68        WinEmptyClipbrd( hab );
69
70        len = strlen( text );
71        olen = (len + 2)*2;
72
73        void *memuni = NULL;
74
75        // place to clipboard as unicode
76        if ( DosAllocSharedMem( &memuni, NULL, olen ,
77                                PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == 0 )
78        {
79            memset( memuni, 0, olen );
80            void *tmem = memuni;
81
82            //cpconv c( 1208, 1200 );
83            tsav = text;
84            //c.conv( &text, &len, (char **)&memuni, &olen );
85            cnvUTF8ToUni( &text, &len, (char **)&memuni, &olen );
86            text = tsav;
87
88            ULONG ulFormatID = RegisterClipboardFormat( kUnicodeMime );
89            WinSetClipbrdData( hab, (ULONG)tmem, ulFormatID, CFI_POINTER );
90        }
91
92        len = strlen( text );
93        olen = (len + 2)*2;
94        void *memcp = NULL;
95
96        // place to clipboard as current codepage
97        if ( DosAllocSharedMem( &memcp, NULL, olen ,
98                                PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) == 0 )
99        {
100            memset( memcp, 0, olen );
101            void *tmem = memcp;
102
103            //cpconv c( 1208 );
104            tsav = text;
105            //c.conv( &text, &len, (char **)&memcp, &olen );
106            cnvUTF8ToSys( &text, &len, (char **)&memcp, &olen );
107                        text = tsav;
108
109            WinSetClipbrdData( hab, (ULONG)tmem, CF_TEXT, CFI_POINTER );
110        }
111
112
113        WinCloseClipbrd( hab );
114    }
115}
116
Note: See TracBrowser for help on using the repository browser.