Actually, I wanted to send this little-bit cleaner patch, sorry.

   T.

ps: lots of debugging stuff that I will remove at the end

Tommaso Cucinotta ha scritto:
Hi,

with the attached patch for the lyx-advsearch branch:

- The GuiView tracks the currentMainWorkArea()

- there is a visual highlight of the current main wa through a thick border; feel
 free to customize if you think it looks like ugly;

- now Esc, Enter and Shift+Enter are correctly intercepted by the container dialog
 by installing an eventFilter

- Search Buffer is added to theBufferList() like other buffers, so it is destroyed
 on program exit

- SearchWA is not destroyed by the GuiView::closeEvent() loop, but by its
own container, i.e., in the dialog destructor GuiSearchAdv::~GuiSearchAdv()

- I couldn't find a way to crash it, but I didn't play too much finding all the
 nested possible things close to borders or inset begins/ends etc...

- I really could not understand why the search workarea is focused in then
 immediately focused out when opening the dialog via C-S-f;
 for now, the correct focus may be obtained in various ways:
 - C-S-f, then click the search wa
 - C-S-f, then Tab
 - C-S-f, then Alt-Tab twice

- when the dialog opens up, the searchworkarea contents is again selected
entirely, so starting to type whatever (after a Tab for gaining focus) deletes
 the last search text

- there is also a little focus issue when closing the program with unsaved changed buffer: the dialog asking if I want to save is not focused; however,
 this is an issue in regular trunk as well. Specifically:
 - if I close via menu, then it is focused.
