xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
trace_form_base.h
Go to the documentation of this file.
1
4#pragma once
5#include <chrono>
7#include "form.h"
8#include "text_box.h"
9
11namespace xtd {
13 namespace forms {
21 public:
29 }
30
33 virtual const xtd::ustring& header_separator() const {return header_separator_;}
38 if (header_separator_ != header_separator_) {
39 header_separator_ = header_separator;
40 update_format();
41 }
42 return *this;
43 }
44
45 const xtd::ustring& name() const override {return form::name();}
46
49 virtual bool show_date() const {return show_date_;}
53 virtual trace_form_base& show_date(bool value) {
54 if (show_date_ != value) {
55 show_date_ = value;
56 update_format();
57 }
58 return *this;
59 }
60
63 virtual bool show_time() const {return show_time_;}
67 virtual trace_form_base& show_time(bool value) {
68 if (show_time_ != value) {
69 show_time_ = value;
70 update_format();
71 }
72 return *this;
73 }
74
75 protected:
79 name("9f5767d6-7a21-4ebe-adfe-2427b2024a55");
80 text_.name("d014d407-851c-49c1-a343-3380496a639a");
81
85 this->text(text);
86
88 text_.multiline(true);
89 text_.parent(*this);
90 text_.read_only(true);
91 text_.word_wrap(false);
92 update_format();
93 }
94
95 void on_back_color_changed(const xtd::event_args& e) override {
96 text_.back_color(back_color());
97 }
98
99 void on_fore_color_changed(const xtd::event_args& e) override {
100 text_.fore_color(fore_color());
101 }
102
104 e.cancel(true);
107 }
108
111 virtual void write(const xtd::ustring& trace) {
112 if (need_header()) write_header();
113 text_.append_text(trace);
114 }
115
118 virtual void write_line(const xtd::ustring& trace) {
119 write(trace);
121 need_header(true);
122 }
123
126 virtual void write_header() {
127 auto now = std::chrono::system_clock::now();
128 text_.append_text(xtd::ustring::format(format_, now, (std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch())).count() % 1000000, header_separator_));
129 need_header_ = false;
130 }
131
135 virtual bool need_header() const {return need_header_;}
140 virtual trace_form_base& need_header(bool value) {
141 if (need_header_ != value)
142 need_header_ = value;
143 return *this;
144 }
145
146 private:
147 using form::name;
148
149 void update_format() {
150 format_ = "";
151 if (show_date_ && show_time_) format_ = "{0:u}.{1:D6}{2}" + format_;
152 else if (show_date_) format_ = "{0:L}-{0:k}-{0:i}{2}" + format_;
153 else if (show_time_) format_ = "{0:t}.{1:D6}{2}" + format_;
154 }
155
156 bool need_header_ = true;
157 bool show_date_ = true;
158 bool show_time_ = true;
159 xtd::ustring format_ = "{0}";
160 xtd::ustring header_separator_ = "|";
162 };
163 }
164}
static font_family generic_monospace()
Gets a generic monospace font_family.
Definition font_family.h:64
Defines a particular format for text, including font face, size, and style attributes....
Definition font.h:39
static xtd::ustring new_line()
Gets the newline string defined for this environment.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.h:18
Defines the base class for controls, which are components with visual representation.
Definition control.h:67
virtual drawing::font font() const
Gets the font of the text displayed by the control.
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Definition control.h:650
virtual drawing::color fore_color() const
Gets the foreground color of the control.
virtual const xtd::ustring & name() const
Gets the name of the control.
Definition control.h:573
virtual std::optional< control_ref > parent() const
Gets the parent container of the control.
Definition control.h:596
virtual dock_style dock() const
Gets or sets which control borders are docked to its parent control and determines how a control is r...
Definition control.h:423
virtual drawing::color back_color() const
Gets the background color for the control.
virtual drawing::rectangle bounds() const
Gets the size and location of the control including its nonclient elements, in pixels,...
Definition control.h:301
Provides data for the form_closing event.
Definition form_closing_event_args.h:19
Represents a window or dialog box that makes up an application's user interface.
Definition form.h:40
virtual void on_form_closing(form_closing_event_args &e)
Raises the form::form_closing event.
Definition form.h:306
virtual form_window_state window_state() const
Gets a value that indicates whether form is minimized, maximized, or normal.
Definition form.h:227
virtual form_start_position start_position() const
Gets the starting position of the form at run time.
Definition form.h:187
static drawing::rectangle get_working_area(const control &control)
Retrieves the working area for the display that contains the largest region of the specified control....
virtual bool multiline() const
Gets a value indicating whether this is a multiline text box control.
Definition text_box_base.h:73
virtual bool word_wrap() const
Indicates whether a multiline text box control automatically wraps words to the beginning of the next...
Definition text_box_base.h:132
virtual bool read_only() const
Gets a value indicating whether text in the text box is read-only.
Definition text_box_base.h:90
Represents a standard Windows text box.
Definition text_box.h:22
void append_text(const xtd::ustring &value) override
Appends text to the current text of a text box.
Represents a base form for debug_form and trace_form forms. This class cannot be instantiated.
Definition trace_form_base.h:20
void on_fore_color_changed(const xtd::event_args &e) override
Raises the control::fore_color_changed event.
Definition trace_form_base.h:99
virtual bool show_date() const
Gets a value indicate if date is showing before trace text.
Definition trace_form_base.h:49
virtual trace_form_base & header_separator(const xtd::ustring &header_separator)
Sets the string used to separate date and/or time from trace text.
Definition trace_form_base.h:37
trace_form_base(const xtd::ustring &text)
Initializes a new instance of the trace_form_base class with specified caption text.
Definition trace_form_base.h:78
virtual trace_form_base & show_date(bool value)
Sets a value indicate if date is showing before trace text.
Definition trace_form_base.h:53
xtd::forms::control & dock(xtd::forms::dock_style dock) override
Sets or sets which control borders are docked to its parent control and determines how a control is r...
Definition trace_form_base.h:22
virtual const xtd::ustring & header_separator() const
Gets the string used to separate date and/or time from trace text.
Definition trace_form_base.h:33
virtual trace_form_base & need_header(bool value)
Sets a value indicate if header need written.
Definition trace_form_base.h:140
const xtd::ustring & name() const override
Gets the name of the control.
Definition trace_form_base.h:45
virtual void write_line(const xtd::ustring &trace)
Writes trace string to the multiline text followed by a line terminator.
Definition trace_form_base.h:118
virtual void write(const xtd::ustring &trace)
Writes trace string to the multiline text.
Definition trace_form_base.h:111
virtual bool show_time() const
Gets a value indicate if time is showing before trace text.
Definition trace_form_base.h:63
virtual trace_form_base & show_time(bool value)
Sets a value indicate if time is showing before trace text.
Definition trace_form_base.h:67
void on_back_color_changed(const xtd::event_args &e) override
Raises the control::back_color_changed event.
Definition trace_form_base.h:95
virtual bool need_header() const
Gets a value indicate if header need written.
Definition trace_form_base.h:135
void on_form_closing(form_closing_event_args &e) override
Raises the form::form_closing event.
Definition trace_form_base.h:103
virtual void write_header()
Writes header, if needed. Writes date and/or time and header_separator.
Definition trace_form_base.h:126
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:48
Contains xtd::drawing::font_family class.
Contains xtd::forms::form container.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:689
dock_style
Specifies the position and manner in which a control is docked.
Definition dock_style.h:19
@ e
The E key.
@ size
Specifies that both the width and height property values of the control are defined.
@ minimized
A minimized window.
@ bottom
The control's bottom edge is docked to the bottom of its containing control.
@ right
The control's right edge is docked to the right edge of its containing control.
@ left
The control's left edge is docked to the left edge of its containing control.
@ fill
All the control's edges are docked to the all edges of its containing control and sized appropriately...
@ top
The control's top edge is docked to the top of its containing control.
@ manual
The position of the form is determined by the Location property.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::forms::text_box control.