*** empty log message ***

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-05-21 15:02:02 +00:00
parent aad5220b82
commit 10b959e372
18 changed files with 3723 additions and 45 deletions

View File

@@ -12,14 +12,16 @@
#ifndef __APPH_BASE__ #ifndef __APPH_BASE__
#define __APPH_BASE__ #define __APPH_BASE__
/* #ifndef __GTK__
class WXDLLEXPORT wxApp; class WXDLLEXPORT wxApp;
typedef wxApp* (*wxAppInitializerFunction) (void); typedef wxApp* (*wxAppInitializerFunction) (void);
*/ #endif
#include "wx/object.h" #include "wx/object.h"
#ifdef __GTK
typedef wxObject* (*wxAppInitializerFunction) (void); // returning wxApp* won't work with gcc typedef wxObject* (*wxAppInitializerFunction) (void); // returning wxApp* won't work with gcc
#endif
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
#include "wx/msw/app.h" #include "wx/msw/app.h"

View File

@@ -531,6 +531,12 @@ typedef void (*wxFunction) (wxObject&, wxEvent&);
#define wxTAB_FIXEDWIDTH 0x0008 #define wxTAB_FIXEDWIDTH 0x0008
#define wxTAB_OWNERDRAW 0x0010 #define wxTAB_OWNERDRAW 0x0010
// Sorry, I changed my mind about these names...
#define wxTC_MULTILINE 0x0000
#define wxTC_RIGHTJUSTIFY 0x0004
#define wxTC_FIXEDWIDTH 0x0008
#define wxTC_OWNERDRAW 0x0010
/* /*
* wxStatusBar95 flags * wxStatusBar95 flags
*/ */

129
include/wx/expr.h Normal file
View File

@@ -0,0 +1,129 @@
/////////////////////////////////////////////////////////////////////////////
// Name: expr.h
// Purpose: C helper defines and functions for wxExpr class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __EXPRH__
#define __EXPRH__
#include <math.h>
#include <stdlib.h>
#ifdef ____HPUX__
#define alloca malloc
#endif
/* Rename all YACC/LEX stuff or we'll conflict with other
* applications
*/
#define yyback PROIO_yyback
#define yylook PROIO_yylook
#define yywrap PROIO_yywrap
#define yyoutput PROIO_yyoutput
#define yylex PROIO_yylex
#define yyerror PROIO_yyerror
#define input PROIO_input
#define unput PROIO_unput
#define yyleng PROIO_yyleng
#define yytext PROIO_yytext
#define yymorfg PROIO_yymorfg
#define yylineno PROIO_yylineno
#define yytchar PROIO_yytchar
#define yyin PROIO_yyin
#define yyout PROIO_yyout
#define yysvf PROIO_yysvf
#define yyestate PROIO_yyestate
#define yysvec PROIO_yysvec
#define yybgin PROIO_yybgin
#define yyprevious PROIO_yyprevious
#define yylhs PROIO_yylhs
#define yylen PROIO_yylen
#define yydefred PROIO_yydefred
#define yydgoto PROIO_yydgoto
#define yysindex PROIO_yysindex
#define yyrindex PROIO_yyrindex
#define yygindex PROIO_yygindex
#define yytable PROIO_yytable
#define yycheck PROIO_yycheck
#define yyname PROIO_yyname
#define yyrule PROIO_yyrule
#define yydebug PROIO_yydebug
#define yynerrs PROIO_yynerrs
#define yyerrflag PROIO_yyerrflag
#define yychar PROIO_yychar
#define yyvsp PROIO_yyvsp
#define yyssp PROIO_yyssp
#define yyval PROIO_yyval
#define yylval PROIO_yylval
#define yyss PROIO_yyss
#define yyvs PROIO_yyvs
#define yyparse PROIO_yyparse
/* +++steve162e: more defines necessary */
#define yy_init_buffer PROIO_yy_init_buffer
#define yy_create_buffer PROIO_yy_create_buffer
#define yy_load_buffer_state PROIO_yy_load_buffer_state
#define yyrestart PROIO_yyrestart
#define yy_switch_to_buffer PROIO_yy_switch_to_buffer
#define yy_delete_buffer PROIO_yy_delete_buffer
/* ---steve162e */
/* WG 1/96: still more for flex 2.5 */
#define yy_scan_buffer PROIO_scan_buffer
#define yy_scan_string PROIO_scan_string
#define yy_scan_bytes PROIO_scan_bytes
#define yy_flex_debug PROIO_flex_debug
#define yy_flush_buffer PROIO_flush_buffer
#define yyleng PROIO_yyleng
#define yytext PROIO_yytext
#ifdef __cplusplus
extern "C" {
char *proio_cons(char *, char *);
char * make_integer(char *);
char * make_word(char *);
char * make_string(char *);
char * make_real(char *, char *);
char * make_exp(char *, char *);
char * make_exp2(char *, char *, char*);
void add_expr(char *);
void process_command(char *);
void syntax_error(char *);
}
#else
#if __BORLANDC__
char *proio_cons(char *, char *);
char * make_integer(char *);
char * make_word(char *);
char * make_string(char *);
char * make_real(char *, char *);
char * make_exp(char *, char *);
char * make_exp2(char *, char *, char*);
void add_expr(char *);
void process_command(char *);
void syntax_error(char *);
#else
char *proio_cons();
char * make_integer();
char * make_word();
char * make_string();
char * make_real();
char * make_exp();
char * make_exp2();
void add_expr();
void process_command();
void syntax_error();
#endif
#endif
#endif
// __EXPRH__

View File

@@ -62,17 +62,17 @@ class WXDLLEXPORT wxPostScriptDC: public wxDC
void DrawRoundedRectangle(long x, long y, long width, long height, double radius = 20); void DrawRoundedRectangle(long x, long y, long width, long height, double radius = 20);
void DrawEllipse(long x, long y, long width, long height); void DrawEllipse(long x, long y, long width, long height);
/* // RR: I define these in wxDC, after all they all do the same everywhere
#ifdef __WINDOWS__
// Splines // Splines
// 3-point spline // 3-point spline
void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3); void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3);
// Any number of control points - a list of pointers to wxPoints // Any number of control points - a list of pointers to wxPoints
void DrawSpline(wxList *points); void DrawSpline(wxList *points);
void DrawSpline(int n, wxPoint points[]); void DrawSpline(int n, wxPoint points[]);
#endif
I define these in wxDC, after all they all do the same everywhere
*/
void DrawOpenSpline(wxList *points); void DrawOpenSpline(wxList *points);
void DrawIcon(const wxIcon& icon, long x, long y); void DrawIcon(const wxIcon& icon, long x, long y);

13
include/wx/tbar95.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __TBAR95H_BASE__
#define __TBAR95H_BASE__
#if defined(__WINDOWS__)
#include "wx/msw/tbar95.h"
#elif defined(__MOTIF__)
#include "wx/xt/tbar95.h"
#elif defined(__GTK__)
#include "wx/gtk/tbar95.h"
#endif
#endif
// __TBAR95H_BASE__

240
include/wx/tbarbase.h Normal file
View File