- if I close via Alt+F4 (Ubuntu/Gnome) or via the close `X' button on the top-right
 - window corner, then it is unfocused.

I hope Abdel has some clue on how to fix the focus issue (I read he's the Gui man).

Bye,

   T.

Index: src/lyxfindadv.cpp
===================================================================
--- src/lyxfindadv.cpp	(revisione 27242)
+++ src/lyxfindadv.cpp	(copia locale)
@@ -100,19 +100,19 @@
  ** the found occurrence were escaped.
  **/
 std::string apply_escapes(std::string s, Escapes const & escape_map) {
-	LYXERR(Debug::DEBUG, "Escaping: '" << s << "'" << std::endl);
+	LYXERR(Debug::DEBUG, "Escaping: '" << s << "'");
 	Escapes::const_iterator it;
 	for (it = escape_map.begin(); it != escape_map.end(); ++it) {
-//		LYXERR(Debug::DEBUG, "Escaping " << it->first << " as " << it->second << std::endl);
+//		LYXERR(Debug::DEBUG, "Escaping " << it->first << " as " << it->second);
 		unsigned int pos = 0;
 		while (pos < s.length() && (pos = s.find(it->first, pos)) < s.length()) {
 			s.replace(pos, it->first.length(), it->second);
-//			LYXERR(Debug::DEBUG, "After escape: " << s << std::endl);
+//			LYXERR(Debug::DEBUG, "After escape: " << s);
 			pos += it->second.length();
-//			LYXERR(Debug::DEBUG, "pos: " << pos << std::endl);
+//			LYXERR(Debug::DEBUG, "pos: " << pos);
 		}
 	}
-	LYXERR(Debug::DEBUG, "Escaped : '" << s << "'" << std::endl);
+	LYXERR(Debug::DEBUG, "Escaped : '" << s << "'");
 	return s;
 }
 
@@ -143,30 +143,30 @@
 		size_t new_pos = s.find("\\regexp{", pos);
 		if (new_pos == std::string::npos)
 			new_pos = s.size();
-		LYXERR(Debug::DEBUG, "new_pos: " << new_pos << std::endl);
+		LYXERR(Debug::DEBUG, "new_pos: " << new_pos);
 		std::string t = apply_escapes(s.substr(pos, new_pos - pos), get_lyx_unescapes());
-		LYXERR(Debug::DEBUG, "t      : " << t << std::endl);
+		LYXERR(Debug::DEBUG, "t      : " << t);
 		t = apply_escapes(t, get_regexp_escapes());
 		s.replace(pos, new_pos - pos, t);
 		new_pos = pos + t.size();
-		LYXERR(Debug::DEBUG, "Regexp after escaping: " << s << std::endl);
-		LYXERR(Debug::DEBUG, "new_pos: " << new_pos << std::endl);
+		LYXERR(Debug::DEBUG, "Regexp after escaping: " << s);
+		LYXERR(Debug::DEBUG, "new_pos: " << new_pos);
 		if (new_pos == s.size())
 			break;
 		size_t end_pos = find_matching_brace(s, new_pos + 7);
-		LYXERR(Debug::DEBUG, "end_pos: " << end_pos << std::endl);
+		LYXERR(Debug::DEBUG, "end_pos: " << end_pos);
 		t = apply_escapes(s.substr(new_pos + 8, end_pos - (new_pos + 8)), get_lyx_unescapes());
-		LYXERR(Debug::DEBUG, "t      : " << t << std::endl);
+		LYXERR(Debug::DEBUG, "t      : " << t);
 		if (end_pos == s.size()) {
 			s.replace(new_pos, end_pos - new_pos, t);
 			pos = s.size();
-			LYXERR(Debug::DEBUG, "Regexp after \\regexp{} removal: " << s << std::endl);
+			LYXERR(Debug::DEBUG, "Regexp after \\regexp{} removal: " << s);
 			break;
 		}
 		s.replace(new_pos, end_pos + 1 - new_pos, t);
-		LYXERR(Debug::DEBUG, "Regexp after \\regexp{} removal: " << s << std::endl);
+		LYXERR(Debug::DEBUG, "Regexp after \\regexp{} removal: " << s);
 		pos = new_pos + t.size();
-		LYXERR(Debug::DEBUG, "pos: " << pos << std::endl);
+		LYXERR(Debug::DEBUG, "pos: " << pos);
 	}
 	return s;
 }
@@ -194,7 +194,7 @@
 bool braces_match(std::string::const_iterator const & beg, std::string::const_iterator const & end, int unmatched = 0) {
 	int open_pars = 0;
 	std::string::const_iterator it = beg;
-	LYXERR(Debug::DEBUG, "Checking " << unmatched << " unmatched braces in '" << std::string(beg, end) << "'" << std::endl);
+	LYXERR(Debug::DEBUG, "Checking " << unmatched << " unmatched braces in '" << std::string(beg, end) << "'");
 	for (; it != end; ++it) {
 		// Skip escaped braces in the count
 		if (*it == '\\') {
@@ -205,17 +205,17 @@
 			++open_pars;
 		} else if (*it == '}') {
 			if (open_pars == 0) {
-				LYXERR(Debug::DEBUG, "Found unmatched closed brace" << std::endl);
+				LYXERR(Debug::DEBUG, "Found unmatched closed brace");
 				return false;
 			} else
 				--open_pars;
 		}
 	}
 	if (open_pars != unmatched) {
-	  LYXERR(Debug::DEBUG, "Found " << open_pars << " instead of " << unmatched << " unmatched open braces at the end of count" << std::endl);
+	  LYXERR(Debug::DEBUG, "Found " << open_pars << " instead of " << unmatched << " unmatched open braces at the end of count");
 		return false;
 	}
-	LYXERR(Debug::DEBUG, "Braces match as expected" << std::endl);
+	LYXERR(Debug::DEBUG, "Braces match as expected");
 	return true;
 }
 
@@ -236,7 +236,7 @@
 		if (! opt.regexp) {
 			// Remove trailing closure of math, macros and environments, so to catch parts of them.
 			do {
-				LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'" << std::endl);
+				LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'");
 				if (regex_replace(par_as_string, par_as_string, "(.*)[[:blank:]]\\'", "$1"))
 					continue;
 				if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\$\\'", "$1"))
@@ -252,13 +252,13 @@
 				}
 				break;
 			} while (true);
-			LYXERR(Debug::DEBUG, "Open braces: " << open_braces << std::endl);
+			LYXERR(Debug::DEBUG, "Open braces: " << open_braces);
 			BOOST_ASSERT(braces_match(par_as_string.begin(), par_as_string.end(), open_braces));
-			LYXERR(Debug::DEBUG, "Built MatchStringAdv object: par_as_string = '" << par_as_string << "'" << std::endl);
+			LYXERR(Debug::DEBUG, "Built MatchStringAdv object: par_as_string = '" << par_as_string << "'");
 		} else {
 			par_as_string = escape_for_regex(par_as_string);
 			// Insert (.*?) before trailing closure of math, macros and environments, so to catch parts of them.
-			LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'" << std::endl);
+			LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'");
 			if (
 					// Insert .* before trailing '\$' ('$' has been escaped by escape_for_regex)
 					regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\$)\\'", "$1(.*?)$2")
@@ -271,13 +271,13 @@
 			) {
 				++close_wildcards;
 			}
-			LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'" << std::endl);
-			LYXERR(Debug::DEBUG, "Open braces: " << open_braces << std::endl);
-			LYXERR(Debug::DEBUG, "Close .*?  : " << close_wildcards << std::endl);
+			LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'");
+			LYXERR(Debug::DEBUG, "Open braces: " << open_braces);
+			LYXERR(Debug::DEBUG, "Close .*?  : " << close_wildcards);
 			BOOST_ASSERT(braces_match(par_as_string.begin(), par_as_string.end(), open_braces));
 			// Entered regexp must match at begin of searched string buffer
 			par_as_string = std::string("\\`") + par_as_string;
-			LYXERR(Debug::DEBUG, "Replaced text (to be used as regex): " << par_as_string << std::endl);
+			LYXERR(Debug::DEBUG, "Replaced text (to be used as regex): " << par_as_string);
 			regexp = boost::regex(par_as_string);
 		}
 	}
