mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-10 09:28:21 +02:00
lcl: bidi mode patch from Ido with modifications
git-svn-id: trunk@14991 -
This commit is contained in:
parent
0e6090e646
commit
dbddffe2cb
@ -74,7 +74,7 @@ end;
|
||||
procedure TMenu.BidiModeChanged;
|
||||
begin
|
||||
if HandleAllocated then
|
||||
TWSMenuClass(WidgetSetClass).SetBiDiMode(Self, BidiMode);
|
||||
TWSMenuClass(WidgetSetClass).SetBiDiMode(Self, UseRightToLeftAlignment, UseRightToLeftReading);
|
||||
end;
|
||||
|
||||
procedure TMenu.ParentBidiModeChanged(AOwner: TComponent);
|
||||
@ -350,4 +350,14 @@ Begin
|
||||
Result := BidiMode <> bdLeftToRight;
|
||||
end;
|
||||
|
||||
function TMenu.UseRightToLeftAlignment : Boolean;
|
||||
begin
|
||||
Result := (BiDiMode = bdRightToLeft);
|
||||
end;
|
||||
|
||||
function TMenu.UseRightToLeftReading : Boolean;
|
||||
begin
|
||||
Result := (BiDiMode <> bdLeftToRight);
|
||||
end;
|
||||
|
||||
// included by menus.pp
|
||||
|
@ -5970,7 +5970,7 @@ begin
|
||||
inherited;
|
||||
NotifyControls(CM_PARENTBIDIMODECHANGED);
|
||||
if HandleAllocated and (Message.wParam = 0) then
|
||||
TWSWinControlClass(WidgetSetClass).SetBiDiMode(Self, BiDiMode);
|
||||
TWSWinControlClass(WidgetSetClass).SetBiDiMode(Self, UseRightToLeftAlignment, UseRightToLeftReading, UseRightToLeftScrollBar);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -153,6 +153,17 @@ procedure gdk_pango_renderer_set_override_color(gdk_renderer: PGdkPangoRenderer;
|
||||
// gdk 2.8
|
||||
procedure gdk_display_warp_pointer(display: PGdkDisplay; screen: PGdkScreen; x, y: gint); cdecl; external gdklib;
|
||||
function gdk_screen_get_rgba_colormap(screen: PGdkScreen): PGdkColormap; cdecl; external gdklib;
|
||||
|
||||
type
|
||||
TGtkPackDirection = longint;
|
||||
|
||||
const
|
||||
GTK_PACK_DIRECTION_LTR = 0;
|
||||
GTK_PACK_DIRECTION_RTL = 1;
|
||||
GTK_PACK_DIRECTION_TTB = 2;
|
||||
GTK_PACK_DIRECTION_BTT = 3;
|
||||
|
||||
procedure gtk_menu_bar_set_pack_direction(menubar : PGtkMenuBar; pack_dir : TGtkPackDirection); cdecl; external gtklib;
|
||||
{$endif}
|
||||
{$ifdef GTK_2_10}
|
||||
function gdk_screen_is_composited(screen: PGdkScreen): gboolean; cdecl; external gdklib;
|
||||
|
@ -68,7 +68,7 @@ type
|
||||
public
|
||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override;
|
||||
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; const ABiDiMode: TBiDiMode); override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); override;
|
||||
|
||||
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
|
||||
class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
|
||||
@ -235,20 +235,24 @@ begin
|
||||
end;
|
||||
|
||||
class procedure TGtk2WSWinControl.SetBiDiMode(const AWinControl : TWinControl;
|
||||
const ABiDiMode : TBiDiMode);
|
||||
UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean
|
||||
);
|
||||
const
|
||||
WidgetDirection : array[boolean] of longint = (GTK_TEXT_DIR_LTR, GTK_TEXT_DIR_RTL);
|
||||
begin
|
||||
case ABiDiMode of
|
||||
bdLeftToRight : begin
|
||||
DebugLn('Setting Left to Right control', []);
|
||||
gtk_widget_set_direction(PGtkWidget(AWinControl.Handle), GTK_TEXT_DIR_LTR);
|
||||
end;
|
||||
bdRightToLeft : begin
|
||||
DebugLn('Setting Right to left control', []);
|
||||
gtk_widget_set_direction(PGtkWidget(AWinControl.Handle), GTK_TEXT_DIR_RTL);
|
||||
end;
|
||||
bdRightToLeftNoAlign : ; // I don't know how to do it for now (if possible)
|
||||
bdRightToLeftReadingOnly : ; // By default GTK2 support bidi regardless of the layout
|
||||
end;
|
||||
gtk_widget_set_direction(PGtkWidget(AWinControl.Handle), WidgetDirection[UseRightToLeftAlign]);
|
||||
|
||||
if UseRightToLeftReading then // By default GTK2 support bidi regardless of the layout
|
||||
begin
|
||||
end
|
||||
else begin
|
||||
end;
|
||||
|
||||
if UseRightToLeftScrollBar then // I don't know how to do it for now (if possible)
|
||||
begin
|
||||
end
|
||||
else begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TGtk2WSWinControl.GetText(const AWinControl: TWinControl;
|
||||
|
@ -59,6 +59,7 @@ type
|
||||
private
|
||||
protected
|
||||
public
|
||||
class procedure SetBiDiMode(const AMenu: TMenu; UseRightToLeftAlign, UseRightToLeftReading : Boolean); override;
|
||||
end;
|
||||
|
||||
{ TGtk2WSMainMenu }
|
||||
@ -80,6 +81,8 @@ type
|
||||
|
||||
implementation
|
||||
|
||||
{$I gtkdefines.inc}
|
||||
|
||||
{ TGtk2WSMenuItem }
|
||||
|
||||
class procedure TGtk2WSMenuItem.AttachMenu(const AMenuItem: TMenuItem);
|
||||
@ -341,6 +344,29 @@ begin
|
||||
// TODO
|
||||
end;
|
||||
|
||||
{ TGtk2WSMenu }
|
||||
|
||||
class procedure TGtk2WSMenu.SetBiDiMode(const AMenu : TMenu;
|
||||
UseRightToLeftAlign, UseRightToLeftReading : Boolean
|
||||
);
|
||||
{$ifdef GTK_2_8}
|
||||
const
|
||||
MenuDirection : array[Boolean] of Longint = (GTK_PACK_DIRECTION_LTR, GTK_PACK_DIRECTION_RTL);
|
||||
{$endif}
|
||||
|
||||
begin
|
||||
{$ifdef GTK_2_8}
|
||||
gtk_menu_bar_set_pack_direction(PGtkMenuBar(AMenu.Handle), MenuDirection[UseRightToLeftAlign]);
|
||||
{$endif}
|
||||
|
||||
if UseRightToLeftReading then
|
||||
begin
|
||||
end
|
||||
else begin
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
@ -79,7 +79,7 @@ type
|
||||
class function GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean; override;
|
||||
class function GetClientRect(const AWincontrol: TWinControl; var ARect: TRect): Boolean; override;
|
||||
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; const ABiDiMode: TBiDiMode); override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); override;
|
||||
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
|
||||
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
||||
class procedure SetPos(const AWinControl: TWinControl; const ALeft, ATop: Integer); override;
|
||||
@ -317,12 +317,14 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
class procedure TQtWSWinControl.SetBiDiMode(const AWinControl: TWinControl;
|
||||
const ABiDiMode: TBiDiMode);
|
||||
class procedure TQtWSWinControl.SetBiDiMode(const AWinControl : TWinControl;
|
||||
UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean
|
||||
);
|
||||
begin
|
||||
if not WSCheckHandleAllocated(AWinControl, 'SetBiDiMode') then
|
||||
Exit;
|
||||
TQtWidget(AWinControl.Handle).setLayoutDirection(TLayoutDirectionMap[AWinControl.UseRightToLeftReading]);
|
||||
|
||||
TQtWidget(AWinControl.Handle).setLayoutDirection(TLayoutDirectionMap[UseRightToLeftAlign]);
|
||||
end;
|
||||
|
||||
class procedure TQtWSWinControl.GetPreferredSize(const AWinControl: TWinControl;
|
||||
|
@ -66,7 +66,7 @@ type
|
||||
protected
|
||||
public
|
||||
class function CreateHandle(const AMenu: TMenu): HMENU; override;
|
||||
class procedure SetBiDiMode(const AMenu: TMenu; const ABiDiMode: TBiDiMode); override;
|
||||
class procedure SetBiDiMode(const AMenu: TMenu; UseRightToLeftAlign, UseRightToLeftReading : Boolean); override;
|
||||
end;
|
||||
|
||||
{ TQtWSMainMenu }
|
||||
@ -387,12 +387,13 @@ begin
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
class procedure TQtWSMenu.SetBiDiMode(const AMenu: TMenu;
|
||||
const ABiDiMode: TBiDiMode);
|
||||
class procedure TQtWSMenu.SetBiDiMode(const AMenu : TMenu; UseRightToLeftAlign,
|
||||
UseRightToLeftReading : Boolean);
|
||||
begin
|
||||
TQtWidget(AMenu.Handle).setLayoutDirection(TLayoutDirectionMap[AMenu.IsRightToLeft]);
|
||||
TQtWidget(AMenu.Handle).setLayoutDirection(TLayoutDirectionMap[UseRightToLeftAlign]);
|
||||
end;
|
||||
|
||||
|
||||
{ TQtWSPopupMenu }
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -75,7 +75,7 @@ type
|
||||
class procedure AddControl(const AControl: TControl); override;
|
||||
|
||||
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; const ABiDiMode: TBiDiMode); override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); override;
|
||||
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
|
||||
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
||||
class procedure SetChildZPosition(const AWinControl, AChild: TWinControl;
|
||||
@ -144,7 +144,6 @@ procedure WindowCreateInitBuddy(const AWinControl: TWinControl;
|
||||
|
||||
// Must be in win32proc but TCreateWindowExParams declared here
|
||||
procedure SetStdBiDiModeParams(const AWinControl: TWinControl; var Params:TCreateWindowExParams);
|
||||
procedure UpdateStdBiDiModeFlags(const AWinControl: TWinControl);
|
||||
|
||||
implementation
|
||||
|
||||
@ -304,24 +303,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure UpdateStdBiDiModeFlags(const AWinControl: TWinControl);
|
||||
var
|
||||
FlagsEx: dword;
|
||||
begin
|
||||
//UpdateStdBiDiModeFlags must called after form loaded when the BidiMode changed at run time
|
||||
if not WSCheckHandleAllocated(AWinControl, 'UpdateStdBiDiModeFlags') then Exit;
|
||||
|
||||
FlagsEx := GetWindowLong(AWinControl.Handle, GWL_EXSTYLE);
|
||||
FlagsEx := FlagsEx and not (WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LEFTSCROLLBAR);
|
||||
if AWinControl.UseRightToLeftAlignment then
|
||||
FlagsEx := FlagsEx or WS_EX_RIGHT;
|
||||
if AWinControl.UseRightToLeftReading then
|
||||
FlagsEx := FlagsEx or WS_EX_RTLREADING ;
|
||||
if AWinControl.UseRightToLeftScrollBar then
|
||||
FlagsEx := FlagsEx or WS_EX_LEFTSCROLLBAR;
|
||||
SetWindowLong(AWinControl.Handle, GWL_EXSTYLE, FlagsEx);
|
||||
end;
|
||||
|
||||
{ TWin32WSWinControl }
|
||||
|
||||
class function TWin32WSWinControl.CreateHandle(const AWinControl: TWinControl;
|
||||
@ -374,10 +355,24 @@ begin
|
||||
Result := false;
|
||||
end;
|
||||
|
||||
class procedure TWin32WSWinControl.SetBiDiMode(const AWinControl: TWinControl;
|
||||
const ABiDiMode: TBiDiMode);
|
||||
class procedure TWin32WSWinControl.SetBiDiMode(const AWinControl : TWinControl;
|
||||
UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean
|
||||
);
|
||||
var
|
||||
FlagsEx: dword;
|
||||
begin
|
||||
UpdateStdBiDiModeFlags(AWinControl);
|
||||
if not WSCheckHandleAllocated(AWinControl, 'SetBiDiMode') then
|
||||
Exit;
|
||||
|
||||
FlagsEx := GetWindowLong(AWinControl.Handle, GWL_EXSTYLE);
|
||||
FlagsEx := FlagsEx and not (WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LEFTSCROLLBAR);
|
||||
if UseRightToLeftAlign then
|
||||
FlagsEx := FlagsEx or WS_EX_RIGHT;
|
||||
if UseRightToLeftReading then
|
||||
FlagsEx := FlagsEx or WS_EX_RTLREADING ;
|
||||
if UseRightToLeftScrollBar then
|
||||
FlagsEx := FlagsEx or WS_EX_LEFTSCROLLBAR;
|
||||
SetWindowLong(AWinControl.Handle, GWL_EXSTYLE, FlagsEx);
|
||||
end;
|
||||
|
||||
class procedure TWin32WSWinControl.SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle);
|
||||
|
@ -66,7 +66,7 @@ type
|
||||
protected
|
||||
public
|
||||
class function CreateHandle(const AMenu: TMenu): HMENU; override;
|
||||
class procedure SetBiDiMode(const AMenu: TMenu; const ABiDiMode: TBiDiMode); override;
|
||||
class procedure SetBiDiMode(const AMenu: TMenu; UseRightToLeftAlign, UseRightToLeftReading : Boolean); override;
|
||||
end;
|
||||
|
||||
{ TWin32WSMainMenu }
|
||||
@ -782,7 +782,8 @@ begin
|
||||
Result := CreateMenu;
|
||||
end;
|
||||
|
||||
class procedure TWin32WSMenu.SetBiDiMode(const AMenu: TMenu; const ABiDiMode: TBiDiMode);
|
||||
class procedure TWin32WSMenu.SetBiDiMode(const AMenu : TMenu;
|
||||
UseRightToLeftAlign, UseRightToLeftReading : Boolean);
|
||||
begin
|
||||
if not WSCheckHandleAllocated(AMenu, 'SetBiDiMode')
|
||||
then Exit;
|
||||
@ -793,10 +794,11 @@ begin
|
||||
if not (AMenu.Parent is TCustomForm) then Exit;
|
||||
if not TCustomForm(AMenu.Parent).HandleAllocated then Exit;
|
||||
if csDestroying in AMenu.Parent.ComponentState then Exit;
|
||||
|
||||
|
||||
AddToChangedMenus(TCustomForm(AMenu.Parent).Handle);
|
||||
end;
|
||||
|
||||
|
||||
{ TWin32WSPopupMenu }
|
||||
|
||||
class function TWin32WSPopupMenu.CreateHandle(const AMenu: TMenu): HMENU;
|
||||
|
@ -63,7 +63,8 @@ type
|
||||
const AParams: TCreateParams): HWND; override;
|
||||
class procedure AdaptBounds(const AWinControl: TWinControl;
|
||||
var Left, Top, Width, Height: integer; var SuppressMove: boolean); override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; const ABiDiMode: TBiDiMode); override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign,
|
||||
UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); override;
|
||||
end;
|
||||
|
||||
{ TWin32WSGroupBox }
|
||||
@ -272,7 +273,8 @@ type
|
||||
class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override;
|
||||
class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox;
|
||||
const OldShortCut, NewShortCut: TShortCut); override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; const ABiDiMode: TBiDiMode); override;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign,
|
||||
UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); override;
|
||||
class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override;
|
||||
end;
|
||||
|
||||
@ -525,7 +527,8 @@ begin
|
||||
end;
|
||||
|
||||
class procedure TWin32WSCustomGroupBox.SetBiDiMode(
|
||||
const AWinControl: TWinControl; const ABiDiMode: TBiDiMode);
|
||||
const AWinControl: TWinControl; UseRightToLeftAlign,
|
||||
UseRightToLeftReading, UseRightToLeftScrollBar : Boolean);
|
||||
begin
|
||||
RecreateWnd(AWinControl);
|
||||
end;
|
||||
@ -1443,7 +1446,8 @@ begin
|
||||
end;
|
||||
|
||||
class procedure TWin32WSCustomCheckBox.SetBiDiMode(
|
||||
const AWinControl: TWinControl; const ABiDiMode: TBiDiMode);
|
||||
const AWinControl: TWinControl; UseRightToLeftAlign,
|
||||
UseRightToLeftReading, UseRightToLeftScrollBar : Boolean);
|
||||
begin
|
||||
// UpdateStdBiDiModeFlags(AWinControl); not worked
|
||||
RecreateWnd(AWinControl);
|
||||
|
@ -317,6 +317,8 @@ type
|
||||
function IsShortcut(var Message: TLMKey): boolean;
|
||||
function HandleAllocated: Boolean;
|
||||
function IsRightToLeft: Boolean; virtual;
|
||||
function UseRightToLeftAlignment: Boolean; virtual;
|
||||
function UseRightToLeftReading: Boolean; virtual;
|
||||
procedure HandleNeeded;
|
||||
function DispatchCommand(ACommand: Word): Boolean;
|
||||
public
|
||||
|
@ -91,7 +91,7 @@ type
|
||||
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; virtual;
|
||||
class function GetTextLen(const AWinControl: TWinControl; var ALength: Integer): Boolean; virtual;
|
||||
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; const ABiDiMode: TBiDiMode); virtual;
|
||||
class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); virtual;
|
||||
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); virtual;
|
||||
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); virtual;
|
||||
class procedure SetColor(const AWinControl: TWinControl); virtual;
|
||||
@ -203,8 +203,7 @@ begin
|
||||
then ALength := Length(S);
|
||||
end;
|
||||
|
||||
class procedure TWSWinControl.SetBiDiMode(const AWinControl: TWinControl;
|
||||
const ABiDiMode: TBiDiMode);
|
||||
class procedure TWSWinControl.SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean);
|
||||
begin
|
||||
end;
|
||||
|
||||
|
@ -73,7 +73,7 @@ type
|
||||
TWSMenu = class(TWSLCLComponent)
|
||||
class function CreateHandle(const AMenu: TMenu): HMENU; virtual;
|
||||
|
||||
class procedure SetBiDiMode(const AMenu: TMenu; const ABiDiMode: TBiDiMode); virtual;
|
||||
class procedure SetBiDiMode(const AMenu: TMenu; UseRightToLeftAlign, UseRightToLeftReading : Boolean); virtual;
|
||||
end;
|
||||
|
||||
{ TWSMainMenu }
|
||||
@ -158,10 +158,12 @@ begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
class procedure TWSMenu.SetBiDiMode(const AMenu: TMenu; const ABiDiMode: TBiDiMode);
|
||||
class procedure TWSMenu.SetBiDiMode(const AMenu : TMenu; UseRightToLeftAlign,
|
||||
UseRightToLeftReading : Boolean);
|
||||
begin
|
||||
end;
|
||||
|
||||
|
||||
{ TWSPopupMenu }
|
||||
|
||||
class procedure TWSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X, Y: integer);
|
||||
|
Loading…
Reference in New Issue
Block a user