@@ -0,0 +1,240 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarbase.h
// Purpose: Base class for toolbar classes
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __TBARBASEH__
#define __TBARBASEH__
#ifdef __GNUG__
#pragma interface "tbarbase.h"
#endif
#include "wx/defs.h"
#if USE_TOOLBAR
#include "wx/bitmap.h"
#include "wx/list.h"
#include "wx/control.h"
WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
#define wxTOOL_STYLE_BUTTON 1
#define wxTOOL_STYLE_SEPARATOR 2
class WXDLLEXPORT wxToolBarTool: public wxObject
{
DECLARE_DYNAMIC_CLASS(wxToolBarTool)
public:
wxToolBarTool(const int theIndex = 0, const wxBitmap& bitmap1 = wxNullBitmap, const wxBitmap& bitmap2 = wxNullBitmap,
const bool toggle = FALSE, const long xPos = -1, const long yPos = -1,
const wxString& shortHelpString = "", const wxString& longHelpString = "");
~wxToolBarTool ();
inline void SetSize( const long w, const long h ) { m_width = w; m_height = h; }
inline long GetWidth () const { return m_width; }
inline long GetHeight () const { return m_height; }
public:
int m_toolStyle;
wxObject * m_clientData;
int m_index;
long m_x;
long m_y;
long m_width;
long m_height;
bool m_toggleState;
bool m_isToggle;
bool m_deleteSecondBitmap;
bool m_enabled;
wxBitmap m_bitmap1;
wxBitmap m_bitmap2;
bool m_isMenuCommand;
wxString m_shortHelpString;
wxString m_longHelpString;
};
class WXDLLEXPORT wxToolBarBase : public wxControl
{
DECLARE_DYNAMIC_CLASS(wxToolBarBase)
public:
wxToolBarBase(void);
~wxToolBarBase(void);
// Handle wxToolBar events
// Only allow toggle if returns TRUE. Call when left button up.
virtual bool OnLeftClick(int toolIndex, bool toggleDown);
// Call when right button down.
virtual void OnRightClick(int toolIndex, long x, long y);
// Called when the mouse cursor enters a tool bitmap.
// Argument is -1 if mouse is exiting the toolbar.
virtual void OnMouseEnter(int toolIndex);
// If pushedBitmap is NULL, a reversed version of bitmap is
// created and used as the pushed/toggled image.
// If toggle is TRUE, the button toggles between the two states.
virtual wxToolBarTool *AddTool(const int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
const bool toggle = FALSE, const long xPos = -1, const long yPos = -1, wxObject *clientData = NULL,
const wxString& helpString1 = "", const wxString& helpString2 = "");
virtual void AddSeparator(void);
virtual void ClearTools(void);
virtual void EnableTool(const int toolIndex, const bool enable);
virtual void ToggleTool(const int toolIndex, const bool toggle); // toggle is TRUE if toggled on
virtual void SetToggle(const int toolIndex, const bool toggle); // Set this to be togglable (or not)
virtual wxObject *GetToolClientData(const int index) const;
inline wxList& GetTools(void) const { return (wxList&) m_tools; }
// After the toolbar has initialized, this is the size the tools take up
#if WXWXIN_COMPATIBILITY
inline void GetMaxSize ( long * width, long * height ) const
{ wxSize maxSize(GetMaxSize()); *width = maxSize.x; *height = maxSize.y; }
#endif
virtual wxSize GetMaxSize ( void ) const;
virtual bool GetToolState(const int toolIndex) const;
virtual bool GetToolEnabled(const int toolIndex) const;
virtual wxToolBarTool *FindToolForPosition(const long x, const long y) const;
virtual void SetToolShortHelp(const int toolIndex, const wxString& helpString);
virtual wxString GetToolShortHelp(const int toolIndex) const;
virtual void SetToolLongHelp(const int toolIndex, const wxString& helpString);
virtual wxString GetToolLongHelp(const int toolIndex) const;
virtual void SetMargins(const int x, const int y);
inline void SetMargins(const wxSize& size) { SetMargins(size.x, size.y); }
virtual void SetToolPacking(const int packing);
virtual void SetToolSeparation(const int separation);
inline virtual wxSize GetToolMargins(void) { return wxSize(m_xMargin, m_yMargin); }
inline virtual int GetToolPacking(void) { return m_toolPacking; }
inline virtual int GetToolSeparation(void) { return m_toolSeparation; }
virtual void SetDefaultSize(const wxSize& size) { m_defaultWidth = size.x; m_defaultHeight = size.y; };
virtual wxSize GetDefaultSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); }
// The button size (in some implementations) is bigger than the bitmap size: this returns
// the total button size.
virtual wxSize GetDefaultButtonSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); } ;
// Compatibility
#if WXWIN_COMPATIBILITY
inline void SetDefaultSize(const int w, const int h) { SetDefaultSize(wxSize(w, h)); }
inline long GetDefaultWidth(void) const { return m_defaultWidth; }
inline long GetDefaultHeight(void) const { return m_defaultHeight; }
inline int GetDefaultButtonWidth(void) const { return GetDefaultButtonSize().x; };
inline int GetDefaultButtonHeight(void) const { return GetDefaultButtonSize().y; };
#endif
// Lay the tools out
virtual void Layout(void);
// Add all the buttons: required for Win95.
// TODO: unify API so there's no ambiguity
virtual bool CreateTools(void) { return TRUE; }
void Command(wxCommandEvent& event);
// SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
// inherits from wxControl. This could have been put into wxToolBarSimple,
// but we might want any derived toolbar class to be scrollable.
// Number of pixels per user unit (0 or -1 for no scrollbar)
// Length of virtual canvas in user units
virtual void SetScrollbars(const int horizontal, const int vertical,
const int x_length, const int y_length,
const int x_pos = 0, const int y_pos = 0);
// Physically scroll the window
virtual void Scroll(const int x_pos, const int y_pos);
virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
virtual void EnableScrolling(const bool x_scrolling, const bool y_scrolling);
virtual void AdjustScrollbars(void);
// Prepare the DC by translating it according to the current scroll position
virtual void PrepareDC(wxDC& dc);
int GetScrollPageSize(int orient) const ;
void SetScrollPageSize(int orient, int pageSize);
// Get the view start
virtual void ViewStart(int *x, int *y) const;
// Actual size in pixels when scrolling is taken into account
virtual void GetVirtualSize(int *x, int *y) const;
// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
virtual void DoToolbarUpdates(void);
/*
virtual void CalcScrolledPosition(const int x, const int y, int *xx, int *yy) const ;
virtual void CalcUnscrolledPosition(const int x, const int y, long *xx, long *yy) const ;
*/
void OnScroll(wxScrollEvent& event);
void OnSize(wxSizeEvent& event);
void OnIdle(wxIdleEvent& event);
// Required to force normal cursor-setting behaviour in Windows
#ifdef __WINDOWS__
virtual void MSWOnMouseMove(const int x, const int y, const WXUINT flags);
#endif
protected:
wxList m_tools;
int m_tilingDirection;
int m_rowsOrColumns;
int m_currentRowsOrColumns;
long m_lastX, m_lastY;
long m_maxWidth, m_maxHeight;
int m_currentTool; // Tool where mouse currently is
int m_pressedTool; // Tool where mouse pressed
int m_xMargin;
int m_yMargin;
int m_toolPacking;
int m_toolSeparation;
long m_defaultWidth;
long m_defaultHeight;
public:
////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollEvent& event);
////////////////////////////////////////////////////////////////////////
//// PROTECTED DATA
protected:
int m_xScrollPixelsPerLine;
int m_yScrollPixelsPerLine;
bool m_xScrollingEnabled;
bool m_yScrollingEnabled;
int m_xScrollPosition;
int m_yScrollPosition;
bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
int m_xScrollLines;
int m_yScrollLines;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
public:
DECLARE_EVENT_TABLE()
};
#endif // USE_TOOLBAR
#endif
// __TBARBASEH__

13
include/wx/tbarmsw.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __TBARMSWH_BASE__
#define __TBARMSWH_BASE__
#if defined(__WINDOWS__)
#include "wx/msw/tbarmsw.h"
#elif defined(__MOTIF__)
#include "wx/xt/tbarmsw.h"
#elif defined(__GTK__)
#include "wx/gtk/tbarmsw.h"
#endif
#endif
// __TBARMSWH_BASE__

77
include/wx/tbarsmpl.h Normal file
View File

@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarsmpl.h
// Purpose: wxToolBarSimple class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __TBARSMPLH__
#define __TBARSMPLH__
#ifdef __GNUG__
#pragma interface "tbarsmpl.h"
#endif
#include "wx/defs.h"
#if USE_TOOLBAR
#include "wx/bitmap.h"
#include "wx/list.h"
#include "wx/tbarbase.h"
WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
// XView can't cope properly with panels that behave like canvases
// (e.g. no scrollbars in panels)
class WXDLLEXPORT wxToolBarSimple : public wxToolBarBase
{
DECLARE_DYNAMIC_CLASS(wxToolBarSimple)
public:
wxToolBarSimple(void);
#if WXWIN_COMPATIBILITY > 0
inline wxToolBarSimple(wxWindow *parent, int x, int y, int w, int h,
long style = wxNO_BORDER, int orientation = wxVERTICAL, int RowsOrColumns = 1,
const char *name = wxToolBarNameStr)
{
Create(parent, -1, wxPoint(x, y), wxSize(w, h), style, orientation, RowsOrColumns, name);
}
#endif
inline wxToolBarSimple(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
const long style = wxNO_BORDER, const int orientation = wxVERTICAL,
const int RowsOrColumns = 1, const wxString& name = wxToolBarNameStr)
{
Create(parent, id, pos, size, style, orientation, RowsOrColumns, name);
}
~wxToolBarSimple(void);
bool Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
const long style = wxNO_BORDER, const int orientation = wxVERTICAL, const int RowsOrColumns = 1, const wxString& name = wxToolBarNameStr);
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnMouseEvent(wxMouseEvent& event);
void OnKillFocus(wxFocusEvent& event);
// Handle wxToolBar events
virtual void DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool);
virtual void ToggleTool(const int toolIndex, const bool toggle); // toggle is TRUE if toggled on
virtual void SpringUpButton(const int index);
DECLARE_EVENT_TABLE()
};
#endif // USE_TOOLBAR
#endif
// __TBARSMPLH__

145
include/wx/thread.h Normal file
View File