@@ -290,9 +290,9 @@
 	 **/
 	int operator()(DocIterator const & cur, int len = -1) const {
 		docstring docstr = stringifyFromForSearch(opt, buf, cur, len);
-		LYXERR(Debug::DEBUG, "Matching against     '" << lyx::to_utf8(docstr) << "'" << std::endl);
+		LYXERR(Debug::DEBUG, "Matching against     '" << lyx::to_utf8(docstr) << "'");
 		std::string str = normalize(docstr);
-		LYXERR(Debug::DEBUG, "After normalization: '" << str << "'" << std::endl);
+		LYXERR(Debug::DEBUG, "After normalization: '" << str << "'");
 		if (! opt.regexp) {
 			if (str.substr(0, par_as_string.size()) == par_as_string)
 				return par_as_string.size();
@@ -377,7 +377,7 @@
  ** if len is positive, or at the paragraph or innermost inset end if len is -1.
  **/
 docstring stringifyFromCursor(Buffer const & buf, DocIterator const & cur, int len) {
-  LYXERR(Debug::DEBUG, "Stringifying with len=" << len << " from cursor at pos: " << cur << std::endl);
+  LYXERR(Debug::DEBUG, "Stringifying with len=" << len << " from cursor at pos: " << cur);
 	if (cur.inTexted()) {
 		Paragraph const & par = cur.paragraph();
 		// TODO what about searching beyond/across paragraph breaks ?
@@ -401,7 +401,7 @@
  **/
 docstring latexifyFromCursor(Buffer const & buf, DocIterator const & cur, int len) {
   LYXERR(Debug::DEBUG, "Latexifying with len=" << len << " from cursor at pos: " << cur);
-  LYXERR(Debug::DEBUG, "  with cur.lastpost=" << cur.lastpos() << ", cur.lastrow=" << cur.lastrow() << ", cur.lastcol=" << cur.lastcol() << std::endl);
+  LYXERR(Debug::DEBUG, "  with cur.lastpost=" << cur.lastpos() << ", cur.lastrow=" << cur.lastrow() << ", cur.lastcol=" << cur.lastcol());
 	BOOST_ASSERT(buf.isLatex());
 
 	TexRow texrow;
@@ -423,7 +423,7 @@
 //		lyx::latexParagraphs(buf, cur.innerText()->paragraphs(), ods, texrow, runparams, std::string(), pit, pit_end);
 		lyx::TeXOnePar(buf, *cur.innerText(), pit, ods, texrow, runparams, std::string(),
 				cur.pos(), ( len == -1 || cur.pos() + len > int(pit->size()) ) ? -1 : cur.pos() + len);
-		LYXERR(Debug::DEBUG, "Latexified text: '" << lyx::to_utf8(ods.str()) << "'" << std::endl);
+		LYXERR(Debug::DEBUG, "Latexified text: '" << lyx::to_utf8(ods.str()) << "'");
 	} else if (cur.inMathed()) {
 		// Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly
 		for (int s = cur.depth() - 1; s >= 0; --s) {
@@ -435,7 +435,7 @@
 			}
 		}
 
-		CursorSlice cs = cur.top();
+		CursorSlice const & cs = cur.top();
 		MathData md = cs.cell();
 		MathData::const_iterator it_end = ( ( len == -1 || cs.pos() + len > int(md.size()) ) ? md.end() : md.begin() + cs.pos() + len );
 		for (MathData::const_iterator it = md.begin() + cs.pos(); it != it_end; ++it)
@@ -457,14 +457,14 @@
 				break;
 			}
 		}
-		LYXERR(Debug::DEBUG, "Latexified math: '" << lyx::to_utf8(ods.str()) << "'" << std::endl);
+		LYXERR(Debug::DEBUG, "Latexified math: '" << lyx::to_utf8(ods.str()) << "'");
 	} else {
 		LYXERR(Debug::DEBUG, "Don't know how to stringify from here: " << cur);
 	}
 	return ods.str();
 }
 
-/** Finalize an advanced find operation, advancing the cursor to the foremost
+/** Finalize an advanced find operation, advancing the cursor to the innermost
  ** position that matches, plus computing the length of the matching text to
  ** be selected
  **/
@@ -473,28 +473,21 @@
 	size_t d;
 	DocIterator old_cur;
 	do {
-	  LYXERR(Debug::DEBUG, "Forwarding one step (searching for innermost match)" << std::endl);
+	  LYXERR(Debug::DEBUG, "Forwarding one step (searching for innermost match)");
 		d = cur.depth();
 		old_cur = cur;
 		cur.forwardPos();
 	} while (cur && cur.depth() > d && match(cur) > 0);
-	if (! cur.empty()) {
-		LYXERR(Debug::DEBUG, "Backwarding one step" << std::endl);
-		cur.backwardPos();
-	}
+	cur = old_cur;
 	BOOST_ASSERT(match(cur) > 0);
-//	if (! match(cur)) {
-//		LYXERR(Debug::DEBUG, "Ignoring assert !" << std::endl);
-//		//
-//	} else
-	LYXERR(Debug::DEBUG, "Ok" << std::endl);
+	LYXERR(Debug::DEBUG, "Ok");
 
 	// Compute the match length
 	int len = 1;
-	LYXERR(Debug::DEBUG, "verifying unmatch with len = " << len << std::endl);
+	LYXERR(Debug::DEBUG, "verifying unmatch with len = " << len);
 	while (cur.pos() + len <= cur.lastpos() && match(cur, len) == 0) {
 		++len;
-		LYXERR(Debug::DEBUG, "verifying unmatch with len = " << len << std::endl);
+		LYXERR(Debug::DEBUG, "verifying unmatch with len = " << len);
 	}
 	int old_len = match(cur, len);		// Length of matched text (different from len param)
 	int new_len;
