bool PageView::searchTextOnPage(const char * text, int * occures, double * top) { XOJ_CHECK_TYPE(PageView); if (this->search == NULL) { if (text == NULL) { return true; } int pNr = this->page.getPdfPageNr(); XojPopplerPage * pdf = NULL; if (pNr != -1) { Document * doc = xournal->getControl()->getDocument(); doc->lock(); pdf = doc->getPdfPage(pNr); doc->unlock(); } this->search = new SearchControl(page, pdf); } bool found = this->search->search(text, occures, top); repaintPage(); return found; }
void PageView::selectObjectAt(double x, double y) { XOJ_CHECK_TYPE(PageView); int selected = this->page.getSelectedLayerId(); GdkRectangle matchRect = { x - 10, y - 10, 20, 20 }; Stroke * strokeMatch = NULL; double gap = 1000000000; Element * elementMatch = NULL; // clear old selection anyway this->xournal->getControl()->clearSelection(); ListIterator<Layer*> it = this->page.layerIterator(); while (it.hasNext() && selected) { Layer * l = it.next(); ListIterator<Element *> eit = l->elementIterator(); while (eit.hasNext()) { Element * e = eit.next(); if (e->intersectsArea(&matchRect)) { if (e->getType() == ELEMENT_STROKE) { Stroke * s = (Stroke *) e; double tmpGap = 0; if (s->intersects(x, y, 5, &tmpGap)) { if (gap > tmpGap) { gap = tmpGap; strokeMatch = s; } } } else { elementMatch = e; } } } selected--; } if (strokeMatch) { elementMatch = strokeMatch; } if (elementMatch) { xournal->setSelection(new EditSelection(xournal->getControl()->getUndoRedoHandler(), elementMatch, this, page)); repaintPage(); } }
bool PageView::onButtonReleaseEvent(GtkWidget* widget, GdkEventButton* event) { XOJ_CHECK_TYPE(PageView); Control* control = xournal->getControl(); this->inputHandler->onButtonReleaseEvent(event, this->page); if (this->inEraser) { this->inEraser = false; Document* doc = this->xournal->getControl()->getDocument(); doc->lock(); this->eraser->finalize(); doc->unlock(); } if (this->verticalSpace) { MoveUndoAction* undo = this->verticalSpace->finalize(); delete this->verticalSpace; this->verticalSpace = NULL; control->getUndoRedoHandler()->addUndoAction(undo); } if (this->selection) { if (this->selection->finalize(this->page)) { xournal->setSelection(new EditSelection(control->getUndoRedoHandler(), this->selection, this)); delete this->selection; this->selection = NULL; } else { delete this->selection; this->selection = NULL; repaintPage(); } } else if (this->textEditor) { this->textEditor->mouseReleased(); } return false; }
bool PageView::onButtonPressEvent(GtkWidget * widget, GdkEventButton * event) { XOJ_CHECK_TYPE(PageView); if ((event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) != 0) { return false; // not handled here } if (!this->selected) { xournal->getControl()->firePageSelected(this->page); } ToolHandler * h = xournal->getControl()->getToolHandler(); double x = event->x; double y = event->y; if ((x < 0 || y < 0) && !extendedWarningDisplayd && settings->isXinputEnabled()) { GtkWidget * dialog = gtk_message_dialog_new((GtkWindow *) *xournal->getControl()->getWindow(), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_NONE, _("There was a wrong input event, input is not working.\nDo you want to disable \"Extended Input\"?")); gtk_dialog_add_button(GTK_DIALOG(dialog), "Disable \"Extended Input\"", 1); gtk_dialog_add_button(GTK_DIALOG(dialog), "Cancel", 2); this->extendedWarningDisplayd = true; gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(this->xournal->getControl()->getWindow()->getWindow())); if (gtk_dialog_run(GTK_DIALOG(dialog)) == 1) { settings->setXinputEnabled(false); xournal->updateXEvents(); } gtk_widget_destroy(dialog); return true; } double zoom = xournal->getZoom(); x /= zoom; y /= zoom; Cursor * cursor = xournal->getCursor(); cursor->setMouseDown(true); if (h->getToolType() == TOOL_PEN) { this->inputHandler->startStroke(event, STROKE_TOOL_PEN, x, y); } else if (h->getToolType() == TOOL_HILIGHTER) { this->inputHandler->startStroke(event, STROKE_TOOL_HIGHLIGHTER, x, y); } else if (h->getToolType() == TOOL_ERASER) { if (h->getEraserType() == ERASER_TYPE_WHITEOUT) { this->inputHandler->startStroke(event, STROKE_TOOL_ERASER, x, y); this->inputHandler->getTmpStroke()->setColor(0xffffff); // White } else { this->eraser->erase(x, y); this->inEraser = true; } } else if (h->getToolType() == TOOL_VERTICAL_SPACE) { this->verticalSpace = new VerticalToolHandler(this, this->page, y, zoom); } else if (h->getToolType() == TOOL_SELECT_RECT || h->getToolType() == TOOL_SELECT_REGION || h->getToolType() == TOOL_SELECT_OBJECT) { if (h->getToolType() == TOOL_SELECT_RECT) { if (this->selection) { delete this->selection; this->selection = NULL; repaintPage(); } this->selection = new RectSelection(x, y, this); } else if (h->getToolType() == TOOL_SELECT_REGION) { if (this->selection) { delete this->selection; this->selection = NULL; repaintPage(); } this->selection = new RegionSelect(x, y, this); } else if (h->getToolType() == TOOL_SELECT_OBJECT) { selectObjectAt(x, y); } } else if (h->getToolType() == TOOL_TEXT) { startText(x, y); } else if (h->getToolType() == TOOL_IMAGE) { ImageHandler imgHandler(xournal->getControl(), this); imgHandler.insertImage(x, y); } return true; }