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.
18 #if defined(FEAT_GUI_PHOTON)
19 int is_photon_available
;
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
;
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 */
42 if( is_photon_available
== TRUE
&& !gui
.in_use
)
46 /*****************************************************************************/
49 /* No support for owning the clipboard */
51 clip_mch_own_selection( VimClipboard
*cbd
)
57 clip_mch_lose_selection( VimClipboard
*cbd
)
62 clip_mch_request_selection( VimClipboard
*cbd
)
64 int type
= MLINE
, clip_length
= 0, is_type_set
= FALSE
;
66 PhClipHeader
*clip_header
;
67 char_u
*clip_text
= NULL
;
69 cbdata
= PhClipboardPasteStart( PhInputGroup( 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;
82 case 'B': type
= MBLOCK
; break;
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
);
109 clip_mch_set_selection( VimClipboard
*cbd
)
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
)
121 clip_get_selection( cbd
);
124 type
= clip_convert_selection( &str
, &len
, cbd
);
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
;
143 default: /* fallthrough to MLINE */
144 case MLINE
: *vim_clip
= 'L'; break;
145 case MCHAR
: *vim_clip
= 'C'; break;
147 case MBLOCK
: *vim_clip
= 'B'; break;
151 vim_strncpy( text_clip
, str
, len
);
155 PhClipboardCopy( PhInputGroup( NULL
), 2, clip_header
);
157 vim_free( text_clip
);