2019-07-28 23:53:15 +03:00
// Copyright (©) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
2018-01-05 12:55:13 +03:00
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
2020-08-01 00:13:27 +03:00
///Модуль элементов управления для GraphWPF, WPFObjects и Graph3D
2018-01-05 12:55:13 +03:00
unit Controls;
interface
2020-08-01 00:13:27 +03:00
uses GraphWPFBase;
2018-01-05 12:55:13 +03:00
uses System. Windows;
uses System. Windows. Media;
2020-07-20 11:36:38 +03:00
uses System. Windows. Media. Imaging;
2018-01-05 12:55:13 +03:00
uses System. Windows. Controls;
2020-07-20 09:27:50 +03:00
uses System. Windows. Controls. Primitives;
2019-08-16 09:48:11 +03:00
uses System. ComponentModel;
2018-01-05 12:55:13 +03:00
2020-07-20 09:27:50 +03:00
const PanelsColor = Colors. WhiteSmoke;
2018-01-05 12:55:13 +03:00
type
2020-07-20 09:27:50 +03:00
Dock = System. Windows. Controls. Dock;
2018-01-05 12:55:13 +03:00
GButton = System. Windows. Controls. Button;
GTextBlock = System. Windows. Controls. TextBlock;
GTextBox = System. Windows. Controls. TextBox;
2019-08-16 09:48:11 +03:00
GListBox = System. Windows. Controls. ListBox;
2020-07-20 09:27:50 +03:00
GPanel = System. Windows. Controls. Panel;
GControl = System. Windows. Controls. Control;
GStatusBar = System. Windows. Controls. Primitives. StatusBar;
2020-08-03 21:26:25 +03:00
Orientation = System. Windows. Controls. Orientation;
2020-07-25 23:25:47 +03:00
MessageBox = System. Windows. MessageBox;
MessageBoxButton = System. Windows. MessageBoxButton;
MessageBoxResult = System. Windows. MessageBoxResult;
MessageBoxImage = System. Windows. MessageBoxImage;
/// Н а б о р предопределённых цветов
2020-07-20 09:27:50 +03:00
Colors = System. Windows. Media. Colors;
2019-08-18 00:16:39 +03:00
Key = System. Windows. Input. Key;
2020-07-20 09:27:50 +03:00
var
2020-08-01 00:13:27 +03:00
_ActivePanel: GPanel;
2020-07-20 09:27:50 +03:00
GlobalHMargin : = 1 2 ;
2020-08-01 00:13:27 +03:00
function __ActivePanelInternal: GPanel;
procedure __SetActivePanelInternal( p: GPanel) ;
2020-07-20 09:27:50 +03:00
2020-07-24 22:00:21 +03:00
procedure Invoke( d: System. Delegate; params args: array of object ) ;
procedure InvokeP( p: procedure( r: real ) ; r: real ) ;
2020-07-20 09:27:50 +03:00
type
2021-07-13 23:52:47 +03:00
///!#
/// Базовый класс для всех элементов управления
CommonElementWPF = class
protected
element: FrameworkElement;
procedure Init0( el: FrameworkElement; width: real : = 0 ; x: real : = - 1 ; y: real : = - 1 ) ;
private
procedure SetWP( w: real ) : = element. Width : = w;
procedure SetHP( h: real ) : = element. Height : = h;
procedure SetMPB( m: real ) : = element. Margin : = new Thickness( 0 , 0 , 0 , m) ;
procedure SetMPs( m: ( real , real , real , real ) ) : = element. Margin : = new Thickness( m[ 0 ] , m[ 1 ] , m[ 2 ] , m[ 3 ] ) ;
procedure SetTTP( s: string ) : = element. Tooltip : = s;
procedure SetEP( enabled: boolean ) : = element. IsEnabled : = enabled;
public
/// Ширина элемента управления
property Width: real read InvokeReal( ( ) - > element. Width) write Invoke( SetWP, value) ;
/// Высота элемента управления
property Height: real read InvokeReal( ( ) - > element. Height) write Invoke( SetHP, value) ; virtual ;
/// Отступ элемента управления
//property Margin: real read InvokeReal(()->element.Margin.Bottom) write Invoke(SetMPB, value);
/// Нижний отступ элемента управления
property BottomMargin: real read InvokeReal( ( ) - > element. Margin. Bottom) write Invoke( SetMPB, value) ;
/// Отступы элемента управления
property Margins: ( real , real , real , real )
//read InvokeReal(()->element.Margin.Bottom)
write Invoke( SetMPs, value) ;
/// Активирован ли элемент управления
property Enabled: boolean read InvokeBoolean( ( ) - > element. IsEnabled) write Invoke( SetEP, value) ;
/// Всплывающая подсказка
property Tooltip: string read Invokestring( ( ) - > element. ToolTip as string ) write Invoke( SetTTP, value) ;
end ;
2018-01-05 12:55:13 +03:00
///!#
2020-07-25 23:25:47 +03:00
/// Базовый класс для панелей
2021-07-13 23:52:47 +03:00
PanelWPF = class( CommonElementWPF)
2020-08-12 15:22:16 +03:00
public
fsize: real : = 1 2 ;
2020-07-25 23:25:47 +03:00
private
2020-07-20 09:27:50 +03:00
bb: Border;
2021-07-13 23:52:47 +03:00
property p: StackPanel read element as StackPanel;
2020-07-20 09:27:50 +03:00
procedure CreateP( wh: real ; d: Dock; c: Color; InternalMargin: real ) ;
begin
bb : = new Border( ) ;
bb. Background : = new SolidColorBrush( c) ;
2021-07-13 23:52:47 +03:00
var p : = new StackPanel;
element : = p;
2020-07-20 09:27:50 +03:00
bb. Child : = p;
p. Background : = GetBrush( c) ;
p. Margin : = new System. Windows. Thickness( InternalMargin) ;
if ( d = Dock. Left) or ( d = Dock. Right) then
begin
p. Orientation : = Orientation. Vertical;
bb. Width : = wh;
end
else
begin
p. Orientation : = Orientation. Horizontal;
bb. Height : = wh;
end ;
DockPanel. SetDock( bb, d) ;
MainDockPanel. children. Insert( 0 , bb) ;
2020-08-01 00:13:27 +03:00
//ActivePanel := p;
__SetActivePanelInternal( p) ;
2020-08-12 15:22:16 +03:00
p. Tag : = Self;
2020-07-20 09:27:50 +03:00
end ;
procedure SetColorP( c: GColor) ;
begin
p. Background : = GetBrush( c) ;
bb. Background : = p. Background
end ;
function GetColorP : = ( p. Background as SolidColorBrush) . Color;
2020-08-12 15:22:16 +03:00
procedure SetTTP( s: string ) : = p. ToolTip : = s;
static procedure SetFSzPP( p: GPanel; value: real ) ;
begin
if value< = 0 then exit;
foreach var c: FrameworkElement in p. Children do
SetFSzElement( c, value) ;
end ;
static procedure SetFSzElement( c: FrameworkElement; value: real ) ;
begin
if value< = 0 then exit;
if c is GControl then
( c as GControl) . FontSize : = value
else if c is GTextBlock then
( c as GTextBlock) . FontSize : = value
else if c is GPanel then
SetFSzPP( c as GPanel, value) ;
end ;
procedure SetFSzP( value: real ) ;
2020-08-01 00:13:27 +03:00
begin
2020-08-12 15:22:16 +03:00
if value< = 0 then exit;
fsize : = value;
SetFSzPP( Self. p, value) ;
2020-08-01 00:13:27 +03:00
end ;
2020-07-20 09:27:50 +03:00
public
2021-04-21 11:54:06 +03:00
constructor Create( wh: real ; d: Dock; c: Color; internalMargin: real ) ;
2020-07-20 09:27:50 +03:00
begin
Invoke( CreateP, wh, d, c, internalMargin) ;
end ;
2021-04-21 11:54:06 +03:00
constructor Create( wh: real ; d: Dock; c: Color) : = Create( wh, d, c, 1 0 ) ;
constructor Create( wh: real : = 1 5 0 ; d: Dock : = Dock. Left) : = Create( wh, d, PanelsColor, 1 0 ) ;
2020-08-01 00:13:27 +03:00
/// Цвет
2020-07-20 09:27:50 +03:00
property Color: GColor read Invoke& < GColor> ( GetColorP) write Invoke( SetColorP, value) ;
2020-08-01 00:13:27 +03:00
/// Ширина внутренней границы
2020-07-20 09:27:50 +03:00
property InternalMargin: real
read InvokeReal( ( ) - > p. Margin. Left)
write Invoke( procedure - > p. Margin : = new System. Windows. Thickness( internalMargin) , value) ;
2020-08-01 00:13:27 +03:00
/// Всплывающая подсказка
property Tooltip: string read Invokestring( ( ) - > p. ToolTip as string ) write Invoke( SetTTP, value) ;
2020-08-12 15:22:16 +03:00
/// Размер шрифта
property FontSize: real read fsize write Invoke( SetFSzP, value) ; virtual ;
/// Имя шрифта
//property FontName: string write Invoke(SetFontNameP, value); virtual;
2020-07-20 09:27:50 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Класс левой панели
2020-07-20 09:27:50 +03:00
LeftPanelWPF = class( PanelWPF)
public
2021-04-21 11:54:06 +03:00
constructor Create( width: real ; c: GColor; internalMargin: real ) ;
2020-07-20 09:27:50 +03:00
begin
inherited Create( width, Dock. Left, c, internalMargin)
end ;
2021-04-21 11:54:06 +03:00
constructor Create( width: real ; c: GColor) : = Create( width, c, 1 0 ) ;
constructor Create( width: real : = 1 5 0 ) : = Create( width, PanelsColor, 1 0 ) ;
2020-07-20 09:27:50 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Класс правой панели
2020-07-20 09:27:50 +03:00
RightPanelWPF = class( PanelWPF)
public
2021-04-21 11:54:06 +03:00
constructor Create( width: real ; c: GColor; internalMargin: real ) ;
2020-07-20 09:27:50 +03:00
begin
inherited Create( width, Dock. Right, c, internalMargin)
end ;
2021-04-21 11:54:06 +03:00
constructor Create( width: real ; c: GColor) : = Create( width, c, 1 0 ) ;
constructor Create( width: real : = 1 5 0 ) : = Create( width, PanelsColor, 1 0 ) ;
2020-07-20 09:27:50 +03:00
end ;
CommonControlWPF = class( CommonElementWPF)
private
property Control: GControl read element as GControl;
2020-08-12 15:22:16 +03:00
procedure SetFSzP( size: real ) : = if size > 0 then control. FontSize : = size;
2020-07-25 23:25:47 +03:00
procedure SetFontNameP( name : string ) : = control. FontFamily : = new FontFamily( name ) ;
2020-07-24 22:00:21 +03:00
public
2020-07-25 23:25:47 +03:00
/// Размер шрифта
2020-07-24 22:00:21 +03:00
property FontSize: real read InvokeReal( ( ) - > control. FontSize) write Invoke( SetFSzP, value) ; virtual ;
2020-07-25 23:25:47 +03:00
/// Имя шрифта
property FontName: string write Invoke( SetFontNameP, value) ; virtual ;
2020-07-20 09:27:50 +03:00
end ;
2021-07-13 23:52:47 +03:00
2018-01-05 12:55:13 +03:00
///!#
2020-07-20 09:27:50 +03:00
ClickableControlWPF = class( CommonControlWPF)
2018-01-05 12:55:13 +03:00
protected
2020-07-20 09:27:50 +03:00
procedure ClickP( sender: Object ; e: RoutedEventArgs) ;
2018-01-05 12:55:13 +03:00
begin
if Click < > nil then
Click;
end ;
2020-07-20 09:27:50 +03:00
public
2020-07-25 23:25:47 +03:00
/// Событие нажатия на элемент управления
2020-07-20 09:27:50 +03:00
Click: procedure ;
end ;
2020-08-03 21:26:25 +03:00
StackPanelWPF = class( CommonControlWPF)
private
property sp: StackPanel read element as StackPanel;
procedure CreateP( Orient: Orientation; width, height: real ) ;
begin
element : = new StackPanel;
element. Focusable : = False ;
if width> 0 then
element. Width : = width;
if height> 0 then
element. Height : = height;
sp. Orientation : = Orient;
__ActivePanelInternal. Children. Add( sp) ;
_ActivePanel : = sp;
end ;
procedure SetColorP( c: GColor) ;
begin
sp. Background : = GetBrush( c) ;
end ;
function GetColorP : = ( sp. Background as SolidColorBrush) . Color;
procedure SetTTP( s: string ) ;
begin
sp. ToolTip : = s;
end ;
public
constructor ( Orient: Orientation; width: real : = 0 ; height: real : = 0 ) : = Invoke( CreateP, Orient, width, height) ;
property Color: GColor read Invoke& < GColor> ( GetColorP) write Invoke( SetColorP, value) ;
end ;
2020-07-20 09:27:50 +03:00
2021-07-13 23:52:47 +03:00
/// Элемент управления Grid
GridWPF = class( CommonElementWPF)
private
property gr: UniformGrid read element as UniformGrid;
procedure CreatePP( rows, columns: integer ) ; // только для добавления как главной панели
begin
element : = new UniformGrid( ) ;
gr. Rows : = rows;
gr. Columns : = columns;
element. Focusable : = False ;
MainDockPanel. children. RemoveAt( MainDockPanel. children. Count- 1 ) ;
MainDockPanel. children. Add( gr) ;
end ;
procedure CreateP( rows, columns, InternalMargin: integer ) ;
begin
element : = new UniformGrid( ) ;
element. Focusable : = False ;
gr. Rows : = rows;
gr. Columns : = columns;
__ActivePanelInternal. Children. Add( gr) ;
_ActivePanel : = gr;
_ActivePanel. Tag : = Self;
Self. InternalMargin : = InternalMargin;
end ;
constructor ( i: boolean ; rows, columns: integer ) : = Invoke( CreatePP, rows, columns) ; // фиктивный первый параметр
public
constructor ( rows: integer : = 1 ; columns: integer : = 1 ; InternalMargin: integer : = 5 )
: = Invoke( CreateP, rows, columns, InternalMargin) ;
property Rows: integer read InvokeInteger( ( ) - > gr. Rows)
write Invoke( procedure - > if value> 0 then gr. Rows : = value) ;
property Columns: integer read InvokeInteger( ( ) - > gr. Columns)
write Invoke( procedure - > if value> 0 then gr. Columns : = value) ;
auto property InternalMargin: real : = 5 ;
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Изображение"
2020-07-20 11:36:38 +03:00
ImageWPF = class( CommonControlWPF)
2020-07-25 23:25:47 +03:00
private
2020-07-20 11:36:38 +03:00
property im: Image read element as Image;
2020-07-24 22:00:21 +03:00
procedure CreatePXY( x, y: real ; name : string ; width: real : = 0 ) ;
2020-07-20 11:36:38 +03:00
begin
2020-07-24 22:00:21 +03:00
Init0( new Image( ) , width, x, y) ;
2020-07-21 19:12:02 +03:00
im. Source : = new BitmapImage( ) ;
2020-07-25 23:25:47 +03:00
im. Source : = new BitmapImage( new System. Uri( name , System. UriKind. RelativeOrAbsolute) ) ;
2020-07-21 19:12:02 +03:00
end ;
2020-07-24 22:00:21 +03:00
procedure CreateP( name : string ) : = CreatePXY( - 1 , - 1 , name , 0 ) ;
2020-07-21 19:12:02 +03:00
procedure CreatePP;
begin
element : = new Image( ) ;
element. Focusable : = False ;
2020-07-20 11:36:38 +03:00
MainDockPanel. children. RemoveAt( MainDockPanel. children. Count- 1 ) ;
MainDockPanel. children. Add( im) ;
end ;
2020-07-21 19:12:02 +03:00
function GetNameP: string ;
begin
Result : = ( im. Source as BitmapImage) . UriSource. AbsolutePath
end ;
procedure SetNameP( value: string ) ;
begin
2020-07-25 23:25:47 +03:00
im. Source : = new BitmapImage( new System. Uri( value, System. UriKind. RelativeOrAbsolute) ) ;
2020-07-21 19:12:02 +03:00
end ;
constructor ( i: integer ) : = Invoke( CreatePP) ; // фиктивный первый параметр
2020-07-20 11:36:38 +03:00
public
constructor ( name : string ) : = Invoke( CreateP, name ) ;
2020-07-24 22:00:21 +03:00
constructor ( x, y: real ; name : string ; width: real : = 0 ) : = Invoke( CreatePXY, x, y, name , width) ;
2020-07-25 23:25:47 +03:00
/// Имя файла изображения
2020-07-21 19:12:02 +03:00
property Name : string read InvokeString( GetNameP) write Invoke( SetNameP, value) ;
2020-07-20 11:36:38 +03:00
end ;
2020-07-24 22:00:21 +03:00
2020-07-20 11:36:38 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Кнопка"
ButtonWPF = class( ClickableControlWPF)
2020-08-12 15:22:16 +03:00
public
2020-07-20 09:27:50 +03:00
property b: GButton read element as GButton;
2019-08-18 00:16:39 +03:00
2020-07-20 09:27:50 +03:00
procedure CreatePXY( x, y: real ; Txt: string ; width: real ; fontSize: real ) ;
2018-01-05 12:55:13 +03:00
begin
2020-07-20 09:27:50 +03:00
Init0( new GButton, width, x, y) ;
2018-01-05 12:55:13 +03:00
Text : = Txt;
2019-08-18 00:16:39 +03:00
Self. FontSize : = fontSize;
2020-07-20 09:27:50 +03:00
b. Click + = ( o, e) - > if Click < > nil then Click;
2019-08-15 23:54:13 +03:00
end ;
2020-07-20 09:27:50 +03:00
procedure CreateP( text : string ; fontSize: real ) : = CreatePXY( - 1 , - 1 , text , 0 , fontSize) ;
procedure SetTextP( t: string ) : = b. Content : = t;
public
2020-08-12 15:22:16 +03:00
constructor Create( Txt: string ; fontSize: real : = 0 ) : = Invoke( CreateP, Txt, fontSize) ;
constructor Create( x, y: real ; Txt: string ; width: real : = 0 ; fontSize: real : = 0 ) : = Invoke( CreatePXY, x, y, Txt, width, fontSize) ;
2019-08-18 00:16:39 +03:00
2020-07-25 23:25:47 +03:00
/// Текст на кнопке
2020-07-20 09:27:50 +03:00
property Text : string read InvokeString( ( ) - > b. Content as string ) write Invoke( SetTextP, value) ;
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Текст"
2020-07-20 09:27:50 +03:00
TextBlockWPF = class( CommonElementWPF)
2020-07-25 23:25:47 +03:00
private
2020-07-20 09:27:50 +03:00
property tb: GTextBlock read element as GTextBlock;
procedure CreatePXY( x, y: real ; Txt: string ; width: real ; fontsize: real ) ;
2019-08-15 23:54:13 +03:00
begin
2020-07-20 09:27:50 +03:00
Init0( new GTextBlock, width, x, y) ;
2020-08-01 00:13:27 +03:00
//Margin := 3;
2019-08-15 23:54:13 +03:00
Text : = Txt;
2020-07-20 09:27:50 +03:00
Self. FontSize : = fontSize;
2018-01-05 12:55:13 +03:00
end ;
2020-07-20 09:27:50 +03:00
procedure CreateP( text : string ; fontSize: real ) : = CreatePXY( - 1 , - 1 , text , 0 , fontSize) ;
2019-08-18 00:16:39 +03:00
2020-07-20 09:27:50 +03:00
procedure SetTextP( t: string ) : = tb. Text : = t;
2020-08-12 15:22:16 +03:00
procedure SetFontSizeP( sz: real ) : = if sz> 0 then tb. FontSize : = sz;
2020-07-25 23:25:47 +03:00
procedure SetFontNameP( name : string ) : = tb. FontFamily : = new FontFamily( name ) ;
2020-08-01 00:13:27 +03:00
procedure SetTextWrappingP( value: boolean ) : = if value then tb. TextWrapping : = TextWrapping. Wrap else
tb. TextWrapping : = TextWrapping. NoWrap;
2020-07-20 09:27:50 +03:00
public
2020-08-12 15:22:16 +03:00
constructor Create( Txt: string ; fontsize: real : = 0 ) : = Invoke( CreateP, Txt, fontsize) ;
constructor Create( x, y: real ; Txt: string ; width: real : = 0 ; fontSize: real : = 0 ) : = Invoke( CreatePXY, x, y, Txt, width, fontSize) ;
2020-07-20 09:27:50 +03:00
2020-07-25 23:25:47 +03:00
/// Текст блока текста
2020-07-20 09:27:50 +03:00
property Text : string read InvokeString( ( ) - > tb. Text ) write Invoke( SetTextP, value) ;
2020-07-25 23:25:47 +03:00
/// Размер шрифта
property FontSize: real read InvokeReal( ( ) - > tb. FontSize) write Invoke( SetFontSizeP, value) ; virtual ;
/// Имя шрифта
property FontName: string write Invoke( SetFontNameP, value) ; virtual ;
2020-08-01 00:13:27 +03:00
/// Включён ли режим переноса слов
property Wrapping: boolean read InvokeBoolean( ( ) - > tb. TextWrapping = TextWrapping. Wrap)
write Invoke( SetTextWrappingP, value) ; virtual ;
2020-07-20 09:27:50 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Целое число"
2020-07-20 09:27:50 +03:00
IntegerBlockWPF = class( TextBlockWPF)
private
val : = 0 ;
message : string ;
2020-08-12 15:22:16 +03:00
procedure CreatePXY( x, y: real ; message : string ; width: real ; initValue: integer : = 0 ; fontSize: real : = 0 ) ;
2020-07-20 09:27:50 +03:00
begin
inherited CreatePXY( x, y, message + ' ' + initValue, width, fontSize) ;
Self. message : = message ;
val : = initValue;
end ;
2020-08-12 15:22:16 +03:00
procedure CreateP( message : string ; initValue: integer : = 0 ; fontSize: real : = 0 ) : = CreatePXY( - 1 , - 1 , message , 0 , initValue, fontSize) ;
2020-07-20 09:27:50 +03:00
public
2020-08-12 15:22:16 +03:00
constructor Create( message : string ; initValue: integer : = 0 ; fontSize: real : = 0 ) : = Invoke( CreateP, message , initValue, fontSize) ;
constructor Create( x, y: real ; message : string ; width: real : = 0 ; initValue: integer : = 0 ; fontSize: real : = 0 ) : = Invoke( CreatePXY, x, y, message , width, initValue, fontSize) ;
2020-07-20 09:27:50 +03:00
2020-07-25 23:25:47 +03:00
/// Значение целого
2020-07-20 09:27:50 +03:00
property Value: integer read val write begin val : = value; Text : = message + ' ' + val; end ;
2020-08-12 15:22:16 +03:00
static function operator implicit( ib: IntegerBlockWPF) : = ib. Value;
static function operator = ( ib: IntegerBlockWPF; v: integer ) : = ib. Value = v;
static function operator = ( v: integer ; ib: IntegerBlockWPF) : = ib. Value = v;
static function operator< > ( ib: IntegerBlockWPF; v: integer ) : = ib. Value < > v;
static function operator< > ( v: integer ; ib: IntegerBlockWPF) : = ib. Value < > v;
static procedure operator + = ( ib: IntegerBlockWPF; v: integer ) ;
begin
ib. Value + = v;
end ;
static procedure operator - = ( ib: IntegerBlockWPF; v: integer ) ;
begin
ib. Value - = v;
end ;
static procedure operator : = ( ib: IntegerBlockWPF; v: integer ) : = ib. Value : = v;
2020-07-20 09:27:50 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Вещественное число"
2020-07-20 09:27:50 +03:00
RealBlockWPF = class( TextBlockWPF)
private
val : = 0.0 ;
message : string ;
2020-08-12 15:22:16 +03:00
procedure CreatePXY( x, y: real ; message : string ; width: real ; initValue: real : = 0 ; fontSize: real : = 0 ) ;
2020-07-20 09:27:50 +03:00
begin
2020-08-01 00:13:27 +03:00
inherited CreatePXY( x, y, message + ' ' + initValue. ToString( FracDigits) , width, fontSize) ;
2020-07-20 09:27:50 +03:00
Self. message : = message ;
val : = initValue;
end ;
2020-08-12 15:22:16 +03:00
procedure CreateP( message : string ; initValue: real : = 0 ; fontSize: real : = 0 ) : = CreatePXY( - 1 , - 1 , message , 0 , initValue, fontSize) ;
2020-07-20 09:27:50 +03:00
public
2020-08-12 15:22:16 +03:00
constructor Create( message : string ; initValue: real : = 0 ; fontSize: real : = 0 ) : = Invoke( CreateP, message , initValue, fontSize) ;
constructor Create( x, y: real ; message : string ; width: real : = 0 ; initValue: real : = 0 ; fontSize: real : = 0 ) : = Invoke( CreatePXY, x, y, message , width, initValue, fontSize) ;
2020-07-20 09:27:50 +03:00
2020-07-25 23:25:47 +03:00
/// Значение вещественного
2020-07-20 09:27:50 +03:00
property Value: real read val write begin val : = value; Text : = message + ' ' + val. ToString( FracDigits) ; end ;
2020-07-25 23:25:47 +03:00
/// Количество цифр после десятичной точки
2020-07-20 09:27:50 +03:00
auto property FracDigits: integer : = 1 ;
2020-08-12 15:22:16 +03:00
static function operator implicit( ib: RealBlockWPF) : = ib. Value;
static function operator = ( ib: RealBlockWPF; v: real ) : = ib. Value = v;
static function operator = ( v: real ; ib: RealBlockWPF) : = ib. Value = v;
static function operator< > ( ib: RealBlockWPF; v: real ) : = ib. Value < > v;
static function operator< > ( v: real ; ib: RealBlockWPF) : = ib. Value < > v;
static procedure operator + = ( rb: RealBlockWPF; v: real ) ;
begin
rb. Value + = v;
end ;
static procedure operator - = ( rb: RealBlockWPF; v: real ) ;
begin
rb. Value - = v;
end ;
static procedure operator : = ( rb: RealBlockWPF; v: real ) : = rb. Value : = v;
2020-07-20 09:27:50 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Текстовое поле"
2020-07-24 22:00:21 +03:00
TextBoxNoTitleWPF = class( CommonControlWPF)
private
2020-07-20 09:27:50 +03:00
property tb: GTextBox read element as GTextBox;
procedure SetTextP( t: string ) : = tb. Text : = t;
procedure CreatePXY( x, y: real ; txt: string ; width: real ) ;
begin
Init0( new GTextBox, width, x, y) ;
Text : = txt;
2020-07-24 22:00:21 +03:00
tb. TextChanged + = ( o, e) - > if TextChanged < > nil then TextChanged;
2020-07-20 09:27:50 +03:00
element. Focusable : = True ;
//element.HorizontalAlignment := HorizontalAlignment.Stretch;
end ;
procedure CreateP( text : string ) : = CreatePXY( - 1 , - 1 , text , 0 ) ;
2020-07-24 22:00:21 +03:00
procedure CreatePP;
begin
element : = new TextBox( ) ;
element. Focusable : = False ;
2020-07-25 23:25:47 +03:00
tb. AcceptsReturn : = True ;
//tb.TextWrapping := TextWrapping.Wrap;
tb. VerticalScrollBarVisibility : = ScrollBarVisibility. Auto;
tb. HorizontalScrollBarVisibility : = ScrollBarVisibility. Auto;
2020-07-24 22:00:21 +03:00
MainDockPanel. children. RemoveAt( MainDockPanel. children. Count- 1 ) ;
MainDockPanel. children. Add( element) ;
end ;
2020-07-25 23:25:47 +03:00
procedure SetReadOnlyP( value: boolean ) ;
begin
element. Focusable : = not value;
end ;
2020-07-24 22:00:21 +03:00
constructor Create( i: integer ) : = Invoke( CreatePP) ;
2018-01-05 12:55:13 +03:00
public
2020-07-25 23:25:47 +03:00
/// Событие изменения текста
2020-07-24 22:00:21 +03:00
TextChanged: procedure ;
2020-07-20 09:27:50 +03:00
constructor Create( text : string : = '' ) : = Invoke( CreateP, text ) ;
constructor Create( x, y: real ; text : string : = '' ; width: real : = 0 ) : = Invoke( CreatePXY, x, y, text , width) ;
2020-07-25 23:25:47 +03:00
/// Текст в текстовом поле
2020-07-20 09:27:50 +03:00
property Text : string read InvokeString( ( ) - > tb. Text ) write Invoke( SetTextP, value) ;
2020-07-25 23:25:47 +03:00
/// Добавление строки в конец
2020-07-24 22:00:21 +03:00
procedure Print( s: string ) ;
begin
Text + = s + ' ' ;
end ;
2020-07-25 23:25:47 +03:00
/// Добавление строки в конец и переход на новую строку
2020-07-24 22:00:21 +03:00
procedure Println( s: string ) ;
begin
Text + = s + NewLine;
end ;
2020-07-25 23:25:47 +03:00
/// Очистка текста в текстовом поле
procedure Clear : = Text : = '' ;
/// Разрешено ли ручное редактирование текста
2020-08-01 00:13:27 +03:00
property ReadOnly : boolean read InvokeBoolean( ( ) - > not element. Focusable) write Invoke( SetReadOnlyP, value) ;
2020-07-24 22:00:21 +03:00
end ;
///!#
ControlWithTitleWPF = class( CommonControlWPF)
private
property tb: GTextBlock read ( element as StackPanel) . Children[ 0 ] as TextBlock;
property MainElement: GControl read ( element as StackPanel) . Children[ 1 ] as GControl;
procedure SetTitleP( t: string ) ;
begin
if t = '' then
tb. Visibility : = System. Windows. Visibility. Collapsed
else tb. Visibility : = System. Windows. Visibility. Visible;
tb. Text : = t;
end ;
2020-08-03 21:26:25 +03:00
procedure SetTitleVisibilityP( v: boolean ) ;
begin
if v then
tb. Visibility : = System. Windows. Visibility. Visible
else tb. Visibility : = System. Windows. Visibility. Collapsed;
end ;
2020-07-24 22:00:21 +03:00
procedure SetHP( h: real ) : = MainElement. Height : = h;
function CreateStackPanel( el: FrameworkElement; title: string ) : StackPanel;
begin
var sp : = new StackPanel;
var tb : = new TextBlock;
tb. Text : = title;
tb. Margin : = new Thickness( 0 , 0 , 0 , 3 ) ;
sp. Children. Add( tb) ;
if title = '' then
tb. Visibility : = System. Windows. Visibility. Collapsed;
sp. Children. Add( el) ;
Result : = sp;
end ;
procedure Init1( el: FrameworkElement; title: string ; width: real : = 0 ; x: real : = - 1 ; y: real : = - 1 ) ;
begin
var sp : = CreateStackPanel( el, title) ;
Init0( sp, width, x, y) ;
end ;
2020-07-25 23:25:47 +03:00
procedure SetFSzP( size: real ) ;
begin
2020-08-12 15:22:16 +03:00
if size< = 0 then
exit;
2020-07-25 23:25:47 +03:00
tb. FontSize : = size;
MainElement. FontSize : = size;
end ;
procedure SetFontNameP( name : string ) ;
begin
tb. FontFamily : = new FontFamily( name ) ;
MainElement. FontFamily : = new FontFamily( name ) ;
end ;
2020-07-24 22:00:21 +03:00
public
2020-07-25 23:25:47 +03:00
/// Заголовок
2020-08-03 21:26:25 +03:00
property Title: string read InvokeString( ( ) - > tb. Text ) write Invoke( SetTitleP, value) ; virtual ;
/// Видим ли заголовок
property TitleVisible: boolean read InvokeBoolean( ( ) - > tb. Visibility < > System. Windows. Visibility. Collapsed)
write Invoke( SetTitleVisibilityP, value) ; virtual ;
2020-07-25 23:25:47 +03:00
/// Высота элемента управления
2020-07-24 22:00:21 +03:00
property Height: real read InvokeReal( ( ) - > MainElement. ActualHeight) write Invoke( SetHP, value) ; override ;
2020-07-25 23:25:47 +03:00
/// Размер шрифта
property FontSize: real read InvokeReal( ( ) - > MainElement. FontSize) write Invoke( SetFSzP, value) ; override ;
/// Имя шрифта
property FontName: string write Invoke( SetFontNameP, value) ; override ;
2020-07-24 22:00:21 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Текстовое поле с заголовком"
2020-07-24 22:00:21 +03:00
TextBoxWPF = class( ControlWithTitleWPF)
private
property tbx: GTextBox read MainElement as TextBox;
procedure SetTextP( t: string ) : = tbx. Text : = t;
procedure SetMultiLineP( b: boolean ) : = if b then tbx. TextWrapping : = TextWrapping. Wrap else tbx. TextWrapping : = TextWrapping. NoWrap;
procedure CreatePXY( x, y: real ; title, txt: string ; width: real ) ;
begin
Init1( new TextBox, title, width, x, y) ;
//tbx.TextWrapping := TextWrapping.Wrap;
tbx. Text : = txt;
2020-08-01 00:13:27 +03:00
tbx. TextChanged + = ( o, e) - > if ValueChanged < > nil then ValueChanged;
2020-07-24 22:00:21 +03:00
end ;
procedure CreateAsMainControlP;
begin
element : = CreateStackPanel( new TextBox, '' ) ;
2020-08-01 00:13:27 +03:00
Wrapping : = True ;
tbx. TextChanged + = ( o, e) - > if ValueChanged < > nil then ValueChanged;
2020-07-24 22:00:21 +03:00
MainDockPanel. children. RemoveAt( MainDockPanel. children. Count- 1 ) ;
MainDockPanel. children. Add( element) ;
end ;
procedure CreateP( title, text : string ) : = CreatePXY( - 1 , - 1 , title, text , 0 ) ;
constructor Create( i: integer ) : = Invoke( CreateAsMainControlP) ;
public
2020-08-01 00:13:27 +03:00
/// Событие "значение изменилось"
ValueChanged: procedure ;
2020-07-24 22:00:21 +03:00
constructor Create( title: string : = '' ) : = Invoke( CreateP, title, '' ) ;
constructor Create( x, y: real ; title: string : = '' ; width: real : = 1 2 0 ) : = Invoke( CreatePXY, x, y, title, '' , width) ;
2020-07-25 23:25:47 +03:00
/// Очистка текста в текстовом поле
2020-07-24 22:00:21 +03:00
procedure Clear : = Text : = '' ;
2020-07-25 23:25:47 +03:00
/// Текст в текстовом поле
2020-07-24 22:00:21 +03:00
property Text : string read InvokeString( ( ) - > tbx. Text ) write Invoke( SetTextP, value) ;
2020-08-01 00:13:27 +03:00
/// Включён ли режим переноса слов
property Wrapping: boolean read InvokeBoolean( ( ) - > tbx. TextWrapping = TextWrapping. Wrap) write Invoke( SetMultiLineP, value) ;
2020-07-20 09:27:50 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Целое поле"
2020-07-20 09:27:50 +03:00
IntegerBoxWPF = class( TextBoxWPF)
2020-07-24 22:00:21 +03:00
private
2020-07-20 09:27:50 +03:00
function GetValue: integer ;
2018-01-05 12:55:13 +03:00
begin
2020-07-20 09:27:50 +03:00
if Trim( Text ) = '' then
Result : = 0
else Result : = integer . Parse( Text ) ;
2020-07-25 23:25:47 +03:00
Result : = Result . Clamp( Minimum, Maximum) ;
2018-01-05 12:55:13 +03:00
end ;
2019-08-18 00:16:39 +03:00
2020-07-25 23:25:47 +03:00
procedure SetValue( x: integer ) : = Text : = x. Clamp( Minimum, Maximum) . ToString;
2020-07-20 09:27:50 +03:00
procedure Rest( min, max: integer ) ;
2019-08-15 23:54:13 +03:00
begin
2020-07-24 22:00:21 +03:00
Invoke( ( ) - > begin
2020-07-25 23:25:47 +03:00
Self. Minimum : = min;
Self. Maximum : = max;
Value : = Minimum;
2020-07-24 22:00:21 +03:00
tbx. MouseWheel + = ( o, e) - > begin
if e. Delta > 0 then
Value : = Value + 1
else if e. Delta < 0 then
Value : = Value - 1
end ;
tbx. KeyDown + = ( o, e) - > begin
if not ( ( e. Key > = Key. D0) and ( e. Key < = Key. D9) ) then
e. Handled : = True ;
end ;
end ) ;
2020-07-20 09:27:50 +03:00
end ;
public
2020-07-24 22:00:21 +03:00
constructor Create( title: string : = '' ; min: integer : = 0 ; max: integer : = 1 0 ) ;
2020-07-20 09:27:50 +03:00
begin
2020-07-24 22:00:21 +03:00
inherited Create( title) ;
2020-07-20 09:27:50 +03:00
Rest( min, max) ;
end ;
2020-07-24 22:00:21 +03:00
constructor Create( x, y: real ; title: string ; min, max: integer ; width: real : = 0 ) ;
2020-07-20 09:27:50 +03:00
begin
2020-07-24 22:00:21 +03:00
inherited Create( x, y, title, width) ;
2020-07-20 09:27:50 +03:00
Rest( min, max) ;
2019-08-15 23:54:13 +03:00
end ;
2019-08-18 00:16:39 +03:00
2020-07-25 23:25:47 +03:00
/// Минимальное значение в тектовом поле
auto property Minimum: integer : = 0 ;
/// Максимальное значение в тектовом поле
auto property Maximum: integer : = 1 0 0 ;
/// Текущее значение текстового поля
2020-07-20 09:27:50 +03:00
property Value: integer read GetValue write SetValue;
2020-08-12 15:22:16 +03:00
static function operator implicit( ib: IntegerBoxWPF) : = ib. Value;
static function operator = ( ib: IntegerBoxWPF; v: integer ) : = ib. Value = v;
static function operator = ( v: integer ; ib: IntegerBoxWPF) : = ib. Value = v;
static function operator< > ( ib: IntegerBoxWPF; v: integer ) : = ib. Value < > v;
static function operator< > ( v: integer ; ib: IntegerBoxWPF) : = ib. Value < > v;
static procedure operator : = ( ib: IntegerBoxWPF; v: integer ) : = ib. Value : = v;
2018-01-05 12:55:13 +03:00
end ;
2020-07-20 09:27:50 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Список"
2020-07-24 22:00:21 +03:00
ListBoxWPF = class( ControlWithTitleWPF)
2020-07-20 09:27:50 +03:00
protected
2020-07-24 22:00:21 +03:00
function lb: GListBox : = MainElement as GListBox;
procedure CreatePXY( x, y: real ; title: string ; width, height: real ) ;
2020-07-20 09:27:50 +03:00
begin
2020-07-24 22:00:21 +03:00
Init1( new GListBox, title, width, x, y) ;
2020-07-20 09:27:50 +03:00
//element.HorizontalAlignment := HorizontalAlignment.Stretch;
2020-07-24 22:00:21 +03:00
Self. Height : = height;
2020-07-20 09:27:50 +03:00
lb. SelectionChanged + = ( o, e) - > if SelectionChanged< > nil then SelectionChanged;
end ;
2020-07-24 22:00:21 +03:00
procedure CreateP( title: string ; height: real ) : = CreatePXY( - 1 , - 1 , title, 0 , height) ;
2020-07-20 09:27:50 +03:00
procedure AddP( s: string ) ;
begin
var lbi : = new ListBoxItem( ) ;
lbi. Content : = s;
lb. Items. Add( lbi) ;
end ;
2019-08-18 00:16:39 +03:00
2020-07-20 09:27:50 +03:00
procedure AddRangeP( ss: sequence of string ) ;
begin
foreach var s in ss do
AddP( s) ;
end ;
procedure SortP : = lb. Items. SortDescriptions. Add( new SortDescription( 'Content' , ListSortDirection. Ascending) ) ;
procedure SortPDescending : = lb. Items. SortDescriptions. Add( new SortDescription( 'Content' , ListSortDirection. Descending) ) ;
public
2020-07-25 23:25:47 +03:00
/// Событие, возникающее при изменении текущего выделения
2020-07-20 09:27:50 +03:00
SelectionChanged: procedure ;
2020-07-24 22:00:21 +03:00
constructor Create( title: string : = '' ; height: real : = 1 5 0 ) : = Invoke( CreateP, title, height) ;
constructor Create( x, y: real ; title: string : = '' ; width: real : = 1 5 0 ; height: real : = 1 5 0 ) : = Invoke( CreatePXY, x, y, title, width, height) ;
2020-07-25 23:25:47 +03:00
/// Сортировка строк в списке по возрастанию
2020-07-20 09:27:50 +03:00
procedure Sort : = Invoke( SortP) ;
2020-07-25 23:25:47 +03:00
/// Сортировка строк в списке по убыванию
2020-07-20 09:27:50 +03:00
procedure SortDescending : = Invoke( SortPDescending) ;
2020-07-25 23:25:47 +03:00
/// Добавляет элемент в список
2020-07-20 09:27:50 +03:00
procedure Add( s: string ) : = Invoke( AddP, s) ;
2020-07-25 23:25:47 +03:00
/// Добавляет набор элементов в список
procedure AddRange( params ss: array of string ) : = Invoke( AddRangeP, ss) ;
/// Количество элементов в списке
2020-07-20 09:27:50 +03:00
property Count: integer read InvokeInteger( ( ) - > lb. Items. Count) ;
2020-07-25 23:25:47 +03:00
/// Индекс выбранного элемента
2020-07-20 09:27:50 +03:00
property SelectedIndex: integer read InvokeInteger( ( ) - > lb. SelectedIndex) write Invoke( procedure( t: integer ) - > lb. SelectedIndex : = t, value) ;
2020-07-25 23:25:47 +03:00
/// Текст выбранного элемента
2020-07-20 09:27:50 +03:00
property SelectedText: string read InvokeString( ( ) - > ( lb. SelectedItem as ListBoxItem) . Content. ToString)
write Invoke( procedure( t: string ) - > ( lb. SelectedItem as ListBoxItem) . Content : = t, value) ;
2019-08-18 00:16:39 +03:00
end ;
2020-07-24 22:00:21 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Раскрывающийся список"
2020-07-24 22:00:21 +03:00
ComboBoxWPF = class( ControlWithTitleWPF)
private
property cb: ComboBox read MainElement as ComboBox;
procedure CreatePXY( x, y: real ; title: string ; width: real ) ;
begin
Init1( new ComboBox, title, width, x, y) ;
cb. SelectionChanged + = ( o, e) - > if SelectionChanged < > nil then SelectionChanged;
end ;
procedure CreateP( title: string ) : = CreatePXY( - 1 , - 1 , title, 0 ) ;
procedure AddP( s: string ) ;
begin
cb. Items. Add( s) ;
if cb. Items. Count = 1 then
cb. SelectedIndex : = 0 ;
end ;
procedure AddRangeP( params ss: array of string ) ;
begin
foreach var s in ss do
AddP( s) ;
end ;
public
2020-07-25 23:25:47 +03:00
/// Событие, возникающее при изменении текущего выделения
2020-07-24 22:00:21 +03:00
SelectionChanged: procedure ;
constructor Create( title: string : = '' ) : = Invoke( CreateP, title) ;
2020-08-01 00:13:27 +03:00
constructor Create( x, y: real ; title: string : = '' ; width: real : = 1 2 0 ) : = Invoke( CreatePXY, x, y, title, width) ;
2020-07-24 22:00:21 +03:00
2020-07-25 23:25:47 +03:00
/// Добавляет элемент в список
2020-07-24 22:00:21 +03:00
procedure Add( s: string ) : = Invoke( AddP, s) ;
2020-07-25 23:25:47 +03:00
/// Добавляет набор элементов в список
2020-07-24 22:00:21 +03:00
procedure AddRange( params ss: array of string ) : = Invoke( AddRangeP, ss) ;
2020-07-25 23:25:47 +03:00
/// Выбранная строка
2020-08-01 00:13:27 +03:00
function SelectedText : = InvokeString( ( ) - > cb. SelectedItem as string ) ;
/// Индекс выбранной строки
function SelectedIndex : = InvokeInteger( ( ) - > cb. SelectedIndex) ;
property Items[ i: integer ] : string read InvokeString( ( ) - > cb. Items[ i] as string ) ; default ;
2020-07-24 22:00:21 +03:00
end ;
2019-08-18 00:16:39 +03:00
2020-08-03 21:26:25 +03:00
SliderBase = class( ControlWithTitleWPF)
2020-07-20 09:27:50 +03:00
private
2020-08-03 21:26:25 +03:00
titl: string ; // часть заголовка без числа
function sl: Slider : = MainElement as Slider;
2020-07-20 09:27:50 +03:00
function GetMinimum: real : = InvokeReal( ( ) - > sl. Minimum) ;
procedure SetMinimumP( r: real ) : = sl. Minimum : = r;
procedure SetMinimum( r: real ) : = Invoke( SetMinimumP, r) ;
function GetMaximum: real : = InvokeReal( ( ) - > sl. Maximum) ;
procedure SetMaximumP( r: real ) : = sl. Maximum : = r;
procedure SetMaximum( r: real ) : = Invoke( SetMaximumP, r) ;
function GetValue: real : = InvokeReal( ( ) - > sl. Value) ;
procedure SetValueP( r: real ) : = sl. Value : = r;
procedure SetValue( r: real ) : = Invoke( SetValueP, r) ;
function GetFrequency: real : = InvokeReal( ( ) - > sl. TickFrequency) ;
procedure SetFrequencyP( r: real ) : = sl. TickFrequency : = r;
procedure SetFrequency( r: real ) : = Invoke( SetFrequencyP, r) ;
2020-08-03 21:26:25 +03:00
private
procedure CreatePXY( x, y: real ; title: string ; min, max, val, freq: real ; width: real ) ;
begin
Init1( new Slider, title, width, x, y) ;
Remainder( title, min, max, val, freq) ;
end ;
procedure Remainder( tit: string ; min, max, val, freq: real ) ;
2020-07-20 09:27:50 +03:00
begin
2020-08-03 21:26:25 +03:00
titl : = tit;
sl. ValueChanged + = procedure( o, e) - > if ValueChanged < > nil then ValueChanged;
sl. ValueChanged + = procedure( o, e) - > if title < > '' then tb. Text : = Title + ' ' + sl. Value;
if titl < > '' then tb. Text : = Title + ' ' + sl. Value;
2020-07-20 09:27:50 +03:00
sl. TickPlacement : = System. Windows. Controls. Primitives. TickPlacement. BottomRight;
sl. Minimum : = min;
sl. Maximum : = max;
2020-07-24 22:00:21 +03:00
sl. Value : = val. Clamp( min, max) ;
2020-07-20 09:27:50 +03:00
if freq< = 0 then
sl. TickFrequency : = ( max- min) / 1 0
else sl. TickFrequency : = freq;
sl. Foreground : = Brushes. Black;
2020-08-03 21:26:25 +03:00
sl. IsSnapToTickEnabled : = True ;
end ;
procedure CreateP( title: string ; min, max, val, freq: real ) : = CreatePXY( - 1 , - 1 , title, min, max, val, freq, 0 ) ;
procedure SetTitleP1( tit: string ) ;
begin
titl : = tit;
SetTitleP( tit + ' ' + sl. Value) ;
2020-07-20 09:27:50 +03:00
end ;
public
2020-07-25 23:25:47 +03:00
/// Событие, возникающее при изменении значения
2020-07-20 09:27:50 +03:00
ValueChanged: procedure ;
2020-08-03 21:26:25 +03:00
/// Заголовок
property Title: string read InvokeString( ( ) - > titl) write Invoke( SetTitleP1, value) ; override ;
end ;
/// Элемент управления "Слайдер" с целыми значениями
SliderWPF = class( SliderBase)
private
procedure CreatePXYI( x, y: real ; title: string ; min, max, val, freq: integer ; width: integer ) ;
begin
Init1( new Slider, title, width, x, y) ;
if freq< = 0 then
freq : = ( max- min) div 1 0 ;
if freq = 0 then
freq : = 1 ;
Remainder( title, min, max, val, freq) ;
end ;
procedure CreatePI( title: string ; min, max, val, freq: integer ) : = CreatePXYI( - 1 , - 1 , title, min, max, val, freq, 0 ) ;
public
constructor Create( min, max: integer ; val: integer : = integer . MinValue; freq: integer : = 0 )
: = Invoke( CreatePI, '' , min, max, val, freq) ;
constructor Create( title: string : = '' ) ;
begin
Create( title, 0 , 1 0 , 0 ) ;
end ;
constructor Create( title: string ; min, max: integer ; val: integer : = integer . MinValue; freq: integer : = 0 )
: = Invoke( CreatePI, title, min, max, val, freq) ;
constructor Create( x, y: real ; title: string ; min, max: integer ; width: integer ; val: integer : = integer . MinValue; freq: integer : = 0 )
: = Invoke( CreatePXYI, x, y, title, min, max, val, freq, width) ;
/// Минимальное значение
property Minimum: integer read GetMinimum. Round write SetMinimum( value) ;
/// Максимальное значение
property Maximum: integer read GetMaximum. Round write SetMaximum( value) ;
/// Текущее значение
property Value: integer read GetValue. Round write SetValue( value) ;
/// Интервал между делениями
property Frequency: integer read GetFrequency. Round write SetFrequency( value) ;
end ;
/// Элемент управления "Слайдер" с вещественными значениями
SliderRealWPF = class( SliderBase)
public
constructor Create( min, max: real ; val: real : = real . MinValue; freq: real : = 0 ) : = Invoke( CreateP, '' , min, max, val, freq) ;
constructor Create( title: string : = '' ) : = Create( title, 0 , 1 0 , 0 ) ;
constructor Create( title: string ; min, max: real ; val: real : = real . MinValue; freq: real : = 0 ) : = Invoke( CreateP, title, min, max, val, freq) ;
constructor Create( x, y: real ; title: string ; min, max: real ; width: real ; val: real : = real . MinValue; freq: real : = 0 ) : = Invoke( CreatePXY, x, y, title, min, max, val, freq, width) ;
2020-07-25 23:25:47 +03:00
/// Минимальное значение
2020-07-20 09:27:50 +03:00
property Minimum: real read GetMinimum write SetMinimum;
2020-07-25 23:25:47 +03:00
/// Максимальное значение
2020-07-20 09:27:50 +03:00
property Maximum: real read GetMaximum write SetMaximum;
2020-07-25 23:25:47 +03:00
/// Текущее значение
2020-07-20 09:27:50 +03:00
property Value: real read GetValue write SetValue;
2020-07-25 23:25:47 +03:00
/// Интервал между делениями
2020-07-20 09:27:50 +03:00
property Frequency: real read GetFrequency write SetFrequency;
2019-08-15 23:54:13 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Флажок"
2020-07-20 09:27:50 +03:00
CheckBoxWPF = class( ClickableControlWPF)
private
property cb: CheckBox read element as CheckBox;
protected
procedure CreatePXY( x, y: real ; text : string ; width: real ) ;
begin
Init0( new CheckBox, width, x, y) ;
cb. Content : = text ;
cb. Click + = ClickP;
end ;
procedure CreateP( text : string ) : = CreatePXY( - 1 , - 1 , text , 0 ) ;
public
constructor Create( text : string ) : = Invoke( CreateP, text ) ;
constructor Create( x, y: real ; text : string ; width: real : = 0 ) : = Invoke( CreatePXY, x, y, text , width) ;
2020-07-25 23:25:47 +03:00
/// Текст элемента управления
2020-07-20 09:27:50 +03:00
property Text : string read InvokeString( ( ) - > cb. Content as string ) write Invoke( procedure( t: string ) - > cb. Content : = t, value) ;
2020-07-25 23:25:47 +03:00
/// Включен ли флажок
property Checked: boolean read InvokeBoolean( ( ) - > cb. IsChecked. Value) write Invoke( procedure( t: boolean ) - > cb. IsChecked : = t, value) ;
2019-08-18 00:16:39 +03:00
end ;
2020-08-01 00:13:27 +03:00
/// Элемент управления "Переключатель"
2020-07-20 09:27:50 +03:00
RadioButtonWPF = class( ClickableControlWPF)
private
property rb: RadioButton read element as RadioButton;
protected
procedure CreatePXY( x, y: real ; text : string ; width: real ) ;
begin
Init0( new RadioButton, width, x, y) ;
rb. Content : = text ;
rb. Click + = ClickP;
end ;
procedure CreateP( text : string ) : = CreatePXY( - 1 , - 1 , text , 0 ) ;
public
constructor Create( text : string ) : = Invoke( CreateP, text ) ;
constructor Create( x, y: real ; text : string ; width: real : = 0 ) : = Invoke( CreatePXY, x, y, text , width) ;
2019-08-18 00:16:39 +03:00
2020-07-25 23:25:47 +03:00
/// Текст элемента управления
2020-07-20 09:27:50 +03:00
property Text : string read InvokeString( ( ) - > rb. Content as string ) write Invoke( procedure( t: string ) - > rb. Content : = t, value) ;
2020-07-25 23:25:47 +03:00
/// Включена ли радиокнопка
property Checked: boolean read InvokeBoolean( ( ) - > rb. IsChecked. Value) write Invoke( procedure( t: boolean ) - > rb. IsChecked : = t, value) ;
2018-01-05 12:55:13 +03:00
end ;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Строка статуса"
2020-07-20 09:27:50 +03:00
StatusBarWPF = class( CommonControlWPF)
private
property sb: GStatusBar read element as GStatusBar;
procedure SetTextP( text : string ) : = ( sb. Items[ 0 ] as StatusBarItem) . Content : = text ;
procedure SetTextPI( i: integer ; text : string ) : = ( sb. Items[ i] as StatusBarItem) . Content : = text ;
protected
procedure CreateP( height: real ; itemWidth: real ) ;
begin
element : = new GStatusBar;
element. Focusable : = False ;
element. Height : = height;
DockPanel. SetDock( sb, Dock. Bottom) ;
MainDockPanel. children. Insert( 0 , sb) ;
var sbi : = new StatusBarItem( ) ;
sbi. Content : = '' ;
if itemWidth > 0 then
sbi. Width : = itemWidth;
sb. Items. Add( sbi) ;
// последняя фиктивная панель - для заполнения
sbi : = new StatusBarItem( ) ;
sbi. Content : = '' ;
sb. Items. Add( sbi) ;
2018-01-05 12:55:13 +03:00
end ;
2020-07-20 09:27:50 +03:00
procedure AddItemP( text : string ; itemWidth: real ) ;
begin
var sbi : = new StatusBarItem( ) ;
sbi. Content : = text ;
if itemWidth > 0 then
sbi. Width : = itemWidth;
sb. Items. Insert( sb. Items. Count- 1 , sbi) ;
2018-01-05 12:55:13 +03:00
end ;
2020-07-20 09:27:50 +03:00
public
constructor Create( height: real : = 2 4 ; itemWidth: real : = 0 ) : = Invoke( CreateP, height, itemWidth) ;
2020-07-25 23:25:47 +03:00
/// Добавить текстовое поле указанной ширины к строке статуса
2020-07-20 09:27:50 +03:00
procedure AddText( text : string ; itemWidth: real : = 0 ) : = Invoke( AddItemP, text , itemWidth) ;
2020-07-25 23:25:47 +03:00
/// Текст основного текстового поля в строке статуса
2020-07-20 09:27:50 +03:00
property Text : string read InvokeString( ( ) - > ( sb. Items[ 0 ] as StatusBarItem) . Content as string )
write Invoke( SetTextP, value) ;
2020-07-25 23:25:47 +03:00
/// Текст i-того текстового поля в строке статуса
property ItemText[ i: integer ] : string read InvokeString( ( ) - > ( sb. Items[ i] as StatusBarItem) . Content as string )
2020-07-20 09:27:50 +03:00
write Invoke( SetTextPI, i, value) ;
2018-01-05 12:55:13 +03:00
end ;
2018-02-27 09:15:59 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Канва"
2020-07-24 22:00:21 +03:00
CanvasWPF = class( CommonControlWPF)
protected
property can: Canvas read element as Canvas;
procedure CreatePP;
begin
element : = new Canvas( ) ;
element. Focusable : = False ;
MainDockPanel. children. RemoveAt( MainDockPanel. children. Count- 1 ) ;
MainDockPanel. children. Add( can) ;
2020-08-01 00:13:27 +03:00
__SetActivePanelInternal( can) ;
//ActivePanel := can;
2020-07-24 22:00:21 +03:00
end ;
constructor ( i: integer ) : = Invoke( CreatePP) ; // фиктивный первый параметр
procedure SetColorP( c: GColor) ;
begin
can. Background : = GetBrush( c) ;
end ;
function GetColorP : = ( can. Background as SolidColorBrush) . Color;
public
2020-07-25 23:25:47 +03:00
/// Цвет элемента управления
2020-07-24 22:00:21 +03:00
property Color: GColor read Invoke& < GColor> ( GetColorP) write Invoke( SetColorP, value) ;
end ;
function GetProperties< T> ( t1: T) : sequence of string ;
function GetFields< T> ( t1: T) : sequence of string ;
type
2020-07-25 23:25:47 +03:00
/// Элемент управления "Список данных"
2020-07-24 22:00:21 +03:00
ListViewWPF = class( CommonControlWPF)
private
gv: GridView;
property lv: ListView read element as ListView;
procedure CreatePP;
begin
element : = new ListView( ) ;
element. Focusable : = False ;
MainDockPanel. children. RemoveAt( MainDockPanel. children. Count- 1 ) ;
MainDockPanel. children. Add( lv) ;
gv : = new GridView;
lv. View : = gv;
end ;
function ColumnCountP: integer : = gv. Columns. Count;
function RowCountP: integer : = lv. Items. Count;
constructor ( i: integer ) ;
begin
Invoke( CreatePP) ;
end ;
2020-07-25 23:25:47 +03:00
public
/// Заполнить элемент управления данными
2020-07-24 22:00:21 +03:00
procedure Fill< T> ( data: sequence of T) ;
begin
Invoke( ( ) - > begin
var properties : = GetProperties( data. First) ;
gv. Columns. Clear;
foreach var fld in properties do
begin
var col : = new GridViewColumn;
col. Header : = fld;
col. Width : = 1 5 0 ;
col. DisplayMemberBinding : = new System. Windows. Data. Binding( fld) ;
gv. Columns. Add( col) ;
end ;
lv. ItemsSource : = data;
end ) ;
end ;
2020-07-25 23:25:47 +03:00
/// Очистить данные
2020-07-24 22:00:21 +03:00
procedure Clear;
begin
Invoke( ( ) - > begin
gv. Columns. Clear;
end ) ;
end ;
2020-07-25 23:25:47 +03:00
/// Установить заголовки для данных
2020-07-24 22:00:21 +03:00
procedure SetHeaders( params a: array of string ) ;
begin
Invoke( ( ) - > begin
for var i: = 0 to a. Length - 1 do
gv. Columns[ i] . Header : = a[ i] ;
end ) ;
end ;
2020-07-25 23:25:47 +03:00
/// Число столбцов данных
2020-07-24 22:00:21 +03:00
function ColumnCount: integer : = InvokeInteger( ColumnCountP) ;
2020-07-25 23:25:47 +03:00
/// Число строк данных
2020-07-24 22:00:21 +03:00
function RowCount: integer : = InvokeInteger( RowCountP) ;
2020-07-21 19:12:02 +03:00
end ;
2020-07-25 23:25:47 +03:00
///!#
/// Пункт меню
2020-07-24 22:00:21 +03:00
MenuItemWPF = class
private
mi: MenuItem;
2020-07-25 23:25:47 +03:00
litem : = new List< MenuItemWPF> ;
2020-07-24 22:00:21 +03:00
procedure CreateP( mii: MenuItem; text : string ) ;
begin
mi : = mii;
mi. Header : = text ;
mi. Click + = ( o, e) - > begin
if Click< > nil then Click;
end ;
end ;
constructor Create( mi: MenuItem; text : string ) : = Invoke( CreateP, mi, text ) ;
procedure SetTextP( text : string ) ;
begin
mi. Header : = text ;
end ;
2020-07-25 23:25:47 +03:00
function AddMenuItemP( text : string ; p: procedure ) : MenuItemWPF;
2020-07-24 22:00:21 +03:00
begin
2020-07-25 23:25:47 +03:00
if text = '-' then
begin
mi. Items. Add( new Separator) ;
exit
end ;
2020-07-24 22:00:21 +03:00
var mii : = new MenuItem;
mii. Header : = text ;
mi. Items. Add( mii) ;
2020-07-25 23:25:47 +03:00
mii. Click + = ( o, e) - > if Click< > nil then Click;
Result : = new MenuItemWPF( mii, text ) ;
Result . Click : = p;
litem. Add( Result ) ;
2020-07-24 22:00:21 +03:00
end ;
2020-07-25 23:25:47 +03:00
procedure AddSeparatorP : = mi. Items. Add( new Separator) ;
2020-07-24 22:00:21 +03:00
public
2020-07-25 23:25:47 +03:00
/// Событие выбора пункта меню
2020-07-24 22:00:21 +03:00
Click: procedure ;
2020-07-25 23:25:47 +03:00
/// Текст пункта меню
2020-07-24 22:00:21 +03:00
property Text : string read InvokeString( ( ) - > mi. Header as string ) write Invoke( SetTextP, text ) ;
2020-07-25 23:25:47 +03:00
/// Н а б о р пунктов меню
property Items[ i: integer ] : MenuItemWPF read Invoke& < MenuItemWPF> ( ( ) - > litem[ i] ) ; default ;
/// Добавить пункт подменю
function Add( text : string ; p: procedure : = nil ) : MenuItemWPF
: = Invoke& < MenuItemWPF> ( ( ) - > AddMenuItemP( text , p) ) ;
/// Добавить разделитель
procedure AddSeparator : = Invoke( AddSeparatorP) ;
/// Добавить набор пунктов меню
procedure AddRange( params items: array of string ) ;
begin
foreach var it in items do
Add( it) ;
end ;
2020-07-24 22:00:21 +03:00
end ;
2020-07-21 19:12:02 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Главное меню"
2020-07-24 22:00:21 +03:00
MenuWPF = class( CommonControlWPF)
2020-07-20 09:27:50 +03:00
private
2020-07-25 23:25:47 +03:00
litem : = new List< MenuItemWPF> ;
2020-07-24 22:00:21 +03:00
property m: Menu read element as Menu;
procedure CreatePP;
2020-07-20 09:27:50 +03:00
begin
2020-07-24 22:00:21 +03:00
element : = new Menu( ) ;
element. Height : = 2 0 ;
DockPanel. SetDock( m, Dock. Top) ;
MainDockPanel. children. Insert( 0 , element) ;
end ;
function AddMenuItemP( text : string ) : MenuItemWPF;
begin
var mi : = new MenuItem;
mi. Header : = text ;
m. Items. Add( mi) ;
2020-07-25 23:25:47 +03:00
Result : = new MenuItemWPF( mi, text ) ;
litem. Add( Result ) ;
2020-07-20 09:27:50 +03:00
end ;
public
2020-07-24 22:00:21 +03:00
constructor Create : = Invoke( CreatePP) ;
2020-07-25 23:25:47 +03:00
property Items[ i: integer ] : MenuItemWPF read Invoke& < MenuItemWPF> ( ( ) - > litem[ i] ) ; default ;
/// Добавить пункт горизонтального меню
2020-07-24 22:00:21 +03:00
function Add( text : string ) : MenuItemWPF : = Invoke& < MenuItemWPF> ( ( ) - > AddMenuItemP( text ) ) ;
2020-07-25 23:25:47 +03:00
/// Добавить набор пунктов меню
procedure AddRange( params items: array of string ) ;
begin
foreach var it in items do
Add( it) ;
end ;
2020-07-24 22:00:21 +03:00
end ;
///!#
2020-07-25 23:25:47 +03:00
/// Статический класс для создания главных элементов управления
2020-07-24 22:00:21 +03:00
SetMainControl = static class
public
static function AsImage: ImageWPF : = new ImageWPF( 0 ) ;
static function AsCanvas: CanvasWPF : = new CanvasWPF( 0 ) ;
static function AsListView: ListViewWPF : = new ListViewWPF( 0 ) ;
static function AsTextBox: TextBoxNoTitleWPF : = new TextBoxNoTitleWPF( 0 ) ;
2021-07-13 23:52:47 +03:00
static function AsGrid( rows: integer : = 1 ; columns: integer : = 1 ) : GridWPF : = new GridWPF( true , rows, columns) ;
2020-07-24 22:00:21 +03:00
end ;
2020-07-25 23:25:47 +03:00
///!#
/// Базовый класс стандартных окон диалога
FileDialogWPF = class
private
d: Microsoft. Win32. FileDialog;
procedure SetFilterP( value: string ) : = d. Filter : = value;
procedure SetInitialDirectoryP( value: string ) : = d. InitialDirectory : = value;
function ShowDialogP: boolean ;
begin
var r : = d. ShowDialog;
Result : = r. HasValue and r. Value;
end ;
public
function ShowDialog: boolean : = InvokeBoolean( ShowDialogP) ;
function FileName: string : = InvokeString( ( ) - > d. FileName) ;
property Filter: string read InvokeString( ( ) - > d. Filter) write Invoke( SetFilterP, value) ;
property InitialDirectory: string read InvokeString( ( ) - > d. InitialDirectory) write Invoke( SetInitialDirectoryP, value) ;
end ;
/// Стандартное окно диалога открытия файла
OpenFileDialogWPF = class( FileDialogWPF)
private
procedure CreateP( initDirectory, filter: string ) ;
begin
d : = new Microsoft. Win32. OpenFileDialog;
d. InitialDirectory : = initDirectory;
d. Filter : = filter;
end ;
public
constructor Create( initDirectory: string : = '' ; filter: string : = '' ) : = Invoke( CreateP, initDirectory, filter) ;
end ;
/// Стандартное окно диалога сохранения файла
SaveFileDialogWPF = class( FileDialogWPF)
private
procedure CreateP( initDirectory, filter: string ) ;
begin
d : = new Microsoft. Win32. SaveFileDialog;
d. InitialDirectory : = initDirectory;
d. Filter : = filter;
end ;
public
constructor Create( initDirectory: string : = '' ; filter: string : = '' ) : = Invoke( CreateP, initDirectory, filter) ;
end ;
2020-07-20 09:27:50 +03:00
{-----------------------------------------------------}
// Для каждого контрола - пара функций.
// Функция без координат и ширины рассчитана на создание внутри вертикальной StackPanel (LeftPanel, RightPanel)
// Panel - вспомогательная, нужна только для создания LeftPanel, RightPanel
2018-03-29 22:21:23 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Кнопка"
2020-08-12 15:22:16 +03:00
function Button( Txt: string ; fontSize: real : = 0 ) : ButtonWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Кнопка" с заданными координатами
2020-08-12 15:22:16 +03:00
function Button( x, y: real ; Txt: string ; width: real : = 0 ; fontSize: real : = 0 ) : ButtonWPF;
2019-08-18 00:16:39 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Текст"
2020-08-12 15:22:16 +03:00
function TextBlock( Txt: string ; fontSize: real : = 0 ) : TextBlockWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Текст" с заданными координатами
2020-08-12 15:22:16 +03:00
function TextBlock( x, y: real ; Txt: string ; width: real : = 0 ; fontSize: real : = 0 ) : TextBlockWPF;
2018-03-29 22:21:23 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Целое число"
2020-08-12 15:22:16 +03:00
function IntegerBlock( message : string ; initValue: integer : = 0 ; fontSize: real : = 0 ) : IntegerBlockWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Целое число" с заданными координатами
2020-08-12 15:22:16 +03:00
function IntegerBlock( x, y: real ; message : string ; width: real : = 0 ; initValue: integer : = 0 ; fontSize: real : = 0 ) : IntegerBlockWPF;
2020-07-20 09:27:50 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Вещественное число"
2020-08-12 15:22:16 +03:00
function RealBlock( message : string ; initValue: real : = 0 ; fontSize: real : = 0 ) : RealBlockWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Вещественное число" с заданными координатами
2020-08-12 15:22:16 +03:00
function RealBlock( x, y: real ; message : string ; width: real : = 0 ; initValue: real : = 0 ; fontSize: real : = 0 ) : RealBlockWPF;
2020-07-20 09:27:50 +03:00
2020-08-01 00:13:27 +03:00
/// Элемент управления "Флажок"
function CheckBox( text : string ) : CheckBoxWPF;
/// Элемент управления "Флажок" с заданными координатами
function CheckBox( x, y: real ; text : string ; width: real : = 0 ) : CheckBoxWPF;
/// Элемент управления "Переключатель"
function RadioButton( text : string ) : RadioButtonWPF;
/// Элемент управления "Переключатель" с заданными координатами
function RadioButton( x, y: real ; text : string ; width: real : = 0 ) : RadioButtonWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Текстовое поле с заголовком"
2020-07-20 09:27:50 +03:00
function TextBox( text : string : = '' ) : TextBoxWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Текстовое поле с заголовком" с заданными координатами
2020-07-20 09:27:50 +03:00
function TextBox( x, y: real ; text : string : = '' ; width: real : = 0 ) : TextBoxWPF;
2021-11-14 22:46:25 +03:00
/// Элемент управления "Целое поле" с диапазоном 0..10
function IntegerBox( title: string ) : IntegerBoxWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Целое поле" с заданным диапазоном значений
2020-07-24 22:00:21 +03:00
function IntegerBox( title: string ; min, max: integer ) : IntegerBoxWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Целое поле" с заданными координатами
2020-07-24 22:00:21 +03:00
function IntegerBox( x, y: real ; title: string ; min, max: integer ; width: real : = 0 ) : IntegerBoxWPF;
2019-08-18 00:16:39 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Список"
2020-07-24 22:00:21 +03:00
function ListBox( title: string : = '' ; height: real : = 1 5 0 ) : ListBoxWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Список" с заданными координатами
2020-07-24 22:00:21 +03:00
function ListBox( x, y: real ; title: string : = '' ; width: real : = 1 5 0 ; height: real : = 1 5 0 ) : ListBoxWPF;
2020-07-20 09:27:50 +03:00
2020-08-03 21:26:25 +03:00
/// Элемент управления "Слайдер с вещественными значениями"
function SliderReal( title: string : = '' ) : SliderRealWPF;
/// Элемент управления "Слайдер с вещественными значениями" с заданным диапазоном значений и заголовком
function SliderReal( title: string ; min, max: real ; val: real : = real . MinValue; freq: real : = 0 ) : SliderRealWPF;
/// Элемент управления "Слайдер с вещественными значениями" с заданным диапазоном значений
function SliderReal( min, max: real ; val: real : = real . MaxValue; freq: real : = 0 ) : SliderRealWPF;
/// Элемент управления "Слайдер с вещественными значениями" с заданными координатами
function SliderReal( x, y: real ; title: string ; min, max: real ; width: real ; val: real : = real . MinValue; freq: real : = 0 ) : SliderRealWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Слайдер"
2020-08-03 21:26:25 +03:00
function Slider( title: string : = '' ) : SliderWPF;
/// Элемент управления "Слайдер" с заданным диапазоном значений и заголовком
function Slider( title: string ; min, max: integer ; val: integer : = integer . MinValue; freq: integer : = 0 ) : SliderWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Слайдер" с заданным диапазоном значений
2020-08-03 21:26:25 +03:00
function Slider( min, max: integer ; val: integer : = integer . MinValue; freq: integer : = 0 ) : SliderWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Слайдер" с заданными координатами
2020-08-03 21:26:25 +03:00
function Slider( x, y: real ; title: string ; min, max: integer ; width: integer ; val: integer : = integer . MinValue; freq: integer : = 0 ) : SliderWPF;
2020-07-24 22:00:21 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Изображение"
2020-07-24 22:00:21 +03:00
function Image( name : string ) : ImageWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Изображение" с заданными координатами
2020-07-24 22:00:21 +03:00
function Image( x, y: real ; name : string ; width: real : = 0 ) : ImageWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Раскрывающийся список"
function ComboBox( title: string : = '' ) : ComboBoxWPF;
/// Элемент управления "Раскрывающийся список" с заданными координатами
function ComboBox( x, y: real ; title: string : = '' ; width: real : = 1 2 0 ) : ComboBoxWPF;
/// Элемент управления "Главное меню"
function Menu: MenuWPF;
2020-07-20 09:27:50 +03:00
2020-07-25 23:25:47 +03:00
/// Стандартное окно диалога открытия файла
function OpenFileDialog( initDirectory: string : = '' ; filter: string : = '' ) : OpenFileDialogWPF;
/// Стандартное окно диалога сохранения файла
function SaveFileDialog( initDirectory: string : = '' ; filter: string : = '' ) : SaveFileDialogWPF;
/// Элемент управления "Левая панель"
2021-04-21 11:54:06 +03:00
function LeftPanel( width: real ; c: Color; InternalMargin: real : = 1 0 ) : PanelWPF;
/// Элемент управления "Левая панель"
function LeftPanel( width: real : = 1 5 0 ) : PanelWPF;
/// Элемент управления "Правая панель"
function RightPanel( width: real ; c: Color; InternalMargin: real : = 1 0 ) : PanelWPF;
2020-07-25 23:25:47 +03:00
/// Элемент управления "Правая панель"
2021-04-21 11:54:06 +03:00
function RightPanel( width: real : = 1 5 0 ) : PanelWPF;
2020-07-20 09:27:50 +03:00
2020-07-25 23:25:47 +03:00
/// Элемент управления "Строка статуса"
2020-07-20 09:27:50 +03:00
function StatusBar( height: real : = 2 4 ; itemWidth: real : = 0 ) : StatusBarWPF;
2019-08-18 00:16:39 +03:00
2020-07-25 23:25:47 +03:00
/// Пустой блок для задания промежутков между компонентами
2019-03-17 21:58:24 +03:00
procedure EmptyBlock( sz: integer : = 1 6 ) ;
2018-01-05 12:55:13 +03:00
2020-08-01 00:13:27 +03:00
/// Установка активной панели, на которую размещаются элементы управления
2021-07-13 23:52:47 +03:00
procedure SetActivePanel( p: CommonElementWPF) ;
2020-08-01 00:13:27 +03:00
2021-07-13 23:52:47 +03:00
/// Толщина границ элемента
function Margins( l, t, r, b: real ) : ( real , real , real , real ) ;
2020-08-01 00:13:27 +03:00
2021-07-13 23:52:47 +03:00
/// Толщина границ элемента
function Margins( all: real ) : ( real , real , real , real ) ;
2020-08-01 00:13:27 +03:00
2020-07-25 23:25:47 +03:00
/// Графическое окно
2020-08-01 00:13:27 +03:00
//function Window: WindowType;
2020-07-20 09:27:50 +03:00
2020-11-15 19:35:47 +03:00
///--
procedure __InitModule__;
///--
procedure __FinalizeModule__;
2018-01-05 12:55:13 +03:00
implementation
2020-08-01 00:13:27 +03:00
//uses GraphWPF;
2018-01-05 12:55:13 +03:00
uses System. Windows;
uses System. Windows. Controls;
uses System. Windows. Controls. Primitives;
uses System. Windows. Media. Imaging;
2020-08-01 00:13:27 +03:00
//function Window: WindowType := GraphWPF.Window;
2018-01-05 12:55:13 +03:00
2020-07-20 09:27:50 +03:00
function Button( Txt: string ; fontSize: real ) : ButtonWPF : = ButtonWPF. Create( Txt, fontSize) ;
function Button( x, y: real ; Txt: string ; width: real ; fontSize: real ) : ButtonWPF : = ButtonWPF. Create( x, y, Txt, width, fontSize) ;
2019-08-18 00:16:39 +03:00
2020-07-20 09:27:50 +03:00
function TextBlock( Txt: string ; fontSize: real ) : TextBlockWPF : = TextBlockWPF. Create( Txt, fontSize) ;
function TextBlock( x, y: real ; Txt: string ; width: real ; fontSize: real ) : TextBlockWPF : = TextBlockWPF. Create( x, y, Txt, width, fontSize) ;
2019-08-18 00:16:39 +03:00
2020-07-20 09:27:50 +03:00
function IntegerBlock( message : string ; initValue: integer ; fontSize: real ) : IntegerBlockWPF : = IntegerBlockWPF. Create( message , initValue, fontSize) ;
function IntegerBlock( x, y: real ; message : string ; width: real ; initValue: integer ; fontSize: real ) : IntegerBlockWPF : = IntegerBlockWPF. Create( x, y, message , width, initValue, fontSize) ;
2019-08-18 00:16:39 +03:00
2020-07-20 09:27:50 +03:00
function RealBlock( message : string ; initValue: real ; fontSize: real ) : RealBlockWPF : = RealBlockWPF. Create( message , initValue, fontSize) ;
function RealBlock( x, y: real ; message : string ; width: real ; initValue: real ; fontSize: real ) : RealBlockWPF : = RealBlockWPF. Create( x, y, message , width, initValue, fontSize) ;
2019-08-18 00:16:39 +03:00
2020-08-01 00:13:27 +03:00
function CheckBox( text : string ) : CheckBoxWPF : = CheckBoxWPF. Create( text ) ;
function CheckBox( x, y: real ; text : string ; width: real ) : CheckBoxWPF : = CheckBoxWPF. Create( x, y, text , width) ;
function RadioButton( text : string ) : RadioButtonWPF : = RadioButtonWPF. Create( text ) ;
function RadioButton( x, y: real ; text : string ; width: real ) : RadioButtonWPF : = RadioButtonWPF. Create( x, y, text , width) ;
2020-07-20 09:27:50 +03:00
function TextBox( text : string ) : TextBoxWPF : = TextBoxWPF. Create( text ) ;
function TextBox( x, y: real ; text : string ; width: real ) : TextBoxWPF : = TextBoxWPF. Create( x, y, text , width) ;
2019-08-18 00:16:39 +03:00
2021-11-14 22:46:25 +03:00
function IntegerBox( title: string ) : IntegerBoxWPF : = IntegerBoxWPF. Create( title, 0 , 1 0 ) ;
2020-07-24 22:00:21 +03:00
function IntegerBox( title: string ; min, max: integer ) : IntegerBoxWPF : = IntegerBoxWPF. Create( title, min, max) ;
function IntegerBox( x, y: real ; title: string ; min, max: integer ; width: real ) : = IntegerBoxWPF. Create( x, y, title, min, max, width) ;
2019-08-18 00:16:39 +03:00
2020-07-24 22:00:21 +03:00
function ListBox( title: string ; height: real ) : ListBoxWPF : = ListBoxWPF. Create( title, height) ;
function ListBox( x, y: real ; title: string ; width: real ; height: real ) : ListBoxWPF : = ListBoxWPF. Create( x, y, title, width, height) ;
2019-08-18 00:16:39 +03:00
2020-08-03 21:26:25 +03:00
function SliderReal( title: string ) : SliderRealWPF : = SliderRealWPF. Create( title, 0 , 1 0 , 0 , 0 ) ;
function SliderReal( title: string ; min, max, val, freq: real ) : SliderRealWPF;
begin
if val = real . MinValue then
val : = min;
Result : = SliderRealWPF. Create( title, min, max, val, freq) ;
end ;
function SliderReal( min, max, val, freq: real ) : SliderRealWPF : = SliderReal( '' , min, max, val, freq) ;
function SliderReal( x, y: real ; title: string ; min, max, width, val, freq: real ) : SliderRealWPF;
2020-07-20 09:27:50 +03:00
begin
if val = real . MinValue then
val : = min;
2020-08-03 21:26:25 +03:00
Result : = SliderRealWPF. Create( x, y, title, min, max, width, val, freq) ;
2020-07-20 09:27:50 +03:00
end ;
2020-08-03 21:26:25 +03:00
function Slider( title: string ) : SliderWPF : = SliderWPF. Create( title) ;
function Slider( title: string ; min, max, val, freq: integer ) : SliderWPF;
begin
if val = real . MinValue then
val : = min;
Result : = SliderWPF. Create( title, min, max, val, freq) ;
end ;
function Slider( min, max, val, freq: integer ) : SliderWPF : = Slider( '' , min, max, val, freq) ;
function Slider( x, y: real ; title: string ; min, max, width, val, freq: integer ) : SliderWPF;
2020-07-20 09:27:50 +03:00
begin
if val = real . MinValue then
val : = min;
2020-08-03 21:26:25 +03:00
Result : = SliderWPF. Create( x, y, title, min, max, width, val, freq) ;
2020-07-20 09:27:50 +03:00
end ;
2019-08-18 00:16:39 +03:00
2020-07-24 22:00:21 +03:00
function Image( name : string ) : ImageWPF : = new ImageWPF( name ) ;
2020-07-25 23:25:47 +03:00
function Image( x, y: real ; name : string ; width: real ) : ImageWPF : = new ImageWPF( x, y, name , width) ;
function ComboBox( title: string ) : ComboBoxWPF : = new ComboBoxWPF( title) ;
function ComboBox( x, y: real ; title: string ; width: real ) : ComboBoxWPF : = new ComboBoxWPF( x, y, title, width) ;
function Menu: MenuWPF : = new MenuWPF;
2020-07-24 22:00:21 +03:00
2020-07-25 23:25:47 +03:00
function OpenFileDialog( initDirectory: string ; filter: string ) : = new OpenFileDialogWPF( initDirectory, filter) ;
function SaveFileDialog( initDirectory: string ; filter: string ) : = new SaveFileDialogWPF( initDirectory, filter) ;
2020-07-24 22:00:21 +03:00
2020-07-20 09:27:50 +03:00
function LeftPanel( width: real ; c: Color; internalMargin: real ) : = new LeftPanelWPF( width, c, internalMargin) ;
2021-04-21 11:54:06 +03:00
function LeftPanel( width: real ) : PanelWPF : = new LeftPanelWPF( width, PanelsColor, 1 0 ) ;
2020-07-20 09:27:50 +03:00
function RightPanel( width: real ; c: Color; internalMargin: real ) : = new RightPanelWPF( width, c, internalMargin) ;
2021-04-21 11:54:06 +03:00
function RightPanel( width: real ) : PanelWPF : = new RightPanelWPF( width, PanelsColor, 1 0 ) ;
2019-08-18 00:16:39 +03:00
2020-07-24 22:00:21 +03:00
function StatusBar( height: real ; itemWidth: real ) : StatusBarWPF : = new StatusBarWPF( height, itemWidth) ;
2019-08-18 00:16:39 +03:00
2018-02-27 09:15:59 +03:00
procedure EmptyBlock( sz: integer ) ;
begin
2019-08-18 00:16:39 +03:00
var e : = TextBlock( '' ) ;
e. Height : = sz;
e. Width : = sz;
2018-02-27 09:15:59 +03:00
end ;
2020-07-24 22:00:21 +03:00
function GetProperties< T> ( t1: T) : sequence of string ;
begin
var props : = t1. GetType. GetProperties( ) ;
Result : = props. OrderBy( f- > f. CustomAttributes. FirstOrDefault? . ToString ? ? 'NoAttr' ) . Select( f- > f. Name ) ;
end ;
function GetFields< T> ( t1: T) : sequence of string ;
begin
var flds : = t1. GetType. GetFields( ) ;
//var flds := t1.GetType.GetFields(System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Public or System.Reflection.BindingFlags.NonPublic);
Result : = flds. OrderBy( f- > f. CustomAttributes. FirstOrDefault? . ToString ? ? 'NoAttr' ) . Select( f- > f. Name ) ;
end ;
2020-08-01 00:13:27 +03:00
type ControlsCannotBeRunWithoutGraphModules = class( System. ApplicationException) end ;
procedure Invoke( d: System. Delegate; params args: array of object ) ;
begin
if app = nil then
raise new ControlsCannotBeRunWithoutGraphModules( 'Модуль Controls должен испольоваться только совместно с модулями GraphWPF и WPFObjects либо Graph3D' ) ;
GraphWPFBase. Invoke( d, args) ;
end ;
procedure InvokeP( p: procedure( r: real ) ; r: real ) ;
begin
if app = nil then
raise new ControlsCannotBeRunWithoutGraphModules( 'Модуль Controls должен испольоваться только совместно с модулями GraphWPF и WPFObjects либо Graph3D' ) ;
GraphWPFBase. Invoke( p, r) ;
end ;
function Invoke< T> ( d: Func0< T> ) : T;
begin
if app = nil then
raise new ControlsCannotBeRunWithoutGraphModules( 'Модуль Controls должен испольоваться только совместно с модулями GraphWPF и WPFObjects либо Graph3D' ) ;
Result : = T( app. Dispatcher. Invoke( d) ) ;
end ;
procedure __SetActivePanelInternal( p: GPanel) ;
begin
Invoke( ( ) - > begin
_ActivePanel : = p;
end ) ;
end ;
2021-07-13 23:52:47 +03:00
procedure SetActivePanel( p: CommonElementWPF) ;
2020-08-01 00:13:27 +03:00
begin
2021-07-13 23:52:47 +03:00
if p. element is GPanel then
__SetActivePanelInternal( p. element as GPanel)
2020-08-01 00:13:27 +03:00
end ;
2020-07-24 22:00:21 +03:00
2019-03-17 21:58:24 +03:00
procedure SetActivePanelInit;
begin
2020-08-01 00:13:27 +03:00
__SetActivePanelInternal( MainWindow. MainPanel. Children[ 0 ] as GPanel) ;
//ActivePanel := MainWindow.MainPanel.Children[0] as GPanel
2019-03-17 21:58:24 +03:00
end ;
2018-02-27 09:15:59 +03:00
2020-08-01 00:13:27 +03:00
function __ActivePanelInternal: GPanel;
2018-01-05 12:55:13 +03:00
begin
2020-08-01 00:13:27 +03:00
if _ActivePanel = nil then
Invoke( SetActivePanelInit) ;
Result : = _ActivePanel;
end ;
2021-07-13 23:52:47 +03:00
function Margins( l, t, r, b: real ) : ( real , real , real , real ) : = ( l, t, r, b) ;
function Margins( all: real ) : ( real , real , real , real ) : = ( all, all, all, all) ;
procedure CommonElementWPF. Init0( el: FrameworkElement; width: real ; x: real ; y: real ) ;
begin
element : = el;
element. Focusable : = False ;
if __ActivePanelInternal is StackPanel( var sp) then
if sp. Orientation = Orientation. Vertical then
element. Margin : = new Thickness( 0 , 0 , 0 , GlobalHMargin) ;
//else element.Margin := new Thickness(0,0,GlobalHMargin,0);
if x< > - 1 then
begin
element. SetLeft( x) ;
element. SetTop( y) ;
end ;
if width> 0 then
element. Width : = width;
__ActivePanelInternal. Children. Add( element) ;
if __ActivePanelInternal. Tag is PanelWPF( var pwpf) then
PanelWPF. SetFSzElement( element, pwpf. fsize) ;
if __ActivePanelInternal. Tag is GridWPF( var grwpf) then
element. Margin : = new Thickness( grwpf. InternalMargin) ;
end ;
2020-11-15 19:35:47 +03:00
var
///--
__initialized : = false ;
var
///--
__finalized : = false ;
///--
procedure __InitModule__;
begin
if not __initialized then
begin
__initialized : = true ;
end ;
end ;
///--
procedure __FinalizeModule__;
begin
if not __finalized then
begin
__finalized : = true ;
end ;
end ;
2020-08-01 00:13:27 +03:00
initialization
finalization
2018-01-05 12:55:13 +03:00
end .