Autor Beitrag
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 14.08.05 13:23 
Das Problem ist zwar etwas kurios, aber ich setzes mal rein, da ich mir keinen reim drauf machen kann, woran es liegt, bzw. was in meiner Komponente noch fehlt:

Ich habe einen Objekt-Inspektor programmieren wollen (vom Layout her) und dafür eine neue Komponente von TScrollingWinControl abgeleitet. Soweit, sogut: Funzt auch noch. Auch das Positionieren der Subcontrols (Eingabefelder, Comboboxes, ...) geht tadellos. Diese werden auch Gezeichnet (in der Source-Version, siehe unten).

Wenn ich nun für die Komponente eine Zeichenfläche (realisiert über TControlCanvas) erzeuge UND die WM_Pain-Nachricht überschreibe, treten kuriose Fehler auf:
- Sub-Komponenten werden nur Teilweise oder auch gar nicht gezeichnet
- Komponenten anderer Formulare werden manchmal nicht gezeichnet
- Aktualisierungen des Zeichnens werden erst nach mehreren Fokus-Wechseln gezeichnet
- Die Zeichenfläche wird ständig neu gezeichnet

Problem: Ich seh nicht, wo in meiner Paint-Routine ein weiteres Paint aufgerufen wird, da innerhalb des Paint-Befehls
- keinerlei Realigns oder Resizes von Komponenten stattfinden
- Nur GDI-Befehle bzw. Kapselungen dieser ausgeführt werden.

Aber nun zum Source:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
Unit OVCLPropertyEdit;
// *****************************************************************************
// Omorphia Library V0.0 - Planning State
// VCL Submodule
//
// This unit contains the Omorphia Property Editor used in the Omorphia SDK.
//
// *****************************************************************************
// To Do:
//
// *****************************************************************************
// News:
//
// *****************************************************************************
// Bugs:
//  TODO -oBenBE -cBug, VCL, Property Edit : Heavy Problems with control painting\update
//
// *****************************************************************************
// Info:
//  BenBE: ATM there's only the functionality for aligning and adjusting control 
//  sizes as reqiured for the control layout. Painting the control doesn't work
//  because of recursion (???) problem when overriding the WM_PAINT message.
//
// *****************************************************************************

// Include the Compiler Version and Options Settings
{$I 'Omorphia.config.inc'}

Interface

Uses
    Windows,
    Messages,
    SysUtils,
    Classes,
    Controls,
    Graphics,
    ExtCtrls,
    StdCtrls,
    ComCtrls,
    Forms,
    OVCLForm;

Type
    TOVCLPropertyEdit = Class(TScrollingWinControl)
    Private
        FOnBeforePaint: TOVCLBeforePaint;
        FOnAfterPaint: TOVCLAfterPaint;

        FCellWidth: Integer;
        FCellHeight: Integer;
        FGridColor: TColor;

        FCanvas: TControlCanvas;

        Procedure DoBeforePaint;
        Procedure DoAfterPaint;
        Procedure SetCellWidth(AValue: Integer);
        Procedure SetCellHeight(AValue: Integer);
        Procedure SetGridColor(AValue: TColor);

        Function myCellWidth: Integer;
        Function ClientX: Integer;
        Function ClientY: Integer;
    Protected
    procedure AlignControls(AControl: TControl; var ARect: TRect); override;
        Procedure Paint; virtual;
        Procedure InsertControl(AControl: TControl);reintroduce; virtual;
        Procedure RemoveControl(AControl: TControl);reintroduce; virtual;
        procedure Realign; reintroduce; virtual; 
    Public
        Constructor Create(AOwner: TComponent); Override;
        Destructor Destroy; Override;

        Procedure DrawCLS(AColor: TColor);
        Procedure DrawLine(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor: TColor);
        Procedure DrawBox(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor0, AColor1, AColor2, AColor3: TColor); Overload;
        Procedure DrawBox(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor: TColor); Overload;
        Procedure DrawText(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor: TColor; AText: String; ASize: Integer);

        Procedure Add(AName: String; AObject: TWinControl);
        Procedure Del(AObject: TWinControl);
    Published
    property Align;
    property Anchors;
    property AutoScroll;
    property AutoSize;
    property BevelEdges;
    property BevelInner;
    property BevelOuter;
    property BevelKind;
    property BevelWidth;
    property BiDiMode;
    property Constraints;
    property DockSite;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Color nodefault;
    property Ctl3D;
    property Font;
    property ParentBiDiMode;
    property ParentBackground default False;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnCanResize;
    property OnClick;
    property OnConstrainedResize;
    property OnContextPopup;
    property OnDblClick;
    property OnDockDrop;
    property OnDockOver;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnGetSiteInfo;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnMouseWheel;
    property OnMouseWheelDown;
    property OnMouseWheelUp;
    property OnResize;
    property OnStartDock;
    property OnStartDrag;
    property OnUnDock;

        Property CellWidth: Integer Read FCellWidth Write SetCellWidth;
        Property CellHeight: Integer Read FCellHeight Write SetCellHeight;
        Property GridColor: TColor Read FGridColor Write SetGridColor;

        Property OnBeforePaint: TOVCLBeforePaint Read FOnBeforePaint Write FOnBeforePaint;
        Property OnAfterPaint: TOVCLAfterPaint Read FOnAfterPaint Write FOnAfterPaint;
    End;

