- fixing "point" issues (change from PPoint to PQtPoint)

- fixing lazarus splash screen launch (there was assumption in the code that application already has MainForm, so all calls like Application.MainForm.Visible causes AV)
- fixing issues with Menu

git-svn-id: trunk@11448 -
This commit is contained in:
paul 2007-07-09 05:56:24 +00:00
parent 92017a02c7
commit abc335dd5a
3 changed files with 116 additions and 139 deletions

View File

@ -1172,8 +1172,12 @@ end;
Returns: Nothing
------------------------------------------------------------------------------}
procedure TQtDeviceContext.brushOrigin(retval: PPoint);
var
QtPoint: TQtPoint;
begin
QPainter_brushOrigin(Widget, retval);
QPainter_brushOrigin(Widget, @QtPoint);
retval^.x := QtPoint.x;
retval^.y := QtPoint.y;
end;
{------------------------------------------------------------------------------

View File

@ -503,17 +503,25 @@ type
TQtMenu = class(TQtWidget)
private
FIcon: QIconH;
public
MenuItem: TMenuItem;
public
constructor Create(const AParent: QWidgetH); overload;
constructor Create(const AHandle: QMenuH); overload;
destructor Destroy; override;
public
procedure PopUp(pos: PPoint; at: QActionH = nil);
function addAction(text: PWideString): TQtAction;
procedure SlotTriggered(checked: Boolean = False); cdecl;
public
procedure PopUp(pos: PQtPoint; at: QActionH = nil);
function actionHandle: QActionH;
function addMenu(title: PWideString): TQtMenu;
function addSeparator: TQtAction;
function addSeparator: TQtMenu;
procedure setChecked(p1: Boolean);
procedure setCheckable(p1: Boolean);
procedure setHasSubmenu(AValue: Boolean);
procedure setIcon(AIcon: QIconH);
procedure setImage(AImage: TQtImage);
procedure setSeparator(AValue: Boolean);
end;
{ TQtMenuBar }
@ -524,9 +532,8 @@ type
constructor Create(const AParent: QWidgetH); overload;
destructor Destroy; override;
public
function addAction(text: PWideString): TQtAction;
function addMenu(title: PWideString): TQtMenu;
function addSeparator: TQtAction;
function addSeparator: TQtMenu;
end;
{ TQtProgressBar }
@ -1039,7 +1046,7 @@ end;
procedure TQtWidget.SlotMouse(Event: QEventH); cdecl;
var
Msg: TLMMouse;
MousePos: TPoint;
MousePos: PQtPoint;
Mbutton: QTMouseButtons;
Modifiers: QtKeyboardModifiers;
begin
@ -1049,7 +1056,7 @@ begin
FillChar(Msg, SizeOf(Msg), #0);
QMouseEvent_pos(QMouseEventH(Event), @MousePos);
MousePos := QMouseEvent_pos(QMouseEventH(Event));
Msg.Keys := 0;
Modifiers := QInputEvent_modifiers(QInputEventH(Event));
@ -1057,8 +1064,8 @@ begin
if Modifiers and qtControlModifier<>0 then Msg.Keys := Msg.Keys or MK_CONTROL;
{ TODO: add support for ALT, META and NUMKEYPAD }
Msg.XPos := SmallInt(MousePos.X);
Msg.YPos := SmallInt(MousePos.Y);
Msg.XPos := SmallInt(MousePos^.X);
Msg.YPos := SmallInt(MousePos^.Y);
MButton := QmouseEvent_Button(QMouseEventH(Event));
@ -1130,16 +1137,16 @@ end;
procedure TQtWidget.SlotMouseMove(Event: QEventH); cdecl;
var
Msg: TLMMouseMove;
MousePos: TPoint;
MousePos: PQtPoint;
begin
FillChar(Msg, SizeOf(Msg), #0);
QMouseEvent_pos(QMouseEventH(Event), @MousePos);
MousePos := QMouseEvent_pos(QMouseEventH(Event));
//QCursor_pos(@MousePos);
Msg.XPos := SmallInt(MousePos.X);
Msg.YPos := SmallInt(MousePos.Y);
Msg.XPos := SmallInt(MousePos^.X);
Msg.YPos := SmallInt(MousePos^.Y);
Msg.Msg := LM_MOUSEMOVE;
@ -1159,16 +1166,16 @@ end;
procedure TQtWidget.SlotMouseWheel(Event: QEventH); cdecl;
var
Msg: TLMMouseEvent;
MousePos: TPoint;
MousePos: PQtPoint;
begin
FillChar(Msg, SizeOf(Msg), #0);
QWheelEvent_pos(QWheelEventH(Event), @MousePos);
MousePos := QWheelEvent_pos(QWheelEventH(Event));
Msg.Msg := LM_MOUSEWHEEL;
Msg.X := SmallInt(MousePos.X);
Msg.Y := SmallInt(MousePos.Y);
Msg.X := SmallInt(MousePos^.X);
Msg.Y := SmallInt(MousePos^.Y);
Msg.WheelDelta := QWheelEvent_delta(QWheelEventH(Event)) div 120;
@ -1994,7 +2001,7 @@ begin
w := QApplication_activeWindow;
if not Assigned(w) and not (Application.MainForm.Visible) then
if not Assigned(w) and not ((Application.MainForm <> nil) and (Application.MainForm.Visible)) then
begin
Result := QMainWindow_create(nil, QtWindow);
@ -2012,7 +2019,7 @@ begin
window will receive and handle them
------------------------------------------------------------------------------}
if Assigned(Application.MainForm.Menu) then
if Assigned(Application.MainForm) and Assigned(Application.MainForm.Menu) then
QMainWindow_setMenuBar(QMainWindowH(Result), QMenuBarH(MenuBar.Widget));
{$ifdef USE_QT_4_3}
@ -4076,14 +4083,14 @@ begin
inherited Destroy;
end;
procedure TQtMenu.PopUp(pos: PPoint; at: QActionH);
procedure TQtMenu.PopUp(pos: PQtPoint; at: QActionH);
begin
QMenu_Popup(QMenuH(Widget), pos, at);
end;
function TQtMenu.addAction(text: PWideString): TQtAction;
function TQtMenu.actionHandle: QActionH;
begin
Result := TQtAction.Create(QMenu_addAction(QMenuH(Widget), text));
Result := QMenu_menuAction(QMenuH(Widget));
end;
function TQtMenu.addMenu(title: PWideString): TQtMenu;
@ -4091,9 +4098,31 @@ begin
Result := TQtMenu.Create(QMenu_addMenu(QMenuH(Widget), title));
end;
function TQtMenu.addSeparator: TQtAction;
function TQtMenu.addSeparator: TQtMenu;
begin
Result := TQtAction.Create(QMenu_addSeparator(QMenuH(Widget)));
Result := TQtMenu.Create(QMenu_addMenu(QMenuH(Widget), nil));
Result.setSeparator(True);
end;
procedure TQtMenu.setChecked(p1: Boolean);
begin
if p1 then setCheckable(True)
else setCheckable(False);
QAction_setChecked(ActionHandle, p1);
end;
procedure TQtMenu.setCheckable(p1: Boolean);
begin
QAction_setCheckable(ActionHandle, p1);
end;
procedure TQtMenu.setHasSubmenu(AValue: Boolean);
begin
if AValue then
QAction_setMenu(ActionHandle, QMenuH(Widget))
else
QAction_setMenu(ActionHandle, nil);
end;
procedure TQtMenu.setIcon(AIcon: QIconH);
@ -4117,6 +4146,22 @@ begin
setIcon(FIcon);
end;
procedure TQtMenu.setSeparator(AValue: Boolean);
begin
QAction_setSeparator(ActionHandle, AValue);
end;
{------------------------------------------------------------------------------
Method: TQtMenu.SlotTriggered
Callback for menu item click
------------------------------------------------------------------------------}
procedure TQtMenu.SlotTriggered(checked: Boolean); cdecl;
begin
if Assigned(MenuItem) and Assigned(MenuItem.OnClick) then
MenuItem.OnClick(Self.MenuItem);
end;
{ TQtMenuBar }
constructor TQtMenuBar.Create(const AParent: QWidgetH);
@ -4129,19 +4174,15 @@ begin
inherited Destroy;
end;
function TQtMenuBar.addAction(text: PWideString): TQtAction;
begin
Result := TQtAction.Create(QMenuBar_addAction(QMenuBarH(Widget), text));
end;
function TQtMenuBar.addMenu(title: PWideString): TQtMenu;
begin
Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), title));
end;
function TQtMenuBar.addSeparator: TQtAction;
function TQtMenuBar.addSeparator: TQtMenu;
begin
Result := TQtAction.Create(QMenuBar_addSeparator(QMenuBarH(Widget)));
Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), nil));
Result.setSeparator(True);
end;
{ TQtProgressBar }

