+static size_t crcCheck(docstring const & s)
+{
+ boost::crc_32_type crc;
+ crc.process_bytes(&s[0], sizeof(char_type) * s.size());
+ return crc.checksum();
+}
+
+
+/** get the source code of selected paragraphs, or the whole document
+ \param fullSource get full source code
+ \return true if the content has changed since last call.
+ */
+static bool getContent(BufferView const * view, bool fullSource, QString & qstr)
+{
+ // get the *top* level paragraphs that contain the cursor,
+ // or the selected text
+ pit_type par_begin;
+ pit_type par_end;
+
+ if (!view->cursor().selection()) {
+ par_begin = view->cursor().bottom().pit();
+ par_end = par_begin;
+ } else {
+ par_begin = view->cursor().selectionBegin().bottom().pit();
+ par_end = view->cursor().selectionEnd().bottom().pit();
+ }
+ if (par_begin > par_end)
+ swap(par_begin, par_end);
+ odocstringstream ostr;
+ view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
+ docstring s = ostr.str();
+ static size_t crc = 0;
+ size_t newcrc = crcCheck(s);
+ if (newcrc == crc)
+ return false;
+ crc = newcrc;
+ qstr = toqstr(s);
+ return true;
+}
+
+
+void ViewSourceWidget::setBufferView(BufferView const * bv)
+{
+ bv_ = bv;
+ setEnabled(bv ? true : false);
+}
+
+