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:
51
samples/sashtest/makefile.nt
Normal file
51
samples/sashtest/makefile.nt
Normal file
@@ -0,0 +1,51 @@
|
||||
#
|
||||
# File: makefile.nt
|
||||
# Author: Julian Smart
|
||||
# Created: 1993
|
||||
# Updated:
|
||||
# Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile : Builds sashtest example (MS VC++).
|
||||
# Use FINAL=1 argument to nmake to build final version with no debugging
|
||||
# info
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
WXUSINGDLL=0
|
||||
|
||||
!include $(WXDIR)\src\ntwxwin.mak
|
||||
|
||||
PROGRAM=sashtest
|
||||
PROGOBJECTS = $(PROGRAM).obj
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
$(PROGRAM): $(PROGRAM).exe
|
||||
|
||||
$(PROGRAM).exe: $(DUMMYOBJ) $(WXLIB) $(PROGOBJECTS) $(PROGRAM).res
|
||||
$(link) @<<
|
||||
-out:$(PROGRAM).exe
|
||||
$(LINKFLAGS)
|
||||
$(DUMMYOBJ) $(PROGOBJECTS) $(PROGRAM).res
|
||||
$(LIBS)
|
||||
<<
|
||||
|
||||
$(PROGRAM).obj: $(PROGRAM).$(SRCSUFF) $(DUMMYOBJ)
|
||||
$(cc) @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
$(PROGRAM).res : $(PROGRAM).rc $(WXDIR)\include\wx\msw\wx.rc
|
||||
$(rc) -r /i$(WXDIR)\include -fo$@ $(PROGRAM).rc
|
||||
|
||||
|
||||
clean:
|
||||
-erase *.obj
|
||||
-erase *.exe
|
||||
-erase *.res
|
||||
-erase *.map
|
||||
-erase *.sbr
|
||||
-erase *.pdb
|
||||
|
375
samples/sashtest/sashtest.cpp
Normal file
375
samples/sashtest/sashtest.cpp
Normal file
@@ -0,0 +1,375 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sashtest.cpp
|
||||
// Purpose: Layout/sash sample
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 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/toolbar.h>
|
||||
#include <wx/laywin.h>
|
||||
|
||||
#include "sashtest.h"
|
||||
|
||||
MyFrame *frame = NULL;
|
||||
wxList my_children;
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
// For drawing lines in a canvas
|
||||
long xpos = -1;
|
||||
long ypos = -1;
|
||||
|
||||
int winNumber = 1;
|
||||
|
||||
// Initialise this in OnInit, not statically
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
// Create the main frame window
|
||||
|
||||
frame = new MyFrame(NULL, -1, "Sash Demo", wxPoint(0, 0), wxSize(500, 400),
|
||||
wxDEFAULT_FRAME | wxHSCROLL | wxVSCROLL);
|
||||
|
||||
// Give it an icon (this is ignored in MDI mode: uses resources)
|
||||
#ifdef __WXMSW__
|
||||
frame->SetIcon(wxIcon("sashtest_icn"));
|
||||
#endif
|
||||
#ifdef __X__
|
||||
frame->SetIcon(wxIcon("sashtest.xbm"));
|
||||
#endif
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(SASHTEST_NEW_WINDOW, "&New window");
|
||||
file_menu->Append(SASHTEST_TOGGLE_WINDOW, "&Toggle window");
|
||||
file_menu->Append(SASHTEST_QUIT, "&Exit");
|
||||
|
||||
wxMenu *help_menu = new wxMenu;
|
||||
help_menu->Append(SASHTEST_ABOUT, "&About");
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, "&File");
|
||||
menu_bar->Append(help_menu, "&Help");
|
||||
|
||||
// Associate the menu bar with the frame
|
||||
frame->SetMenuBar(menu_bar);
|
||||
|
||||
frame->CreateStatusBar();
|
||||
|
||||
frame->Show(TRUE);
|
||||
|
||||
SetTopWindow(frame);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
|
||||
EVT_MENU(SASHTEST_ABOUT, MyFrame::OnAbout)
|
||||
EVT_MENU(SASHTEST_NEW_WINDOW, MyFrame::OnNewWindow)
|
||||
EVT_SIZE(MyFrame::OnSize)
|
||||
EVT_MENU(SASHTEST_QUIT, MyFrame::OnQuit)
|
||||
EVT_MENU(SASHTEST_TOGGLE_WINDOW, MyFrame::OnToggleWindow)
|
||||
EVT_SASH_DRAGGED_RANGE(ID_WINDOW_TOP, ID_WINDOW_BOTTOM, MyFrame::OnSashDrag)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
// Define my frame constructor
|
||||
MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
|
||||
const long style):
|
||||
wxMDIParentFrame(parent, id, title, pos, size, style)
|
||||
{
|
||||
// Create some dummy layout windows
|
||||
|
||||
// A window like a toolbar
|
||||
wxSashLayoutWindow* win = new wxSashLayoutWindow(this, ID_WINDOW_TOP, wxDefaultPosition, wxSize(200, 30), wxNO_BORDER|wxSW_3D);
|
||||
win->SetDefaultSize(wxSize(1000, 30));
|
||||
win->SetOrientation(wxLAYOUT_HORIZONTAL);
|
||||
win->SetAlignment(wxLAYOUT_TOP);
|
||||
win->SetBackgroundColour(wxColour(255, 0, 0));
|
||||
win->SetSashVisible(wxSASH_BOTTOM, TRUE);
|
||||
|
||||
m_topWindow = win;
|
||||
|
||||
// A window like a statusbar
|
||||
win = new wxSashLayoutWindow(this, ID_WINDOW_BOTTOM, wxDefaultPosition, wxSize(200, 30), wxNO_BORDER|wxSW_3D);
|
||||
win->SetDefaultSize(wxSize(1000, 30));
|
||||
win->SetOrientation(wxLAYOUT_HORIZONTAL);
|
||||
win->SetAlignment(wxLAYOUT_BOTTOM);
|
||||
win->SetBackgroundColour(wxColour(0, 0, 255));
|
||||
win->SetSashVisible(wxSASH_TOP, TRUE);
|
||||
|
||||
m_bottomWindow = win;
|
||||
|
||||
// A window to the left of the client window
|
||||
win = new wxSashLayoutWindow(this, ID_WINDOW_LEFT1, wxDefaultPosition, wxSize(200, 30), wxNO_BORDER|wxSW_3D);
|
||||
win->SetDefaultSize(wxSize(120, 1000));
|
||||
win->SetOrientation(wxLAYOUT_VERTICAL);
|
||||
win->SetAlignment(wxLAYOUT_LEFT);
|
||||
win->SetBackgroundColour(wxColour(0, 255, 0));
|
||||
win->SetSashVisible(wxSASH_RIGHT, TRUE);
|
||||
win->SetExtraBorderSize(10);
|
||||
|
||||
wxTextCtrl* textWindow = new wxTextCtrl(win, -1, "", wxDefaultPosition, wxDefaultSize,
|
||||
wxTE_MULTILINE|wxSUNKEN_BORDER);
|
||||
// wxTE_MULTILINE|wxNO_BORDER);
|
||||
textWindow->SetValue("A help window");
|
||||
|
||||
m_leftWindow1 = win;
|
||||
|
||||
// Another window to the left of the client window
|
||||
win = new wxSashLayoutWindow(this, ID_WINDOW_LEFT2, wxDefaultPosition, wxSize(200, 30), wxNO_BORDER|wxSW_3D);
|
||||
win->SetDefaultSize(wxSize(120, 1000));
|
||||
win->SetOrientation(wxLAYOUT_VERTICAL);
|
||||
win->SetAlignment(wxLAYOUT_LEFT);
|
||||
win->SetBackgroundColour(wxColour(0, 255, 255));
|
||||
win->SetSashVisible(wxSASH_RIGHT, TRUE);
|
||||
|
||||
m_leftWindow2 = win;
|
||||
}
|
||||
|
||||
void MyFrame::OnQuit(wxCommandEvent& event)
|
||||
{
|
||||
Close(TRUE);
|
||||
}
|
||||
|
||||
void MyFrame::OnAbout(wxCommandEvent& event)
|
||||
{
|
||||
(void)wxMessageBox("wxWindows 2.0 Sash Demo\nAuthor: Julian Smart (c) 1998", "About Sash Demo");
|
||||
}
|
||||
|
||||
void MyFrame::OnToggleWindow(wxCommandEvent& event)
|
||||
{
|
||||
if (m_leftWindow1->IsShown())
|
||||
{
|
||||
m_leftWindow1->Show(FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_leftWindow1->Show(TRUE);
|
||||
}
|
||||
wxLayoutAlgorithm layout;
|
||||
layout.LayoutMDIFrame(this);
|
||||
}
|
||||
|
||||
void MyFrame::OnSashDrag(wxSashEvent& event)
|
||||
{
|
||||
if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
|
||||
return;
|
||||
|
||||
switch (event.GetId())
|
||||
{
|
||||
case ID_WINDOW_TOP:
|
||||
{
|
||||
m_topWindow->SetDefaultSize(wxSize(1000, event.GetDragRect().height));
|
||||
break;
|
||||
}
|
||||
case ID_WINDOW_LEFT1:
|
||||
{
|
||||
m_leftWindow1->SetDefaultSize(wxSize(event.GetDragRect().width, 1000));
|
||||
break;
|
||||
}
|
||||
case ID_WINDOW_LEFT2:
|
||||
{
|
||||
m_leftWindow2->SetDefaultSize(wxSize(event.GetDragRect().width, 1000));
|
||||
break;
|
||||
}
|
||||
case ID_WINDOW_BOTTOM:
|
||||
{
|
||||
m_bottomWindow->SetDefaultSize(wxSize(1000, event.GetDragRect().height));
|
||||
break;
|
||||
}
|
||||
}
|
||||
wxLayoutAlgorithm layout;
|
||||
layout.LayoutMDIFrame(this);
|
||||
|
||||
// Leaves bits of itself behind sometimes
|
||||
GetClientWindow()->Refresh();
|
||||
}
|
||||
|
||||
void MyFrame::OnNewWindow(wxCommandEvent& event)
|
||||
{
|
||||
// Make another frame, containing a canvas
|
||||
MyChild *subframe = new MyChild(frame, "Canvas Frame", wxPoint(10, 10), wxSize(300, 300),
|
||||
wxDEFAULT_FRAME);
|
||||
|
||||
char titleBuf[100];
|
||||
sprintf(titleBuf, "Canvas Frame %d", winNumber);
|
||||
subframe->SetTitle(titleBuf);
|
||||
winNumber ++;
|
||||
|
||||
// Give it an icon (this is ignored in MDI mode: uses resources)
|
||||
#ifdef __WXMSW__
|
||||
subframe->SetIcon(wxIcon("sashtest_icn"));
|
||||
#endif
|
||||
|
||||
// Give it a status line
|
||||
subframe->CreateStatusBar();
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(SASHTEST_NEW_WINDOW, "&New window");
|
||||
file_menu->Append(SASHTEST_CHILD_QUIT, "&Close child");
|
||||
file_menu->Append(SASHTEST_QUIT, "&Exit");
|
||||
|
||||
wxMenu *option_menu = new wxMenu;
|
||||
|
||||
// Dummy option
|
||||
option_menu->Append(SASHTEST_REFRESH, "&Refresh picture");
|
||||
|
||||
wxMenu *help_menu = new wxMenu;
|
||||
help_menu->Append(SASHTEST_ABOUT, "&About");
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, "&File");
|
||||
menu_bar->Append(option_menu, "&Options");
|
||||
menu_bar->Append(help_menu, "&Help");
|
||||
|
||||
// Associate the menu bar with the frame
|
||||
subframe->SetMenuBar(menu_bar);
|
||||
|
||||
int width, height;
|
||||
subframe->GetClientSize(&width, &height);
|
||||
MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height));
|
||||
canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
|
||||
subframe->canvas = canvas;
|
||||
|
||||
// Give it scrollbars
|
||||
canvas->SetScrollbars(20, 20, 50, 50);
|
||||
|
||||
subframe->Show(TRUE);
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||
EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// Define a constructor for my canvas
|
||||
MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size):
|
||||
wxScrolledWindow(parent, -1, pos, size, wxSUNKEN_BORDER)
|
||||
{
|
||||
}
|
||||
|
||||
// Define the repainting behaviour
|
||||
void MyCanvas::OnDraw(wxDC& dc)
|
||||
{
|
||||
dc.SetFont(*wxSWISS_FONT);
|
||||
dc.SetPen(*wxGREEN_PEN);
|
||||
dc.DrawLine(0, 0, 200, 200);
|
||||
dc.DrawLine(200, 0, 0, 200);
|
||||
|
||||
dc.SetBrush(*wxCYAN_BRUSH);
|
||||
dc.SetPen(*wxRED_PEN);
|
||||
dc.DrawRectangle(100, 100, 100, 50);
|
||||
dc.DrawRoundedRectangle(150, 150, 100, 50, 20);
|
||||
|
||||
dc.DrawEllipse(250, 250, 100, 50);
|
||||
dc.DrawSpline(50, 200, 50, 100, 200, 10);
|
||||
dc.DrawLine(50, 230, 200, 230);
|
||||
dc.DrawText("This is a test string", 50, 230);
|
||||
|
||||
wxPoint points[3];
|
||||
points[0].x = 200; points[0].y = 300;
|
||||
points[1].x = 100; points[1].y = 400;
|
||||
points[2].x = 300; points[2].y = 400;
|
||||
|
||||
dc.DrawPolygon(3, points);
|
||||
}
|
||||
|
||||
// This implements a tiny doodling program! Drag the mouse using
|
||||
// the left button.
|
||||
void MyCanvas::OnEvent(wxMouseEvent& event)
|
||||
{
|
||||
wxClientDC dc(this);
|
||||
PrepareDC(dc);
|
||||
|
||||
wxPoint pt(event.GetLogicalPosition(dc));
|
||||
|
||||
if (xpos > -1 && ypos > -1 && event.Dragging())
|
||||
{
|
||||
dc.SetPen(*wxBLACK_PEN);
|
||||
dc.DrawLine(xpos, ypos, pt.x, pt.y);
|
||||
}
|
||||
xpos = pt.x;
|
||||
ypos = pt.y;
|
||||
}
|
||||
|
||||
// Define the behaviour for the frame closing
|
||||
// - must delete all frames except for the main one.
|
||||
bool MyFrame::OnClose(void)
|
||||
{
|
||||
// Must delete children
|
||||
wxNode *node = my_children.First();
|
||||
while (node)
|
||||
{
|
||||
MyChild *child = (MyChild *)node->Data();
|
||||
wxNode *next = node->Next();
|
||||
child->OnClose();
|
||||
delete child;
|
||||
node = next;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void MyFrame::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
wxLayoutAlgorithm layout;
|
||||
layout.LayoutMDIFrame(this);
|
||||
}
|
||||
|
||||
// Note that SASHTEST_NEW_WINDOW and SASHTEST_ABOUT commands get passed
|
||||
// to the parent window for processing, so no need to
|
||||
// duplicate event handlers here.
|
||||
|
||||
BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
|
||||
EVT_MENU(SASHTEST_CHILD_QUIT, MyChild::OnQuit)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size,
|
||||
const long style):
|
||||
wxMDIChildFrame(parent, -1, title, pos, size, style)
|
||||
{
|
||||
canvas = NULL;
|
||||
my_children.Append(this);
|
||||
}
|
||||
|
||||
MyChild::~MyChild(void)
|
||||
{
|
||||
my_children.DeleteObject(this);
|
||||
}
|
||||
|
||||
void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
Close(TRUE);
|
||||
}
|
||||
|
||||
void MyChild::OnActivate(wxActivateEvent& event)
|
||||
{
|
||||
if (event.GetActive() && canvas)
|
||||
canvas->SetFocus();
|
||||
}
|
||||
|
||||
bool MyChild::OnClose(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
79
samples/sashtest/sashtest.h
Normal file
79
samples/sashtest/sashtest.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sashtest.h
|
||||
// Purpose: Layout window/sash sample
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <wx/toolbar.h>
|
||||
|
||||
// Define a new application
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit(void);
|
||||
};
|
||||
|
||||
class MyCanvas: public wxScrolledWindow
|
||||
{
|
||||
public:
|
||||
MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size);
|
||||
virtual void OnDraw(wxDC& dc);
|
||||
void OnEvent(wxMouseEvent& event);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
// Define a new frame
|
||||
class MyFrame: public wxMDIParentFrame
|
||||
{
|
||||
public:
|
||||
|
||||
MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
|
||||
|
||||
bool OnClose(void);
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnNewWindow(wxCommandEvent& event);
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnToggleWindow(wxCommandEvent& event);
|
||||
void OnSashDrag(wxSashEvent& event);
|
||||
|
||||
protected:
|
||||
wxSashLayoutWindow* m_topWindow;
|
||||
wxSashLayoutWindow* m_leftWindow1;
|
||||
wxSashLayoutWindow* m_leftWindow2;
|
||||
wxSashLayoutWindow* m_bottomWindow;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class MyChild: public wxMDIChildFrame
|
||||
{
|
||||
public:
|
||||
MyCanvas *canvas;
|
||||
MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
|
||||
~MyChild(void);
|
||||
bool OnClose(void);
|
||||
void OnActivate(wxActivateEvent& event);
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#define SASHTEST_QUIT 1
|
||||
#define SASHTEST_NEW_WINDOW 2
|
||||
#define SASHTEST_REFRESH 3
|
||||
#define SASHTEST_CHILD_QUIT 4
|
||||
#define SASHTEST_ABOUT 5
|
||||
#define SASHTEST_TOGGLE_WINDOW 6
|
||||
|
||||
#define ID_WINDOW_TOP 100
|
||||
#define ID_WINDOW_LEFT1 101
|
||||
#define ID_WINDOW_LEFT2 102
|
||||
#define ID_WINDOW_BOTTOM 103
|
||||
|
BIN
samples/sashtest/sashtest.ico
Normal file
BIN
samples/sashtest/sashtest.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
9
samples/sashtest/sashtest.rc
Normal file
9
samples/sashtest/sashtest.rc
Normal file
@@ -0,0 +1,9 @@
|
||||
aaaa ICON "sashtest.ico"
|
||||
|
||||
wxSTD_MDIPARENTFRAME ICON "sashtest.ico"
|
||||
wxSTD_MDICHILDFRAME ICON "sashtest.ico"
|
||||
|
||||
sashtest_icn ICON "sashtest.ico"
|
||||
|
||||
#include "wx/msw/wx.rc"
|
||||
|
Reference in New Issue
Block a user