@@ -502,16 +495,16 @@
 	while ((new_len = match(cur, len + 1)) > old_len) {
 		++len;
 		old_len = new_len;
-		LYXERR(Debug::DEBUG, "verifying   match with len = " << len << std::endl);
+		LYXERR(Debug::DEBUG, "verifying   match with len = " << len);
 	}
 	return len;
 }
 
 /// Finds forward
-int findForwardAdv(Cursor & cur, MatchStringAdv const & match) {
+int findForwardAdv(DocIterator & cur, MatchStringAdv const & match) {
 	if (! cur)
 		return 0;
-	for (; cur; cur.forwardChar()) {
+	for (; cur; cur.forwardPos()) {
 //		odocstringstream ods;
 //		ods << _("Searching ... ") << (cur.bottom().lastpit() - cur.bottom().pit()) * 100 / total;
 //		cur.message(ods.str());
@@ -522,38 +515,40 @@
 }
 
 /// Finds backwards
-int findBackwardsAdv(Cursor & cur, MatchStringAdv const & match) {
+int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match) {
 //	if (cur.pos() > 0 || cur.depth() > 0)
-//		cur.backwardChar();
+//		cur.backwardPos();
 	DocIterator cur_orig(cur);
 	if (match(cur_orig))
 		findAdvFinalize(cur_orig, match);
 //	int total = cur.bottom().pit() + 1;
-	for (; cur; cur.backwardChar()) {
+	for (; cur; cur.backwardPos()) {
 //		odocstringstream ods;
 //		ods << _("Searching ... ") << (total - cur.bottom().pit()) * 100 / total;
 //		cur.message(ods.str());
 		if (match(cur)) {
 			// Find the most backward consecutive match within same paragraph while searching backwards.
 			int pit = cur.pit();
+			int old_len;
 			DocIterator old_cur;
+			int len = findAdvFinalize(cur, match);
 			do {
 				old_cur = cur;
-				cur.backwardChar();
-			} while (cur && cur.pit() == pit && match(cur));
-			cur.setCursor(old_cur);
-			DocIterator cur_foremost(cur);
-			int len = findAdvFinalize(cur_foremost, match);
+				old_len = len;
+				cur.backwardPos();
+				LYXERR(Debug::DEBUG, "old_cur: " << old_cur << ", old_len=" << len << ", cur: " << cur);
+			} while (cur && cur.pit() == pit && match(cur)
+				 && (len = findAdvFinalize(cur, match)) > old_len);
+			cur = old_cur;
+			len = old_len;
 			LYXERR(Debug::DEBUG, "cur_orig    : " << cur_orig);
-			LYXERR(Debug::DEBUG, "cur_foremost: " << cur_foremost);
 			LYXERR(Debug::DEBUG, "cur         : " << cur);
-			if (cur_foremost != cur_orig) {
-				((DocIterator &) cur) = cur_foremost;
+			if (cur != cur_orig) {
 				return len;
 			}
 		}
 	}
-	return false;
+	return 0;
 }
 
 } // anonym namespace
@@ -585,7 +580,7 @@
 
 /// Perform a FindAdv operation.
 bool findAdv(BufferView * bv, FindAdvOptions const & opt) {
-	Cursor cur = bv->cursor();
+	DocIterator cur = bv->cursor();
 	int match_len = 0;
 
 	if (opt.search.empty()) {
@@ -614,7 +609,7 @@
 		return false;
 	}
 
-	LYXERR(Debug::DEBUG, "Setting selection with len: " << match_len << std::endl);
+	LYXERR(Debug::DEBUG, "Putting selection at " << cur << " with len: " << match_len);
 	bv->putSelectionAt(cur, match_len, ! opt.forward);
 	bv->message(_("Match found !"));
 	//bv->update();
@@ -645,14 +640,14 @@
 	   << opt.ignoreformat << ' '
 	   << opt.regexp;
 
-	LYXERR(Debug::DEBUG, "built: " << os.str() << std::endl);
+	LYXERR(Debug::DEBUG, "built: " << os.str());
 
 	return os;
 }
 
 /// Read a FindAdvOptions instance from a stringstream
 std::istringstream & operator>>(std::istringstream & is, lyx::FindAdvOptions & opt) {
-	LYXERR(Debug::DEBUG, "parsing" << std::endl);
+	LYXERR(Debug::DEBUG, "parsing");
 	std::string s;
 	std::string line;
 	getline(is, line);
@@ -664,11 +659,11 @@
 			break;
 		getline(is, line);
 	}
-	LYXERR(Debug::DEBUG, "searching for: '" << s << "'" << std::endl);
+	LYXERR(Debug::DEBUG, "searching for: '" << s << "'");
 	opt.search = from_utf8(s);
 	is >> opt.casesensitive >> opt.matchword >> opt.forward >> opt.expandmacros >> opt.ignoreformat >> opt.regexp;
 	LYXERR(Debug::DEBUG, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' '
-	       << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.regexp << std::endl);
+	       << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.regexp);
 	return is;
 }
 
Index: src/BufferView.cpp
===================================================================
--- src/BufferView.cpp	(revisione 27225)
+++ src/BufferView.cpp	(copia locale)
@@ -1820,10 +1820,6 @@
 
 void BufferView::setCursor(DocIterator const & dit)
 {
-	size_t const n = dit.depth();
-	for (size_t i = 0; i < n; ++i)
-		dit[i].inset().edit(d->cursor_, true);
-
 	d->cursor_.setCursor(dit);
 	d->cursor_.setSelection(false);
 }

Proprietà modificate su: src/frontends/qt4
___________________________________________________________________
Modified: svn:ignore
   - Makefile
Makefile.in
libqt4.la
.deps
.libs
*_moc.cpp
*.lo
pch.h.gch.dep
pch.h.gch

   + Makefile
Makefile.in
libqt4.la
.deps
.libs
*_moc.cpp
*.lo
pch.h.gch.dep
pch.h.gch

ui_*Ui.h

Resources.qrc

Resources.cpp


Index: src/frontends/qt4/GuiSearchAdv.h
===================================================================
--- src/frontends/qt4/GuiSearchAdv.h	(revisione 27242)
+++ src/frontends/qt4/GuiSearchAdv.h	(copia locale)
@@ -58,7 +58,6 @@
 
 protected:
 	void find(bool backwards);
-	virtual void keyPressEvent(QKeyEvent * ev);
 
 private:
 	// add a string to the combo if needed
@@ -72,7 +71,6 @@
 	Buffer *searchBuffer_;
 	BufferView *searchBufferView_;
 
-	GuiWorkArea * origWorkArea_;	// The work area in which to search
 	GuiWorkArea * searchWorkArea_;	// The work area defining what to search
 
 private:
@@ -85,6 +83,12 @@
 	void replace(docstring const & findstr,
 		     docstring const & replacestr,
 		     bool casesens, bool words, bool backwards, bool expandmacros, bool all);
+	bool eventFilter(QObject *obj, QEvent *event);
+
+public Q_SLOTS:
+	/// this happens when the dialog is simply closed/hidden
+	void closeEvent(QCloseEvent * e);
+
 };
 
 
Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h	(revisione 27242)
+++ src/frontends/qt4/GuiView.h	(copia locale)
@@ -142,6 +142,11 @@
 	/// return the current WorkArea (the one that has the focus).
 	GuiWorkArea * currentWorkArea();
 