@@ -0,0 +1,145 @@
/////////////////////////////////////////////////////////////////////////////
// Name: thread.h
// Purpose: Thread API
// Author: Guilhem Lavaux
// Modified by:
// Created: 04/13/98
// RCS-ID: $Id$
// Copyright: (c) Guilhem Lavaux
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __THREADH__
#define __THREADH__
#ifdef __GNUG__
#pragma interface "thread.h"
#endif
#include "wx/object.h"
#include "wx/setup.h"
typedef enum {
MUTEX_NO_ERROR=0,
MUTEX_DEAD_LOCK, // Mutex has been already locked by THE CALLING thread
MUTEX_BUSY // Mutex has been already locked by ONE thread
} wxMutexError;
typedef enum {
THREAD_NO_ERROR=0, // No error
THREAD_NO_RESOURCE, // No resource left to create a new thread
THREAD_RUNNING, // The thread is already running
THREAD_NOT_RUNNING // The thread isn't running
} wxThreadError;
// defines the interval of priority.
#define WXTHREAD_MIN_PRIORITY 0
#define WXTHREAD_DEFAULT_PRIORITY 50
#define WXTHREAD_MAX_PRIORITY 100
// ---------------------------------------------------------------------------
// Mutex handler
class wxMutexInternal;
class WXDLLEXPORT wxMutex {
public:
// constructor & destructor
wxMutex(void);
~wxMutex(void);
// Lock the mutex.
wxMutexError Lock(void);
// Try to lock the mutex: if it can't, returns immediately with an error.
wxMutexError TryLock(void);
// Unlock the mutex.
wxMutexError Unlock(void);
// Returns true if the mutex is locked.
bool IsLocked(void) { return (m_locked > 0); }
protected:
friend class wxCondition;
int m_locked;
wxMutexInternal *p_internal;
};
// ---------------------------------------------------------------------------
// Condition handler.
class wxConditionInternal;
class WXDLLEXPORT wxCondition {
public:
// constructor & destructor
wxCondition(void);
~wxCondition(void);
// Waits undefinitely.
void Wait(wxMutex& mutex);
// Waits until a signal is raised or the timeout is elapsed.
bool Wait(wxMutex& mutex, unsigned long sec, unsigned long nsec);
// Raises a signal: only one "Waiter" is released.
void Signal(void);
// Broadcasts to all "Waiters".
void Broadcast(void);
private:
wxConditionInternal *p_internal;
};
// ---------------------------------------------------------------------------
// Thread management class
class wxThreadInternal;
class WXDLLEXPORT wxThread {
public:
// constructor & destructor.
wxThread(void);
virtual ~wxThread(void);
// Create a new thread, this method should check there is only one thread
// running by object.
wxThreadError Create(void);
// Destroys the thread immediately if the flag DIFFER isn't true.
wxThreadError Destroy(void);
// Switches on the DIFFER flag.
void DeferDestroy(bool on);
// Waits for the termination of the thread.
void *Join(void);
// Sets the priority to "prio". (Warning: The priority can only be set before
// the thread is created)
void SetPriority(int prio);
// Get the current priority.
int GetPriority(void);
// Get the thread ID
unsigned long GetID(void);
// Returns true if the thread is alive.
bool IsAlive(void);
// Returns true if the thread is the main thread (aka the GUI thread).
static bool IsMain(void);
// Called when thread exits.
virtual void OnExit(void);
protected:
// In case, the DIFFER flag is true, enables another thread to kill this one.
void TestDestroy(void);
// Exits from the current thread.
void Exit(void *status = NULL);
private:
// Entry point for the thread.
virtual void *Entry(void) = 0;
private:
friend class wxThreadInternal;
wxThreadInternal *p_internal;
};
// ---------------------------------------------------------------------------
// Global variables
// GUI mutex.
WXDLLEXPORT_DATA(extern wxMutex) wxMainMutex;
#endif

279
include/wx/wxexpr.h Normal file
View File

@@ -0,0 +1,279 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wxexpr.h
// Purpose: Prolog-like file I/O, used by resource system.
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WXEXPRH__
#define __WXEXPRH__
#ifdef __GNUG__
#pragma interface "wxexpr.h"
#endif
#include <stdio.h>
#include "wx/defs.h"
#include "wx/string.h"
#if USE_IOSTREAMH
#include <iostream.h>
#else
#include <iostream>
#endif
#include "wx/list.h"
#include "wx/hash.h"
#include "wx/expr.h"
// Compatibility
#define PrologExpr wxExpr
#define PrologDatabase wxExprDatabase
#define proioErrorHandler wxExprErrorHandler
#define PROIO_ERROR_GENERAL 1
#define PROIO_ERROR_SYNTAX 2
#define PrologNull wxExprNull
#define PrologInteger wxExprInteger
#define PrologReal wxExprReal
#define PrologWord wxExprWord
#define PrologString wxExprString
#define PrologList wxExprList
#define PrologType wxExprType
// Error types
#define WXEXPR_ERROR_GENERAL 1
#define WXEXPR_ERROR_SYNTAX 2
// Error handler function definition. If app returns TRUE,
// carry on processing.
typedef bool (*wxExprErrorHandler) (int errorType, char *msg);
WXDLLEXPORT_DATA(extern wxExprErrorHandler) currentwxExprErrorHandler;
WXDLLEXPORT_DATA(extern "C" FILE*) yyin;
extern "C" int WXDLLEXPORT yyparse(void);
typedef enum {
wxExprNull,
wxExprInteger,
wxExprReal,
wxExprWord,
wxExprString,
wxExprList
} wxExprType;
class WXDLLEXPORT wxExprDatabase;
class WXDLLEXPORT wxExpr
{
public:
wxObject *client_data;
wxExprType type;
union {
long integer;
char *word;
char *string;
float real;
wxExpr *first; // If is a list expr, points to the first node
} value;
wxExpr *next; // If this is a node in a list, points to the next node
wxExpr *last; // If is a list expr, points to the last node
wxExpr(wxExprType the_type, char *word_or_string, bool allocate);
wxExpr(const wxString& functor); // Assume this is a new clause - pass functor
wxExpr(wxExprType the_type, const wxString& word_or_string = "");
wxExpr(long the_integer);
wxExpr(float the_real);
wxExpr(wxList *the_list);
~wxExpr(void);
inline wxExprType Type(void) const { return type; }
inline long IntegerValue(void) const
{
if (type == wxExprInteger)
return value.integer;
else if (type == wxExprReal)
return (long)value.real;
else return 0;
}
inline float RealValue(void) const {
if (type == wxExprReal)
return value.real;
else if (type == wxExprInteger)
return (float)value.integer;
else return (float)0.0;
}
inline wxString WordValue(void) const {
if (type == wxExprWord)
return value.word;
else if (type == wxExprString)
return wxString(value.string);
else return wxString("");
}
inline wxString StringValue(void) const {
if (type == wxExprString)
return wxString(value.string);
else if (type == wxExprWord)
return wxString(value.word);
else return wxString("");
}
// Get nth arg of clause (starting from 1)
wxExpr *Arg(wxExprType type, int arg) const;
// Return nth argument of a list expression (starting from zero)
wxExpr *Nth(int arg) const;
// Returns the number of elements in a list expression
int Number(void) const;
// Make a clone
wxExpr *Copy(void) const;
wxExpr *GetAttributeValueNode(const wxString& word) const; // Use only for a clause or list
wxExpr *AttributeValue(const wxString& word) const; // Use only for a clause
wxString Functor(void) const; // Only for a clause
bool IsFunctor(const wxString& s) const; // Only for a clause
void WriteClause(ostream& stream); // Write this expression as a top-level clause
void WriteExpr(ostream& stream); // Write as any other subexpression
void WriteLispExpr(ostream& stream);
// Append an expression to a list
void Append(wxExpr *expr);
// Insert at beginning of list
void Insert(wxExpr *expr);
// Get first expr in list
inline wxExpr *GetFirst(void) const { return ((type == wxExprList) ? value.first : (wxExpr*)NULL); }
// Get next expr if this is a node in a list
inline wxExpr *GetNext(void) const { return next; }
// Get last expr in list
inline wxExpr *GetLast(void) const { return ((type == wxExprList) ? last : (wxExpr*)NULL); }
// This should really be called SetAttributeValue since any existing
// attribute-value is deleted first.
void AddAttributeValue(const wxString& attribute, long value);
void AddAttributeValue(const wxString& attribute, float value);
void AddAttributeValueWord(const wxString& attribute, const wxString& value);
void AddAttributeValueString(const wxString& attribute, const wxString& value);
void AddAttributeValue(const wxString& attribute, wxList *value);
void AddAttributeValue(const wxString& attribute, wxExpr *value);
void AddAttributeValueStringList(const wxString& attribute, wxList *string_list);
void DeleteAttributeValue(const wxString& attribute);
bool GetAttributeValue(const wxString& att, int& var) const;
bool GetAttributeValue(const wxString& att, long& var) const;
bool GetAttributeValue(const wxString& att, float& var) const;
bool GetAttributeValue(const wxString& att, wxString& var) const; // Word OR string -> string
bool GetAttributeValue(const wxString& att, wxExpr **var) const;
// Compatibility with old PrologIO
inline void AssignAttributeValue(char *att, int *var) const { GetAttributeValue(att, *var); }
inline void AssignAttributeValue(char *att, long *var) const { GetAttributeValue(att, *var); }
inline void AssignAttributeValue(char *att, float *var) const { GetAttributeValue(att, *var); }
inline void AssignAttributeValue(char *att, wxExpr **var) const { GetAttributeValue(att, var); }
void AssignAttributeValue(char *att, char **var) const ; // Word OR string -> string
// Add string items to list if the list attribute exists
bool GetAttributeValueStringList(const wxString& att, wxList *var) const;
// Associate other data with this expression, e.g. when reading in a
// number of linked items - store C++ object pointer with the expression
// so we can index into the wxExpr database and fish out the pointer.
inline void SetClientData(wxObject *data) { client_data = data; }
inline wxObject *GetClientData(void) const { return client_data; }
};
class WXDLLEXPORT wxExprDatabase: public wxList
{
DECLARE_DYNAMIC_CLASS(wxExprDatabase)
private:
wxNode *position; // Where we are in a search
wxHashTable *hash_table;
wxString attribute_to_hash;
public:
int noErrors;
wxExprDatabase(wxExprErrorHandler handler = 0);
// Use hashing on both the functor, and the attribute of
// specified type (wxExprString or wxExprInteger) and name.
// So to find node 45
// (i.e. match the clause node(id=45, ...))
// it usually requires 1 look-up: the keys for functor and attribute
// are added together.
// Obviously if the attribute was missing in a clause, it would
// fail to be found by this method, but could be retrieved by a
// linear search using BeginFind and FindClauseByFunctor,
// or just searching through the list as per usual.
wxExprDatabase(wxExprType type, const wxString& attribute, int size = 500,
wxExprErrorHandler handler = 0);
~wxExprDatabase(void);
void BeginFind(void) ; // Initialise a search
wxExpr *FindClause(long id) ; // Find a term based on an integer id attribute
// e.g. node(id=23, type=rectangle, ....).
// Find on basis of attribute/value pairs, e.g. type=rectangle
// This doesn't use hashing; it's a linear search.
wxExpr *FindClause(const wxString& word, const wxString& value);
wxExpr *FindClause(const wxString& word, long value);
wxExpr *FindClause(const wxString& word, float value);
wxExpr *FindClauseByFunctor(const wxString& functor);
wxExpr *HashFind(const wxString& functor, const wxString& value) const;
wxExpr *HashFind(const wxString& functor, long value) const;
void Append(wxExpr *expr); // Does cleverer things if hashing is on
void ClearDatabase(void);
inline int GetErrorCount() const { return noErrors; }
bool Read(const wxString& filename);
bool ReadFromString(const wxString& buffer);
bool Write(const wxString& fileName);
bool Write(ostream& stream);
void WriteLisp(ostream& stream);
// Compatibility
inline bool ReadProlog(char *filename) { return Read(wxString(filename)); }
inline bool ReadPrologFromString(char *buffer) { return ReadFromString(wxString(buffer)); }
inline void WriteProlog(ostream& stream) { Write(stream); }
};
// Function call-style interface - some more convenience wrappers/unwrappers
// Make a call
wxExpr* WXDLLEXPORT wxExprMakeCall(const wxString& functor ...);
#define wxExprMakeInteger(x) (new wxExpr((long)x))
#define wxExprMakeReal(x) (new wxExpr((float)x))
#define wxExprMakeString(x) (new wxExpr(wxExprString, x))
#define wxExprMakeWord(x) (new wxExpr(wxExprWord, x))
#define wxExprMake(x) (new wxExpr(x))
// Checks functor
bool WXDLLEXPORT wxExprIsFunctor(wxExpr *expr, const wxString& functor);
// Temporary variable for communicating between wxexpr.cpp and YACC/LEX
WXDLLEXPORT_DATA(extern wxExprDatabase*) thewxExprDatabase;
// YACC/LEX can leave memory lying around...
extern "C" WXDLLEXPORT wxExprCleanUp();
#endif

