Added wxSashWindow, wxSashLayoutWindow, wxLayoutAlgorithm classes and sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@702 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
226
src/generic/laywin.cpp
Normal file
226
src/generic/laywin.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: laywin.cpp
|
||||
// Purpose: Implements a simple layout algorithm, plus
|
||||
// wxSashLayoutWindow which is an example of a window with
|
||||
// layout-awareness (via event handlers). This is suited to
|
||||
// IDE-style window layout.
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#include "wx/mdi.h"
|
||||
#endif
|
||||
|
||||
#include "wx/laywin.h"
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxQueryLayoutInfoEvent, wxEvent)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCalculateLayoutEvent, wxEvent)
|
||||
|
||||
IMPLEMENT_CLASS(wxSashLayoutWindow, wxSashWindow)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxSashLayoutWindow, wxSashWindow)
|
||||
EVT_CALCULATE_LAYOUT(wxSashLayoutWindow::OnCalculateLayout)
|
||||
EVT_QUERY_LAYOUT_INFO(wxSashLayoutWindow::OnQueryLayoutInfo)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxSashLayoutWindow::wxSashLayoutWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos,
|
||||
const wxSize& size, long style, const wxString& name):
|
||||
wxSashWindow(parent, id, pos, size, style, name)
|
||||
{
|
||||
m_orientation = wxLAYOUT_HORIZONTAL;
|
||||
m_alignment = wxLAYOUT_TOP;
|
||||
}
|
||||
|
||||
// These are the functions that wxWin will call to ascertain the window
|
||||
// dimensions.
|
||||
void wxSashLayoutWindow::OnQueryLayoutInfo(wxQueryLayoutInfoEvent& event)
|
||||
{
|
||||
int flags = event.GetFlags();
|
||||
int requestedLength = event.GetRequestedLength();
|
||||
|
||||
// This code won't be in the final thing, it's just so we don't have to give it
|
||||
// real windows: mock up some dimensions.
|
||||
|
||||
event.SetOrientation(m_orientation);
|
||||
event.SetAlignment(m_alignment);
|
||||
|
||||
if (m_orientation == wxLAYOUT_HORIZONTAL)
|
||||
event.SetSize(wxSize(requestedLength, m_defaultSize.y));
|
||||
else
|
||||
event.SetSize(wxSize(m_defaultSize.x, requestedLength));
|
||||
}
|
||||
|
||||
// Called by parent to allow window to take a bit out of the
|
||||
// client rectangle, and size itself if not in wxLAYOUT_QUERY mode.
|
||||
// Will eventually be an event.
|
||||
|
||||
void wxSashLayoutWindow::OnCalculateLayout(wxCalculateLayoutEvent& event)
|
||||
{
|
||||
wxRect clientSize(event.GetRect());
|
||||
|
||||
int flags = event.GetFlags();
|
||||
|
||||
if (!IsShown())
|
||||
return;
|
||||
|
||||
// Let's assume that all windows stretch the full extent of the window in
|
||||
// the direction of that window orientation. This will work for non-docking toolbars,
|
||||
// and the status bar. Note that the windows have to have been created in a certain
|
||||
// order to work, else you might get a left-aligned window going to the bottom
|
||||
// of the window, and the status bar appearing to the right of it. The
|
||||
// status bar would have to be created after or before the toolbar(s).
|
||||
|
||||
wxRect thisRect;
|
||||
|
||||
// Try to stretch
|
||||
int length = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? clientSize.width : clientSize.height;
|
||||
wxLayoutOrientation orient = GetOrientation();
|
||||
|
||||
// We assume that a window that says it's horizontal, wants to be stretched in that
|
||||
// direction. Is this distinction too fine? Do we assume that any horizontal
|
||||
// window needs to be stretched in that direction? Possibly.
|
||||
int whichDimension = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? wxLAYOUT_LENGTH_X : wxLAYOUT_LENGTH_Y;
|
||||
|
||||
wxQueryLayoutInfoEvent infoEvent(GetId());
|
||||
infoEvent.SetEventObject(this);
|
||||
infoEvent.SetRequestedLength(length);
|
||||
infoEvent.SetFlags(orient | whichDimension);
|
||||
|
||||
if (!GetEventHandler()->ProcessEvent(infoEvent))
|
||||
return;
|
||||
|
||||
wxSize sz = infoEvent.GetSize();
|
||||
|
||||
if (sz.x == 0 && sz.y == 0) // Assume it's invisible
|
||||
return;
|
||||
|
||||
// Now we know the size it wants to be. We wish to decide where to place it, i.e.
|
||||
// how it's aligned.
|
||||
switch (GetAlignment())
|
||||
{
|
||||
case wxLAYOUT_TOP:
|
||||
{
|
||||
thisRect.x = clientSize.x; thisRect.y = clientSize.y;
|
||||
thisRect.width = sz.x; thisRect.height = sz.y;
|
||||
clientSize.y += thisRect.height;
|
||||
clientSize.height -= thisRect.height;
|
||||
break;
|
||||
}
|
||||
case wxLAYOUT_LEFT:
|
||||
{
|
||||
thisRect.x = clientSize.x; thisRect.y = clientSize.y;
|
||||
thisRect.width = sz.x; thisRect.height = sz.y;
|
||||
clientSize.x += thisRect.width;
|
||||
clientSize.width -= thisRect.width;
|
||||
break;
|
||||
}
|
||||
case wxLAYOUT_RIGHT:
|
||||
{
|
||||
thisRect.x = clientSize.x + (clientSize.width - sz.x); thisRect.y = clientSize.y;
|
||||
thisRect.width = sz.x; thisRect.height = sz.y;
|
||||
clientSize.width -= thisRect.width;
|
||||
break;
|
||||
}
|
||||
case wxLAYOUT_BOTTOM:
|
||||
{
|
||||
thisRect.x = clientSize.x; thisRect.y = clientSize.y + (clientSize.height - sz.y);
|
||||
thisRect.width = sz.x; thisRect.height = sz.y;
|
||||
clientSize.height -= thisRect.height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & wxLAYOUT_QUERY) == 0)
|
||||
{
|
||||
// If not in query mode, resize the window.
|
||||
// TODO: add wxRect& form to wxWindow::SetSize
|
||||
SetSize(thisRect.x, thisRect.y, thisRect.width, thisRect.height);
|
||||
}
|
||||
|
||||
event.SetRect(clientSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* wxLayoutAlgorithm
|
||||
*/
|
||||
|
||||
// Lays out windows for an MDI frame. The MDI client area gets what's left
|
||||
// over.
|
||||
bool wxLayoutAlgorithm::LayoutMDIFrame(wxMDIParentFrame* frame)
|
||||
{
|
||||
int cw, ch;
|
||||
frame->GetClientSize(& cw, & ch);
|
||||
|
||||
wxRect rect(0, 0, cw, ch);
|
||||
|
||||
wxCalculateLayoutEvent event;
|
||||
event.SetRect(rect);
|
||||
|
||||
wxNode* node = frame->GetChildren()->First();
|
||||
while (node)
|
||||
{
|
||||
wxWindow* win = (wxWindow*) node->Data();
|
||||
|
||||
event.SetId(win->GetId());
|
||||
event.SetEventObject(win);
|
||||
event.SetFlags(0); // ??
|
||||
|
||||
win->GetEventHandler()->ProcessEvent(event);
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
wxWindow* clientWindow = frame->GetClientWindow();
|
||||
|
||||
rect = event.GetRect();
|
||||
|
||||
clientWindow->SetSize(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Layout algorithm for normal frame. mainWindow gets what's left over.
|
||||
bool wxLayoutAlgorithm::LayoutFrame(wxFrame* frame, wxWindow* mainWindow)
|
||||
{
|
||||
int cw, ch;
|
||||
frame->GetClientSize(& cw, & ch);
|
||||
|
||||
wxRect rect(0, 0, cw, ch);
|
||||
|
||||
wxCalculateLayoutEvent event;
|
||||
event.SetRect(rect);
|
||||
|
||||
wxNode* node = frame->GetChildren()->First();
|
||||
while (node)
|
||||
{
|
||||
wxWindow* win = (wxWindow*) node->Data();
|
||||
|
||||
event.SetId(win->GetId());
|
||||
event.SetEventObject(win);
|
||||
event.SetFlags(0); // ??
|
||||
|
||||
win->GetEventHandler()->ProcessEvent(event);
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
rect = event.GetRect();
|
||||
|
||||
mainWindow->SetSize(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
588
src/generic/sashwin.cpp
Normal file
588
src/generic/sashwin.cpp
Normal file
@@ -0,0 +1,588 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sashwin.cpp
|
||||
// Purpose: wxSashWindow implementation. A sash window has an optional
|
||||
// sash on each edge, allowing it to be dragged. An event
|
||||
// is generated when the sash is released.
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 01/02/97
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sashwin.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "wx/string.h"
|
||||
#include "wx/dcscreen.h"
|
||||
#include "wx/sashwin.h"
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSashWindow, wxWindow)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSashEvent, wxCommandEvent)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxSashWindow, wxWindow)
|
||||
EVT_PAINT(wxSashWindow::OnPaint)
|
||||
EVT_SIZE(wxSashWindow::OnSize)
|
||||
EVT_MOUSE_EVENTS(wxSashWindow::OnMouseEvent)
|
||||
END_EVENT_TABLE()
|
||||
#endif
|
||||
|
||||
wxSashWindow::wxSashWindow()
|
||||
{
|
||||
m_draggingEdge = wxSASH_NONE;
|
||||
m_dragMode = wxSASH_DRAG_NONE;
|
||||
m_oldX = 0;
|
||||
m_oldY = 0;
|
||||
m_firstX = 0;
|
||||
m_firstY = 0;
|
||||
m_borderSize = 3 ;
|
||||
m_extraBorderSize = 0;
|
||||
m_sashCursorWE = NULL;
|
||||
m_sashCursorNS = NULL;
|
||||
|
||||
m_minimumPaneSizeX = 0;
|
||||
m_minimumPaneSizeY = 0;
|
||||
m_maximumPaneSizeX = 0;
|
||||
m_maximumPaneSizeY = 0;
|
||||
}
|
||||
|
||||
wxSashWindow::wxSashWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos,
|
||||
const wxSize& size, long style, const wxString& name)
|
||||
:wxWindow(parent, id, pos, size, style, name)
|
||||
{
|
||||
m_draggingEdge = wxSASH_NONE;
|
||||
m_dragMode = wxSASH_DRAG_NONE;
|
||||
m_oldX = 0;
|
||||
m_oldY = 0;
|
||||
m_firstX = 0;
|
||||
m_firstY = 0;
|
||||
m_borderSize = 3;
|
||||
m_extraBorderSize = 0;
|
||||
m_minimumPaneSizeX = 0;
|
||||
m_minimumPaneSizeY = 0;
|
||||
m_maximumPaneSizeX = 0;
|
||||
m_maximumPaneSizeY = 0;
|
||||
m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
|
||||
m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
|
||||
|
||||
// Eventually, we'll respond to colour change messages
|
||||
InitColours();
|
||||
}
|
||||
|
||||
wxSashWindow::~wxSashWindow()
|
||||
{
|
||||
delete m_sashCursorWE;
|
||||
delete m_sashCursorNS;
|
||||
}
|
||||
|
||||
void wxSashWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
|
||||
#if 0
|
||||
if ( m_borderSize > 0 )
|
||||
DrawBorders(dc);
|
||||
#endif
|
||||
|
||||
DrawSashes(dc);
|
||||
}
|
||||
|
||||
void wxSashWindow::OnMouseEvent(wxMouseEvent& event)
|
||||
{
|
||||
long x, y;
|
||||
event.Position(&x, &y);
|
||||
|
||||
wxSashEdgePosition sashHit = SashHitTest(x, y);
|
||||
|
||||
if (event.LeftDown())
|
||||
{
|
||||
if ( sashHit != wxSASH_NONE )
|
||||
{
|
||||
CaptureMouse();
|
||||
|
||||
// Required for X to specify that
|
||||
// that we wish to draw on top of all windows
|
||||
// - and we optimise by specifying the area
|
||||
// for creating the overlap window.
|
||||
wxScreenDC::StartDrawingOnTop(this);
|
||||
|
||||
// We don't say we're dragging yet; we leave that
|
||||
// decision for the Dragging() branch, to ensure
|
||||
// the user has dragged a little bit.
|
||||
m_dragMode = wxSASH_DRAG_LEFT_DOWN;
|
||||
m_draggingEdge = sashHit;
|
||||
m_firstX = x;
|
||||
m_firstY = y;
|
||||
}
|
||||
}
|
||||
else if ( event.LeftUp() && m_dragMode == wxSASH_DRAG_LEFT_DOWN )
|
||||
{
|
||||
// Wasn't a proper drag
|
||||
ReleaseMouse();
|
||||
wxScreenDC::EndDrawingOnTop();
|
||||
m_dragMode = wxSASH_DRAG_NONE;
|
||||
m_draggingEdge = wxSASH_NONE;
|
||||
|
||||
SetCursor(*wxSTANDARD_CURSOR);
|
||||
}
|
||||
else if (event.LeftUp() && m_dragMode == wxSASH_DRAG_DRAGGING)
|
||||
{
|
||||
// We can stop dragging now and see what we've got.
|
||||
m_dragMode = wxSASH_DRAG_NONE;
|
||||
ReleaseMouse();
|
||||
// Erase old tracker
|
||||
DrawSashTracker(m_draggingEdge, m_oldX, m_oldY);
|
||||
|
||||
// End drawing on top (frees the window used for drawing
|
||||
// over the screen)
|
||||
wxScreenDC::EndDrawingOnTop();
|
||||
|
||||
int w, h;
|
||||
GetSize(&w, &h);
|
||||
int xp, yp;
|
||||
GetPosition(&xp, &yp);
|
||||
|
||||
wxSashEdgePosition edge = m_draggingEdge;
|
||||
m_draggingEdge = wxSASH_NONE;
|
||||
|
||||
wxRect dragRect;
|
||||
wxSashDragStatus status = wxSASH_STATUS_OK;
|
||||
switch (edge)
|
||||
{
|
||||
case wxSASH_TOP:
|
||||
{
|
||||
if (y > (yp + h))
|
||||
status = wxSASH_STATUS_OUT_OF_RANGE;
|
||||
int newHeight = (h - y);
|
||||
dragRect = wxRect(xp, (yp + h) - newHeight, w, newHeight);
|
||||
break;
|
||||
}
|
||||
case wxSASH_BOTTOM:
|
||||
{
|
||||
if (y < 0)
|
||||
status = wxSASH_STATUS_OUT_OF_RANGE;
|
||||
int newHeight = y;
|
||||
dragRect = wxRect(xp, yp, w, newHeight);
|
||||
break;
|
||||
}
|
||||
case wxSASH_LEFT:
|
||||
{
|
||||
if (x > (xp + w))
|
||||
status = wxSASH_STATUS_OUT_OF_RANGE;
|
||||
int newWidth = (w - x);
|
||||
dragRect = wxRect((xp + w) - newWidth, yp, newWidth, h);
|
||||
break;
|
||||
}
|
||||
case wxSASH_RIGHT:
|
||||
{
|
||||
if (x < 0)
|
||||
status = wxSASH_STATUS_OUT_OF_RANGE;
|
||||
int newWidth = x;
|
||||
dragRect = wxRect(xp, yp, newWidth, h);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wxSashEvent event(GetId(), edge);
|
||||
event.SetEventObject(this);
|
||||
event.SetDragStatus(status);
|
||||
event.SetDragRect(dragRect);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
else if (event.Moving() && !event.Dragging())
|
||||
{
|
||||
// Just change the cursor if required
|
||||
if ( sashHit != wxSASH_NONE )
|
||||
{
|
||||
if ( (sashHit == wxSASH_LEFT) || (sashHit == wxSASH_RIGHT) )
|
||||
{
|
||||
SetCursor(*m_sashCursorWE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCursor(*m_sashCursorNS);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCursor(*wxSTANDARD_CURSOR);
|
||||
}
|
||||
}
|
||||
else if ( event.Dragging() &&
|
||||
((m_dragMode == wxSASH_DRAG_DRAGGING) || (m_dragMode == wxSASH_DRAG_LEFT_DOWN))
|
||||
)
|
||||
{
|
||||
if ( (m_draggingEdge == wxSASH_LEFT) || (m_draggingEdge == wxSASH_RIGHT) )
|
||||
{
|
||||
SetCursor(*m_sashCursorWE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCursor(*m_sashCursorNS);
|
||||
}
|
||||
|
||||
if (m_dragMode == wxSASH_DRAG_LEFT_DOWN)
|
||||
{
|
||||
m_dragMode = wxSASH_DRAG_DRAGGING;
|
||||
DrawSashTracker(m_draggingEdge, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_dragMode == wxSASH_DRAG_DRAGGING )
|
||||
{
|
||||
// Erase old tracker
|
||||
DrawSashTracker(m_draggingEdge, m_oldX, m_oldY);
|
||||
|
||||
// Draw new one
|
||||
DrawSashTracker(m_draggingEdge, x, y);
|
||||
}
|
||||
}
|
||||
m_oldX = x;
|
||||
m_oldY = y;
|
||||
}
|
||||
else if ( event.LeftDClick() )
|
||||
{
|
||||
// Nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void wxSashWindow::OnSize(wxSizeEvent& WXUNUSED(event))
|
||||
{
|
||||
SizeWindows();
|
||||
}
|
||||
|
||||
wxSashEdgePosition wxSashWindow::SashHitTest(int x, int y, int tolerance)
|
||||
{
|
||||
int cx, cy;
|
||||
GetClientSize(& cx, & cy);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
wxSashEdge& edge = m_sashes[i];
|
||||
wxSashEdgePosition position = (wxSashEdgePosition) i ;
|
||||
|
||||
if (edge.m_show)
|
||||
{
|
||||
switch (position)
|
||||
{
|
||||
case wxSASH_TOP:
|
||||
{
|
||||
if (y >= 0 && y <= GetEdgeMargin(position))
|
||||
return wxSASH_TOP;
|
||||
break;
|
||||
}
|
||||
case wxSASH_RIGHT:
|
||||
{
|
||||
if ((x >= cx - GetEdgeMargin(position)) && (x <= cx))
|
||||
return wxSASH_RIGHT;
|
||||
break;
|
||||
}
|
||||
case wxSASH_BOTTOM:
|
||||
{
|
||||
if ((y >= cy - GetEdgeMargin(position)) && (y <= cy))
|
||||
return wxSASH_BOTTOM;
|
||||
break;
|
||||
}
|
||||
case wxSASH_LEFT:
|
||||
{
|
||||
if ((x >= GetEdgeMargin(position)) && (x >= 0))
|
||||
return wxSASH_LEFT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return wxSASH_NONE;
|
||||
}
|
||||
|
||||
// Draw 3D effect borders
|
||||
void wxSashWindow::DrawBorders(wxDC& dc)
|
||||
{
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
|
||||
wxPen mediumShadowPen(m_mediumShadowColour, 1, wxSOLID);
|
||||
wxPen darkShadowPen(m_darkShadowColour, 1, wxSOLID);
|
||||
wxPen lightShadowPen(m_lightShadowColour, 1, wxSOLID);
|
||||
wxPen hilightPen(m_hilightColour, 1, wxSOLID);
|
||||
|
||||
if ( GetWindowStyleFlag() & wxSP_3D )
|
||||
{
|
||||
dc.SetPen(mediumShadowPen);
|
||||
dc.DrawLine(0, 0, w-1, 0);
|
||||
dc.DrawLine(0, 0, 0, h - 1);
|
||||
|
||||
dc.SetPen(darkShadowPen);
|
||||
dc.DrawLine(1, 1, w-2, 1);
|
||||
dc.DrawLine(1, 1, 1, h-2);
|
||||
|
||||
dc.SetPen(hilightPen);
|
||||
dc.DrawLine(0, h-1, w-1, h-1);
|
||||
dc.DrawLine(w-1, 0, w-1, h); // Surely the maximum y pos. should be h - 1.
|
||||
/// Anyway, h is required for MSW.
|
||||
|
||||
dc.SetPen(lightShadowPen);
|
||||
dc.DrawLine(w-2, 1, w-2, h-2); // Right hand side
|
||||
dc.DrawLine(1, h-2, w-1, h-2); // Bottom
|
||||
}
|
||||
else if ( GetWindowStyleFlag() & wxSP_BORDER )
|
||||
{
|
||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
dc.SetPen(*wxBLACK_PEN);
|
||||
dc.DrawRectangle(0, 0, w-1, h-1);
|
||||
}
|
||||
|
||||
dc.SetPen(wxNullPen);
|
||||
dc.SetBrush(wxNullBrush);
|
||||
}
|
||||
|
||||
void wxSashWindow::DrawSashes(wxDC& dc)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 4; i++)
|
||||
if (m_sashes[i].m_show)
|
||||
DrawSash((wxSashEdgePosition) i, dc);
|
||||
}
|
||||
|
||||
// Draw the sash
|
||||
void wxSashWindow::DrawSash(wxSashEdgePosition edge, wxDC& dc)
|
||||
{
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
|
||||
wxPen facePen(m_faceColour, 1, wxSOLID);
|
||||
wxBrush faceBrush(m_faceColour, wxSOLID);
|
||||
wxPen mediumShadowPen(m_mediumShadowColour, 1, wxSOLID);
|
||||
wxPen darkShadowPen(m_darkShadowColour, 1, wxSOLID);
|
||||
wxPen lightShadowPen(m_lightShadowColour, 1, wxSOLID);
|
||||
wxPen hilightPen(m_hilightColour, 1, wxSOLID);
|
||||
wxPen blackPen(wxColour(0, 0, 0), 1, wxSOLID);
|
||||
wxPen whitePen(wxColour(255, 255, 255), 1, wxSOLID);
|
||||
|
||||
if ( edge == wxSASH_LEFT || edge == wxSASH_RIGHT )
|
||||
{
|
||||
int sashPosition = 0;
|
||||
if (edge == wxSASH_LEFT)
|
||||
sashPosition = 0;
|
||||
else
|
||||
sashPosition = w - GetEdgeMargin(edge);
|
||||
|
||||
dc.SetPen(facePen);
|
||||
dc.SetBrush(faceBrush);
|
||||
dc.DrawRectangle(sashPosition, 0, GetEdgeMargin(edge), h);
|
||||
|
||||
if (GetWindowStyleFlag() & wxSW_3D)
|
||||
{
|
||||
if (edge == wxSASH_LEFT)
|
||||
{
|
||||
// Draw a black line on the left to indicate that the
|
||||
// sash is raised
|
||||
dc.SetPen(blackPen);
|
||||
dc.DrawLine(GetEdgeMargin(edge), 0, GetEdgeMargin(edge), h);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw a white line on the right to indicate that the
|
||||
// sash is raised
|
||||
dc.SetPen(whitePen);
|
||||
dc.DrawLine(w - GetEdgeMargin(edge), 0, w - GetEdgeMargin(edge), h);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // top or bottom
|
||||
{
|
||||
int sashPosition = 0;
|
||||
if (edge == wxSASH_TOP)
|
||||
sashPosition = 0;
|
||||
else
|
||||
sashPosition = h - GetEdgeMargin(edge);
|
||||
|
||||
dc.SetPen(facePen);
|
||||
dc.SetBrush(faceBrush);
|
||||
dc.DrawRectangle(0, sashPosition, w, GetEdgeMargin(edge));
|
||||
|
||||
if (GetWindowStyleFlag() & wxSW_3D)
|
||||
{
|
||||
if (edge == wxSASH_BOTTOM)
|
||||
{
|
||||
// Draw a black line on the bottom to indicate that the
|
||||
// sash is raised
|
||||
dc.SetPen(blackPen);
|
||||
dc.DrawLine(0, h - GetEdgeMargin(edge), w, h - GetEdgeMargin(edge));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw a white line on the top to indicate that the
|
||||
// sash is raised
|
||||
dc.SetPen(whitePen);
|
||||
dc.DrawLine(0, GetEdgeMargin(edge), w, GetEdgeMargin(edge));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dc.SetPen(wxNullPen);
|
||||
dc.SetBrush(wxNullBrush);
|
||||
}
|
||||
|
||||
// Draw the sash tracker (for whilst moving the sash)
|
||||
void wxSashWindow::DrawSashTracker(wxSashEdgePosition edge, int x, int y)
|
||||
{
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
|
||||
wxScreenDC screenDC;
|
||||
int x1, y1;
|
||||
int x2, y2;
|
||||
|
||||
if ( edge == wxSASH_LEFT || edge == wxSASH_RIGHT )
|
||||
{
|
||||
x1 = x; y1 = 2;
|
||||
x2 = x; y2 = h-2;
|
||||
|
||||
if ( (edge == wxSASH_LEFT) && (x1 > w) )
|
||||
{
|
||||
x1 = w; x2 = w;
|
||||
}
|
||||
else if ( (edge == wxSASH_RIGHT) && (x1 < 0) )
|
||||
{
|
||||
x1 = 0; x2 = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = 2; y1 = y;
|
||||
x2 = w-2; y2 = y;
|
||||
|
||||
if ( (edge == wxSASH_TOP) && (y1 > h) )
|
||||
{
|
||||
y1 = h;
|
||||
y2 = h;
|
||||
}
|
||||
else if ( (edge == wxSASH_BOTTOM) && (y1 < 0) )
|
||||
{
|
||||
y1 = 0;
|
||||
y2 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ClientToScreen(&x1, &y1);
|
||||
ClientToScreen(&x2, &y2);
|
||||
|
||||
wxPen sashTrackerPen(*wxBLACK, 2, wxSOLID);
|
||||
|
||||
screenDC.SetLogicalFunction(wxXOR);
|
||||
screenDC.SetPen(sashTrackerPen);
|
||||
screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
|
||||
screenDC.DrawLine(x1, y1, x2, y2);
|
||||
|
||||
screenDC.SetLogicalFunction(wxCOPY);
|
||||
|
||||
screenDC.SetPen(wxNullPen);
|
||||
screenDC.SetBrush(wxNullBrush);
|
||||
}
|
||||
|
||||
// Position and size subwindows.
|
||||
// Note that the border size applies to each subwindow, not
|
||||
// including the edges next to the sash.
|
||||
void wxSashWindow::SizeWindows()
|
||||
{
|
||||
int cw, ch;
|
||||
GetClientSize(&cw, &ch);
|
||||
|
||||
if (GetChildren()->Number() > 0)
|
||||
{
|
||||
wxWindow* child = (wxWindow*) (GetChildren()->First()->Data());
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = cw;
|
||||
int height = ch;
|
||||
|
||||
// Top
|
||||
if (m_sashes[0].m_show)
|
||||
{
|
||||
y = m_borderSize;
|
||||
height -= m_borderSize;
|
||||
}
|
||||
y += m_extraBorderSize;
|
||||
|
||||
// Left
|
||||
if (m_sashes[3].m_show)
|
||||
{
|
||||
x = m_borderSize;
|
||||
width -= m_borderSize;
|
||||
}
|
||||
x += m_extraBorderSize;
|
||||
|
||||
// Right
|
||||
if (m_sashes[1].m_show)
|
||||
{
|
||||
width -= m_borderSize;
|
||||
}
|
||||
width -= 2*m_extraBorderSize;
|
||||
|
||||
// Bottom
|
||||
if (m_sashes[2].m_show)
|
||||
{
|
||||
height -= m_borderSize;
|
||||
}
|
||||
height -= 2*m_extraBorderSize;
|
||||
|
||||
child->SetSize(x, y, width, height);
|
||||
}
|
||||
|
||||
wxClientDC dc(this);
|
||||
DrawBorders(dc);
|
||||
DrawSashes(dc);
|
||||
}
|
||||
|
||||
// Initialize colours
|
||||
void wxSashWindow::InitColours()
|
||||
{
|
||||
// Shadow colours
|
||||
#if defined(__WIN95__)
|
||||
m_faceColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
|
||||
m_mediumShadowColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW);
|
||||
m_darkShadowColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW);
|
||||
m_lightShadowColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT);
|
||||
m_hilightColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT);
|
||||
#else
|
||||
m_faceColour = *(wxTheColourDatabase->FindColour("LIGHT GREY"));
|
||||
m_mediumShadowColour = *(wxTheColourDatabase->FindColour("GREY", 1, wxSOLID));
|
||||
m_darkShadowColour = *(wxTheColourDatabase->FindColour("BLACK"));
|
||||
m_lightShadowColour = *(wxTheColourDatabase->FindColour("LIGHT GREY"));
|
||||
m_hilightColour = *(wxTheColourDatabase->FindColour("WHITE"));
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxSashWindow::SetSashVisible(wxSashEdgePosition edge, bool sash)
|
||||
{
|
||||
m_sashes[edge].m_show = sash;
|
||||
if (sash)
|
||||
m_sashes[edge].m_margin = m_borderSize;
|
||||
else
|
||||
m_sashes[edge].m_margin = 0;
|
||||
}
|
||||
|
@@ -61,10 +61,12 @@ GENERICOBJS= \
|
||||
$(GENDIR)\fontdlgg.obj \
|
||||
$(GENDIR)\gridg.obj \
|
||||
$(GENDIR)\helpxlp.obj \
|
||||
$(GENDIR)\laywin.obj \
|
||||
$(GENDIR)\msgdlgg.obj \
|
||||
$(GENDIR)\panelg.obj \
|
||||
$(GENDIR)\printps.obj \
|
||||
$(GENDIR)\prntdlgg.obj \
|
||||
$(GENDIR)\sashwin.obj \
|
||||
$(GENDIR)\scrolwin.obj \
|
||||
$(GENDIR)\splitter.obj \
|
||||
$(GENDIR)\statusbr.obj \
|
||||
@@ -1074,6 +1076,11 @@ $(GENDIR)/helpxlp.obj: $*.$(SRCSUFF)
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||
<<
|
||||
|
||||
$(GENDIR)/laywin.obj: $*.$(SRCSUFF)
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||
<<
|
||||
|
||||
$(GENDIR)/msgdlgg.obj: $*.$(SRCSUFF)
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||
@@ -1094,6 +1101,11 @@ $(GENDIR)/prntdlgg.obj: $*.$(SRCSUFF)
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||
<<
|
||||
|
||||
$(GENDIR)/sashwin.obj: $*.$(SRCSUFF)
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||
<<
|
||||
|
||||
$(GENDIR)/scrolwin.obj: $*.$(SRCSUFF)
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
|
||||
|
Reference in New Issue
Block a user