Implementation

Uses
    Types,
    ODbgInterface,
    OIncProcs;

Constructor TOVCLPropertyEdit.Create(AOwner: TComponent);
Begin
    Inherited;

    // Neo: init inherited propertys
    BevelInner := bvNone;
    BevelOuter := bvLowered;
    // Neo: item

    // Neo:
    CellHeight := 16;
    CellWidth := -1;
    GridColor := clGray;

    ParentBackground := False;

    FCanvas := TControlCanvas.Create;
    FCanvas.Control := Self;

    Color := clBtnFace;
End;

Destructor TOVCLPropertyEdit.Destroy;
Begin
    FreeAndNilSecure(FCanvas);

    Inherited;
End;

Procedure TOVCLPropertyEdit.InsertControl(AControl: TControl);
Begin
    // ToDo -oNeo -cVCL, Property Editor : Fix the Designtime Update
    Inherited;
    Realign;
End;

Function TOVCLPropertyEdit.ClientX: Integer;
Begin
    If Ctl3D Then
        Result := BevelWidth * 2
    Else
        Result := 1;
End;

Function TOVCLPropertyEdit.ClientY: Integer;
Begin
    If Ctl3D Then
        Result := BevelWidth * 2
    Else
        Result := 1;
End;

Procedure TOVCLPropertyEdit.DrawCLS(AColor: TColor);
Begin
    FCanvas.Pen.Color := AColor;
    FCanvas.FillRect(FCanvas.ClipRect);
End;

Procedure TOVCLPropertyEdit.DrawLine(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor: TColor);
Begin
    FCanvas.Pen.Color := AColor;
    FCanvas.MoveTo(AX, AY);
    FCanvas.LineTo(ASizeX, ASizeY);
End;

Procedure TOVCLPropertyEdit.DrawBox(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor0, AColor1, AColor2, AColor3: TColor);
Begin
    FCanvas.Pen.Color := AColor0;
    FCanvas.MoveTo(AX, AY);
    FCanvas.LineTo(AX + ASizeX - 1, AY);
    FCanvas.Pen.Color := AColor1;
    FCanvas.LineTo(AX + ASizeX - 1, AY + ASizeY - 1);
    FCanvas.Pen.Color := AColor2;
    FCanvas.LineTo(AX, AY + ASizeY - 1);
    FCanvas.Pen.Color := AColor3;
    FCanvas.LineTo(AX, AY);
End;

Procedure TOVCLPropertyEdit.DrawBox(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor: TColor);
Begin
    DrawBox(AX, AY, ASizeX, ASizeY, AColor, AColor, AColor, AColor);
End;

Procedure TOVCLPropertyEdit.DrawText(AX, AY: Integer; ASizeX, ASizeY: Integer; AColor: TColor; AText: String; ASize: Integer);
Begin
    //DONE -oBenBE@Neo -cVCL, Property Editor : DrawText über TCanvas.TextRect realisieren
    FCanvas.Font.Size := ASize;
    FCanvas.Font.Color := AColor;

    If FCanvas.TextHeight(AText) > ASizeY Then
        OmorphiaDebugStr(vl_Hint, 'TOVCLPropertyEditor.DrawText', 'Outputting the text using the given font settings leads to a truncated text output.');

    FCanvas.TextRect(Rect(AX, AY, AX+ASizeX-1, AY+ASizeY-1), AX, AY, AText);
