- wxWindow *win = m_canvas;
- while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
- if (win->HasCustomPalette()) {
+ wxWindow *win = m_canvas->GetAncestorWithCustomPalette();
+
+ m_hasCustomPalette = win && win->HasCustomPalette();
+ if ( m_hasCustomPalette )
+ {