+	/// return the current document WorkArea (it may not have the focus).
+	GuiWorkArea const * currentMainWorkArea() const;
+	/// return the current document WorkArea (it may not have the focus).
+	GuiWorkArea * currentMainWorkArea();
+
 Q_SIGNALS:
 	void closing(int);
 
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp	(revisione 27327)
+++ src/frontends/qt4/GuiView.cpp	(copia locale)
@@ -153,7 +153,8 @@
 struct GuiView::GuiViewPrivate
 {
 	GuiViewPrivate()
-		: current_work_area_(0), layout_(0), autosave_timeout_(5000),
+		: current_work_area_(0), current_main_work_area_(0),
+		layout_(0), autosave_timeout_(5000),
 		in_show_(false)
 	{
 		// hardcode here the platform specific icon size
@@ -233,7 +234,7 @@
 
 		for (int i = 0; i != splitter_->count(); ++i) {
 			TabWorkArea * twa = tabWorkArea(i);
-			if (current_work_area_ == twa->currentWorkArea())
+			if (current_main_work_area_ == twa->currentWorkArea())
 				return twa;
 		}
 
@@ -243,6 +244,7 @@
 
 public:
 	GuiWorkArea * current_work_area_;
+	GuiWorkArea * current_main_work_area_;
 	QSplitter * splitter_;
 	QStackedWidget * stack_widget_;
 	BackgroundWidget * bg_widget_;
@@ -480,6 +482,7 @@
 
 void GuiView::setFocus()
 {
+	LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this << std::endl);
 	// Make sure LyXFunc points to the correct view.
 	guiApp->setCurrentView(this);
 	theLyXFunc().setLyXView(this);
@@ -509,6 +512,9 @@
 }
 
 
+/** Destroy only all tabbed WorkAreas. Destruction of other WorkAreas
+ ** is responsibility of the container (e.g., dialog)
+ **/
 void GuiView::closeEvent(QCloseEvent * close_event)
 {
 	LYXERR(Debug::DEBUG, "GuiView::closeEvent()");
@@ -518,8 +524,9 @@
 	// e.g. when clicking the close button on a background window.
 	setFocus();
 
-	while (d.current_work_area_) {
-		Buffer * b = &d.current_work_area_->bufferView().buffer();
+	while (currentMainWorkArea()) {
+		GuiWorkArea * wa = currentMainWorkArea();
+		Buffer * b = &wa->bufferView().buffer();
 		if (b->parent()) {
 			// This is a child document, just close the tab after saving
 			// but keep the file loaded.
@@ -530,7 +537,7 @@
 			}
 		}
 
-		removeWorkArea(d.current_work_area_);
+		removeWorkArea(wa);
 
 		QList<int> const ids = guiApp->viewIds();
 		for (int i = 0; i != ids.size(); ++i) {
@@ -896,24 +903,53 @@
 }
 
 
+GuiWorkArea const * GuiView::currentMainWorkArea() const
+{
+	if (d.currentTabWorkArea() == NULL)
+		return NULL;
+	return d.currentTabWorkArea()->currentWorkArea();
+}
+
+
+GuiWorkArea * GuiView::currentMainWorkArea()
+{
+	if (d.currentTabWorkArea() == NULL)
+		return NULL;
+	return d.currentTabWorkArea()->currentWorkArea();
+}
+
+
 void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
 {
-	LASSERT(wa, return);
-	lyxerr << "Setting current wa: " << wa << endl;
-	if (d.current_work_area_ != wa) {
+	LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
+	if (wa == NULL) {
+		d.current_work_area_ = NULL;
+		d.setBackground();
+		return;
+	}
+	GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
+	if (old_gwa != wa) {
+		theGuiApp()->setCurrentView(this);
 		d.current_work_area_ = wa;
 		for (int i = 0; i != d.splitter_->count(); ++i) {
-			if (d.tabWorkArea(i)->setCurrentWorkArea(wa))
+			if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) {
+				if (d.current_main_work_area_)
+					d.current_main_work_area_->setFrameStyle(QFrame::NoFrame);
+				d.current_main_work_area_ = wa;
+				d.current_main_work_area_->setFrameStyle(QFrame::Box | QFrame::Plain);
+				d.current_main_work_area_->setLineWidth(2);
+				LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
 				return;
 		}
-		lyxerr << "This is not a tabbed wa" << endl;
+		}
+		LYXERR(Debug::DEBUG, "This is not a tabbed wa");
 		on_currentWorkAreaChanged(wa);
 		BufferView & bv = wa->bufferView();
 		bv.cursor().fixIfBroken();
 		bv.updateMetrics();
 		wa->setUpdatesEnabled(true);
-		theLyXFunc().setLyXView(this);
 	}
+	LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
 }
 
 
@@ -924,6 +960,7 @@
 		disconnectBuffer();
 		disconnectBufferView();
 		d.current_work_area_ = 0;
+		d.current_main_work_area_ = 0;
 	}
 
 	bool found_twa = false;
@@ -945,10 +982,9 @@
 		}
 	}
 
