Пример #1
0
void
EditViewBase::slotTestClipboard()
{
    if (getClipboard()->isEmpty()) {
        RG_DEBUG << "EditViewBase::slotTestClipboard(): empty";
        leaveActionState("have_clipboard");
        leaveActionState("have_clipboard_single_segment");
    } else {
        RG_DEBUG << "EditViewBase::slotTestClipboard(): not empty";
        enterActionState("have_clipboard");
        if (getClipboard()->isSingleSegment()) {
            enterActionState("have_clipboard_single_segment");
        } else {
            leaveActionState("have_clipboard_single_segment");
        }
    }
}
GtkClipboard* PasteboardHelperGtk::getCurrentTarget(Frame* frame) const
{
    WebKitWebView* webView = webkit_web_frame_get_web_view(kit(frame));

    if (webkit_web_view_use_primary_for_paste(webView))
        return getPrimary(frame);
    else
        return getClipboard(frame);
}
Пример #3
0
void genericAction(char *tmpBuffer, int size, char c)
{
	if(isControl())
	{
		toggleControl();

		setPressedChar(c);

		// control character
		switch(c)
		{
			case 'x':// cut
				// make sure highlight bounds are correct
				if(beginHighlight == -1 || endHighlight == -1)
				{
					return;
				}

				if(beginHighlight > endHighlight)
				{
					quickSwap(&beginHighlight, &endHighlight);
				}

				// perform cut
				setClipboardRange(tmpBuffer, beginHighlight, endHighlight);
				removeText(tmpBuffer, size);
				moveKBCursorAbsolute(beginHighlight);

				// reset the edit mode
				clearFakeHighlight();
				select = 0;
				break;
			case 'c':// copy
				// make sure highlight bounds are correct
				if(beginHighlight == -1 || endHighlight == -1)
				{
					return;
				}

				if(beginHighlight > endHighlight)
				{
					quickSwap(&beginHighlight, &endHighlight);
				}

				// perform copy
				setClipboardRange(tmpBuffer, beginHighlight, endHighlight);

				// reset the edit mode
				clearFakeHighlight();
				select = 0;
				break;
			case 'v':// paste
				if(beginHighlight != -1 && endHighlight != -1)
				{
					if(beginHighlight > endHighlight)
					{
						quickSwap(&beginHighlight, &endHighlight);
					}

					// we need to overwrite, but first check to make sure we don't overdo it
					if(strlen(tmpBuffer) - (endHighlight - beginHighlight) + strlen(getClipboard()) > size)
					{
						// after removing the current text and adding the new text, we are going over the size
						return;
					}

					// remove the current text
					removeText(tmpBuffer, size);
					moveKBCursorAbsolute(beginHighlight);
					clearFakeHighlight();
					select = 0;

					// cursor is now where we want to add the new text
					// we know also that there is enough room, so just insert the text

					// ensure we are inserting, even if overwrite
					uint16 tInsert = insert;
					insert = 1;

					char *tAdd = getClipboard();

					// loop and add chars
					while(*tAdd != 0)
					{
						insertChar(tmpBuffer, size, *tAdd);
						tAdd++;
					}

					// reset insert
					insert = tInsert;
				}
				else
				{
					if(strlen(tmpBuffer) + strlen(getClipboard()) > size)
					{
						// after adding the new text, we are going over the size
						return;
					}

					clearFakeHighlight();
					select = 0;

					// add the text
					char *tAdd = getClipboard();

					// loop and add chars
					while(*tAdd != 0)
					{
						insertChar(tmpBuffer, size, *tAdd);
						tAdd++;
					}
				}

				break;
		}
	}
	else
	{
		if(getKBCursor() < 0)
		{
			moveKBCursorAbsolute(0);
		}
		else if(getKBCursor() >= size)
		{
			moveKBCursorAbsolute(size - 1);
		}

		if(beginHighlight != -1 && endHighlight != -1)
		{
			if(beginHighlight > endHighlight)
			{
				quickSwap(&beginHighlight, &endHighlight);
			}

			// we have to clear out the data before performing the action
			removeText(tmpBuffer, size);

			// move the cursor
			moveKBCursorAbsolute(beginHighlight);

			// reset the edit mode
			clearFakeHighlight();
			select = 0;

			if(c == BSP || c == DEL)
			{
				// we've done the work required, exit

				return;
			}
		}

		if(c == BSP)
		{
			// backspace
			if(getKBCursor() == 0) // handle backspacing nothing
			{
				return;
			}

			int z;
			for(z=getKBCursor()-1;z<=size;z++)
			{
				tmpBuffer[z] = tmpBuffer[z+1];
			}

			moveKBCursorRelative(CURSOR_BACKWARD);
		}
		else if(c == DEL)
		{
			// del
			if(tmpBuffer[getKBCursor()] == 0) // handle deleting nothing
			{
				return;
			}

			moveKBCursorRelative(CURSOR_FORWARD);

			int z;
			for(z=getKBCursor()-1;z<=size;z++)
			{
				tmpBuffer[z] = tmpBuffer[z+1];
			}

			moveKBCursorRelative(CURSOR_BACKWARD);
		}
		else
		{
			// normal add
			insertChar(tmpBuffer, size, c);
		}

		tmpBuffer[size] = 0;
	}
}
void ofxTextInputField::keyPressed(ofKeyEventArgs& args) {
	//ew: add charachter (non unicode sorry!)
	//jg: made a step closer to this with swappable renderers and ofxFTGL -- but need unicode text input...
	lastTimeCursorMoved = ofGetElapsedTimef();
	int key = args.key;
	
	
    if(key == OF_KEY_SHIFT) {
        isShifted = true;
    }
    
    if(key == 4352) {
        isCommand = true;
    }
	
    #ifdef USE_GLFW_CLIPBOARD
    if(key == 'c' && isCommand ) {
        setClipboard(text.substr(selectionBegin, selectionEnd - selectionBegin));
        return;
    }
	
    if(key == 'v' && isCommand ) {
        text.insert(cursorPosition, getClipboard());
        return;
    }
	#endif
    
	if ((key >=32 && key <=126) || key=='\t' || key==OF_KEY_RETURN) {
		if(selecting) {
			text.erase(text.begin() + selectionBegin,
					   text.begin() + selectionEnd
					   );
			cursorPosition = selectionBegin;
			selecting = false;
		}
	}
			
			
	if (key == OF_KEY_RETURN) {
		if(!multiline) {
			endEditing();
			return;
		}
		text.insert(text.begin()+cursorPosition, '\n');
		cursorPosition++;
		

		if(autoTab) {
			// how much whitespace is there on the previous line?
			int xx, yy;
			getCursorCoords(cursorPosition, xx, yy);
			vector<string> lines = ofSplitString(text, "\n");
			if(yy>0) {
				
				// collect all the whitespace on the previous line.
				string previousWhitespace = "";
				string previousLine = lines[yy-1];
				int pos = 0;
				for(int i = 0; i < previousLine.size(); i++) {
					if(previousLine[i]==' ' || previousLine[i]=='\t') {
						previousWhitespace += previousLine[i];
					} else {
						break;
					}
				}
				// if we have a curly brace as the last char on the previous line
				// increase the indentation
				if(previousLine[previousLine.size()-1]=='{') {
					if(previousWhitespace=="") {
						previousWhitespace = "\t";
					} else {
						previousWhitespace += previousWhitespace[previousWhitespace.size()-1];
					}
				}
				text = text.insert(cursorPosition, previousWhitespace);
				cursorPosition += previousWhitespace.size();
			}
		}

        return;
	}
	
	if ((key >=32 && key <=126) || key=='\t') {
        
        if(isShifted) {
            
            char toInsert;
            if( !(key > 96 && key < 123) && !(key > 65 && key < 90) && shiftMap.find(key) != shiftMap.end() ) {
                toInsert = shiftMap[key];//toInsert = key - 32;
            } else {
                toInsert = key;
            }
            
            text.insert(text.begin()+cursorPosition, toInsert);
        } else {
            text.insert(text.begin()+cursorPosition, key);
        }
		cursorPosition++;
	}
	
	
	if (key==OF_KEY_BACKSPACE) {
		if(selecting) {
			text.erase(text.begin() + selectionBegin,
					   text.begin() + selectionEnd
			);
			cursorPosition = selectionBegin;
			selecting = false;
		} else {
			if (cursorPosition>0) {
				text.erase(text.begin()+cursorPosition-1);
				--cursorPosition;
			}
		}
	}
	
	if (key==OF_KEY_DEL) {
		if(selecting) {
			text.erase(text.begin() + selectionBegin,
					   text.begin() + selectionEnd
					   );
			cursorPosition = selectionBegin;
			selecting = false;
		} else {
			if (text.size() > cursorPosition) {
				text.erase(text.begin()+cursorPosition);
			}
		}
	}
	
	if (key==OF_KEY_LEFT){
		if(selecting) {
			cursorPosition = selectionBegin;
			selecting = false;
			
		} else {
			if (cursorPosition>0){
				--cursorPosition;
			}
		}
	}
	
	
	
	if (key==OF_KEY_RIGHT){
		if(selecting) {
			cursorPosition = selectionEnd;
			selecting = false;
		} else {
			if (cursorPosition<text.size()){
				++cursorPosition;
			}
		}
	}
	
	
	if (key==OF_KEY_UP){
		if(selecting) {
			cursorPosition = selectionBegin;
			selecting = false;
			
		} else {
			if (cursorPosition>0) {
				int xx, yy;
				getCursorCoords(cursorPosition, xx, yy);
				if(yy>0) {
					yy--;
					vector<string> lines = ofSplitString(text, "\n");
					xx = MIN(lines[yy].size()-1, xx);
					cursorPosition = xx;
					for(int i = 0; i < yy; i++) cursorPosition += lines[i].size()+1;
					printf("Cursor position: %d\n", cursorPosition);
				} else {
					cursorPosition = 0;
				}
			}
		}
	}
	
	
	
	if (key==OF_KEY_DOWN){
		if(selecting) {
			cursorPosition = selectionEnd;
			selecting = false;
		} else {
			int xx, yy;
			getCursorCoords(cursorPosition, xx, yy);
			vector<string> lines = ofSplitString(text, "\n");
			yy++;
			if(yy<lines.size()-1) {
				
				xx = MIN(lines[yy].size()-1, xx);
				cursorPosition = xx;
				for(int i = 0; i < yy; i++) cursorPosition += lines[i].size()+1;
				printf("Cursor position: %d\n", cursorPosition);
			} else {
				cursorPosition = text.size()-1;
			}
		}
	}
	
	
	
	
}
Пример #5
0
GtkClipboard* PasteboardHelper::getCurrentClipboard(Frame* frame)
{
    if (usePrimarySelectionClipboard(widgetFromFrame(frame)))
        return getPrimarySelectionClipboard(frame);
    return getClipboard(frame);
}
Пример #6
0
void Run()
{
    char octaveWindowName[255];
    char *runCommand = (char*) malloc(strlen(in) + 1);

    SKIP_SPACES;
    int bytesRead;
    sscanf(in, "%[^\n]%n", octaveWindowName, &bytesRead);
    in += bytesRead + 1; // +1 is for \n

    sscanf(in, "%[^\0]", runCommand);

    // Find Octave window
    HWND octaveWindow = getOctaveWindow(octaveWindowName);
    if (!octaveWindow)
    {
        sprintf(output, "echo 'Octavim: Octave window not found. Is Octave running?'");
        return;
    }
    
    // Save current focused window (we will return the focus to it later)
    HWND currentWindow = GetForegroundWindow();
    
    // Save clipboard contents.
    char *oldClipboard = getClipboard();
    if (!oldClipboard)
    {
        sprintf(output, "echo 'Octavim: could not get current clipboard contents!'");
        return;
    }
    
    // Change clipboard contents to the run command call.
    if (!setClipboard(runCommand))
    {
        sprintf(output, "echo 'Octavim: could not set clipboard contents!'");
        return;
    }

    // Bring Octave windows to Focus
    SetForegroundWindow(octaveWindow);

    // Send CTRL+V to paste the run command and press ENTER
    int controlPressed = GetAsyncKeyState(VK_CONTROL);
    if (controlPressed)
        keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_CONTROL, 0, 0, 0);
    keybd_event('V', 0, 0, 0);
    keybd_event('V', 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
    if (controlPressed)
        keybd_event(VK_CONTROL, 0, 0, 0);

    // Give Octave some time to process the request
    Sleep(200);

    // Restore old clibboard contents.
    setClipboard(oldClipboard);

    // Let's return the focus to VIM
    SetForegroundWindow(currentWindow);
}