End;

Function TOVCLPropertyEdit.myCellWidth: Integer;
Begin
    If (FCellWidth <= 0) Or (FCellWidth >= ClientWidth) Then
        Result := ClientWidth Div 2
    Else
        Result := FCellWidth;
End;

Procedure TOVCLPropertyEdit.Paint;
Var
    Lauf: Integer;
    X, Y: Integer;
    Xs, Ys: Integer;
Begin
    DoBeforePaint;

    DrawCLS(Color);

    For Lauf := 0 To ControlCount - 1 Do
    Begin
        X := ClientX;
        Y := ClientY + Lauf * FCellHeight - VertScrollBar.Position;

        Xs := myCellWidth;
        Ys := FCellHeight;
        
        DrawBox(X, Y, Xs, Ys, FGridColor);
        DrawText(X + 1, Y, Xs - 1, Ys, clBlack, Controls[Lauf].Name, FCellHeight - 5);

        X := X + Xs;
        Xs := ClientWidth - X;

        DrawBox(X, Y, Xs, Ys, FGridColor);
    End;

    DoAfterPaint;
End;

Procedure TOVCLPropertyEdit.Add(AName: String; AObject: TWinControl);
Begin
    If Not Assigned(AObject) Then
        OmorphiaErrorStr(vl_Error, 'TOVCLPropertyEdit.Add', 'No default control supplied.');

    AObject.Parent := Self;
    AObject.Name := AName;
    Realign;
End;

Procedure TOVCLPropertyEdit.Del(AObject: TWinControl);
Begin
    FreeAndNilSecure(AObject);
    Realign;
End;

Procedure TOVCLPropertyEdit.SetCellWidth(AValue: Integer);
Begin
    FCellWidth := AValue;
    Repaint;
End;

Procedure TOVCLPropertyEdit.SetCellHeight(AValue: Integer);
Begin
    FCellHeight := AValue;
    Repaint;
End;

Procedure TOVCLPropertyEdit.SetGridColor(AValue: TColor);
Begin
    FGridColor := AValue;
    Repaint;
End;

Procedure TOVCLPropertyEdit.DoBeforePaint;
Begin
    If Assigned(FOnBeforePaint) Then
        FOnBeforePaint(Self, FCanvas);
End;

Procedure TOVCLPropertyEdit.DoAfterPaint;
Begin
    If Assigned(FOnAfterPaint) Then
        FOnAfterPaint(Self, FCanvas);
End;

procedure TOVCLPropertyEdit.Realign;
var
    Lauf: Integer;
    X, Y, Xs, Ys: Integer;
begin
  inherited;
  
    For Lauf := 0 To ControlCount - 1 Do
    Begin
        X := ClientX + myCellWidth;
        Y := ClientY + Lauf * FCellHeight;

        Xs := ClientWidth - X;
        Ys := FCellHeight;
        
        Controls[Lauf].SetBounds(X, Y, Xs, Ys);
    End;

    Repaint;
end;

procedure TOVCLPropertyEdit.RemoveControl(AControl: TControl);
begin
    // ToDo -oNeo -cVCL, Property Editor : Fix the Designtime Update
    inherited;
    Realign;
end;

procedure TOVCLPropertyEdit.AlignControls(AControl: TControl;
  var ARect: TRect);
begin
    ARect.Left := myCellWidth;
    ARect.Right := ClientWidth - 1;
    ARect.Bottom := ARect.Top + FCellHeight - 1;
  inherited;
end;

End.


Die Probleme treten dann auf, wenn ich folgende Routine implementiere:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TOVCLPropertyEdit.WMPaint(var Message: TWMPaint); {message WM_PAINT;}
begin
    Paint;    
    Message.Result := 0; //Eigentlich egal, bei NZ tritt der gleiche Fehler auf
end;


Ähnliche Effekte lassen sich auch mit WM_EraseBkgnd erzeugen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 14.08.05 22:58 
Du hast BeginPaint und EndPaint vergessen. Ohne EndPaint schickt dir Windows immer wieder WM_PAINT Nachrichten.
BenBE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 15.08.05 12:47 
Thx, hab auch noch eine weitere Möglichkeit gefunden, die das Problem löst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TOVCLPropertyEdit.WMPaint(var Message: TWMPaint);
begin
    Paint;
    inherited;
end;


Einfach aber wirkungsvoll.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.