Next round of RTL fixes. This change greatly simplifes

the code and makes most #ifdefs redundant.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41255 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-09-16 21:44:21 +00:00
parent 9b0b3151e0
commit 807a572ef4
4 changed files with 65 additions and 140 deletions

View File

@@ -1701,23 +1701,22 @@ void wxListHeaderWindow::AdjustDC(wxDC& dc)
int view_start; int view_start;
m_owner->GetViewStart( &view_start, NULL ); m_owner->GetViewStart( &view_start, NULL );
if (GetLayoutDirection() == wxLayout_RightToLeft)
{
// FIXME: we need a better way for RTL scrolling..
int scroll_lines = m_owner->GetScrollLines( wxHORIZONTAL );
if (scroll_lines)
{
int client_size = m_owner->GetClientSize().x;
view_start = scroll_lines - (client_size / xpix) - view_start;
view_start = -view_start;
}
}
int org_x = 0; int org_x = 0;
int org_y = 0; int org_y = 0;
dc.GetDeviceOrigin( &org_x, &org_y ); dc.GetDeviceOrigin( &org_x, &org_y );
// account for the horz scrollbar offset // account for the horz scrollbar offset
#ifdef __WXGTK__
if (GetLayoutDirection() == wxLayout_RightToLeft)
{
// Maybe we just have to check for m_signX
// in the DC, but I leave the #ifdef __WXGTK__
// for now
dc.SetDeviceOrigin( org_x + (view_start * xpix), org_y );
}
else
#endif
dc.SetDeviceOrigin( org_x - (view_start * xpix), org_y ); dc.SetDeviceOrigin( org_x - (view_start * xpix), org_y );
} }
@@ -3154,17 +3153,6 @@ void wxListMainWindow::MoveToItem(size_t item)
Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine ); Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
} }
else // !report else // !report
{
if (GetLayoutDirection() == wxLayout_RightToLeft)
{
#if 0
wxPrintf( wxT("rect %d %d %d %d view_x %d\n"), rect.x, rect.y, rect.width, rect.height, view_x );
int virtual_width = GetVirtualSize().x;
view_x = virtual_width - view_x - client_w;
wxPrintf( wxT("virtual_width %d view_x = %d client_w = %d\n"), virtual_width, view_x, client_w );
#endif
}
else
{ {
if (rect.x-view_x < 5) if (rect.x-view_x < 5)
Scroll( (rect.x - 5) / SCROLL_UNIT_X, -1 ); Scroll( (rect.x - 5) / SCROLL_UNIT_X, -1 );
@@ -3172,7 +3160,6 @@ void wxListMainWindow::MoveToItem(size_t item)
Scroll( (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X, -1 ); Scroll( (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X, -1 );
} }
} }
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// keyboard handling // keyboard handling

View File

@@ -815,6 +815,15 @@ void wxScrollHelper::AdjustScrollbars()
void wxScrollHelper::DoPrepareDC(wxDC& dc) void wxScrollHelper::DoPrepareDC(wxDC& dc)
{ {
wxPoint pt = dc.GetDeviceOrigin(); wxPoint pt = dc.GetDeviceOrigin();
#ifdef __WXGTK__
// It may actually be correct to always query
// the m_sign from the DC here, but I leve the
// #ifdef GTK for now.
if (m_win->GetLayoutDirection() == wxLayout_RightToLeft)
dc.SetDeviceOrigin( pt.x + m_xScrollPosition * m_xScrollPixelsPerLine,
pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
else
#endif
dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine, dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine,
pt.y - m_yScrollPosition * m_yScrollPixelsPerLine ); pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
dc.SetUserScale( m_scaleX, m_scaleY ); dc.SetUserScale( m_scaleX, m_scaleY );
@@ -949,33 +958,7 @@ void wxScrollHelper::GetViewStart (int *x, int *y) const
void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const
{ {
if ( xx ) if ( xx )
{
if ((m_xScrollLines == 0) || (m_xScrollPixelsPerLine == 0))
{
// nothing to do
*xx = x;
}
else
{
#ifdef __WXGTK__
if (m_win->GetLayoutDirection() == wxLayout_RightToLeft)
{
int w = 0, h = 0;
GetTargetSize(&w, &h);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = w/m_xScrollPixelsPerLine;
if (noPagePositions < 1) noPagePositions = 1;
*xx = x - ((m_xScrollLines - noPagePositions - m_xScrollPosition) * m_xScrollPixelsPerLine);
}
else
#endif
{
*xx = x - m_xScrollPosition * m_xScrollPixelsPerLine; *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
}
}
}
if ( yy ) if ( yy )
*yy = y - m_yScrollPosition * m_yScrollPixelsPerLine; *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
} }
@@ -983,33 +966,7 @@ void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) cons
void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
{ {
if ( xx ) if ( xx )
{
if ((m_xScrollLines == 0) || (m_xScrollPixelsPerLine == 0))
{
// nothing to do
*xx = x;
}
else
{
#ifdef __WXGTK__
if (m_win->GetLayoutDirection() == wxLayout_RightToLeft)
{
int w = 0, h = 0;
GetTargetSize(&w, &h);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = w/m_xScrollPixelsPerLine;
if (noPagePositions < 1) noPagePositions = 1;
*xx = x + ((m_xScrollLines - noPagePositions - m_xScrollPosition) * m_xScrollPixelsPerLine);
}
else
#endif
{
*xx = x + m_xScrollPosition * m_xScrollPixelsPerLine; *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
}
}
}
if ( yy ) if ( yy )
*yy = y + m_yScrollPosition * m_yScrollPixelsPerLine; *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
} }

View File

@@ -331,37 +331,7 @@ wxWindowDC::wxWindowDC( wxWindow *window )
m_signX = -1; m_signX = -1;
// origin in the upper right corner // origin in the upper right corner
m_deviceOriginX = m_owner->GetClientSize().x;
int scroll_lines = 0;
int scroll_step = 0;
// Are we using scrolling?
wxScrollHelper *sh = (wxScrollHelper*) m_owner->GetScrollHelper();
if (sh)
{
scroll_lines = sh->GetScrollLines(wxHORIZONTAL);
sh->GetScrollPixelsPerUnit( &scroll_step, NULL );
}
if (scroll_lines == 0)
{
int client_width = m_owner->GetClientSize().x;
m_deviceOriginX = client_width;
}
else
{
// We cannot use just the virtual size here, because
// the virtual size may be less than the visible area
// due to rounding errors of the scroll steps. If the
// horizontal scroll step is 10 pixels and the virtual
// area is 97 pixels, we should be able to see or scroll
// to 100 pixels, so the origin is at -100, not -97.
int client_width = sh->GetTargetWindow()->GetClientSize().x;
int virtual_size = m_owner->GetVirtualSize().x;
int steps = (virtual_size + scroll_step - 1) / scroll_step;
int width = steps * scroll_step + (client_width % scroll_step);
m_deviceOriginX = width;
}
} }
} }

