ButtonConfig* ButtonConfig::create(string text, ButtonCallback callback) { ButtonConfig *pRet = new ButtonConfig(text, callback); if (pRet && pRet->init()) { pRet->autorelease(); return pRet; } else { delete pRet; pRet = NULL; return NULL; } }
static bool change_tool(Settings* settings, GdkEventButton* event, GtkXournal* xournal) { ButtonConfig* cfg = NULL; ButtonConfig* cfgTouch = settings->getTouchButtonConfig(); ToolHandler* h = xournal->view->getControl()->getToolHandler(); if (event->button == 2) // Middle Button { cfg = settings->getMiddleButtonConfig(); } else if (event->button == 3 && !xournal->selection) // Right Button { cfg = settings->getRightButtonConfig(); } else if (event->device->source == GDK_SOURCE_ERASER) { cfg = settings->getEraserButtonConfig(); } else if (cfgTouch->device == event->device->name) { cfg = cfgTouch; // If an action is defined we do it, even if it's a drawing action... if (cfg->getDisableDrawing() && cfg->getAction() == TOOL_NONE) { ToolType tool = h->getToolType(); if (tool == TOOL_PEN || tool == TOOL_ERASER || tool == TOOL_HILIGHTER) { printf("ignore touchscreen for drawing!\n"); return true; } } } if (cfg && cfg->getAction() != TOOL_NONE) { h->copyCurrentConfig(); cfg->acceptActions(h); } return false; }
gboolean gtk_xournal_button_press_event(GtkWidget * widget, GdkEventButton * event) { /** * true: Core event, false: XInput event */ gboolean isCore = (event->device == gdk_device_get_core_pointer()); INPUTDBG("ButtonPress (%s) (x,y)=(%.2f,%.2f), button %d, modifier %x, isCore %i", gdk_device_get_name(event->device), event->x, event->y, event->button, event->state, isCore); GtkXournal * xournal = GTK_XOURNAL(widget); Settings * settings = xournal->view->getControl()->getSettings(); if(isCore && settings->isXinputEnabled() && settings->isIgnoreCoreEvents()) { INPUTDBG2("gtk_xournal_button_press_event return false (ignore core)"); return false; } XInputUtils::fixXInputCoords((GdkEvent*) event, widget); if (event->type != GDK_BUTTON_PRESS) { INPUTDBG2("gtk_xournal_button_press_event return false (event->type != GDK_BUTTON_PRESS)"); return false; // this event is not handled here } if (event->button > 3) { // scroll wheel events XInputUtils::handleScrollEvent(event, widget); INPUTDBG2("gtk_xournal_button_press_event return true handled scroll event"); return true; } gtk_widget_grab_focus(widget); ToolHandler * h = xournal->view->getControl()->getToolHandler(); // none button release event was sent, send one now if (xournal->currentInputPage) { INPUTDBG2("gtk_xournal_button_press_event (xournal->currentInputPage != NULL)"); GdkEventButton ev = *event; xournal->currentInputPage->translateEvent((GdkEvent*) &ev, xournal->x, xournal->y); xournal->currentInputPage->onButtonReleaseEvent(widget, &ev); } // Change the tool depending on the key or device ButtonConfig * cfg = NULL; ButtonConfig * cfgTouch = settings->getTouchButtonConfig(); if (event->button == 2) { // Middle Button cfg = settings->getMiddleButtonConfig(); } else if (event->button == 3) { // Right Button cfg = settings->getRightButtonConfig(); } else if (event->device->source == GDK_SOURCE_ERASER) { cfg = settings->getEraserButtonConfig(); } else if (cfgTouch->device == event->device->name) { cfg = cfgTouch; // If an action is defined we do it, even if it's a drawing action... if (cfg->getDisableDrawing() && cfg->getAction() == TOOL_NONE) { ToolType tool = h->getToolType(); if (tool == TOOL_PEN || tool == TOOL_ERASER || tool == TOOL_HILIGHTER) { printf("ignore touchscreen for drawing!\n"); return true; } } } if (cfg && cfg->getAction() != TOOL_NONE) { h->copyCurrentConfig(); cfg->acceptActions(h); } // hand tool don't change the selection, so you can scroll e.g. // with your touchscreen without remove the selection if (h->getToolType() == TOOL_HAND) { Cursor * cursor = xournal->view->getCursor(); cursor->setMouseDown(true); xournal->lastMousePositionX = 0; xournal->lastMousePositionY = 0; xournal->inScrolling = true; gtk_widget_get_pointer(widget, &xournal->lastMousePositionX, &xournal->lastMousePositionY); INPUTDBG2("gtk_xournal_button_press_event (h->getToolType() == TOOL_HAND) return true"); return true; } else if (xournal->selection) { EditSelection * selection = xournal->selection; PageView * view = selection->getView(); GdkEventButton ev = *event; view->translateEvent((GdkEvent*) &ev, xournal->x, xournal->y); CursorSelectionType selType = selection->getSelectionTypeForPos(ev.x, ev.y, xournal->view->getZoom()); if (selType) { xournal->view->getCursor()->setMouseDown(true); xournal->selection->mouseDown(selType, ev.x, ev.y); INPUTDBG2("gtk_xournal_button_press_event (selection) return true"); return true; } else { xournal->view->clearSelection(); } } PageView * pv = gtk_xournal_get_page_view_for_pos_cached(xournal, event->x, event->y); if (pv) { xournal->currentInputPage = pv; pv->translateEvent((GdkEvent*) event, xournal->x, xournal->y); INPUTDBG2("gtk_xournal_button_press_event (pv->onButtonPressEvent) return"); xournal->view->getDocument()->indexOf(pv->getPage()); return pv->onButtonPressEvent(widget, event); } INPUTDBG2("gtk_xournal_button_press_event (not handled) return false"); return false; // not handled }
/** * Change the tool according to the device and button * @return true to ignore event */ bool InputSequence::changeTool() { XOJ_CHECK_TYPE(InputSequence); Settings* settings = inputHandler->getSettings(); ButtonConfig* cfgTouch = settings->getTouchButtonConfig(); ToolHandler* h = inputHandler->getToolHandler(); GtkXournal* xournal = inputHandler->getXournal(); ButtonConfig* cfg = NULL; if (gdk_device_get_source(device) == GDK_SOURCE_PEN) { penDevice = true; if (button == 2) { cfg = settings->getStylusButton1Config(); } else if (button == 3) { cfg = settings->getStylusButton2Config(); } } else if (button == 2 /* Middle Button */ && !xournal->selection) { cfg = settings->getMiddleButtonConfig(); } else if (button == 3 /* Right Button */ && !xournal->selection) { cfg = settings->getRightButtonConfig(); } else if (gdk_device_get_source(device) == GDK_SOURCE_ERASER) { penDevice = true; cfg = settings->getEraserButtonConfig(); } else if (cfgTouch->device == gdk_device_get_name(device)) { cfg = cfgTouch; // If an action is defined we do it, even if it's a drawing action... if (cfg->getDisableDrawing() && cfg->getAction() == TOOL_NONE) { ToolType tool = h->getToolType(); if (tool == TOOL_PEN || tool == TOOL_ERASER || tool == TOOL_HILIGHTER) { g_message("ignore touchscreen for drawing!\n"); return true; } } } if (cfg && cfg->getAction() != TOOL_NONE) { h->copyCurrentConfig(); cfg->acceptActions(h); } else { h->restoreLastConfig(); } return false; }