xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
trace_form_base.h
Go to the documentation of this file.
1 #pragma once
5 #include <chrono>
7 #include "form.h"
8 #include "text_box.h"
9 
11 namespace xtd {
13  namespace forms {
21  public:
23 
31  return xtd::forms::control::dock(dock);
32  }
33 
36  virtual const xtd::ustring& header_separator() const {return header_separator_;}
41  if (header_separator_ != header_separator_) {
42  header_separator_ = header_separator;
43  update_format();
44  }
45  return *this;
46  }
47 
48  const xtd::ustring& name() const override {return form::name();}
49 
52  virtual bool show_date() const {return show_date_;}
56  virtual trace_form_base& show_date(bool value) {
57  if (show_date_ != value) {
58  show_date_ = value;
59  update_format();
60  }
61  return *this;
62  }
63 
66  virtual bool show_time() const {return show_time_;}
70  virtual trace_form_base& show_time(bool value) {
71  if (show_time_ != value) {
72  show_time_ = value;
73  update_format();
74  }
75  return *this;
76  }
78 
79  protected:
81 
86  close_box(false);
87  name("9f5767d6-7a21-4ebe-adfe-2427b2024a55");
88  text_.name("d014d407-851c-49c1-a343-3380496a639a");
89 
93  this->text(text);
94 
96  text_.multiline(true);
97  text_.parent(*this);
98  text_.read_only(true);
99  text_.word_wrap(false);
100  update_format();
101  }
103 
105 
107  void on_back_color_changed(const xtd::event_args& e) override {
108  text_.back_color(back_color());
109  }
110 
111  void on_fore_color_changed(const xtd::event_args& e) override {
112  text_.fore_color(fore_color());
113  }
114 
117  virtual void write(const xtd::ustring& trace) {
118  if (need_header()) write_header();
119  text_.append_text(trace);
120  }
121 
124  virtual void write_line(const xtd::ustring& trace) {
125  write(trace);
127  need_header(true);
128  }
129 
132  virtual void write_header() {
133  auto now = std::chrono::system_clock::now();
134  text_.append_text(xtd::ustring::format(format_, now, (std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch())).count() % 1000000, header_separator_));
135  need_header_ = false;
136  }
137 
141  virtual bool need_header() const {return need_header_;}
146  virtual trace_form_base& need_header(bool value) {
147  if (need_header_ != value)
148  need_header_ = value;
149  return *this;
150  }
152 
153  private:
154  using form::name;
155 
156  void update_format() {
157  format_ = "";
158  if (show_date_ && show_time_) format_ = "{0:u}.{1:D6}{2}" + format_;
159  else if (show_date_) format_ = "{0:L}-{0:k}-{0:i}{2}" + format_;
160  else if (show_time_) format_ = "{0:t}.{1:D6}{2}" + format_;
161  }
162 
163  bool need_header_ = true;
164  bool show_date_ = true;
165  bool show_time_ = true;
166  xtd::ustring format_ = "{0}";
167  xtd::ustring header_separator_ = "|";
168  xtd::forms::text_box text_;
169  };
170  }
171 }
virtual void write(const xtd::ustring &trace)
Writes trace string to the multiline text.
Definition: trace_form_base.h:117
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:124
Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.
Definition: font.h:39
virtual const drawing::size & size() const
Gets the height and width of the control.
The control&#39;s right edge is docked to the right edge of its containing control.
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, relative to the parent control.
virtual const xtd::ustring & name() const
Gets the name of the control.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
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:85
Contains xtd::forms::text_box control.
virtual form_start_position start_position() const
Gets the starting position of the form at run time.
Definition: form.h:194
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents a base form for debug_form and trace_form forms. This class cannot be instantiated.
Definition: trace_form_base.h:20
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:134
All the control&#39;s edges are docked to the all edges of its containing control and sized appropriately...
virtual dock_style dock() const
Gets or sets which control borders are docked to its parent control and determines how a control is r...
const xtd::ustring & name() const override
Gets the name of the control.
Definition: trace_form_base.h:48
virtual trace_form_base & show_date(bool value)
Sets a value indicate if date is showing before trace text.
Definition: trace_form_base.h:56
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
virtual bool close_box() const
Gets a value indicating whether a close box is displayed in the caption bar of the form...
Definition: form.h:91
virtual bool show_time() const
Gets a value indicate if time is showing before trace text.
Definition: trace_form_base.h:66
void on_fore_color_changed(const xtd::event_args &e) override
Raises the control::fore_color_changed event.
Definition: trace_form_base.h:111
void on_back_color_changed(const xtd::event_args &e) override
Raises the control::back_color_changed event.
Definition: trace_form_base.h:107
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.
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:36
Contains xtd::drawing::font_family class.
virtual void write_header()
Writes header, if needed. Writes date and/or time and header_separator.
Definition: trace_form_base.h:132
Represents a window or dialog box that makes up an application&#39;s user interface.
Definition: form.h:40
virtual bool show_date() const
Gets a value indicate if date is showing before trace text.
Definition: trace_form_base.h:52
Contains xtd::forms::form container.
virtual drawing::color fore_color() const
Gets the foreground color of the control.
The position of the form is determined by the Location property.
virtual bool multiline() const
Gets a value indicating whether this is a multiline text box control.
Definition: text_box_base.h:75
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:40
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...
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:25
The control&#39;s bottom edge is docked to the bottom of its containing control.
static xtd::ustring new_line()
Gets the newline string defined for this environment.
virtual bool read_only() const
Gets a value indicating whether text in the text box is read-only.
Definition: text_box_base.h:92
intptr_t handle() const override
Gets the window handle that the control is bound to.
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
dock_style
Specifies the position and manner in which a control is docked.
Definition: dock_style.h:19
The control&#39;s left edge is docked to the left edge of its containing control.
virtual drawing::font font() const
Gets the font of the text displayed by the control.
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:700
virtual std::optional< control_ref > parent() const
Gets the parent container of the control.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The control&#39;s top edge is docked to the top of its containing control.
virtual trace_form_base & show_time(bool value)
Sets a value indicate if time is showing before trace text.
Definition: trace_form_base.h:70
virtual trace_form_base & need_header(bool value)
Sets a value indicate if header need written.
Definition: trace_form_base.h:146
virtual const xtd::ustring & text() const
Gets the text associated with this control.
static font_family generic_monospace()
Gets a generic monospace font_family.
Definition: font_family.h:71
virtual bool need_header() const
Gets a value indicate if header need written.
Definition: trace_form_base.h:141