Merged from the latest developing branch.
[MacVim/KaoriYa.git] / src / os_qnx.c
blob1a7250eab10d89840345cd9ccb34f649238d6bd4
1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * QNX port by Julian Kinraid
7 * Do ":help uganda" in Vim to read copying and usage conditions.
8 * Do ":help credits" in Vim to see a list of people who contributed.
9 */
12 * os_qnx.c
15 #include "vim.h"
18 #if defined(FEAT_GUI_PHOTON)
19 int is_photon_available;
20 #endif
22 void qnx_init()
24 #if defined(FEAT_GUI_PHOTON)
25 PhChannelParms_t parms;
27 memset( &parms, 0, sizeof( parms ) );
28 parms.flags = Ph_DYNAMIC_BUFFER;
30 is_photon_available = (PhAttach( NULL, &parms ) != NULL) ? TRUE : FALSE;
31 #endif
34 #if (defined(FEAT_GUI_PHOTON) && defined(FEAT_CLIPBOARD)) || defined(PROTO)
36 #define CLIP_TYPE_VIM "VIMTYPE"
37 #define CLIP_TYPE_TEXT "TEXT"
39 /* Turn on the clipboard for a console vim when photon is running */
40 void qnx_clip_init()
42 if( is_photon_available == TRUE && !gui.in_use)
43 clip_init( TRUE );
46 /*****************************************************************************/
47 /* Clipboard */
49 /* No support for owning the clipboard */
50 int
51 clip_mch_own_selection( VimClipboard *cbd )
53 return FALSE;
56 void
57 clip_mch_lose_selection( VimClipboard *cbd )
61 void
62 clip_mch_request_selection( VimClipboard *cbd )
64 int type = MLINE, clip_length = 0, is_type_set = FALSE;
65 void *cbdata;
66 PhClipHeader *clip_header;
67 char_u *clip_text = NULL;
69 cbdata = PhClipboardPasteStart( PhInputGroup( NULL ));
70 if( cbdata != NULL )
72 /* Look for the vim specific clip first */
73 clip_header = PhClipboardPasteType( cbdata, CLIP_TYPE_VIM );
74 if( clip_header != NULL && clip_header->data != NULL )
76 switch( *(char *) clip_header->data )
78 default: /* fallthrough to line type */
79 case 'L': type = MLINE; break;
80 case 'C': type = MCHAR; break;
81 #ifdef FEAT_VISUAL
82 case 'B': type = MBLOCK; break;
83 #endif
85 is_type_set = TRUE;
88 /* Try for just normal text */
89 clip_header = PhClipboardPasteType( cbdata, CLIP_TYPE_TEXT );
90 if( clip_header != NULL )
92 clip_text = clip_header->data;
93 clip_length = clip_header->length - 1;
95 if( clip_text != NULL && is_type_set == FALSE )
96 type = (strchr( clip_text, '\r' ) != NULL) ? MLINE : MCHAR;
99 if( (clip_text != NULL) && (clip_length > 0) )
101 clip_yank_selection( type, clip_text, clip_length, cbd );
104 PhClipboardPasteFinish( cbdata );
108 void
109 clip_mch_set_selection( VimClipboard *cbd )
111 int type;
112 long_u len;
113 char_u *text_clip, vim_clip[2], *str = NULL;
114 PhClipHeader clip_header[2];
116 /* Prevent recursion from clip_get_selection() */
117 if( cbd->owned == TRUE )
118 return;
120 cbd->owned = TRUE;
121 clip_get_selection( cbd );
122 cbd->owned = FALSE;
124 type = clip_convert_selection( &str, &len, cbd );
125 if( type >= 0 )
127 text_clip = lalloc( len + 1, TRUE ); /* Normal text */
129 if( text_clip && vim_clip )
131 memset( clip_header, 0, sizeof( clip_header ) );
133 STRNCPY( clip_header[0].type, CLIP_TYPE_VIM, 8 );
134 clip_header[0].length = sizeof( vim_clip );
135 clip_header[0].data = vim_clip;
137 STRNCPY( clip_header[1].type, CLIP_TYPE_TEXT, 8 );
138 clip_header[1].length = len + 1;
139 clip_header[1].data = text_clip;
141 switch( type )
143 default: /* fallthrough to MLINE */
144 case MLINE: *vim_clip = 'L'; break;
145 case MCHAR: *vim_clip = 'C'; break;
146 #ifdef FEAT_VISUAL
147 case MBLOCK: *vim_clip = 'B'; break;
148 #endif
151 vim_strncpy( text_clip, str, len );
153 vim_clip[ 1 ] = NUL;
155 PhClipboardCopy( PhInputGroup( NULL ), 2, clip_header);
157 vim_free( text_clip );
159 vim_free( str );
161 #endif