Hi,
Attached is a patch to enable color support in the Messages Window.
It now makes it much easier to find your $Hint and $Note messages in a
lengthy compile.
Still outstanding is the option to enable users to custom select the
colors used. At the moment it is hard-coded to Green and Blue.
Regards,
- Graeme -
Index: msgview.pp
===================================================================
--- msgview.pp (revision 8356)
+++ msgview.pp (working copy)
@@ -94,6 +94,8 @@
procedure MessageViewClicked(Sender: TObject);
procedure MessagesViewKeyDown(Sender: TObject; var Key: word;
Shift: TShiftState);
+ procedure MessageViewDrawItem(Control: TWinControl; Index: Integer;
+ ARect: TRect; State: TOwnerDrawState);
procedure SaveAllToFileMenuItemClick(Sender: TObject);
private
FItems: TList; // list of TMessageLine
@@ -159,6 +161,10 @@
implementation
+uses
+ Graphics, // used for TColor
+ LCLType; // used for TOwnerDrawState
+
const
SeparatorLine = '---------------------------------------------';
@@ -191,6 +197,8 @@
FLastSelectedIndex := -1;
Caption := lisMenuViewMessages;
+ MessageView.Style := lbOwnerDrawFixed;
+ MessageView.OnDrawItem := @MessageViewDrawItem;
// assign the root TMenuItem to the registered menu root.
// This will automatically create all registered items
@@ -480,6 +488,51 @@
ExecuteIDEShortCut(Self, Key, Shift);
end;
+//------------------------------------------------------------------------------
+procedure TMessagesView.MessageViewDrawItem(Control: TWinControl;
+ Index: Integer; ARect: TRect; State: TOwnerDrawState);
+var
+ TheText: string;
+ lb: TListBox;
+ IsHint: boolean;
+ IsNote: boolean;
+ IsFocused: boolean;
+ cl: TColor;
+const
+ cHint = 'Hint: User defined:';
+ cNote = 'Note: User defined:';
+ clMsgHint = clBlue;
+ clMsgNote = clGreen;
+ cLeftSpacer = 3;
+begin
+ lb := Control as TListBox;
+ lb.Canvas.FillRect(ARect);
+ TheText := lb.Items[Index];
+
+ IsNote := StrPos(PChar(TheText), cNote) <> nil;
+ IsHint := StrPos(PChar(TheText), cHint) <> nil;
+ IsFocused := (odFocused in State) or (odSelected in State);
+
+ { Only use custom colors if not focused, otherwise it is difficult to read }
+ if IsNote and (not IsFocused) then
+ begin
+ cl := lb.Canvas.Font.Color; // save original color
+ lb.Canvas.Font.Color := clMsgNote;
+ lb.Canvas.TextOut(ARect.Left + cLeftSpacer, ARect.Top, TheText);
+ lb.Canvas.Font.Color := cl; // restore original color
+ end
+ else if IsHint and (not IsFocused) then
+ begin
+ cl := lb.Canvas.Font.Color; // save original color
+ lb.Canvas.Font.Color := clMsgHint;
+ lb.Canvas.TextOut(ARect.Left + cLeftSpacer, ARect.Top, TheText);
+ lb.Canvas.Font.Color := cl; // restore original color
+ end
+ else
+ lb.Canvas.TextOut(ARect.Left + cLeftSpacer, ARect.Top, TheText);
+end;
+
+//------------------------------------------------------------------------------
procedure TMessagesView.SaveAllToFileMenuItemClick(Sender: TObject);
var
SaveDialog: TSaveDialog;