void SplitView::split(BufferView* view, Qt::Orientation orientation) { if (view) { QSplitter* container = qobject_cast<QSplitter*>(view->parentWidget()); if (container) { int index = container->indexOf(view); BufferView* bv = 0; const int size = (orientation == Qt::Horizontal ? container->width() : container->height()) - container->handleWidth(); if (container->count() == 1 || container->orientation() == orientation) { container->setOrientation(orientation); bv = createBufferView(container, index + 1); QList<int> sizes; for (int i = 0; i < container->count(); ++i) sizes += size / container->count(); container->setSizes(sizes); } else if (index != -1) { QList<int> sizes = container->sizes(); QSplitter* splitter = wrap(view, orientation); if (splitter) { container->setSizes(sizes); bv = createBufferView(splitter); splitter->setSizes(QList<int>() << size/2 << size/2); } } if (bv) { bv->setBuffer(view->buffer()); emit viewAdded(bv); } } } }
void cmd_util::fetch(Executable *peExe, offset_t offset, Executable::addr_type aType, bool hex) { offset = peExe->toRaw(offset, aType); if (offset == INVALID_ADDR) { std::cerr << "ERROR: Invalid Address suplied" << endl; return; } BufferView *sub = new BufferView(peExe, offset, 100); if (sub->getContent() == NULL) { cout << "Cannot fetch" << endl; delete sub; return; } AbstractFormatter *formatter = NULL; std::string separator = " "; if (hex) formatter = new HexFormatter(sub); else { formatter = new Formatter(sub); separator = ""; } cout << "Fetched:" << endl; for (bufsize_t i = 0; i < sub->getContentSize(); i++) { printf("%s%s", (*formatter)[i].toStdString().c_str(), separator.c_str()); } putchar('\n'); delete formatter; delete sub; }
int VSpace::inPixels(BufferView const & bv) const { // Height of a normal line in pixels (zoom factor considered) int const default_height = defaultRowHeight(); switch (kind_) { case DEFSKIP: return bv.buffer().params().getDefSkip().inPixels(bv); // This is how the skips are normally defined by LateX. // But there should be some way to change this per document. case SMALLSKIP: return default_height / 4; case MEDSKIP: return default_height / 2; case BIGSKIP: return default_height; case VFILL: // leave space for the vfill symbol return 3 * default_height; case LENGTH: return len_.len().inPixels(bv.workWidth()); default: LATTEST(false); // fall through in release mode } return 0; }
void sample_primary_rays(const Camera &camera, const BufferView<CameraSample> &samples, BufferView<Ray> rays, BufferView<RayDifferential> ray_differentials, bool use_gpu) { parallel_for(primary_ray_sampler{ camera, samples.begin(), rays.begin(), ray_differentials.begin()}, samples.size(), use_gpu); }
void update_active_pixels(const BufferView<int> &active_pixels, const BufferView<Intersection> &isects, BufferView<int> &new_active_pixels, bool use_gpu) { auto op = is_valid_intersection{isects.begin()}; auto new_end = DISPATCH(use_gpu, thrust::copy_if, active_pixels.begin(), active_pixels.end(), new_active_pixels.begin(), op); new_active_pixels.count = new_end - new_active_pixels.begin(); }
/** Copy selected elements from bv's BufferParams to the dest_bv's one ** We don't want to copy'em all, e.g., not the default master **/ static void copy_params(BufferView const & bv, BufferView & dest_bv) { Buffer const & doc_buf = bv.buffer(); BufferParams const & doc_bp = doc_buf.params(); string const & lang = doc_bp.language->lang(); string const & doc_class = doc_bp.documentClass().name(); Buffer & dest_buf = dest_bv.buffer(); dest_buf.params().setLanguage(lang); dest_buf.params().setBaseClass(doc_class); dest_buf.params().makeDocumentClass(); dest_bv.cursor().current_font.setLanguage(doc_bp.language); }
void CommandBuffer::set_buffer_view(unsigned set, unsigned binding, const BufferView &view) { VK_ASSERT(set < VULKAN_NUM_DESCRIPTOR_SETS); VK_ASSERT(binding < VULKAN_NUM_BINDINGS); VK_ASSERT(view.get_buffer().get_create_info().usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT); if (view.get_cookie() == cookies[set][binding]) return; auto &b = bindings[set][binding]; b.buffer_view = view.get_view(); cookies[set][binding] = view.get_cookie(); dirty_sets |= 1u << set; }
void GuiSpellchecker::check() { LYXERR(Debug::GUI, "Check the spelling of a word"); DocIterator from = bufferview()->cursor(); DocIterator to; WordLangTuple word_lang; docstring_list suggestions; int progress; try { progress = buffer().spellCheck(from, to, word_lang, suggestions); } catch (ExceptionMessage const & message) { if (message.type_ == WarningException) { Alert::warning(message.title_, message.details_); close(); return; } throw message; } LYXERR(Debug::GUI, "Found word \"" << word_lang.word() << "\""); d->count_ += progress; d->progress_ += progress; // end of document if (from == doc_iterator_end(&buffer())) { showSummary(); return; } if (!isVisible()) show(); d->word_ = word_lang; int const progress_bar = d->total_ ? int(100.0 * float(d->progress_)/d->total_) : 100; LYXERR(Debug::GUI, "Updating spell progress."); // set progress bar d->ui.spellcheckPR->setValue(progress_bar); // set suggestions updateSuggestions(suggestions); // set language int const pos = d->ui.languageCO->findData(toqstr(word_lang.lang()->lang())); if (pos != -1) d->ui.languageCO->setCurrentIndex(pos); // FIXME: if we used a lfun like in find/replace, dispatch would do // that for us int const size = to.pos() - from.pos(); BufferView * bv = const_cast<BufferView *>(bufferview()); bv->putSelectionAt(from, size, false); }
int ParagraphMetrics::rightMargin(BufferView const & bv) const { BufferParams const & params = bv.buffer().params(); DocumentClass const & tclass = params.documentClass(); frontend::FontMetrics const & fm = theFontMetrics(params.getFont()); int const r_margin = bv.rightMargin() + fm.signedWidth(tclass.rightmargin()) + fm.signedWidth(par_->layout().rightmargin) * 4 / (par_->getDepth() + 4); return r_margin; }
bool SpellcheckerWidget::initialiseParams(std::string const &) { BufferView * bv = d->gv_->documentBufferView(); if (bv == 0) return false; std::set<Language const *> languages = bv->buffer().masterBuffer()->getLanguages(); if (!languages.empty()) d->setLanguage(*languages.begin()); d->start_ = DocIterator(); d->wrapAround(false); d->canCheck(); return true; }
int HSpace::inPixels(BufferView const & bv) const { switch (kind_) { case DEFAULT: // FIXME: replace by correct length return bv.buffer().params().getIndentation().inPixels(bv); case LENGTH: return len_.len().inPixels(bv.workWidth()); default: LATTEST(false); // fall through in release mode } return 0; }
docstring InsetCitation::toolTip(BufferView const & bv, int, int) const { Buffer const & buf = bv.buffer(); // Only after the buffer is loaded from file... if (!buf.isFullyLoaded()) return docstring(); BiblioInfo const & bi = buf.masterBibInfo(); if (bi.empty()) return _("No bibliography defined!"); docstring const & key = getParam("key"); if (key.empty()) return _("No citations selected!"); vector<docstring> keys = getVectorFromString(key); vector<docstring>::const_iterator it = keys.begin(); vector<docstring>::const_iterator en = keys.end(); docstring tip; for (; it != en; ++it) { docstring const key_info = bi.getInfo(*it, buffer()); if (key_info.empty()) continue; if (!tip.empty()) tip += "\n"; tip += wrap(key_info, -4); } return tip; }
void SpellcheckerWidget::Private::hide() const { BufferView * bv = gv_->documentBufferView(); Cursor & bvcur = bv->cursor(); dv_->hide(); if (isCurrentBuffer(bvcur)) { if (!begin_.empty() && !end_.empty()) { // restore previous selection setSelection(begin_, end_); } else { // restore cursor position bvcur.setCursor(start_); bvcur.clearSelection(); bv->processUpdateFlags(Update::Force | Update::FitCursor); } } }
Dimension const InsetText::dimension(BufferView const & bv) const { TextMetrics const & tm = bv.textMetrics(&text_); Dimension dim = tm.dimension(); dim.wid += 2 * TEXT_TO_INSET_OFFSET; dim.des += TEXT_TO_INSET_OFFSET; dim.asc += TEXT_TO_INSET_OFFSET; return dim; }
void init_active_pixels(const BufferView<Ray> &rays, BufferView<int> &active_pixels, bool use_gpu, ThrustCachedAllocator &thrust_alloc) { assert(rays.size() == active_pixels.size()); DISPATCH(use_gpu, thrust::sequence, active_pixels.begin(), active_pixels.end()); auto op = is_invalid_ray{rays.begin()}; auto new_end = DISPATCH_CACHED(use_gpu, thrust_alloc, thrust::remove_if, active_pixels.begin(), active_pixels.end(), active_pixels.begin(), op); active_pixels.count = new_end - active_pixels.begin(); }
void SpellcheckerWidget::Private::setSelection( DocIterator const & from, DocIterator const & to) const { BufferView * bv = gv_->documentBufferView(); DocIterator end = to; if (from.pit() != end.pit()) { // there are multiple paragraphs in selection Cursor & bvcur = bv->cursor(); bvcur.setCursor(from); bvcur.clearSelection(); bvcur.setSelection(true); bvcur.setCursor(end); bvcur.setSelection(true); } else { // FIXME LFUN // If we used a LFUN, dispatch would do all of this for us int const size = end.pos() - from.pos(); bv->putSelectionAt(from, size, false); } bv->processUpdateFlags(Update::Force | Update::FitCursor); }
bool GuiErrorList::goTo(int item) { if (&buffer() != buf_) { if (!theBufferList().isLoaded(buf_)) return false; FuncRequest fr(LFUN_BUFFER_SWITCH, buf_->absFileName()); dispatch(fr); } ErrorItem const & err = errorList()[item]; if (err.par_id == -1) return false; if (from_master_) // FIXME: implement return false; DocIterator dit = buf_->getParFromID(err.par_id); if (dit == doc_iterator_end(buf_)) { // FIXME: Happens when loading a read-only doc with // unknown layout. Should this be the case? LYXERR0("par id " << err.par_id << " not found"); return false; } // Now make the selection. // if pos_end is 0, this means it is end-of-paragraph pos_type const s = dit.paragraph().size(); pos_type const end = err.pos_end ? min(err.pos_end, s) : s; pos_type const start = min(err.pos_start, end); pos_type const range = end - start; dit.pos() = start; BufferView * bv = const_cast<BufferView *>(bufferview()); // FIXME: If we used an LFUN, we would not need this line: bv->putSelectionAt(dit, range, false); bv->processUpdateFlags(Update::Force | Update::FitCursor); return true; }
void InsetText::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const { x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET; y = bv.textMetrics(&text_).cursorY(sl, boundary); }
void accumulate_roughness(const Scene &scene, const BufferView<DTexture1> &d_roughness_texs, BufferView<DMaterial> d_materials) { parallel_for(roughness_accumulator{d_roughness_texs.begin(), d_materials.begin()}, d_roughness_texs.size(), scene.use_gpu); }
void SpellcheckerWidget::Private::check() { BufferView * bv = gv_->documentBufferView(); if (!bv || bv->buffer().text().empty()) return; fixPositionsIfBroken(); SpellChecker * speller = theSpellChecker(); if (speller && !speller->hasDictionary(bv->buffer().language())) { int dsize = speller->numDictionaries(); if (0 == dsize) { hide(); QMessageBox::information(p, qt_("Spell Checker"), qt_("Spell checker has no dictionaries.")); return; } } DocIterator from = bv->cursor(); DocIterator to = isCurrentBuffer(from) ? end_ : doc_iterator_end(&bv->buffer()); WordLangTuple word_lang; docstring_list suggestions; LYXERR(Debug::GUI, "Spellchecker: start check at " << from); try { bv->buffer().spellCheck(from, to, word_lang, suggestions); } catch (ExceptionMessage const & message) { if (message.type_ == WarningException) { Alert::warning(message.title_, message.details_); return; } throw message; } // end of document or selection? if (atLastPos(from)) { if (isWrapAround()) { hide(); return; } if (continueFromBeginning()) check(); return; } if (isWrapAround(from)) { hide(); return; } word_ = word_lang; // set suggestions updateSuggestions(suggestions); // set language if (!word_lang.lang()) return; setLanguage(word_lang.lang()); // mark misspelled word setSelection(from, to); }
bool Inset::covers(BufferView const & bv, int x, int y) const { return bv.coordCache().getInsets().covers(this, x, y); }
void accumulate_specular(const Scene &scene, const BufferView<DTexture3> &d_specular_texs, BufferView<DMaterial> d_materials) { parallel_for(specular_accumulator{d_specular_texs.begin(), d_materials.begin()}, d_specular_texs.size(), scene.use_gpu); }
int Inset::yo(BufferView const & bv) const { return bv.coordCache().getInsets().y(this); }
Dimension const Inset::dimension(BufferView const & bv) const { return bv.coordCache().getInsets().dim(this); }
void GuiSearch::wrap_dispatch(const FuncRequest & func, bool forward) { dispatch(func); BufferView * bv = const_cast<BufferView *>(bufferview()); if (!bv->cursor().result().dispatched()) { GuiView & lv = *const_cast<GuiView *>(&lyxview()); DocIterator cur_orig(bv->cursor()); docstring q; if (forward) q = _("End of file reached while searching forward.\n" "Continue searching from the beginning?"); else q = _("Beginning of file reached while searching backward.\n" "Continue searching from the end?"); int wrap_answer = frontend::Alert::prompt(_("Wrap search?"), q, 0, 1, _("&Yes"), _("&No")); if (wrap_answer == 0) { if (forward) { bv->cursor().clear(); bv->cursor().push_back(CursorSlice(bv->buffer().inset())); } else { bv->cursor().setCursor(doc_iterator_end(&bv->buffer())); bv->cursor().backwardPos(); } bv->clearSelection(); dispatch(func); if (bv->cursor().result().dispatched()) return; } bv->cursor().setCursor(cur_orig); lv.message(_("String not found.")); } }
void GuiCompleter::tab() { BufferView * bv = &gui_->bufferView(); Cursor cur = bv->cursor(); cur.screenUpdateFlags(Update::None); // check that inline completion is active if (!inlineVisible() && !uniqueCompletionAvailable()) { // try to activate the inline completion if (cur.inset().inlineCompletionSupported(cur)) { showInline(); // show popup without delay because the completion was not unique if (lyxrc.completion_popup_after_complete && !popupVisible() && popup()->model()->rowCount() > 1) popup_timer_.start(0); return; } // or try popup if (!popupVisible() && cur.inset().completionSupported(cur)) { showPopup(); return; } return; } // Make undo possible cur.recordUndo(); // If completion is active, at least complete by one character docstring prefix = cur.inset().completionPrefix(cur); docstring completion = qstring_to_ucs4(currentCompletion()); if (completion.size() <= prefix.size()) { // finalize completion cur.inset().insertCompletion(cur, docstring(), true); // hide popup and inline completion hidePopup(cur); hideInline(cur); updateVisibility(false, false); return; } docstring nextchar = completion.substr(prefix.size(), 1); if (!cur.inset().insertCompletion(cur, nextchar, false)) return; updatePrefix(cur); // try to complete as far as it is unique docstring longestCompletion = longestUniqueCompletion(); prefix = cur.inset().completionPrefix(cur); docstring postfix = longestCompletion.substr(min(longestCompletion.size(), prefix.size())); cur.inset().insertCompletion(cur, postfix, false); old_cursor_ = bv->cursor(); updatePrefix(cur); // show popup without delay because the completion was not unique if (lyxrc.completion_popup_after_complete && !popupVisible() && popup()->model()->rowCount() > 1) popup_timer_.start(0); // redraw if needed if (cur.result().update()) gui_->bufferView().processUpdateFlags(cur.result().update()); }
/// Return true if a match was found bool FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt, bool replace_all) { BufferView * bv = view_.documentBufferView(); if (!bv) return false; Buffer * buf = &bv->buffer(); Buffer * buf_orig = &bv->buffer(); DocIterator cur_orig(bv->cursor()); int wrap_answer = -1; ostringstream oss; oss << opt; FuncRequest cmd(LFUN_WORD_FINDADV, from_utf8(oss.str())); view_.setBusy(true); if (opt.scope == FindAndReplaceOptions::S_ALL_MANUALS) { vector<string> const & v = allManualsFiles(); if (std::find(v.begin(), v.end(), buf->absFileName()) == v.end()) { FileName const & fname = FileName(*v.begin()); if (!theBufferList().exists(fname)) { guiApp->currentView()->setBusy(false); guiApp->currentView()->loadDocument(fname, false); guiApp->currentView()->setBusy(true); } buf = theBufferList().getBuffer(fname); lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, buf->absFileName())); bv = view_.documentBufferView(); bv->cursor().clear(); bv->cursor().push_back(CursorSlice(buf->inset())); } } do { LYXERR(Debug::FIND, "Dispatching LFUN_WORD_FINDADV"); dispatch(cmd); LYXERR(Debug::FIND, "dispatched"); if (bv->cursor().result().dispatched()) { // New match found and selected (old selection replaced if needed) if (replace_all) continue; view_.setBusy(false); return true; } // No match found in current buffer (however old selection might have been replaced) // select next buffer in scope, if any bool prompt = nextPrevBuffer(buf, opt); if (prompt) { if (wrap_answer != -1) break; docstring q = getQuestionString(opt); view_.setBusy(false); wrap_answer = frontend::Alert::prompt( _("Wrap search?"), q, 0, 1, _("&Yes"), _("&No")); view_.setBusy(true); if (wrap_answer == 1) break; } if (buf != &view_.documentBufferView()->buffer()) lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, buf->absFileName())); bv = view_.documentBufferView(); if (opt.forward) { bv->cursor().clear(); bv->cursor().push_back(CursorSlice(buf->inset())); } else { //lyx::dispatch(FuncRequest(LFUN_BUFFER_END)); bv->cursor().setCursor(doc_iterator_end(buf)); bv->cursor().backwardPos(); LYXERR(Debug::FIND, "findBackAdv5: cur: " << bv->cursor()); } bv->clearSelection(); } while (wrap_answer != 1); if (buf_orig != &view_.documentBufferView()->buffer()) lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, buf_orig->absFileName())); bv = view_.documentBufferView(); // This may happen after a replace occurred if (cur_orig.pos() > cur_orig.lastpos()) cur_orig.pos() = cur_orig.lastpos(); bv->cursor().setCursor(cur_orig); view_.setBusy(false); return false; }
void SplitView::setCurrentBuffer(IrcBuffer* buffer) { BufferView* view = currentView(); if (view) view->setBuffer(buffer); }
DocIterator const SpellcheckerWidget::Private::cursor() const { BufferView * bv = gv_->documentBufferView(); return bv ? bv->cursor() : DocIterator(); }