mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 00:38:10 +02:00
customdrawn: Implements minimally functional popup menu and combobox item selection
git-svn-id: trunk@48908 -
This commit is contained in:
parent
ac0dee2b7f
commit
5d06fc87a9
@ -1057,7 +1057,7 @@ begin
|
||||
begin
|
||||
// Call the combobox dialog
|
||||
LCLIntf.OnShowSelectItemDialogResult := @OnShowSelectItemDialogResult;
|
||||
LCLIntf.ShowSelectItemDialog(FItems);
|
||||
LCLIntf.ShowSelectItemDialog(FItems, Self.ClientToScreen(Point(Left, Top+Height)));
|
||||
|
||||
Exit;
|
||||
end;
|
||||
|
@ -661,7 +661,7 @@ end;
|
||||
// This routine is only for platforms which need a special combobox dialog, like Android
|
||||
// It returns true if a dialog was provided for doing this task or false otherwise
|
||||
// The process is assynchronous, so the result will be given in LCLIntf.OnShowSelectItemDialogResult
|
||||
function TWidgetSet.ShowSelectItemDialog(const AItems: TStrings): Boolean;
|
||||
function TWidgetSet.ShowSelectItemDialog(const AItems: TStrings; APos: TPoint): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
end;
|
||||
|
@ -455,9 +455,9 @@ begin
|
||||
WidgetSet.SetRubberBandRect(ARubberBand, ARect);
|
||||
end;
|
||||
|
||||
function ShowSelectItemDialog(const AItems: TStrings): Boolean;
|
||||
function ShowSelectItemDialog(const AItems: TStrings; APos: TPoint): Boolean;
|
||||
begin
|
||||
Result := Widgetset.ShowSelectItemDialog(AItems);
|
||||
Result := Widgetset.ShowSelectItemDialog(AItems, APos);
|
||||
end;
|
||||
|
||||
function StretchMaskBlt(DestDC: HDC; X, Y, Width, Height: Integer;
|
||||
|
@ -115,7 +115,7 @@ function SetCaretRespondToFocus(handle: HWND; ShowHideOnFocus: boolean): Boolean
|
||||
function SetComboMinDropDownSize(Handle: HWND; MinItemsWidth, MinItemsHeight, MinItemCount: integer): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
|
||||
procedure SetEventHandlerFlags(AHandler: PEventHandler; NewFlags: dword); {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
|
||||
procedure SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect); {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
|
||||
function ShowSelectItemDialog(const AItems: TStrings): Boolean;{$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
|
||||
function ShowSelectItemDialog(const AItems: TStrings; APos: TPoint): Boolean;{$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
|
||||
function StretchMaskBlt(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; Mask: HBITMAP; XMask, YMask: Integer; Rop: DWORD): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
|
||||
|
||||
function TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: Longint): Boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
|
||||
|
@ -757,10 +757,29 @@ begin
|
||||
end;*)
|
||||
|
||||
{$ifndef CD_HasNativeSelectItemDialog}
|
||||
function TCDWidgetset.ShowSelectItemDialog(const AItems: TStrings): Boolean;
|
||||
function TCDWidgetset.ShowSelectItemDialog(const AItems: TStrings; APos: TPoint): Boolean;
|
||||
var
|
||||
i: Integer;
|
||||
lPopUpMenu: TPopUpMenu;
|
||||
lCurItem: TMenuItem;
|
||||
begin
|
||||
Result := False;
|
||||
lPopUpMenu := TPopUpMenu.Create(nil);
|
||||
for i := 0 to AItems.Count-1 do
|
||||
begin
|
||||
lCurItem := TMenuItem.Create(lPopUpMenu);
|
||||
lPopUpMenu.Items.Add(lCurItem);
|
||||
lCurItem.Caption := AItems[i];
|
||||
end;
|
||||
lPopUpMenu.OnClose := @HandleSelectItemDialogClose;
|
||||
lPopUpMenu.PopUp(APos.X, APos.Y);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TCDWidgetset.HandleSelectItemDialogClose(ASender: TObject);
|
||||
begin
|
||||
//ASender.Free; Crashes in X11 =( Fix me!!!
|
||||
end;
|
||||
|
||||
{$endif}
|
||||
|
||||
(*function TQtWidgetSet.TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: Longint): Boolean;
|
||||
|
@ -272,7 +272,7 @@ begin
|
||||
ARawImage.Init;
|
||||
end;
|
||||
|
||||
function TCDWidgetset.ShowSelectItemDialog(const AItems: TStrings): Boolean;
|
||||
function TCDWidgetset.ShowSelectItemDialog(const AItems: TStrings; APos: TPoint): Boolean;
|
||||
var
|
||||
javaAndroidAppAlertDialogBuilderClass: JClass = nil;
|
||||
javaCharSequence: JClass = nil;
|
||||
|
@ -78,7 +78,10 @@ procedure RemoveProcessEventHandler(var AHandler: PProcessEventHandler); overrid
|
||||
|
||||
procedure SetEventHandlerFlags(AHandler: PEventHandler; NewFlags: dword); override;
|
||||
procedure SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect); override;*)
|
||||
function ShowSelectItemDialog(const AItems: TStrings): Boolean; override;
|
||||
function ShowSelectItemDialog(const AItems: TStrings; APos: TPoint): Boolean; override;
|
||||
{$ifndef CD_HasNativeSelectItemDialog}
|
||||
procedure HandleSelectItemDialogClose(ASender: TObject);
|
||||
{$endif}
|
||||
procedure ShowVirtualKeyboard();
|
||||
|
||||
// No need to implement this one as the default is redirecting to ExtTextOut
|
||||
|
@ -523,8 +523,8 @@ end;
|
||||
|
||||
function RegisterPopupMenu: Boolean; alias : 'WSRegisterPopupMenu';
|
||||
begin
|
||||
// RegisterWSComponent(TPopupMenu, TCDWSPopupMenu);
|
||||
Result := False;
|
||||
RegisterWSComponent(TPopupMenu, TCDWSPopupMenu);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function RegisterPairSplitterSide: Boolean; alias : 'WSRegisterPairSplitterSide';
|
||||
|
@ -26,7 +26,8 @@ uses
|
||||
{$ifdef CD_Windows}Windows, customdrawn_WinProc,{$endif}
|
||||
{$ifdef CD_Cocoa}MacOSAll, CocoaAll, customdrawn_cocoaproc, CocoaGDIObjects, CocoaUtils,{$endif}
|
||||
// LCL
|
||||
SysUtils, Classes, Types, LCLType, LCLProc, Graphics, Controls, Forms, Menus,
|
||||
SysUtils, Classes, Types, Math,
|
||||
LCLType, LCLProc, Graphics, Controls, Forms, Menus,
|
||||
// Widgetset
|
||||
WSMenus, WSLCLClasses;
|
||||
|
||||
@ -78,6 +79,31 @@ implementation
|
||||
{$define CD_HasNativeWSMenusINC}
|
||||
{$endif}
|
||||
{$ifndef CD_HasNativeWSMenusINC}
|
||||
|
||||
uses
|
||||
StdCtrls, LCLIntf;
|
||||
|
||||
type
|
||||
TCDPopUpMenuForm = class(TForm)
|
||||
public
|
||||
Items: array of TStaticText;
|
||||
LCLMenu: TPopUpMenu;
|
||||
procedure HandleItemClick(ASender: TObject);
|
||||
end;
|
||||
|
||||
procedure TCDPopUpMenuForm.HandleItemClick(ASender: TObject);
|
||||
var
|
||||
lSelectedItem: PtrInt;
|
||||
begin
|
||||
Self.Close;
|
||||
lSelectedItem := TStaticText(ASender).Tag;
|
||||
if LCLIntf.OnShowSelectItemDialogResult <> nil then
|
||||
LCLIntf.OnShowSelectItemDialogResult(lSelectedItem);
|
||||
end;
|
||||
|
||||
var
|
||||
CDPopUpMenus: TFPList; // of TCDPopUpMenuForm
|
||||
|
||||
{ TCDWSMenuItem }
|
||||
|
||||
class procedure TCDWSMenuItem.AttachMenu(const AMenuItem: TMenuItem);
|
||||
@ -154,11 +180,49 @@ end;
|
||||
|
||||
{ TCDWSPopupMenu }
|
||||
|
||||
class procedure TCDWSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X,
|
||||
Y: integer);
|
||||
class procedure TCDWSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X, Y: integer);
|
||||
var
|
||||
i, CurY, MaxWidth, CurWidth, ItemHeight: Integer;
|
||||
CurItem: TStaticText;
|
||||
CurCDPopUpMenu: TCDPopUpMenuForm;
|
||||
begin
|
||||
inherited Popup(APopupMenu, X, Y);
|
||||
if APopUpMenu.Items.Count = 0 then Exit;
|
||||
|
||||
CurCDPopUpMenu := TCDPopUpMenuForm.CreateNew(nil);
|
||||
CDPopUpMenus.Add(CurCDPopUpMenu);
|
||||
CurCDPopUpMenu.Left := X;
|
||||
CurCDPopUpMenu.Top := Y;
|
||||
ItemHeight := CurCDPopUpMenu.Canvas.TextHeight('Áç') + 5;
|
||||
CurCDPopUpMenu.Height := ItemHeight * APopUpMenu.Items.Count;
|
||||
CurY := 0;
|
||||
MaxWidth := 0;
|
||||
|
||||
SetLength(CurCDPopUpMenu.Items, APopUpMenu.Items.Count);
|
||||
for i := 0 to APopUpMenu.Items.Count-1 do
|
||||
begin
|
||||
CurItem := TStaticText.Create(CurCDPopUpMenu);
|
||||
CurCDPopUpMenu.Items[i] := CurItem;
|
||||
CurItem.Top := CurY;
|
||||
Inc(CurY, ItemHeight);
|
||||
CurItem.Left := 0;
|
||||
CurItem.AutoSize := True;
|
||||
CurItem.Parent := CurCDPopUpMenu;
|
||||
CurItem.Caption := APopUpMenu.Items[i].Caption;
|
||||
CurItem.Tag := i;
|
||||
CurItem.OnClick := @CurCDPopUpMenu.HandleItemClick;
|
||||
CurWidth := CurCDPopUpMenu.Canvas.TextWidth(CurItem.Caption);
|
||||
MaxWidth := Max(MaxWidth, CurWidth);
|
||||
end;
|
||||
|
||||
CurCDPopUpMenu.Width := MaxWidth;
|
||||
|
||||
CurCDPopUpMenu.Show;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
CDPopUpMenus := TFPList.Create;
|
||||
|
||||
{$endif}
|
||||
|
||||
end.
|
||||
|
@ -1407,8 +1407,7 @@ begin
|
||||
TQtLineEdit(ACustomEdit.Handle).setAlignment(AlignmentMap[AAlignment]);
|
||||
end;*)
|
||||
|
||||
class function TCDWSCustomEdit.GetCaretPos(const ACustomEdit: TCustomEdit
|
||||
): TPoint;
|
||||
class function TCDWSCustomEdit.GetCaretPos(const ACustomEdit: TCustomEdit): TPoint;
|
||||
var
|
||||
lCDWinControl: TCDWinControl;
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user