|
#include "StdAfx.h"
#include "RollupCtrlPage.h"
#include "RollupCtrl.h"
//
// The user Toggles the page state with button1
//
void RollupCtrlPage::button1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
if ( e->Button == ::MouseButtons::Left )
{
//
// suppress the processing of the rollup page button clicks stored in buffer
// otherwise the user could click the button many, many times, and be forced
// to wait and watch numerous amounts of unneccessary page scrolling/unscrolling animations
// There is also a drawback doing this: When user is rapidly clicking the button, some clicks are lost
// (i.e. never processed)
//
if(e->Clicks > 1)return;
// toggle the page state unconditionally
bIsExpanded = !bIsExpanded;
RollThePage();
((RollupCtrl^)(this->Parent))->UpdatePageStates(this->Name,bIsExpanded);
}
}
//
// Developers call this method to conditionally change the rollup state to a new state
// if bExpand is true the page is expanded, if bExpand is false the page is contracted
//
void RollupCtrlPage::Expand(bool bExpand)
{
// change the page state only if it is not already in the state indictaed by the bExpand flag
if(bIsExpanded != bExpand)
{
bIsExpanded = bExpand;
RollThePage();
}
}
void RollupCtrlPage::RollThePage()
{
if(((RollupCtrl^)(this->Parent))->AnimatedRoll)
Rollup_Animated();
else
Rollup_Quick();
}
void RollupCtrlPage::Rollup_Quick()
{
int delta = (this->deltaSize-3);
if(bIsExpanded == true)
{
//expand it
this->button1->Text = L"- " + Name;
this->Resize(delta);
((RollupCtrl^)(this->Parent))->AdjustLayout(this,delta);
}
else
{
//close it
this->button1->Text = L"+ " + Name;
this->Resize(-delta);
((RollupCtrl^)(this->Parent))->AdjustLayout(this,-delta);
}
}
void RollupCtrlPage::Rollup_Animated()
{
int delta = ((RollupCtrl^)(this->Parent))->CurrentRollupSpeed;
int maxMove = (this->deltaSize-3);
int movedSoFar = 0;
if(bIsExpanded == true)
{
this->button1->Text = L"- " + Name;
// animation loop
for(movedSoFar = 0;movedSoFar < maxMove;movedSoFar+=delta)
{
if(maxMove-movedSoFar < delta)
delta = maxMove-movedSoFar;
this->Resize(delta);
((RollupCtrl^)(this->Parent))->AdjustLayout(this,delta);
}
}
else//if(bIsExpanded == false)
{
this->button1->Text = L"+ " + Name;
// animation loop
for(movedSoFar = 0;movedSoFar < maxMove;movedSoFar+=delta)
{
if(maxMove-movedSoFar < delta)
delta = maxMove-movedSoFar;
this->Resize(-delta);
((RollupCtrl^)(this->Parent))->AdjustLayout(this,-delta);
}
}
}
void RollupCtrlPage::Resize(int sizeChange)
{
if(dialogPanel == nullptr)
{
this->dialogPanel->Location = System::Drawing::Point(dialogPanel->Location.X, dialogPanel->Location.Y + sizeChange);
this->groupBox1->Size = System::Drawing::Size(groupboxwidth,groupBox1->Height + sizeChange);
this->Size = System::Drawing::Size(width ,this->Height + sizeChange);
}
else
{
this->dialogPanel->Location = System::Drawing::Point(dialogPanel->Location.X, dialogPanel->Location.Y + sizeChange);
this->groupBox1->Size = System::Drawing::Size(groupboxwidth,groupBox1->Height + sizeChange);
this->Size = System::Drawing::Size(width ,this->Height + sizeChange);
}
}
void RollupCtrlPage::OnMouseWheel(System::Windows::Forms::MouseEventArgs^ e)
{
bcontainsMouse = ((RollupCtrl^)(this->Parent))->ContainsMouse();
// only if the mouse cursor is somewhere in the parent rollup control do we want to use the wheel
if(bcontainsMouse == false)return;
//
// Update the drawing based upon the mouse wheel scrolling.
// Currently, a value of 120 is the standard for one detent.
// For more details see:
// http://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.delta(VS.71).aspx
//
int numberOfPixelsToMove = e->Delta * SystemInformation::MouseWheelScrollLines / 120;
((RollupCtrl^)(this->Parent))->MouseWheel_Scroll(numberOfPixelsToMove);
//Panel::OnMouseWheel(e); // base class method should be called according to MS docs. but...
}
void RollupCtrlPage::RollupCtrlPage_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
if ( e->Button == ::MouseButtons::Left )
{
bLButtonDown = true;
// init start position to drag from
lastMouseYPos = MousePosition.Y;
if(((RollupCtrl^)(this->Parent))->VScrollVisible)
{
if(((RollupCtrl^)(this->Parent))->GrabCursorExists)
this->Cursor = gcnew System::Windows::Forms::Cursor("Grab.Cur");
}
}
}
void RollupCtrlPage::RollupCtrlPage_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
if ( e->Button == ::MouseButtons::Left )
{
bLButtonDown = false;
if(bcontainsMouse)
{
if(((RollupCtrl^)(this->Parent))->VScrollVisible)
{
if(((RollupCtrl^)(this->Parent))->PanCursorExists)
this->Cursor = gcnew System::Windows::Forms::Cursor("Pan.Cur");
}
}
}
if ( e->Button == ::MouseButtons::Right )
{
((RollupCtrl^)(this->Parent))->contextMenuStrip_Show(bcontainsMouse);
}
}
void RollupCtrlPage::RollupCtrlPage_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
bcontainsMouse = ((RollupCtrl^)(this->Parent))->ContainsMouse();
if(bcontainsMouse == false)return;
int delta = 0;
if(bLButtonDown)
{
delta = lastMouseYPos-MousePosition.Y;
((RollupCtrl^)(this->Parent))->MouseLeftButtonDrag_Scroll(delta);
}
lastMouseYPos = MousePosition.Y;
}
void RollupCtrlPage::RollupCtrlPage_MouseEnter(Object^ sender, System::EventArgs^ /*e*/)
{
if(bcontainsMouse == false)
bcontainsMouse = ((RollupCtrl^)(this->Parent))->ContainsMouse();
if(bcontainsMouse)
{
((RollupCtrl^)(this->Parent))->CurrentPage = this;
if(((RollupCtrl^)(this->Parent))->VScrollVisible)
if(((RollupCtrl^)(this->Parent))->PanCursorExists)
this->Cursor = gcnew System::Windows::Forms::Cursor("Pan.Cur");
this->Focus();
}
}
void RollupCtrlPage::RollupCtrlPage_MouseLeave(Object^ sender, System::EventArgs^ /*e*/)
{
if(bcontainsMouse == true)
bcontainsMouse = ((RollupCtrl^)(this->Parent))->ContainsMouse();
if(bcontainsMouse)
{
this->Cursor = Cursors::Default;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.