836
src/common/tbarbase.cpp Normal file
View File

@@ -0,0 +1,836 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarbase.cpp
// Purpose: Toolbar base classes
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "tbarbase.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
// For ::UpdateWindow
#ifdef __WINDOWS__
#include <windows.h>
#endif
#if USE_TOOLBAR
#include "wx/tbarbase.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxToolBarBase, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool, wxObject)
BEGIN_EVENT_TABLE(wxToolBarBase, wxControl)
EVT_SCROLL(wxToolBarBase::OnScroll)
EVT_SIZE(wxToolBarBase::OnSize)
EVT_IDLE(wxToolBarBase::OnIdle)
END_EVENT_TABLE()
#endif
// Keep a list of all toolbars created, so you can tell whether a toolbar
// is still valid: a tool may have quit the toolbar.
static wxList gs_ToolBars;
wxToolBarTool::wxToolBarTool(const int theIndex,
const wxBitmap& theBitmap1, const wxBitmap& theBitmap2, const bool toggle,
const long xPos, const long yPos, const wxString& helpS1, const wxString& helpS2)
{
m_toolStyle = wxTOOL_STYLE_BUTTON;
m_clientData = NULL;
m_index = theIndex;
m_isToggle = toggle;
m_toggleState = FALSE;
m_enabled = TRUE;
m_bitmap1 = theBitmap1;
m_bitmap2 = theBitmap2;
m_x = xPos;
m_y = yPos;
m_width = m_height = 0;
m_deleteSecondBitmap = FALSE;
if (m_bitmap1.Ok())
{
m_width = m_bitmap1.GetWidth()+2;
m_height = m_bitmap1.GetHeight()+2;
}
m_shortHelpString = helpS1;
m_longHelpString = helpS2;
}
wxToolBarTool::~wxToolBarTool(void)
{
/*
if (m_deleteSecondBitmap && m_bitmap2)
delete m_bitmap2;
*/
}
// class wxToolBar
wxToolBarBase::wxToolBarBase(void) : m_tools(wxKEY_INTEGER)
{
gs_ToolBars.Append(this);
m_tilingDirection = wxVERTICAL;
m_rowsOrColumns = 0;
m_maxWidth = 0;
m_maxHeight = 0;
m_defaultWidth = 16;
m_defaultHeight = 15;
m_xMargin = 0;
m_yMargin = 0;
m_toolPacking = 1;
m_toolSeparation = 5;
m_currentTool = -1;
m_xScrollPixelsPerLine = 0;
m_yScrollPixelsPerLine = 0;
m_xScrollingEnabled = TRUE;
m_yScrollingEnabled = TRUE;
m_xScrollPosition = 0;
m_yScrollPosition = 0;
m_calcScrolledOffset = TRUE;
m_xScrollLines = 0;
m_yScrollLines = 0;
m_xScrollLinesPerPage = 0;
m_yScrollLinesPerPage = 0;
}
wxToolBarBase::~wxToolBarBase ()
{
gs_ToolBars.DeleteObject(this);
for ( wxNode *node = m_tools.First(); node; node = node->Next() )
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
delete tool;
}
}
// Only allow toggle if returns TRUE
bool wxToolBarBase::OnLeftClick(int toolIndex, bool toggleDown)
{
wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, toolIndex);
event.SetEventObject(this);
event.SetExtraLong((long) toggleDown);
GetEventHandler()->ProcessEvent(event);
return TRUE;
}
// Call when right button down.
void wxToolBarBase::OnRightClick(int toolIndex, long x, long y)
{
wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, toolIndex);
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
// Called when the mouse cursor enters a tool bitmap (no button pressed).
// Argument is -1 if mouse is exiting the toolbar.
void wxToolBarBase::OnMouseEnter ( int toolIndex )
{
wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, toolIndex);
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
// If pushedBitmap is NULL, a reversed version of bitmap is
// created and used as the pushed/toggled image.
// If toggle is TRUE, the button toggles between the two states.
wxToolBarTool *wxToolBarBase::AddTool(const int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap,
const bool toggle, const long xPos, const long yPos, wxObject *clientData,
const wxString& helpString1, const wxString& helpString2)
{
wxToolBarTool *tool = new wxToolBarTool(index, bitmap, pushedBitmap, toggle, xPos, yPos, helpString1, helpString2);
tool->m_clientData = clientData;
if (xPos > -1)
tool->m_x = xPos;
else
tool->m_x = m_xMargin;
if (yPos > -1)
tool->m_y = yPos;
else
tool->m_y = m_yMargin;
// Calculate reasonable max size in case Layout() not called
if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth)
m_maxWidth = (tool->m_x + bitmap.GetWidth() + m_xMargin);
if ((tool->m_y + bitmap.GetHeight() + m_yMargin) > m_maxHeight)
m_maxHeight = (tool->m_y + bitmap.GetHeight() + m_yMargin);
m_tools.Append((long)index, tool);
return tool;
}
void wxToolBarBase::AddSeparator ()
{
wxToolBarTool *tool = new wxToolBarTool;
tool->m_toolStyle = wxTOOL_STYLE_SEPARATOR;
m_tools.Append(tool);
}
void wxToolBarBase::ClearTools(void)
{
m_pressedTool = m_currentTool = -1;
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
wxNode *nextNode = node->Next();
delete tool;
delete node;
node = nextNode;
}
}
void wxToolBarBase::EnableTool(const int index, const bool enable)
{
wxNode *node = m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool)
tool->m_enabled = enable;
}
}
void wxToolBarBase::ToggleTool(const int index, const bool toggle)
{
}
void wxToolBarBase::SetToggle(const int index, const bool value)
{
wxNode *node=m_tools.Find((long)index);
if (node){
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
tool->m_isToggle = value;
}
}
bool wxToolBarBase::GetToolState(const int index) const
{
wxNode *node = m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool)
{
return tool->m_toggleState;
}
else return FALSE;
}
else return FALSE;
}
bool wxToolBarBase::GetToolEnabled(const int index) const
{
wxNode *node = m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool)
{
return tool->m_enabled;
}
else return FALSE;
}
else return FALSE;
}
wxObject *wxToolBarBase::GetToolClientData(const int index) const
{
wxNode *node = m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool)
{
return tool->m_clientData;
}
else return NULL;
}
else return NULL;
}
void wxToolBarBase::SetToolShortHelp(const int index, const wxString& helpString)
{
wxNode *node=m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
tool->m_shortHelpString = helpString;
}
}
wxString wxToolBarBase::GetToolShortHelp(const int index) const
{
wxNode *node=m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
return tool->m_shortHelpString;
}
else
return wxString("");
}
void wxToolBarBase::SetToolLongHelp(const int index, const wxString& helpString)
{
wxNode *node=m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
tool->m_longHelpString = helpString;
}
}
wxString wxToolBarBase::GetToolLongHelp(const int index) const
{
wxNode *node=m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
return tool->m_longHelpString;
}
else
return wxString("");
}
wxToolBarTool *wxToolBarBase::FindToolForPosition(const long x, const long y) const
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if ((x >= tool->m_x) && (y >= tool->m_y) &&
(x <= (tool->m_x + tool->GetWidth())) &&
(y <= (tool->m_y + tool->GetHeight())))
return tool;
node = node->Next();
}
return NULL;
}
wxSize wxToolBarBase::GetMaxSize ( void ) const
{
return wxSize(m_maxWidth, m_maxHeight);
}
// Okay, so we've left the tool we're in ... we must check if
// the tool we're leaving was a 'sprung push button' and if so,
// spring it back to the up state.
//
void wxToolBarBase::SetMargins(const int x, const int y)
{
m_xMargin = x;
m_yMargin = y;
}
void wxToolBarBase::SetToolPacking(const int packing)
{
m_toolPacking = packing;
}
void wxToolBarBase::SetToolSeparation(const int separation)
{
m_toolSeparation = separation;
}
void wxToolBarBase::Command(wxCommandEvent& event)
{
}
void wxToolBarBase::Layout(void)
{
m_currentRowsOrColumns = 0;
m_lastX = m_xMargin;
m_lastY = m_yMargin;
int maxToolWidth = 0;
int maxToolHeight = 0;
m_maxWidth = 0;
m_maxHeight = 0;
// Find the maximum tool width and height
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->GetWidth() > maxToolWidth)
maxToolWidth = (int)tool->GetWidth();
if (tool->GetHeight() > maxToolHeight)
maxToolHeight = (int)tool->GetHeight();
node = node->Next();
}
int separatorSize = m_toolSeparation;
node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_toolStyle == wxTOOL_STYLE_SEPARATOR)
{
if (m_tilingDirection == wxHORIZONTAL)
{
if (m_currentRowsOrColumns >= m_rowsOrColumns)
m_lastY += separatorSize;
else
m_lastX += separatorSize;
}
else
{
if (m_currentRowsOrColumns >= m_rowsOrColumns)
m_lastX += separatorSize;
else
m_lastY += separatorSize;
}
}
else if (tool->m_toolStyle == wxTOOL_STYLE_BUTTON)
{
if (m_tilingDirection == wxHORIZONTAL)
{
if (m_currentRowsOrColumns >= m_rowsOrColumns)
{
m_currentRowsOrColumns = 0;
m_lastX = m_xMargin;
m_lastY += maxToolHeight + m_toolPacking;
}
tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0);
tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0);
m_lastX += maxToolWidth + m_toolPacking;
}
else
{
if (m_currentRowsOrColumns >= m_rowsOrColumns)
{
m_currentRowsOrColumns = 0;
m_lastX += (maxToolWidth + m_toolPacking);
m_lastY = m_yMargin;
}
tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0);
tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0);
m_lastY += maxToolHeight + m_toolPacking;
}
m_currentRowsOrColumns ++;
}
if (m_lastX > m_maxWidth)
m_maxWidth = m_lastX;
if (m_lastY > m_maxHeight)
m_maxHeight = m_lastY;
node = node->Next();
}
if (m_tilingDirection == wxVERTICAL)
m_maxWidth += maxToolWidth;
else
m_maxHeight += maxToolHeight;
m_maxWidth += m_xMargin;
m_maxHeight += m_yMargin;
}
// SCROLLING IMPLEMENTATION
/*
* pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
* noUnitsX/noUnitsY: : no. units per scrollbar
*/
void wxToolBarBase::SetScrollbars (const int pixelsPerUnitX, const int pixelsPerUnitY,
const int noUnitsX, const int noUnitsY,
const int xPos, const int yPos)
{
m_xScrollPixelsPerLine = pixelsPerUnitX;
m_yScrollPixelsPerLine = pixelsPerUnitY;
m_xScrollLines = noUnitsX;
m_yScrollLines = noUnitsY;
int w, h;
GetSize(&w, &h);
// Recalculate scroll bar range and position
if (m_xScrollLines > 0)
{
m_xScrollPosition = xPos;
SetScrollPos (wxHORIZONTAL, m_xScrollPosition, TRUE);
}
else
{
SetScrollbar(wxHORIZONTAL, 0, 0, 0, FALSE);
m_xScrollPosition = 0;
}
if (m_yScrollLines > 0)
{
m_yScrollPosition = yPos;
SetScrollPos (wxVERTICAL, m_yScrollPosition, TRUE);
}
else
{
SetScrollbar(wxVERTICAL, 0, 0, 0, FALSE);
m_yScrollPosition = 0;
}
AdjustScrollbars();
Refresh();
#ifdef __WINDOWS__
::UpdateWindow ((HWND) GetHWND());
#endif
}
void wxToolBarBase::OnScroll(wxScrollEvent& event)
{
int orient = event.GetOrientation();
int nScrollInc = CalcScrollInc(event);
if (nScrollInc == 0)
return;
if (orient == wxHORIZONTAL)
{
int newPos = m_xScrollPosition + nScrollInc;
SetScrollPos(wxHORIZONTAL, newPos, TRUE );
}
else
{
int newPos = m_yScrollPosition + nScrollInc;
SetScrollPos(wxVERTICAL, newPos, TRUE );
}
if (orient == wxHORIZONTAL)
{
if (m_xScrollingEnabled)
ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, NULL);
else
Refresh();
}
else
{
if (m_yScrollingEnabled)
ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, NULL);
else
Refresh();
}
if (orient == wxHORIZONTAL)
{
m_xScrollPosition += nScrollInc;
}
else
{
m_yScrollPosition += nScrollInc;
}
}
int wxToolBarBase::CalcScrollInc(wxScrollEvent& event)
{
int pos = event.GetPosition();
int orient = event.GetOrientation();
int nScrollInc = 0;
switch (event.GetEventType())
{
case wxEVENT_TYPE_SCROLL_TOP:
{
if (orient == wxHORIZONTAL)
nScrollInc = - m_xScrollPosition;
else
nScrollInc = - m_yScrollPosition;
break;
}
case wxEVENT_TYPE_SCROLL_BOTTOM:
{
if (orient == wxHORIZONTAL)
nScrollInc = m_xScrollLines - m_xScrollPosition;
else
nScrollInc = m_yScrollLines - m_yScrollPosition;
break;
}
case wxEVENT_TYPE_SCROLL_LINEUP:
{
nScrollInc = -1;
break;
}
case wxEVENT_TYPE_SCROLL_LINEDOWN:
{
nScrollInc = 1;
break;
}
case wxEVENT_TYPE_SCROLL_PAGEUP:
{
if (orient == wxHORIZONTAL)
nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
else
nScrollInc = -GetScrollPageSize(wxVERTICAL);
break;
}
case wxEVENT_TYPE_SCROLL_PAGEDOWN:
{
if (orient == wxHORIZONTAL)
nScrollInc = GetScrollPageSize(wxHORIZONTAL);
else
nScrollInc = GetScrollPageSize(wxVERTICAL);
break;
}
case wxEVENT_TYPE_SCROLL_THUMBTRACK:
{
if (orient == wxHORIZONTAL)
nScrollInc = pos - m_xScrollPosition;
else
nScrollInc = pos - m_yScrollPosition;
break;
}
default:
{
break;
}
}
if (orient == wxHORIZONTAL)
{
int w, h;
GetClientSize(&w, &h);
int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
int noPositions = (int) ( ((nMaxWidth - w)/(float)m_xScrollPixelsPerLine) + 0.5 );
if (noPositions < 0)
noPositions = 0;
if ( (m_xScrollPosition + nScrollInc) < 0 )
nScrollInc = -m_xScrollPosition; // As -ve as we can go
else if ( (m_xScrollPosition + nScrollInc) > noPositions )
nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
return nScrollInc;
}
else
{
int w, h;
GetClientSize(&w, &h);
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
int noPositions = (int) ( ((nMaxHeight - h)/(float)m_yScrollPixelsPerLine) + 0.5 );
if (noPositions < 0)
noPositions = 0;
if ( (m_yScrollPosition + nScrollInc) < 0 )
nScrollInc = -m_yScrollPosition; // As -ve as we can go
else if ( (m_yScrollPosition + nScrollInc) > noPositions )
nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
return nScrollInc;
}
}
// Adjust the scrollbars - new version.
void wxToolBarBase::AdjustScrollbars(void)
{
int w, h;
GetClientSize(&w, &h);
// Recalculate scroll bar range and position
if (m_xScrollLines > 0)
{
int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
int newRange = (int) ( ((nMaxWidth)/(float)m_xScrollPixelsPerLine) + 0.5 );
if (newRange < 0)
newRange = 0;
m_xScrollPosition = wxMin(newRange, m_xScrollPosition);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1)
noPagePositions = 1;
SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange);
SetScrollPageSize(wxHORIZONTAL, noPagePositions);
}
if (m_yScrollLines > 0)
{
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
int newRange = (int) ( ((nMaxHeight)/(float)m_yScrollPixelsPerLine) + 0.5 );
if (newRange < 0)
newRange = 0;
m_yScrollPosition = wxMin(newRange, m_yScrollPosition);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1)
noPagePositions = 1;
SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange);
SetScrollPageSize(wxVERTICAL, noPagePositions);
}
}
// Default OnSize resets scrollbars, if any
void wxToolBarBase::OnSize(wxSizeEvent& event)
{
#if USE_CONSTRAINTS
if (GetAutoLayout())
Layout();
#endif
AdjustScrollbars();
}
// Prepare the DC by translating it according to the current scroll position
void wxToolBarBase::PrepareDC(wxDC& dc)
{
dc.SetDeviceOrigin(- m_xScrollPosition * m_xScrollPixelsPerLine, - m_yScrollPosition * m_yScrollPixelsPerLine);
}
void wxToolBarBase::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
{
*x_unit = m_xScrollPixelsPerLine;
*y_unit = m_yScrollPixelsPerLine;
}
int wxToolBarBase::GetScrollPageSize(int orient) const
{
if ( orient == wxHORIZONTAL )
return m_xScrollLinesPerPage;
else
return m_yScrollLinesPerPage;
}
void wxToolBarBase::SetScrollPageSize(int orient, int pageSize)
{
if ( orient == wxHORIZONTAL )
m_xScrollLinesPerPage = pageSize;
else
m_yScrollLinesPerPage = pageSize;
}
/*
* Scroll to given position (scroll position, not pixel position)
*/
void wxToolBarBase::Scroll (const int x_pos, const int y_pos)
{
int old_x, old_y;
ViewStart (&old_x, &old_y);
if (((x_pos == -1) || (x_pos == old_x)) && ((y_pos == -1) || (y_pos == old_y)))
return;
if (x_pos > -1)
{
m_xScrollPosition = x_pos;
SetScrollPos (wxHORIZONTAL, x_pos, TRUE);
}
if (y_pos > -1)
{
m_yScrollPosition = y_pos;
SetScrollPos (wxVERTICAL, y_pos, TRUE);
}
Refresh();
#ifdef __WINDOWS__
UpdateWindow ((HWND) GetHWND());
#endif
}
void wxToolBarBase::EnableScrolling (const bool x_scroll, const bool y_scroll)
{
m_xScrollingEnabled = x_scroll;
m_yScrollingEnabled = y_scroll;
}
void wxToolBarBase::GetVirtualSize (int *x, int *y) const
{
*x = m_xScrollPixelsPerLine * m_xScrollLines;
*y = m_yScrollPixelsPerLine * m_yScrollLines;
}
// Where the current view starts from
void wxToolBarBase::ViewStart (int *x, int *y) const
{
*x = m_xScrollPosition;
*y = m_yScrollPosition;
}
/*
void wxToolBarBase::CalcScrolledPosition(const int x, const int y, int *xx, int *yy) const
{
*xx = (m_calcScrolledOffset ? (x - m_xScrollPosition * m_xScrollPixelsPerLine) : x);
*yy = (m_calcScrolledOffset ? (y - m_yScrollPosition * m_yScrollPixelsPerLine) : y);
}
void wxToolBarBase::CalcUnscrolledPosition(const int x, const int y, float *xx, float *yy) const
{
*xx = (float)(m_calcScrolledOffset ? (x + m_xScrollPosition * m_xScrollPixelsPerLine) : x);
*yy = (float)(m_calcScrolledOffset ? (y + m_yScrollPosition * m_yScrollPixelsPerLine) : y);
}
*/
void wxToolBarBase::OnIdle(wxIdleEvent& event)
{
DoToolbarUpdates();
}
// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
void wxToolBarBase::DoToolbarUpdates(void)
{
wxNode* node = GetTools().First();
while (node)
{
wxToolBarTool* tool = (wxToolBarTool* ) node->Data();
wxUpdateUIEvent event(tool->m_index);
event.SetEventObject(this);
if (GetEventHandler()->ProcessEvent(event))
{
if (event.GetSetEnabled())
EnableTool(tool->m_index, event.GetEnabled());
if (event.GetSetChecked())
ToggleTool(tool->m_index, event.GetChecked());
/*
if (event.GetSetText())
// Set tooltip?
*/
}
node = node->Next();
}
}
#ifdef __WINDOWS__
// Circumvent wxControl::MSWOnMouseMove which doesn't set the cursor.
void wxToolBarBase::MSWOnMouseMove(const int x, const int y, const WXUINT flags)
{
wxWindow::MSWOnMouseMove(x, y, flags);
}
#endif
#endif

