| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | /* vi:set ts=8 sts=4 sw=4:
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * VIM - Vi IMproved	by Bram Moolenaar | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * QNX port by Julian Kinraid | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Do ":help uganda"  in Vim to read copying and usage conditions. | 
					
						
							|  |  |  |  * Do ":help credits" in Vim to see a list of people who contributed. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * os_qnx.c | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "vim.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(FEAT_GUI_PHOTON)
 | 
					
						
							|  |  |  | int is_photon_available; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qnx_init() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if defined(FEAT_GUI_PHOTON)
 | 
					
						
							|  |  |  |     PhChannelParms_t parms; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     memset(&parms, 0, sizeof(parms)); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     parms.flags = Ph_DYNAMIC_BUFFER; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     is_photon_available = (PhAttach(NULL, &parms) != NULL) ? TRUE : FALSE; | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if (defined(FEAT_GUI_PHOTON) && defined(FEAT_CLIPBOARD)) || defined(PROTO)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define CLIP_TYPE_VIM "VIMTYPE"
 | 
					
						
							|  |  |  | #define CLIP_TYPE_TEXT "TEXT"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Turn on the clipboard for a console vim when photon is running */ | 
					
						
							|  |  |  | void qnx_clip_init() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     if (is_photon_available == TRUE && !gui.in_use) | 
					
						
							|  |  |  | 	clip_init(TRUE); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Clipboard */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* No support for owning the clipboard */ | 
					
						
							|  |  |  | int | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | clip_mch_own_selection(VimClipboard *cbd) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | clip_mch_lose_selection(VimClipboard *cbd) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | clip_mch_request_selection(VimClipboard *cbd) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int		    type = MLINE, clip_length = 0, is_type_set = FALSE; | 
					
						
							|  |  |  |     void	    *cbdata; | 
					
						
							|  |  |  |     PhClipHeader    *clip_header; | 
					
						
							|  |  |  |     char_u	    *clip_text = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     cbdata = PhClipboardPasteStart(PhInputGroup(NULL)); | 
					
						
							|  |  |  |     if (cbdata != NULL) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     { | 
					
						
							|  |  |  | 	/* Look for the vim specific clip first */ | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM); | 
					
						
							|  |  |  | 	if (clip_header != NULL && clip_header->data != NULL) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    switch(*(char *) clip_header->data) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 		default: /* fallthrough to line type */ | 
					
						
							|  |  |  | 		case 'L': type = MLINE; break; | 
					
						
							|  |  |  | 		case 'C': type = MCHAR; break; | 
					
						
							|  |  |  | #ifdef FEAT_VISUAL
 | 
					
						
							|  |  |  | 		case 'B': type = MBLOCK; break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	    is_type_set = TRUE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Try for just normal text */ | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_TEXT); | 
					
						
							|  |  |  | 	if (clip_header != NULL) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	    clip_text = clip_header->data; | 
					
						
							|  |  |  | 	    clip_length  = clip_header->length - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    if (clip_text != NULL && is_type_set == FALSE) | 
					
						
							| 
									
										
										
										
											2011-06-19 01:14:29 +02:00
										 |  |  | 		type = MAUTO; | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	if ((clip_text != NULL) && (clip_length > 0)) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    clip_yank_selection(type, clip_text, clip_length, cbd); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	PhClipboardPasteFinish(cbdata); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | clip_mch_set_selection(VimClipboard *cbd) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int type; | 
					
						
							|  |  |  |     long_u  len; | 
					
						
							|  |  |  |     char_u *text_clip, vim_clip[2], *str = NULL; | 
					
						
							|  |  |  |     PhClipHeader clip_header[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Prevent recursion from clip_get_selection() */ | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     if (cbd->owned == TRUE) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cbd->owned = TRUE; | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     clip_get_selection(cbd); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     cbd->owned = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     type = clip_convert_selection(&str, &len, cbd); | 
					
						
							|  |  |  |     if (type >= 0) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	text_clip = lalloc(len + 1, TRUE); /* Normal text */ | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	if (text_clip && vim_clip) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    memset(clip_header, 0, sizeof(clip_header)); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    STRNCPY(clip_header[0].type, CLIP_TYPE_VIM, 8); | 
					
						
							|  |  |  | 	    clip_header[0].length = sizeof(vim_clip); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	    clip_header[0].data   = vim_clip; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    STRNCPY(clip_header[1].type, CLIP_TYPE_TEXT, 8); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	    clip_header[1].length = len + 1; | 
					
						
							|  |  |  | 	    clip_header[1].data   = text_clip; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    switch(type) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 		default: /* fallthrough to MLINE */ | 
					
						
							|  |  |  | 		case MLINE:	*vim_clip = 'L'; break; | 
					
						
							|  |  |  | 		case MCHAR:	*vim_clip = 'C'; break; | 
					
						
							|  |  |  | #ifdef FEAT_VISUAL
 | 
					
						
							|  |  |  | 		case MBLOCK:	*vim_clip = 'B'; break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    vim_strncpy(text_clip, str, len); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	    vim_clip[ 1 ] = NUL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	    PhClipboardCopy(PhInputGroup(NULL), 2, clip_header); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  | 	vim_free(text_clip); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-21 19:50:05 +02:00
										 |  |  |     vim_free(str); | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 |