cghislai has proposed merging lp:~widelands-dev/widelands/bug657285 into 
lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug657285/+merge/175551

I corrected the bug by handling mousein events in the Window class.
I also fixed two things found along in the way:
 1 text alignment was not honored in tables
 2 texts containing false tag such as '<parent>' to go up one directory, threw 
exception with the new font handler.

For 2, the parser will consider unallowed tags as normal text. Another way 
could be to escape all these correctly, but the solution here should be safe 
for translated strings as well. A warning is printed if such tag is detected 
and an exception should still be thrown for typos, as the closing tag will be 
parsed.
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug657285/+merge/175551
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug657285 into lp:widelands.
=== modified file 'src/graphic/text/rt_parse.cc'
--- src/graphic/text/rt_parse.cc	2013-02-10 18:47:18 +0000
+++ src/graphic/text/rt_parse.cc	2013-07-18 12:47:29 +0000
@@ -27,6 +27,7 @@
 #include "rt_parse.h"
 #include "textstream.h"
 #include "rt_errors_impl.h"
+#include "log.h"
 
 using namespace std;
 using namespace boost;
@@ -184,11 +185,19 @@
 		Tag * child = new Tag();
 		line = ts.line(); col = ts.col(); size_t cpos = ts.pos();
 		child->parse(ts, tcs, allowed_tags);
-		if (!tc.allowed_childs.count(child->name()))
-			throw SyntaxError_Impl(line, col, "an allowed tag", child->name(), ts.peek(100, cpos));
-		if (!allowed_tags.empty() and !allowed_tags.count(child->name()))
-			throw SyntaxError_Impl(line, col, "an allowed tag", child->name(), ts.peek(100, cpos));
-
+		// Only log unallowed tags and consider them as normal text, if allowed
+		if (!tc.allowed_childs.count(child->name())
+			|| (!allowed_tags.empty() and !allowed_tags.count(child->name())))
+		{
+			if (!tc.text_allowed) {
+				throw SyntaxError_Impl(line, col, "an allowed tag", child->name(), ts.peek(100, cpos));
+			} else {
+				std::string tag_string = (boost::format("<%1%>") % child->name()).str();
+				log("Warning: Tag not allowed: %s. Will be considered as normal text\n", tag_string.c_str());
+				m_childs.push_back(new Child(tag_string));
+				return;
+			}
+		}
 		m_childs.push_back(new Child(child));
 	}
 }

=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc	2013-07-16 17:30:22 +0000
+++ src/ui_basic/table.cc	2013-07-18 12:47:29 +0000
@@ -294,10 +294,15 @@
 			}
 
 			const Image* entry_text_im = UI::g_fh1->render(as_uifont(entry_string, m_fontsize));
+			uint16_t text_width = entry_text_im->width();
+			if (alignment & Align_Right) {
+				point.x += curw - picw;
+			} else if (alignment & Align_HCenter) {
+				point.x += (curw - picw) / 2;
+			}
+			UI::correct_for_align(alignment, text_width, entry_text_im->height(), &point);
 			// Crop to column width
-			UI::correct_for_align(alignment, entry_text_im->width(), entry_text_im->height(), &point);
 			dst.blitrect(point, entry_text_im, Rect(0, 0, curw - picw, lineheight));
-
 			curx += curw;
 		}
 

=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc	2013-02-10 19:36:24 +0000
+++ src/ui_basic/window.cc	2013-07-18 12:47:29 +0000
@@ -24,9 +24,11 @@
 #include "graphic/font_handler1.h"
 #include "graphic/graphic.h"
 #include "graphic/rendertarget.h"
+#include "wui/mapview.h"
 #include "log.h"
 #include "text_layout.h"
 #include "wlapplication.h"
+#include "upcast.h"
 
 #include "compile_assert.h"
 
@@ -475,6 +477,21 @@
 	return true;
 }
 
+void Window::handle_mousein(bool mousein)
+{
+	Panel* parent = get_parent();
+	// Reset the mapview tooltip if it is our parent
+	if (!mousein || parent == NULL) {
+		NamedPanel::handle_mousein(mousein);
+		return;
+	}
+	upcast(Map_View, mapview, parent);
+	if (mapview) {
+		mapview->set_tooltip("");
+	}
+	NamedPanel::handle_mousein(mousein);
+}
+
 bool Window::handle_alt_drag(int32_t mx, int32_t my)
 {
 	_dragging = true;

=== modified file 'src/ui_basic/window.h'
--- src/ui_basic/window.h	2013-02-09 23:18:23 +0000
+++ src/ui_basic/window.h	2013-07-18 12:47:29 +0000
@@ -86,6 +86,7 @@
 	bool handle_mouserelease(Uint8 btn, int32_t mx, int32_t my);
 	bool handle_mousemove
 		(Uint8 state, int32_t mx, int32_t my, int32_t xdiff, int32_t ydiff);
+	void handle_mousein(bool mousein);
 	bool handle_alt_drag (int32_t mx, int32_t my);
 
 protected:

=== modified file 'src/wui/building_ui.cc'
--- src/wui/building_ui.cc	2013-07-16 10:17:53 +0000
+++ src/wui/building_ui.cc	2013-07-18 12:47:29 +0000
@@ -32,8 +32,6 @@
  */
 void Building::show_options(Interactive_GameBase & igbase, bool avoid_fastclick)
 {
-	// Reset tooltip before opening the window
-	igbase.set_tooltip("");
 	if (m_optionswindow) {
 		if (m_optionswindow->is_minimal())
 			m_optionswindow->restore();

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to