371
src/common/tbarsmpl.cpp Normal file
View File

@@ -0,0 +1,371 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarsmpl.cpp
// Purpose: wxToolBarSimple
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "tbarsmpl.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx.h"
#endif
#if USE_TOOLBAR
#include "wx/tbarsmpl.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple, wxToolBarBase)
BEGIN_EVENT_TABLE(wxToolBarSimple, wxToolBarBase)
EVT_SIZE(wxToolBarSimple::OnSize)
EVT_PAINT(wxToolBarSimple::OnPaint)
EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus)
EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent)
END_EVENT_TABLE()
#endif
// TODO: eliminate these; use system colours
static wxPen * white_pen = NULL,
* dark_grey_pen = NULL,
* black_pen = NULL,
* thick_black_pen;
wxToolBarSimple::wxToolBarSimple(void)
{
}
bool wxToolBarSimple::Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, const long style,
const int direction, const int RowsOrColumns, const wxString& name )
{
if ( ! wxWindow::Create(parent, id, pos, size, style, name) )
return FALSE;
// Set it to grey (or other 3D face colour)
wxSystemSettings settings;
SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_3DFACE));
SetDefaultBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_3DFACE));
if ( white_pen == 0 )
{
white_pen = new wxPen;
white_pen->SetColour( "WHITE" );
}
if ( dark_grey_pen == 0 )
{
dark_grey_pen = new wxPen;
dark_grey_pen->SetColour( 85,85,85 );
}
if ( black_pen == 0 )
{
black_pen = new wxPen;
black_pen->SetColour( "BLACK" );
}
if ( thick_black_pen == 0 )
{
thick_black_pen = new wxPen("BLACK", 3, wxSOLID);
}
m_tilingDirection = direction;
m_rowsOrColumns = RowsOrColumns;
if ( m_tilingDirection == wxVERTICAL )
{ m_lastX = 3; m_lastY = 7; }
else
{ m_lastX = 7; m_lastY = 3; }
m_maxWidth = m_maxHeight = 0;
m_pressedTool = m_currentTool = -1;
m_xMargin = 0;
m_yMargin = 0;
m_toolPacking = 1;
m_toolSeparation = 5;
return TRUE;
}
wxToolBarSimple::~wxToolBarSimple ()
{
}
void wxToolBarSimple::OnPaint (wxPaintEvent& event)
{
wxPaintDC dc(this);
PrepareDC(dc);
static int count = 0;
// Prevent reentry of OnPaint which would cause wxMemoryDC errors.
if ( count > 0 )
return;
count++;
wxMemoryDC mem_dc;
for ( wxNode *node = m_tools.First(); node; node = node->Next() )
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_toolStyle == wxTOOL_STYLE_BUTTON)
DrawTool(dc, mem_dc, tool);
}
/* Old code which drew a line beneath the toolbar - not generally
* wanted.
int w, h;
GetClientSize( &w, &h );
wxPen * old_pen = dc.GetPen();
dc.SetPen( *white_pen );
dc.DrawLine(0,0,w,0);
dc.SetPen( *black_pen );
dc.DrawLine(0,(h-1),w,(h-1));
dc.SetPen( *old_pen );
*/
count--;
}
void wxToolBarSimple::OnSize ( wxSizeEvent& event )
{
wxToolBarBase::OnSize(event);
}
void wxToolBarSimple::OnKillFocus (wxFocusEvent& event)
{
OnMouseEnter(m_pressedTool = m_currentTool = -1);
}
void wxToolBarSimple::OnMouseEvent ( wxMouseEvent & event )
{
long x, y;
event.Position(&x, &y);
wxToolBarTool *tool = FindToolForPosition(x, y);
if (!tool)
{
if (m_currentTool > -1)
{
if (event.LeftIsDown())
SpringUpButton(m_currentTool);
m_currentTool = -1;
OnMouseEnter(-1);
}
return;
}
if (!event.IsButton())
{
if (tool->m_index != m_currentTool)
{
// If the left button is kept down and moved over buttons,
// press those buttons.
if (event.LeftIsDown() && tool->m_enabled) {
SpringUpButton(m_currentTool);
tool->m_toggleState = !tool->m_toggleState;
wxMemoryDC *dc2 = new wxMemoryDC;
wxClientDC dc(this);
DrawTool(dc, *dc2, tool);
delete dc2;
}
OnMouseEnter(tool->m_index);
m_currentTool = tool->m_index;
}
return;
}
// Left button pressed.
if (event.LeftDown() && tool->m_enabled)
{
tool->m_toggleState = !tool->m_toggleState;
wxMemoryDC *dc2 = new wxMemoryDC;
wxClientDC dc(this);
DrawTool(dc, *dc2, tool);
delete dc2;
}
else if (event.RightDown())
{
OnRightClick(tool->m_index, x, y);
}
// Left Button Released. Only this action confirms selection.
// If the button is enabled and it is not a toggle tool and it is
// in the pressed state, then raise the button and call OnLeftClick.
//
if (event.LeftUp() && tool->m_enabled &&
(tool->m_toggleState || tool->m_isToggle)){
if (!tool->m_isToggle)
tool->m_toggleState = FALSE;
// Pass the OnLeftClick event to tool
if (!OnLeftClick(tool->m_index, tool->m_toggleState) && tool->m_isToggle)
// If it was a toggle, and OnLeftClick says No Toggle allowed,
// then change it back
tool->m_toggleState = !tool->m_toggleState;
wxClientDC dc(this);
wxMemoryDC *dc2 = new wxMemoryDC;
DrawTool(dc, *dc2, tool);
delete dc2;
}
}
void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool)
{
PrepareDC(dc);
wxBitmap *bitmap = tool->m_toggleState ? (& tool->m_bitmap2) : (& tool->m_bitmap1);
if (bitmap && bitmap->Ok())
{
if (bitmap->GetColourMap())
memDC.SetPalette(*bitmap->GetColourMap());
int ax = (int)tool->m_x,
ay = (int)tool->m_y,
bx = (int)(tool->m_x+tool->GetWidth()),
by = (int)(tool->m_y+tool->GetHeight());
memDC.SelectObject(*bitmap);
if (m_windowStyle & wxTB_3DBUTTONS)
{
dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1));
dc.Blit((ax+1), (ay+1), (bx-ax-2), (by-ay-2), &memDC, 0, 0);
wxPen * old_pen = dc.GetPen();
dc.SetPen( *white_pen );
dc.DrawLine(ax,(by-1),ax,ay);
dc.DrawLine(ax,ay,(bx-1),ay);
dc.SetPen( *dark_grey_pen );
dc.DrawLine((bx-1),(ay+1),(bx-1),(by-1));
dc.DrawLine((bx-1),(by-1),(ax+1),(by-1));
dc.SetPen( *black_pen );
dc.DrawLine(bx,ay,bx,by);
dc.DrawLine(bx,by,ax,by);
dc.SetPen( *old_pen );
dc.DestroyClippingRegion();
// Select bitmap out of the DC
}
else
{
dc.Blit(tool->m_x, tool->m_y,
bitmap->GetWidth(), bitmap->GetHeight(),
&memDC, 0, 0);
}
memDC.SelectObject(wxNullBitmap);
memDC.SetPalette(wxNullPalette);
}
// No second bitmap, so draw a thick line around bitmap, or invert if mono
else if (tool->m_toggleState)
{
bool drawBorder = FALSE;
#ifdef __X__ // X doesn't invert properly on colour
drawBorder = wxColourDisplay();
#else // Inversion works fine under Windows
drawBorder = FALSE;
#endif
if (!drawBorder)
{
memDC.SelectObject(tool->m_bitmap1);
dc.Blit(tool->m_x, tool->m_y, tool->GetWidth(), tool->GetHeight(),
&memDC, 0, 0, wxSRC_INVERT);
memDC.SelectObject(wxNullBitmap);
}
else
{
if (m_windowStyle & wxTB_3DBUTTONS)
{
int ax = (int)tool->m_x,
ay = (int)tool->m_y,
bx = (int)(tool->m_x+tool->GetWidth()),
by = (int)(tool->m_y+tool->GetHeight());
memDC.SelectObject(tool->m_bitmap1);
dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1));
dc.Blit((ax+2), (ay+2), (bx-ax-2), (by-ay-2), &memDC, 0, 0);
wxPen * old_pen = dc.GetPen();
dc.SetPen( *black_pen );
dc.DrawLine(ax,(by-1),ax,ay);
dc.DrawLine(ax,ay,(bx-1),ay);
dc.SetPen( *dark_grey_pen );
dc.DrawLine((ax+1),(by-2),(ax+1),(ay+1));
dc.DrawLine((ax+1),(ay+1),(bx-2),(ay+1));
dc.SetPen( *white_pen );
dc.DrawLine(bx,ay,bx,by);
dc.DrawLine(bx,by,ax,by);
dc.SetPen( *old_pen );
dc.DestroyClippingRegion();
memDC.SelectObject(wxNullBitmap);
}
else
{
long x = tool->m_x;
long y = tool->m_y;
long w = tool->m_bitmap1.GetWidth();
long h = tool->m_bitmap1.GetHeight();
memDC.SelectObject(tool->m_bitmap1);
dc.SetClippingRegion(tool->m_x, tool->m_y, w, h);
dc.Blit(tool->m_x, tool->m_y, w, h,
&memDC, 0, 0);
dc.SetPen(*thick_black_pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(x, y, w-1, h-1);
dc.DestroyClippingRegion();
memDC.SelectObject(wxNullBitmap);
}
}
}
}
void wxToolBarSimple::ToggleTool(const int index, const bool toggle)
{
wxNode *node = m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool && tool->m_isToggle)
{
bool oldState = tool->m_toggleState;
tool->m_toggleState = toggle;
if (oldState != toggle)
{
wxMemoryDC memDC;
wxClientDC dc(this);
DrawTool(dc, memDC, tool);
}
}
}
}
// Okay, so we've left the tool we're in ... we must check if
// the tool we're leaving was a 'sprung push button' and if so,
// spring it back to the up state.
//
void wxToolBarSimple::SpringUpButton(const int index)
{
wxNode *node=m_tools.Find((long)index);
if (node) {
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool && !tool->m_isToggle && tool->m_toggleState){
tool->m_toggleState = FALSE;
wxMemoryDC memDC;
wxClientDC dc(this);
DrawTool(dc, memDC, tool);
}
else if (tool && tool->m_isToggle){
tool->m_toggleState = !tool->m_toggleState;
wxMemoryDC memDC;
wxClientDC dc(this);
DrawTool(dc, memDC, tool);
}
}
}
#endif

