WxWidgets custom separation bar Control
By default, it seems that it is not easy to write one by yourself.
# Ifndef _ vsplitpanel_h _
# DEFINE _ vsplitpanel_h _
# Include <wx/intl. h>
# Include <wx/string. h>
# Include <wx/panel. h>
# Include <wx/button. h>
# Include <wx/dialog. h>
# Include <wx/msgdlg. h>
# Include <vector>
// Virtual separator bar
// Events can be bound only after they are inherited from wxevthandler.
Class vsplitpanel: Public wxevthandler //: Public wxpanel
{
Public:
Static STD: vector <vsplitpanel *> allsplitwindow;
Public:
Vsplitpanel ()
{
Init ();
}
Virtual ~ Vsplitpanel ();
Public:
// Wxpanel
Wxwindow * panel;
Wxwindow * parentwindow;
Wxwindow * leftwindow;
Wxwindow * rightwindow;
Wxwindow * topwindow;
Wxwindow * bottomwindow;
Bool isleft;
Bool Istop;
//--------------------------------------------------
// Drag and drop
Int lastx;
Int lasty;
Bool isdown; // press the mouse
//--------------------------------------------------
Void Init ()
{
Panel = NULL;
Parentwindow = NULL;
Leftwindow = NULL;
Rightwindow = NULL;
Topwindow = NULL;
Bottomwindow = NULL;
Isleft = false;
Istop = false;
Lastx = 0;
Lasty = 0;
Isdown = false;
}//
// Associate the control. The default value is left and right.
Void assign (wxwindow * splitpanel, wxwindow * parentwindow, wxwindow * W1, wxwindow * W2, bool isleft = true)
{
Init ();
This-> isleft = isleft;
This-> Panel = splitpanel;
This-> parentwindow = parentwindow;
If (isleft)
{
Leftwindow = W1;
Rightwindow = W2;
}
Else
{
Topwindow = W1;
Bottomwindow = W2;
}
}//
// It can be called when the onsize of the child window is reset when the parent window is changed
Int geth (wxwindow * window)
{
If (window = NULL) return 0;
Return window-> getsize (). Y;
}//
Int getw (wxwindow * window)
{
If (window = NULL) return 0;
Return window-> getsize (). X;
}//
Int getleft (wxwindow * window)
{
If (window = NULL) return 0;
Return window-> getposition (). X;
}//
Int gettop (wxwindow * window)
{
If (window = NULL) return 0;
Return window-> getposition (). Y;
}//
Void movewindow (wxwindow * window, int X, int y, int width, int height)
{
If (window! = NULL)
{
// Rightwindow-> setposition (wxpoint (left, 10); // In the current wxWidgets-2.8.12 version, this will actually change the position of the Panel neutron control, preferably using the encapsulated Function
// Rightwindow-> setsize (left, 10, wxdefacocoord, wxdefacocoord, wxsize_use_existing );
// Rightwindow-> setsize (client. X-left, client. y );
Window-> setsize (X, Y, width, height); //, wxdefacocoord );
}
}//
Void movewindowpos (wxwindow * window, int X, int y)
{
If (window! = NULL)
{
Wxrect rect = Window-> getrect ();
Movewindow (window, X, Y, rect. Width, rect. Height );
}
}//
Void movewindowleft (wxwindow * window, int X)
{
If (window! = NULL)
{
Wxrect rect = Window-> getrect ();
Movewindow (window, X, rect. Y, rect. Width, rect. Height );
}
}//
Void move1_wwidth (wxwindow * window, int width)
{
If (window! = NULL)
{
Wxrect rect = Window-> getrect ();
Movewindow (window, rect. X, rect. Y, width, rect. Height );
}
}//
Void movewindowheight (wxwindow * window, int height)
{
If (window! = NULL)
{
Wxrect rect = Window-> getrect ();
Movewindow (window, rect. X, rect. Y, rect. width, height );
}
}//
Void onparentsize (bool refresh = true)
{
Wxsize client = parentwindow-> getclientsize ();
Int left = getw (leftwindow );
Int Top = geth (topwindow );
Left + = panel-> getsize (). X;
Top + = panel-> getsize (). Y;
If (leftwindow! = NULL)
{
// Leftwindow-> setposition (wxpoint (0, 0 ));
// Leftwindow-> setsize (getw (leftwindow), client. y );
Movewindow (leftwindow, 0, 0, getw (leftwindow), client. y );
}
If (topwindow! = NULL)
{
Movewindow (topwindow, 0, 0, client. X, geth (topwindow ));
}
If (rightwindow! = NULL)
{
// Rightwindow-> setposition (wxpoint (left, 10); // In the current wxWidgets-2.8.12 version, this will actually change the position of the Panel neutron control, preferably using the encapsulated Function
// Rightwindow-> setsize (left, 10, wxdefacocoord, wxdefacocoord, wxsize_use_existing );
// Rightwindow-> setsize (client. X-left, client. y );
/// Rightwindow-> setsize (left, 0, client. X-left, client. Y); //, wxdefacocoord );
Movewindow (rightwindow, left, 0, client. X-left, client. y );
}
If (bottomwindow! = NULL)
{
Movewindow (bottomwindow, 0, top, client. X, client. Y-top );
}
If (isleft = true)
{
// Panel-> setposition (wxpoint (getw (leftwindow), 0 ));
// Panel-> setsize (getw (panel), client. y );
movewindow (panel, getw (leftwindow), 0, getw (panel), client. y);
}else
{< br> movewindow (panel, 0, geth (topwindow), client. x, geth (panel);
}
If (refresh = true)
{< br> // This-> Panel1-> refresh (); // according to the Wx Help File
// according to the Wx help file, you need to call this after moving the window
// If (leftwindow! = NULL) leftwindow-> refresh ();
// If (rightwindow! = NULL) rightwindow-> refresh ();
// If (topwindow! = NULL) topwindow-> refresh ();
// If (bottomwindow! = NULL) bottomwindow-> refresh ();
// Refreshwindow (panel );
Refreshwindow (parentwindow );
// Refreshwindow (leftwindow );
// Refreshwindow (rightwindow );
// Refreshwindow (topwindow );
// Refreshwindow (bottomwindow); // The sequence is exquisite. Why?
}
// Panel-> capturemouse ();
}//
// Events can be bound only after they are inherited from wxevthandler.
Void setevents () // Test
{
// Panel-> connect (wxevt_left_down, (wxobjecteventfunction) & vsplitpanel: onleftdown, 0, this );
Panel-> connect (wxevt_left_down, (wxobjecteventfunction) & vsplitpanel: onleftdown, 0, this );
Panel-> connect (wxevt_left_up, (wxobjecteventfunction) & vsplitpanel: doonleftup, 0, this );
Panel-> connect (wxevt_motion, (wxobjecteventfunction) & vsplitpanel: doonmousemove, 0, this );
// Panel-> connect (wxevt_left_down, (wxobjecteventfunction) & vsplitpanel: onleftdown, 0, this );
}
//
Void onleftdown (wxmouseevent & event)
{
// Panel-> capturemouse ();
// Wxmessagebox ("","");
Doonleftdown (event );
}//
// Do things on...
Void doonleftdown (wxmouseevent & event)
{
Int x =: wxgetmouseposition (). X; // event. m_x;
Int y =: wxgetmouseposition (). Y; // event. m_y;
Panel-> capturemouse ();
// Wxmessagebox ("","");
Lastx = X;
Lasty = y;
Isdown = true;
}//
// Do things on...
Void doonleftup (wxmouseevent & event)
{
Isdown = false;
Int x =: wxgetmouseposition (). X; // event. m_x;
Int y =: wxgetmouseposition (). Y; // event. m_y;
Panel-> releasemouse (); // capturemouse ();
// Wxmessagebox ("up ","");
Lastx = X;
Lasty = y;
}//
// Void refreshwindow
Void refreshwindow (wxwindow * window)
{
If (window = NULL) return;
Window-> refresh ();
Window-> Update (); // Based on the Wx help, you must call this operation to re-draw the image immediately.
}
// Do things on...
Void doonmousemove (wxmouseevent & event)
{
Int x =: wxgetmouseposition (). X; // event. m_x;
Int y =: wxgetmouseposition (). Y; // event. m_y;
Int left = getleft (panel );
If (isdown = true)
{
// Panel-> capturemouse ();
// Wxmessagebox ("","");
If (isleft = true)
{
Int sp = x-lastx;
Left + = sp;
// Movewindowleft (panel, left );
// left = getleft (rightwindow);
// movewindowleft (rightwindow, left + SP);
int W = getw (leftwindow);
W + = sp;
If (W> 0) move1_wwidth (leftwindow, W );
}// left
else
{< br> int sp = Y-lasty;
Int H = geth (topwindow );
H + = sp;
If (h> 0) move1_wheight (topwindow, H );
} // Top
Onparentsize (true );
Lastx = X;
Lasty = y;
}
}//
Protected:
PRIVATE:
};
# endif // _ vsplitpanel_h _