gtk: move CreateComponent code for ToggleBox, RadioButton, Checkbox, PopupMenu, MainMenu to CreateHandle and FinishComponentCreate to SetCallbacks

git-svn-id: trunk@13457 -
This commit is contained in:
paul 2007-12-26 03:06:56 +00:00
parent 760f373489
commit 07cb989050
4 changed files with 190 additions and 115 deletions

View File

@ -4731,15 +4731,9 @@ end;
function TGTKWidgetSet.CreateComponentWidget(Sender: TObject; ACompStyle: Integer; const ACaption: String): PGtkWidget;
var
p: Pointer absolute Result;
TempWidget,
TempWidget2 : PGTKWidget; // pointer to gtk-widget (local use when neccessary)
TempInt : Integer; // local use when neccessary
Box : Pointer; // currently only used for MainMenu
ParentForm: TCustomForm;
Adjustment: PGtkAdjustment;
LabelWidget: PGtkLabel;
begin
Result := nil;
@ -4769,12 +4763,6 @@ begin
gtk_widget_show_all(p);
end;
csCheckbox :
begin
p := gtk_check_button_new_with_label(PChar(ACaption));
end;
csColorDialog :
begin
P := gtk_color_selection_dialog_new(PChar(ACaption));
@ -4785,7 +4773,6 @@ begin
InitializeCommonDialog(TCommonDialog(Sender),p);
end;
csFileDialog, csOpenFileDialog, csSaveFileDialog, csSelectDirectoryDialog,
csPreviewFileDialog:
InitializeFileDialog(TFileDialog(Sender),p,PChar(ACaption));
@ -4802,32 +4789,6 @@ begin
p := gtk_image_new();
end;
csMainMenu:
begin
p := gtk_menu_bar_new();
// get the VBox, the form has one child, a VBox
ParentForm:=TCustomForm(TMenu(Sender).Parent);
if (ParentForm=nil) or (not (ParentForm is TCustomForm)) then
RaiseGDBException('MainMenu without form');
if ParentForm.Menu<>TMenu(Sender) then
RaiseGDBException('form has already a MainMenu');
if ParentForm.HandleAllocated then begin
Box := PGTKBin(ParentForm.Handle)^.Child;
gtk_box_pack_start(Box, p, False, False, 0);
end;
gtk_widget_show(p);
end;
csMenuBar :
begin
P := gtk_menu_bar_new();
gtk_container_add(
GTK_Container(
GetFixedWidget(Pointer(TWinControl(TMenu(Sender).Owner).Handle))), P);
gtk_widget_show(p);
end;
csPage: // TCustomPage - Notebook page
P:=CreateSimpleClientAreaWidget(Sender, true);
@ -4837,9 +4798,6 @@ begin
csPairSplitterSide:
P:=CreateSimpleClientAreaWidget(Sender,true);
csPopupMenu :
P := gtk_menu_new();
csPreviewFileControl:
P:=CreateSimpleClientAreaWidget(Sender,true);
@ -4852,29 +4810,6 @@ begin
P := gtk_progress_bar_new_with_adjustment (PGtkAdjustment (TempWidget));
end;
csRadioButton :
with TRadioButton(Sender) do
begin
// Look for our parent's control and use the first radio we find for grouping
TempWidget:= nil;
if (Parent <> nil) then begin
for TempInt:= 0 to Parent.ControlCount - 1 do begin
if (Parent.Controls[TempInt] is TRadioButton)
and TWinControl(Parent.Controls[TempInt]).HandleAllocated then begin
TempWidget:= PGtkWidget(TWinControl(Parent.Controls[TempInt]).Handle);
Break;
end;
end;
end;
if TempWidget <> nil then
P:= gtk_radio_button_new_with_label(PGtkRadioButton(TempWidget)^.group,'')
else
P:= gtk_radio_button_new_with_label(nil, '');
LabelWidget:=pGtkLabel(gtk_bin_get_child(PGtkBin(@PGTKToggleButton(P)^.Button)));
SetLabelCaption(LabelWidget, PChar(ACaption)
{$IFDEF Gtk1}, TWinControl(Sender),PGtkWidget(p), 'clicked'{$ENDIF});
end;
csScrollBar :
begin
Adjustment := PgtkAdjustment(
@ -4904,11 +4839,6 @@ begin
p:=CreateStatusBar(Sender);
end;
csToggleBox :
begin
P := gtk_toggle_button_new_with_label(PChar(ACaption));
end;
csToolbar:
P:=CreateToolBar(Sender);
@ -4980,8 +4910,12 @@ begin
csForm,
csEdit,
csBitBtn,
csButton: DebugLn('[WARNING] Obsolete call to TGTKOBject.CreateComponent for ', Sender.ClassName);
csButton,
csToggleBox,
csRadioButton,
csPopupMenu,
csCheckbox,
csMainMenu: DebugLn('[WARNING] Obsolete call to TGTKOBject.CreateComponent for ', Sender.ClassName);
end; //end case
end;

View File

@ -34,7 +34,7 @@ uses
{$ENDIF}
GtkInt, gtkProc, gtkglobals, GTKExtra,
Classes, InterfaceBase, Types, LCLProc, LCLType, WSMenus, WSLCLClasses,
Graphics, Menus;
Graphics, Menus, Forms;
type
{ TGtkWSMenuItem }
@ -62,7 +62,7 @@ type
private
protected
public
class function CreateHandle(const AMenu: TMenu): HMENU; override;
class function CreateHandle(const AMenu: TMenu): HMENU; override;
end;
{ TGtkWSMainMenu }
@ -79,6 +79,7 @@ type
private
protected
public
class function CreateHandle(const AMenu: TMenu): HMENU; override;
class procedure Popup(const APopupMenu: TPopupMenu; const X, Y: integer); override;
end;
@ -157,10 +158,7 @@ class function TGtkWSMenuItem.CreateHandle(const AMenuItem: TMenuItem): HMENU;
var
MenuItemWidget: PGtkWidget;
begin
//Result := HMENU(TGtkWidgetSet(WidgetSet).CreateComponent(AMenuItem));
MenuItemWidget:=CreateMenuItem(AMenuItem);
//Set_RC_Name(AMenuItem,MenuItemWidget);
MenuItemWidget := CreateMenuItem(AMenuItem);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(MenuItemWidget,dbgsName(AMenuItem));
{$ENDIF}
@ -268,13 +266,34 @@ end;
{ TGtkWSMenu }
class function TGtkWSMenu.CreateHandle(const AMenu: TMenu): HMENU;
var
Widget: PGtkWidget;
Box: Pointer;
ParentForm: TCustomForm;
begin
{ TODO: cleanup }
Result := HMENU(TGtkWidgetSet(WidgetSet).CreateComponent(AMenu));
Widget := gtk_menu_bar_new();
// get the VBox, the form has one child, a VBox
ParentForm := TCustomForm(AMenu.Parent);
if (ParentForm=nil) or (not (ParentForm is TCustomForm)) then
RaiseGDBException('MainMenu without form');
if ParentForm.Menu <> AMenu then
RaiseGDBException('Form already has a MainMenu');
if ParentForm.HandleAllocated then
begin
Box := PGTKBin(ParentForm.Handle)^.Child;
gtk_box_pack_start(Box, Widget, False, False, 0);
end;
gtk_widget_show(Widget);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AMenu));
{$ENDIF}
Result := THandle(PtrUInt(Widget));
// no callbacks for main menu
end;
{ TGtkWSPopupMenu }
procedure GtkWS_Popup(menu: PGtkMenu; X, Y: pgint;
procedure GtkWS_Popup(menu: PGtkMenu; X, Y: pgint;
{$IFDEF GTK2} ForceInScreen: pgboolean; {$ENDIF}
Point: PPoint); cdecl;
begin
@ -282,6 +301,18 @@ begin
Y^ := Point^.Y;
end;
class function TGtkWSPopupMenu.CreateHandle(const AMenu: TMenu): HMENU;
var
Widget: PGtkWidget;
begin
Widget := gtk_menu_new;
Result := HMENU(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(Sender));
{$ENDIF}
// no callbacks for popup menu
end;
class procedure TGtkWSPopupMenu.Popup(const APopupMenu: TPopupMenu;
const X, Y: integer);
var
@ -296,7 +327,7 @@ begin
AProc := nil
else
AProc := @GtkWS_Popup;
gtk_menu_popup(PgtkMenu(APopupMenu.Handle),
gtk_menu_popup(PGtkMenu(APopupMenu.Handle),
nil,
nil,
TGtkMenuPositionFunc(AProc),

View File

@ -58,7 +58,6 @@ type
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
// class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
@ -148,11 +147,9 @@ type
TGtkWSCustomEdit = class(TWSCustomEdit)
private
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
public
{$IFDEF GTK1}
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
// class procedure DestroyHandle(const AWinControl: TWinControl); override;
{$ENDIF}
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
@ -282,7 +279,9 @@ type
TGtkWSCustomCheckBox = class(TWSCustomCheckBox)
private
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function RetrieveState(const ACustomCheckBox: TCustomCheckBox
): TCheckBoxState; override;
class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox;
@ -310,6 +309,7 @@ type
private
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
end;
{ TGtkWSRadioButton }
@ -318,6 +318,7 @@ type
private
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
end;
function WidgetGetSelStart(const Widget: PGtkWidget): integer;
@ -934,21 +935,39 @@ end;
{ TGtkWSCustomEdit }
{$IFDEF GTK1}
class procedure TGtkWSCustomEdit.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
with TGtkWidgetset(Widgetset) do
begin
SetCallback(LM_CHANGED, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_ACTIVATE, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_CUTTOCLIP, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_COPYTOCLIP, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
SetCallback(LM_PASTEFROMCLIP, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
end;
end;
class function TGtkWSCustomEdit.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
p: pointer; // ptr to the newly created GtkWidget
Widget: PGtkWidget; // ptr to the newly created GtkWidget
WidgetInfo: PWidgetInfo;
begin
p := gtk_entry_new();
GtkWidgetSet.FinishComponentCreate(AWinControl, P);
Widget := gtk_entry_new();
gtk_editable_set_editable(PGtkEditable(Widget), not TCustomEdit(AWinControl).ReadOnly);
gtk_widget_show_all(Widget);
Result := TLCLIntfHandle(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P,dbgsName(AWinControl));
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(PtrUInt(P));
if Result = 0 then
Exit;
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
SetCallbacks(Widget, WidgetInfo);
end;
{$ENDIF}
class function TGtkWSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit): integer;
begin
@ -1375,6 +1394,36 @@ end;
{ TGtkWSCustomCheckBox }
class procedure TGtkWSCustomCheckBox.SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
TGtkWidgetset(WidgetSet).SetCallback(LM_CHANGED, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
end;
class function TGtkWSCustomCheckBox.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams
): TLCLIntfHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
begin
Widget := gtk_check_button_new_with_label(AParams.Caption);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := THandle(PtrUInt(Widget));
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(PGtkWidget(Result), @Allocation);
SetCallbacks(PGtkWidget(Result), WidgetInfo);
end;
class function TGtkWSCustomCheckBox.RetrieveState(
const ACustomCheckBox: TCustomCheckBox): TCheckBoxState;
var
@ -1721,6 +1770,84 @@ begin
//debugln('TGtkWSCustomGroupBox.GetPreferredSize ',DbgSName(AWinControl),' PreferredWidth=',dbgs(PreferredWidth),' PreferredHeight=',dbgs(PreferredHeight));
end;
{ TGtkWSRadioButton }
class function TGtkWSRadioButton.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
Widget, TempWidget: PGtkWidget;
LabelWidget: PGtkLabel;
TempInt: Integer;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
begin
with TRadioButton(AWinControl) do
begin
// Look for our parent's control and use the first radio we find for grouping
TempWidget := nil;
if (Parent <> nil) then
begin
for TempInt := 0 to Parent.ControlCount - 1 do
begin
if (Parent.Controls[TempInt] is TRadioButton) and
TWinControl(Parent.Controls[TempInt]).HandleAllocated then
begin
TempWidget := PGtkWidget(TWinControl(Parent.Controls[TempInt]).Handle);
Break;
end;
end;
end;
if TempWidget <> nil then
Widget := gtk_radio_button_new_with_label(PGtkRadioButton(TempWidget)^.group,'')
else
Widget := gtk_radio_button_new_with_label(nil, '');
LabelWidget := PGtkLabel(gtk_bin_get_child(PGtkBin(@PGTKToggleButton(Widget)^.Button)));
GtkWidgetSet.SetLabelCaption(LabelWidget, AParams.Caption
{$IFDEF Gtk1}, AWinControl, Widget, 'clicked'{$ENDIF});
end;
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := THandle(PtrUInt(Widget));
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(PGtkWidget(Result), @Allocation);
TGtkWSCustomCheckBox.SetCallbacks(PGtkWidget(Result), WidgetInfo);
end;
{ TGtkWSToggleBox }
class function TGtkWSToggleBox.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
Allocation: TGTKAllocation;
begin
Widget := gtk_toggle_button_new_with_label(AParams.Caption);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := THandle(PtrUInt(Widget));
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Allocation.X := AParams.X;
Allocation.Y := AParams.Y;
Allocation.Width := AParams.Width;
Allocation.Height := AParams.Height;
gtk_widget_size_allocate(PGtkWidget(Result), @Allocation);
TGtkWSCustomCheckBox.SetCallbacks(PGtkWidget(Result), WidgetInfo);
end;
initialization
////////////////////////////////////////////////////
@ -1746,8 +1873,8 @@ initialization
{$endif}
RegisterWSComponent(TCustomCheckBox, TGtkWSCustomCheckBox);
// RegisterWSComponent(TCheckBox, TGtkWSCheckBox);
// RegisterWSComponent(TToggleBox, TGtkWSToggleBox);
// RegisterWSComponent(TRadioButton, TGtkWSRadioButton);
RegisterWSComponent(TToggleBox, TGtkWSToggleBox);
RegisterWSComponent(TRadioButton, TGtkWSRadioButton);
RegisterWSComponent(TCustomStaticText, TGtkWSCustomStaticText);
// RegisterWSComponent(TStaticText, TGtkWSStaticText);
////////////////////////////////////////////////////

View File

@ -179,9 +179,8 @@ type
private
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override;
class procedure SetPasswordChar(const ACustomEdit: TCustomEdit; NewChar: char); override;
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
@ -723,22 +722,6 @@ end;
{ TGtk2WSCustomEdit }
class function TGtk2WSCustomEdit.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
p: PGtkWidget; // ptr to the newly created GtkWidget
begin
p := gtk_entry_new();
gtk_editable_set_editable (PGtkEditable(P), not TCustomEdit(AWinControl).ReadOnly);
gtk_widget_show_all(P);
Result := TLCLIntfHandle(PtrUInt(P));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(p,dbgsName(AWinControl));
{$ENDIF}
gtk2WidgetSet.FinishComponentCreate(AWinControl, P);
end;
class function TGtk2WSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit
): integer;
var