View File

@@ -338,14 +338,6 @@ static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
if (!win->m_hasVMT) if (!win->m_hasVMT)
return; return;
int dw = 0;
int dh = 0;
if (win->m_hasScrolling)
{
GetScrollbarWidth(widget, dw, dh);
}
int dx = 0; int dx = 0;
int dy = 0; int dy = 0;
if (GTK_WIDGET_NO_WINDOW (widget)) if (GTK_WIDGET_NO_WINDOW (widget))
@@ -354,6 +346,27 @@ static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
dy += widget->allocation.y; dy += widget->allocation.y;
} }
int x = dx;
int y = dy;
int dw = 0;
int dh = 0;
if (win->m_hasScrolling)
{
GetScrollbarWidth(widget, dw, dh);
if (win->GetLayoutDirection() == wxLayout_RightToLeft)
{
// This is actually wrong for old GTK+ version
// which do not display the scrollbar on the
// left side in RTL
x += dw;
}
}
int w = widget->allocation.width-dw;
int h = widget->allocation.height-dh;
if (win->HasFlag(wxRAISED_BORDER)) if (win->HasFlag(wxRAISED_BORDER))
{ {
gtk_paint_shadow (widget->style, gtk_paint_shadow (widget->style,
@@ -361,8 +374,7 @@ static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
GTK_STATE_NORMAL, GTK_STATE_NORMAL,
GTK_SHADOW_OUT, GTK_SHADOW_OUT,
NULL, NULL, NULL, // FIXME: No clipping? NULL, NULL, NULL, // FIXME: No clipping?
dx, dy, x, y, w, h );
widget->allocation.width-dw, widget->allocation.height-dh );
return; return;
} }
@@ -373,8 +385,7 @@ static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
GTK_STATE_NORMAL, GTK_STATE_NORMAL,
GTK_SHADOW_IN, GTK_SHADOW_IN,
NULL, NULL, NULL, // FIXME: No clipping? NULL, NULL, NULL, // FIXME: No clipping?
dx, dy, x, y, w, h );
widget->allocation.width-dw, widget->allocation.height-dh );
return; return;
} }
@@ -383,9 +394,7 @@ static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
GdkGC *gc; GdkGC *gc;
gc = gdk_gc_new( widget->window ); gc = gdk_gc_new( widget->window );
gdk_gc_set_foreground( gc, &widget->style->black ); gdk_gc_set_foreground( gc, &widget->style->black );
gdk_draw_rectangle( widget->window, gc, FALSE, gdk_draw_rectangle( widget->window, gc, FALSE, x, y, w-1, h-1 );
dx, dy,
widget->allocation.width-dw-1, widget->allocation.height-dh-1 );
g_object_unref (gc); g_object_unref (gc);
return; return;
} }
@@ -2460,6 +2469,8 @@ bool wxWindowGTK::Create( wxWindow *parent,
m_scrollBar[ScrollDir_Horz] = GTK_RANGE(scrolledWindow->hscrollbar); m_scrollBar[ScrollDir_Horz] = GTK_RANGE(scrolledWindow->hscrollbar);
m_scrollBar[ScrollDir_Vert] = GTK_RANGE(scrolledWindow->vscrollbar); m_scrollBar[ScrollDir_Vert] = GTK_RANGE(scrolledWindow->vscrollbar);
if (GetLayoutDirection() == wxLayout_RightToLeft)
gtk_range_set_inverted( m_scrollBar[ScrollDir_Horz], TRUE );
m_wxwindow = gtk_pizza_new(); m_wxwindow = gtk_pizza_new();
@@ -3764,6 +3775,7 @@ void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect )
gdk_rect.height = rect->height; gdk_rect.height = rect->height;
if (GetLayoutDirection() == wxLayout_RightToLeft) if (GetLayoutDirection() == wxLayout_RightToLeft)
gdk_rect.x = GetClientSize().x - gdk_rect.x - gdk_rect.width; gdk_rect.x = GetClientSize().x - gdk_rect.x - gdk_rect.width;
p = &gdk_rect; p = &gdk_rect;
} }
else // invalidate everything else // invalidate everything
@@ -3829,8 +3841,6 @@ void wxWindowGTK::GtkSendPaintEvents()
// Clip to paint region in wxClientDC // Clip to paint region in wxClientDC
m_clipPaintRegion = true; m_clipPaintRegion = true;
wxRegion maybe_rtl_region = m_updateRegion;
#if 0 #if 0
if (GetLayoutDirection() == wxLayout_RightToLeft) if (GetLayoutDirection() == wxLayout_RightToLeft)
{ {
@@ -3893,8 +3903,6 @@ void wxWindowGTK::GtkSendPaintEvents()
} }
else else
{ {
m_updateRegion = maybe_rtl_region;
wxWindowDC dc( (wxWindow*)this ); wxWindowDC dc( (wxWindow*)this );
dc.SetClippingRegion( m_updateRegion ); dc.SetClippingRegion( m_updateRegion );
@@ -3904,8 +3912,6 @@ void wxWindowGTK::GtkSendPaintEvents()
GetEventHandler()->ProcessEvent(erase_event); GetEventHandler()->ProcessEvent(erase_event);
} }
m_updateRegion = maybe_rtl_region;
wxNcPaintEvent nc_paint_event( GetId() ); wxNcPaintEvent nc_paint_event( GetId() );
nc_paint_event.SetEventObject( this ); nc_paint_event.SetEventObject( this );
GetEventHandler()->ProcessEvent( nc_paint_event ); GetEventHandler()->ProcessEvent( nc_paint_event );
@@ -4290,8 +4296,8 @@ void wxWindowGTK::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
pos = max; pos = max;
if (pos < 0) if (pos < 0)
pos = 0; pos = 0;
m_scrollPos[dir] = m_scrollPos[dir] = adj->value = pos;
adj->value = pos;
// If a "value_changed" signal emission is not already in progress // If a "value_changed" signal emission is not already in progress
if (!m_blockValueChanged[dir]) if (!m_blockValueChanged[dir])
{ {
@@ -4344,7 +4350,9 @@ wxEventType wxWindowGTK::GetScrollEventType(GtkRange* range)
const int barIndex = range == m_scrollBar[1]; const int barIndex = range == m_scrollBar[1];
GtkAdjustment* adj = range->adjustment; GtkAdjustment* adj = range->adjustment;
const int value = int(adj->value + 0.5); const int value = int(adj->value + 0.5);
// save previous position // save previous position
const double oldPos = m_scrollPos[barIndex]; const double oldPos = m_scrollPos[barIndex];
// update current position // update current position
@@ -4390,6 +4398,9 @@ void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )
m_clipPaintRegion = true; m_clipPaintRegion = true;
if (GetLayoutDirection() == wxLayout_RightToLeft)
gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), dx, -dy );
else
gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), -dx, -dy ); gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), -dx, -dy );
m_clipPaintRegion = false; m_clipPaintRegion = false;