-	if (! found_twa) {
-		// It is not a tabbed work area (i.e., the search work area), so explicitly delete it
-		delete wa;
-	}
+	// It is not a tabbed work area (i.e., the search work area), so it
+	// should be deleted bu other means.
+	LASSERT(found_twa, /* */);
 
 	if (d.current_work_area_ == 0) {
 		if (d.splitter_->count() != 0) {
@@ -956,7 +992,7 @@
 			setCurrentWorkArea(twa->currentWorkArea());
 		} else {
 			// No more work area, switch to the background widget.
-			d.setBackground();
+			setCurrentWorkArea(0);
 		}
 	}
 }
@@ -1015,6 +1051,7 @@
 
 void GuiView::setBuffer(Buffer * newBuffer)
 {
+	LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << std::endl);
 	LASSERT(newBuffer, return);
 	setBusy(true);
 
@@ -2048,15 +2085,11 @@
 				twa = d.currentTabWorkArea();
 				// Switch to the next GuiWorkArea in the found TabWorkArea.
 				if (twa) {
-					d.current_work_area_ = twa->currentWorkArea();
 					// Make sure the work area is up to date.
-					twa->setCurrentWorkArea(d.current_work_area_);
+					setCurrentWorkArea(twa->currentWorkArea());
 				} else {
-					d.current_work_area_ = 0;
+					setCurrentWorkArea(0);
 				}
-				if (d.splitter_->count() == 0)
-					// No more work area, switch to the background widget.
-					d.setBackground();
 			}
 			break;
 			
Index: src/frontends/qt4/GuiWorkArea.cpp
===================================================================
--- src/frontends/qt4/GuiWorkArea.cpp	(revisione 27242)
+++ src/frontends/qt4/GuiWorkArea.cpp	(copia locale)
@@ -285,7 +285,7 @@
 	// the viewport because we have our own backing pixmap.
 	viewport()->setAttribute(Qt::WA_NoSystemBackground);
 
-	setFocusPolicy(Qt::WheelFocus);
+	setFocusPolicy(Qt::StrongFocus);
 
 	viewport()->setCursor(Qt::IBeamCursor);
 