View File

@ -110,12 +110,10 @@ end;
------------------------------------------------------------------------------}
class function TQtWSMenuItem.CreateHandle(const AMenuItem: TMenuItem): HMENU;
var
Action: TQtAction;
ParentMenu, Menu: TQtMenu;
MenuBar: TQtMenuBar;
Text: WideString;
Method: TMethod;
ActionHandle: Boolean = False;
begin
{$ifdef VerboseQt}
WriteLn('trace:> [TQtWSMenuItem.CreateHandle] Caption: ', AMenuItem.Caption,
@ -154,35 +152,26 @@ begin
{ IsLine indicates that the menu item is a separator }
if AMenuItem.IsLine then
begin
ActionHandle := True;
Action := MenuBar.addSeparator;
Result := HMENU(Action);
end
{ Count indicates the number of subitems this item has }
else if AMenuItem.Count > 0 then
begin
Text := UTF8Decode(AMenuItem.Caption);
Menu := MenuBar.addSeparator;
Menu := MenuBar.addMenu(@Text);
if AMenuItem.HasIcon then
Menu.setImage(TQtImage(AMenuItem.Bitmap.Handle));
Menu.setHasSubmenu(False);
Result := HMENU(Menu);
end
else
begin
ActionHandle := True;
Text := UTF8Decode(AMenuItem.Caption);
Action := MenuBar.addAction(@Text);
Action.MenuItem := AMenuItem;
Menu := MenuBar.addMenu(@Text);
Result := HMENU(Action);
Menu.MenuItem := AMenuItem;
if AMenuItem.HasIcon then
Menu.setImage(TQtImage(AMenuItem.Bitmap.Handle));
Menu.setHasSubmenu(AMenuItem.Count > 0);
Result := HMENU(Menu);
end;
end
{------------------------------------------------------------------------------
@ -191,6 +180,8 @@ begin
else
begin
ParentMenu := TQtMenu(AMenuItem.Parent.Handle);
ParentMenu.setHasSubmenu(True);
{$ifdef VerboseQt}
Write(' Parent: ', dbghex(PtrInt(ParentMenu)),
@ -200,52 +191,41 @@ begin
{ IsLine indicates that the menu item is a separator }
if AMenuItem.IsLine then
begin
ActionHandle := True;
Action := ParentMenu.addSeparator;
Menu := ParentMenu.addSeparator;
Result := HMENU(Action);
Menu.setHasSubmenu(False);
Result := HMENU(Menu);
end
{ Count indicates the number of subitems this item has }
else if AMenuItem.Count > 0 then
else
begin
Text := UTF8Decode(AMenuItem.Caption);
Menu := ParentMenu.addMenu(@Text);
Menu.MenuItem := AMenuItem;
Menu.setEnabled(AMenuItem.Enabled);
Menu.setChecked(AMenuItem.Checked);
if AMenuItem.HasIcon then
Menu.setImage(TQtImage(AMenuItem.Bitmap.Handle));
Result := HMENU(Menu);
end
else
begin
ActionHandle := True;
Text := UTF8Decode(AMenuItem.Caption);
Action := ParentMenu.addAction(@Text);
Action.MenuItem := AMenuItem;
Action.setEnabled(AMenuItem.Enabled);
Action.setChecked(AMenuItem.Checked);
Menu.setHasSubmenu(AMenuItem.Count > 0);
if AMenuItem.HasIcon then
Action.setImage(TQtImage(AMenuItem.Bitmap.Handle));
Result := HMENU(Action);
Result := HMENU(Menu);
end;
end;
if ActionHandle then
if Menu <> nil then
begin
// Trigger event
QAction_triggered_Event(Method) := Action.SlotTriggered;
QAction_triggered_Event(Method) := Menu.SlotTriggered;
QAction_hook_hook_triggered(QAction_hook_create(Action.Handle), Method);
QAction_hook_hook_triggered(QAction_hook_create(Menu.ActionHandle), Method);
end;
{$ifdef VerboseQt}
@ -277,18 +257,10 @@ begin
if AMenuItem.HasParent then
begin
{ Here the menu item has a QMenuH handle
Obs: Commented because they cause access violations inside Qt
library on the Virtual Magnifying Glass }
if AMenuItem.Count > 0 then
begin
TQtMenu(AMenuItem.Handle).Free;
end
{ Here the menu item has a QActionH handle }
else
begin
TQtAction(AMenuItem.Handle).Free;
end;
library on the Virtual Magnifying Glass
}
TQtMenu(AMenuItem.Handle).Free;
end;
end;
@ -320,15 +292,7 @@ end;
class procedure TQtWSMenuItem.SetVisible(const AMenuItem: TMenuItem; const Visible: boolean);
begin
{ Here the menu item has a QMenuH handle }
if AMenuItem.Count > 0 then
begin
TQtMenu(AMenuItem.Handle).setVisible(Visible);
end
{ Here the menu item has a QActionH handle }
else
begin
TQtAction(AMenuItem.Handle).setVisible(Visible);
end;
TQtMenu(AMenuItem.Handle).setVisible(Visible);
end;
{------------------------------------------------------------------------------
@ -338,17 +302,7 @@ end;
------------------------------------------------------------------------------}
class function TQtWSMenuItem.SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean;
begin
{ Here the menu item has a QMenuH handle }
if AMenuItem.Count > 0 then
begin
end
{ Here the menu item has a QActionH handle }
else
begin
TQtAction(AMenuItem.Handle).setChecked(Checked);
end;
TQtMenu(AMenuItem.Handle).setChecked(Checked);
Result := True;
end;
@ -359,17 +313,7 @@ end;
------------------------------------------------------------------------------}
class function TQtWSMenuItem.SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean;
begin
{ Here the menu item has a QMenuH handle }
if AMenuItem.Count > 0 then
begin
TQtMenu(AMenuItem.Handle).setEnabled(Enabled);
end
{ Here the menu item has a QActionH handle }
else
begin
TQtAction(AMenuItem.Handle).setEnabled(Enabled);
end;
TQtMenu(AMenuItem.Handle).setEnabled(Enabled);
Result := True;
end;
@ -399,22 +343,10 @@ class procedure TQtWSMenuItem.UpdateMenuIcon(const AMenuItem: TMenuItem;
begin
if AMenuItem.HasParent then
begin
{ Here the menu item has a QMenuH handle}
if AMenuItem.Count > 0 then
begin
if HasIcon then
TQtMenu(AMenuItem.Handle).setImage(TQtImage(AIcon.Handle))
else
TQtMenu(AMenuItem.Handle).setImage(nil);
end
{ Here the menu item has a QActionH handle }
if HasIcon then
TQtMenu(AMenuItem.Handle).setImage(TQtImage(AIcon.Handle))
else
begin
if HasIcon then
TQtAction(AMenuItem.Handle).setImage(TQtImage(AIcon.Handle))
else
TQtAction(AMenuItem.Handle).setImage(nil);
end;
TQtMenu(AMenuItem.Handle).setImage(nil);
end;
end;
@ -470,7 +402,7 @@ end;
------------------------------------------------------------------------------}
class procedure TQtWSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X, Y: integer);
var
Point: TPoint;
Point: TQtPoint;
begin
{$ifdef VerboseQt}
WriteLn('[TQtWSPopupMenu.Popup] APopupMenu.Handle ' + dbghex(APopupMenu.Handle)