Home » Community » Newbie corner » Alignment of two (or more) toolbars at the same "level"
Alignment of two (or more) toolbars at the same "level" [message #28334] |
Sun, 29 August 2010 11:56  |
281264
Messages: 272 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
Hi,
Is it possible to align more than one tool bar in the same application “row/level” (or column, if they are vertically oriented?; I am referring to the typical feature of many applications, through which some toolbars share the same “row” (very common when the toolbars in question are rather small).
A second query: is it possible to relocate a toolbar with drag and drop?
Cheers,
Javier
|
|
|
|
|
|
|
|
|
|
Re: Alignment of two (or more) toolbars at the same "level" [message #28418 is a reply to message #28407] |
Wed, 01 September 2010 14:54   |
andrei_natanael
Messages: 262 Registered: January 2009
|
Experienced Member |
|
|
281264 wrote on Tue, 31 August 2010 22:37 | Andrei,
Very grateful. It will be very useful.
What about the drag and drop feature?
Cheers,
Javier
|
Hello Javier,
If you want drag and drop you may use Docking from Bazaar, which provide rich docking options. If you want something simple, you may do it by your self 
Here is my solution. Add an instance of BarHandler to a Bar (MenuBar, Toolbar) and see how it's working.
class BarHandler: public Ctrl {
public:
Ctrl *parent;
BarCtrl* bar;
bool left_down;
Point left_point;
BarHandler() : bar(0), parent(0), left_down(false) {}
void UpdateLayout()
{
if (bar) {
int align = bar->GetAlign();
if (align == BarCtrl::BAR_LEFT || align == BarCtrl::BAR_RIGHT)
TopPos(1, 4).HSizePosZ(2, 2);
else
VSizePosZ(2, 2).LeftPos(1, 4);
}
}
void ParentChange()
{
bar = 0;
VSizePos(2, 2).LeftPos(1, 4);
}
void InitCtrl()
{
Ctrl* ctrl = GetParent();
while (ctrl) {
bar = dynamic_cast<BarCtrl*>(ctrl);
if (bar && (bar->IsToolBar() || bar->IsMenuBar())) {
parent = bar->GetParent();
break;
} else {
bar = 0;
}
ctrl = ctrl->GetParent();
}
}
void MouseLeave()
{
if (left_down)
SetCapture();
}
void LeftDown(Point p, dword keyflags)
{
left_down = true;
left_point = p;
if (!bar || !parent)
InitCtrl();
if (bar && !bar->IsPopUp()) {
Rect r = bar->GetScreenView();
parent->RemoveFrame((CtrlFrame&)*bar);
bar->SetRect(r.left , r.top, r.Width(), r.Height());
bar->PopUp(NULL, true, true, true, true);
}
}
void MouseMove(Point p, dword keyflags)
{
if (bar && left_down) {
Rect r = bar->GetScreenView();
bar->SetRect(p.x - left_point.x + r.left, p.y - left_point.y + r.top , r.Width(), r.Height());
}
}
void LeftUp(Point p, dword keyflags)
{
left_down = false;
int left, right, top, bottom;
left = right = top = bottom = 0;
if (bar && bar->IsPopUp()) {
Rect pr = parent->GetRect();
Point pt = GetMousePos();
if (pr.Contains(pt)) {
bar->Close();
parent->AddFrame(*bar);
left = pt.x - pr.left;
right = pr.right - pt.x;
top = pt.y - pr.top;
bottom = pr.bottom - pt.y;
if (left < right && left < top && left < bottom)
bar->Left();
if (right < left && right < top && right < bottom)
bar->Right();
if (top < left && top < right && top < bottom)
bar->Top();
if (bottom < left && bottom < right && bottom < top)
bar->Bottom();
}
}
ReleaseCapture();
UpdateLayout();
}
void Paint(Draw& w)
{
ChPaint(w, GetSize(), CtrlImg::SmallDot());
}
};
Andrei
|
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 01:43:36 CEST 2025
Total time taken to generate the page: 0.03395 seconds
|