@@ -662,7 +662,7 @@
 
 void GuiWorkArea::focusInEvent(QFocusEvent * e)
 {
-	//lyxerr << "focusInEvent on workArea: " << this->id() << std::endl;
+	LYXERR(Debug::DEBUG, "GuiWorkArea::focusInEvent(): " << this << std::endl);
 	GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
 	if (old_gwa)
 		old_gwa->stopBlinkingCursor();
@@ -678,6 +678,7 @@
 
 void GuiWorkArea::focusOutEvent(QFocusEvent * e)
 {
+	LYXERR(Debug::DEBUG, "GuiWorkArea::focusOutEvent(): " << this << std::endl);
 	stopBlinkingCursor();
 	QAbstractScrollArea::focusOutEvent(e);
 }
Index: src/frontends/qt4/ui/SearchAdvUi.ui
===================================================================
--- src/frontends/qt4/ui/SearchAdvUi.ui	(revisione 27242)
+++ src/frontends/qt4/ui/SearchAdvUi.ui	(copia locale)
@@ -38,7 +38,7 @@
     <rect>
      <x>0</x>
      <y>30</y>
-     <width>233</width>
+     <width>235</width>
      <height>371</height>
     </rect>
    </property>
@@ -63,6 +63,9 @@
         <height>48</height>
        </size>
       </property>
+      <property name="focusPolicy" >
+       <enum>Qt::StrongFocus</enum>
+      </property>
       <property name="title" >
        <string>&amp;Find ...</string>
       </property>
@@ -70,22 +73,10 @@
     </item>
     <item>
      <layout class="QGridLayout" >
-      <property name="leftMargin" >
-       <number>0</number>
-      </property>
-      <property name="topMargin" >
-       <number>0</number>
-      </property>
-      <property name="rightMargin" >
+      <property name="margin" >
        <number>0</number>
       </property>
-      <property name="bottomMargin" >
-       <number>0</number>
-      </property>
-      <property name="horizontalSpacing" >
-       <number>6</number>
-      </property>
-      <property name="verticalSpacing" >
+      <property name="spacing" >
        <number>6</number>
       </property>
       <item row="0" column="1" >
Index: src/frontends/qt4/GuiSearchAdv.cpp
===================================================================
--- src/frontends/qt4/GuiSearchAdv.cpp	(revisione 27327)
+++ src/frontends/qt4/GuiSearchAdv.cpp	(copia locale)
@@ -22,7 +22,6 @@
 #include "output_latex.h"
 #include "lyxfindadv.h"
 
-#include "frontends/qt4/GuiApplication.h"
 #include "frontends/qt4/GuiWorkArea.h"
 #include "frontends/qt4/GuiView.h"
 #include "frontends/qt4/GuiSearchAdv.h"
@@ -49,20 +48,25 @@
 /////////////////////////////////////////////////////////////////////
 
 
-void SearchAdvDialog::keyPressEvent(QKeyEvent * e) {
+bool SearchAdvDialog::eventFilter(QObject *obj, QEvent *event) {
+	LYXERR(Debug::DEBUG, "SearchAdvDialog::eventFilter()" << std::endl);
+	if (obj == searchWorkArea_ && event->type() == QEvent::KeyPress) {
+		QKeyEvent *e = static_cast<QKeyEvent *> (event);
 	if (e->key() == Qt::Key_Escape && e->modifiers() == Qt::NoModifier) {
 		on_closePB_clicked();
-		return;
+			return true;
 	} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
 		if (e->modifiers() == Qt::ShiftModifier) {
 			on_findPrevPB_clicked();
-			return;
+				return true;
 		} else if (e->modifiers() == Qt::NoModifier) {
 			on_findNextPB_clicked();
-			return;
+				return true;
 		}
 	}
-	QWidget::keyPressEvent(e);
+	}
+	// standard event processing
+	return QObject::eventFilter(obj, event);
 }
 
 
@@ -71,7 +75,7 @@
  ) :	DockView(parent, "Find LyX", "Find LyX Dialog", Qt::RightDockWidgetArea),
 	parent_view_(parent)
 {
-	searchBuffer_ = new Buffer(
+	searchBuffer_ = theBufferList().newBuffer(
 		support::FileName::tempName().absFilename() + "_searchadv.internal");
 	LASSERT(searchBuffer_ != 0, /* */);
 	searchBufferView_ = new BufferView(*searchBuffer_);
@@ -86,33 +90,48 @@
 		frame->setLayout(layout);
 	}
 	QRect frameRect = frame->childrenRect();
-	origWorkArea_ = parent_view_.currentWorkArea();
 	searchWorkArea_ = new GuiWorkArea(*searchBuffer_, parent_view_);
 	searchWorkArea_->setUpdatesEnabled(false);
 	searchWorkArea_->dialogMode() = true;
+	searchWorkArea_->installEventFilter(this);
 
 	layout->addWidget(searchWorkArea_);
 
-	setFocusPolicy(Qt::WheelFocus);
+//	setFocusPolicy(Qt::StrongFocus);
 
-	parent.setCurrentWorkArea(searchWorkArea_);
+//	parent.setCurrentWorkArea(searchWorkArea_);
 
-	searchWorkArea_->setFocus();
-	searchWorkArea_->redraw();
+//	searchWorkArea_->redraw();
+//	searchWorkArea_->setFocus();
 }
 
 
+/** No need to destroy buffer and bufferview here, because it is done
+ ** in theBuffeerList() destruction loop at application exit
+ **/
 SearchAdvDialog::~SearchAdvDialog() {
-	//delete searchWorkArea_;
-	//delete searchBuffer_;
-	//delete searchBufferView_;
+	LYXERR(Debug::DEBUG, "SearchAdvDialog::~SearchAdvDialog()");
+	if (parent_view_.currentWorkArea() == searchWorkArea_) {
+		LASSERT(parent_view_.currentMainWorkArea(), /* */);
+		parent_view_.setCurrentWorkArea(parent_view_.currentMainWorkArea());
+	}
+	delete searchWorkArea_;
+	searchWorkArea_ = 0;
+}
+
+
+void SearchAdvDialog::closeEvent(QCloseEvent * close_event)
+{
+	LYXERR(Debug::DEBUG, "SearchAdvDialog::closeEvent()");
+	on_closePB_clicked();
+	close_event->accept();
 }
 
 
 void SearchAdvDialog::selectAll() {
-	searchBufferView_->dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
-	searchBufferView_->dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
-	//searchBufferView_.update();
+	lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
+	lyx::dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
+	searchWorkArea_->redraw();
 }
 
 
