Moved the creation of Edit, StaticText and Panel from the old CreateComponent to the new CreateHandle methods on Gtk. Also moved CreateForm into the CreateHandle method.

git-svn-id: trunk@11540 -
This commit is contained in:
sekelsenmat 2007-07-17 09:31:14 +00:00
parent 3447519a82
commit 8781f4543a
9 changed files with 254 additions and 150 deletions

View File

@ -146,7 +146,6 @@ type
function CreateComboBox(ComboBoxObject: TObject): Pointer;
{$ENDIF}
function CreateAPIWidget(AWinControl: TWinControl): PGtkWidget;
function CreateForm(ACustomForm: TCustomForm): PGtkWidget; virtual;
function CreatePairSplitter(PairSplitterObject: TObject): PGtkWidget;
function CreateStatusBar(StatusBar: TObject): PGtkWidget;
function OldCreateStatusBarPanel(StatusBar: TObject; Index: integer): PGtkWidget;

View File

@ -4686,90 +4686,6 @@ begin
end;
end;
function TGtkWidgetSet.CreateForm(ACustomForm: TCustomForm): PGtkWidget;
var
Box: Pointer;
ABorderStyle: TFormBorderStyle;
PCaption: PChar;
WindowType: TGtkWindowType;
begin
if ACustomForm.Parent=nil then begin
if csDesigning in ACustomForm.ComponentState then
ABorderStyle:=bsSizeable
else
ABorderStyle:=ACustomForm.BorderStyle;
end else
ABorderStyle:=bsNone;
WindowType:=FormStyleMap[ABorderStyle];
if (ABorderStyle=bsNone) and (ACustomForm.FormStyle in fsAllStayOnTop)
and (not (csDesigning in ACustomForm.ComponentState)) then begin
WindowType:=GTK_WINDOW_POPUP;
end;
if ACustomForm.Parent=nil then begin
// create a floating form
Result := gtk_window_new(WindowType);
{$IFDEF Gtk2}
g_signal_connect(GTK_OBJECT(Result), 'window-state-event',
gtk_signal_func(@GTKWindowStateEventCB),
ACustomForm);
{$ENDIF}
gtk_window_set_policy(GTK_WINDOW(Result), FormResizableMap[ABorderStyle],
FormResizableMap[ABorderStyle], 0);
PCaption:=PChar(ACustomForm.Caption);
if PCaption=nil then PCaption:=#0;
gtk_window_set_title(pGtkWindow(Result), PCaption);
// Shows in taskbar only Main Form.
// MG: on some systems like the default under ubuntu, this also removes
// it from the window cycle list, so you can no longer switch to each window.
// So I disabled it until a better solution is found.
{$IFDEF HasGTK2_2}
{if Assigned(ACustomForm) then
if (ACustomForm=Application.MainForm) OR (Application.MainForm = Nil) then
begin
gtk_window_set_skip_taskbar_hint(pGtkWindow(Result),False); //SHOW
end
else
begin
gtk_window_set_skip_taskbar_hint(pGtkWindow(Result),True); //HIDE
end;}
{$ENDIF}
// the clipboard needs a widget
if ClipboardWidget=nil then
SetClipboardWidget(Result);
//drag icons
if Drag_Icon = nil then begin
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
Drag_Icon := gdk_pixmap_colormap_create_from_xpm_d (nil,
gtk_widget_get_colormap (Result), Drag_Mask,
nil, @IMGDrag_Icon[0]);
{$IFDEF DebugGDK}EndGDKErrorTrap;{$ENDIF}
end;
end else begin
// create a form as child control
Result := gtk_hbox_new(false,0);
end;
Box := CreateFormContents(ACustomForm,Result);
gtk_container_add(PGtkContainer(Result), Box);
{$IfDef GTK2}
//so we can double buffer ourselves, eg, the Form Designer
gtk_widget_set_double_buffered(Box, False);
{$EndIf}
gtk_widget_show(Box);
// main menu
if (ACustomForm.Menu<>nil)
and (ACustomForm.Menu.HandleAllocated) then begin
gtk_box_pack_start(Box, PGtkWidget(ACustomForm.Menu.Handle),False,False,0);
end;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.CreatePairSplitter(PairSplitterObject: TObject
): PGtkWidget;
@ -5032,15 +4948,15 @@ begin
'clicked', gtk_signal_func(@gtkDialogCancelclickedCB), Sender);
InitializeCommonDialog(TCommonDialog(Sender),p);
end;
{$IFDEF GTK1}
csComboBox :
p:=CreateComboBox(TComboBox(Sender));
{$ENDIF}
{$IfDef GTK1}
csEdit :
p := gtk_entry_new();
{$EndIF}
RaiseGDBException('obsolete call to CreateComponent');
csFileDialog, csOpenFileDialog, csSaveFileDialog, csSelectDirectoryDialog,
csPreviewFileDialog:
InitializeFileDialog(TFileDialog(Sender),p,StrTemp);
@ -5052,7 +4968,8 @@ begin
p:=CreateAPIWidget(TWinControl(Sender));
csForm:
p:=CreateForm(TCustomForm(Sender));
RaiseGDBException('obsolete call to CreateComponent');
(*
csFrame :
begin
@ -5061,15 +4978,7 @@ begin
end;
*)
csGroupBox:
begin
P := gtk_frame_new (StrTemp);
TempWidget := CreateFixedClientWidget;
gtk_container_add(GTK_CONTAINER(p), TempWidget);
gtk_widget_show(TempWidget);
SetFixedWidget(p, TempWidget);
SetMainWidget(p, TempWidget);
gtk_widget_show (P);
end;
RaiseGDBException('obsolete call to CreateComponent');
csHintWindow :
Begin
@ -5101,13 +5010,6 @@ begin
p := gtk_image_new();
end;
csStaticText:
begin
P := gtk_label_new(StrTemp);
SetLabelAlignment(PGtkLabel(p),TCustomStaticText(Sender).Alignment);
end;
csListBox, csCheckListBox:
{$IFdef GTK2}
begin
@ -5149,7 +5051,6 @@ begin
DebugLn('[WARNING] Obsolete call to TGTKObject.CreateComponent for ', Sender.ClassName);
end;
csMainMenu:
begin
p := gtk_menu_bar_new();
@ -5195,6 +5096,7 @@ begin
gtk_widget_show_all(P);
end;
{$EndIF}
csMenuBar :
begin
P := gtk_menu_bar_new();
@ -5217,17 +5119,7 @@ begin
P:=CreateSimpleClientAreaWidget(Sender,true);
csPanel:
begin
// create a fixed widget in a horizontal box
// a fixed on a fixed has no z-order
p := gtk_hbox_new(false,0);
TempWidget := CreateFixedClientWidget;
gtk_container_add(GTK_CONTAINER(P), TempWidget);
gtk_widget_show(TempWidget);
SetFixedWidget(p, TempWidget);
SetMainWidget(p, TempWidget);
gtk_widget_show(P);
end;
RaiseGDBException('obsolete call to CreateComponent');
csPopupMenu :
with (TPopupMenu(Sender)) do
@ -5293,7 +5185,10 @@ begin
end;
csSpinEdit :
RaiseGDBException('this should never be called');
RaiseGDBException('obsolete call to CreateComponent');
csStaticText:
RaiseGDBException('obsolete call to CreateComponent');
csStatusBar :
begin

