mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 13:17:18 +02:00
Now TComboBox is almost working in Android. It shows the item selection dialog, but it crashes when the user selects an item
git-svn-id: trunk@35652 -
This commit is contained in:
parent
5369526396
commit
4d20dae129
@ -228,6 +228,16 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
lclxdpi = (int) metrics.xdpi;
|
lclxdpi = (int) metrics.xdpi;
|
||||||
lclydpi = (int) metrics.ydpi;
|
lclydpi = (int) metrics.ydpi;
|
||||||
LCLOnCreate(this);
|
LCLOnCreate(this);
|
||||||
|
|
||||||
|
// Prepare dialog callbacks
|
||||||
|
// for TCDComboBox
|
||||||
|
lclselectitemcallback = new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override public void onClick(DialogInterface dialog, int which)
|
||||||
|
{
|
||||||
|
LCLOnMessageBoxFinished(which, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onConfigurationChanged (Configuration newConfig)
|
@Override public void onConfigurationChanged (Configuration newConfig)
|
||||||
@ -253,7 +263,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
public native int LCLDrawToBitmap(int width, int height, Bitmap bitmap);
|
public native int LCLDrawToBitmap(int width, int height, Bitmap bitmap);
|
||||||
public native int LCLOnTouch(float x, float y, int action);
|
public native int LCLOnTouch(float x, float y, int action);
|
||||||
public native int LCLOnCreate(LCLActivity lclactivity);
|
public native int LCLOnCreate(LCLActivity lclactivity);
|
||||||
public native int LCLOnMessageBoxFinished(int Result);
|
public native int LCLOnMessageBoxFinished(int Result, int DialogType);
|
||||||
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, int AChar);
|
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, int AChar);
|
||||||
public native int LCLOnTimer(Runnable timerid);
|
public native int LCLOnTimer(Runnable timerid);
|
||||||
public native int LCLOnConfigurationChanged(int ANewDPI, int ANewWidth);
|
public native int LCLOnConfigurationChanged(int ANewDPI, int ANewWidth);
|
||||||
@ -347,13 +357,13 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
LCLOnMessageBoxFinished(lclbutton1);
|
LCLOnMessageBoxFinished(lclbutton1, 0);
|
||||||
break;
|
break;
|
||||||
case DialogInterface.BUTTON_NEUTRAL:
|
case DialogInterface.BUTTON_NEUTRAL:
|
||||||
LCLOnMessageBoxFinished(lclbutton2);
|
LCLOnMessageBoxFinished(lclbutton2, 0);
|
||||||
break;
|
break;
|
||||||
case DialogInterface.BUTTON_NEGATIVE:
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
LCLOnMessageBoxFinished(lclbutton3);
|
LCLOnMessageBoxFinished(lclbutton3, 0);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -365,7 +375,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
public void onCancel(DialogInterface dialog)
|
public void onCancel(DialogInterface dialog)
|
||||||
{
|
{
|
||||||
// The Cancel button number matches for LCLIntf.MessageBox and LCLIntf.PromptDialog
|
// The Cancel button number matches for LCLIntf.MessageBox and LCLIntf.PromptDialog
|
||||||
LCLOnMessageBoxFinished(idButtonCancel);
|
LCLOnMessageBoxFinished(idButtonCancel, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -613,6 +623,9 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
public String lcldestination;
|
public String lcldestination;
|
||||||
public int lclkind;
|
public int lclkind;
|
||||||
|
|
||||||
|
// Dialog callbacks
|
||||||
|
DialogInterface.OnClickListener lclselectitemcallback;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -28,7 +28,7 @@ object Form1: TForm1
|
|||||||
object ProgressBar1: TProgressBar
|
object ProgressBar1: TProgressBar
|
||||||
Left = 72
|
Left = 72
|
||||||
Height = 20
|
Height = 20
|
||||||
Top = 80
|
Top = 72
|
||||||
Width = 140
|
Width = 140
|
||||||
Position = 60
|
Position = 60
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
@ -36,7 +36,7 @@ object Form1: TForm1
|
|||||||
object TrackBar1: TTrackBar
|
object TrackBar1: TTrackBar
|
||||||
Left = 72
|
Left = 72
|
||||||
Height = 31
|
Height = 31
|
||||||
Top = 112
|
Top = 96
|
||||||
Width = 140
|
Width = 140
|
||||||
Position = 0
|
Position = 0
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
@ -86,4 +86,19 @@ object Form1: TForm1
|
|||||||
OnClick = btnShowInfoClick
|
OnClick = btnShowInfoClick
|
||||||
TabOrder = 6
|
TabOrder = 6
|
||||||
end
|
end
|
||||||
|
object ComboBox1: TComboBox
|
||||||
|
Left = 72
|
||||||
|
Height = 27
|
||||||
|
Top = 128
|
||||||
|
Width = 140
|
||||||
|
AutoSize = False
|
||||||
|
ItemHeight = 0
|
||||||
|
Items.Strings = (
|
||||||
|
'Item1'
|
||||||
|
'Item2'
|
||||||
|
'Item3'
|
||||||
|
)
|
||||||
|
TabOrder = 7
|
||||||
|
Text = 'ComboBox1'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,6 +20,7 @@ type
|
|||||||
Button3: TButton;
|
Button3: TButton;
|
||||||
btnShowInfo: TButton;
|
btnShowInfo: TButton;
|
||||||
CheckBox1: TCheckBox;
|
CheckBox1: TCheckBox;
|
||||||
|
ComboBox1: TComboBox;
|
||||||
Label1: TLabel;
|
Label1: TLabel;
|
||||||
ProgressBar1: TProgressBar;
|
ProgressBar1: TProgressBar;
|
||||||
TrackBar1: TTrackBar;
|
TrackBar1: TTrackBar;
|
||||||
|
@ -34,5 +34,6 @@
|
|||||||
// Default options for various backends
|
// Default options for various backends
|
||||||
{$if defined(CD_Android) or defined(CD_Windows)}
|
{$if defined(CD_Android) or defined(CD_Windows)}
|
||||||
{$define CD_UseNativeText}
|
{$define CD_UseNativeText}
|
||||||
|
{$define CD_HasNativeSelectItemDialog}
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ function Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap(
|
|||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnCreate(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnCreate(
|
||||||
env:PJNIEnv; this:jobject; alclactivity: jobject): jint; cdecl;
|
env:PJNIEnv; this:jobject; alclactivity: jobject): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
||||||
env:PJNIEnv; this:jobject; AResult: jint): jint; cdecl;
|
env:PJNIEnv; this:jobject; AResult, ADialogType: jint): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
||||||
env:PJNIEnv; this:jobject; AKind: jint; AKeyCode: jint;
|
env:PJNIEnv; this:jobject; AKind: jint; AKeyCode: jint;
|
||||||
AEvent: jobject; AChar: jint): jint; cdecl;
|
AEvent: jobject; AChar: jint): jint; cdecl;
|
||||||
|
@ -731,9 +731,16 @@ end;
|
|||||||
procedure TQtWidgetSet.SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect);
|
procedure TQtWidgetSet.SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect);
|
||||||
begin
|
begin
|
||||||
QRubberBand_setGeometry(QRubberBandH(ARubberBand), @ARect);
|
QRubberBand_setGeometry(QRubberBandH(ARubberBand), @ARect);
|
||||||
end;
|
end;*)
|
||||||
|
|
||||||
function TQtWidgetSet.TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: Longint): Boolean;
|
{$ifndef CD_HasNativeSelectItemDialog}
|
||||||
|
function TCDWidgetset.ShowSelectItemDialog(const AItems: TStrings): Boolean;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
end;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
(*function TQtWidgetSet.TextUTF8Out(DC: HDC; X, Y: Integer; Str: PChar; Count: Longint): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
if IsValidDC(DC) then
|
if IsValidDC(DC) then
|
||||||
|
@ -274,6 +274,60 @@ begin
|
|||||||
ARawImage.Init;
|
ARawImage.Init;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCDWidgetset.ShowSelectItemDialog(const AItems: TStrings): Boolean;
|
||||||
|
var
|
||||||
|
javaAndroidAppAlertDialogBuilderClass: JClass = nil;
|
||||||
|
javaCharSequence: JClass = nil;
|
||||||
|
javaMethod_AlertDialogBuilder_new, javaMethod_AlertDialogBuilder_setSingleChoiceItems,
|
||||||
|
javaMethod_AlertDialogBuilder_show: JMethodID;
|
||||||
|
JavaField_lclselectitemcallback: JFieldID;
|
||||||
|
javaAlertDialog: JObject;
|
||||||
|
javaObjectArray: JObjectArray;
|
||||||
|
// array for the parameters
|
||||||
|
lParams: array[0..2] of JValue;
|
||||||
|
lJavaString: JString;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
//__android_log_write(ANDROID_LOG_INFO, 'lclapp', '[TCDWidgetset.ShowSelectItemDialog]');
|
||||||
|
|
||||||
|
// First get the classes
|
||||||
|
javaAndroidAppAlertDialogBuilderClass := javaEnvRef^^.FindClass(javaEnvRef, 'android/app/AlertDialog$Builder');
|
||||||
|
javaCharSequence := javaEnvRef^^.FindClass(javaEnvRef, 'java/lang/CharSequence');
|
||||||
|
//__android_log_write(ANDROID_LOG_INFO, 'lclapp', PChar('[TCDWidgetset.ShowSelectItemDialog] 2 javaAndroidAppAlertDialogBuilderClass='+IntToStr(PtrInt(javaAndroidAppAlertDialogBuilderClass))));
|
||||||
|
|
||||||
|
// final AlertDialog.Builder ad = new AlertDialog.Builder(this);
|
||||||
|
javaMethod_AlertDialogBuilder_new := javaEnvRef^^.GetMethodID(javaEnvRef, javaAndroidAppAlertDialogBuilderClass, '<init>', '(Landroid/content/Context;)V');
|
||||||
|
//__android_log_write(ANDROID_LOG_INFO, 'lclapp', '[TCDWidgetset.ShowSelectItemDialog] 2,5');
|
||||||
|
lParams[0].l := javaActivityObject;
|
||||||
|
javaAlertDialog := javaEnvRef^^.NewObjectA(javaEnvRef, javaAndroidAppAlertDialogBuilderClass, javaMethod_AlertDialogBuilder_new, @lParams[0]);
|
||||||
|
//__android_log_write(ANDROID_LOG_INFO, 'lclapp', '[TCDWidgetset.ShowSelectItemDialog] 3');
|
||||||
|
|
||||||
|
// ad.setSingleChoiceItems( adapter, -1, MyOnClickListener);
|
||||||
|
// DialogInterface.OnClickListener lclselectitemcallback;
|
||||||
|
// public AlertDialog.Builder setSingleChoiceItems (CharSequence[] items, int checkedItem, DialogInterface.OnClickListener listener)
|
||||||
|
JavaField_lclselectitemcallback := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclselectitemcallback', 'Landroid/content/DialogInterface$OnClickListener;');
|
||||||
|
javaMethod_AlertDialogBuilder_setSingleChoiceItems := javaEnvRef^^.GetMethodID(javaEnvRef, javaAndroidAppAlertDialogBuilderClass, 'setSingleChoiceItems',
|
||||||
|
'([Ljava/lang/CharSequence;ILandroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;');
|
||||||
|
javaObjectArray := javaEnvRef^^.NewObjectArray(javaEnvRef, AItems.Count, javaCharSequence, nil);
|
||||||
|
lParams[0].l := javaObjectArray;
|
||||||
|
//__android_log_write(ANDROID_LOG_INFO, 'lclapp', PChar('[TCDWidgetset.ShowSelectItemDialog] javaObjectArray='+IntToStr(PtrInt(javaObjectArray))));
|
||||||
|
for i := 0 to AItems.Count-1 do
|
||||||
|
begin
|
||||||
|
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(AItems.Strings[i]));
|
||||||
|
javaEnvRef^^.SetObjectArrayElement(javaEnvRef, javaObjectArray, i, lJavaString);
|
||||||
|
__android_log_write(ANDROID_LOG_INFO, 'lclapp', PChar('[TCDWidgetset.ShowSelectItemDialog] Adding string='+AItems.Strings[i]));
|
||||||
|
end;
|
||||||
|
lParams[1].i := -1;
|
||||||
|
lParams[2].l := javaEnvRef^^.GetObjectField(javaEnvRef, javaActivityClass, JavaField_lclselectitemcallback);
|
||||||
|
javaEnvRef^^.CallObjectMethodA(javaEnvRef, javaAlertDialog, javaMethod_AlertDialogBuilder_setSingleChoiceItems, @lParams[0]);
|
||||||
|
|
||||||
|
// ad.show();
|
||||||
|
javaMethod_AlertDialogBuilder_show := javaEnvRef^^.GetMethodID(javaEnvRef, javaAndroidAppAlertDialogBuilderClass, 'show', '()Landroid/app/AlertDialog;');
|
||||||
|
javaEnvRef^^.CallObjectMethod(javaEnvRef, javaAlertDialog, javaMethod_AlertDialogBuilder_show);
|
||||||
|
|
||||||
|
__android_log_write(ANDROID_LOG_INFO, 'lclapp', '[TCDWidgetset.ShowSelectItemDialog] END');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCDWidgetSet.ShowVirtualKeyboard;
|
procedure TCDWidgetSet.ShowVirtualKeyboard;
|
||||||
begin
|
begin
|
||||||
DebugLn('[TCDWidgetSet.ShowVirtualKeyboard]');
|
DebugLn('[TCDWidgetSet.ShowVirtualKeyboard]');
|
||||||
|
@ -82,6 +82,7 @@ procedure RemoveProcessEventHandler(var AHandler: PProcessEventHandler); overrid
|
|||||||
|
|
||||||
procedure SetEventHandlerFlags(AHandler: PEventHandler; NewFlags: dword); override;
|
procedure SetEventHandlerFlags(AHandler: PEventHandler; NewFlags: dword); override;
|
||||||
procedure SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect); override;*)
|
procedure SetRubberBandRect(const ARubberBand: HWND; const ARect: TRect); override;*)
|
||||||
|
function ShowSelectItemDialog(const AItems: TStrings): Boolean; override;
|
||||||
procedure ShowVirtualKeyboard();
|
procedure ShowVirtualKeyboard();
|
||||||
|
|
||||||
// No need to implement this one as the default is redirecting to ExtTextOut
|
// No need to implement this one as the default is redirecting to ExtTextOut
|
||||||
|
@ -106,17 +106,20 @@ begin
|
|||||||
CDWidgetset.DefaultFontAndroidSize := Round(16 * (Screen.PixelsPerInch / 125));
|
CDWidgetset.DefaultFontAndroidSize := Round(16 * (Screen.PixelsPerInch / 125));
|
||||||
// Now inform the application
|
// Now inform the application
|
||||||
if Assigned(CDWidgetset.ActivityOnCreate) then CDWidgetset.ActivityOnCreate()
|
if Assigned(CDWidgetset.ActivityOnCreate) then CDWidgetset.ActivityOnCreate()
|
||||||
else Application.Run; // <- Support for older code up to 21 dezember
|
else Application.Run; // <- Support for older code up to 21 dezember 2011
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// This one is for all simple dialogs: MessageBox, PromptUser (MessageDlg) and AskUser
|
// This one is for all simple dialogs: MessageBox, PromptUser (MessageDlg) and AskUser
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
||||||
env:PJNIEnv; this:jobject; AResult: jint): jint; cdecl;
|
env:PJNIEnv; this:jobject; AResult, ADialogType: jint): jint; cdecl;
|
||||||
begin
|
begin
|
||||||
//__android_log_write(ANDROID_LOG_INFO, 'lclapp', 'LCLOnCreate called by LCLActivity.onCreate');
|
__android_log_write(ANDROID_LOG_INFO, 'lclapp', 'LCLOnMessageBoxFinished called');
|
||||||
Result := 0;
|
Result := 0;
|
||||||
if Assigned(Application.OnMessageDialogFinished) then
|
case ADialogType of
|
||||||
Application.OnMessageDialogFinished(Application, AResult);
|
0: if Assigned(Application.OnMessageDialogFinished) then
|
||||||
|
Application.OnMessageDialogFinished(Application, AResult);
|
||||||
|
1: if Assigned(OnShowSelectItemDialogResult) then OnShowSelectItemDialogResult(AResult);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
||||||
@ -342,7 +345,7 @@ const NativeMethods: array[0..7] of JNINativeMethod=
|
|||||||
signature:'(Lcom/pascal/lcltest/LCLActivity;)I'; //android/app/Activity;
|
signature:'(Lcom/pascal/lcltest/LCLActivity;)I'; //android/app/Activity;
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnCreate;),
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnCreate;),
|
||||||
(name:'LCLOnMessageBoxFinished';
|
(name:'LCLOnMessageBoxFinished';
|
||||||
signature:'(I)I';
|
signature:'(II)I';
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished;),
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished;),
|
||||||
(name:'LCLOnKey';
|
(name:'LCLOnKey';
|
||||||
signature:'(IILandroid/view/KeyEvent;I)I';
|
signature:'(IILandroid/view/KeyEvent;I)I';
|
||||||
|
@ -32,6 +32,11 @@ type
|
|||||||
LCLControl: TCustomCheckBox;
|
LCLControl: TCustomCheckBox;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TCDIntfComboBox = class(TCDComboBox)
|
||||||
|
public
|
||||||
|
LCLControl: TCustomComboBox;
|
||||||
|
end;
|
||||||
|
|
||||||
// Additional Tab
|
// Additional Tab
|
||||||
|
|
||||||
TCDIntfStaticText = class(TCDProgressBar)
|
TCDIntfStaticText = class(TCDProgressBar)
|
||||||
|
@ -280,8 +280,8 @@ end;
|
|||||||
|
|
||||||
function RegisterCustomComboBox: Boolean; alias : 'WSRegisterCustomComboBox';
|
function RegisterCustomComboBox: Boolean; alias : 'WSRegisterCustomComboBox';
|
||||||
begin
|
begin
|
||||||
// RegisterWSComponent(TCustomComboBox, TWinCEWSCustomComboBox);
|
RegisterWSComponent(TCustomComboBox, TCDWSCustomComboBox);
|
||||||
Result := False;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RegisterCustomListBox: Boolean; alias : 'WSRegisterCustomListBox';
|
function RegisterCustomListBox: Boolean; alias : 'WSRegisterCustomListBox';
|
||||||
|
@ -40,7 +40,7 @@ uses
|
|||||||
lazutf8sysutils,
|
lazutf8sysutils,
|
||||||
// LCL
|
// LCL
|
||||||
Controls, LCLType, Forms, LCLProc, GraphType, IntfGraphics, lazcanvas,
|
Controls, LCLType, Forms, LCLProc, GraphType, IntfGraphics, lazcanvas,
|
||||||
lazregions, LCLIntf,
|
lazregions, LCLIntf, Lmessages,
|
||||||
customdrawncontrols,
|
customdrawncontrols,
|
||||||
// Widgetset
|
// Widgetset
|
||||||
InterfaceBase, WSForms, WSProc, WSLCLClasses, LCLMessageGlue,
|
InterfaceBase, WSForms, WSProc, WSLCLClasses, LCLMessageGlue,
|
||||||
|
@ -71,17 +71,24 @@ type
|
|||||||
{ TCDWSCustomComboBox }
|
{ TCDWSCustomComboBox }
|
||||||
|
|
||||||
TCDWSCustomComboBox = class(TWSCustomComboBox)
|
TCDWSCustomComboBox = class(TWSCustomComboBox)
|
||||||
|
public
|
||||||
|
class procedure InjectCDControl(const AWinControl: TWinControl; var ACDControlField: TCDControl);
|
||||||
published
|
published
|
||||||
{ class function CreateHandle(const AWinControl: TWinControl;
|
// TWSWinControl
|
||||||
const AParams: TCreateParams): TLCLIntfHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl;
|
||||||
class function GetDroppedDown(const ACustomComboBox: TCustomComboBox
|
const AParams: TCreateParams): HWND; override;
|
||||||
|
class procedure DestroyHandle(const AWinControl: TWinControl); override;
|
||||||
|
class procedure ShowHide(const AWinControl: TWinControl); override;
|
||||||
|
|
||||||
|
{ class function GetDroppedDown(const ACustomComboBox: TCustomComboBox
|
||||||
): Boolean; override;
|
): Boolean; override;
|
||||||
class function GetItemIndex(const ACustomComboBox: TCustomComboBox): integer; override;
|
class function GetItemIndex(const ACustomComboBox: TCustomComboBox): integer; override;}
|
||||||
class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; override;
|
class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; override;
|
||||||
class function GetMaxLength(const ACustomComboBox: TCustomComboBox): integer; override;
|
class procedure FreeItems(var AItems: TStrings); override;
|
||||||
|
// class function GetMaxLength(const ACustomComboBox: TCustomComboBox): integer; override;
|
||||||
class procedure GetPreferredSize(const AWinControl: TWinControl;
|
class procedure GetPreferredSize(const AWinControl: TWinControl;
|
||||||
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override;
|
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override;
|
||||||
class function GetSelStart(const ACustomComboBox: TCustomComboBox): integer; override;
|
{ class function GetSelStart(const ACustomComboBox: TCustomComboBox): integer; override;
|
||||||
class function GetSelLength(const ACustomComboBox: TCustomComboBox): integer; override;
|
class function GetSelLength(const ACustomComboBox: TCustomComboBox): integer; override;
|
||||||
class procedure SetSelStart(const ACustomComboBox: TCustomComboBox; NewStart: integer); override;
|
class procedure SetSelStart(const ACustomComboBox: TCustomComboBox; NewStart: integer); override;
|
||||||
class procedure SetSelLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;
|
class procedure SetSelLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;
|
||||||
@ -443,9 +450,365 @@ begin
|
|||||||
Widget.BeginUpdate;
|
Widget.BeginUpdate;
|
||||||
Widget.setVisible(AWinControl.HandleObjectShouldBeVisible);
|
Widget.setVisible(AWinControl.HandleObjectShouldBeVisible);
|
||||||
Widget.EndUpdate;
|
Widget.EndUpdate;
|
||||||
|
end;*)
|
||||||
|
|
||||||
|
{ TCDWSCustomGroupBox }
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TCDWSCustomGroupBox.CreateHandle
|
||||||
|
Params: None
|
||||||
|
Returns: Nothing
|
||||||
|
|
||||||
|
Allocates memory and resources for the control and shows it
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class function TCDWSCustomGroupBox.CreateHandle(const AWinControl: TWinControl;
|
||||||
|
const AParams: TCreateParams): TLCLIntfHandle;
|
||||||
|
var
|
||||||
|
lCDWinControl: TCDWinControl;
|
||||||
|
begin
|
||||||
|
Result := TCDWSWinControl.CreateHandle(AWinControl, AParams);
|
||||||
|
lCDWinControl := TCDWinControl(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCDWSCustomListBox }
|
(*class function TCDWSCustomGroupBox.GetDefaultClientRect(
|
||||||
|
const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
|
||||||
|
var aClientRect: TRect): boolean;
|
||||||
|
var
|
||||||
|
dx, dy: integer;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if AWinControl.HandleAllocated then
|
||||||
|
begin
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
dx := QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutLeftMargin) +
|
||||||
|
QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutRightMargin);
|
||||||
|
dy := QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutTopMargin) +
|
||||||
|
QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutBottomMargin);
|
||||||
|
|
||||||
|
aClientRect:=Rect(0,0,
|
||||||
|
Max(0, aWidth - dx),
|
||||||
|
Max(0, aHeight - dy));
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
end;*)
|
||||||
|
|
||||||
|
class procedure TCDWSCustomGroupBox.ShowHide(const AWinControl: TWinControl);
|
||||||
|
var
|
||||||
|
lCDWinControl: TCDWinControl;
|
||||||
|
begin
|
||||||
|
lCDWinControl := TCDWinControl(AWinControl.Handle);
|
||||||
|
|
||||||
|
TCDWSWinControl.ShowHide(AWinControl);
|
||||||
|
|
||||||
|
// if lCDWinControl.CDControl = nil then
|
||||||
|
// CreateCDControl(AWinControl, lCDWinControl.CDControl);
|
||||||
|
end;
|
||||||
|
|
||||||
|
(*{ TCDWSCustomComboBox }
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TCDWSCustomComboBox.CreateHandle
|
||||||
|
Params: None
|
||||||
|
Returns: Nothing
|
||||||
|
|
||||||
|
Allocates memory and resources for the control and shows it
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class function TCDWSCustomComboBox.CreateHandle(const AWinControl: TWinControl;
|
||||||
|
const AParams: TCreateParams): TLCLIntfHandle;
|
||||||
|
var
|
||||||
|
QtComboBox: TQtComboBox;
|
||||||
|
ItemIndex: Integer;
|
||||||
|
Text: String;
|
||||||
|
begin
|
||||||
|
QtComboBox := TQtComboBox.Create(AWinControl, AParams);
|
||||||
|
|
||||||
|
// create our FList helper
|
||||||
|
QtComboBox.FList := TQtComboStrings.Create(AWinControl, QtComboBox);
|
||||||
|
QtComboBox.setMaxVisibleItems(TCustomComboBox(AWinControl).DropDownCount);
|
||||||
|
|
||||||
|
// load combo data imediatelly and set LCLs itemIndex and Text otherwise
|
||||||
|
// qt will set itemindex to 0 if lcl itemindex = -1.
|
||||||
|
ItemIndex := TCustomComboBox(AWinControl).ItemIndex;
|
||||||
|
Text := TCustomComboBox(AWinControl).Text;
|
||||||
|
QtComboBox.FList.Assign(TCustomComboBox(AWinControl).Items);
|
||||||
|
QtComboBox.setCurrentIndex(ItemIndex);
|
||||||
|
QtComboBox.setText(GetUTF8String(Text));
|
||||||
|
QtComboBox.setEditable(AParams.Style and CBS_DROPDOWN <> 0);
|
||||||
|
|
||||||
|
QtComboBox.AttachEvents;
|
||||||
|
QtComboBox.OwnerDrawn := (AParams.Style and CBS_OWNERDRAWFIXED <> 0) or
|
||||||
|
(AParams.Style and CBS_OWNERDRAWVARIABLE <> 0);
|
||||||
|
|
||||||
|
Result := TLCLIntfHandle(QtComboBox);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCDWSCustomComboBox.GetDroppedDown(
|
||||||
|
const ACustomComboBox: TCustomComboBox): Boolean;
|
||||||
|
var
|
||||||
|
QtComboBox: TQtComboBox;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
if not ACustomComboBox.HandleAllocated then
|
||||||
|
exit;
|
||||||
|
QtComboBox := TQtComboBox(ACustomComboBox.Handle);
|
||||||
|
Result := QtComboBox.getDroppedDown;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TCDWSCustomComboBox.GetItemIndex
|
||||||
|
Params: None
|
||||||
|
Returns: The state of the control
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class function TCDWSCustomComboBox.GetItemIndex(
|
||||||
|
const ACustomComboBox: TCustomComboBox): integer;
|
||||||
|
var
|
||||||
|
QtComboBox: TQtComboBox;
|
||||||
|
WStr: WideString;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result := -1;
|
||||||
|
if not WSCheckHandleAllocated(ACustomComboBox, 'GetItemIndex') then
|
||||||
|
Exit;
|
||||||
|
QtComboBox := TQtComboBox(ACustomComboBox.Handle);
|
||||||
|
if QtComboBox.getEditable then
|
||||||
|
begin
|
||||||
|
WStr := QtComboBox.getText;
|
||||||
|
i := QComboBox_findText(QComboBoxH(QtComboBox.Widget), @WStr);
|
||||||
|
Result := i;
|
||||||
|
end else
|
||||||
|
Result := TQtComboBox(ACustomComboBox.Handle).currentIndex;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCDWSCustomComboBox.GetMaxLength(
|
||||||
|
const ACustomComboBox: TCustomComboBox): integer;
|
||||||
|
var
|
||||||
|
LineEdit: TQtLineEdit;
|
||||||
|
begin
|
||||||
|
LineEdit := TQtComboBox(ACustomComboBox.Handle).LineEdit;
|
||||||
|
if LineEdit <> nil then
|
||||||
|
begin
|
||||||
|
Result := LineEdit.getMaxLength;
|
||||||
|
if Result = QtMaxEditLength then
|
||||||
|
Result := 0;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCDWSCustomComboBox.GetSelStart(const ACustomComboBox: TCustomComboBox): integer;
|
||||||
|
var
|
||||||
|
Widget: TQtWidget;
|
||||||
|
QtEdit: IQtEdit;
|
||||||
|
begin
|
||||||
|
Result := 0;
|
||||||
|
if not WSCheckHandleAllocated(ACustomComboBox, 'GetSelStart') then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
Widget := TQtWidget(ACustomComboBox.Handle);
|
||||||
|
if Supports(Widget, IQtEdit, QtEdit) then
|
||||||
|
Result := QtEdit.getSelectionStart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCDWSCustomComboBox.GetSelLength(const ACustomComboBox: TCustomComboBox): integer;
|
||||||
|
var
|
||||||
|
Widget: TQtWidget;
|
||||||
|
QtEdit: IQtEdit;
|
||||||
|
begin
|
||||||
|
Result := 0;
|
||||||
|
if not WSCheckHandleAllocated(ACustomComboBox, 'GetSelLength') then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
Widget := TQtWidget(ACustomComboBox.Handle);
|
||||||
|
if Supports(Widget, IQtEdit, QtEdit) then
|
||||||
|
Result := QtEdit.getSelectionLength;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.SetSelStart(const ACustomComboBox: TCustomComboBox;
|
||||||
|
NewStart: integer);
|
||||||
|
var
|
||||||
|
Widget: TQtWidget;
|
||||||
|
QtEdit: IQtEdit;
|
||||||
|
ALength: Integer;
|
||||||
|
begin
|
||||||
|
if not WSCheckHandleAllocated(ACustomComboBox, 'SetSelStart') then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
Widget := TQtWidget(ACustomComboBox.Handle);
|
||||||
|
ALength := GetSelLength(ACustomComboBox);
|
||||||
|
if Supports(Widget, IQtEdit, QtEdit) then
|
||||||
|
QtEdit.setSelection(NewStart, ALength);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.SetSelLength(
|
||||||
|
const ACustomComboBox: TCustomComboBox; NewLength: integer);
|
||||||
|
var
|
||||||
|
Widget: TQtWidget;
|
||||||
|
QtEdit: IQtEdit;
|
||||||
|
AStart: Integer;
|
||||||
|
begin
|
||||||
|
if not WSCheckHandleAllocated(ACustomComboBox, 'SetSelLength') then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
Widget := TQtWidget(ACustomComboBox.Handle);
|
||||||
|
AStart := GetSelStart(ACustomComboBox);
|
||||||
|
if Supports(Widget, IQtEdit, QtEdit) then
|
||||||
|
QtEdit.setSelection(AStart, NewLength);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.SetArrowKeysTraverseList(
|
||||||
|
const ACustomComboBox: TCustomComboBox; NewTraverseList: boolean);
|
||||||
|
begin
|
||||||
|
{$note implement TCDWSCustomComboBox.SetArrowKeysTraverseList}
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.SetDropDownCount(
|
||||||
|
const ACustomComboBox: TCustomComboBox; NewCount: Integer);
|
||||||
|
begin
|
||||||
|
TQtComboBox(ACustomComboBox.Handle).setMaxVisibleItems(NewCount);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.SetDroppedDown(
|
||||||
|
const ACustomComboBox: TCustomComboBox; ADroppedDown: Boolean);
|
||||||
|
var
|
||||||
|
QtComboBox: TQtComboBox;
|
||||||
|
begin
|
||||||
|
QtComboBox := TQtComboBox(ACustomComboBox.Handle);
|
||||||
|
QtComboBox.setDroppedDown(ADroppedDown);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Method: TCDWSCustomComboBox.SetItemIndex
|
||||||
|
Params: None
|
||||||
|
Returns: The state of the control
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class procedure TCDWSCustomComboBox.SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer);
|
||||||
|
begin
|
||||||
|
TQtComboBox(ACustomComboBox.Handle).setCurrentIndex(NewIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.SetMaxLength(
|
||||||
|
const ACustomComboBox: TCustomComboBox; NewLength: integer);
|
||||||
|
var
|
||||||
|
Widget: TQtWidget;
|
||||||
|
QtEdit: IQtEdit;
|
||||||
|
MaxLength: Integer;
|
||||||
|
begin
|
||||||
|
if not WSCheckHandleAllocated(ACustomComboBox, 'SetMaxLength') then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
Widget := TQtWidget(ACustomComboBox.Handle);
|
||||||
|
if Supports(Widget, IQtEdit, QtEdit) then
|
||||||
|
begin
|
||||||
|
// qt doesn't accept -1
|
||||||
|
MaxLength := QtEdit.getMaxLength;
|
||||||
|
if (NewLength <= 0) or (NewLength > QtMaxEditLength) then
|
||||||
|
NewLength := QtMaxEditLength;
|
||||||
|
if NewLength <> MaxLength then
|
||||||
|
QtEdit.setMaxLength(NewLength);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.SetStyle(
|
||||||
|
const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle);
|
||||||
|
begin
|
||||||
|
TQtComboBox(ACustomComboBox.Handle).setEditable(NewStyle = csDropDown);
|
||||||
|
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle in
|
||||||
|
[csOwnerDrawFixed,
|
||||||
|
csOwnerDrawVariable];
|
||||||
|
// TODO: implement styles: csSimple
|
||||||
|
inherited SetStyle(ACustomComboBox, NewStyle);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.Sort(
|
||||||
|
const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean);
|
||||||
|
begin
|
||||||
|
TQtComboStrings(AList).Sorted := IsSorted;
|
||||||
|
end;*)
|
||||||
|
|
||||||
|
{ TCDWSCustomComboBox }
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.InjectCDControl(
|
||||||
|
const AWinControl: TWinControl; var ACDControlField: TCDControl);
|
||||||
|
begin
|
||||||
|
TCDIntfComboBox(ACDControlField).LCLControl := TCustomComboBox(AWinControl);
|
||||||
|
ACDControlField.Caption := AWinControl.Caption;
|
||||||
|
ACDControlField.Parent := AWinControl;
|
||||||
|
ACDControlField.Align := alClient;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCDWSCustomComboBox.CreateHandle(const AWinControl: TWinControl;
|
||||||
|
const AParams: TCreateParams): HWND;
|
||||||
|
var
|
||||||
|
lCDWinControl: TCDWinControl;
|
||||||
|
begin
|
||||||
|
Result := TCDWSWinControl.CreateHandle(AWinControl, AParams);
|
||||||
|
lCDWinControl := TCDWinControl(Result);
|
||||||
|
lCDWinControl.CDControl := TCDIntfComboBox.Create(AWinControl);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.DestroyHandle(const AWinControl: TWinControl);
|
||||||
|
var
|
||||||
|
lCDWinControl: TCDWinControl;
|
||||||
|
begin
|
||||||
|
lCDWinControl := TCDWinControl(AWinControl.Handle);
|
||||||
|
lCDWinControl.CDControl.Free;
|
||||||
|
lCDWinControl.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.ShowHide(const AWinControl: TWinControl);
|
||||||
|
var
|
||||||
|
lCDWinControl: TCDWinControl;
|
||||||
|
begin
|
||||||
|
lCDWinControl := TCDWinControl(AWinControl.Handle);
|
||||||
|
|
||||||
|
TCDWSWinControl.ShowHide(AWinControl);
|
||||||
|
|
||||||
|
if not lCDWinControl.CDControlInjected then
|
||||||
|
begin
|
||||||
|
InjectCDControl(AWinControl, lCDWinControl.CDControl);
|
||||||
|
lCDWinControl.CDControlInjected := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCDWSCustomComboBox.GetItems(
|
||||||
|
const ACustomComboBox: TCustomComboBox): TStrings;
|
||||||
|
var
|
||||||
|
lCDWinControl: TCDWinControl;
|
||||||
|
begin
|
||||||
|
lCDWinControl := TCDWinControl(ACustomComboBox.Handle);
|
||||||
|
Result := TCDComboBox(lCDWinControl.CDControl).Items;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCDWSCustomComboBox.FreeItems(var AItems: TStrings);
|
||||||
|
begin
|
||||||
|
//Widgetset atomatically frees the items, so override
|
||||||
|
//and do not call inherited.
|
||||||
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
Set's the size of a TComboBox when autosized
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
class procedure TCDWSCustomComboBox.GetPreferredSize(
|
||||||
|
const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
|
||||||
|
WithThemeSpace: Boolean);
|
||||||
|
var
|
||||||
|
lCDWinControl: TCDWinControl;
|
||||||
|
lIntfComboBox: TCDIntfComboBox;
|
||||||
|
begin
|
||||||
|
// ToDo: Do something to correct the combobox height when autosized, now something in the LCL seams to hardcode it to 50...
|
||||||
|
{ lCDWinControl := TCDWinControl(AWinControl.Handle);
|
||||||
|
lIntfComboBox := TCDIntfComboBox(lCDWinControl.CDControl);
|
||||||
|
if lIntfComboBox.OriginalHeight = 0 then lIntfComboBox.OriginalHeight := AWinControl.Height;
|
||||||
|
PreferredHeight := lIntfComboBox.OriginalHeight;
|
||||||
|
//AWinControl.Height := PreferredHeight;}
|
||||||
|
|
||||||
|
// The correct behavior for the LCL is not forcing any specific value for
|
||||||
|
// TComboBox.Width, so we set it to zero to signal that here
|
||||||
|
PreferredWidth := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
(*{ TCDWSCustomListBox }
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TCDWSCustomListBox.CreateHandle
|
Method: TCDWSCustomListBox.CreateHandle
|
||||||
@ -1358,318 +1721,8 @@ begin
|
|||||||
QtRadioButton.AttachEvents;
|
QtRadioButton.AttachEvents;
|
||||||
|
|
||||||
Result := TLCLIntfHandle(QtRadioButton);
|
Result := TLCLIntfHandle(QtRadioButton);
|
||||||
end;*)
|
|
||||||
|
|
||||||
{ TCDWSCustomGroupBox }
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Method: TCDWSCustomGroupBox.CreateHandle
|
|
||||||
Params: None
|
|
||||||
Returns: Nothing
|
|
||||||
|
|
||||||
Allocates memory and resources for the control and shows it
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
class function TCDWSCustomGroupBox.CreateHandle(const AWinControl: TWinControl;
|
|
||||||
const AParams: TCreateParams): TLCLIntfHandle;
|
|
||||||
var
|
|
||||||
lCDWinControl: TCDWinControl;
|
|
||||||
begin
|
|
||||||
Result := TCDWSWinControl.CreateHandle(AWinControl, AParams);
|
|
||||||
lCDWinControl := TCDWinControl(Result);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
(*class function TCDWSCustomGroupBox.GetDefaultClientRect(
|
|
||||||
const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
|
|
||||||
var aClientRect: TRect): boolean;
|
|
||||||
var
|
|
||||||
dx, dy: integer;
|
|
||||||
begin
|
|
||||||
Result:=false;
|
|
||||||
if AWinControl.HandleAllocated then
|
|
||||||
begin
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
dx := QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutLeftMargin) +
|
|
||||||
QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutRightMargin);
|
|
||||||
dy := QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutTopMargin) +
|
|
||||||
QStyle_pixelMetric(QApplication_style(), QStylePM_LayoutBottomMargin);
|
|
||||||
|
|
||||||
aClientRect:=Rect(0,0,
|
|
||||||
Max(0, aWidth - dx),
|
|
||||||
Max(0, aHeight - dy));
|
|
||||||
Result:=true;
|
|
||||||
end;
|
|
||||||
end;*)
|
|
||||||
|
|
||||||
class procedure TCDWSCustomGroupBox.ShowHide(const AWinControl: TWinControl);
|
|
||||||
var
|
|
||||||
lCDWinControl: TCDWinControl;
|
|
||||||
begin
|
|
||||||
lCDWinControl := TCDWinControl(AWinControl.Handle);
|
|
||||||
|
|
||||||
TCDWSWinControl.ShowHide(AWinControl);
|
|
||||||
|
|
||||||
// if lCDWinControl.CDControl = nil then
|
|
||||||
// CreateCDControl(AWinControl, lCDWinControl.CDControl);
|
|
||||||
end;
|
|
||||||
|
|
||||||
(*{ TCDWSCustomComboBox }
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Method: TCDWSCustomComboBox.CreateHandle
|
|
||||||
Params: None
|
|
||||||
Returns: Nothing
|
|
||||||
|
|
||||||
Allocates memory and resources for the control and shows it
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
class function TCDWSCustomComboBox.CreateHandle(const AWinControl: TWinControl;
|
|
||||||
const AParams: TCreateParams): TLCLIntfHandle;
|
|
||||||
var
|
|
||||||
QtComboBox: TQtComboBox;
|
|
||||||
ItemIndex: Integer;
|
|
||||||
Text: String;
|
|
||||||
begin
|
|
||||||
QtComboBox := TQtComboBox.Create(AWinControl, AParams);
|
|
||||||
|
|
||||||
// create our FList helper
|
|
||||||
QtComboBox.FList := TQtComboStrings.Create(AWinControl, QtComboBox);
|
|
||||||
QtComboBox.setMaxVisibleItems(TCustomComboBox(AWinControl).DropDownCount);
|
|
||||||
|
|
||||||
// load combo data imediatelly and set LCLs itemIndex and Text otherwise
|
|
||||||
// qt will set itemindex to 0 if lcl itemindex = -1.
|
|
||||||
ItemIndex := TCustomComboBox(AWinControl).ItemIndex;
|
|
||||||
Text := TCustomComboBox(AWinControl).Text;
|
|
||||||
QtComboBox.FList.Assign(TCustomComboBox(AWinControl).Items);
|
|
||||||
QtComboBox.setCurrentIndex(ItemIndex);
|
|
||||||
QtComboBox.setText(GetUTF8String(Text));
|
|
||||||
QtComboBox.setEditable(AParams.Style and CBS_DROPDOWN <> 0);
|
|
||||||
|
|
||||||
QtComboBox.AttachEvents;
|
|
||||||
QtComboBox.OwnerDrawn := (AParams.Style and CBS_OWNERDRAWFIXED <> 0) or
|
|
||||||
(AParams.Style and CBS_OWNERDRAWVARIABLE <> 0);
|
|
||||||
|
|
||||||
Result := TLCLIntfHandle(QtComboBox);
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TCDWSCustomComboBox.GetDroppedDown(
|
|
||||||
const ACustomComboBox: TCustomComboBox): Boolean;
|
|
||||||
var
|
|
||||||
QtComboBox: TQtComboBox;
|
|
||||||
begin
|
|
||||||
Result := False;
|
|
||||||
if not ACustomComboBox.HandleAllocated then
|
|
||||||
exit;
|
|
||||||
QtComboBox := TQtComboBox(ACustomComboBox.Handle);
|
|
||||||
Result := QtComboBox.getDroppedDown;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Method: TCDWSCustomComboBox.GetItemIndex
|
|
||||||
Params: None
|
|
||||||
Returns: The state of the control
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
class function TCDWSCustomComboBox.GetItemIndex(
|
|
||||||
const ACustomComboBox: TCustomComboBox): integer;
|
|
||||||
var
|
|
||||||
QtComboBox: TQtComboBox;
|
|
||||||
WStr: WideString;
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
Result := -1;
|
|
||||||
if not WSCheckHandleAllocated(ACustomComboBox, 'GetItemIndex') then
|
|
||||||
Exit;
|
|
||||||
QtComboBox := TQtComboBox(ACustomComboBox.Handle);
|
|
||||||
if QtComboBox.getEditable then
|
|
||||||
begin
|
|
||||||
WStr := QtComboBox.getText;
|
|
||||||
i := QComboBox_findText(QComboBoxH(QtComboBox.Widget), @WStr);
|
|
||||||
Result := i;
|
|
||||||
end else
|
|
||||||
Result := TQtComboBox(ACustomComboBox.Handle).currentIndex;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TCDWSCustomComboBox.GetMaxLength(
|
|
||||||
const ACustomComboBox: TCustomComboBox): integer;
|
|
||||||
var
|
|
||||||
LineEdit: TQtLineEdit;
|
|
||||||
begin
|
|
||||||
LineEdit := TQtComboBox(ACustomComboBox.Handle).LineEdit;
|
|
||||||
if LineEdit <> nil then
|
|
||||||
begin
|
|
||||||
Result := LineEdit.getMaxLength;
|
|
||||||
if Result = QtMaxEditLength then
|
|
||||||
Result := 0;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := 0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Set's the size of a TComboBox when autosized
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
class procedure TCDWSCustomComboBox.GetPreferredSize(
|
|
||||||
const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
|
|
||||||
WithThemeSpace: Boolean);
|
|
||||||
begin
|
|
||||||
if AWinControl.HandleAllocated then
|
|
||||||
TQtWidget(AWinControl.Handle).PreferredSize(PreferredWidth,
|
|
||||||
PreferredHeight, WithThemeSpace);
|
|
||||||
|
|
||||||
// The correct behavior for the LCL is not forcing any specific value for
|
|
||||||
// TComboBox.Width, so we set it to zero to signal that here
|
|
||||||
PreferredWidth := 0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TCDWSCustomComboBox.GetSelStart(const ACustomComboBox: TCustomComboBox): integer;
|
|
||||||
var
|
|
||||||
Widget: TQtWidget;
|
|
||||||
QtEdit: IQtEdit;
|
|
||||||
begin
|
|
||||||
Result := 0;
|
|
||||||
if not WSCheckHandleAllocated(ACustomComboBox, 'GetSelStart') then
|
|
||||||
Exit;
|
|
||||||
|
|
||||||
Widget := TQtWidget(ACustomComboBox.Handle);
|
|
||||||
if Supports(Widget, IQtEdit, QtEdit) then
|
|
||||||
Result := QtEdit.getSelectionStart;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TCDWSCustomComboBox.GetSelLength(const ACustomComboBox: TCustomComboBox): integer;
|
|
||||||
var
|
|
||||||
Widget: TQtWidget;
|
|
||||||
QtEdit: IQtEdit;
|
|
||||||
begin
|
|
||||||
Result := 0;
|
|
||||||
if not WSCheckHandleAllocated(ACustomComboBox, 'GetSelLength') then
|
|
||||||
Exit;
|
|
||||||
|
|
||||||
Widget := TQtWidget(ACustomComboBox.Handle);
|
|
||||||
if Supports(Widget, IQtEdit, QtEdit) then
|
|
||||||
Result := QtEdit.getSelectionLength;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.SetSelStart(const ACustomComboBox: TCustomComboBox;
|
|
||||||
NewStart: integer);
|
|
||||||
var
|
|
||||||
Widget: TQtWidget;
|
|
||||||
QtEdit: IQtEdit;
|
|
||||||
ALength: Integer;
|
|
||||||
begin
|
|
||||||
if not WSCheckHandleAllocated(ACustomComboBox, 'SetSelStart') then
|
|
||||||
Exit;
|
|
||||||
|
|
||||||
Widget := TQtWidget(ACustomComboBox.Handle);
|
|
||||||
ALength := GetSelLength(ACustomComboBox);
|
|
||||||
if Supports(Widget, IQtEdit, QtEdit) then
|
|
||||||
QtEdit.setSelection(NewStart, ALength);
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.SetSelLength(
|
|
||||||
const ACustomComboBox: TCustomComboBox; NewLength: integer);
|
|
||||||
var
|
|
||||||
Widget: TQtWidget;
|
|
||||||
QtEdit: IQtEdit;
|
|
||||||
AStart: Integer;
|
|
||||||
begin
|
|
||||||
if not WSCheckHandleAllocated(ACustomComboBox, 'SetSelLength') then
|
|
||||||
Exit;
|
|
||||||
|
|
||||||
Widget := TQtWidget(ACustomComboBox.Handle);
|
|
||||||
AStart := GetSelStart(ACustomComboBox);
|
|
||||||
if Supports(Widget, IQtEdit, QtEdit) then
|
|
||||||
QtEdit.setSelection(AStart, NewLength);
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.SetArrowKeysTraverseList(
|
|
||||||
const ACustomComboBox: TCustomComboBox; NewTraverseList: boolean);
|
|
||||||
begin
|
|
||||||
{$note implement TCDWSCustomComboBox.SetArrowKeysTraverseList}
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.SetDropDownCount(
|
|
||||||
const ACustomComboBox: TCustomComboBox; NewCount: Integer);
|
|
||||||
begin
|
|
||||||
TQtComboBox(ACustomComboBox.Handle).setMaxVisibleItems(NewCount);
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.SetDroppedDown(
|
|
||||||
const ACustomComboBox: TCustomComboBox; ADroppedDown: Boolean);
|
|
||||||
var
|
|
||||||
QtComboBox: TQtComboBox;
|
|
||||||
begin
|
|
||||||
QtComboBox := TQtComboBox(ACustomComboBox.Handle);
|
|
||||||
QtComboBox.setDroppedDown(ADroppedDown);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Method: TCDWSCustomComboBox.SetItemIndex
|
|
||||||
Params: None
|
|
||||||
Returns: The state of the control
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
class procedure TCDWSCustomComboBox.SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer);
|
|
||||||
begin
|
|
||||||
TQtComboBox(ACustomComboBox.Handle).setCurrentIndex(NewIndex);
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.SetMaxLength(
|
|
||||||
const ACustomComboBox: TCustomComboBox; NewLength: integer);
|
|
||||||
var
|
|
||||||
Widget: TQtWidget;
|
|
||||||
QtEdit: IQtEdit;
|
|
||||||
MaxLength: Integer;
|
|
||||||
begin
|
|
||||||
if not WSCheckHandleAllocated(ACustomComboBox, 'SetMaxLength') then
|
|
||||||
Exit;
|
|
||||||
|
|
||||||
Widget := TQtWidget(ACustomComboBox.Handle);
|
|
||||||
if Supports(Widget, IQtEdit, QtEdit) then
|
|
||||||
begin
|
|
||||||
// qt doesn't accept -1
|
|
||||||
MaxLength := QtEdit.getMaxLength;
|
|
||||||
if (NewLength <= 0) or (NewLength > QtMaxEditLength) then
|
|
||||||
NewLength := QtMaxEditLength;
|
|
||||||
if NewLength <> MaxLength then
|
|
||||||
QtEdit.setMaxLength(NewLength);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.SetStyle(
|
|
||||||
const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle);
|
|
||||||
begin
|
|
||||||
TQtComboBox(ACustomComboBox.Handle).setEditable(NewStyle = csDropDown);
|
|
||||||
TQtComboBox(ACustomComboBox.Handle).OwnerDrawn := NewStyle in
|
|
||||||
[csOwnerDrawFixed,
|
|
||||||
csOwnerDrawVariable];
|
|
||||||
// TODO: implement styles: csSimple
|
|
||||||
inherited SetStyle(ACustomComboBox, NewStyle);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Method: TCDWSCustomComboBox.GetItems
|
|
||||||
Params: None
|
|
||||||
Returns: ComboBox items
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
class function TCDWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox): TStrings;
|
|
||||||
var
|
|
||||||
ComboBox: TQtComboBox;
|
|
||||||
begin
|
|
||||||
ComboBox := TQtComboBox(ACustomComboBox.Handle);
|
|
||||||
if not Assigned(ComboBox.FList) then
|
|
||||||
begin
|
|
||||||
ComboBox.BeginUpdate;
|
|
||||||
ComboBox.FList := TQtComboStrings.Create(ACustomComboBox, ComboBox);
|
|
||||||
ComboBox.EndUpdate;
|
|
||||||
end;
|
|
||||||
Result := ComboBox.FList;
|
|
||||||
end;
|
|
||||||
|
|
||||||
class procedure TCDWSCustomComboBox.Sort(
|
|
||||||
const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean);
|
|
||||||
begin
|
|
||||||
TQtComboStrings(AList).Sorted := IsSorted;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TCDWSToggleBox }
|
{ TCDWSToggleBox }
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user