@@ -162,24 +181,25 @@
 
 void SearchAdvDialog::showEvent(QShowEvent *ev)
 {
+	LYXERR(Debug::DEBUG, "SearchAdvDialog::showEvent" << std::endl);
 	this->QWidget::showEvent(ev);
-	searchWorkArea_->setFocus();
+	parent_view_.setCurrentWorkArea(searchWorkArea_);
 	selectAll();
 	searchWorkArea_->redraw();
-	//lyxerr << "showEvent()" << std::endl;
+	searchWorkArea_->setFocus();
 }
 
 
 void SearchAdvDialog::find(bool backwards) {
-	origWorkArea_->view().setCurrentWorkArea(origWorkArea_);
+	parent_view_.setCurrentWorkArea(parent_view_.currentMainWorkArea());
 	findAdv(caseCB->isChecked(),
 			wordsCB->isChecked(),
 			backwards,
 			expandMacrosCB->isChecked(),
 			ignoreFormatCB->isChecked());
-	origWorkArea_->redraw();
-	origWorkArea_->view().setCurrentWorkArea(searchWorkArea_);
-	//searchWorkArea_->setFocus();
+	parent_view_.currentMainWorkArea()->redraw();
+	parent_view_.setCurrentWorkArea(searchWorkArea_);
+	searchWorkArea_->setFocus();
 }
 
 
@@ -198,10 +218,11 @@
 	}
 }
 
+
 void SearchAdvDialog::on_closePB_clicked() {
-	theGuiApp()->currentView()->setCurrentWorkArea(origWorkArea_);
-	lyxerr << "Dispatching dialog-hide findreplaceadv" << std::endl;
-	theGuiApp()->currentView()->dispatch(FuncRequest(LFUN_DIALOG_TOGGLE, "findreplaceadv"));
+	parent_view_.setCurrentWorkArea(parent_view_.currentMainWorkArea());
+	LYXERR(Debug::DEBUG, "Dispatching dialog-hide findreplaceadv" << std::endl);
+	parent_view_.dispatch(FuncRequest(LFUN_DIALOG_TOGGLE, "findreplaceadv"));
 }
 
 
Index: src/LyXFunc.cpp
===================================================================
--- src/LyXFunc.cpp	(revisione 27242)
+++ src/LyXFunc.cpp	(copia locale)
@@ -569,6 +569,7 @@
 
 	case LFUN_WORD_FIND_FORWARD:
 	case LFUN_WORD_FIND_BACKWARD:
+	case LFUN_WORD_FINDADV:
 	case LFUN_COMMAND_PREFIX:
 	case LFUN_COMMAND_EXECUTE:
 	case LFUN_CANCEL:
@@ -615,11 +616,6 @@
 		// these are handled in our dispatch()
 		break;
 
-	case LFUN_WORD_FINDADV: {
-// Apply to WorkArea in main TabWidget, rather than on curren\tWorkArea(),
-// because the last could be the searchWorkArea itself.
-	}
-
 	default:
 		if (!theApp()) {
 			enable = false;

Proprietà modificate su: src/support
___________________________________________________________________
Modified: svn:ignore
   - Makefile.in
Makefile
*.deps
*.lo
libsupport.la
.libs
path_defines.C
pch.h.gch
pch.h.gch.dep
package.C
   + Makefile.in
Makefile
*.deps
*.lo
libsupport.la
.libs
path_defines.C
pch.h.gch
pch.h.gch.dep
package.C
*_moc.cpp


Index: src/support/lassert.h
===================================================================
--- src/support/lassert.h	(revisione 27225)
+++ src/support/lassert.h	(copia locale)
Index: src/Paragraph.cpp
===================================================================
--- src/Paragraph.cpp	(revisione 27242)
+++ src/Paragraph.cpp	(copia locale)
@@ -2110,18 +2110,17 @@
 		rp.local_font = &font;
 		rp.intitle = style.intitle;
 
-		if (i < start_pos || i >= end_pos)
-			continue;
-
 		// Two major modes:  LaTeX or plain
 		// Handle here those cases common to both modes
 		// and then split to handle the two modes separately.
-		if (c == META_INSET)
+		if (c == META_INSET) {
+			if (i >= start_pos && i < end_pos)
 			d->latexInset(bparams, os,
 					texrow, rp, running_font,
 					basefont, outerfont, open_font,
 					runningChange, style, i, column);
-		else {
+		} else {
+			if (i >= start_pos && i < end_pos) {
 			try {
 				d->latexSpecialChar(os, rp, running_font, runningChange,
 					style, i, column);
@@ -2139,6 +2138,7 @@
 				}
 			}
 		}
+		}
 
 		// Set the encoding to that returned from latexSpecialChar (see
 		// comment for encoding member in OutputParams.h)

Reply via email to