xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 {
23  public:
26  size_ = default_size();
28  }
29 
40  virtual control& dock(dock_style dock) override {
41  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_);
42  control::dock(dock);
43  cursor(default_cursor());
44  if (default_width_ && (dock == dock_style::left || dock == dock_style::right)) width(3);
45  if (default_width_ && (dock == dock_style::top || dock == dock_style::bottom)) height(3);
46  return *this;
47  }
48 
51  virtual int min_size() const {return min_size_;}
55  virtual splitter& min_size(int min_size) {
56  if (min_size_ != min_size) {
57  min_size_ = min_size;
58  }
59  return *this;
60  }
61 
64  virtual xtd::forms::splitter_style splitter_style() const {return splitter_style_;}
69  if (splitter_style_ != splitter_style) {
70  splitter_style_ = splitter_style;
71  }
72  return *this;
73  }
74 
76 
77  drawing::size default_size() const override {return {3, 3};}
78 
79  protected:
80  void on_mouse_down(const mouse_event_args& e) override {
83  if (parent().has_value()) {
84  for(size_t index = 0; index < parent().value().get().controls().size(); index++) {
85  if (parent().value().get().controls()[index].get() == *this) {
86  if (index > 0) previous_control_cursor_ = (previous_control_ = &parent().value().get().controls()[index - 1].get())->cursor();
87  if (index < parent().value().get().controls().size() -1) next_control_cursor_ = (next_control_ = &parent().value().get().controls()[index + 1].get())->cursor();
88  break;
89  }
90  }
91  }
92  if (previous_control_) previous_control_->cursor(default_cursor());
93  if (next_control_) next_control_->cursor(default_cursor());
94  }
95 
96  void on_mouse_move(const mouse_event_args& e) override {
98  if (previous_control_) previous_control_->cursor(default_cursor());
99  if (next_control_) next_control_->cursor(default_cursor());
100  if (mouse_down_location != -1 && next_control_) {
101  if (splitter_style_ == splitter_style::draw_line) {
102 
103  } else {
104  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());
105  int new_size = delta_size - mouse_down_location;
106  if (new_size < min_size_) new_size = min_size_;
107  //if (previous_control_.size() < min_size_extra_) new_size = min_size_;
108  if (control::dock() == dock_style::left || control::dock() == dock_style::right) next_control_->width(new_size);
109  else next_control_->height(new_size);
110  mouse_down_location = control::dock() == dock_style::left || control::dock() == dock_style::right ? cursor::position().x() : cursor::position().y();
111  }
112  }
113  }
114 
115  void on_mouse_up(const mouse_event_args& e) override {
117  if (previous_control_) previous_control_->cursor(previous_control_cursor_);
118  if (next_control_) next_control_->cursor(previous_control_cursor_);
119  if (mouse_down_location != -1 && parent().has_value() && next_control_) {
120  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;
121  if (new_size < min_size_) new_size = min_size_;
122  if (control::dock() == dock_style::left || control::dock() == dock_style::right) next_control_->width(new_size);
123  else next_control_->height(new_size);
124  mouse_down_location = -1;
125  }
126  previous_control_ = nullptr;
127  next_control_ = nullptr;
128  }
129 
130  void on_handle_created(const event_args& e) override {
132  }
133 
134  private:
135  bool default_width_ = true;
136  int min_size_ = 25;
137  //int min_size_extra_ = 25;
138  //int split_position_ = -1;
139  int mouse_down_location = -1;
141  xtd::forms::cursor previous_control_cursor_;
142  xtd::forms::cursor next_control_cursor_;
143  control* previous_control_ = nullptr;
144  control* next_control_ = nullptr;
145  };
146  }
147 }
Contains xtd::argument_exception exception.
The exception that is thrown when one of the arguments provided to a method is not valid.
Definition: argument_exception.h:19
int32_t y() const
Gets the y-coordinate of this point.
Definition: point.h:205
int32_t x() const
Gets the x-coordinate of this point.
Definition: point.h:159
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
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 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
Represents the image used to paint the mouse pointer.
Definition: cursor.h:35
static drawing::point position()
Gets the cursor's position.
cursor()
Initializes a new instance of the cursor class.
static cursor hsplit()
Gets the cursor that appears when the mouse is positioned over a horizontal splitter bar.
static cursor vsplit()
Gets the cursor that appears when the mouse is positioned over a vertical splitter bar.
Provides data for the xtd::forms::control::mouse_up, xtd::forms::control::mouse_down,...
Definition: mouse_event_args.h:29
Represents a splitter control that enables the user to resize docked controls.
Definition: splitter.h:22
forms::cursor default_cursor() const override
Gets the default cursor for the control.
Definition: splitter.h:75
splitter()
Initializes a new instance of the splitter class.
Definition: splitter.h:25
void on_mouse_move(const mouse_event_args &e) override
Raises the control::mouse_move event.
Definition: splitter.h:96
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:55
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:51
void on_mouse_down(const mouse_event_args &e) override
Raises the control::mouse_down event.
Definition: splitter.h:80
void on_handle_created(const event_args &e) override
Raises the control::handle_created event.
Definition: splitter.h:130
virtual splitter & splitter_style(xtd::forms::splitter_style splitter_style)
Sets the style of the splitter.
Definition: splitter.h:68
void on_mouse_up(const mouse_event_args &e) override
Raises the control::mouse_up event.
Definition: splitter.h:115
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:40
drawing::size default_size() const override
Gets the default size of the control.
Definition: splitter.h:77
virtual xtd::forms::splitter_style splitter_style() const
Gets the style of the splitter.
Definition: splitter.h:64
Contains xtd::forms::control control.
virtual void on_mouse_up(const mouse_event_args &e)
Raises the control::mouse_up event.
virtual void on_handle_created(const event_args &e)
Raises the control::handle_created event.
virtual void on_mouse_down(const mouse_event_args &e)
Raises the control::mouse_down event.
virtual void on_mouse_move(const mouse_event_args &e)
Raises the control::mouse_move event.
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
@ e
The E key.
splitter_style
Represent splitter style used by splitter control.
Definition: splitter_style.h:17
dock_style
Specifies the position and manner in which a control is docked.
Definition: dock_style.h:19
@ height
Specifies that the height of the control is defined.
@ width
Specifies that the width of the control is defined.
@ update_children
Update children splitter style.
@ draw_line
Draw line splitter style.
@ 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.
@ top
The control's top edge is docked to the top of its containing control.
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::splitter_style enum class.