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.
splitter.h
Go to the documentation of this file.
1 #pragma once
5 #include "control.h"
6 #include "splitter_style.h"
8 
10 namespace xtd {
12  namespace forms {
22  class forms_export_ splitter : public xtd::forms::control {
23  public:
25 
29  size(default_size());
31  }
33 
35 
38 
39  drawing::size default_size() const override {return {3, 3};}
40 
51  virtual control& dock(dock_style dock) override {
52  if (control::dock() != dock_style::left && control::dock() == dock_style::right && control::dock() == dock_style::top && control::dock() == dock_style::bottom) throw argument_exception("splitter control must be docked left, right, top, or bottom."_t, current_stack_frame_);
53  control::dock(dock);
54  cursor(default_cursor());
55  if (default_width_ && (dock == dock_style::left || dock == dock_style::right)) width(3);
56  if (default_width_ && (dock == dock_style::top || dock == dock_style::bottom)) height(3);
57  return *this;
58  }
59 
62  virtual int min_size() const {return min_size_;}
66  virtual splitter& min_size(int min_size) {
67  if (min_size_ != min_size) {
68  min_size_ = min_size;
69  }
70  return *this;
71  }
72 
75  virtual xtd::forms::splitter_style splitter_style() const {return splitter_style_;}
80  if (splitter_style_ != splitter_style) {
81  splitter_style_ = splitter_style;
82  }
83  return *this;
84  }
86 
87  protected:
89 
91  void on_mouse_down(const mouse_event_args& e) override {
94  if (parent().has_value()) {
95  for(size_t index = 0; index < parent().value().get().controls().size(); index++) {
96  if (parent().value().get().controls()[index].get() == *this) {
97  if (index > 0) previous_control_cursor_ = (previous_control_ = &parent().value().get().controls()[index - 1].get())->cursor();
98  if (index < parent().value().get().controls().size() -1) next_control_cursor_ = (next_control_ = &parent().value().get().controls()[index + 1].get())->cursor();
99  break;
100  }
101  }
102  }
103  if (previous_control_) previous_control_->cursor(default_cursor());
104  if (next_control_) next_control_->cursor(default_cursor());
105  }
106 
107  void on_mouse_move(const mouse_event_args& e) override {
109  if (previous_control_) previous_control_->cursor(default_cursor());
110  if (next_control_) next_control_->cursor(default_cursor());
111  if (mouse_down_location != -1 && next_control_) {
112  if (splitter_style_ == splitter_style::draw_line) {
113 
114  } else {
115  int delta_size = control::dock() == dock_style::left || control::dock() == dock_style::right ? (next_control_->width() + cursor::position().x()) : (next_control_->height() + cursor::position().y());
116  int new_size = delta_size - mouse_down_location;
117  if (new_size < min_size_) new_size = min_size_;
118  //if (previous_control_.size() < min_size_extra_) new_size = min_size_;
119  if (control::dock() == dock_style::left || control::dock() == dock_style::right) next_control_->width(new_size);
120  else next_control_->height(new_size);
121  mouse_down_location = control::dock() == dock_style::left || control::dock() == dock_style::right ? cursor::position().x() : cursor::position().y();
122  }
123  }
124  }
125 
126  void on_mouse_up(const mouse_event_args& e) override {
128  if (previous_control_) previous_control_->cursor(previous_control_cursor_);
129  if (next_control_) next_control_->cursor(previous_control_cursor_);
130  if (mouse_down_location != -1 && parent().has_value() && next_control_) {
131  int new_size = (control::dock() == dock_style::left || control::dock() == dock_style::right ? (next_control_->width() + cursor::position().x()) : (next_control_->height() + cursor::position().y())) - mouse_down_location;
132  if (new_size < min_size_) new_size = min_size_;
133  if (control::dock() == dock_style::left || control::dock() == dock_style::right) next_control_->width(new_size);
134  else next_control_->height(new_size);
135  mouse_down_location = -1;
136  }
137  previous_control_ = nullptr;
138  next_control_ = nullptr;
139  }
140 
141  void on_handle_created(const event_args& e) override {
143  }
145 
146  private:
147  bool default_width_ = true;
148  int min_size_ = 25;
149  //int min_size_extra_ = 25;
150  //int split_position_ = -1;
151  int mouse_down_location = -1;
153  xtd::forms::cursor previous_control_cursor_;
154  xtd::forms::cursor next_control_cursor_;
155  control* previous_control_ = nullptr;
156  control* next_control_ = nullptr;
157  };
158  }
159 }
Contains xtd::forms::splitter_style enum class.
The control&#39;s right edge is docked to the right edge of its containing control.
static cursor hsplit()
Gets the cursor that appears when the mouse is positioned over a horizontal splitter bar...
virtual void on_mouse_down(const mouse_event_args &e)
Raises the control::mouse_down event.
void on_handle_created(const event_args &e) override
Raises the control::handle_created event.
Definition: splitter.h:141
virtual void on_handle_created(const event_args &e)
Raises the control::handle_created event.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
virtual control & dock(dock_style dock) override
Sets or sets which control borders are docked to its parent control and determines how a control is r...
Definition: splitter.h:51
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:170
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
virtual dock_style dock() const
Gets or sets which control borders are docked to its parent control and determines how a control is r...
cursor()
Initializes a new instance of the cursor class.
Represents the image used to paint the mouse pointer.
Definition: cursor.h:35
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:219
virtual splitter & splitter_style(xtd::forms::splitter_style splitter_style)
Sets the style of the splitter.
Definition: splitter.h:79
static cursor vsplit()
Gets the cursor that appears when the mouse is positioned over a vertical splitter bar...
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition: splitter.h:126
Specifies that the height of the control is defined.
virtual void on_mouse_up(const mouse_event_args &e)
Raises the control::mouse_up event.
virtual int min_size() const
Gets the minimum distance that must remain between the splitter control and the container edge that t...
Definition: splitter.h:62
Specifies that both the width and height property values of the control are defined.
void on_mouse_move(const mouse_event_args &e) override
Raises the control::mouse_move event.
Definition: splitter.h:107
The exception that is thrown when one of the arguments provided to a method is not valid...
Definition: argument_exception.h:19
void on_mouse_down(const mouse_event_args &e) override
Raises the control::mouse_down event.
Definition: splitter.h:91
forms::cursor default_cursor() const override
Gets the default cursor for the control.
Definition: splitter.h:37
virtual xtd::forms::splitter_style splitter_style() const
Gets the style of the splitter.
Definition: splitter.h:75
splitter()
Initializes a new instance of the splitter class.
Definition: splitter.h:28
Specifies that the width of the control is defined.
The control&#39;s bottom edge is docked to the bottom of its containing control.
Update children splitter style.
virtual splitter & min_size(int min_size)
Sets the minimum distance that must remain between the splitter control and the container edge that t...
Definition: splitter.h:66
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:216
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.
Provides data for the xtd::forms::control::mouse_up, xtd::forms::control::mouse_down, and xtd::forms::control::mouse_move events.
Definition: mouse_event_args.h:29
Contains xtd::forms::control control.
splitter_style
Represent splitter style used by splitter control.
Definition: splitter_style.h:17
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual void on_mouse_move(const mouse_event_args &e)
Raises the control::mouse_move event.
The control&#39;s top edge is docked to the top of its containing control.
Draw line splitter style.
Contains xtd::argument_exception exception.
static drawing::point position()
Gets the cursor&#39;s position.
drawing::size default_size() const override
Gets the default size of the control.
Definition: splitter.h:39
Represents a splitter control that enables the user to resize docked controls.
Definition: splitter.h:22