1240
src/common/wxexpr.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1505,6 +1505,7 @@ void wxDC::GetSizeMM(long *width, long *height) const
*height = h; *height = h;
} }
/*
#if USE_SPLINES #if USE_SPLINES
# if USE_XFIG_SPLINE_CODE # if USE_XFIG_SPLINE_CODE
# include "../common/xfspline.inc" # include "../common/xfspline.inc"
@@ -1512,6 +1513,11 @@ void wxDC::GetSizeMM(long *width, long *height) const
# include "../common/wxspline.inc" # include "../common/wxspline.inc"
# endif # endif
#endif // USE_SPLINES #endif // USE_SPLINES
*/
#if USE_SPLINES
#include "xfspline.inc"
#endif // USE_SPLINES
void wxDC::DrawPolygon(wxList *list, long xoffset, long yoffset,int fillStyle) void wxDC::DrawPolygon(wxList *list, long xoffset, long yoffset,int fillStyle)
{ {

View File

@@ -103,36 +103,3 @@ int wxMessageDialog::ShowModal(void)
return ans; return ans;
} }
/*
* Common dialogs
*
*/
// Pop up a message box
int wxMessageBox(const wxString& message, const wxString& caption, const long style,
wxWindow *parent, const int x, const int y)
{
wxMessageDialog dialog(parent, message, caption, style);
int ans = dialog.ShowModal();
switch ( ans )
{
case wxID_OK:
return wxOK;
break;
case wxID_YES:
return wxYES;
break;
case wxID_NO:
return wxNO;
break;
default:
case wxID_CANCEL:
return wxCANCEL;
break;
}
return ans;
}

