From ecccf982ed6b7b05f8c7c91097cf24e9160bdb3c Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 2 May 2010 11:26:52 +0000 Subject: [PATCH] qt: initial implementation for GetSysColorBrush + various cleanup and bug fixes git-svn-id: trunk@25131 - --- lcl/interfaces/qt/qtint.pp | 8 +++-- lcl/interfaces/qt/qtobject.inc | 27 ++++++++++++++-- lcl/interfaces/qt/qtobjects.pas | 29 +++++++----------- lcl/interfaces/qt/qtprivate.pp | 4 --- lcl/interfaces/qt/qtthemes.pas | 1 - lcl/interfaces/qt/qtwidgets.pas | 12 +------- lcl/interfaces/qt/qtwinapi.inc | 51 +++++++++++++++++++------------ lcl/interfaces/qt/qtwinapih.inc | 1 + lcl/interfaces/qt/qtwscomctrls.pp | 5 --- lcl/interfaces/qt/qtwsstdctrls.pp | 1 - 10 files changed, 75 insertions(+), 64 deletions(-) diff --git a/lcl/interfaces/qt/qtint.pp b/lcl/interfaces/qt/qtint.pp index 57adfcce17..a5f8262630 100644 --- a/lcl/interfaces/qt/qtint.pp +++ b/lcl/interfaces/qt/qtint.pp @@ -70,7 +70,8 @@ type FDragImageList: QWidgetH; FDragHotSpot: TPoint; FDragImageLock: Boolean; - FCachedColors: Array[0..MAX_SYS_COLORS + 1] of PLongWord; + FCachedColors: array[0..MAX_SYS_COLORS] of PLongWord; + FSysColorBrushes: array[0..MAX_SYS_COLORS] of HBrush; procedure ClearCachedColors; procedure SetOverrideCursor(const AValue: TObject); protected @@ -138,8 +139,9 @@ type function GetQtDefaultDC: HDC; virtual; procedure DeleteDefaultDC; virtual; procedure SetQtDefaultDC(Handle: HDC); virtual; - procedure InitStockItems; virtual; - procedure FreeStockItems; virtual; + procedure InitStockItems; + procedure FreeStockItems; + procedure FreeSysColorBrushes; property DragImageLock: Boolean read FDragImageLock write FDragImageLock; property OverrideCursor: TObject read FOverrideCursor write SetOverrideCursor; diff --git a/lcl/interfaces/qt/qtobject.inc b/lcl/interfaces/qt/qtobject.inc index d0197c2e54..61a0259d0e 100644 --- a/lcl/interfaces/qt/qtobject.inc +++ b/lcl/interfaces/qt/qtobject.inc @@ -53,6 +53,7 @@ begin DestroyGlobalCaret; Clipboard.Free; FreeStockItems; + FreeSysColorBrushes; QtDefaultPrinter.Free; QtWidgetSet := nil; @@ -564,7 +565,8 @@ function TQtWidgetSet.CreateDefaultFont: HFONT; var QtFont: TQtFont; begin - QtFont := TQtFont.Create(True, True); + QtFont := TQtFont.Create(True); + QtFont.FShared := True; QApplication_font(QtFont.Widget); Result := HFONT(QtFont); end; @@ -580,8 +582,10 @@ procedure TQtWidgetSet.FreeStockItems; procedure DeleteAndNilObject(var h: HGDIOBJ); begin + if h <> 0 then + TQtResource(h).FShared := False; DeleteObject(h); - h:=0; + h := 0; end; begin @@ -599,6 +603,25 @@ begin DeleteAndNilObject(FStockSystemFont); end; +procedure TQtWidgetSet.FreeSysColorBrushes; + + procedure DeleteAndNilObject(var h: HGDIOBJ); + begin + if h <> 0 then + begin + TQtResource(h).FShared := False; + DeleteObject(h); + h := 0; + end; + end; + +var + i: integer; +begin + for i := Low(FSysColorBrushes) to High(FSysColorBrushes) do + DeleteAndNilObject(FSysColorBrushes[i]); +end; + function TQtWidgetSet.GetQtDefaultDC: HDC; begin Result := FStockDefaultDC; diff --git a/lcl/interfaces/qt/qtobjects.pas b/lcl/interfaces/qt/qtobjects.pas index 5eb227d9b2..616d28afee 100644 --- a/lcl/interfaces/qt/qtobjects.pas +++ b/lcl/interfaces/qt/qtobjects.pas @@ -174,7 +174,7 @@ type Widget: QFontH; Angle: Integer; public - constructor Create(CreateHandle: Boolean; Const AShared: Boolean = False); virtual; + constructor Create(CreateHandle: Boolean); virtual; destructor Destroy; override; public function getPointSize: Integer; @@ -231,7 +231,7 @@ type private public Widget: QBrushH; - constructor Create(CreateHandle: Boolean; const AShared: Boolean = False); virtual; + constructor Create(CreateHandle: Boolean); virtual; destructor Destroy; override; function getColor: PQColor; procedure setColor(AColor: PQColor); @@ -247,7 +247,7 @@ type FIsExtPen: Boolean; public Widget: QPenH; - constructor Create(CreateHandle: Boolean; const AShared: Boolean = False); virtual; + constructor Create(CreateHandle: Boolean); virtual; destructor Destroy; override; public function getCapStyle: QtPenCapStyle; @@ -1206,7 +1206,7 @@ end; Params: None Returns: Nothing ------------------------------------------------------------------------------} -constructor TQtFont.Create(CreateHandle: Boolean; Const AShared: Boolean = False); +constructor TQtFont.Create(CreateHandle: Boolean); begin {$ifdef VerboseQt} WriteLn('TQtFont.Create CreateHandle: ', dbgs(CreateHandle)); @@ -1215,7 +1215,7 @@ begin if CreateHandle then Widget := QFont_create; - FShared := AShared; + FShared := False; FMetrics := nil; end; @@ -1459,7 +1459,7 @@ end; Params: None Returns: Nothing ------------------------------------------------------------------------------} -constructor TQtBrush.Create(CreateHandle: Boolean; Const AShared: Boolean = False); +constructor TQtBrush.Create(CreateHandle: Boolean); begin // Creates the widget {$ifdef VerboseQt} @@ -1469,7 +1469,7 @@ begin if CreateHandle then Widget := QBrush_create; - FShared := AShared; + FShared := False; FSelected := False; end; @@ -1537,7 +1537,7 @@ end; Params: None Returns: Nothing ------------------------------------------------------------------------------} -constructor TQtPen.Create(CreateHandle: Boolean; const AShared: Boolean = False); +constructor TQtPen.Create(CreateHandle: Boolean); begin {$ifdef VerboseQt} WriteLn('TQtPen.Create CreateHandle: ', dbgs(CreateHandle)); @@ -1545,7 +1545,7 @@ begin if CreateHandle then Widget := QPen_create; - FShared := AShared; + FShared := False; FIsExtPen := False; end; @@ -1780,8 +1780,6 @@ begin end; function TQtRegion.GetRegionType: integer; -var - R: TRect; begin try if not IsPolyRegion and QRegion_isEmpty(Widget) then @@ -2795,8 +2793,6 @@ end; Returns: Region type ------------------------------------------------------------------------------} function TQtDeviceContext.getRegionType(ARegion: QRegionH): integer; -var - R: TRect; begin try if QRegion_isEmpty(ARegion) then @@ -2883,14 +2879,13 @@ var APixmap, ATemp: QPixmapH; AMask: QBitmapH; ScaledImage: QImageH; - TmpRegion: QRegionH; NewRect: TRect; function NeedScaling: boolean; var R: TRect; - TgtW, TgtH, SrcW, - SrcH, ClpW, ClpH: integer; + TgtW, TgtH, + ClpW, ClpH: integer; begin if not getClipping or EqualRect(LocalRect, sourceRect^) then @@ -2900,8 +2895,6 @@ var TgtW := LocalRect.Right - LocalRect.Left; TgtH := LocalRect.Right - LocalRect.Left; - SrcW := sourceRect^.Right - sourceRect^.Left; - SrcH := sourceRect^.Bottom - sourceRect^.Top; ClpW := R.Right - R.Left; ClpH := R.Bottom - R.Top; diff --git a/lcl/interfaces/qt/qtprivate.pp b/lcl/interfaces/qt/qtprivate.pp index c95e773ba5..7217bc3100 100644 --- a/lcl/interfaces/qt/qtprivate.pp +++ b/lcl/interfaces/qt/qtprivate.pp @@ -349,8 +349,6 @@ end; Deletes line at Index. ------------------------------------------------------------------------------} procedure TQtMemoStrings.Delete(Index: integer); -var - W: WideString; begin if FTextChanged then InternalUpdate; if (Index >= 0) and (Index < FStringList.Count) then @@ -455,7 +453,6 @@ end; procedure TQtComboStrings.Clear; var - I: Integer; C: Integer; begin C := Count; @@ -551,7 +548,6 @@ end; procedure TQtListStrings.Clear; var - I: Integer; C: Integer; begin C := Count; diff --git a/lcl/interfaces/qt/qtthemes.pas b/lcl/interfaces/qt/qtthemes.pas index b1c2ae87ce..a6954afc3d 100644 --- a/lcl/interfaces/qt/qtthemes.pas +++ b/lcl/interfaces/qt/qtthemes.pas @@ -336,7 +336,6 @@ procedure TQtThemeServices.DrawText(ACanvas: TPersistent; Flags2: Cardinal); var Palette: QPaletteH; - Brush: QBrushH; Context: TQtDeviceContext; Widget: QWidgetH; W: WideString; diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index 61bf387644..7b5315529d 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -2979,7 +2979,6 @@ end; procedure TQtWidget.SlotContextMenu(Sender: QObjectH; Event: QEventH); cdecl; var Msg: TLMContextMenu; - Modifiers: QtKeyboardModifiers; MousePos: TQtPoint; QtEdit: IQtEdit; AResult: LResult; @@ -3021,7 +3020,6 @@ begin FillChar(Msg, SizeOf(Msg), #0); MousePos := QContextMenuEvent_pos(QContextMenuEventH(Event))^; OffsetMousePos(@MousePos); - Modifiers := QInputEvent_modifiers(QInputEventH(Event)); Msg.Msg := LM_CONTEXTMENU; Msg.hWnd := HWND(Self); @@ -4508,7 +4506,7 @@ begin pmAuto: // active form is parent if Screen.ActiveForm <> nil then - NewParent := TQtWidget(Screen.ActiveForm).Widget; + NewParent := TQtWidget(Screen.ActiveForm.Handle).Widget; pmExplicit: // parent is FPopupParent if FPopupParent <> nil then @@ -4913,7 +4911,6 @@ end; function TQtRadioButton.CreateWidget(const AParams: TCreateParams): QWidgetH; var Parent: QWidgetH; - W: WideString; begin // Creates the widget {$ifdef VerboseQt} @@ -6045,7 +6042,6 @@ end; procedure TQtTextEdit.insertLine(const AIndex: integer; AText: WideString); var QtCursor: QTextCursorH; - b: Boolean; WrapMode: QTextEditLineWrapMode; begin WrapMode := QTextEdit_lineWrapMode(QTextEditH(Widget)); @@ -7132,8 +7128,6 @@ end; function TQtComboBox.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; var - ev: QEventH; - str: WideString; R, R1: TRect; ButtonRect: TRect; P: TQtPoint; @@ -9725,10 +9719,6 @@ begin end; function TQtMenu.actionHandle: QActionH; -var - i: Integer; - Arr: TQActions; - GotItem: boolean = False; begin if FActionHandle = nil then begin diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index eed94eb607..34c0619be7 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -821,27 +821,16 @@ begin Result := False; if GDIObject = 0 then - begin - Result := true; - - {$ifdef VerboseQtWinAPI} - WriteLn('Trace:< [WinAPI DeleteObject]'); - {$endif} - - Exit; - end; + Exit(True); if not IsValidGDIObject(GDIObject) then - begin - {$ifdef VerboseQtWinAPI} - WriteLn('Trace:< [WinAPI DeleteObject] Invalid GDI Object'); - {$endif} - Exit; - end; aObject := TObject(GDIObject); + if (aObject is TQtResource) and TQtResource(aObject).FShared then + Exit(True); + {------------------------------------------------------------------------------ Font ------------------------------------------------------------------------------} @@ -2883,7 +2872,8 @@ begin {$ifdef VerboseQtWinAPI} WriteLn('Trace:Unknown lcl system color: [TQtWidgetSet.GetSysColor]'); {$endif} - exit; + Result := 0; + Exit; end; if FCachedColors[nIndex] = nil then @@ -2906,8 +2896,8 @@ begin COLOR_BTNHIGHLIGHT : Result:=GetColor(QPaletteActive, QPaletteLight); COLOR_3DDKSHADOW : Result:=GetColor(QPaletteActive, QPaletteShadow); COLOR_3DLIGHT : Result:=GetColor(QPaletteActive, QPaletteMidlight); - COLOR_INFOTEXT : Result:=GetColor(QPaletteInActive, QPaletteToolTipText); - COLOR_INFOBK : Result:=GetColor(QPaletteInActive, QPaletteToolTipBase); + COLOR_INFOTEXT : Result:=GetColor(QPaletteInActive, QPaletteToolTipText); + COLOR_INFOBK : Result:=GetColor(QPaletteInActive, QPaletteToolTipBase); COLOR_HOTLIGHT : Result:=GetColor(QPaletteActive, QPaletteLight); // qt does not provide any methods to retrieve titlebar colors @@ -2936,10 +2926,33 @@ begin end; FCachedColors[nIndex] := getMem(SizeOf(LongWord)); FCachedColors[nIndex]^ := Result; - end else + end + else Result := FCachedColors[nIndex]^; end; +function TQtWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush; +var + LogBrush: TLogBrush; +begin + if (nIndex < 0) or (nIndex > MAX_SYS_COLORS) then + begin + Result := 0; + Exit; + end; + + if FSysColorBrushes[nIndex] = 0 then + begin + // todo: implement properly with brushes + LogBrush.lbColor := GetSysColor(nIndex); + LogBrush.lbStyle := 0; + LogBrush.lbHatch := 0; + FSysColorBrushes[nIndex] := CreateBrushIndirect(LogBrush); + TQtResource(FSysColorBrushes[nIndex]).FShared := True; + end; + Result := FSysColorBrushes[nIndex]; +end; + {------------------------------------------------------------------------------ Function: GetSystemMetrics Params: diff --git a/lcl/interfaces/qt/qtwinapih.inc b/lcl/interfaces/qt/qtwinapih.inc index 457f64e0a6..eeee95e8eb 100644 --- a/lcl/interfaces/qt/qtwinapih.inc +++ b/lcl/interfaces/qt/qtwinapih.inc @@ -121,6 +121,7 @@ function GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean; override; function GetScrollInfo(Handle: HWND; BarFlag: Integer; Var ScrollInfo: TScrollInfo): Boolean; override; function GetStockObject(Value: Integer): THandle; override; function GetSysColor(nIndex: Integer): DWORD; override; +function GetSysColorBrush(nIndex: Integer): HBrush; override; function GetSystemMetrics(nIndex: Integer): Integer; override; function GetTextColor(DC: HDC) : TColorRef; Override; function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override; diff --git a/lcl/interfaces/qt/qtwscomctrls.pp b/lcl/interfaces/qt/qtwscomctrls.pp index eebc8f89f4..963c51fbf2 100644 --- a/lcl/interfaces/qt/qtwscomctrls.pp +++ b/lcl/interfaces/qt/qtwscomctrls.pp @@ -1045,7 +1045,6 @@ class function TQtWSCustomListView.ItemGetPosition(const ALV: TCustomListView; const AIndex: Integer): TPoint; var QtListWidget: TQtListWidget; - LWI: QListWidgetItemH; QtTreeWidget: TQtTreeWidget; TWI: QTreeWidgetItemH; R: TRect; @@ -1252,7 +1251,6 @@ class procedure TQtWSCustomListView.ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem); var QtListWidget: TQtListWidget; - LWI: QListWidgetItemH; QtTreeWidget: TQtTreeWidget; TWI: QTreeWidgetItemH; Str: WideString; @@ -1316,7 +1314,6 @@ class procedure TQtWSCustomListView.ItemSetText(const ALV: TCustomListView; const AText: String); var QtListWidget: TQtListWidget; - LWI: QListWidgetItemH; QtTreeWidget: TQtTreeWidget; TWI: QTreeWidgetItemH; Str: WideString; @@ -1716,9 +1713,7 @@ const ); var SavedCheckable: Boolean; - i: Integer; QtItemView: TQtAbstractItemView; - Parent: QWidgetH; begin if not WSCheckHandleAllocated(ALV, 'SetProperty') then Exit; diff --git a/lcl/interfaces/qt/qtwsstdctrls.pp b/lcl/interfaces/qt/qtwsstdctrls.pp index 2528ec7164..04bc4cb60d 100644 --- a/lcl/interfaces/qt/qtwsstdctrls.pp +++ b/lcl/interfaces/qt/qtwsstdctrls.pp @@ -415,7 +415,6 @@ end; class function TQtWSCustomListBox.GetSelCount(const ACustomListBox: TCustomListBox): integer; var QtListWidget: TQtListWidget; - SelectedItems: TPtrIntArray; begin QtListWidget := TQtListWidget(ACustomListBox.Handle); Result := QtListWidget.getSelCount;