Initial commit
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#include <vcl.h>
|
||||
#pragma hdrstop
|
||||
|
||||
#include "RadioBtn.h"
|
||||
//---------------------------------------------------------------------------
|
||||
#pragma package(smart_init)
|
||||
//---------------------------------------------------------------------------
|
||||
static inline void ValidCtrCheck(TRadioBtn *)
|
||||
{
|
||||
new TRadioBtn(NULL);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Radiobtn
|
||||
{
|
||||
void __fastcall PACKAGE Register()
|
||||
{
|
||||
TComponentClass classes[1] = {__classid(TRadioBtn)};
|
||||
RegisterComponents(L"Samples", classes, 0);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TRadioBtn::TRadioBtn(System::Classes::TComponent* AOwner) : TPanel(AOwner)
|
||||
{
|
||||
m_pRaBtn = new TRadioButton(this);
|
||||
m_pRaBtn->Parent = this;
|
||||
m_pRaBtn->ControlStyle>>csOpaque;
|
||||
m_pRaBtn->Caption= L"";
|
||||
m_pRaBtn->OnClick = Onclicked;
|
||||
|
||||
m_lbCaption = new TLabel(this);
|
||||
m_lbCaption->Parent = this;
|
||||
m_lbCaption->ControlStyle>>csOpaque;
|
||||
m_lbCaption->OnClick = Onclicked;
|
||||
m_lbCaption->OnMouseMove = MouseMoveEvent;
|
||||
|
||||
this->OnMouseMove = MouseMoveEvent;
|
||||
|
||||
FChecked = false;
|
||||
FEnabled = true;
|
||||
|
||||
SetChildBounds();
|
||||
SetCaption(L"TRadioBtn");
|
||||
SetFont(Font);
|
||||
|
||||
ControlStyle >> csOpaque;
|
||||
|
||||
Width = 100;
|
||||
Height = 17;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TRadioBtn::~TRadioBtn(void)
|
||||
{
|
||||
if(m_lbCaption) delete m_lbCaption;
|
||||
if(m_pRaBtn) delete m_pRaBtn;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::SetChildBounds()
|
||||
{
|
||||
int nEdge = GetSystemMetrics(SM_CXMENUCHECK);
|
||||
|
||||
int mHgt = m_lbCaption->Height;
|
||||
if( mHgt>Height ) Height = mHgt;
|
||||
|
||||
m_lbCaption->SetBounds(nEdge+1, (Height-m_lbCaption->Height)/2,
|
||||
m_lbCaption->Width, m_lbCaption->Height);
|
||||
|
||||
m_pRaBtn->SetBounds(0, 0, nEdge, Height);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::CreateWnd(void)
|
||||
{
|
||||
Vcl::Extctrls::TPanel::CreateWnd();
|
||||
|
||||
SetWindowLong( Parent->Handle, GWL_STYLE,
|
||||
GetWindowLong(Parent->Handle, GWL_STYLE) & ~WS_CLIPCHILDREN );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::CreateParams(Controls::TCreateParams &Params)
|
||||
{
|
||||
Vcl::Extctrls::TPanel::CreateParams(Params);
|
||||
|
||||
Params.ExStyle |= WS_EX_TRANSPARENT;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::Paint()
|
||||
{
|
||||
SetBkMode( Canvas->Handle, TRANSPARENT );
|
||||
StyleServices()->DrawParentBackground( Handle, Canvas->Handle, NULL, true);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::WMSize(Winapi::Messages::TWMSize &Message)
|
||||
{
|
||||
SetChildBounds();
|
||||
}
|
||||
//--------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::SetCaption(String FCaptionTmp)
|
||||
{
|
||||
m_lbCaption->Caption = FCaptionTmp;
|
||||
FCaption = FCaptionTmp;
|
||||
}
|
||||
//--------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::SetFont(TFont *FFontTmp)
|
||||
{
|
||||
m_lbCaption->Font = FFontTmp;
|
||||
SetChildBounds();
|
||||
this->Invalidate();
|
||||
}
|
||||
//--------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::SetChecked(bool bChecked)
|
||||
{
|
||||
m_pRaBtn->Checked = bChecked;
|
||||
FChecked = bChecked;
|
||||
}
|
||||
//--------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::SetEnabled(bool bEnabled)
|
||||
{
|
||||
FEnabled = bEnabled;
|
||||
|
||||
m_lbCaption->Enabled = bEnabled;
|
||||
|
||||
m_pRaBtn->Enabled = bEnabled;
|
||||
}
|
||||
//--------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::SetCheckedSameparent(TWinControl* pCtrl)
|
||||
{
|
||||
if( pCtrl->ClassNameIs( TRadioBtn::ClassName() ) ){
|
||||
TRadioBtn *pTRadioBtn = (TRadioBtn *)pCtrl;
|
||||
if( pTRadioBtn->Checked && pTRadioBtn!=this )
|
||||
pTRadioBtn->Checked = false;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::Onclicked(TObject *Sender)
|
||||
{
|
||||
if(!FChecked) {
|
||||
SetChecked(true);
|
||||
for( int i=0; i<this->Parent->ControlCount; i++ ){
|
||||
SetCheckedSameparent( (TWinControl*)(this->Parent->Controls[i]) );
|
||||
}
|
||||
if( OnClick ) OnClick(this);
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::Click(void)
|
||||
{
|
||||
if( !FEnabled ) return;
|
||||
|
||||
Onclicked(NULL);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TRadioBtn::MouseMoveEvent(System::TObject* Sender, System::Classes::TShiftState Shift, int X, int Y)
|
||||
{
|
||||
if( !FEnabled ) return;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,55 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#ifndef RadioBtnH
|
||||
#define RadioBtnH
|
||||
//---------------------------------------------------------------------------
|
||||
#include <System.SysUtils.hpp>
|
||||
#include <System.Classes.hpp>
|
||||
#include <Vcl.Controls.hpp>
|
||||
#include <Vcl.ExtCtrls.hpp>
|
||||
//---------------------------------------------------------------------------
|
||||
class PACKAGE TRadioBtn :public TPanel {
|
||||
|
||||
private:
|
||||
|
||||
bool FChecked;
|
||||
bool FEnabled;
|
||||
String FCaption;
|
||||
void __fastcall SetCaption(String FCaptionTmp);
|
||||
void __fastcall SetFont(TFont *FFontTmp);
|
||||
void __fastcall SetChecked(bool bChecked);
|
||||
void __fastcall SetEnabled(bool bEnabled);
|
||||
|
||||
|
||||
TLabel *m_lbCaption;
|
||||
TRadioButton *m_pRaBtn;
|
||||
|
||||
void __fastcall Onclicked(TObject *Sender);
|
||||
void __fastcall SetCheckedSameparent(TWinControl* pCtrl);
|
||||
void __fastcall SetChildBounds();
|
||||
COLORREF __fastcall TransformColor(COLORREF icolor, int nNum, bool bplus=true);
|
||||
|
||||
void __fastcall MouseMoveEvent(System::TObject* Sender, System::Classes::TShiftState Shift, int X, int Y);
|
||||
|
||||
virtual void __fastcall CreateWnd();
|
||||
virtual void __fastcall CreateParams(Controls::TCreateParams &Params);
|
||||
virtual void __fastcall Paint(void);
|
||||
|
||||
DYNAMIC void __fastcall Click(void);
|
||||
MESSAGE void __fastcall WMSize(Winapi::Messages::TWMSize &Message);
|
||||
BEGIN_MESSAGE_MAP
|
||||
MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize)
|
||||
END_MESSAGE_MAP( TPanel )
|
||||
|
||||
public:
|
||||
|
||||
__fastcall TRadioBtn(System::Classes::TComponent* AOwner);
|
||||
__fastcall ~TRadioBtn(void);
|
||||
|
||||
__published:
|
||||
__property Font = {write=SetFont};
|
||||
__property String Caption = {read=FCaption, write=SetCaption};
|
||||
__property bool Checked = {read=FChecked, write=SetChecked, default=false};
|
||||
__property bool Enabled = {read=FEnabled, write=SetEnabled, default=true};
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <System.hpp>
|
||||
#pragma hdrstop
|
||||
#pragma package(smart_init)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Package source.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
#pragma argsused
|
||||
extern "C" int _libmain(unsigned long reason)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user