View File

@@ -78,10 +78,6 @@ static const char eHOSTNAME[] = "HostName";
static const char eUSERID[] = "UserId"; static const char eUSERID[] = "UserId";
static const char eUSERNAME[] = "UserName"; static const char eUSERNAME[] = "UserName";
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxList)
#endif
// For the following functions we SHOULD fill in support // For the following functions we SHOULD fill in support
// for Windows-NT (which I don't know) as I assume it begin // for Windows-NT (which I don't know) as I assume it begin
// a POSIX Unix (so claims MS) that it has some special // a POSIX Unix (so claims MS) that it has some special

358
src/msw/xfspline.inc Normal file
View File

@@ -0,0 +1,358 @@
/*
* File: xfspline.cc
* Purpose:
* Author: Julian Smart
* Created: 1993
* Updated: August 1994
* RCS_ID: $Id$
* Copyright: (c) 1993, AIAI, University of Edinburgh
*/
// Must be a comment as this file is #include\'d by wb_dc.cc
/* static const char sccsid[] = "@(#)xfspline.cc 1.3 5/9/94"; */
/*
* FIG : Facility for Interactive Generation of figures
* Copyright (c) 1985 by Supoj Sutanthavibul
*/
#if USE_SPLINES
////#define wx_round(a) (int)((a)+.5)
//#define wx_round(a) (a)
class wxSpline: public wxObject
{
public:
int type;
wxList *points;
wxSpline(wxList *list);
void DeletePoints(void);
// Doesn't delete points
~wxSpline(void);
};
void wx_draw_open_spline(wxDC *dc, wxSpline *spline);
#if USE_POSTSCRIPT
void wx_draw_open_spline_ps(wxPostScriptDC *dc, wxSpline *s);
#endif
void wx_quadratic_spline(double a1, double b1, double a2, double b2,
double a3, double b3, double a4, double b4);
void wx_clear_stack(void);
int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
double *y3, double *x4, double *y4);
void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
double x4, double y4);
static bool wx_spline_add_point(double x, double y);
static void wx_spline_draw_point_array(wxDC *dc);
wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3);
void wxDC::DrawSpline(int n, wxPoint points[])
{
wxList list;
int i;
for (i =0; i < n; i++)
list.Append((wxObject*)&points[i]);
DrawSpline((wxList *)&list);
}
void wxDC::DrawSpline(wxList *list)
{
wxSpline spline(list);
wx_draw_open_spline(this, &spline);
}
wxList wx_spline_point_list;
void wx_draw_open_spline(wxDC *dc, wxSpline *spline)
{
wxPoint *p;
double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
double x1, y1, x2, y2;
wxNode *node = spline->points->First();
p = (wxPoint *)node->Data();
x1 = p->x;
y1 = p->y;
node = node->Next();
p = (wxPoint *)node->Data();
x2 = p->x;
y2 = p->y;
cx1 = (double)((x1 + x2) / 2);
cy1 = (double)((y1 + y2) / 2);
cx2 = (double)((cx1 + x2) / 2);
cy2 = (double)((cy1 + y2) / 2);
wx_spline_add_point(x1, y1);
while ((node = node->Next()) != NULL)
{
p = (wxPoint *)node->Data();
x1 = x2;
y1 = y2;
x2 = p->x;
y2 = p->y;
cx4 = (double)(x1 + x2) / 2;
cy4 = (double)(y1 + y2) / 2;
cx3 = (double)(x1 + cx4) / 2;
cy3 = (double)(y1 + cy4) / 2;
wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
cx1 = cx4;
cy1 = cy4;
cx2 = (double)(cx1 + x2) / 2;
cy2 = (double)(cy1 + y2) / 2;
}
wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1));
wx_spline_add_point(x2, y2);
wx_spline_draw_point_array(dc);
}
#if USE_POSTSCRIPT
void wx_draw_open_spline_ps(wxPostScriptDC *dc, wxSpline *s)
{
double a, b, c, d, x1, y1, x2, y2, x3, y3;
wxPoint *p, *q;
if (dc->GetAutoSetting())
dc->SetPen(* dc->GetPen());
wxNode *node = s->points->First();
p = (wxPoint *)node->Data();
x1 = p->x; y1 = p->y;
node = node->Next();
p = (wxPoint *)node->Data();
c = p->x; d = p->y;
x3 = a = (double)(x1 + c) / 2;
y3 = b = (double)(y1 + d) / 2;
*(dc->GetStream()) << "newpath " << x1 << " " << dc->GetYOrigin() - y1 << " moveto " << x3 << " " << dc->GetYOrigin() - y3;
*(dc->GetStream()) << " lineto\n";
dc->CalcBoundingBox((double)x1, (double)(dc->GetYOrigin() - y1));
dc->CalcBoundingBox((double)x3, (double)(dc->GetYOrigin() - y3));
while ((node = node->Next()) != NULL)
{
q = (wxPoint *)node->Data();
x1 = x3; y1 = y3;
x2 = c; y2 = d;
c = q->x; d = q->y;
x3 = (double)(x2 + c) / 2;
y3 = (double)(y2 + d) / 2;
*(dc->GetStream()) << x1 << " " << dc->GetYOrigin() - y1 << " " << x2 << " " << dc->GetYOrigin() - y2 << " ";
*(dc->GetStream()) << x3 << " " << dc->GetYOrigin() - y3 << " DrawSplineSection\n";
dc->CalcBoundingBox((double)x1, (double)(dc->GetYOrigin() - y1));
dc->CalcBoundingBox((double)x3, (double)(dc->GetYOrigin() - y3));
}
/*
* At this point, (x2,y2) and (c,d) are the position of the
* next-to-last and last point respectively, in the point list
*/
*(dc->GetStream()) << c << " " << dc->GetYOrigin() - d << " lineto stroke\n";
}
#endif
/********************* CURVES FOR SPLINES *****************************
The following spline drawing routine is from
"An Algorithm for High-Speed Curve Generation"
by George Merrill Chaikin,
Computer Graphics and Image Processing, 3, Academic Press,
1974, 346-349.
and
"On Chaikin's Algorithm" by R. F. Riesenfeld,
Computer Graphics and Image Processing, 4, Academic Press,
1975, 304-310.
***********************************************************************/
#define half(z1, z2) ((z1+z2)/2.0)
#define THRESHOLD 5
/* iterative version */
void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
double b4)
{
register double xmid, ymid;
double x1, y1, x2, y2, x3, y3, x4, y4;
wx_clear_stack();
wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
xmid = (double)half(x2, x3);
ymid = (double)half(y2, y3);
if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
wx_spline_add_point((double)wx_round(x1), (double)wx_round(y1));
wx_spline_add_point((double)wx_round(xmid), (double)wx_round(ymid));
} else {
wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
(double)half(x3, x4), (double)half(y3, y4), x4, y4);
wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
(double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
}
}
}
/* utilities used by spline drawing routines */
typedef struct wx_spline_stack_struct {
double x1, y1, x2, y2, x3, y3, x4, y4;
}
Stack;
#define SPLINE_STACK_DEPTH 20
static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
static Stack *wx_stack_top;
static int wx_stack_count;
void wx_clear_stack(void)
{
wx_stack_top = wx_spline_stack;
wx_stack_count = 0;
}
void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
wx_stack_top->x1 = x1;
wx_stack_top->y1 = y1;
wx_stack_top->x2 = x2;
wx_stack_top->y2 = y2;
wx_stack_top->x3 = x3;
wx_stack_top->y3 = y3;
wx_stack_top->x4 = x4;
wx_stack_top->y4 = y4;
wx_stack_top++;
wx_stack_count++;
}
int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
double *x3, double *y3, double *x4, double *y4)
{
if (wx_stack_count == 0)
return (0);
wx_stack_top--;
wx_stack_count--;
*x1 = wx_stack_top->x1;
*y1 = wx_stack_top->y1;
*x2 = wx_stack_top->x2;
*y2 = wx_stack_top->y2;
*x3 = wx_stack_top->x3;
*y3 = wx_stack_top->y3;
*x4 = wx_stack_top->x4;
*y4 = wx_stack_top->y4;
return (1);
}
static bool wx_spline_add_point(double x, double y)
{
wxPoint *point = new wxPoint ;
point->x = (int) x;
point->y = (int) y;
wx_spline_point_list.Append((wxObject*)point);
return TRUE;
}
static void wx_spline_draw_point_array(wxDC *dc)
{
dc->DrawLines(&wx_spline_point_list, (double)0.0, (double)0.0);
wxNode *node = wx_spline_point_list.First();
while (node)
{
wxPoint *point = (wxPoint *)node->Data();
delete point;
delete node;
node = wx_spline_point_list.First();
}
}
wxSpline::wxSpline(wxList *list)
{
points = list;
}
wxSpline::~wxSpline(void)
{
}
void wxSpline::DeletePoints(void)
{
for(wxNode *node = points->First(); node; node = points->First())
{
wxPoint *point = (wxPoint *)node->Data();
delete point;
delete node;
}
delete points;
}
#if USE_POSTSCRIPT
// Make a 3-point spline
void wxPostScriptDC::DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3)
{
wxList *point_list = new wxList;
wxPoint *point1 = new wxPoint;
point1->x = x1; point1->y = y1;
point_list->Append((wxObject*)point1);
wxPoint *point2 = new wxPoint;
point2->x = x2; point2->y = y2;
point_list->Append((wxObject*)point2);
wxPoint *point3 = new wxPoint;
point3->x = x3; point3->y = y3;
point_list->Append((wxObject*)point3);
wxSpline spline(point_list);
wx_draw_open_spline_ps(this, &spline);
spline.DeletePoints();
}
void wxPostScriptDC::DrawSpline(wxList *list)
{
wxSpline spline(list);
wx_draw_open_spline_ps(this, &spline);
}
void wxPostScriptDC::DrawSpline(int n, wxPoint points[])
{
wxList list;
int i;
for (i =0; i < n; i++)
list.Append((wxObject*)&points[i]);
DrawSpline((wxList *)&list);
}
#endif // USE_POSTSCRIPT
#endif // USE_SPLINES

View File

@@ -98,7 +98,7 @@ EXTRADLLFLAGS=
EXTRADLLFLAGS=$(EXTRADLLFLAGS) /DNOMAIN EXTRADLLFLAGS=$(EXTRADLLFLAGS) /DNOMAIN
!endif !endif
INC=-I$(WXINC) -I$(WXDIR)/src/other/png -I$(WXDIR)/src/other/zlib $(EXTRAINC) INC=-I$(WXINC) -I$(WXDIR)/src/png -I$(WXDIR)/src/zlib $(EXTRAINC)
LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS) LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS)
!ifndef FINAL !ifndef FINAL