View File

@ -9450,29 +9450,9 @@ begin
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is not a gtkwindow');
{$IFDEF Gtk2}
//debugln('TGtkWidgetSet.ShowWindow A ',GetWidgetDebugReport(PGtkWidget(GtkWindow)),' nCmdShow=',dbgs(nCmdShow),' SW_MINIMIZE=',dbgs(SW_MINIMIZE=nCmdShow));
case nCmdShow of
SW_SHOWNORMAL:
begin
gtk_window_deiconify(GtkWindow);
gtk_window_unmaximize(GtkWindow);
end;
SW_HIDE:
gdk_window_hide(PgtkWidget(GtkWindow)^.Window);
SW_MINIMIZE:
gtk_window_iconify(GtkWindow);
SW_SHOWMAXIMIZED:
gtk_window_maximize(GtkWindow);
end;
// Implemented on gtk2winapi.inc
// This ifdef is necessary otherwise the gtk2 interface wont compile
{$ELSE}
case nCmdShow of
SW_SHOWNORMAL:
@ -9497,9 +9477,9 @@ begin
end;
end;
Result:=true;
{$ENDIF}
Result:=true;
end;
{------------------------------------------------------------------------------

View File

@ -198,6 +198,8 @@ type
private
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
// class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure SetColor(const AWinControl: TWinControl); override;
end;
@ -571,11 +573,32 @@ begin
{$ENDIF}
end;
class function TGtkWSCustomPanel.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
TempWidget : PGTKWidget; // pointer to gtk-widget (local use when neccessary)
p : pointer; // ptr to the newly created GtkWidget
begin
// create a fixed widget in a horizontal box
// a fixed on a fixed has no z-order
p := gtk_hbox_new(false, 0);
TempWidget := CreateFixedClientWidget;
gtk_container_add(GTK_CONTAINER(P), TempWidget);
gtk_widget_show(TempWidget);
SetFixedWidget(p, TempWidget);
SetMainWidget(p, TempWidget);
gtk_widget_show(P);
GtkWidgetSet.FinishComponentCreate(AWinControl, P);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P,dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(P);
end;
class procedure TGtkWSCustomPanel.SetColor(const AWinControl: TWinControl);
var
MainWidget: PGtkWidget;
begin
if not AWinControl.HandleAllocated then exit;
{ if ((csOpaque in AWinControl.ControlStyle)

View File

@ -35,7 +35,7 @@ uses
SysUtils, Classes, LCLProc, LCLType, Controls, LMessages, InterfaceBase,
Graphics, Dialogs,Forms, Math,
WSDialogs, WSLCLClasses, WSControls, WSForms, WSProc,
gtkInt, gtkProc, gtkWSControls, gtkDef, gtkExtra, GtkWSPrivate;
gtkInt, gtkProc, gtkWSControls, gtkDef, gtkExtra, gtkGlobals, GtkWSPrivate;
type
@ -79,7 +79,7 @@ type
class procedure SetCallbacks(const AWinControl: TWinControl; const AWidgetInfo: PWidgetInfo); virtual;
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override;
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure SetFormBorderStyle(const AForm: TCustomForm;
const AFormBorderStyle: TFormBorderStyle); override;
@ -199,14 +199,109 @@ begin
end;
class function TGtkWSCustomForm.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
const AParams: TCreateParams): TLCLIntfHandle;
var
AWidgetInfo: PWidgetInfo;
p : pointer; // ptr to the newly created GtkWidget
Box: Pointer;
ABorderStyle: TFormBorderStyle;
PCaption: PChar;
WindowType: TGtkWindowType;
ACustomForm: TCustomForm;
begin
// TODO: Move GtkInt.CreateForm to here. Somewhat complicated though because
// it depends on several other methods from gtkint that are private.
Result:=WidgetSet.CreateComponent(AWinControl);
AWidgetInfo := GetWidgetInfo(Pointer(Result));
// p := GtkWidgetSet.CreateForm(TCustomForm(AWinControl));
// Start of old CreateForm method
ACustomForm := TCustomForm(AWinControl);
if ACustomForm.Parent = nil then
begin
if csDesigning in ACustomForm.ComponentState then
ABorderStyle:=bsSizeable
else
ABorderStyle:=ACustomForm.BorderStyle;
end
else
ABorderStyle:=bsNone;
WindowType := FormStyleMap[ABorderStyle];
if (ABorderStyle=bsNone) and (ACustomForm.FormStyle in fsAllStayOnTop)
and (not (csDesigning in ACustomForm.ComponentState)) then begin
WindowType:=GTK_WINDOW_POPUP;
end;
if ACustomForm.Parent = nil then
begin
// create a floating form
P := gtk_window_new(WindowType);
{$IFDEF Gtk2}
g_signal_connect(GTK_OBJECT(P), 'window-state-event',
gtk_signal_func(@GTKWindowStateEventCB),
ACustomForm);
{$ENDIF}
gtk_window_set_policy(GTK_WINDOW(P), FormResizableMap[ABorderStyle],
FormResizableMap[ABorderStyle], 0);
PCaption:=PChar(ACustomForm.Caption);
if PCaption=nil then PCaption:=#0;
gtk_window_set_title(pGtkWindow(P), PCaption);
// Shows in taskbar only Main Form.
// MG: on some systems like the default under ubuntu, this also removes
// it from the window cycle list, so you can no longer switch to each window.
// So I disabled it until a better solution is found.
{$IFDEF HasGTK2_2}
{if Assigned(ACustomForm) then
if (ACustomForm=Application.MainForm) OR (Application.MainForm = Nil) then
begin
gtk_window_set_skip_taskbar_hint(pGtkWindow(P),False); //SHOW
end
else
begin
gtk_window_set_skip_taskbar_hint(pGtkWindow(P),True); //HIDE
end;}
{$ENDIF}
// the clipboard needs a widget
if ClipboardWidget=nil then
GtkWidgetSet.SetClipboardWidget(P);
//drag icons
if Drag_Icon = nil then begin
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
Drag_Icon := gdk_pixmap_colormap_create_from_xpm_d (nil,
gtk_widget_get_colormap (P), Drag_Mask,
nil, @IMGDrag_Icon[0]);
{$IFDEF DebugGDK}EndGDKErrorTrap;{$ENDIF}
end;
end
else
begin
// create a form as child control
P := gtk_hbox_new(false,0);
end;
Box := CreateFormContents(ACustomForm, P);
gtk_container_add(PGtkContainer(P), Box);
{$IfDef GTK2}
//so we can double buffer ourselves, eg, the Form Designer
gtk_widget_set_double_buffered(Box, False);
{$EndIf}
gtk_widget_show(Box);
// main menu
if (ACustomForm.Menu <> nil) and (ACustomForm.Menu.HandleAllocated) then
begin
gtk_box_pack_start(Box, PGtkWidget(ACustomForm.Menu.Handle),False,False,0);
end;
// End of the old CreateForm method
GtkWidgetSet.FinishComponentCreate(AWinControl, P);
AWidgetInfo := GetWidgetInfo(P);
if not (csDesigning in AWinControl.ComponentState) then
AWidgetInfo^.UserData := Pointer(1);
@ -215,6 +310,11 @@ begin
@FileDragTarget, 1, GDK_ACTION_COPY);
SetCallbacks(AWinControl, AWidgetInfo);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P,dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(P);
end;
class procedure TGtkWSCustomForm.SetFormBorderStyle(const AForm: TCustomForm;

View File

@ -56,6 +56,8 @@ type
private
protected
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;
@ -144,6 +146,10 @@ type
private
protected
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;
@ -210,6 +216,8 @@ type
private
protected
public
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
// class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure SetAlignment(const ACustomStaticText: TCustomStaticText;
const NewAlignment: TAlignment); override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
@ -831,6 +839,22 @@ end;
{ TGtkWSCustomEdit }
{$IFDEF GTK1}
class function TGtkWSCustomEdit.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
p: pointer; // ptr to the newly created GtkWidget
begin
p := gtk_entry_new();
GtkWidgetSet.FinishComponentCreate(AWinControl, P);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P,dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(P);
end;
{$ENDIF}
class function TGtkWSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit): integer;
begin
Result := WidgetGetSelStart(GetWidgetInfo(Pointer(ACustomEdit.Handle),
@ -932,6 +956,24 @@ end;
{ TGtkWSCustomStaticText }
class function TGtkWSCustomStaticText.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams
): TLCLIntfHandle;
var
p : pointer; // ptr to the newly created GtkWidget
begin
p := nil;
P := gtk_label_new(AParams.Caption);
SetLabelAlignment(PGtkLabel(p), TCustomStaticText(AWinControl).Alignment);
GtkWidgetset.FinishComponentCreate(AWinControl, P);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(P);
end;
class procedure TGtkWSCustomStaticText.SetAlignment(const ACustomStaticText: TCustomStaticText;
const NewAlignment: TAlignment);
begin
@ -1314,6 +1356,27 @@ end;
{ TGtkWSCustomGroupBox }
class function TGtkWSCustomGroupBox.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
var
TempWidget : PGTKWidget; // pointer to gtk-widget (local use when neccessary)
p : pointer; // ptr to the newly created GtkWidget
begin
P := gtk_frame_new (AParams.Caption);
TempWidget := CreateFixedClientWidget;
gtk_container_add(GTK_CONTAINER(p), TempWidget);
gtk_widget_show(TempWidget);
SetFixedWidget(p, TempWidget);
SetMainWidget(p, TempWidget);
gtk_widget_show (P);
GtkWidgetSet.FinishComponentCreate(AWinControl, P);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(P,dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(P);
end;
class procedure TGtkWSCustomGroupBox.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
var

View File

@ -75,6 +75,7 @@ type
function CreateThemeServices: TThemeServices; override;
public
function LCLPlatform: TLCLPlatform; override;
function AppHandle: Thandle; override;
{$I gtk2winapih.inc}
{$I gtk2lclintfh.inc}

View File

@ -481,6 +481,47 @@ begin
end;
end;
{------------------------------------------------------------------------------
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
nCmdShow:
SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED
------------------------------------------------------------------------------}
function TGtk2WidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
var
GtkWindow: PGtkWindow;
begin
Result:=false;
GtkWindow:=PGtkWindow(hWnd);
if GtkWindow=nil then
RaiseGDBException('TGtk2WidgetSet.ShowWindow hWnd is nil');
if not GtkWidgetIsA(PGtkWidget(GtkWindow),GTK_TYPE_WINDOW) then
RaiseGDBException('TGtk2WidgetSet.ShowWindow hWnd is not a gtkwindow');
//debugln('TGtk2WidgetSet.ShowWindow A ',GetWidgetDebugReport(PGtkWidget(GtkWindow)),' nCmdShow=',dbgs(nCmdShow),' SW_MINIMIZE=',dbgs(SW_MINIMIZE=nCmdShow));
case nCmdShow of
SW_SHOWNORMAL:
begin
gtk_window_deiconify(GtkWindow);
gtk_window_unmaximize(GtkWindow);
end;
SW_HIDE:
gdk_window_hide(PgtkWidget(GtkWindow)^.Window);
SW_MINIMIZE:
gtk_window_iconify(GtkWindow);
SW_SHOWMAXIMIZED:
gtk_window_maximize(GtkWindow);
end;
Result := True;
end;
{------------------------------------------------------------------------------
Function: TextOut
Params: DC:

View File

@ -44,6 +44,8 @@ function ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str:
function GetCursorPos(var lpPoint: TPoint ): Boolean; override;
function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override;
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; override;
function TextOut(DC: HDC; X,Y : Integer; Str : Pchar; Count: Integer) : Boolean; override;
function UpdateWindow(Handle: HWND): Boolean; override;