added more files (unchanged) from wxUniv branch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10674 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2001-06-26 21:05:06 +00:00
parent 1e6feb95a7
commit 32b8ec418a
78 changed files with 14777 additions and 0 deletions

89
include/wx/mgl/app.h Normal file
View File

@ -0,0 +1,89 @@
/////////////////////////////////////////////////////////////////////////////
// Name: app.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_APP_H__
#define __WX_APP_H__
#ifdef __GNUG__
#pragma interface "app.h"
#endif
#include "wx/frame.h"
#include "wx/icon.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class wxApp;
class wxLog;
//-----------------------------------------------------------------------------
// wxApp
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxApp: public wxAppBase
{
public:
wxApp() {}
~wxApp() {}
/* override for altering the way wxGTK intializes the GUI
* (palette/visual/colorcube). under wxMSW, OnInitGui() does nothing by
* default. when overriding this method, the code in it is likely to be
* platform dependent, otherwise use OnInit(). */
virtual bool OnInitGui() {return 0;}
// override base class (pure) virtuals
virtual int MainLoop() {return 0;}
virtual void ExitMainLoop() {}
virtual bool Initialized() {return 0;}
virtual bool Pending() {return 0;}
virtual void Dispatch() {}
virtual wxIcon GetStdIcon(int which) const {return wxNullIcon;}
// implementation only from now on
void OnIdle( wxIdleEvent &event ) {}
bool SendIdleEvents() {return 0;}
bool SendIdleEvents( wxWindow* win ) {return 0;}
static bool Initialize() {return 0;}
static bool InitialzeVisual() {return 0;}
static void CleanUp() {}
bool ProcessIdle() {return 0;}
void DeletePendingObjects() {}
// This can be used to suppress the generation of Idle events.
void SuppressIdleEvents(bool arg = TRUE) { m_suppressIdleEvents = arg; }
bool GetSuppressIdleEvents() const { return m_suppressIdleEvents; }
#if 0 //FIXME MGL
bool m_initialized;
gint m_idleTag;
#if wxUSE_THREADS
gint m_wakeUpTimerTag;
#endif
unsigned char *m_colorCube;
#endif
private:
/// Set to TRUE while we are in wxYield().
bool m_suppressIdleEvents;
private:
DECLARE_DYNAMIC_CLASS(wxApp)
DECLARE_EVENT_TABLE()
};
int WXDLLEXPORT wxEntry( int argc, char *argv[] );
#endif // __WX_APP_H__

139
include/wx/mgl/bitmap.h Normal file
View File

@ -0,0 +1,139 @@
/////////////////////////////////////////////////////////////////////////////
// Name: bitmap.h
// Author: Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_BITMAP_H__
#define __WX_BITMAP_H__
#ifdef __GNUG__
#pragma interface
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/string.h"
#include "wx/palette.h"
#include "wx/gdiobj.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxMask;
class WXDLLEXPORT wxBitmap;
class WXDLLEXPORT wxImage;
class WXDLLEXPORT wxDC;
class WXDLLEXPORT wxMemoryDC;
class MGLDevCtx;
struct bitmap_t;
//-----------------------------------------------------------------------------
// wxMask
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxMask: public wxObject
{
public:
wxMask();
wxMask(const wxBitmap& bitmap, const wxColour& colour);
wxMask(const wxBitmap& bitmap, int paletteIndex);
wxMask(const wxBitmap& bitmap);
~wxMask();
bool Create(const wxBitmap& bitmap, const wxColour& colour);
bool Create(const wxBitmap& bitmap, int paletteIndex);
bool Create(const wxBitmap& bitmap);
// implementation
wxBitmap *m_bitmap;
wxBitmap *GetBitmap() const { return m_bitmap; }
private:
DECLARE_DYNAMIC_CLASS(wxMask)
};
//-----------------------------------------------------------------------------
// wxBitmap
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmapHandler : public wxBitmapHandlerBase
{
public:
wxBitmapHandler() : wxBitmapHandlerBase() {}
private:
DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
};
class WXDLLEXPORT wxBitmap: public wxBitmapBase
{
public:
wxBitmap();
wxBitmap(int width, int height, int depth = -1);
wxBitmap(const char bits[], int width, int height, int depth = 1);
wxBitmap(const char **bits) { CreateFromXpm(bits); }
wxBitmap(char **bits) { CreateFromXpm((const char **)bits); }
wxBitmap(const wxBitmap& bmp);
wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_RESOURCE);
wxBitmap(const wxImage& image, int depth = -1);
~wxBitmap();
wxBitmap& operator = (const wxBitmap& bmp);
bool operator == (const wxBitmap& bmp) const;
bool operator != (const wxBitmap& bmp) const;
bool Ok() const;
bool Create(int width, int height, int depth = -1);
virtual int GetHeight() const;
virtual int GetWidth() const;
virtual int GetDepth() const;
virtual wxImage ConvertToImage() const;
virtual wxMask *GetMask() const;
virtual void SetMask(wxMask *mask);
virtual wxBitmap GetSubBitmap(const wxRect& rect) const;
virtual bool SaveFile(const wxString &name, wxBitmapType type, const wxPalette *palette = (wxPalette *) NULL) const;
virtual bool LoadFile(const wxString &name, wxBitmapType type = wxBITMAP_TYPE_RESOURCE);
virtual wxPalette *GetPalette() const;
virtual void SetPalette(const wxPalette& palette);
// copies the contents and mask of the given (colour) icon to the bitmap
virtual bool CopyFromIcon(const wxIcon& icon);
static void InitStandardHandlers();
// implementation:
virtual void SetHeight(int height);
virtual void SetWidth(int width);
virtual void SetDepth(int depth);
// get underlying native representation:
bitmap_t *GetMGLbitmap_t() const;
protected:
bool CreateFromXpm(const char **bits);
// creates temporary DC for access to bitmap's data:
MGLDevCtx *CreateTmpDC() const;
// sets fg & bg colours for 1bit bitmaps:
void SetMonoPalette(const wxColour& fg, const wxColour& bg);
private:
DECLARE_DYNAMIC_CLASS(wxBitmap)
friend class wxDC;
friend class wxMemoryDC;
};
#endif // __WX_BITMAP_H__

68
include/wx/mgl/brush.h Normal file
View File

@ -0,0 +1,68 @@
/////////////////////////////////////////////////////////////////////////////
// Name: brush.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_BRUSH_H__
#define __WX_BRUSH_H__
#ifdef __GNUG__
#pragma interface "brush.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/string.h"
#include "wx/gdiobj.h"
#include "wx/bitmap.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmap;
class WXDLLEXPORT wxBrush;
//-----------------------------------------------------------------------------
// wxBrush
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxBrush: public wxGDIObject
{
public:
wxBrush();
wxBrush(const wxColour &colour, int style);
wxBrush(const wxBitmap &stippleBitmap);
wxBrush(const wxBrush &brush);
~wxBrush();
wxBrush& operator = (const wxBrush& brush);
bool operator == (const wxBrush& brush) const;
bool operator != (const wxBrush& brush) const;
bool Ok() const;
int GetStyle() const;
wxColour &GetColour() const;
wxBitmap *GetStipple() const;
void SetColour(const wxColour& col);
void SetColour(unsigned char r, unsigned char g, unsigned char b);
void SetStyle(int style);
void SetStipple(const wxBitmap& stipple);
// implementation:
void Unshare();
void* GetMaskPattern() const;
void* GetPixPattern() const;
private:
DECLARE_DYNAMIC_CLASS(wxBrush)
};
#endif // __WX_BRUSH_H__

88
include/wx/mgl/clipbrd.h Normal file
View File

@ -0,0 +1,88 @@
/////////////////////////////////////////////////////////////////////////////
// Name: clipboard.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_CLIPBOARD_H__
#define __WX_CLIPBOARD_H__
#ifdef __GNUG__
#pragma interface "clipbrd.h"
#endif
#if wxUSE_CLIPBOARD
#include "wx/object.h"
#include "wx/list.h"
#include "wx/dataobj.h"
#include "wx/control.h"
#include "wx/module.h"
// ----------------------------------------------------------------------------
// wxClipboard
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxClipboard : public wxClipboardBase
{
public:
wxClipboard() {}
~wxClipboard() {}
// open the clipboard before SetData() and GetData()
virtual bool Open() {}
// close the clipboard after SetData() and GetData()
virtual void Close() {}
// query whether the clipboard is opened
virtual bool IsOpened() const {}
// set the clipboard data. all other formats will be deleted.
virtual bool SetData( wxDataObject *data ) {}
// add to the clipboard data.
virtual bool AddData( wxDataObject *data ) {}
// ask if data in correct format is available
virtual bool IsSupported( const wxDataFormat& format ) {}
// fill data with data on the clipboard (if available)
virtual bool GetData( wxDataObject& data ) {}
// clears wxTheClipboard and the system's clipboard if possible
virtual void Clear() {}
// If primary == TRUE, use primary selection in all further ops,
// primary == FALSE resets it.
virtual void UsePrimarySelection(bool primary = TRUE)
{ m_usePrimary = primary; }
// implementation from now on
bool m_open;
bool m_ownsClipboard;
bool m_ownsPrimarySelection;
wxDataObject *m_data;
GtkWidget *m_clipboardWidget; /* for getting and offering data */
GtkWidget *m_targetsWidget; /* for getting list of supported formats */
bool m_waiting; /* querying data or formats is asynchronous */
bool m_formatSupported;
GdkAtom m_targetRequested;
bool m_usePrimary;
wxDataObject *m_receivedData;
private:
DECLARE_DYNAMIC_CLASS(wxClipboard)
};
#endif
// wxUSE_CLIPBOARD
#endif
// __WX_CLIPBOARD_H__

90
include/wx/mgl/colour.h Normal file
View File

@ -0,0 +1,90 @@
/////////////////////////////////////////////////////////////////////////////
// Name: colour.h
// Purpose: wxColour class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_COLOUR_H_
#define _WX_COLOUR_H_
#ifdef __GNUG__
#pragma interface "colour.h"
#endif
#include "wx/object.h"
// Colour
class WXDLLEXPORT wxColour: public wxObject
{
public:
// ctors
// default
wxColour();
// from RGB
wxColour(unsigned char red, unsigned char green, unsigned char blue);
wxColour(unsigned long colRGB) { Set(colRGB); }
// implicit conversion from the colour name
wxColour(const wxString &colourName) { InitFromName(colourName); }
wxColour(const char *colourName) { InitFromName(colourName); }
// copy ctors and assignment operators
wxColour(const wxColour& col);
wxColour& operator = (const wxColour& col);
// dtor
~wxColour();
// Set() functions
void Set(unsigned char red, unsigned char green, unsigned char blue);
void Set(unsigned long colRGB)
{
// we don't need to know sizeof(long) here because we assume that the three
// least significant bytes contain the R, G and B values
Set((unsigned char)colRGB,
(unsigned char)(colRGB >> 8),
(unsigned char)(colRGB >> 16));
}
// accessors
bool Ok() const { return m_isInit; }
// Let's remove this inelegant function
#if WXWIN_COMPATIBILITY
void Get(unsigned char *r, unsigned char *g, unsigned char *b) const;
#endif
unsigned char Red() const { return m_red; }
unsigned char Green() const { return m_green; }
unsigned char Blue() const { return m_blue; }
// comparison
bool operator == (const wxColour& colour) const
{
return (m_red == colour.m_red &&
m_green == colour.m_green &&
m_blue == colour.m_blue &&
m_isInit == colour.m_isInit);
}
bool operator != (const wxColour& colour) const { return !(*this == colour); }
private:
bool m_isInit;
unsigned char m_red;
unsigned char m_blue;
unsigned char m_green;
// helper func
void InitFromName(const wxString& colourName);
private:
DECLARE_DYNAMIC_CLASS(wxColour)
};
#endif
// _WX_COLOUR_H_

54
include/wx/mgl/cursor.h Normal file
View File

@ -0,0 +1,54 @@
/////////////////////////////////////////////////////////////////////////////
// Name: cursor.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_CURSOR_H__
#define __WX_CURSOR_H__
#ifdef __GNUG__
#pragma interface "cursor.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/gdicmn.h"
class MGLCursor;
//-----------------------------------------------------------------------------
// wxCursor
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxCursor: public wxObject
{
public:
wxCursor();
wxCursor(int cursorId);
wxCursor(const wxCursor &cursor);
wxCursor(const char bits[], int width, int height,
int hotSpotX=-1, int hotSpotY=-1,
const char maskBits[]=0, wxColour *fg=0, wxColour *bg=0);
wxCursor(const wxString& name,
long flags = wxBITMAP_TYPE_CUR_RESOURCE,
int hotSpotX = 0, int hotSpotY = 0);
~wxCursor();
wxCursor& operator = ( const wxCursor& cursor );
bool operator == (const wxCursor& cursor) const;
bool operator != (const wxCursor& cursor) const;
bool Ok() const;
// implementation
MGLCursor *GetMGLCursor() const;
private:
DECLARE_DYNAMIC_CLASS(wxCursor)
};
#endif // __WX_CURSOR_H__

279
include/wx/mgl/dc.h Normal file
View File

@ -0,0 +1,279 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dc.h
// Purpose: wxDC class
// Author: Vaclav Slavik
// Created: 2001/03/09
// RCS-ID: $Id$
// Copyright: (c) Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DC_H_
#define _WX_DC_H_
#ifdef __GNUG__
#pragma interface "dc.h"
#endif
#include "wx/defs.h"
#include "wx/dc.h"
#include "wx/region.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxDC;
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
#define MM_TEXT 0
#define MM_ISOTROPIC 1
#define MM_ANISOTROPIC 2
#define MM_LOMETRIC 3
#define MM_HIMETRIC 4
#define MM_TWIPS 5
#define MM_POINTS 6
#define MM_METRIC 7
//-----------------------------------------------------------------------------
// wxDC
//-----------------------------------------------------------------------------
// MGL fwd declarations:
class MGLDevCtx;
struct font_t;
class WXDLLEXPORT wxDC : public wxDCBase
{
DECLARE_DYNAMIC_CLASS(wxDC)
public:
wxDC();
~wxDC();
// implement base class pure virtuals
// ----------------------------------
virtual void Clear();
virtual bool StartDoc(const wxString& message);
virtual void EndDoc();
virtual void StartPage();
virtual void EndPage();
virtual void SetFont(const wxFont& font);
virtual void SetPen(const wxPen& pen);
virtual void SetBrush(const wxBrush& brush);
virtual void SetBackground(const wxBrush& brush);
virtual void SetBackgroundMode(int mode);
virtual void SetPalette(const wxPalette& palette);
virtual void DestroyClippingRegion();
virtual wxCoord GetCharHeight() const;
virtual wxCoord GetCharWidth() const;
virtual void DoGetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,
wxCoord *descent = NULL,
wxCoord *externalLeading = NULL,
wxFont *theFont = NULL) const;
virtual bool CanDrawBitmap() const;
virtual bool CanGetTextExtent() const;
virtual int GetDepth() const;
virtual wxSize GetPPI() const;
virtual void SetMapMode(int mode);
virtual void SetUserScale(double x, double y);
virtual void SetLogicalScale(double x, double y);
virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
virtual void SetLogicalFunction(int function);
// implementation from now on
// --------------------------
virtual void ComputeScaleAndOrigin();
wxCoord XDEV2LOG(wxCoord x) const
{
wxCoord new_x = x - m_deviceOriginX;
if (new_x > 0)
return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
else
return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
}
wxCoord XDEV2LOGREL(wxCoord x) const
{
if (x > 0)
return (wxCoord)((double)(x) / m_scaleX + 0.5);
else
return (wxCoord)((double)(x) / m_scaleX - 0.5);
}
wxCoord YDEV2LOG(wxCoord y) const
{
wxCoord new_y = y - m_deviceOriginY;
if (new_y > 0)
return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
else
return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
}
wxCoord YDEV2LOGREL(wxCoord y) const
{
if (y > 0)
return (wxCoord)((double)(y) / m_scaleY + 0.5);
else
return (wxCoord)((double)(y) / m_scaleY - 0.5);
}
wxCoord XLOG2DEV(wxCoord x) const
{
wxCoord new_x = x - m_logicalOriginX;
if (new_x > 0)
return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
else
return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
}
wxCoord XLOG2DEVREL(wxCoord x) const
{
if (x > 0)
return (wxCoord)((double)(x) * m_scaleX + 0.5);
else
return (wxCoord)((double)(x) * m_scaleX - 0.5);
}
wxCoord YLOG2DEV(wxCoord y) const
{
wxCoord new_y = y - m_logicalOriginY;
if (new_y > 0)
return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
else
return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
}
wxCoord YLOG2DEVREL(wxCoord y) const
{
if (y > 0)
return (wxCoord)((double)(y) * m_scaleY + 0.5);
else
return (wxCoord)((double)(y) * m_scaleY - 0.5);
}
MGLDevCtx *GetMGLDC() const { return m_MGLDC; }
void SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC = FALSE);
protected:
virtual void DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
int style = wxFLOOD_SURFACE);
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
virtual void DoDrawPoint(wxCoord x, wxCoord y);
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
virtual void DoDrawArc(wxCoord x1, wxCoord y1,
wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc);
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
double sa, double ea);
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
wxCoord width, wxCoord height,
double radius);
virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
virtual void DoCrossHair(wxCoord x, wxCoord y);
virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
bool useMask = FALSE);
virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
double angle);
virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
int rop = wxCOPY, bool useMask = FALSE);
// this is gnarly - we can't even call this function DoSetClippingRegion()
// because of virtual function hiding
virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
wxCoord width, wxCoord height);
virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
wxCoord *width, wxCoord *height)
{
GetClippingBox(x, y, width, height);
}
virtual void DoGetSize(int *width, int *height) const;
virtual void DoGetSizeMM(int* width, int* height) const;
virtual void DoDrawLines(int n, wxPoint points[],
wxCoord xoffset, wxCoord yoffset);
virtual void DoDrawPolygon(int n, wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
int fillStyle = wxODDEVEN_RULE);
// implementation from now on:
protected:
// setup newly attached MGLDevCtx for wxDC's use
// (does things like setting RGB blending mode for antialiased texts):
void InitializeMGLDC();
// common part of DoDrawText() and DoDrawRotatedText()
void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
// MGL uses pens as both wxPens and wxBrushes, so we have to
// switch them as needed:
void SelectPen();
void SelectBrush();
void SelectMGLStipplePen(int style);
void SelectMGLFatPen(int style, int flag);
// Select m_font into m_MGLDC:
bool SelectMGLFont();
// Convert wxWin logical function to MGL rop:
int LogicalFunctionToMGLRop(int logFunc) const;
// Unified implementation of DrawIcon, DrawBitmap and Blit:
void DoDrawSubBitmap(const wxBitmap &bmp,
wxCoord x, wxCoord y, wxCoord w, wxCoord h,
wxCoord destx, wxCoord desty, int rop, bool useMask);
// MGL DC class we use:
MGLDevCtx *m_MGLDC;
bool m_OwnsMGLDC:1;
// helper variables for SelectXXXX():
bool m_penSelected;
bool m_brushSelected;
bool m_downloadedPatterns[2];
// MGL does not render lines with width>1 with endings centered
// at given coords but with top left corner of the pen at them,
// these offsets are used to correct it. They are computed by
// SelectPen.
int m_penOfsX, m_penOfsY;
double m_mm_to_pix_x, m_mm_to_pix_y;
wxPalette m_oldPalette;
wxRegion m_currentClippingRegion;
// wxDC::Blit handles memoryDCs as special cases :(
bool m_isMemDC;
font_t *m_mglFont;
};
#endif
// _WX_DC_H_

71
include/wx/mgl/dcclient.h Normal file
View File

@ -0,0 +1,71 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcclient.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_DCCLIENT_H__
#define __WX_DCCLIENT_H__
#ifdef __GNUG__
#pragma interface "dcclient.h"
#endif
#include "wx/dc.h"
#include "wx/window.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxWindowDC;
class WXDLLEXPORT wxPaintDC;
class WXDLLEXPORT wxClientDC;
//-----------------------------------------------------------------------------
// wxWindowDC
//-----------------------------------------------------------------------------
//FIXME_MGL
class WXDLLEXPORT wxWindowDC : public wxDC
{
public:
wxWindowDC() {}
wxWindowDC( wxWindow *win ) {}
private:
DECLARE_DYNAMIC_CLASS(wxWindowDC)
};
//-----------------------------------------------------------------------------
// wxClientDC
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxClientDC : public wxWindowDC
{
public:
wxClientDC() {}
wxClientDC( wxWindow *win ) {}
private:
DECLARE_DYNAMIC_CLASS(wxClientDC)
};
//-----------------------------------------------------------------------------
// wxPaintDC
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxPaintDC : public wxClientDC
{
public:
wxPaintDC() { }
wxPaintDC( wxWindow *win ) {}
private:
DECLARE_DYNAMIC_CLASS(wxPaintDC)
};
#endif // __WX_DCCLIENT_H__

59
include/wx/mgl/dcmemory.h Normal file
View File

@ -0,0 +1,59 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcmemory.h
// Purpose:
// Author: Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_DCMEMORY_H__
#define __WX_DCMEMORY_H__
#ifdef __GNUG__
#pragma interface "dcmemory.h"
#endif
#include "wx/defs.h"
#include "wx/dcclient.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxMemoryDC;
//-----------------------------------------------------------------------------
// wxMemoryDC
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxMemoryDC : public wxDC
{
public:
wxMemoryDC();
wxMemoryDC(wxDC *dc); // Create compatible DC
~wxMemoryDC();
virtual void SelectObject(const wxBitmap& bitmap);
// these get reimplemented for mono-bitmaps to behave
// more like their Win32 couterparts. They now interpret
// wxWHITE, wxWHITE_BRUSH and wxWHITE_PEN as drawing 0
// and everything else as drawing 1.
virtual void SetPen(const wxPen &pen);
virtual void SetBrush(const wxBrush &brush);
virtual void SetTextForeground(const wxColour &col);
virtual void SetTextBackground(const wxColour &col);
// implementation
wxBitmap m_selected;
wxBitmap GetSelectedObject() const { return m_selected; }
private:
DECLARE_DYNAMIC_CLASS(wxMemoryDC)
};
#endif
// __WX_DCMEMORY_H__

47
include/wx/mgl/dcscreen.h Normal file
View File

@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcscreen.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_DCSCREEN_H__
#define __WX_DCSCREEN_H__
#ifdef __GNUG__
#pragma interface "dcscreen.h"
#endif
#include "wx/dcclient.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxScreenDC;
//-----------------------------------------------------------------------------
// wxScreenDC
//-----------------------------------------------------------------------------
//FIXME_MGL
class WXDLLEXPORT wxScreenDC: public wxPaintDC
{
public:
wxScreenDC() {}
~wxScreenDC() {}
static bool StartDrawingOnTop( wxWindow *window ) {}
static bool StartDrawingOnTop( wxRect *rect = (wxRect *) NULL ) {}
static bool EndDrawingOnTop() {}
private:
DECLARE_DYNAMIC_CLASS(wxScreenDC)
};
#endif
// __WX_DCSCREEN_H__

120
include/wx/mgl/dialog.h Normal file
View File

@ -0,0 +1,120 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dialog.h
// Purpose:
// Author: Robert Roebling
// Created:
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __GTKDIALOGH__
#define __GTKDIALOGH__
#ifdef __GNUG__
#pragma interface "dialog.h"
#endif
#include "wx/defs.h"
#include "wx/panel.h"
#include "wx/icon.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class wxDialog;
//-----------------------------------------------------------------------------
// global data
//-----------------------------------------------------------------------------
//FIXME_MGL - belongs to wXUniv
extern const wxChar *wxDialogNameStr;
//-----------------------------------------------------------------------------
// wxDialog
//-----------------------------------------------------------------------------
class wxDialog: public wxDialogBase
{
public:
wxDialog() { Init(); }
wxDialog( wxWindow *parent, wxWindowID id,
const wxString &title,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE,
const wxString &name = wxDialogNameStr ) {}
bool Create( wxWindow *parent, wxWindowID id,
const wxString &title,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE,
const wxString &name = wxDialogNameStr ) {}
~wxDialog() {}
void SetTitle(const wxString& title){}
wxString GetTitle() const {}
void OnApply( wxCommandEvent &event ) {}
void OnCancel( wxCommandEvent &event ) {}
void OnOK( wxCommandEvent &event ) {}
void OnPaint( wxPaintEvent& event ) {}
void OnSize( wxSizeEvent &event ) {}
void OnCloseWindow( wxCloseEvent& event ) {}
/*
void OnCharHook( wxKeyEvent& event );
*/
bool Destroy() {}
virtual bool Show( bool show ) {}
virtual int ShowModal() {}
virtual void EndModal( int retCode ) {}
virtual bool IsModal() const {}
void SetModal( bool modal ) {}
virtual void InitDialog(void) {}
virtual void SetIcon( const wxIcon &icon ) {}
virtual void Iconize( bool WXUNUSED(iconize)) { }
virtual bool IsIconized() const { return FALSE; }
bool Iconized() const { return IsIconized(); }
virtual void Maximize() { }
virtual void Restore() { }
virtual bool IsTopLevel() const { return TRUE; }
// implementation
// --------------
// move the window to the specified location and resize it: this is called
// from both DoSetSize() and DoSetClientSize()
virtual void DoMoveWindow(int x, int y, int width, int height) {}
virtual void GtkOnSize( int x, int y, int width, int height ) {}
virtual void OnInternalIdle() {}
bool m_modalShowing;
wxString m_title;
wxIcon m_icon;
protected:
// common part of all ctors
void Init() {}
// common part of Destroy() and ~wxDialog
void CleanUp() {}
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO) {}
private:
// DECLARE_EVENT_TABLE() FIXME_MGL
DECLARE_DYNAMIC_CLASS(wxDialog)
};
#endif // __GTKDIALOGH__

107
include/wx/mgl/font.h Normal file
View File

@ -0,0 +1,107 @@
/////////////////////////////////////////////////////////////////////////////
// Name: font.h
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001, Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_FONT_H__
#define __WX_FONT_H__
#ifdef __GNUG__
#pragma interface "font.h"
#endif
#include "wx/hash.h"
// ----------------------------------------------------------------------------
// classes
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxDC;
class WXDLLEXPORT wxPaintDC;
class WXDLLEXPORT wxWindow;
class WXDLLEXPORT wxFont;
struct font_t;
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxFont : public wxFontBase
{
public:
// ctors and such
wxFont() { Init(); }
wxFont(const wxFont& font) { Init(); Ref(font); }
wxFont(const wxNativeFontInfo& info)
{
Init();
(void)Create(info);
}
wxFont(int size,
int family,
int style,
int weight,
bool underlined = FALSE,
const wxString& face = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
{
Init();
(void)Create(size, family, style, weight, underlined, face, encoding);
}
bool Create(int size,
int family,
int style,
int weight,
bool underlined = FALSE,
const wxString& face = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
bool Create(const wxNativeFontInfo& fontinfo);
~wxFont();
// assignment
wxFont& operator=(const wxFont& font);
// implement base class pure virtuals
virtual int GetPointSize() const;
virtual int GetFamily() const;
virtual int GetStyle() const;
virtual int GetWeight() const;
virtual wxString GetFaceName() const;
virtual bool GetUnderlined() const;
virtual wxFontEncoding GetEncoding() const;
virtual void SetPointSize(int pointSize);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
virtual void SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
// implementation from now on
void Unshare();
struct font_t *GetMGLfont_t(float scale, bool antialiased);
// no data :-)
protected:
// common part of all ctors
void Init();
private:
DECLARE_DYNAMIC_CLASS(wxFont)
};
#endif // __WX_FONT_H__

126
include/wx/mgl/fontutil.h Normal file
View File

@ -0,0 +1,126 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/nix/fontutil.h
// Purpose: font-related helper functions for MGL
// Author: Vaclav Slavik
// Created: 2001/05/01
// RCS-ID: $Id$
// Copyright: (c) 2001, Vaclav Slavik
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MGL_FONTUTIL_H_
#define _WX_MGL_FONTUTIL_H_
#ifdef __WXMGL__
#include "wx/list.h"
struct font_info_t;
struct font_lib_t;
struct font_t;
class wxMGLFontInstance;
class wxMGLFontInstanceList;
class wxMGLFontLibrary;
class wxMGLFontFamily;
enum
{
wxFONTFACE_REGULAR = 0,
wxFONTFACE_ITALIC = 1,
wxFONTFACE_BOLD = 2, // = (regular | bold)
wxFONTFACE_BOLD_ITALIC = 3, // = (italic | bold)
wxFONTFACE_MAX
};
// structure representing particular loaded font instance:
class wxMGLFontInstance
{
public:
wxMGLFontInstance(wxMGLFontLibrary *fontLib, float pt, bool slant, bool aa);
~wxMGLFontInstance();
struct font_t *GetMGLfont_t() const { return m_font; }
float GetPt() const { return m_pt; }
bool GetSlant() const { return m_slant; }
bool GetAA() const { return m_aa; }
private:
wxMGLFontLibrary *m_fontLib;
font_t *m_font;
float m_pt;
bool m_slant;
bool m_aa;
};
// structure representing loaded font library:
class wxMGLFontLibrary
{
public:
wxMGLFontLibrary(const wxString& filename, int type);
~wxMGLFontLibrary();
wxMGLFontInstance *GetFontInstance(wxFont *font, float scale, bool aa);
void IncRef();
void DecRef();
struct font_lib_t *GetMGLfont_lib_t() const { return m_fontLib; }
private:
font_lib_t *m_fontLib;
int m_type;
wxString m_fileName;
size_t m_refs;
wxMGLFontInstanceList *m_instances;
};
// structure representing native MGL font family
class wxMGLFontFamily : public wxObject
{
public:
wxMGLFontFamily(const font_info_t *info);
virtual ~wxMGLFontFamily();
wxString GetName() const { return m_name; }
const font_info_t *GetInfo() const { return m_fontInfo; }
bool HasFace(int type) const;
wxMGLFontLibrary *GetLibrary(int type) const
{ return m_fontLibs[type]; }
private:
wxString m_name;
const font_info_t *m_fontInfo;
wxMGLFontLibrary *m_fontLibs[wxFONTFACE_MAX];
};
WX_DECLARE_LIST(wxMGLFontFamily, wxMGLFontFamilyList);
class wxFontsManager
{
public:
wxFontsManager();
~wxFontsManager();
void AddFamily(const font_info_t *info);
// return info about font with given name:
wxMGLFontFamily *GetFamily(const wxString& name) const;
// return list of all families
wxMGLFontFamilyList *GetFamilyList() { return m_list; }
wxMGLFontLibrary *GetFontLibrary(wxFont *font);
private:
wxHashTable *m_hash;
wxMGLFontFamilyList *m_list;
};
extern wxFontsManager *wxTheFontsManager;
#endif
#endif // _WX_MGL_FONTUTIL_H_

132
include/wx/mgl/frame.h Normal file
View File

@ -0,0 +1,132 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/frame.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __MGL_FRAME_H__
#define __MGL_FRAME_H__
#ifdef __GNUG__
#pragma interface "frame.h"
#endif
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxMDIChildFrame;
class WXDLLEXPORT wxMDIClientWindow;
class WXDLLEXPORT wxMenu;
class WXDLLEXPORT wxMenuBar;
class WXDLLEXPORT wxToolBar;
class WXDLLEXPORT wxStatusBar;
class WXDLLEXPORT wxFrame;
//-----------------------------------------------------------------------------
// wxFrame
//-----------------------------------------------------------------------------
//FIXME_MGL
class WXDLLEXPORT wxFrame : public wxFrameBase
{
public:
// construction
wxFrame() { Init(); }
wxFrame(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE,
const wxString& name = wxFrameNameStr)
{
Init();
Create(parent, id, title, pos, size, style, name);
}
bool Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE,
const wxString& name = wxFrameNameStr) {}
virtual ~wxFrame() {}
// implement base class pure virtuals
virtual void Maximize(bool maximize = TRUE) {}
virtual bool IsMaximized() const {}
virtual void Iconize(bool iconize = TRUE) {}
virtual bool IsIconized() const {}
virtual void SetIcon(const wxIcon& icon) {}
virtual void MakeModal(bool modal = TRUE) {}
virtual void Restore() {}
#if wxUSE_MENUS
virtual void SetMenuBar( wxMenuBar *menuBar ) {}
#endif // wxUSE_MENUS
#if wxUSE_STATUSBAR
virtual void PositionStatusBar() {}
virtual wxStatusBar* CreateStatusBar(int number = 1,
long style = wxST_SIZEGRIP,
wxWindowID id = 0,
const wxString& name = wxStatusLineNameStr) {}
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
virtual wxToolBar* CreateToolBar(long style = wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT,
wxWindowID id = -1,
const wxString& name = wxToolBarNameStr) {}
void SetToolBar(wxToolBar *toolbar) {}
#endif // wxUSE_TOOLBAR
virtual bool Show(bool show = TRUE) {}
virtual void SetTitle( const wxString &title ) {}
virtual wxString GetTitle() const { return m_title; }
// implementation from now on
// --------------------------
// move the window to the specified location and resize it: this is called
// from both DoSetSize() and DoSetClientSize()
virtual void DoMoveWindow(int x, int y, int width, int height) {}
// GTK callbacks
virtual void GtkOnSize( int x, int y, int width, int height ) {}
virtual void OnInternalIdle() {}
wxString m_title;
int m_miniEdge,
m_miniTitle;
bool m_menuBarDetached;
bool m_toolBarDetached;
bool m_insertInClientArea; /* not from within OnCreateXXX */
protected:
// common part of all ctors
void Init() {}
// override wxWindow methods to take into account tool/menu/statusbars
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO) {}
virtual void DoSetClientSize(int width, int height) {}
virtual void DoGetClientSize( int *width, int *height ) const {}
private:
DECLARE_DYNAMIC_CLASS(wxFrame)
};
#endif // __WX_FRAME_H__

55
include/wx/mgl/gdiobj.h Normal file
View File

@ -0,0 +1,55 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/gdiobj.h
// Purpose: wxGDIObject class: base class for other GDI classes
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GDIOBJ_H_
#define _WX_GDIOBJ_H_
#ifdef __GNUG__
#pragma interface "gdiobj.h"
#endif
#include "wx/object.h" // base class
// ----------------------------------------------------------------------------
// wxGDIRefData is the base class for wxXXXData structures which contain the
// real data for the GDI object and are shared among all wxWin objects sharing
// the same native GDI object
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGDIRefData : public wxObjectRefData
{
// this class is intentionally left blank
};
// ----------------------------------------------------------------------------
// wxGDIObject
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGDIObject : public wxObject
{
public:
wxGDIObject() {}
virtual bool GetVisible() { return m_visible; }
virtual void SetVisible( bool visible ) { m_visible = visible; }
bool IsNull() const { return (m_refData == 0); }
protected:
bool m_visible; /* can a pointer to this object be safely taken?
* - only if created within FindOrCreate... */
private:
DECLARE_DYNAMIC_CLASS(wxGDIObject)
};
#endif
// _WX_GDIOBJ_H_

60
include/wx/mgl/icon.h Normal file
View File

@ -0,0 +1,60 @@
/////////////////////////////////////////////////////////////////////////////
// Name: icon.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_ICON_H__
#define __WX_ICON_H__
#ifdef __GNUG__
#pragma interface "icon.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/bitmap.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxIcon;
//-----------------------------------------------------------------------------
// wxIcon
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxIcon: public wxBitmap
{
public:
wxIcon() : wxBitmap() {}
wxIcon(const wxIcon& icon);
wxIcon(const char **bits, int width=-1, int height=-1);
wxIcon(char **bits, int width=-1, int height=-1);
// For compatibility with wxMSW where desired size is sometimes required to
// distinguish between multiple icons in a resource.
wxIcon(const wxString& filename, wxBitmapType type = wxBITMAP_TYPE_ICO_RESOURCE,
int WXUNUSED(desiredWidth)=-1, int WXUNUSED(desiredHeight)=-1 ) :
wxBitmap(filename, type) {}
wxIcon& operator = (const wxIcon& icon);
inline bool operator == (const wxIcon& icon) { return m_refData == icon.m_refData; }
inline bool operator != (const wxIcon& icon) { return m_refData != icon.m_refData; }
// create from bitmap (which should have a mask unless it's monochrome):
// there shouldn't be any implicit bitmap -> icon conversion (i.e. no
// ctors, assignment operators...), but it's ok to have such function
void CopyFromBitmap(const wxBitmap& bmp);
private:
DECLARE_DYNAMIC_CLASS(wxIcon)
};
#endif // __WX_ICON_H__

64
include/wx/mgl/palette.h Normal file
View File

@ -0,0 +1,64 @@
/////////////////////////////////////////////////////////////////////////////
// Name: palette.h
// Purpose:
// Author: Vaclav Slavik
// Created: 2001/03/11
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_PALETTE_H__
#define __WX_PALETTE_H__
#ifdef __GNUG__
#pragma interface "palette.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/gdiobj.h"
#include "wx/gdicmn.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxPalette;
struct palette_t;
//-----------------------------------------------------------------------------
// wxPalette
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxPalette: public wxGDIObject
{
DECLARE_DYNAMIC_CLASS(wxPalette)
public:
wxPalette();
wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue);
wxPalette(const wxPalette& palette);
~wxPalette();
wxPalette& operator = (const wxPalette& palette);
bool operator == (const wxPalette& palette) const;
bool operator != (const wxPalette& palette) const;
bool Ok() const;
bool Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue);
int GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const;
bool GetRGB(int pixel, unsigned char *red, unsigned char *green, unsigned char *blue) const;
// implementation
int GetColoursCount() const;
// FIXME_MGL -- make this method standard part of wx API
// FIXME_MGL -- create wxXXXBase classes for all GDI stuff (Vadim wants that)
palette_t *GetMGLpalette_t() const;
};
#define wxColorMap wxPalette
#define wxColourMap wxPalette
#endif // __WX_PALETTE_H__

77
include/wx/mgl/pen.h Normal file
View File

@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////
// Name: pen.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_PEN_H__
#define __WX_PEN_H__
#ifdef __GNUG__
#pragma interface "pen.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/string.h"
#include "wx/gdiobj.h"
#include "wx/gdicmn.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxBitmap;
class WXDLLEXPORT wxPen;
//-----------------------------------------------------------------------------
// wxPen
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxPen: public wxGDIObject
{
public:
wxPen();
wxPen(const wxColour &colour, int width, int style);
wxPen(const wxBitmap& stipple, int width);
wxPen(const wxPen& pen);
~wxPen();
wxPen& operator = (const wxPen& pen);
bool operator == (const wxPen& pen) const;
bool operator != (const wxPen& pen) const;
void SetColour(const wxColour &colour);
void SetColour(int red, int green, int blue);
void SetCap(int capStyle);
void SetJoin(int joinStyle);
void SetStyle(int style);
void SetWidth(int width);
void SetDashes(int number_of_dashes, const wxDash *dash);
void SetStipple(const wxBitmap& stipple);
wxColour &GetColour() const;
int GetCap() const;
int GetJoin() const;
int GetStyle() const;
int GetWidth() const;
int GetDashes(wxDash **ptr) const;
int GetDashCount() const;
wxDash* GetDash() const;
wxBitmap *GetStipple() const;
bool Ok() const;
void Unshare();
// implementation:
void* GetPixPattern() const;
private:
DECLARE_DYNAMIC_CLASS(wxPen)
};
#endif // __WX_PEN_H__

51
include/wx/mgl/private.h Normal file
View File

@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////
// Name: private.h
// Purpose: Private declarations: as this header is only included by
// wxWindows itself, it may contain identifiers which don't start
// with "wx".
// Author: Vaclav Slavik
// Created: 2001/04/07
// RCS-ID: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_H_
#define _WX_PRIVATE_H_
#include <mgraph.hpp>
class WXDLLEXPORT wxBitmap;
// ---------------------------------------------------------------------------
// private variables
// ---------------------------------------------------------------------------
extern MGLDevCtx *g_displayDC;
// ---------------------------------------------------------------------------
// helper functions
// ---------------------------------------------------------------------------
// This function converts wxBitmap into pixpattern24_t representation
// (used by wxBrush and wxPen)
extern void wxBitmapToPixPattern(const wxBitmap& bitmap,
pixpattern24_t *pix, pattern_t *mask);
// Sets current DC and restores previous one upon destruction:
class wxCurrentDCSwitcher
{
public:
wxCurrentDCSwitcher(MGLDevCtx *dc)
{ m_old = dc->makeCurrent(); }
~wxCurrentDCSwitcher()
{ MGL_makeCurrentDC(m_old); }
MGLDC *m_old;
};
#endif // _WX_PRIVATE_H_

142
include/wx/mgl/region.h Normal file
View File

@ -0,0 +1,142 @@
/////////////////////////////////////////////////////////////////////////////
// Name: region.h
// Purpose: wxRegion class
// Author: Vaclav Slavik
// Created: 2001/03/12
// RCS-ID: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_REGION_H_
#define _WX_REGION_H_
#ifdef __GNUG__
#pragma interface "region.h"
#endif
#include "wx/list.h"
#include "wx/gdiobj.h"
#include "wx/gdicmn.h"
#include "wx/list.h"
class WXDLLEXPORT wxRect;
class WXDLLEXPORT wxPoint;
class MGLRegion;
enum wxRegionContain
{
wxOutRegion = 0,
wxPartRegion = 1,
wxInRegion = 2
};
class WXDLLEXPORT wxRegion : public wxGDIObject
{
DECLARE_DYNAMIC_CLASS(wxRegion);
friend class WXDLLEXPORT wxRegionIterator;
public:
wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
wxRegion(const wxRect& rect);
wxRegion(const MGLRegion& region);
wxRegion();
~wxRegion();
//# Copying
inline wxRegion(const wxRegion& r)
{ Ref(r); }
inline wxRegion& operator = (const wxRegion& r)
{ Ref(r); return (*this); }
//# Modify region
// Clear current region
void Clear(void);
// Union rectangle or region with this.
bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
bool Union(const wxRect& rect) { return Union(rect.x, rect.y, rect.width, rect.height); }
bool Union(const wxRegion& region);
// Intersect rectangle or region with this.
bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
bool Intersect(const wxRect& rect) { return Intersect(rect.x, rect.y, rect.width, rect.height); }
bool Intersect(const wxRegion& region);
// Subtract rectangle or region from this:
// Combines the parts of 'this' that are not part of the second region.
bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
bool Subtract(const wxRect& rect) { return Subtract(rect.x, rect.y, rect.width, rect.height); }
bool Subtract(const wxRegion& region);
// XOR: the union of two combined regions except for any overlapping areas.
bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
bool Xor(const wxRect& rect) { return Xor(rect.x, rect.y, rect.width, rect.height); }
bool Xor(const wxRegion& region);
//# Information on region
// Outer bounds of region
void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
wxRect GetBox(void) const ;
// Is region empty?
bool Empty(void) const;
inline bool IsEmpty(void) const { return Empty(); }
//# Tests
// Does the region contain the point (x,y)?
wxRegionContain Contains(wxCoord x, wxCoord y) const;
// Does the region contain the point pt?
wxRegionContain Contains(const wxPoint& pt) const;
// Does the region contain the rectangle (x, y, w, h)?
wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
// Does the region contain the rectangle rect?
wxRegionContain Contains(const wxRect& rect) const;
// implementation from now on:
const MGLRegion& GetMGLRegion() const;
private:
void Unshare();
};
WX_DECLARE_EXPORTED_LIST(wxRect, wxRegionRectList);
class WXDLLEXPORT wxRegionIterator : public wxObject
{
DECLARE_DYNAMIC_CLASS(wxRegionIterator);
public:
wxRegionIterator(void);
wxRegionIterator(const wxRegion& region);
~wxRegionIterator(void);
void Reset(void) { m_currentNode = NULL; }
void Reset(const wxRegion& region);
#ifndef __SALFORDC__
operator bool (void) const { return (m_currentNode != NULL); }
#endif
bool HaveRects(void) const { return (m_currentNode != NULL); }
void operator ++ (void);
void operator ++ (int);
wxCoord GetX(void) const;
wxCoord GetY(void) const;
wxCoord GetW(void) const;
wxCoord GetWidth(void) const { return GetW(); }
wxCoord GetH(void) const;
wxCoord GetHeight(void) const { return GetH(); }
wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
private:
wxRegionRectList m_rects;
wxRegionRectList::Node *m_currentNode;
};
#endif
// _WX_REGION_H_

43
include/wx/mgl/settings.h Normal file
View File

@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////
// Name: settings.h
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __GTKSETTINGSH__
#define __GTKSETTINGSH__
#ifdef __GNUG__
#pragma interface "settings.h"
#endif
#include "wx/defs.h"
#include "wx/gdicmn.h"
#include "wx/pen.h"
#include "wx/font.h"
// FIXME_MGL - probably belongs to wxUniversal
class wxSystemSettings: public wxObject
{
public:
inline wxSystemSettings() {}
inline static void Init() {}
static void Done() {}
// Get a system colour
static wxColour GetSystemColour(int index) {}
// Get a system font
static wxFont GetSystemFont(int index) {}
// Get a system metric, e.g. scrollbar size
static int GetSystemMetric(int index) {}
};
#endif
// __GTKSETTINGSH__

45
include/wx/mgl/timer.h Normal file
View File

@ -0,0 +1,45 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_TIMER_H__
#define __WX_TIMER_H__
#ifdef __GNUG__
#pragma interface "timer.h"
#endif
//-----------------------------------------------------------------------------
// wxTimer
//-----------------------------------------------------------------------------
//FIXME_MGL
class WXDLLEXPORT wxTimer : public wxTimerBase
{
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id)
{ Init(); }
~wxTimer() {}
virtual bool Start( int millisecs = -1, bool oneShot = FALSE ) {}
virtual void Stop() {}
virtual bool IsRunning() const { return m_tag != -1; }
protected:
void Init() {}
int m_tag;
private:
DECLARE_ABSTRACT_CLASS(wxTimer)
};
#endif // __GTKTIMERH__

127
include/wx/mgl/window.h Normal file
View File

@ -0,0 +1,127 @@
/////////////////////////////////////////////////////////////////////////////
// Name: window.h
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_WINDOW_H__
#define __WX_WINDOW_H__
#ifdef __GNUG__
#pragma interface "window.h"
#endif
//-----------------------------------------------------------------------------
// wxWindow
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxWindowMGL : public wxWindowBase
{
DECLARE_DYNAMIC_CLASS(wxWindowMGL)
public:
// creating the window
// -------------------
wxWindowMGL() {}
wxWindowMGL(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxPanelNameStr) {}
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxPanelNameStr) {}
virtual ~wxWindowMGL() {}
// implement base class (pure) virtual methods
// -------------------------------------------
virtual bool Destroy() {return TRUE;}
virtual void Raise() {}
virtual void Lower() {}
virtual bool Show( bool show = TRUE ) {return TRUE;}
virtual bool Enable( bool enable = TRUE ) {return TRUE;}
virtual bool IsRetained() const {return TRUE;}
virtual void SetFocus() {}
virtual bool AcceptsFocus() const {return TRUE;}
virtual bool Reparent( wxWindowBase *newParent ) {return TRUE;}
virtual void WarpPointer(int x, int y) {}
virtual void CaptureMouse() {}
virtual void ReleaseMouse() {}
virtual void Refresh( bool eraseBackground = TRUE,
const wxRect *rect = (const wxRect *) NULL ) {}
virtual void Clear() {}
virtual bool SetBackgroundColour( const wxColour &colour ) {return TRUE;}
virtual bool SetForegroundColour( const wxColour &colour ) {return TRUE;}
virtual bool SetCursor( const wxCursor &cursor ) {return TRUE;}
virtual bool SetFont( const wxFont &font ) {return TRUE;}
virtual int GetCharHeight() const {return 0;}
virtual int GetCharWidth() const {return 0;}
virtual void GetTextExtent(const wxString& string,
int *x, int *y,
int *descent = (int *) NULL,
int *externalLeading = (int *) NULL,
const wxFont *theFont = (const wxFont *) NULL)
const {}
virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) {return TRUE;}
virtual void SetScrollbar( int orient, int pos, int thumbVisible,
int range, bool refresh = TRUE ) {}
virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) {}
virtual int GetScrollPos( int orient ) const {return 0;}
virtual int GetScrollThumb( int orient ) const {return 0;}
virtual int GetScrollRange( int orient ) const {return 0;}
virtual void ScrollWindow( int dx, int dy,
const wxRect* rect = (wxRect *) NULL ) {}
#if wxUSE_DRAG_AND_DROP
virtual void SetDropTarget( wxDropTarget *dropTarget ) {}
#endif // wxUSE_DRAG_AND_DROP
virtual WXWidget GetHandle() const { return NULL; }
/* For compatibility across platforms (not in event table) */
void OnIdle(wxIdleEvent& WXUNUSED(event)) {};
// implement the base class pure virtuals
virtual void DoClientToScreen( int *x, int *y ) const {}
virtual void DoScreenToClient( int *x, int *y ) const {}
virtual void DoGetPosition( int *x, int *y ) const {}
virtual void DoGetSize( int *width, int *height ) const {}
virtual void DoGetClientSize( int *width, int *height ) const {}
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO) {}
virtual void DoSetClientSize(int width, int height) {}
virtual void DoMoveWindow(int x, int y, int width, int height) {}
#if wxUSE_TOOLTIPS
virtual void DoSetToolTip( wxToolTip *tip ) {}
#endif // wxUSE_TOOLTIPS
// common part of all ctors (can't be virtual because called from ctor)
void Init() {}
private:
DECLARE_NO_COPY_CLASS(wxWindowMGL);
};
#endif // ___WX_WINDOW_H__

View File

@ -0,0 +1,31 @@
#
# File: makefile.unx
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julian Smart
#
# "%W% %G%"
#
# Makefile for minimal example (UNIX).
top_srcdir = @top_srcdir@/..
top_builddir = ../..
program_dir = samples/widgets
PROGRAM=widgets
OBJECTS=button.o \
combobox.o \
gauge.o \
listbox.o \
notebook.o \
radiobox.o \
slider.o \
spinbtn.o \
static.o \
textctrl.o \
widgets.o
include ../../src/makeprog.env

371
samples/widgets/button.cpp Normal file
View File

@ -0,0 +1,371 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: button.cpp
// Purpose: Part of the widgets sample showing wxButton
// Author: Vadim Zeitlin
// Created: 10.04.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "widgets.h"
#include "icons/button.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
ButtonPage_Reset = 100,
ButtonPage_ChangeLabel,
ButtonPage_Button
};
// radio boxes
enum
{
ButtonHAlign_Left,
ButtonHAlign_Centre,
ButtonHAlign_Right
};
enum
{
ButtonVAlign_Top,
ButtonVAlign_Centre,
ButtonVAlign_Bottom
};
// ----------------------------------------------------------------------------
// ButtonWidgetsPage
// ----------------------------------------------------------------------------
class ButtonWidgetsPage : public WidgetsPage
{
public:
ButtonWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~ButtonWidgetsPage();
protected:
// event handlers
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnButton(wxCommandEvent& event);
void OnButtonReset(wxCommandEvent& event);
void OnButtonChangeLabel(wxCommandEvent& event);
// reset the wxButton parameters
void Reset();
// (re)create the wxButton
void CreateButton();
// the controls
// ------------
// the check/radio boxes for styles
wxCheckBox *m_chkImage,
*m_chkFit,
*m_chkDefault;
wxRadioBox *m_radioHAlign,
*m_radioVAlign;
// the gauge itself and the sizer it is in
wxButton *m_button;
wxSizer *m_sizerButton;
// the text entries for command parameters
wxTextCtrl *m_textLabel;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(ButtonWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(ButtonWidgetsPage, WidgetsPage)
EVT_BUTTON(ButtonPage_Button, ButtonWidgetsPage::OnButton)
EVT_BUTTON(ButtonPage_Reset, ButtonWidgetsPage::OnButtonReset)
EVT_BUTTON(ButtonPage_ChangeLabel, ButtonWidgetsPage::OnButtonChangeLabel)
EVT_CHECKBOX(-1, ButtonWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, ButtonWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(ButtonWidgetsPage, _T("Button"));
ButtonWidgetsPage::ButtonWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(button_xpm));
// init everything
m_chkImage =
m_chkFit =
m_chkDefault = (wxCheckBox *)NULL;
m_radioHAlign =
m_radioVAlign = (wxRadioBox *)NULL;
m_textLabel = (wxTextCtrl *)NULL;
m_button = (wxButton *)NULL;
m_sizerButton = (wxSizer *)NULL;
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
m_chkImage = CreateCheckBoxAndAddToSizer(sizerLeft, _T("With &image"));
m_chkFit = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Fit exactly"));
m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Default"));
#ifndef __WXUNIVERSAL__
// only wxUniv currently supoprts buttons with images
m_chkImage->Disable();
#endif // !wxUniv
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
// should be in sync with enums Button[HV]Align!
static const wxString halign[] =
{
_T("left"),
_T("centre"),
_T("right"),
};
static const wxString valign[] =
{
_T("top"),
_T("centre"),
_T("bottom"),
};
m_radioHAlign = new wxRadioBox(this, -1, _T("&Horz alignment"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(halign), halign);
m_radioVAlign = new wxRadioBox(this, -1, _T("&Vert alignment"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(valign), valign);
sizerLeft->Add(m_radioHAlign, 0, wxGROW | wxALL, 5);
sizerLeft->Add(m_radioVAlign, 0, wxGROW | wxALL, 5);
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
wxButton *btn = new wxButton(this, ButtonPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Operations"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxSizer *sizerRow = CreateSizerWithTextAndButton(ButtonPage_ChangeLabel,
_T("Change label"),
-1,
&m_textLabel);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
m_button = new wxButton(this, ButtonPage_Button, _T("&Press me!"));
sizerRight->Add(0, 0, 1, wxCENTRE);
sizerRight->Add(m_button, 1, wxCENTRE);
sizerRight->Add(0, 0, 1, wxCENTRE);
sizerRight->SetMinSize(250, 0);
m_sizerButton = sizerRight; // save it to modify it later
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
Reset();
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
ButtonWidgetsPage::~ButtonWidgetsPage()
{
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void ButtonWidgetsPage::Reset()
{
m_chkFit->SetValue(TRUE);
m_chkImage->SetValue(FALSE);
m_chkDefault->SetValue(FALSE);
m_radioHAlign->SetSelection(ButtonHAlign_Centre);
m_radioVAlign->SetSelection(ButtonVAlign_Centre);
}
void ButtonWidgetsPage::CreateButton()
{
wxString label;
if ( m_button )
{
label = m_button->GetLabel();
size_t count = m_sizerButton->GetChildren().GetCount();
for ( size_t n = 0; n < count; n++ )
{
m_sizerButton->Remove(0);
}
delete m_button;
}
else
{
label = _T("&Press me!");
}
int flags = 0;
switch ( m_radioHAlign->GetSelection() )
{
case ButtonHAlign_Left:
flags |= wxALIGN_LEFT;
break;
default:
wxFAIL_MSG(_T("unexpected radiobox selection"));
// fall through
case ButtonHAlign_Centre:
flags |= wxALIGN_CENTRE_HORIZONTAL;
break;
case ButtonHAlign_Right:
flags |= wxALIGN_RIGHT;
break;
}
switch ( m_radioVAlign->GetSelection() )
{
case ButtonVAlign_Top:
flags |= wxALIGN_TOP;
break;
default:
wxFAIL_MSG(_T("unexpected radiobox selection"));
// fall through
case ButtonVAlign_Centre:
flags |= wxALIGN_CENTRE_VERTICAL;
break;
case ButtonVAlign_Bottom:
flags |= wxALIGN_BOTTOM;
break;
}
m_button = new wxButton(this, ButtonPage_Button, label,
wxDefaultPosition, wxDefaultSize,
flags);
#ifdef __WXUNIVERSAL__
if ( m_chkImage->GetValue() )
{
m_button->SetImageLabel(wxTheApp->GetStdIcon(wxICON_INFORMATION));
}
#endif // wxUniv
if ( m_chkDefault->GetValue() )
{
m_button->SetDefault();
}
if ( m_chkFit->GetValue() )
{
m_sizerButton->Add(0, 0, 1, wxCENTRE);
m_sizerButton->Add(m_button, 1, wxCENTRE);
m_sizerButton->Add(0, 0, 1, wxCENTRE);
}
else
{
m_sizerButton->Add(m_button, 1, wxGROW | wxALL, 5);
}
m_sizerButton->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void ButtonWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateButton();
}
void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateButton();
}
void ButtonWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event))
{
m_button->SetLabel(m_textLabel->GetValue());
}
void ButtonWidgetsPage::OnButton(wxCommandEvent& event)
{
wxLogMessage(_T("Test button clicked."));
}

View File

@ -0,0 +1,494 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: combobox.cpp
// Purpose: Part of the widgets sample showing wxComboBox
// Author: Vadim Zeitlin
// Created: 27.03.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/combobox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "widgets.h"
#include "icons/combobox.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
ComboPage_Reset = 100,
ComboPage_CurText,
ComboPage_Add,
ComboPage_AddText,
ComboPage_AddSeveral,
ComboPage_AddMany,
ComboPage_Clear,
ComboPage_Change,
ComboPage_ChangeText,
ComboPage_Delete,
ComboPage_DeleteText,
ComboPage_DeleteSel,
ComboPage_Combo
};
// kinds of comboboxes
enum
{
ComboKind_Default,
ComboKind_Simple,
ComboKind_DropDown
};
// ----------------------------------------------------------------------------
// ComboboxWidgetsPage
// ----------------------------------------------------------------------------
class ComboboxWidgetsPage : public WidgetsPage
{
public:
ComboboxWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
protected:
// event handlers
void OnButtonReset(wxCommandEvent& event);
void OnButtonChange(wxCommandEvent& event);
void OnButtonDelete(wxCommandEvent& event);
void OnButtonDeleteSel(wxCommandEvent& event);
void OnButtonClear(wxCommandEvent& event);
void OnButtonAdd(wxCommandEvent& event);
void OnButtonAddSeveral(wxCommandEvent& event);
void OnButtonAddMany(wxCommandEvent& event);
void OnComboBox(wxCommandEvent& event);
void OnComboText(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnUpdateUICurText(wxUpdateUIEvent& event);
void OnUpdateUIAddSeveral(wxUpdateUIEvent& event);
void OnUpdateUIClearButton(wxUpdateUIEvent& event);
void OnUpdateUIDeleteButton(wxUpdateUIEvent& event);
void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event);
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
// reset the combobox parameters
void Reset();
// (re)create the combobox
void CreateCombo();
// the controls
// ------------
// the sel mode radiobox
wxRadioBox *m_radioKind;
// the checkboxes for styles
wxCheckBox *m_chkSort,
*m_chkReadonly;
// the combobox itself and the sizer it is in
wxComboBox *m_combobox;
wxSizer *m_sizerCombo;
// the text entries for "Add/change string" and "Delete" buttons
wxTextCtrl *m_textAdd,
*m_textChange,
*m_textDelete;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(ComboboxWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
EVT_BUTTON(ComboPage_Reset, ComboboxWidgetsPage::OnButtonReset)
EVT_BUTTON(ComboPage_Change, ComboboxWidgetsPage::OnButtonChange)
EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete)
EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel)
EVT_BUTTON(ComboPage_Clear, ComboboxWidgetsPage::OnButtonClear)
EVT_BUTTON(ComboPage_Add, ComboboxWidgetsPage::OnButtonAdd)
EVT_BUTTON(ComboPage_AddSeveral, ComboboxWidgetsPage::OnButtonAddSeveral)
EVT_BUTTON(ComboPage_AddMany, ComboboxWidgetsPage::OnButtonAddMany)
EVT_TEXT_ENTER(ComboPage_AddText, ComboboxWidgetsPage::OnButtonAdd)
EVT_TEXT_ENTER(ComboPage_DeleteText, ComboboxWidgetsPage::OnButtonDelete)
EVT_UPDATE_UI(ComboPage_CurText, ComboboxWidgetsPage::OnUpdateUICurText)
EVT_UPDATE_UI(ComboPage_Reset, ComboboxWidgetsPage::OnUpdateUIResetButton)
EVT_UPDATE_UI(ComboPage_AddSeveral, ComboboxWidgetsPage::OnUpdateUIAddSeveral)
EVT_UPDATE_UI(ComboPage_Clear, ComboboxWidgetsPage::OnUpdateUIClearButton)
EVT_UPDATE_UI(ComboPage_DeleteText, ComboboxWidgetsPage::OnUpdateUIClearButton)
EVT_UPDATE_UI(ComboPage_Delete, ComboboxWidgetsPage::OnUpdateUIDeleteButton)
EVT_UPDATE_UI(ComboPage_Change, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_UPDATE_UI(ComboPage_ChangeText, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_UPDATE_UI(ComboPage_DeleteSel, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_COMBOBOX(ComboPage_Combo, ComboboxWidgetsPage::OnComboBox)
EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
EVT_CHECKBOX(-1, ComboboxWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, ComboboxWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(ComboboxWidgetsPage, _T("Combobox"));
ComboboxWidgetsPage::ComboboxWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(combobox_xpm));
// init everything
m_chkSort =
m_chkReadonly = (wxCheckBox *)NULL;
m_combobox = (wxComboBox *)NULL;
m_sizerCombo = (wxSizer *)NULL;
/*
What we create here is a frame having 3 panes: style pane is the
leftmost one, in the middle the pane with buttons allowing to perform
miscellaneous combobox operations and the pane containing the combobox
itself to the right
*/
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
// should be in sync with ComboKind_XXX values
static const wxString kinds[] =
{
_T("default"),
_T("simple"),
_T("drop down"),
};
m_radioKind = new wxRadioBox(this, -1, _T("Combobox &kind:"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(kinds), kinds,
1, wxRA_SPECIFY_COLS);
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Sort items"));
m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Read only"));
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5);
wxButton *btn = new wxButton(this, ComboPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change combobox contents"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxSizer *sizerRow;
wxTextCtrl *text;
sizerRow = CreateSizerWithTextAndLabel(_T("Current selection"),
ComboPage_CurText,
&text);
text->SetEditable(FALSE);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(ComboPage_Add,
_T("&Add this string"),
ComboPage_AddText,
&m_textAdd);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ComboPage_AddSeveral, _T("&Insert a few strings"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ComboPage_AddMany, _T("Add &many strings"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(ComboPage_Change,
_T("C&hange current"),
ComboPage_ChangeText,
&m_textChange);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(ComboPage_Delete,
_T("&Delete this item"),
ComboPage_DeleteText,
&m_textDelete);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ComboPage_DeleteSel, _T("Delete &selection"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ComboPage_Clear, _T("&Clear"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
m_combobox = new wxComboBox(this, ComboPage_Combo, _T(""),
wxDefaultPosition, wxDefaultSize,
0, NULL,
0);
sizerRight->Add(m_combobox, 1, wxGROW | wxALL, 5);
sizerRight->SetMinSize(250, 0);
m_sizerCombo = sizerRight; // save it to modify it later
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
Reset();
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void ComboboxWidgetsPage::Reset()
{
m_chkSort->SetValue(FALSE);
m_chkReadonly->SetValue(FALSE);
}
void ComboboxWidgetsPage::CreateCombo()
{
int flags = 0;
if ( m_chkSort->GetValue() )
flags |= wxCB_SORT;
if ( m_chkReadonly->GetValue() )
flags |= wxCB_READONLY;
switch ( m_radioKind->GetSelection() )
{
default:
wxFAIL_MSG( _T("unknown combo kind") );
// fall through
case ComboKind_Default:
break;
case ComboKind_Simple:
flags |= wxCB_SIMPLE;
break;
case ComboKind_DropDown:
flags = wxCB_DROPDOWN;
break;
}
wxArrayString items;
if ( m_combobox )
{
int count = m_combobox->GetCount();
for ( int n = 0; n < count; n++ )
{
items.Add(m_combobox->GetString(n));
}
m_sizerCombo->Remove(m_combobox);
delete m_combobox;
}
m_combobox = new wxComboBox(this, ComboPage_Combo, _T(""),
wxDefaultPosition, wxDefaultSize,
0, NULL,
flags);
size_t count = items.GetCount();
for ( size_t n = 0; n < count; n++ )
{
m_combobox->Append(items[n]);
}
m_sizerCombo->Add(m_combobox, 1, wxGROW | wxALL, 5);
m_sizerCombo->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void ComboboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateCombo();
}
void ComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event))
{
int sel = m_combobox->GetSelection();
if ( sel != -1 )
{
#ifndef __WXGTK__
m_combobox->SetString(sel, m_textChange->GetValue());
#else
wxLogMessage(_T("Not implemented in wxGTK"));
#endif
}
}
void ComboboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
{
unsigned long n;
if ( !m_textDelete->GetValue().ToULong(&n) ||
(n >= (unsigned)m_combobox->GetCount()) )
{
return;
}
m_combobox->Delete(n);
}
void ComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event))
{
int sel = m_combobox->GetSelection();
if ( sel != -1 )
{
m_combobox->Delete(sel);
}
}
void ComboboxWidgetsPage::OnButtonClear(wxCommandEvent& event)
{
m_combobox->Clear();
}
void ComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& event)
{
static size_t s_item = 0;
wxString s = m_textAdd->GetValue();
if ( !m_textAdd->IsModified() )
{
// update the default string
m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item));
}
m_combobox->Append(s);
}
void ComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
{
// "many" means 1000 here
for ( size_t n = 0; n < 1000; n++ )
{
m_combobox->Append(wxString::Format(_T("item #%u"), n));
}
}
void ComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& event)
{
m_combobox->Append(_T("First"));
m_combobox->Append(_T("another one"));
m_combobox->Append(_T("and the last (very very very very very very very very very very long) one"));
}
void ComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent& event)
{
event.SetText( wxString::Format(_T("%d"), m_combobox->GetSelection()) );
}
void ComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
{
event.Enable( m_chkSort->GetValue() || m_chkReadonly->GetValue() );
}
void ComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
{
unsigned long n;
event.Enable(m_textDelete->GetValue().ToULong(&n) &&
(n < (unsigned)m_combobox->GetCount()));
}
void ComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event)
{
event.Enable(m_combobox->GetSelection() != -1);
}
void ComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event)
{
event.Enable(m_combobox->GetCount() != 0);
}
void ComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event)
{
event.Enable(!(m_combobox->GetWindowStyle() & wxCB_SORT));
}
void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event)
{
wxString s = event.GetString();
wxASSERT_MSG( s == m_combobox->GetValue(),
_T("event and combobox values should be the same") );
wxLogMessage(_T("Combobox text changed (now '%s')"), s.c_str());
}
void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event)
{
int sel = event.GetInt();
m_textDelete->SetValue(wxString::Format(_T("%ld"), sel));
wxLogMessage(_T("Combobox item %d selected"), sel);
}
void ComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateCombo();
}

402
samples/widgets/gauge.cpp Normal file
View File

@ -0,0 +1,402 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: gauge.cpp
// Purpose: Part of the widgets sample showing wxGauge
// Author: Vadim Zeitlin
// Created: 27.03.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/timer.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/combobox.h"
#include "wx/gauge.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "widgets.h"
#include "icons/gauge.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
GaugePage_Reset = 100,
GaugePage_Progress,
GaugePage_Clear,
GaugePage_SetValue,
GaugePage_SetRange,
GaugePage_CurValueText,
GaugePage_ValueText,
GaugePage_RangeText,
GaugePage_Timer,
GaugePage_Gauge
};
// ----------------------------------------------------------------------------
// GaugeWidgetsPage
// ----------------------------------------------------------------------------
class GaugeWidgetsPage : public WidgetsPage
{
public:
GaugeWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~GaugeWidgetsPage();
protected:
// event handlers
void OnButtonReset(wxCommandEvent& event);
void OnButtonProgress(wxCommandEvent& event);
void OnButtonClear(wxCommandEvent& event);
void OnButtonSetValue(wxCommandEvent& event);
void OnButtonSetRange(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnUpdateUIValueButton(wxUpdateUIEvent& event);
void OnUpdateUIRangeButton(wxUpdateUIEvent& event);
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
void OnUpdateUICurValueText(wxUpdateUIEvent& event);
void OnProgressTimer(wxTimerEvent& event);
// reset the gauge parameters
void Reset();
// (re)create the gauge
void CreateGauge();
// stop the progress timer
void StopTimer();
// the gauge range
unsigned long m_range;
// the controls
// ------------
// the checkboxes for styles
wxCheckBox *m_chkVert,
*m_chkSmooth;
// the gauge itself and the sizer it is in
wxGauge *m_gauge;
wxSizer *m_sizerGauge;
// the text entries for set value/range
wxTextCtrl *m_textValue,
*m_textRange;
// the timer for simulating gauge progress
wxTimer *m_timer;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(GaugeWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(GaugeWidgetsPage, WidgetsPage)
EVT_BUTTON(GaugePage_Reset, GaugeWidgetsPage::OnButtonReset)
EVT_BUTTON(GaugePage_Progress, GaugeWidgetsPage::OnButtonProgress)
EVT_BUTTON(GaugePage_Clear, GaugeWidgetsPage::OnButtonClear)
EVT_BUTTON(GaugePage_SetValue, GaugeWidgetsPage::OnButtonSetValue)
EVT_BUTTON(GaugePage_SetRange, GaugeWidgetsPage::OnButtonSetRange)
EVT_UPDATE_UI(GaugePage_SetValue, GaugeWidgetsPage::OnUpdateUIValueButton)
EVT_UPDATE_UI(GaugePage_SetRange, GaugeWidgetsPage::OnUpdateUIRangeButton)
EVT_UPDATE_UI(GaugePage_Reset, GaugeWidgetsPage::OnUpdateUIResetButton)
EVT_UPDATE_UI(GaugePage_CurValueText, GaugeWidgetsPage::OnUpdateUICurValueText)
EVT_CHECKBOX(-1, GaugeWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, GaugeWidgetsPage::OnCheckOrRadioBox)
EVT_TIMER(GaugePage_Timer, GaugeWidgetsPage::OnProgressTimer)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(GaugeWidgetsPage, _T("Gauge"));
GaugeWidgetsPage::GaugeWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(gauge_xpm));
// init everything
m_range = 100;
m_timer = (wxTimer *)NULL;
m_chkVert =
m_chkSmooth = (wxCheckBox *)NULL;
m_gauge = (wxGauge *)NULL;
m_sizerGauge = (wxSizer *)NULL;
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Vertical"));
m_chkSmooth = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Smooth"));
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
wxButton *btn = new wxButton(this, GaugePage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change gauge value"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxTextCtrl *text;
wxSizer *sizerRow = CreateSizerWithTextAndLabel(_T("Current value"),
GaugePage_CurValueText,
&text);
text->SetEditable(FALSE);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(GaugePage_SetValue,
_T("Set &value"),
GaugePage_ValueText,
&m_textValue);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(GaugePage_SetRange,
_T("Set &range"),
GaugePage_RangeText,
&m_textRange);
m_textRange->SetValue(wxString::Format(_T("%lu"), m_range));
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, GaugePage_Progress, _T("Simulate &progress"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, GaugePage_Clear, _T("&Clear"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
m_gauge = new wxGauge(this, GaugePage_Gauge, m_range);
sizerRight->Add(m_gauge, 1, wxCENTRE | wxALL, 5);
sizerRight->SetMinSize(250, 0);
m_sizerGauge = sizerRight; // save it to modify it later
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
Reset();
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
GaugeWidgetsPage::~GaugeWidgetsPage()
{
delete m_timer;
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void GaugeWidgetsPage::Reset()
{
m_chkVert->SetValue(FALSE);
m_chkSmooth->SetValue(FALSE);
}
void GaugeWidgetsPage::CreateGauge()
{
int flags = 0;
if ( m_chkVert->GetValue() )
flags |= wxGA_VERTICAL;
else
flags |= wxGA_HORIZONTAL;
if ( m_chkSmooth->GetValue() )
flags |= wxGA_SMOOTH;
int val = 0;
if ( m_gauge )
{
val = m_gauge->GetValue();
m_sizerGauge->Remove(m_gauge);
delete m_gauge;
}
m_gauge = new wxGauge(this, GaugePage_Gauge, m_range,
wxDefaultPosition, wxDefaultSize,
flags);
m_gauge->SetValue(val);
if ( flags & wxGA_VERTICAL )
m_sizerGauge->Add(m_gauge, 0, wxGROW | wxALL, 5);
else
m_sizerGauge->Add(m_gauge, 1, wxCENTRE | wxALL, 5);
m_sizerGauge->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void GaugeWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateGauge();
}
void GaugeWidgetsPage::OnButtonProgress(wxCommandEvent& event)
{
if ( !m_timer )
{
static const int INTERVAL = 300;
wxLogMessage(_T("Launched progress timer (interval = %d ms)"), INTERVAL);
m_timer = new wxTimer(this, GaugePage_Timer);
m_timer->Start(INTERVAL);
wxButton *btn = (wxButton *)event.GetEventObject();
btn->SetLabel(_T("&Stop timer"));
}
else // stop the running timer
{
StopTimer();
wxLogMessage(_T("Stopped the timer."));
}
}
void GaugeWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event))
{
m_gauge->SetValue(0);
}
void GaugeWidgetsPage::OnButtonSetRange(wxCommandEvent& WXUNUSED(event))
{
unsigned long val;
if ( !m_textRange->GetValue().ToULong(&val) )
return;
m_gauge->SetRange(val);
}
void GaugeWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
{
unsigned long val;
if ( !m_textValue->GetValue().ToULong(&val) )
return;
m_gauge->SetValue(val);
}
void GaugeWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
{
unsigned long val;
event.Enable( m_textValue->GetValue().ToULong(&val) && (val <= m_range) );
}
void GaugeWidgetsPage::OnUpdateUIRangeButton(wxUpdateUIEvent& event)
{
unsigned long val;
event.Enable( m_textRange->GetValue().ToULong(&val) );
}
void GaugeWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
{
event.Enable( m_chkVert->GetValue() || m_chkSmooth->GetValue() );
}
void GaugeWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateGauge();
}
void GaugeWidgetsPage::OnProgressTimer(wxTimerEvent& WXUNUSED(event))
{
int val = m_gauge->GetValue();
if ( (unsigned)val < m_range )
{
m_gauge->SetValue(val + 1);
}
else // reached the end
{
StopTimer();
}
}
void GaugeWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
{
event.SetText( wxString::Format(_T("%d"), m_gauge->GetValue()));
}
void GaugeWidgetsPage::StopTimer()
{
wxCHECK_RET( m_timer, _T("shouldn't be called") );
m_timer->Stop();
delete m_timer;
m_timer = NULL;
wxButton *btn = (wxButton *)FindWindow(GaugePage_Progress);
wxCHECK_RET( btn, _T("no progress button?") );
btn->SetLabel(_T("Simulate &progress"));
wxLogMessage(_T("Progress finished."));
}

View File

@ -0,0 +1 @@
*.bmp

View File

@ -0,0 +1,37 @@
/* XPM */
static char *magick[] = {
/* columns rows colors chars-per-pixel */
"16 15 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #808080",
"$ c #c0c0c0",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
" ",
" $$$$$$$$$$$$$$ ",
" $$$# #$$$# #$ ",
" $$$ $ $$$ $$ $ ",
" $# $ $$$ $$ $ ",
" $ $ $ $# #$ ",
" $ $ $ $ $$$$$ ",
" $# $$ $ $$$$$ ",
" $ $ ",
" $$$ $$ $$$$$$$ ",
" $$$ $ $$ $ $ ",
" $$$ $ $ $$ $$$ ",
" $$ $ $$$ ",
" $ $$$$$$$$$ ",
" "
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *button_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"##### #####",
"#### :::::::::::::::::::::: ####",
"### :::::::::::::::::::::::$ ###",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"## ::######################$$ ##",
"### $$$$$$$$$$$$$$$$$$$$$$$$ ###",
"#### $$$$$$$$$$$$$$$$$$$$$$ ####",
"##### #####",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *checkbox_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"#####$$$$$$$$$$$$$$$$$$$$$$#####",
"####$ #:####",
"####$ ::::::::::::::::::::#:####",
"####$ ::::::::::::::::::::#:####",
"####$ ::::::::::::::::::::#:####",
"####$ ::: :::::::::: :::#:####",
"####$ ::: :::::::: :::#:####",
"####$ :::: :::::: ::::#:####",
"####$ ::::: :::: :::::#:####",
"####$ :::::: :: ::::::#:####",
"####$ ::::::: :::::::#:####",
"####$ :::::::: ::::::::#:####",
"####$ :::::::: ::::::::#:####",
"####$ ::::::: :::::::#:####",
"####$ :::::: :: ::::::#:####",
"####$ ::::: :::: :::::#:####",
"####$ :::: :::::: ::::#:####",
"####$ ::: :::::::: :::#:####",
"####$ ::: :::::::::: :::#:####",
"####$ ::::::::::::::::::::#:####",
"####$ ::::::::::::::::::::#:####",
"####$ ::::::::::::::::::::#:####",
"####$ #####################:####",
"#####::::::::::::::::::::::#####",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *combobox_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"## ##",
"## ################ ##",
"## ################ ##### ##",
"## ################ ### ##",
"## ################ # ##",
"## ################ ##",
"## ##",
"#### ############## ######### ##",
"#### ############## ######### ##",
"#### ############## #### #### ##",
"#### ############## ### ### ##",
"#### ## ##### ## ## ##",
"#### ############## ######### ##",
"#### ## #### ######### ##",
"#### ############## ######### ##",
"#### ## ### ##",
"#### ############## ######### ##",
"#### ## #### ######### ##",
"#### ############## ######### ##",
"#### ## ##### ## ## ##",
"#### ############## ### ### ##",
"#### ## #### #### #### ##",
"#### ############## ######### ##",
"#### ############## ######### ##",
"#### ############## ######### ##",
"#### ##",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *gauge_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"## ##",
"## $$$$$$$$$$$$$$$$$::::::::: ##",
"## $$$$$$$$$$$$$$$$$::::::::: ##",
"## $$$$$$$$$$$$$$$$$::::::::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$ $$$$$ $$$$$ :::: :::: ##",
"## $$$$$$$$$$$$$$$$$::::::::: ##",
"## $$$$$$$$$$$$$$$$$::::::::: ##",
"## $$$$$$$$$$$$$$$$$::::::::: ##",
"## ##",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *listbox_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"### ###",
"### ############## ######### ###",
"### ############## ######### ###",
"### ############## #### #### ###",
"### ############## ### ### ###",
"### ## ##### ## ## ###",
"### ############## ######### ###",
"### ## #### ######### ###",
"### ############## ######### ###",
"### ## ### ###",
"### ############## ######### ###",
"### ## #### ######### ###",
"### ############## ######### ###",
"### ## ##### ## ## ###",
"### ############## ### ### ###",
"### ## #### #### #### ###",
"### ############## ######### ###",
"### ############## ######### ###",
"### ############## ######### ###",
"### ###",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *notebook_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"### # # ###",
"## :::::::$ :::::::$ :::::::$ ##",
"## :######$ :######$ :######$ ##",
"## :######$ :######$ :######$ ##",
"## :######$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## :########################$ ##",
"## $$$$$$$$$$$$$$$$$$$$$$$$$$ ##",
"## ##",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *radio_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"###########$$$$$$$$$#:##########",
"#########$$$ $$#:#########",
"########$$ $:::::: $::########",
"#######$$ :::::::::::#$::#######",
"######$$ :::::::::::::#$::######",
"#####$$ :::::::::::::::#$::#####",
"####$$ ::::::#####::::::#$:#####",
"####$ $:::::$ $#:::::$#:####",
"###$$ :::::$ $#::::$#:####",
"###$ :::::$ $:::::$:####",
"###$ ::::: #::::$:####",
"###$ ::::: #::::$:####",
"###$ ::::: #::::$:####",
"###$ ::::: #::::$:####",
"###$ ::::: #::::$:####",
"###$ :::::$ $:::::$:####",
"###$$ :::::$ $#::::$#:####",
"####$ ::::::$ $#:::::$#:####",
"####$$#::::::#####::::::$#:#####",
"####:$$#:::::::::::::::$#:######",
"#####:$$$:::::::::::::$#:#######",
"######:$$$:::::::::::$#:########",
"#######::$$$::::::$$$::#########",
"#########:$$$$$$$$$::###########",
"###########::::::::#############",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *magick[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"## ###",
"## ############ ############ ###",
"## ############ ############ ###",
"## ############ ############ ###",
"## ####### #### #### ####### ###",
"## ###### #### #### ###### ###",
"## ##### #### #### ##### ###",
"## #### #### #### #### ###",
"## ### #### #### ### ###",
"## #### #### #### #### ###",
"## ##### #### #### ##### ###",
"## ###### #### #### ###### ###",
"## ####### #### #### ####### ###",
"## ############ ############ ###",
"## ############ ############ ###",
"## ############ ############ ###",
"## ###",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *slider_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"####### ###################",
"###### :::::$ ##################",
"###### :####$ ##################",
"###### :####$ ##################",
"###### :####$ ##################",
"###### :####$ ##################",
"###### :####$ ##################",
"## :####$ ##",
"## $$$ :####$ $$$$$$$$$$$$$$$ ##",
"## ### :####$ ############### ##",
"## ### :####$ ############### ##",
"## ### :####$ ############### ##",
"###### :####$ ##################",
"###### :####$ ##################",
"###### :$$$$$ ##################",
"####### ###################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,40 @@
/* XPM */
static char *spinbtn_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 2 1",
"$ c None",
" c Black",
/* pixels */
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$ $$$$",
"$$ $$$$",
"$$ $$$$$$$$$$ $$$$$$$$$$ $$$$",
"$$ $$$$$$$$$$ $$$$$$$$$$ $$$$",
"$$ $$$$$$ $$ $$ $$$$$$ $$$$",
"$$ $$$$$$ $$ $$ $$$$$$ $$$$",
"$$ $$$$ $$ $$ $$$$ $$$$",
"$$ $$$$ $$ $$ $$$$ $$$$",
"$$ $$ $$ $$ $$ $$$$",
"$$ $$ $$ $$ $$ $$$$",
"$$ $$$$ $$ $$ $$$$ $$$$",
"$$ $$$$ $$ $$ $$$$ $$$$",
"$$ $$$$$$ $$ $$ $$$$$$ $$$$",
"$$ $$$$$$ $$ $$ $$$$$$ $$$$",
"$$ $$$$$$$$$$ $$$$$$$$$$ $$$$",
"$$ $$$$$$$$$$ $$$$$$$$$$ $$$$",
"$$ $$$$",
"$$ $$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *statbox_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"######## ### # ### # ########",
"######## ### # ### #### ########",
"######### # ### # #### #########",
"## #### ##### #### #### ##",
"## ###### # #### ### ######## ##",
"## ##### ### ### ### ######## ##",
"## ##### ### ### ### ##### ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ########################## ##",
"## ##",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *stattext_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"############### ################",
"############## ################",
"############# ################",
"############ ################",
"###########$ ################",
"##########$ # ################",
"########## ## ######## # #",
"######### ## ###### # ##",
"########$ ### ###### ### ##",
"#######$ #### ##### #### ##",
"####### ##### #### ### ##",
"######$ #### ### ###",
"#####$ ###### ### #### ###",
"####$ ####### ### ### ###",
"#### ######## ### ### ####",
"### ######## ### ## ####",
"## ######### ## # ##",
"# ##### # ## ###",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"
};

View File

@ -0,0 +1,54 @@
/* XPM */
static char *text_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 16 1",
" c Gray0",
". c #808000",
"X c #000080",
"o c #808080",
"O c #000000",
"+ c #808000",
"@ c #000080",
"# c #c0c0c0",
"$ c #808080",
"% c Red",
"& c Green",
"* c Yellow",
"= c Blue",
"- c Magenta",
"; c Cyan",
": c Gray100",
/* pixels */
"################################",
"################################",
"################################",
"################################",
"################################",
"############################ ###",
"############################ ###",
"############### ########## ###",
"############### ########## ###",
"############### ########## ###",
"############### ########## ###",
"############### ########## ###",
"############### ########## ###",
"#### ### #### ###",
"### ##### ## #### ### ###",
"### ##### ## #### ### ###",
"###### ## #### ### ###",
"#### ## #### ### ###",
"### #### ## #### ### ###",
"### #### ## #### ### ###",
"### #### ## #### ### ###",
"### #### ## #### ### ###",
"### #### ## #### ### ###",
"### #### ## #### ### ###",
"#### ## #### ###",
"############################ ###",
"############################ ###",
"################################",
"################################",
"################################",
"################################",
"################################"
};

512
samples/widgets/listbox.cpp Normal file
View File

@ -0,0 +1,512 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: listbox.cpp
// Purpose: Part of the widgets sample showing wxListbox
// Author: Vadim Zeitlin
// Created: 27.03.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/combobox.h"
#include "wx/listbox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "wx/checklst.h"
#include "widgets.h"
#include "icons/listbox.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
ListboxPage_Reset = 100,
ListboxPage_Add,
ListboxPage_AddText,
ListboxPage_AddSeveral,
ListboxPage_AddMany,
ListboxPage_Clear,
ListboxPage_Change,
ListboxPage_ChangeText,
ListboxPage_Delete,
ListboxPage_DeleteText,
ListboxPage_DeleteSel,
ListboxPage_Listbox
};
// ----------------------------------------------------------------------------
// ListboxWidgetsPage
// ----------------------------------------------------------------------------
class ListboxWidgetsPage : public WidgetsPage
{
public:
ListboxWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
protected:
// event handlers
void OnButtonReset(wxCommandEvent& event);
void OnButtonChange(wxCommandEvent& event);
void OnButtonDelete(wxCommandEvent& event);
void OnButtonDeleteSel(wxCommandEvent& event);
void OnButtonClear(wxCommandEvent& event);
void OnButtonAdd(wxCommandEvent& event);
void OnButtonAddSeveral(wxCommandEvent& event);
void OnButtonAddMany(wxCommandEvent& event);
void OnListbox(wxCommandEvent& event);
void OnListboxDClick(wxCommandEvent& event);
void OnCheckListbox(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnUpdateUIAddSeveral(wxUpdateUIEvent& event);
void OnUpdateUIClearButton(wxUpdateUIEvent& event);
void OnUpdateUIDeleteButton(wxUpdateUIEvent& event);
void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event);
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
// reset the listbox parameters
void Reset();
// (re)create the listbox
void CreateLbox();
// listbox parameters
// ------------------
// the selection mode
enum LboxSelection
{
LboxSel_Single,
LboxSel_Extended,
LboxSel_Multiple
} m_lboxSelMode;
// should it be sorted?
bool m_sorted;
// should it have horz scroll/vert scrollbar permanently shown?
bool m_horzScroll,
m_vertScrollAlways;
// the controls
// ------------
// the sel mode radiobox
wxRadioBox *m_radioSelMode;
// the checkboxes
wxCheckBox *m_chkSort,
*m_chkCheck,
*m_chkHScroll,
*m_chkVScroll;
// the listbox itself and the sizer it is in
wxListBox *m_lbox;
wxSizer *m_sizerLbox;
// the text entries for "Add/change string" and "Delete" buttons
wxTextCtrl *m_textAdd,
*m_textChange,
*m_textDelete;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(ListboxWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(ListboxWidgetsPage, WidgetsPage)
EVT_BUTTON(ListboxPage_Reset, ListboxWidgetsPage::OnButtonReset)
EVT_BUTTON(ListboxPage_Change, ListboxWidgetsPage::OnButtonChange)
EVT_BUTTON(ListboxPage_Delete, ListboxWidgetsPage::OnButtonDelete)
EVT_BUTTON(ListboxPage_DeleteSel, ListboxWidgetsPage::OnButtonDeleteSel)
EVT_BUTTON(ListboxPage_Clear, ListboxWidgetsPage::OnButtonClear)
EVT_BUTTON(ListboxPage_Add, ListboxWidgetsPage::OnButtonAdd)
EVT_BUTTON(ListboxPage_AddSeveral, ListboxWidgetsPage::OnButtonAddSeveral)
EVT_BUTTON(ListboxPage_AddMany, ListboxWidgetsPage::OnButtonAddMany)
EVT_TEXT_ENTER(ListboxPage_AddText, ListboxWidgetsPage::OnButtonAdd)
EVT_TEXT_ENTER(ListboxPage_DeleteText, ListboxWidgetsPage::OnButtonDelete)
EVT_UPDATE_UI(ListboxPage_Reset, ListboxWidgetsPage::OnUpdateUIResetButton)
EVT_UPDATE_UI(ListboxPage_AddSeveral, ListboxWidgetsPage::OnUpdateUIAddSeveral)
EVT_UPDATE_UI(ListboxPage_Clear, ListboxWidgetsPage::OnUpdateUIClearButton)
EVT_UPDATE_UI(ListboxPage_DeleteText, ListboxWidgetsPage::OnUpdateUIClearButton)
EVT_UPDATE_UI(ListboxPage_Delete, ListboxWidgetsPage::OnUpdateUIDeleteButton)
EVT_UPDATE_UI(ListboxPage_Change, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_UPDATE_UI(ListboxPage_ChangeText, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_UPDATE_UI(ListboxPage_DeleteSel, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
EVT_LISTBOX(ListboxPage_Listbox, ListboxWidgetsPage::OnListbox)
EVT_LISTBOX_DCLICK(ListboxPage_Listbox, ListboxWidgetsPage::OnListboxDClick)
EVT_CHECKLISTBOX(ListboxPage_Listbox, ListboxWidgetsPage::OnCheckListbox)
EVT_CHECKBOX(-1, ListboxWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, ListboxWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(ListboxWidgetsPage, _T("Listbox"));
ListboxWidgetsPage::ListboxWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(listbox_xpm));
// init everything
m_radioSelMode = (wxRadioBox *)NULL;
m_chkVScroll =
m_chkHScroll =
m_chkCheck =
m_chkSort = (wxCheckBox *)NULL;
m_lbox = (wxListBox *)NULL;
m_sizerLbox = (wxSizer *)NULL;
/*
What we create here is a frame having 3 panes: style pane is the
leftmost one, in the middle the pane with buttons allowing to perform
miscellaneous listbox operations and the pane containing the listbox
itself to the right
*/
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set listbox parameters"));
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
static const wxString modes[] =
{
_T("single"),
_T("extended"),
_T("multiple"),
};
m_radioSelMode = new wxRadioBox(this, -1, _T("Selection &mode:"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(modes), modes,
1, wxRA_SPECIFY_COLS);
m_chkVScroll = CreateCheckBoxAndAddToSizer
(
sizerLeft,
_T("Always show &vertical scrollbar")
);
m_chkHScroll = CreateCheckBoxAndAddToSizer
(
sizerLeft,
_T("Show &horizontal scrollbar")
);
m_chkCheck = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Check list box"));
m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Sort items"));
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
sizerLeft->Add(m_radioSelMode, 0, wxGROW | wxALL, 5);
wxButton *btn = new wxButton(this, ListboxPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change listbox contents"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
btn = new wxButton(this, ListboxPage_Add, _T("&Add this string"));
m_textAdd = new wxTextCtrl(this, ListboxPage_AddText, _T("test item 0"));
sizerRow->Add(btn, 0, wxRIGHT, 5);
sizerRow->Add(m_textAdd, 1, wxLEFT, 5);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ListboxPage_AddSeveral, _T("&Insert a few strings"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ListboxPage_AddMany, _T("Add &many strings"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
sizerRow = new wxBoxSizer(wxHORIZONTAL);
btn = new wxButton(this, ListboxPage_Change, _T("C&hange current"));
m_textChange = new wxTextCtrl(this, ListboxPage_ChangeText, _T(""));
sizerRow->Add(btn, 0, wxRIGHT, 5);
sizerRow->Add(m_textChange, 1, wxLEFT, 5);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = new wxBoxSizer(wxHORIZONTAL);
btn = new wxButton(this, ListboxPage_Delete, _T("&Delete this item"));
m_textDelete = new wxTextCtrl(this, ListboxPage_DeleteText, _T(""));
sizerRow->Add(btn, 0, wxRIGHT, 5);
sizerRow->Add(m_textDelete, 1, wxLEFT, 5);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ListboxPage_DeleteSel, _T("Delete &selection"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, ListboxPage_Clear, _T("&Clear"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
m_lbox = new wxListBox(this, ListboxPage_Listbox,
wxDefaultPosition, wxDefaultSize,
0, NULL,
wxLB_HSCROLL);
sizerRight->Add(m_lbox, 1, wxGROW | wxALL, 5);
sizerRight->SetMinSize(250, 0);
m_sizerLbox = sizerRight; // save it to modify it later
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
Reset();
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void ListboxWidgetsPage::Reset()
{
m_radioSelMode->SetSelection(LboxSel_Single);
m_chkSort->SetValue(FALSE);
m_chkCheck->SetValue(FALSE);
m_chkHScroll->SetValue(TRUE);
m_chkVScroll->SetValue(FALSE);
}
void ListboxWidgetsPage::CreateLbox()
{
int flags = 0;
switch ( m_radioSelMode->GetSelection() )
{
default:
wxFAIL_MSG( _T("unexpected radio box selection") );
case LboxSel_Single: flags |= wxLB_SINGLE; break;
case LboxSel_Extended: flags |= wxLB_EXTENDED; break;
case LboxSel_Multiple: flags |= wxLB_MULTIPLE; break;
}
if ( m_chkVScroll->GetValue() )
flags |= wxLB_ALWAYS_SB;
if ( m_chkHScroll->GetValue() )
flags |= wxLB_HSCROLL;
if ( m_chkSort->GetValue() )
flags |= wxLB_SORT;
wxArrayString items;
if ( m_lbox )
{
int count = m_lbox->GetCount();
for ( int n = 0; n < count; n++ )
{
items.Add(m_lbox->GetString(n));
}
m_sizerLbox->Remove(m_lbox);
delete m_lbox;
}
if ( m_chkCheck->GetValue() )
{
m_lbox = new wxCheckListBox(this, ListboxPage_Listbox,
wxDefaultPosition, wxDefaultSize,
0, NULL,
flags);
}
else // just a listbox
{
m_lbox = new wxListBox(this, ListboxPage_Listbox,
wxDefaultPosition, wxDefaultSize,
0, NULL,
flags);
}
m_lbox->Set(items);
m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5);
m_sizerLbox->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void ListboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateLbox();
}
void ListboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event))
{
wxArrayInt selections;
int count = m_lbox->GetSelections(selections);
wxString s = m_textChange->GetValue();
for ( int n = 0; n < count; n++ )
{
m_lbox->SetString(selections[n], s);
}
}
void ListboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
{
unsigned long n;
if ( !m_textDelete->GetValue().ToULong(&n) ||
(n >= (unsigned)m_lbox->GetCount()) )
{
return;
}
m_lbox->Delete(n);
}
void ListboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event))
{
wxArrayInt selections;
int n = m_lbox->GetSelections(selections);
while ( n > 0 )
{
m_lbox->Delete(selections[--n]);
}
}
void ListboxWidgetsPage::OnButtonClear(wxCommandEvent& event)
{
m_lbox->Clear();
}
void ListboxWidgetsPage::OnButtonAdd(wxCommandEvent& event)
{
static size_t s_item = 0;
wxString s = m_textAdd->GetValue();
if ( !m_textAdd->IsModified() )
{
// update the default string
m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item));
}
m_lbox->Append(s);
}
void ListboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
{
// "many" means 1000 here
for ( size_t n = 0; n < 1000; n++ )
{
m_lbox->Append(wxString::Format(_T("item #%u"), n));
}
}
void ListboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& event)
{
wxArrayString items;
items.Add(_T("First"));
items.Add(_T("another one"));
items.Add(_T("and the last (very very very very very very very very very very long) one"));
m_lbox->InsertItems(items, 0);
}
void ListboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
{
event.Enable( (m_radioSelMode->GetSelection() != LboxSel_Single) ||
m_chkSort->GetValue() ||
!m_chkHScroll->GetValue() ||
m_chkVScroll->GetValue() );
}
void ListboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
{
unsigned long n;
event.Enable(m_textDelete->GetValue().ToULong(&n) &&
(n < (unsigned)m_lbox->GetCount()));
}
void ListboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event)
{
wxArrayInt selections;
event.Enable(m_lbox->GetSelections(selections) != 0);
}
void ListboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event)
{
event.Enable(m_lbox->GetCount() != 0);
}
void ListboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event)
{
event.Enable(!(m_lbox->GetWindowStyle() & wxLB_SORT));
}
void ListboxWidgetsPage::OnListbox(wxCommandEvent& event)
{
int sel = event.GetInt();
m_textDelete->SetValue(wxString::Format(_T("%ld"), sel));
wxLogMessage(_T("Listbox item %d selected"), sel);
}
void ListboxWidgetsPage::OnListboxDClick(wxCommandEvent& event)
{
wxLogMessage(_T("Listbox item %d double clicked"), event.GetInt());
}
void ListboxWidgetsPage::OnCheckListbox(wxCommandEvent& event)
{
wxLogMessage(_T("Listbox item %d toggled"), event.GetInt());
}
void ListboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateLbox();
}

View File

@ -0,0 +1,543 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: notebook.cpp
// Purpose: Part of the widgets sample showing wxNotebook
// Author: Vadim Zeitlin
// Created: 06.04.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/combobox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#include "wx/dynarray.h"
#endif
#include "wx/sizer.h"
#include "wx/notebook.h"
#include "widgets.h"
#include "icons/notebook.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
NotebookPage_Reset = 100,
NotebookPage_SelectPage,
NotebookPage_AddPage,
NotebookPage_InsertPage,
NotebookPage_RemovePage,
NotebookPage_DeleteAll,
NotebookPage_InsertText,
NotebookPage_RemoveText,
NotebookPage_SelectText,
NotebookPage_NumPagesText,
NotebookPage_CurSelectText,
NotebookPage_Notebook
};
// notebook orientations
enum Orient
{
Orient_Top,
Orient_Bottom,
Orient_Left,
Orient_Right,
Orient_Max
};
// old versions of wxWindows don't define this style
#ifndef wxNB_TOP
#define wxNB_TOP (0)
#endif
// ----------------------------------------------------------------------------
// NotebookWidgetsPage
// ----------------------------------------------------------------------------
class NotebookWidgetsPage : public WidgetsPage
{
public:
NotebookWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~NotebookWidgetsPage();
protected:
// event handlers
void OnPageChanging(wxNotebookEvent& event);
void OnPageChanged(wxNotebookEvent& event);
void OnButtonReset(wxCommandEvent& event);
void OnButtonDeleteAll(wxCommandEvent& event);
void OnButtonSelectPage(wxCommandEvent& event);
void OnButtonAddPage(wxCommandEvent& event);
void OnButtonInsertPage(wxCommandEvent& event);
void OnButtonRemovePage(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnUpdateUINumPagesText(wxUpdateUIEvent& event);
void OnUpdateUICurSelectText(wxUpdateUIEvent& event);
void OnUpdateUISelectButton(wxUpdateUIEvent& event);
void OnUpdateUIInsertButton(wxUpdateUIEvent& event);
void OnUpdateUIRemoveButton(wxUpdateUIEvent& event);
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
// reset the wxNotebook parameters
void Reset();
// (re)create the wxNotebook
void CreateNotebook();
// create or destroy the image list
void CreateImageList();
// create a new page
wxWindow *CreateNewPage();
// get the image index for the new page
int GetIconIndex() const;
// get the numeric value of text ctrl
int GetTextValue(wxTextCtrl *text) const;
// the controls
// ------------
// the check/radio boxes for styles
wxCheckBox *m_chkImages;
wxRadioBox *m_radioOrient;
// the text controls containing input for various commands
wxTextCtrl *m_textInsert,
*m_textRemove,
*m_textSelect;
// the notebook itself and the sizer it is in
wxNotebook *m_notebook;
wxSizer *m_sizerNotebook;
// thei mage list for our notebook
wxImageList *m_imageList;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(NotebookWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(NotebookWidgetsPage, WidgetsPage)
EVT_BUTTON(NotebookPage_Reset, NotebookWidgetsPage::OnButtonReset)
EVT_BUTTON(NotebookPage_SelectPage, NotebookWidgetsPage::OnButtonSelectPage)
EVT_BUTTON(NotebookPage_AddPage, NotebookWidgetsPage::OnButtonAddPage)
EVT_BUTTON(NotebookPage_InsertPage, NotebookWidgetsPage::OnButtonInsertPage)
EVT_BUTTON(NotebookPage_RemovePage, NotebookWidgetsPage::OnButtonRemovePage)
EVT_BUTTON(NotebookPage_DeleteAll, NotebookWidgetsPage::OnButtonDeleteAll)
EVT_UPDATE_UI(NotebookPage_NumPagesText, NotebookWidgetsPage::OnUpdateUINumPagesText)
EVT_UPDATE_UI(NotebookPage_CurSelectText, NotebookWidgetsPage::OnUpdateUICurSelectText)
EVT_UPDATE_UI(NotebookPage_SelectPage, NotebookWidgetsPage::OnUpdateUISelectButton)
EVT_UPDATE_UI(NotebookPage_InsertPage, NotebookWidgetsPage::OnUpdateUIInsertButton)
EVT_UPDATE_UI(NotebookPage_RemovePage, NotebookWidgetsPage::OnUpdateUIRemoveButton)
EVT_NOTEBOOK_PAGE_CHANGING(-1, NotebookWidgetsPage::OnPageChanging)
EVT_NOTEBOOK_PAGE_CHANGED(-1, NotebookWidgetsPage::OnPageChanged)
EVT_CHECKBOX(-1, NotebookWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, NotebookWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(NotebookWidgetsPage, _T("Notebook"));
NotebookWidgetsPage::NotebookWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(notebook_xpm));
// init everything
m_chkImages = NULL;
m_imageList = NULL;
m_notebook = (wxNotebook *)NULL;
m_sizerNotebook = (wxSizer *)NULL;
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
// must be in sync with Orient enum
wxString orientations[] =
{
_T("&top"),
_T("&bottom"),
_T("&left"),
_T("&right"),
};
wxASSERT_MSG( WXSIZEOF(orientations) == Orient_Max,
_T("forgot to update something") );
m_chkImages = new wxCheckBox(this, -1, _T("Show &images"));
m_radioOrient = new wxRadioBox(this, -1, _T("&Tab orientation"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(orientations), orientations,
1, wxRA_SPECIFY_COLS);
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
sizerLeft->Add(m_chkImages, 0, wxALL, 5);
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
sizerLeft->Add(m_radioOrient, 0, wxALL, 5);
wxButton *btn = new wxButton(this, NotebookPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Contents"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxTextCtrl *text;
wxSizer *sizerRow = CreateSizerWithTextAndLabel(_T("Number of pages: "),
NotebookPage_NumPagesText,
&text);
text->SetEditable(FALSE);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndLabel(_T("Current selection: "),
NotebookPage_CurSelectText,
&text);
text->SetEditable(FALSE);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(NotebookPage_SelectPage,
_T("&Select page"),
NotebookPage_SelectText,
&m_textSelect);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, NotebookPage_AddPage, _T("&Add page"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(NotebookPage_InsertPage,
_T("&Insert page at"),
NotebookPage_InsertText,
&m_textInsert);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(NotebookPage_RemovePage,
_T("&Remove page"),
NotebookPage_RemoveText,
&m_textRemove);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, NotebookPage_DeleteAll, _T("&Delete All"));
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
m_notebook = new wxNotebook(this, NotebookPage_Notebook);
sizerRight->Add(m_notebook, 1, wxGROW | wxALL, 5);
sizerRight->SetMinSize(250, 0);
m_sizerNotebook = sizerRight; // save it to modify it later
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
Reset();
CreateImageList();
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
NotebookWidgetsPage::~NotebookWidgetsPage()
{
delete m_imageList;
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void NotebookWidgetsPage::Reset()
{
m_chkImages->SetValue(TRUE);
m_radioOrient->SetSelection(Orient_Top);
}
void NotebookWidgetsPage::CreateImageList()
{
if ( m_chkImages->GetValue() )
{
if ( !m_imageList )
{
// create a dummy image list with a few icons
m_imageList = new wxImageList(32, 32);
m_imageList->Add(wxTheApp->GetStdIcon(wxICON_INFORMATION));
m_imageList->Add(wxTheApp->GetStdIcon(wxICON_QUESTION));
m_imageList->Add(wxTheApp->GetStdIcon(wxICON_WARNING));
m_imageList->Add(wxTheApp->GetStdIcon(wxICON_ERROR));
}
m_notebook->SetImageList(m_imageList);
}
else // no images
{
if ( m_imageList )
{
delete m_imageList;
m_imageList = NULL;
}
}
// because of the bug in wxMSW we can't use SetImageList(NULL) - although
// it would be logical if this removed the image list from notebook, under
// MSW it crashes instead
}
void NotebookWidgetsPage::CreateNotebook()
{
int flags;
switch ( m_radioOrient->GetSelection() )
{
default:
wxFAIL_MSG( _T("unknown notebok orientation") );
// fall through
case Orient_Top:
flags = wxNB_TOP;
break;
case Orient_Bottom:
flags = wxNB_BOTTOM;
break;
case Orient_Left:
flags = wxNB_LEFT;
break;
case Orient_Right:
flags = wxNB_RIGHT;
break;
}
wxNotebook *notebook = m_notebook;
m_notebook = new wxNotebook(this, NotebookPage_Notebook,
wxDefaultPosition, wxDefaultSize,
flags);
CreateImageList();
if ( notebook )
{
int sel = notebook->GetSelection();
int count = notebook->GetPageCount();
for ( int n = 0; n < count; n++ )
{
wxNotebookPage *page = notebook->GetPage(0);
page->Reparent(m_notebook);
m_notebook->AddPage(page, notebook->GetPageText(0), FALSE,
notebook->GetPageImage(0));
notebook->RemovePage(0);
}
m_sizerNotebook->Remove(notebook);
delete notebook;
// restore selection
if ( sel != -1 )
{
m_notebook->SetSelection(sel);
}
}
m_sizerNotebook->Add(m_notebook, 1, wxGROW | wxALL, 5);
m_sizerNotebook->Layout();
}
// ----------------------------------------------------------------------------
// helpers
// ----------------------------------------------------------------------------
int NotebookWidgetsPage::GetTextValue(wxTextCtrl *text) const
{
long pos;
if ( !text->GetValue().ToLong(&pos) )
pos = -1;
return (int)pos;
}
int NotebookWidgetsPage::GetIconIndex() const
{
if ( m_imageList )
{
int nImages = m_imageList->GetImageCount();
if ( nImages > 0 )
{
return m_notebook->GetPageCount() % nImages;
}
}
return -1;
}
wxWindow *NotebookWidgetsPage::CreateNewPage()
{
return new wxTextCtrl(m_notebook, -1, _T("I'm a notebook page"));
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void NotebookWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateNotebook();
}
void NotebookWidgetsPage::OnButtonDeleteAll(wxCommandEvent& WXUNUSED(event))
{
m_notebook->DeleteAllPages();
}
void NotebookWidgetsPage::OnButtonSelectPage(wxCommandEvent& event)
{
int pos = GetTextValue(m_textSelect);
wxCHECK_RET( pos >= 0, _T("button should be disabled") );
m_notebook->SetSelection(pos);
}
void NotebookWidgetsPage::OnButtonAddPage(wxCommandEvent& WXUNUSED(event))
{
m_notebook->AddPage(CreateNewPage(), _T("Added page"), FALSE,
GetIconIndex());
}
void NotebookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event))
{
int pos = GetTextValue(m_textInsert);
wxCHECK_RET( pos >= 0, _T("button should be disabled") );
m_notebook->InsertPage(pos, CreateNewPage(), _T("Inserted page"), FALSE,
GetIconIndex());
}
void NotebookWidgetsPage::OnButtonRemovePage(wxCommandEvent& WXUNUSED(event))
{
int pos = GetTextValue(m_textRemove);
wxCHECK_RET( pos >= 0, _T("button should be disabled") );
m_notebook->DeletePage(pos);
}
void NotebookWidgetsPage::OnUpdateUISelectButton(wxUpdateUIEvent& event)
{
event.Enable( GetTextValue(m_textSelect) >= 0 );
}
void NotebookWidgetsPage::OnUpdateUIInsertButton(wxUpdateUIEvent& event)
{
event.Enable( GetTextValue(m_textInsert) >= 0 );
}
void NotebookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event)
{
event.Enable( GetTextValue(m_textRemove) >= 0 );
}
void NotebookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
{
event.Enable( !m_chkImages->GetValue() ||
m_radioOrient->GetSelection() != wxNB_TOP );
}
void NotebookWidgetsPage::OnUpdateUINumPagesText(wxUpdateUIEvent& event)
{
event.SetText( wxString::Format(_T("%d"), m_notebook->GetPageCount()) );
}
void NotebookWidgetsPage::OnUpdateUICurSelectText(wxUpdateUIEvent& event)
{
event.SetText( wxString::Format(_T("%d"), m_notebook->GetSelection()) );
}
void NotebookWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateNotebook();
}
void NotebookWidgetsPage::OnPageChanging(wxNotebookEvent& event)
{
wxLogMessage(_T("Notebook page changing from %d to %d (currently %d)."),
event.GetOldSelection(),
event.GetSelection(),
m_notebook->GetSelection());
event.Skip();
}
void NotebookWidgetsPage::OnPageChanged(wxNotebookEvent& event)
{
wxLogMessage(_T("Notebook page changed from %d to %d (currently %d)."),
event.GetOldSelection(),
event.GetSelection(),
m_notebook->GetSelection());
event.Skip();
}

View File

@ -0,0 +1,455 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: radiobox.cpp
// Purpose: Part of the widgets sample showing wxRadioBox
// Author: Vadim Zeitlin
// Created: 15.04.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "widgets.h"
#include "icons/radiobox.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
RadioPage_Reset = 100,
RadioPage_Update,
RadioPage_Selection,
RadioPage_Label,
RadioPage_LabelBtn,
RadioPage_Radio
};
// layout direction radiobox selections
enum
{
RadioDir_Default,
RadioDir_LtoR,
RadioDir_TtoB
};
// default values for the number of radiobox items
static const size_t DEFAULT_NUM_ENTRIES = 12;
static const size_t DEFAULT_MAJOR_DIM = 4;
// ----------------------------------------------------------------------------
// RadioWidgetsPage
// ----------------------------------------------------------------------------
class RadioWidgetsPage : public WidgetsPage
{
public:
RadioWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~RadioWidgetsPage();
protected:
// event handlers
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnRadioBox(wxCommandEvent& event);
void OnButtonReset(wxCommandEvent& event);
void OnButtonRecreate(wxCommandEvent& event);
void OnButtonSelection(wxCommandEvent& event);
void OnButtonSetLabel(wxCommandEvent& event);
void OnUpdateUIReset(wxUpdateUIEvent& event);
void OnUpdateUIUpdate(wxUpdateUIEvent& event);
void OnUpdateUISelection(wxUpdateUIEvent& event);
// reset the wxRadioBox parameters
void Reset();
// (re)create the wxRadioBox
void CreateRadio();
// the controls
// ------------
// the check/radio boxes for styles
wxCheckBox *m_chkVert;
wxRadioBox *m_radioDir;
// the gauge itself and the sizer it is in
wxRadioBox *m_radio;
wxSizer *m_sizerRadio;
// the text entries for command parameters
wxTextCtrl *m_textNumBtns,
*m_textMajorDim,
*m_textCurSel,
*m_textSel,
*m_textLabel,
*m_textLabelBtns;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(RadioWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(RadioWidgetsPage, WidgetsPage)
EVT_BUTTON(RadioPage_Reset, RadioWidgetsPage::OnButtonReset)
EVT_BUTTON(RadioPage_Update, RadioWidgetsPage::OnButtonRecreate)
EVT_BUTTON(RadioPage_LabelBtn, RadioWidgetsPage::OnButtonRecreate)
EVT_BUTTON(RadioPage_Selection, RadioWidgetsPage::OnButtonSelection)
EVT_BUTTON(RadioPage_Label, RadioWidgetsPage::OnButtonSetLabel)
EVT_UPDATE_UI(RadioPage_Update, RadioWidgetsPage::OnUpdateUIUpdate)
EVT_UPDATE_UI(RadioPage_Selection, RadioWidgetsPage::OnUpdateUISelection)
EVT_RADIOBOX(RadioPage_Radio, RadioWidgetsPage::OnRadioBox)
EVT_CHECKBOX(-1, RadioWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, RadioWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(RadioWidgetsPage, _T("Radio"));
RadioWidgetsPage::RadioWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(radio_xpm));
// init everything
m_chkVert = (wxCheckBox *)NULL;
m_textNumBtns =
m_textLabelBtns =
m_textLabel = (wxTextCtrl *)NULL;
m_radio =
m_radioDir = (wxRadioBox *)NULL;
m_sizerRadio = (wxSizer *)NULL;
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Vertical layout"));
static const wxString layoutDir[] =
{
_T("default"),
_T("left to right"),
_T("top to bottom")
};
m_radioDir = new wxRadioBox(this, -1, _T("Numbering:"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(layoutDir), layoutDir);
sizerLeft->Add(m_radioDir, 0, wxGROW | wxALL, 5);
// if it's not defined, we can't change the radiobox direction
#ifndef wxRA_LEFTTORIGHT
m_radioDir->Disable();
#endif // wxRA_LEFTTORIGHT
wxSizer *sizerRow;
sizerRow = CreateSizerWithTextAndLabel(_T("&Major dimension"),
-1,
&m_textMajorDim);
sizerLeft->Add(sizerRow, 0, wxGROW | wxALL, 5);
sizerRow = CreateSizerWithTextAndLabel(_T("&Number of buttons"),
-1,
&m_textNumBtns);
sizerLeft->Add(sizerRow, 0, wxGROW | wxALL, 5);
wxButton *btn;
btn = new wxButton(this, RadioPage_Update, _T("&Update"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 5);
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
btn = new wxButton(this, RadioPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change parameters"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
sizerRow = CreateSizerWithTextAndLabel(_T("Current selection"),
-1,
&m_textCurSel);
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
sizerRow = CreateSizerWithTextAndButton(RadioPage_Selection,
_T("&Change selection"),
-1,
&m_textSel);
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
sizerRow = CreateSizerWithTextAndButton(RadioPage_Label,
_T("&Label for box"),
-1,
&m_textLabel);
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
sizerRow = CreateSizerWithTextAndButton(RadioPage_LabelBtn,
_T("&Label for buttons"),
-1,
&m_textLabelBtns);
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
sizerRight->SetMinSize(250, 0);
m_sizerRadio = sizerRight; // save it to modify it later
Reset();
CreateRadio();
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
RadioWidgetsPage::~RadioWidgetsPage()
{
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void RadioWidgetsPage::Reset()
{
m_textMajorDim->SetValue(wxString::Format(_T("%d"), DEFAULT_MAJOR_DIM));
m_textNumBtns->SetValue(wxString::Format(_T("%d"), DEFAULT_NUM_ENTRIES));
m_textLabel->SetValue(_T("I'm a radiobox"));
m_textLabelBtns->SetValue(_T("item"));
m_chkVert->SetValue(FALSE);
m_radioDir->SetSelection(RadioDir_Default);
}
void RadioWidgetsPage::CreateRadio()
{
int sel;
if ( m_radio )
{
sel = m_radio->GetSelection();
m_sizerRadio->Remove(m_radio);
delete m_radio;
}
else // first time creation, no old selection to preserve
{
sel = -1;
}
unsigned long count;
if ( !m_textNumBtns->GetValue().ToULong(&count) )
{
wxLogWarning(_T("Should have a valid number for number of items."));
// fall back to default
count = DEFAULT_NUM_ENTRIES;
}
unsigned long majorDim;
if ( !m_textMajorDim->GetValue().ToULong(&majorDim) )
{
wxLogWarning(_T("Should have a valid major dimension number."));
// fall back to default
majorDim = DEFAULT_MAJOR_DIM;
}
wxString *items = new wxString[count];
wxString labelBtn = m_textLabelBtns->GetValue();
for ( size_t n = 0; n < count; n++ )
{
items[n] = wxString::Format(_T("%s %u"), labelBtn.c_str(), n + 1);
}
int flags = m_chkVert->GetValue() ? wxRA_VERTICAL
: wxRA_HORIZONTAL;
#ifdef wxRA_LEFTTORIGHT
switch ( m_radioDir->GetSelection() )
{
default:
wxFAIL_MSG( _T("unexpected wxRadioBox layout direction") );
// fall through
case RadioDir_Default:
break;
case RadioDir_LtoR:
flags |= wxRA_LEFTTORIGHT;
break;
case RadioDir_TtoB:
flags |= wxRA_TOPTOBOTTOM;
break;
}
#endif // wxRA_LEFTTORIGHT
m_radio = new wxRadioBox(this, RadioPage_Radio,
m_textLabel->GetValue(),
wxDefaultPosition, wxDefaultSize,
count, items,
majorDim,
flags);
delete [] items;
if ( sel >= 0 && (size_t)sel < count )
{
m_radio->SetSelection(sel);
}
m_sizerRadio->Add(m_radio, 1, wxGROW);
m_sizerRadio->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void RadioWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateRadio();
}
void RadioWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateRadio();
}
void RadioWidgetsPage::OnRadioBox(wxCommandEvent& event)
{
int sel = m_radio->GetSelection();
wxLogMessage(_T("Radiobox selection changed, now %d"), sel);
wxASSERT_MSG( sel == event.GetSelection(),
_T("selection should be the same in event and radiobox") );
m_textCurSel->SetValue(wxString::Format(_T("%d"), sel));
}
void RadioWidgetsPage::OnButtonRecreate(wxCommandEvent& WXUNUSED(event))
{
CreateRadio();
}
void RadioWidgetsPage::OnButtonSetLabel(wxCommandEvent& WXUNUSED(event))
{
m_radio->wxControl::SetLabel(m_textLabel->GetValue());
}
void RadioWidgetsPage::OnButtonSelection(wxCommandEvent& WXUNUSED(event))
{
unsigned long sel;
if ( !m_textSel->GetValue().ToULong(&sel) ||
(sel >= (size_t)m_radio->GetCount()) )
{
wxLogWarning(_T("Invalid number specified as new selection."));
}
else
{
m_radio->SetSelection(sel);
}
}
void RadioWidgetsPage::OnUpdateUIUpdate(wxUpdateUIEvent& event)
{
unsigned long n;
event.Enable( m_textNumBtns->GetValue().ToULong(&n) &&
m_textMajorDim->GetValue().ToULong(&n) );
}
void RadioWidgetsPage::OnUpdateUISelection(wxUpdateUIEvent& event)
{
unsigned long n;
event.Enable( m_textSel->GetValue().ToULong(&n) &&
(n < (size_t)m_radio->GetCount()) );
}
void RadioWidgetsPage::OnUpdateUIReset(wxUpdateUIEvent& event)
{
// only enable it if something is not set to default
bool enable = m_chkVert->GetValue();
if ( !enable )
{
unsigned long numEntries;
enable = !m_textNumBtns->GetValue().ToULong(&numEntries) ||
numEntries != DEFAULT_NUM_ENTRIES;
if ( !enable )
{
unsigned long majorDim;
enable = !m_textMajorDim->GetValue().ToULong(&majorDim) ||
majorDim != DEFAULT_MAJOR_DIM;
}
}
event.Enable(enable);
}

470
samples/widgets/slider.cpp Normal file
View File

@ -0,0 +1,470 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: slider.cpp
// Purpose: Part of the widgets sample showing wxSlider
// Author: Vadim Zeitlin
// Created: 16.04.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/radiobox.h"
#include "wx/slider.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "widgets.h"
#include "icons/slider.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
SliderPage_Reset = 100,
SliderPage_Clear,
SliderPage_SetValue,
SliderPage_SetMinAndMax,
SliderPage_SetTickFreq,
SliderPage_CurValueText,
SliderPage_ValueText,
SliderPage_MinText,
SliderPage_MaxText,
SliderPage_TickFreqText,
SliderPage_OtherSide,
SliderPage_Slider
};
// ----------------------------------------------------------------------------
// SliderWidgetsPage
// ----------------------------------------------------------------------------
class SliderWidgetsPage : public WidgetsPage
{
public:
SliderWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~SliderWidgetsPage();
protected:
// event handlers
void OnButtonReset(wxCommandEvent& event);
void OnButtonClear(wxCommandEvent& event);
void OnButtonSetValue(wxCommandEvent& event);
void OnButtonSetMinAndMax(wxCommandEvent& event);
void OnButtonSetTickFreq(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnSlider(wxCommandEvent& event);
void OnUpdateUIOtherSide(wxUpdateUIEvent& event);
void OnUpdateUIValueButton(wxUpdateUIEvent& event);
void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event);
void OnUpdateUITickFreq(wxUpdateUIEvent& event);
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
void OnUpdateUICurValueText(wxUpdateUIEvent& event);
// reset the slider parameters
void Reset();
// (re)create the slider
void CreateSlider();
// set the tick frequency from the text field value
void DoSetTickFreq();
// is this slider value in range?
bool IsValidValue(int val) const
{ return (val >= m_min) && (val <= m_max); }
// the slider range
int m_min, m_max;
// the controls
// ------------
// the check/radio boxes for styles
wxCheckBox *m_chkLabels,
*m_chkOtherSide,
*m_chkVert,
*m_chkTicks;
// the slider itself and the sizer it is in
wxSlider *m_slider;
wxSizer *m_sizerSlider;
// the text entries for set value/range
wxTextCtrl *m_textValue,
*m_textMin,
*m_textMax,
*m_textTickFreq;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(SliderWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(SliderWidgetsPage, WidgetsPage)
EVT_BUTTON(SliderPage_Reset, SliderWidgetsPage::OnButtonReset)
EVT_BUTTON(SliderPage_SetValue, SliderWidgetsPage::OnButtonSetValue)
EVT_BUTTON(SliderPage_SetMinAndMax, SliderWidgetsPage::OnButtonSetMinAndMax)
EVT_BUTTON(SliderPage_SetTickFreq, SliderWidgetsPage::OnButtonSetTickFreq)
EVT_UPDATE_UI(SliderPage_OtherSide, SliderWidgetsPage::OnUpdateUIOtherSide)
EVT_UPDATE_UI(SliderPage_SetValue, SliderWidgetsPage::OnUpdateUIValueButton)
EVT_UPDATE_UI(SliderPage_SetMinAndMax, SliderWidgetsPage::OnUpdateUIMinMaxButton)
EVT_UPDATE_UI(SliderPage_SetTickFreq, SliderWidgetsPage::OnUpdateUITickFreq)
EVT_UPDATE_UI(SliderPage_TickFreqText, SliderWidgetsPage::OnUpdateUITickFreq)
EVT_UPDATE_UI(SliderPage_Reset, SliderWidgetsPage::OnUpdateUIResetButton)
EVT_UPDATE_UI(SliderPage_CurValueText, SliderWidgetsPage::OnUpdateUICurValueText)
EVT_SLIDER(SliderPage_Slider, SliderWidgetsPage::OnSlider)
EVT_CHECKBOX(-1, SliderWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, SliderWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(SliderWidgetsPage, _T("Slider"));
SliderWidgetsPage::SliderWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(slider_xpm));
// init everything
m_min = 0;
m_max = 100;
m_chkVert =
m_chkTicks =
m_chkLabels =
m_chkOtherSide = (wxCheckBox *)NULL;
m_slider = (wxSlider *)NULL;
m_sizerSlider = (wxSizer *)NULL;
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Vertical"));
m_chkTicks = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Show &ticks"));
m_chkLabels = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Show &labels"));
m_chkOtherSide = CreateCheckBoxAndAddToSizer
(
sizerLeft,
_T("On &other side"),
SliderPage_OtherSide
);
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
wxButton *btn = new wxButton(this, SliderPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change slider value"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxTextCtrl *text;
wxSizer *sizerRow = CreateSizerWithTextAndLabel(_T("Current value"),
SliderPage_CurValueText,
&text);
text->SetEditable(FALSE);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetValue,
_T("Set &value"),
SliderPage_ValueText,
&m_textValue);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetMinAndMax,
_T("&Min and max"),
SliderPage_MinText,
&m_textMin);
m_textMax = new wxTextCtrl(this, SliderPage_MaxText, _T(""));
sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
m_textMin->SetValue(wxString::Format(_T("%lu"), m_min));
m_textMax->SetValue(wxString::Format(_T("%lu"), m_max));
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetTickFreq,
_T("Tick &frequency"),
SliderPage_TickFreqText,
&m_textTickFreq);
m_textTickFreq->SetValue(_T("10"));
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
sizerRight->SetMinSize(250, 0);
m_sizerSlider = sizerRight; // save it to modify it later
Reset();
CreateSlider();
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
SliderWidgetsPage::~SliderWidgetsPage()
{
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void SliderWidgetsPage::Reset()
{
m_chkLabels->SetValue(TRUE);
m_chkTicks->SetValue(FALSE);
m_chkVert->SetValue(FALSE);
m_chkOtherSide->SetValue(FALSE);
}
void SliderWidgetsPage::CreateSlider()
{
int flags = 0;
bool isVert = m_chkVert->GetValue();
if ( isVert )
flags |= wxSL_VERTICAL;
else
flags |= wxSL_HORIZONTAL;
if ( m_chkLabels->GetValue() )
{
flags |= wxSL_LABELS;
if ( m_chkOtherSide->GetValue() )
flags |= isVert ? wxSL_RIGHT : wxSL_BOTTOM;
else
flags |= isVert ? wxSL_LEFT : wxSL_TOP;
}
if ( m_chkTicks->GetValue() )
{
flags |= wxSL_AUTOTICKS;
}
int val = m_min;
if ( m_slider )
{
int valOld = m_slider->GetValue();
if ( !IsValidValue(valOld) )
{
val = valOld;
}
m_sizerSlider->Remove(m_slider);
if ( m_sizerSlider->GetChildren().GetCount() )
{
// we have 2 spacers, remove them too
m_sizerSlider->Remove((int)0);
m_sizerSlider->Remove((int)0);
}
delete m_slider;
}
m_slider = new wxSlider(this, SliderPage_Slider,
val, m_min, m_max,
wxDefaultPosition, wxDefaultSize,
flags);
if ( isVert )
{
m_sizerSlider->Add(0, 0, 1);
m_sizerSlider->Add(m_slider, 0, wxGROW | wxALL, 5);
m_sizerSlider->Add(0, 0, 1);
}
else
{
m_sizerSlider->Add(m_slider, 1, wxCENTRE | wxALL, 5);
}
if ( m_chkTicks->GetValue() )
{
DoSetTickFreq();
}
m_sizerSlider->Layout();
}
void SliderWidgetsPage::DoSetTickFreq()
{
long freq;
if ( !m_textTickFreq->GetValue().ToLong(&freq) )
{
wxLogWarning(_T("Invalid slider tick frequency"));
return;
}
m_slider->SetTickFreq(freq, 0 /* unused */);
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void SliderWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateSlider();
}
void SliderWidgetsPage::OnButtonSetTickFreq(wxCommandEvent& WXUNUSED(event))
{
DoSetTickFreq();
}
void SliderWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event))
{
long minNew,
maxNew = 0; // init to suppress compiler warning
if ( !m_textMin->GetValue().ToLong(&minNew) ||
!m_textMax->GetValue().ToLong(&maxNew) ||
minNew >= maxNew )
{
wxLogWarning(_T("Invalid min/max values for the slider."));
return;
}
m_min = minNew;
m_max = maxNew;
m_slider->SetRange(minNew, maxNew);
}
void SliderWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
{
long val;
if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
{
wxLogWarning(_T("Invalid slider value."));
return;
}
m_slider->SetValue(val);
}
void SliderWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
{
long val;
event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) );
}
void SliderWidgetsPage::OnUpdateUITickFreq(wxUpdateUIEvent& event)
{
long freq;
event.Enable( m_chkTicks->GetValue() &&
m_textTickFreq->GetValue().ToLong(&freq) &&
(freq > 0) && (freq <= m_max - m_min) );
}
void SliderWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event)
{
long mn, mx;
event.Enable( m_textMin->GetValue().ToLong(&mn) &&
m_textMax->GetValue().ToLong(&mx) &&
mn < mx);
}
void SliderWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
{
event.Enable( m_chkVert->GetValue() ||
!m_chkLabels->GetValue() ||
m_chkOtherSide->GetValue() ||
m_chkTicks->GetValue() );
}
void SliderWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateSlider();
}
void SliderWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
{
event.SetText( wxString::Format(_T("%d"), m_slider->GetValue()));
}
void SliderWidgetsPage::OnUpdateUIOtherSide(wxUpdateUIEvent& event)
{
event.Enable( m_chkLabels->GetValue() );
}
void SliderWidgetsPage::OnSlider(wxCommandEvent& event)
{
int value = event.GetInt();
wxASSERT_MSG( value == m_slider->GetValue(),
_T("slider value should be the same") );
wxLogMessage(_T("Slider value changed, now %d"), value);
}

419
samples/widgets/spinbtn.cpp Normal file
View File

@ -0,0 +1,419 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: spinbtn.cpp
// Purpose: Part of the widgets sample showing wxSpinButton
// Author: Vadim Zeitlin
// Created: 16.04.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/textctrl.h"
#endif
#include "wx/spinbutt.h"
#include "wx/spinctrl.h"
#include "wx/sizer.h"
#include "widgets.h"
#include "icons/spinbtn.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
SpinBtnPage_Reset = 100,
SpinBtnPage_Clear,
SpinBtnPage_SetValue,
SpinBtnPage_SetMinAndMax,
SpinBtnPage_CurValueText,
SpinBtnPage_ValueText,
SpinBtnPage_MinText,
SpinBtnPage_MaxText,
SpinBtnPage_SpinBtn,
SpinBtnPage_SpinCtrl
};
// ----------------------------------------------------------------------------
// SpinBtnWidgetsPage
// ----------------------------------------------------------------------------
class SpinBtnWidgetsPage : public WidgetsPage
{
public:
SpinBtnWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~SpinBtnWidgetsPage();
protected:
// event handlers
void OnButtonReset(wxCommandEvent& event);
void OnButtonClear(wxCommandEvent& event);
void OnButtonSetValue(wxCommandEvent& event);
void OnButtonSetMinAndMax(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnSpinBtn(wxCommandEvent& event);
void OnSpinBtnUp(wxCommandEvent& event);
void OnSpinBtnDown(wxCommandEvent& event);
void OnSpinCtrl(wxCommandEvent& event);
void OnUpdateUIValueButton(wxUpdateUIEvent& event);
void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event);
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
void OnUpdateUICurValueText(wxUpdateUIEvent& event);
// reset the spinbtn parameters
void Reset();
// (re)create the spinbtn
void CreateSpin();
// is this spinbtn value in range?
bool IsValidValue(int val) const
{ return (val >= m_min) && (val <= m_max); }
// the spinbtn range
int m_min, m_max;
// the controls
// ------------
// the check/radio boxes for styles
wxCheckBox *m_chkVert,
*m_chkWrap;
// the spinbtn and the spinctrl and the sizer containing them
wxSpinButton *m_spinbtn;
wxSpinCtrl *m_spinctrl;
wxSizer *m_sizerSpin;
// the text entries for set value/range
wxTextCtrl *m_textValue,
*m_textMin,
*m_textMax;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(SpinBtnWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(SpinBtnWidgetsPage, WidgetsPage)
EVT_BUTTON(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnButtonReset)
EVT_BUTTON(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnButtonSetValue)
EVT_BUTTON(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnButtonSetMinAndMax)
EVT_UPDATE_UI(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnUpdateUIValueButton)
EVT_UPDATE_UI(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnUpdateUIMinMaxButton)
EVT_UPDATE_UI(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnUpdateUIResetButton)
EVT_UPDATE_UI(SpinBtnPage_CurValueText, SpinBtnWidgetsPage::OnUpdateUICurValueText)
EVT_SPIN(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtn)
EVT_SPIN_UP(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtnUp)
EVT_SPIN_DOWN(SpinBtnPage_SpinBtn, SpinBtnWidgetsPage::OnSpinBtnDown)
EVT_SPINCTRL(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinCtrl)
EVT_CHECKBOX(-1, SpinBtnWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, SpinBtnWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(SpinBtnWidgetsPage, _T("Spin"));
SpinBtnWidgetsPage::SpinBtnWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(spinbtn_xpm));
// init everything
m_min = 0;
m_max = 10;
m_chkVert =
m_chkWrap = (wxCheckBox *)NULL;
m_spinbtn = (wxSpinButton *)NULL;
m_sizerSpin = (wxSizer *)NULL;
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Vertical"));
m_chkWrap = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Wrap"));
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
wxButton *btn = new wxButton(this, SpinBtnPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change spinbtn value"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxTextCtrl *text;
wxSizer *sizerRow = CreateSizerWithTextAndLabel(_T("Current value"),
SpinBtnPage_CurValueText,
&text);
text->SetEditable(FALSE);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetValue,
_T("Set &value"),
SpinBtnPage_ValueText,
&m_textValue);
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetMinAndMax,
_T("&Min and max"),
SpinBtnPage_MinText,
&m_textMin);
m_textMax = new wxTextCtrl(this, SpinBtnPage_MaxText, _T(""));
sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
m_textMin->SetValue(wxString::Format(_T("%lu"), m_min));
m_textMax->SetValue(wxString::Format(_T("%lu"), m_max));
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
sizerRight->SetMinSize(250, 0);
m_sizerSpin = sizerRight; // save it to modify it later
Reset();
CreateSpin();
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
SpinBtnWidgetsPage::~SpinBtnWidgetsPage()
{
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void SpinBtnWidgetsPage::Reset()
{
m_chkVert->SetValue(TRUE);
m_chkWrap->SetValue(FALSE);
}
void SpinBtnWidgetsPage::CreateSpin()
{
int flags = 0;
bool isVert = m_chkVert->GetValue();
if ( isVert )
flags |= wxSP_VERTICAL;
else
flags |= wxSP_HORIZONTAL;
if ( m_chkWrap->GetValue() )
flags |= wxSP_WRAP;
int val = m_min;
if ( m_spinbtn )
{
int valOld = m_spinbtn->GetValue();
if ( !IsValidValue(valOld) )
{
val = valOld;
}
m_sizerSpin->Remove(m_spinbtn);
m_sizerSpin->Remove(m_spinctrl);
// there are 3 spacers left
m_sizerSpin->Remove((int)0);
m_sizerSpin->Remove((int)0);
m_sizerSpin->Remove((int)0);
delete m_spinbtn;
delete m_spinctrl;
}
m_spinbtn = new wxSpinButton(this, SpinBtnPage_SpinBtn,
wxDefaultPosition, wxDefaultSize,
flags);
m_spinbtn->SetValue(val);
m_spinbtn->SetRange(m_min, m_max);
m_spinctrl = new wxSpinCtrl(this, SpinBtnPage_SpinCtrl,
wxString::Format(_T("%d"), val),
wxDefaultPosition, wxDefaultSize,
flags,
m_min, m_max, val);
m_sizerSpin->Add(0, 0, 1);
m_sizerSpin->Add(m_spinbtn, 0, wxALIGN_CENTRE | wxALL, 5);
m_sizerSpin->Add(0, 0, 1);
m_sizerSpin->Add(m_spinctrl, 0, wxALIGN_CENTRE | wxALL, 5);
m_sizerSpin->Add(0, 0, 1);
m_sizerSpin->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void SpinBtnWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateSpin();
}
void SpinBtnWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event))
{
long minNew,
maxNew = 0; // init to suppress compiler warning
if ( !m_textMin->GetValue().ToLong(&minNew) ||
!m_textMax->GetValue().ToLong(&maxNew) ||
minNew >= maxNew )
{
wxLogWarning(_T("Invalid min/max values for the spinbtn."));
return;
}
m_min = minNew;
m_max = maxNew;
m_spinbtn->SetRange(minNew, maxNew);
m_spinctrl->SetRange(minNew, maxNew);
}
void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
{
long val;
if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
{
wxLogWarning(_T("Invalid spinbtn value."));
return;
}
m_spinbtn->SetValue(val);
m_spinctrl->SetValue(val);
}
void SpinBtnWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
{
long val;
event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) );
}
void SpinBtnWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event)
{
long mn, mx;
event.Enable( m_textMin->GetValue().ToLong(&mn) &&
m_textMax->GetValue().ToLong(&mx) &&
mn < mx);
}
void SpinBtnWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
{
event.Enable( !m_chkVert->GetValue() || m_chkWrap->GetValue() );
}
void SpinBtnWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateSpin();
}
void SpinBtnWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
{
event.SetText( wxString::Format(_T("%d"), m_spinbtn->GetValue()));
}
void SpinBtnWidgetsPage::OnSpinBtn(wxCommandEvent& event)
{
int value = event.GetInt();
wxASSERT_MSG( value == m_spinbtn->GetValue(),
_T("spinbtn value should be the same") );
wxLogMessage(_T("Spin button value changed, now %d"), value);
}
void SpinBtnWidgetsPage::OnSpinBtnUp(wxCommandEvent& event)
{
wxLogMessage(_T("Spin button value incremented, will be %d (was %d)"),
event.GetInt(), m_spinbtn->GetValue());
}
void SpinBtnWidgetsPage::OnSpinBtnDown(wxCommandEvent& event)
{
wxLogMessage(_T("Spin button value decremented, will be %d (was %d)"),
event.GetInt(), m_spinbtn->GetValue());
}
void SpinBtnWidgetsPage::OnSpinCtrl(wxCommandEvent& event)
{
int value = event.GetInt();
wxASSERT_MSG( value == m_spinctrl->GetValue(),
_T("spinctrl value should be the same") );
wxLogMessage(_T("Spin control value changed, now %d"), value);
}

369
samples/widgets/static.cpp Normal file
View File

@ -0,0 +1,369 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: static.cpp
// Purpose: Part of the widgets sample showing various static controls
// Author: Vadim Zeitlin
// Created: 11.04.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/stattext.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "wx/statline.h"
#include "widgets.h"
#include "icons/statbox.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
StaticPage_Reset = 100,
StaticPage_BoxText,
StaticPage_LabelText
};
// alignment radiobox values
enum
{
StaticHAlign_Left,
StaticHAlign_Centre,
StaticHAlign_Right,
StaticHAlign_Max
};
enum
{
StaticVAlign_Top,
StaticVAlign_Centre,
StaticVAlign_Bottom,
StaticVAlign_Max
};
// ----------------------------------------------------------------------------
// StaticWidgetsPage
// ----------------------------------------------------------------------------
class StaticWidgetsPage : public WidgetsPage
{
public:
StaticWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~StaticWidgetsPage();
protected:
// event handlers
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnButtonReset(wxCommandEvent& event);
void OnButtonBoxText(wxCommandEvent& event);
void OnButtonLabelText(wxCommandEvent& event);
// reset all parameters
void Reset();
// (re)create all controls
void CreateStatic();
// the controls
// ------------
// the check/radio boxes for styles
wxCheckBox *m_chkVert,
*m_chkAutoResize;
wxRadioBox *m_radioHAlign,
*m_radioVAlign;
// the controls and the sizer containing them
wxStaticBoxSizer *m_sizerStatBox;
wxStaticText *m_statText;
wxStaticLine *m_statLine;
wxSizer *m_sizerStatic;
// the text entries for command parameters
wxTextCtrl *m_textBox,
*m_textLabel;
private:
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(StaticWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(StaticWidgetsPage, WidgetsPage)
EVT_BUTTON(StaticPage_Reset, StaticWidgetsPage::OnButtonReset)
EVT_BUTTON(StaticPage_LabelText, StaticWidgetsPage::OnButtonLabelText)
EVT_BUTTON(StaticPage_BoxText, StaticWidgetsPage::OnButtonBoxText)
EVT_CHECKBOX(-1, StaticWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, StaticWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(StaticWidgetsPage, _T("Static"));
StaticWidgetsPage::StaticWidgetsPage(wxNotebook *notebook,
wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(statbox_xpm));
// init everything
m_chkVert =
m_chkAutoResize = (wxCheckBox *)NULL;
m_radioHAlign =
m_radioVAlign = (wxRadioBox *)NULL;
m_statLine = (wxStaticLine *)NULL;
m_statText = (wxStaticText *)NULL;
m_sizerStatBox = (wxStaticBoxSizer *)NULL;
m_sizerStatic = (wxSizer *)NULL;
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
// left pane
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set style"));
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Vertical line"));
m_chkAutoResize = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Fit to text"));
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
static const wxString halign[] =
{
_T("left"),
_T("centre"),
_T("right"),
};
static const wxString valign[] =
{
_T("top"),
_T("centre"),
_T("bottom"),
};
m_radioHAlign = new wxRadioBox(this, -1, _T("&Horz alignment"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(halign), halign);
m_radioVAlign = new wxRadioBox(this, -1, _T("&Vert alignment"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(valign), valign);
sizerLeft->Add(m_radioHAlign, 0, wxGROW | wxALL, 5);
sizerLeft->Add(m_radioVAlign, 0, wxGROW | wxALL, 5);
wxButton *btn = new wxButton(this, StaticPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change labels"));
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
wxSizer *sizerRow;
sizerRow = CreateSizerWithTextAndButton(StaticPage_BoxText,
_T("Change &box label"),
-1, &m_textBox);
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
sizerRow = CreateSizerWithTextAndButton(StaticPage_LabelText,
_T("Change &text label"),
-1, &m_textLabel);
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
m_textBox->SetValue(_T("This is a box"));
m_textLabel->SetValue(_T("And this is a label\ninside the box"));
// right pane
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
sizerRight->SetMinSize(250, 0);
m_sizerStatic = sizerRight;
CreateStatic();
// the 3 panes panes compose the window
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// final initializations
Reset();
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
StaticWidgetsPage::~StaticWidgetsPage()
{
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void StaticWidgetsPage::Reset()
{
m_chkVert->SetValue(FALSE);
m_chkAutoResize->SetValue(TRUE);
m_radioHAlign->SetSelection(StaticHAlign_Left);
m_radioVAlign->SetSelection(StaticVAlign_Top);
}
void StaticWidgetsPage::CreateStatic()
{
bool isVert = m_chkVert->GetValue();
if ( m_sizerStatBox )
{
m_sizerStatic->Remove(m_sizerStatBox);
// delete m_sizerStatBox; -- deleted by Remove()
delete m_statText;
delete m_statLine;
}
int flagsBox = 0,
flagsText = 0;
if ( !m_chkAutoResize->GetValue() )
{
flagsText |= wxST_NO_AUTORESIZE;
}
int align = 0;
switch ( m_radioHAlign->GetSelection() )
{
default:
wxFAIL_MSG(_T("unexpected radiobox selection"));
// fall through
case StaticHAlign_Left:
align |= wxALIGN_LEFT;
break;
case StaticHAlign_Centre:
align |= wxALIGN_CENTRE_HORIZONTAL;
break;
case StaticHAlign_Right:
align |= wxALIGN_RIGHT;
break;
}
switch ( m_radioVAlign->GetSelection() )
{
default:
wxFAIL_MSG(_T("unexpected radiobox selection"));
// fall through
case StaticVAlign_Top:
align |= wxALIGN_TOP;
break;
case StaticVAlign_Centre:
align |= wxALIGN_CENTRE_VERTICAL;
break;
case StaticVAlign_Bottom:
align |= wxALIGN_BOTTOM;
break;
}
flagsText |= align;
flagsBox |= align;
wxStaticBox *box = new wxStaticBox(this, -1, m_textBox->GetValue(),
wxDefaultPosition, wxDefaultSize,
flagsBox);
m_sizerStatBox = new wxStaticBoxSizer(box, isVert ? wxHORIZONTAL
: wxVERTICAL);
m_statText = new wxStaticText(this, -1, m_textLabel->GetValue(),
wxDefaultPosition, wxDefaultSize,
flagsText);
m_statLine = new wxStaticLine(this, -1,
wxDefaultPosition, wxDefaultSize,
isVert ? wxLI_VERTICAL : wxLI_HORIZONTAL);
m_sizerStatBox->Add(m_statText, 1, wxGROW | wxALL, 5);
m_sizerStatBox->Add(m_statLine, 0, wxGROW | wxALL, 5);
m_sizerStatBox->Add(0, 0, 1);
m_sizerStatic->Add(m_sizerStatBox, 1, wxGROW);
m_sizerStatic->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void StaticWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateStatic();
}
void StaticWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateStatic();
}
void StaticWidgetsPage::OnButtonBoxText(wxCommandEvent& event)
{
m_sizerStatBox->GetStaticBox()->SetLabel(m_textBox->GetValue());
}
void StaticWidgetsPage::OnButtonLabelText(wxCommandEvent& event)
{
m_statText->SetLabel(m_textLabel->GetValue());
}

View File

@ -0,0 +1,658 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: textctrl.cpp
// Purpose: part of the widgets sample showing wxTextCtrl
// Author: Vadim Zeitlin
// Created: 27.03.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/timer.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/radiobox.h"
#include "wx/statbox.h"
#include "wx/stattext.h"
#include "wx/textctrl.h"
#endif
#include "wx/sizer.h"
#include "widgets.h"
#include "icons/text.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
TextPage_Reset = 100,
TextPage_Set,
TextPage_Add,
TextPage_Insert,
TextPage_Clear,
TextPage_Load,
TextPage_Password,
TextPage_WrapLines,
TextPage_Textctrl
};
// textctrl line number radiobox values
enum TextLines
{
TextLines_Single,
TextLines_Multi
};
// default values for the controls
static const struct ControlValues
{
TextLines textLines;
bool password;
bool wraplines;
bool readonly;
} DEFAULTS =
{
TextLines_Multi, // multiline
FALSE, // not password
TRUE, // do wrap lines
FALSE // not readonly
};
// ----------------------------------------------------------------------------
// TextWidgetsPage
// ----------------------------------------------------------------------------
// Define a new frame type: this is going to be our main frame
class TextWidgetsPage : public WidgetsPage
{
public:
// ctor(s) and dtor
TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
virtual ~TextWidgetsPage();
protected:
// create an info text contorl
wxTextCtrl *CreateInfoText();
// create a horz sizer holding a static text and this text control
wxSizer *CreateTextWithLabelSizer(const wxString& label,
wxTextCtrl *text,
const wxString& label2 = wxEmptyString,
wxTextCtrl *text2 = NULL);
// event handlers
void OnButtonReset(wxCommandEvent& event);
void OnButtonClearLog(wxCommandEvent& event);
void OnButtonSet(wxCommandEvent& event);
void OnButtonAdd(wxCommandEvent& event);
void OnButtonInsert(wxCommandEvent& event);
void OnButtonClear(wxCommandEvent& event);
void OnButtonLoad(wxCommandEvent& event);
void OnButtonQuit(wxCommandEvent& event);
void OnText(wxCommandEvent& event);
void OnTextEnter(wxCommandEvent& event);
void OnCheckOrRadioBox(wxCommandEvent& event);
void OnUpdateUIClearButton(wxUpdateUIEvent& event);
void OnUpdateUIPasswordCheckbox(wxUpdateUIEvent& event);
void OnUpdateUIWrapLinesCheckbox(wxUpdateUIEvent& event);
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
void OnIdle(wxIdleEvent& event);
// reset the textctrl parameters
void Reset();
// (re)create the textctrl
void CreateText();
// is the control currently single line?
bool IsSingleLine() const
{
return m_radioTextLines->GetSelection() == TextLines_Single;
}
// the controls
// ------------
// the radiobox to choose between single and multi line
wxRadioBox *m_radioTextLines;
// the checkboxes controlling text ctrl styles
wxCheckBox *m_chkPassword,
*m_chkWrapLines,
*m_chkReadonly;
// the textctrl itself and the sizer it is in
wxTextCtrl *m_text;
wxSizer *m_sizerText;
// the information text zones
wxTextCtrl *m_textPosCur,
*m_textRowCur,
*m_textColCur,
*m_textPosLast,
*m_textLineLast,
*m_textSelFrom,
*m_textSelTo;
// and the data to show in them
long m_posCur,
m_posLast,
m_selFrom,
m_selTo;
private:
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(TextWidgetsPage);
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(TextWidgetsPage, WidgetsPage)
EVT_IDLE(TextWidgetsPage::OnIdle)
EVT_BUTTON(TextPage_Reset, TextWidgetsPage::OnButtonReset)
EVT_BUTTON(TextPage_Clear, TextWidgetsPage::OnButtonClear)
EVT_BUTTON(TextPage_Set, TextWidgetsPage::OnButtonSet)
EVT_BUTTON(TextPage_Add, TextWidgetsPage::OnButtonAdd)
EVT_BUTTON(TextPage_Insert, TextWidgetsPage::OnButtonInsert)
EVT_BUTTON(TextPage_Load, TextWidgetsPage::OnButtonLoad)
EVT_UPDATE_UI(TextPage_Clear, TextWidgetsPage::OnUpdateUIClearButton)
EVT_UPDATE_UI(TextPage_Password, TextWidgetsPage::OnUpdateUIPasswordCheckbox)
EVT_UPDATE_UI(TextPage_WrapLines, TextWidgetsPage::OnUpdateUIWrapLinesCheckbox)
EVT_UPDATE_UI(TextPage_Reset, TextWidgetsPage::OnUpdateUIResetButton)
EVT_TEXT(TextPage_Textctrl, TextWidgetsPage::OnText)
EVT_TEXT_ENTER(TextPage_Textctrl, TextWidgetsPage::OnTextEnter)
EVT_CHECKBOX(-1, TextWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(-1, TextWidgetsPage::OnCheckOrRadioBox)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(TextWidgetsPage, _T("Text"));
// ----------------------------------------------------------------------------
// TextWidgetsPage creation
// ----------------------------------------------------------------------------
TextWidgetsPage::TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist)
: WidgetsPage(notebook)
{
imaglist->Add(wxBitmap(text_xpm));
// init everything
m_radioTextLines = (wxRadioBox *)NULL;
m_chkPassword =
m_chkWrapLines =
m_chkReadonly = (wxCheckBox *)NULL;
m_text =
m_textPosCur =
m_textRowCur =
m_textColCur =
m_textPosLast =
m_textLineLast =
m_textSelFrom =
m_textSelTo = (wxTextCtrl *)NULL;
m_sizerText = (wxSizer *)NULL;
m_posCur =
m_posLast =
m_selFrom =
m_selTo = -2; // not -1 which means "no selection"
// left pane
static const wxString modes[] =
{
_T("single line"),
_T("multi line"),
};
wxStaticBox *box = new wxStaticBox(this, -1, _T("&Set textctrl parameters"));
m_radioTextLines = new wxRadioBox(this, -1, _T("&Number of lines:"),
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(modes), modes,
1, wxRA_SPECIFY_COLS);
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
sizerLeft->Add(m_radioTextLines, 0, wxGROW | wxALL, 5);
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
m_chkPassword = CreateCheckBoxAndAddToSizer(
sizerLeft, _T("&Password control"), TextPage_Password
);
m_chkWrapLines = CreateCheckBoxAndAddToSizer(
sizerLeft, _T("Line &wrap"), TextPage_WrapLines
);
m_chkReadonly = CreateCheckBoxAndAddToSizer(
sizerLeft, _T("&Read-only mode")
);
wxButton *btn = new wxButton(this, TextPage_Reset, _T("&Reset"));
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane
wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change contents:"));
wxSizer *sizerMiddleUp = new wxStaticBoxSizer(box2, wxVERTICAL);
btn = new wxButton(this, TextPage_Set, _T("&Set text value"));
sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, TextPage_Add, _T("&Append text"));
sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, TextPage_Insert, _T("&Insert text"));
sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, TextPage_Load, _T("&Load file"));
sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 5);
btn = new wxButton(this, TextPage_Clear, _T("&Clear"));
sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 5);
wxStaticBox *box4 = new wxStaticBox(this, -1, _T("&Info:"));
wxSizer *sizerMiddleDown = new wxStaticBoxSizer(box4, wxVERTICAL);
m_textPosCur = CreateInfoText();
m_textRowCur = CreateInfoText();
m_textColCur = CreateInfoText();
wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
sizerRow->Add(CreateTextWithLabelSizer
(
_T("Current pos:"),
m_textPosCur
),
0, wxRIGHT, 5);
sizerRow->Add(CreateTextWithLabelSizer
(
_T("Col:"),
m_textColCur
),
0, wxLEFT | wxRIGHT, 5);
sizerRow->Add(CreateTextWithLabelSizer
(
_T("Row:"),
m_textRowCur
),
0, wxLEFT, 5);
sizerMiddleDown->Add(sizerRow, 0, wxALL, 5);
m_textLineLast = CreateInfoText();
m_textPosLast = CreateInfoText();
sizerMiddleDown->Add
(
CreateTextWithLabelSizer
(
_T("Number of lines:"),
m_textLineLast,
_T("Last position:"),
m_textPosLast
),
0, wxALL, 5
);
m_textSelFrom = CreateInfoText();
m_textSelTo = CreateInfoText();
sizerMiddleDown->Add
(
CreateTextWithLabelSizer
(
_T("Selection: from"),
m_textSelFrom,
_T("to"),
m_textSelTo
),
0, wxALL, 5
);
wxSizer *sizerMiddle = new wxBoxSizer(wxVERTICAL);
sizerMiddle->Add(sizerMiddleUp, 0, wxGROW);
sizerMiddle->Add(sizerMiddleDown, 1, wxGROW | wxTOP, 5);
// right pane
wxStaticBox *box3 = new wxStaticBox(this, -1, _T("&Text:"));
m_sizerText = new wxStaticBoxSizer(box3, wxHORIZONTAL);
Reset();
CreateText();
m_sizerText->SetMinSize(250, 0);
// the 3 panes panes compose the upper part of the window
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
sizerTop->Add(m_sizerText, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
}
TextWidgetsPage::~TextWidgetsPage()
{
}
// ----------------------------------------------------------------------------
// creation helpers
// ----------------------------------------------------------------------------
wxTextCtrl *TextWidgetsPage::CreateInfoText()
{
static int s_maxWidth = 0;
if ( !s_maxWidth )
{
// calc it once only
GetTextExtent(_T("9999999"), &s_maxWidth, NULL);
}
wxTextCtrl *text = new wxTextCtrl(this, -1, _T(""),
wxDefaultPosition,
wxSize(s_maxWidth, -1),
wxTE_READONLY);
return text;
}
wxSizer *TextWidgetsPage::CreateTextWithLabelSizer(const wxString& label,
wxTextCtrl *text,
const wxString& label2,
wxTextCtrl *text2)
{
wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
sizerRow->Add(new wxStaticText(this, -1, label), 0,
wxALIGN_CENTRE_VERTICAL | wxRIGHT, 5);
sizerRow->Add(text, 0, wxALIGN_CENTRE_VERTICAL);
if ( text2 )
{
sizerRow->Add(new wxStaticText(this, -1, label2), 0,
wxALIGN_CENTRE_VERTICAL | wxLEFT | wxRIGHT, 5);
sizerRow->Add(text2, 0, wxALIGN_CENTRE_VERTICAL);
}
return sizerRow;
}
// ----------------------------------------------------------------------------
// operations
// ----------------------------------------------------------------------------
void TextWidgetsPage::Reset()
{
m_radioTextLines->SetSelection(DEFAULTS.textLines);
m_chkPassword->SetValue(DEFAULTS.password);
m_chkWrapLines->SetValue(DEFAULTS.wraplines);
m_chkReadonly->SetValue(DEFAULTS.readonly);
}
void TextWidgetsPage::CreateText()
{
int flags = 0;
switch ( m_radioTextLines->GetSelection() )
{
default:
wxFAIL_MSG( _T("unexpected radio box selection") );
case TextLines_Single:
break;
case TextLines_Multi:
flags |= wxTE_MULTILINE;
m_chkPassword->SetValue(FALSE);
break;
}
if ( m_chkPassword->GetValue() )
flags |= wxTE_PASSWORD;
if ( m_chkReadonly->GetValue() )
flags |= wxTE_READONLY;
if ( !m_chkWrapLines->GetValue() )
flags |= wxHSCROLL;
wxString valueOld;
if ( m_text )
{
valueOld = m_text->GetValue();
m_sizerText->Remove(m_text);
delete m_text;
}
else
{
valueOld = _T("Hello, Universe!");
}
m_text = new wxTextCtrl(this, TextPage_Textctrl,
valueOld,
wxDefaultPosition, wxDefaultSize,
flags);
m_sizerText->Add(m_text, 1, wxALL |
(flags & wxTE_MULTILINE ? wxGROW
: wxALIGN_TOP), 5);
m_sizerText->Layout();
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void TextWidgetsPage::OnIdle(wxIdleEvent& WXUNUSED(event))
{
// update all info texts
if ( m_textPosCur )
{
long posCur = m_text->GetInsertionPoint();
if ( posCur != m_posCur )
{
m_textPosCur->Clear();
m_textRowCur->Clear();
m_textColCur->Clear();
long col, row;
m_text->PositionToXY(posCur, &col, &row);
*m_textPosCur << posCur;
*m_textRowCur << row;
*m_textColCur << col;
m_posCur = posCur;
}
}
if ( m_textPosLast )
{
long posLast = m_text->GetLastPosition();
if ( posLast != m_posLast )
{
m_textPosLast->Clear();
*m_textPosLast << posLast;
m_posLast = posLast;
}
}
if ( m_textLineLast )
{
m_textLineLast->SetValue(
wxString::Format(_T("%ld"), m_text->GetNumberOfLines()));
}
if ( m_textSelFrom && m_textSelTo )
{
long selFrom, selTo;
m_text->GetSelection(&selFrom, &selTo);
if ( selFrom != m_selFrom )
{
m_textSelFrom->Clear();
*m_textSelFrom << selFrom;
m_selFrom = selFrom;
}
if ( selTo != m_selTo )
{
m_textSelTo->Clear();
*m_textSelTo << selTo;
m_selTo = selTo;
}
}
}
void TextWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
CreateText();
}
void TextWidgetsPage::OnButtonSet(wxCommandEvent& WXUNUSED(event))
{
m_text->SetValue(_T("Yellow submarine"));
m_text->SetFocus();
}
void TextWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
{
m_text->AppendText(_T("here, there and everywhere"));
m_text->SetFocus();
}
void TextWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event))
{
m_text->WriteText(_T("is there anybody going to listen to my story"));
m_text->SetFocus();
}
void TextWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event))
{
m_text->Clear();
m_text->SetFocus();
}
void TextWidgetsPage::OnButtonLoad(wxCommandEvent& WXUNUSED(event))
{
// search for the file in several dirs where it's likely to be
wxPathList pathlist;
pathlist.Add(_T("."));
pathlist.Add(_T(".."));
pathlist.Add(_T("../../../samples/widgets"));
wxString filename = pathlist.FindValidPath(_T("textctrl.cpp"));
if ( !filename )
{
wxLogError(_T("File textctrl.cpp not found."));
}
else // load it
{
wxStopWatch sw;
if ( !m_text->LoadFile(filename) )
{
// this is not supposed to happen ...
wxLogError(_T("Error loading file."));
}
else
{
long elapsed = sw.Time();
wxLogMessage(_T("Loaded file '%s' in %u.%us"),
filename.c_str(), elapsed / 1000, elapsed % 1000);
}
}
}
void TextWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event)
{
event.Enable(!m_text->GetValue().empty());
}
void TextWidgetsPage::OnUpdateUIWrapLinesCheckbox(wxUpdateUIEvent& event)
{
event.Enable( !IsSingleLine() );
}
void TextWidgetsPage::OnUpdateUIPasswordCheckbox(wxUpdateUIEvent& event)
{
// can't put multiline control in password mode
event.Enable( IsSingleLine() );
}
void TextWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
{
event.Enable( (m_radioTextLines->GetSelection() != DEFAULTS.textLines) ||
(m_chkReadonly->GetValue() != DEFAULTS.readonly) ||
(m_chkPassword->GetValue() != DEFAULTS.password) ||
(m_chkWrapLines->GetValue() != DEFAULTS.wraplines) );
}
void TextWidgetsPage::OnText(wxCommandEvent& event)
{
// small hack to suppress the very first message: by then the logging is
// not yet redirected and so initial setting of the text value results in
// an annoying message box
static bool s_firstTime = TRUE;
if ( s_firstTime )
{
s_firstTime = FALSE;
return;
}
wxLogMessage(_T("Text ctrl value changed"));
}
void TextWidgetsPage::OnTextEnter(wxCommandEvent& event)
{
wxLogMessage(_T("Text entered: '%s'"), event.GetString().c_str());
}
void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event)
{
CreateText();
}

404
samples/widgets/widgets.cpp Normal file
View File

@ -0,0 +1,404 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: widgets.cpp
// Purpose: Sample showing most of the simple wxWindows widgets
// Author: Vadim Zeitlin
// Created: 27.03.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// License: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/log.h"
#include "wx/panel.h"
#include "wx/frame.h"
#include "wx/button.h"
#include "wx/checkbox.h"
#include "wx/listbox.h"
#include "wx/statbox.h"
#include "wx/stattext.h"
#include "wx/textctrl.h"
#endif
#include "wx/notebook.h"
#include "wx/sizer.h"
#include "widgets.h"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// control ids
enum
{
Widgets_ClearLog = 100,
Widgets_Quit
};
// ----------------------------------------------------------------------------
// our classes
// ----------------------------------------------------------------------------
// Define a new application type, each program should derive a class from wxApp
class WidgetsApp : public wxApp
{
public:
// override base class virtuals
// ----------------------------
// this one is called on application startup and is a good place for the app
// initialization (doing it here and not in the ctor allows to have an error
// return: if OnInit() returns false, the application terminates)
virtual bool OnInit();
};
// Define a new frame type: this is going to be our main frame
class WidgetsFrame : public wxFrame
{
public:
// ctor(s) and dtor
WidgetsFrame(const wxString& title);
virtual ~WidgetsFrame();
protected:
// event handlers
void OnButtonClearLog(wxCommandEvent& event);
void OnButtonQuit(wxCommandEvent& event);
// initialize the notebook: add all pages to it
void InitNotebook();
private:
// the panel containing everything
wxPanel *m_panel;
// the listbox for logging messages
wxListBox *m_lboxLog;
// the log target we use to redirect messages to the listbox
wxLog *m_logTarget;
// the notebook containing the test pages
wxNotebook *m_notebook;
// and the image list for it
wxImageList *m_imaglist;
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE()
};
// A log target which just redirects the messages to a listbox
class LboxLogger : public wxLog
{
public:
LboxLogger(wxListBox *lbox, wxLog *logOld)
{
m_lbox = lbox;
//m_lbox->Disable(); -- looks ugly under MSW
m_logOld = logOld;
}
virtual ~LboxLogger()
{
wxLog::SetActiveTarget(m_logOld);
}
private:
// implement sink functions
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t)
{
// don't put trace messages into listbox or we can get into infinite
// recursion
if ( level == wxLOG_Trace )
{
if ( m_logOld )
{
// cast is needed to call protected method
((LboxLogger *)m_logOld)->DoLog(level, szString, t);
}
}
else
{
wxLog::DoLog(level, szString, t);
}
}
virtual void DoLogString(const wxChar *szString, time_t t)
{
wxString msg;
TimeStamp(&msg);
msg += szString;
#ifdef __WXUNIVERSAL__
m_lbox->AppendAndEnsureVisible(msg);
#else // other ports don't have this method yet
m_lbox->Append(msg);
m_lbox->SetFirstItem(m_lbox->GetCount() - 1);
#endif
}
// the control we use
wxListBox *m_lbox;
// the old log target
wxLog *m_logOld;
};
// array of pages
WX_DEFINE_ARRAY(WidgetsPage *, ArrayWidgetsPage);
// ----------------------------------------------------------------------------
// misc macros
// ----------------------------------------------------------------------------
IMPLEMENT_APP(WidgetsApp)
#ifdef __WXUNIVERSAL__
#include "wx/univ/theme.h"
WX_USE_THEME(win32);
WX_USE_THEME(gtk);
#endif // __WXUNIVERSAL__
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog)
EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnButtonQuit)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// app class
// ----------------------------------------------------------------------------
bool WidgetsApp::OnInit()
{
// the reason for having these ifdef's is that I often run two copies of
// this sample side by side and it is useful to see which one is which
wxString title =
#if defined(__WXUNIVERSAL__)
_T("wxUniv")
#elif defined(__WXMSW__)
_T("wxMSW")
#elif defined(__WXGTK__)
_T("wxGTK")
#else
_T("wxWindows")
#endif
;
wxFrame *frame = new WidgetsFrame(title + _T(" widgets demo"));
frame->Show();
//wxLog::AddTraceMask(_T("listbox"));
//wxLog::AddTraceMask(_T("scrollbar"));
return TRUE;
}
// ----------------------------------------------------------------------------
// WidgetsFrame construction
// ----------------------------------------------------------------------------
WidgetsFrame::WidgetsFrame(const wxString& title)
: wxFrame(NULL, -1, title, wxPoint(0, 50))
{
// init everything
m_lboxLog = (wxListBox *)NULL;
m_logTarget = (wxLog *)NULL;
m_notebook = (wxNotebook *)NULL;
m_imaglist = (wxImageList *)NULL;
// create controls
m_panel = new wxPanel(this, -1);
wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
// we have 2 panes: notebook which pages demonstrating the controls in the
// upper one and the log window with some buttons in the lower
m_notebook = new wxNotebook(m_panel, -1);
InitNotebook();
wxSizer *sizerUp = new wxNotebookSizer(m_notebook);
// the lower one only has the log listbox and a button to clear it
wxSizer *sizerDown = new wxStaticBoxSizer
(
new wxStaticBox(m_panel, -1, _T("&Log window")),
wxVERTICAL
);
m_lboxLog = new wxListBox(m_panel, -1);
sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5);
wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
wxButton *btn = new wxButton(m_panel, Widgets_ClearLog, _T("Clear &log"));
sizerBtns->Add(btn);
sizerBtns->Add(10, 0); // spacer
btn = new wxButton(m_panel, Widgets_Quit, _T("E&xit"));
sizerBtns->Add(btn);
sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5);
// put everything together
sizerTop->Add(sizerUp, 1, wxGROW | (wxALL & ~(wxTOP | wxBOTTOM)), 10);
sizerTop->Add(0, 5, 0, wxGROW); // spacer in between
sizerTop->Add(sizerDown, 0, wxGROW | (wxALL & ~wxTOP), 10);
m_panel->SetAutoLayout(TRUE);
m_panel->SetSizer(sizerTop);
sizerTop->Fit(this);
sizerTop->SetSizeHints(this);
// now that everything is created we can redirect the log messages to the
// listbox
m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
wxLog::SetActiveTarget(m_logTarget);
}
void WidgetsFrame::InitNotebook()
{
m_imaglist = new wxImageList(32, 32);
ArrayWidgetsPage pages;
wxArrayString labels;
// we need to first create all pages and only then add them to the notebook
// as we need the image list first
WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
while ( info )
{
WidgetsPage *page = (*info->GetCtor())(m_notebook, m_imaglist);
pages.Add(page);
labels.Add(info->GetLabel());
info = info->GetNext();
}
m_notebook->SetImageList(m_imaglist);
// now do add them
size_t count = pages.GetCount();
for ( size_t n = 0; n < count; n++ )
{
m_notebook->AddPage(
pages[n],
labels[n],
FALSE, // don't select
n // image id
);
}
}
WidgetsFrame::~WidgetsFrame()
{
delete m_logTarget;
delete m_imaglist;
}
// ----------------------------------------------------------------------------
// WidgetsFrame event handlers
// ----------------------------------------------------------------------------
void WidgetsFrame::OnButtonQuit(wxCommandEvent& WXUNUSED(event))
{
Close();
}
void WidgetsFrame::OnButtonClearLog(wxCommandEvent& event)
{
m_lboxLog->Clear();
}
// ----------------------------------------------------------------------------
// WidgetsPageInfo
// ----------------------------------------------------------------------------
WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL;
WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label)
: m_label(label)
{
m_ctor = ctor;
m_next = WidgetsPage::ms_widgetPages;
WidgetsPage::ms_widgetPages = this;
}
// ----------------------------------------------------------------------------
// WidgetsPage
// ----------------------------------------------------------------------------
WidgetsPage::WidgetsPage(wxNotebook *notebook)
: wxPanel(notebook, -1)
{
}
wxSizer *WidgetsPage::CreateSizerWithText(wxControl *control,
wxWindowID id,
wxTextCtrl **ppText)
{
wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
wxTextCtrl *text = new wxTextCtrl(this, id, _T(""));
sizerRow->Add(control, 0, wxRIGHT | wxALIGN_CENTRE_VERTICAL, 5);
sizerRow->Add(text, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
if ( ppText )
*ppText = text;
return sizerRow;
}
// create a sizer containing a label and a text ctrl
wxSizer *WidgetsPage::CreateSizerWithTextAndLabel(const wxString& label,
wxWindowID id,
wxTextCtrl **ppText)
{
return CreateSizerWithText(new wxStaticText(this, -1, label), id, ppText);
}
// create a sizer containing a button and a text ctrl
wxSizer *WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn,
const wxString& label,
wxWindowID id,
wxTextCtrl **ppText)
{
return CreateSizerWithText(new wxButton(this, idBtn, label), id, ppText);
}
wxCheckBox *WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer *sizer,
const wxString& label,
wxWindowID id)
{
wxCheckBox *checkbox = new wxCheckBox(this, id, label);
sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
sizer->Add(0, 2, 0, wxGROW); // spacer
return checkbox;
}

110
samples/widgets/widgets.h Normal file
View File

@ -0,0 +1,110 @@
/////////////////////////////////////////////////////////////////////////////
// Program: wxWindows Widgets Sample
// Name: widgets.h
// Purpose: Common stuff for all widgets project files
// Author: Vadim Zeitlin
// Created: 27.03.01
// Id: $Id$
// Copyright: (c) 2001 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_SAMPLE_WIDGETS_H_
#define _WX_SAMPLE_WIDGETS_H_
class WXDLLEXPORT wxCheckBox;
class WXDLLEXPORT wxNotebook;
class WXDLLEXPORT wxSizer;
class WXDLLEXPORT wxTextCtrl;
class WXDLLEXPORT WidgetsPageInfo;
// all source files use wxImageList
#include "wx/imaglist.h"
// ----------------------------------------------------------------------------
// WidgetsPage: a notebook page demonstrating some widget
// ----------------------------------------------------------------------------
class WidgetsPage : public wxPanel
{
public:
WidgetsPage(wxNotebook *notebook);
protected:
// several helper functions for page creation
// create a horz sizer containing the given control and the text ctrl
// (pointer to which will be saved in the provided variable if not NULL)
// with the specified id
wxSizer *CreateSizerWithText(wxControl *control,
wxWindowID id = -1,
wxTextCtrl **ppText = NULL);
// create a sizer containing a label and a text ctrl
wxSizer *CreateSizerWithTextAndLabel(const wxString& label,
wxWindowID id = -1,
wxTextCtrl **ppText = NULL);
// create a sizer containing a button and a text ctrl
wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn,
const wxString& labelBtn,
wxWindowID id = -1,
wxTextCtrl **ppText = NULL);
// create a checkbox and add it to the sizer
wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer,
const wxString& label,
wxWindowID id = -1);
public:
// the head of the linked list containinginfo about all pages
static WidgetsPageInfo *ms_widgetPages;
};
// ----------------------------------------------------------------------------
// dynamic WidgetsPage creation helpers
// ----------------------------------------------------------------------------
class WXDLLEXPORT WidgetsPageInfo
{
public:
typedef WidgetsPage *(*Constructor)(wxNotebook *notebook,
wxImageList *imaglist);
// our ctor
WidgetsPageInfo(Constructor ctor, const wxChar *label);
// accessors
const wxString& GetLabel() const { return m_label; }
Constructor GetCtor() const { return m_ctor; }
WidgetsPageInfo *GetNext() const { return m_next; }
private:
// the label of the page
wxString m_label;
// the function to create this page
Constructor m_ctor;
// next node in the linked list or NULL
WidgetsPageInfo *m_next;
};
// to declare a page, this macro must be used in the class declaration
#define DECLARE_WIDGETS_PAGE(classname) \
private: \
static WidgetsPageInfo ms_info##classname; \
public: \
const WidgetsPageInfo *GetPageInfo() const \
{ return &ms_info##classname; }
// and this one must be inserted somewhere in the source file
#define IMPLEMENT_WIDGETS_PAGE(classname, label) \
WidgetsPage *wxCtorFor##classname(wxNotebook *notebook, \
wxImageList *imaglist) \
{ return new classname(notebook, imaglist); } \
WidgetsPageInfo classname:: \
ms_info##classname(wxCtorFor##classname, label)
#endif // _WX_SAMPLE_WIDGETS_H_

View File

@ -0,0 +1 @@
#include "wx/msw/wx.rc"

94
src/mgl/app.cpp Normal file
View File

@ -0,0 +1,94 @@
/////////////////////////////////////////////////////////////////////////////
// Name: app.cpp
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "app.h"
#endif
#include "wx/app.h"
#include "wx/settings.h"
#include "wx/module.h"
#include <mgraph.hpp>
//-----------------------------------------------------------------------------
// Global data
//-----------------------------------------------------------------------------
// MGL's display DC:
MGLDevCtx *g_displayDC = NULL;
// ----
wxApp *wxTheApp = (wxApp *) NULL;
wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
// FIXME_MGL - whole file
extern bool g_isIdle;
bool g_mainThreadLocked = FALSE;
void wxExit()
{
exit(0);
}
//-----------------------------------------------------------------------------
// wxYield
//-----------------------------------------------------------------------------
bool wxYield()
{
return TRUE;
}
//-----------------------------------------------------------------------------
// wxWakeUpIdle
//-----------------------------------------------------------------------------
void wxWakeUpIdle()
{
}
//-----------------------------------------------------------------------------
// wxApp
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
EVT_IDLE(wxApp::OnIdle)
END_EVENT_TABLE()
int wxEntry( int argc, char *argv[] )
{
return 0;
}
// FIXME_MGL - this is temporary solution, will be removed
// once I have wxApp up and running
bool wxMGL_Initialize()
{
wxBuffer = new wxChar[BUFSIZ + 512];
wxClassInfo::InitializeClasses();
wxSystemSettings::Init();
wxTheColourDatabase = new wxColourDatabase( wxKEY_STRING );
wxTheColourDatabase->Initialize();
wxInitializeStockLists();
wxInitializeStockObjects();
wxModule::RegisterModules();
if (!wxModule::InitializeModules()) return FALSE;
return TRUE;
}

957
src/mgl/bitmap.cpp Normal file
View File

@ -0,0 +1,957 @@
/////////////////////////////////////////////////////////////////////////////
// Name: bitmap.cpp
// Author: Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "bitmap.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/bitmap.h"
#include "wx/icon.h"
#include "wx/filefn.h"
#include "wx/image.h"
#include "wx/dcmemory.h"
#include "wx/utils.h"
#include "wx/log.h"
#include "wx/intl.h"
#include "wx/image.h"
#include "wx/xpmdecod.h"
#include "wx/mgl/private.h"
#include <mgraph.hpp>
//-----------------------------------------------------------------------------
// MGL pixel formats:
//-----------------------------------------------------------------------------
static pixel_format_t gs_pixel_format_15 =
{0x1F,0x0A,3, 0x1F,0x05,3, 0x1F,0x00,3, 0x01,0x0F,7}; // 555 15bpp
static pixel_format_t gs_pixel_format_16 =
{0x1F,0x0B,3, 0x3F,0x05,2, 0x1F,0x00,3, 0x00,0x00,0}; // 565 16bpp
static pixel_format_t gs_pixel_format_24 =
{0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0, 0x00,0x00,0}; // RGB 24bpp
static pixel_format_t gs_pixel_format_32 =
{0xFF,0x18,0, 0xFF,0x10,0, 0xFF,0x08,0, 0xFF,0x00,0}; // RGBA 32bpp
// FIXME_MGL -- these formats will probably have to go into another place,
// where wxApp could use them to initialize g_displayDC
//-----------------------------------------------------------------------------
// wxMask
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMask,wxObject)
wxMask::wxMask()
{
m_bitmap = NULL;
}
wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
{
m_bitmap = NULL;
Create(bitmap, colour);
}
wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
{
m_bitmap = NULL;
Create(bitmap, paletteIndex);
}
wxMask::wxMask(const wxBitmap& bitmap)
{
m_bitmap = NULL;
Create(bitmap);
}
wxMask::~wxMask()
{
delete m_bitmap;
}
bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
{
delete m_bitmap;
m_bitmap = NULL;
wxImage image = bitmap.ConvertToImage().ConvertToMono(
colour.Red(), colour.Green(), colour.Blue());
if ( !image.Ok() ) return FALSE;
m_bitmap = new wxBitmap(image, 1);
return m_bitmap->Ok();
}
bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
{
unsigned char r,g,b;
wxPalette *pal = bitmap.GetPalette();
wxCHECK_MSG( pal, FALSE, wxT("Cannot create mask from bitmap without palette") );
pal->GetRGB(paletteIndex, &r, &g, &b);
return Create(bitmap, wxColour(r, g, b));
}
bool wxMask::Create(const wxBitmap& bitmap)
{
delete m_bitmap;
m_bitmap = NULL;
wxCHECK_MSG( bitmap.Ok(), FALSE, wxT("Invalid bitmap") );
wxCHECK_MSG( bitmap.GetDepth() == 1, FALSE, wxT("Cannot create mask from colour bitmap") );
m_bitmap = new wxBitmap(bitmap);
return TRUE;
}
//-----------------------------------------------------------------------------
// wxBitmap
//-----------------------------------------------------------------------------
class wxBitmapRefData: public wxObjectRefData
{
public:
wxBitmapRefData();
~wxBitmapRefData();
int m_width;
int m_height;
int m_bpp;
wxPalette *m_palette;
wxMask *m_mask;
bitmap_t *m_bitmap;
};
wxBitmapRefData::wxBitmapRefData()
{
m_mask = NULL;
m_width = 0;
m_height = 0;
m_bpp = 0;
m_palette = NULL;
m_bitmap = NULL;
}
wxBitmapRefData::~wxBitmapRefData()
{
if ( m_bitmap )
MGL_unloadBitmap(m_bitmap);
delete m_mask;
delete m_palette;
}
//-----------------------------------------------------------------------------
#define M_BMPDATA ((wxBitmapRefData *)m_refData)
IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler,wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxBitmapBase)
wxBitmap::wxBitmap()
{
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
}
wxBitmap::wxBitmap(int width, int height, int depth)
{
Create(width, height, depth);
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
}
static bitmap_t *MyMGL_createBitmap(int width, int height,
int bpp, pixel_format_t *pf)
{
MGLMemoryDC mdc(width, height, bpp, pf);
return MGL_getBitmapFromDC(mdc.getDC(), 0, 0, width, height, TRUE);
}
bool wxBitmap::Create(int width, int height, int depth)
{
UnRef();
wxCHECK_MSG( (width > 0) && (height > 0), FALSE, wxT("invalid bitmap size") )
pixel_format_t pf_dummy, *pf;
int mglDepth = depth;
switch ( depth )
{
case -1:
wxASSERT_MSG( g_displayDC, wxT("MGL display DC not created yet.") );
g_displayDC->getPixelFormat(pf_dummy);
mglDepth = g_displayDC->getBitsPerPixel();
pf = &pf_dummy;
break;
case 1:
case 8:
pf = NULL;
break;
case 15:
pf = &gs_pixel_format_15;
break;
case 16:
pf = &gs_pixel_format_16;
break;
case 24:
pf = &gs_pixel_format_24;
break;
case 32:
pf = &gs_pixel_format_32;
break;
default:
wxASSERT_MSG( 0, wxT("invalid bitmap depth") );
return FALSE;
break;
}
m_refData = new wxBitmapRefData();
M_BMPDATA->m_mask = (wxMask *) NULL;
M_BMPDATA->m_palette = (wxPalette *) NULL;
M_BMPDATA->m_width = width;
M_BMPDATA->m_height = height;
M_BMPDATA->m_bpp = mglDepth;
if ( mglDepth != 1 )
{
M_BMPDATA->m_bitmap = MyMGL_createBitmap(width, height, mglDepth, pf);
}
else
{
// MGL does not support mono DCs, so we have to emulate them with
// 8bpp ones. We do that by using a special palette with color 0
// set to black and all other colors set to white.
M_BMPDATA->m_bitmap = MyMGL_createBitmap(width, height, 8, pf);
SetMonoPalette(wxColour(255, 255, 255), wxColour(0, 0, 0));
}
return Ok();
}
bool wxBitmap::CreateFromXpm(const char **bits)
{
wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
wxXPMDecoder decoder;
wxImage img = decoder.ReadData(bits);
wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
*this = wxBitmap(img);
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
return TRUE;
}
wxBitmap::wxBitmap(const wxImage& image, int depth = -1)
{
long width, height;
wxCHECK_RET( image.Ok(), wxT("invalid image") )
width = image.GetWidth();
height = image.GetHeight();
if ( !Create(width, height, depth) ) return;
MGLMemoryDC idc(width, height, 24, &gs_pixel_format_24,
width * 3, (void*)image.GetData(), NULL);
wxASSERT_MSG( idc.isValid(), wxT("cannot create custom MGLDC") );
MGLDevCtx *bdc = CreateTmpDC();
if ( depth <= 8 && image.HasPalette() )
SetPalette(image.GetPalette());
bdc->bitBlt(idc, 0, 0, width, height, 0, 0, MGL_REPLACE_MODE);
delete bdc;
if ( image.HasMask() )
{
wxImage mask_image = image.ConvertToMono(image.GetMaskRed(),
image.GetMaskGreen(),
image.GetMaskBlue());
mask_image.SetMask(FALSE);
wxBitmap mask_bmp(mask_image, 1);
SetMask(new wxMask(mask_bmp));
}
}
wxImage wxBitmap::ConvertToImage() const
{
wxCHECK_MSG( Ok(), FALSE, wxT("invalid bitmap") );
long width, height;
width = GetWidth();
height = GetHeight();
wxImage image(width, height);
wxASSERT_MSG( image.Ok(), wxT("cannot create image") );
MGLMemoryDC idc(width, height, 24, &gs_pixel_format_24,
width * 3, (void*)image.GetData(), NULL);
wxASSERT_MSG( idc.isValid(), wxT("cannot create custom MGLDC") );
if ( M_BMPDATA->m_palette )
image.SetPalette(*(M_BMPDATA->m_palette));
if ( GetMask() )
{
// in consistency with other ports, we convert parts covered
// by the mask to <16,16,16> colour and set that colour to image's
// mask. We do that by OR-blitting the mask over image with
// bg colour set to black and fg colour to <16,16,16>
image.SetMaskColour(16, 16, 16);
image.SetMask(TRUE);
wxDC tmpDC;
tmpDC.SetMGLDC(&idc, FALSE);
tmpDC.SetBackground(wxBrush(wxColour(16,16,16), wxSOLID));
tmpDC.Clear();
tmpDC.DrawBitmap(*this, 0, 0, TRUE);
}
else
{
image.SetMask(FALSE);
idc.putBitmap(0, 0, M_BMPDATA->m_bitmap, MGL_REPLACE_MODE);
}
return image;
}
wxBitmap::wxBitmap(const wxBitmap& bmp)
{
Ref(bmp);
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
}
wxBitmap::wxBitmap(const wxString &filename, wxBitmapType type)
{
LoadFile(filename, type);
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
}
wxBitmap::wxBitmap(const char bits[], int width, int height, int depth)
{
wxCHECK_RET( depth == 1, wxT("can only create mono bitmap from XBM data") );
if ( !Create(width, height, 1) ) return;
MGLDevCtx *bdc = CreateTmpDC();
wxCurrentDCSwitcher curDC(bdc);
bdc->setColor(1);
bdc->setBackColor(0);
bdc->clearDevice();
bdc->putMonoImage(0, 0, width, (width + 7) / 8, height, (void*)bits);
delete bdc;
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
}
wxBitmap::~wxBitmap()
{
if ( wxTheBitmapList ) wxTheBitmapList->DeleteObject(this);
}
wxBitmap& wxBitmap::operator = (const wxBitmap& bmp)
{
if ( *this == bmp ) return (*this);
Ref(bmp);
return *this;
}
bool wxBitmap::operator == (const wxBitmap& bmp) const
{
return (m_refData == bmp.m_refData);
}
bool wxBitmap::operator != (const wxBitmap& bmp) const
{
return (m_refData != bmp.m_refData);
}
bool wxBitmap::Ok() const
{
return (m_refData != NULL && M_BMPDATA->m_bitmap != NULL);
}
int wxBitmap::GetHeight() const
{
wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
return M_BMPDATA->m_height;
}
int wxBitmap::GetWidth() const
{
wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
return M_BMPDATA->m_width;
}
int wxBitmap::GetDepth() const
{
wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
return M_BMPDATA->m_bpp;
}
wxMask *wxBitmap::GetMask() const
{
wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") );
return M_BMPDATA->m_mask;
}
void wxBitmap::SetMask(wxMask *mask)
{
wxCHECK_RET( Ok(), wxT("invalid bitmap") );
delete M_BMPDATA->m_mask;
M_BMPDATA->m_mask = mask;
}
bool wxBitmap::CopyFromIcon(const wxIcon& icon)
{
wxBitmap *bmp = (wxBitmap*)(&icon);
*this = *bmp;
return TRUE;
}
wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const
{
wxCHECK_MSG( Ok() &&
(rect.x >= 0) && (rect.y >= 0) &&
(rect.x+rect.width <= M_BMPDATA->m_width) && (rect.y+rect.height <= M_BMPDATA->m_height),
wxNullBitmap, wxT("invalid bitmap or bitmap region") );
wxBitmap ret( rect.width, rect.height, M_BMPDATA->m_bpp );
wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
if ( GetPalette() )
ret.SetPalette(*GetPalette());
MGLDevCtx *tdc = ret.CreateTmpDC();
tdc->putBitmapSection(rect.x, rect.y,
rect.x + rect.width, rect.y + rect.height,
0, 0, M_BMPDATA->m_bitmap, MGL_REPLACE_MODE);
delete tdc;
if ( GetMask() )
{
wxBitmap submask = GetMask()->GetBitmap()->GetSubBitmap(rect);
ret.SetMask(new wxMask(submask));
}
return ret;
}
void wxBitmap::SetMonoPalette(const wxColour& fg, const wxColour& bg)
{
wxCHECK_RET( Ok(), wxT("invalid bitmap") );
palette_t *mono = M_BMPDATA->m_bitmap->pal;
wxCHECK_RET( M_BMPDATA->m_bpp == 1, wxT("bitmap is not 1bpp") );
wxCHECK_RET( mono != NULL, wxT("bitmap w/o palette") );
mono[0].red = bg.Red();
mono[0].green = bg.Green();
mono[0].blue = bg.Blue();
mono[0].alpha = 0;
for (size_t i = 1; i < 256; i++)
{
mono[i].red = fg.Red();
mono[i].green = fg.Green();
mono[i].blue = fg.Blue();
mono[i].alpha = 0;
}
}
MGLDevCtx *wxBitmap::CreateTmpDC() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
MGLDevCtx *tdc = new MGLMemoryDC(GetWidth(), GetHeight(),
M_BMPDATA->m_bitmap->bitsPerPixel,
M_BMPDATA->m_bitmap->pf,
M_BMPDATA->m_bitmap->bytesPerLine,
M_BMPDATA->m_bitmap->surface,
NULL);
wxCHECK_MSG( tdc->isValid(), NULL, wxT("cannot create temporary MGLDC") );
if ( M_BMPDATA->m_bitmap->pal != NULL )
{
int cnt;
switch (M_BMPDATA->m_bitmap->bitsPerPixel)
{
case 2: cnt = 2; break;
case 4: cnt = 16; break;
case 8: cnt = 256; break;
default:
wxFAIL_MSG( wxT("bitmap with this depth cannot have palette") );
break;
}
tdc->setPalette(M_BMPDATA->m_bitmap->pal, cnt, 0);
tdc->realizePalette(cnt, 0, FALSE);
}
return tdc;
}
bool wxBitmap::LoadFile(const wxString &name, wxBitmapType type)
{
UnRef();
if ( type == wxBITMAP_TYPE_BMP || type == wxBITMAP_TYPE_PNG ||
type == wxBITMAP_TYPE_PCX || type == wxBITMAP_TYPE_JPEG )
{
// prevent accidental loading of bitmap from $MGL_ROOT:
if ( !wxFileExists(name) )
{
wxLogError(_("File %s does not exist."), name.c_str());
return FALSE;
}
}
wxBitmapHandler *handler = FindHandler(type);
if ( handler == NULL )
{
wxImage image;
if ( !image.LoadFile(name, type) || !image.Ok() )
{
wxLogError("no bitmap handler for type %d defined.", type);
return FALSE;
}
else
{
*this = wxBitmap(image);
return TRUE;
}
}
m_refData = new wxBitmapRefData();
return handler->LoadFile(this, name, type, -1, -1);
}
bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
{
wxCHECK_MSG( Ok(), FALSE, wxT("invalid bitmap") );
wxBitmapHandler *handler = FindHandler(type);
if ( handler == NULL )
{
wxImage image = ConvertToImage();
if ( palette )
image.SetPalette(*palette);
if ( image.Ok() )
return image.SaveFile(filename, type);
else
{
wxLogError("no bitmap handler for type %d defined.", type);
return FALSE;
}
}
return handler->SaveFile(this, filename, type, palette);
}
wxPalette *wxBitmap::GetPalette() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
return M_BMPDATA->m_palette;
}
void wxBitmap::SetPalette(const wxPalette& palette)
{
wxCHECK_RET( Ok(), wxT("invalid bitmap") );
wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
delete M_BMPDATA->m_palette;
M_BMPDATA->m_palette = NULL;
if ( !palette.Ok() ) return;
M_BMPDATA->m_palette = new wxPalette(palette);
int cnt = palette.GetColoursCount();
palette_t *pal = palette.GetMGLpalette_t();
memcpy(M_BMPDATA->m_bitmap->pal, pal, cnt * sizeof(palette_t));
}
void wxBitmap::SetHeight(int height)
{
if (!m_refData) m_refData = new wxBitmapRefData();
M_BMPDATA->m_height = height;
}
void wxBitmap::SetWidth(int width)
{
if (!m_refData) m_refData = new wxBitmapRefData();
M_BMPDATA->m_width = width;
}
void wxBitmap::SetDepth(int depth)
{
if (!m_refData) m_refData = new wxBitmapRefData();
M_BMPDATA->m_bpp = depth;
}
bitmap_t *wxBitmap::GetMGLbitmap_t() const
{
return M_BMPDATA->m_bitmap;
}
//-----------------------------------------------------------------------------
// wxBitmap I/O handlers
//-----------------------------------------------------------------------------
class wxMGLBitmapHandler: public wxBitmapHandler
{
public:
wxMGLBitmapHandler(wxBitmapType type,
const wxString& extension, const wxString& name);
virtual bool Create(wxBitmap *bitmap, void *data, long flags,
int width, int height, int depth = 1)
{ return FALSE; }
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight);
virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name,
int type, const wxPalette *palette = NULL);
};
wxMGLBitmapHandler::wxMGLBitmapHandler(wxBitmapType type,
const wxString& extension,
const wxString& name)
: wxBitmapHandler()
{
SetType(type);
SetName(name);
SetExtension(extension);
}
bool wxMGLBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
long flags,
int WXUNUSED(desiredWidth),
int WXUNUSED(desiredHeight))
{
int width, height, bpp;
pixel_format_t pf;
wxString fullname;
wxMemoryDC dc;
switch (flags)
{
case wxBITMAP_TYPE_BMP_RESOURCE:
case wxBITMAP_TYPE_JPEG_RESOURCE:
case wxBITMAP_TYPE_PNG_RESOURCE:
case wxBITMAP_TYPE_PCX_RESOURCE:
fullname = name + wxT(".bmp");
break;
default:
fullname= name;
break;
}
switch (flags)
{
case wxBITMAP_TYPE_BMP:
case wxBITMAP_TYPE_BMP_RESOURCE:
if ( !MGL_getBitmapSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
return FALSE;
bitmap->Create(width, height, -1);
if ( !bitmap->Ok() ) return FALSE;
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadBitmapIntoDC(fullname.mb_str(), 0, 0, TRUE) )
return FALSE;
break;
case wxBITMAP_TYPE_JPEG:
case wxBITMAP_TYPE_JPEG_RESOURCE:
if ( !MGL_getJPEGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
return FALSE;
bitmap->Create(width, height, -1);
if ( !bitmap->Ok() ) return FALSE;
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadJPEGIntoDC(fullname.mb_str(), 0, 0, TRUE) )
return FALSE;
break;
case wxBITMAP_TYPE_PNG:
case wxBITMAP_TYPE_PNG_RESOURCE:
if ( !MGL_getPNGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
return FALSE;
bitmap->Create(width, height, -1);
if ( !bitmap->Ok() ) return FALSE;
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadPNGIntoDC(fullname.mb_str(), 0, 0, TRUE) )
return FALSE;
break;
case wxBITMAP_TYPE_PCX:
case wxBITMAP_TYPE_PCX_RESOURCE:
if ( !MGL_getPCXSize(fullname.mb_str(), &width, &height, &bpp) )
return FALSE;
bitmap->Create(width, height, -1);
if ( !bitmap->Ok() ) return FALSE;
dc.SelectObject(*bitmap);
if ( !dc.GetMGLDC()->loadPCXIntoDC(fullname.mb_str(), 0, 0, TRUE) )
return FALSE;
break;
default:
wxFAIL_MSG(wxT("Unsupported image format."));
break;
}
return TRUE;
}
bool wxMGLBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name,
int type, const wxPalette * WXUNUSED(palette))
{
wxMemoryDC mem;
MGLDevCtx *tdc;
int w = bitmap->GetWidth(),
h = bitmap->GetHeight();
mem.SelectObject(*bitmap);
tdc = mem.GetMGLDC();
switch (type)
{
case wxBITMAP_TYPE_BMP:
return tdc->saveBitmapFromDC(name.mb_str(), 0, 0, w, h);
break;
case wxBITMAP_TYPE_JPEG:
return tdc->saveJPEGFromDC(name.mb_str(), 0, 0, w, h, 75);
break;
case wxBITMAP_TYPE_PNG:
return tdc->savePNGFromDC(name.mb_str(), 0, 0, w, h);
break;
case wxBITMAP_TYPE_PCX:
return tdc->savePCXFromDC(name.mb_str(), 0, 0, w, h);
break;
default:
return FALSE;
break;
}
}
// let's handle PNGs in special way because they have alpha channel
// which we can access via bitmap_t most easily
class wxPNGBitmapHandler: public wxMGLBitmapHandler
{
public:
wxPNGBitmapHandler(wxBitmapType type,
const wxString& extension, const wxString& name)
: wxMGLBitmapHandler(type, extension, name) {}
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight);
};
bool wxPNGBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
long flags,
int desiredWidth, int desiredHeight)
{
int width, height, bpp;
pixel_format_t pf;
wxString fullname;
if ( flags == wxBITMAP_TYPE_PNG_RESOURCE )
fullname = name + wxT(".png");
else
fullname = name;
if ( !MGL_getPNGSize(fullname.mb_str(), &width, &height, &bpp, &pf) )
return FALSE;
if ( bpp != 32 )
{
// We can load ordinary PNGs faster with 'normal' MGL handler.
// Only RGBA PNGs need to be processed in special way because
// we have to convert alpha channel to mask
return wxMGLBitmapHandler::LoadFile(bitmap, name, flags,
desiredWidth, desiredHeight);
}
bitmap_t *bmp = MGL_loadPNG(fullname.mb_str(), TRUE);
if ( bmp == NULL ) return FALSE;
bitmap->Create(bmp->width, bmp->height, -1);
if ( !bitmap->Ok() ) return FALSE;
// convert bmp to display's depth and write it to *bitmap:
wxMemoryDC dc;
dc.SelectObject(*bitmap);
dc.GetMGLDC()->putBitmap(0, 0, bmp, MGL_REPLACE_MODE);
dc.SelectObject(wxNullBitmap);
// create mask, if bmp contains alpha channel (ARGB format):
if ( bmp->bitsPerPixel == 32 )
{
int x, y;
wxUint32 *s = (wxUint32*)bmp->surface;
for (y = 0; y < bmp->height; y++)
{
s = ((wxUint32*)bmp->surface) + y * bmp->bytesPerLine/4;
for (x = 0; x < bmp->width; x++, s ++)
{
if ( ((((*s) >> bmp->pf->rsvdPos) & bmp->pf->rsvdMask)
<< bmp->pf->rsvdAdjust) < 128 )
*s = 0;
else
*s = 0x00FFFFFF; // white
}
}
wxBitmap mask(bmp->width, bmp->height, 1);
dc.SelectObject(mask);
dc.GetMGLDC()->putBitmap(0, 0, bmp, MGL_REPLACE_MODE);
dc.SelectObject(wxNullBitmap);
bitmap->SetMask(new wxMask(mask));
}
MGL_unloadBitmap(bmp);
return TRUE;
}
class wxICOBitmapHandler: public wxBitmapHandler
{
public:
wxICOBitmapHandler(wxBitmapType type,
const wxString& extension, const wxString& name);
virtual bool Create(wxBitmap *bitmap, void *data, long flags,
int width, int height, int depth = 1)
{ return FALSE; }
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth, int desiredHeight);
virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name,
int type, const wxPalette *palette = NULL);
};
wxICOBitmapHandler::wxICOBitmapHandler(wxBitmapType type,
const wxString& extension,
const wxString& name)
: wxBitmapHandler()
{
SetType(type);
SetName(name);
SetExtension(extension);
}
bool wxICOBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
long flags,
int WXUNUSED(desiredWidth),
int WXUNUSED(desiredHeight))
{
icon_t *icon = NULL;
MGLDevCtx *dc;
if ( flags == wxBITMAP_TYPE_ICO_RESOURCE )
icon = MGL_loadIcon(wxString(name + wxT(".ico")).mb_str(), TRUE);
else
icon = MGL_loadIcon(name.mb_str(), TRUE);
if ( icon == NULL ) return FALSE;
bitmap->Create(icon->xorMask.width, icon->xorMask.height);
wxMemoryDC mem;
mem.SelectObject(*bitmap);
dc = mem.GetMGLDC();
dc->putBitmap(0, 0, &(icon->xorMask), MGL_REPLACE_MODE);
mem.SelectObject(wxNullBitmap);
wxBitmap mask(icon->xorMask.width, icon->xorMask.height, 1);
mem.SelectObject(mask);
dc = mem.GetMGLDC();
wxCurrentDCSwitcher curDC(dc);
dc->setColor(0);
dc->setBackColor(1);
dc->clearDevice();
dc->putMonoImage(0, 0, icon->xorMask.width, icon->byteWidth,
icon->xorMask.height, (void*)icon->andMask);
bitmap->SetMask(new wxMask(mask));
MGL_unloadIcon(icon);
return TRUE;
}
bool wxICOBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name,
int type, const wxPalette * WXUNUSED(palette))
{
return FALSE;
}
/*static*/ void wxBitmap::InitStandardHandlers()
{
AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP, wxT("bmp"), wxT("Windows bitmap")));
AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_BMP_RESOURCE, wxEmptyString, wxT("Windows bitmap resource")));
AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG, wxT("jpg"), wxT("JPEG image")));
AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_JPEG_RESOURCE, wxEmptyString, wxT("JPEG resource")));
AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX, wxT("pcx"), wxT("PCX image")));
AddHandler(new wxMGLBitmapHandler(wxBITMAP_TYPE_PCX_RESOURCE, wxEmptyString, wxT("PCX resource")));
AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG, wxT("png"), wxT("PNG image")));
AddHandler(new wxPNGBitmapHandler(wxBITMAP_TYPE_PNG_RESOURCE, wxEmptyString, wxT("PNG resource")));
AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO, wxT("ico"), wxT("Icon resource")));
AddHandler(new wxICOBitmapHandler(wxBITMAP_TYPE_ICO_RESOURCE, wxEmptyString, wxT("Icon resource")));
}

289
src/mgl/brush.cpp Normal file
View File

@ -0,0 +1,289 @@
/////////////////////////////////////////////////////////////////////////////
// Name: brush.cpp
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "brush.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/brush.h"
#include "wx/mgl/private.h"
#include "wx/mgl/dcmemory.h"
// ---------------------------------------------------------------------------
// helper functions
// ---------------------------------------------------------------------------
// This function converts wxBitmap into pixpattern24_t representation
// (used by wxBrush and wxPen)
void wxBitmapToPixPattern(const wxBitmap& bitmap,
pixpattern24_t *pix, pattern_t *mask)
{
wxMemoryDC mem;
MGLDevCtx *dc;
int x, y;
if ( pix != NULL )
{
mem.SelectObject(bitmap);
dc = mem.GetMGLDC();
wxCurrentDCSwitcher curDC(dc);
dc->beginPixel();
for (y = 0; y < 8; y++)
for (x = 0; x < 8; x++)
dc->unpackColorFast(dc->getPixelFast(x, y),
pix->p[y][x][2],
pix->p[y][x][1],
pix->p[y][x][0]);
dc->endPixel();
}
if ( mask && bitmap.GetMask() )
{
mem.SelectObject(*bitmap.GetMask()->GetBitmap());
dc = mem.GetMGLDC();
wxCurrentDCSwitcher curDC(dc);
dc->beginPixel();
for (y = 0; y < 8; y++)
{
mask->p[y] = 0;
for (x = 0; x < 8; x++)
if ( dc->getPixelFast(x, y) != 0 )
mask->p[y] |= 1 << (7 - x);
}
dc->endPixel();
}
}
//-----------------------------------------------------------------------------
// wxBrush
//-----------------------------------------------------------------------------
class wxBrushRefData: public wxObjectRefData
{
public:
wxBrushRefData();
wxBrushRefData(const wxBrushRefData& data);
int m_style;
wxColour m_colour;
wxBitmap m_stipple;
pixpattern24_t m_pixPattern;
pattern_t m_maskPattern;
};
wxBrushRefData::wxBrushRefData()
{
m_style = 0;
int x, y, c;
for (y = 0; y < 8; y++)
for (x = 0; x < 8; x++)
for (c = 0; c < 3; c++)
m_pixPattern.p[y][x][c] = 0;
for (y = 0; y < 8; y++)
m_maskPattern.p[y] = 0;
}
wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
{
m_style = data.m_style;
m_stipple = data.m_stipple;
m_colour = data.m_colour;
int x, y, c;
for (y = 0; y < 8; y++)
for (x = 0; x < 8; x++)
for (c = 0; c < 3; c++)
m_pixPattern.p[y][x][c] = data.m_pixPattern.p[y][x][c];
for (y = 0; y < 8; y++)
m_maskPattern.p[y] = data.m_maskPattern.p[y];
}
//-----------------------------------------------------------------------------
#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
wxBrush::wxBrush()
{
if (wxTheBrushList) wxTheBrushList->AddBrush(this);
}
wxBrush::wxBrush(const wxColour &colour, int style)
{
m_refData = new wxBrushRefData();
M_BRUSHDATA->m_style = style;
M_BRUSHDATA->m_colour = colour;
if (wxTheBrushList) wxTheBrushList->AddBrush(this);
}
wxBrush::wxBrush(const wxBitmap &stippleBitmap)
{
wxCHECK_RET( stippleBitmap.Ok(), _T("invalid bitmap") );
wxCHECK_RET( stippleBitmap.GetWidth() == 8 && stippleBitmap.GetHeight() == 8,
_T("stipple bitmap must be 8x8") );
m_refData = new wxBrushRefData();
M_BRUSHDATA->m_colour = *wxBLACK;
M_BRUSHDATA->m_stipple = stippleBitmap;
wxBitmapToPixPattern(stippleBitmap, &(M_BRUSHDATA->m_pixPattern),
&(M_BRUSHDATA->m_maskPattern));
if (M_BRUSHDATA->m_stipple.GetMask())
M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
else
M_BRUSHDATA->m_style = wxSTIPPLE;
if (wxTheBrushList) wxTheBrushList->AddBrush(this);
}
wxBrush::wxBrush(const wxBrush &brush)
{
Ref(brush);
if (wxTheBrushList) wxTheBrushList->AddBrush(this);
}
wxBrush::~wxBrush()
{
if (wxTheBrushList) wxTheBrushList->RemoveBrush(this);
}
wxBrush& wxBrush::operator = (const wxBrush& brush)
{
if (*this == brush) return (*this);
Ref(brush);
return *this;
}
bool wxBrush::operator == (const wxBrush& brush) const
{
return m_refData == brush.m_refData;
}
bool wxBrush::operator != (const wxBrush& brush) const
{
return m_refData != brush.m_refData;
}
bool wxBrush::Ok() const
{
return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
}
int wxBrush::GetStyle() const
{
if (m_refData == NULL)
{
wxFAIL_MSG( wxT("invalid brush") );
return 0;
}
return M_BRUSHDATA->m_style;
}
wxColour &wxBrush::GetColour() const
{
if (m_refData == NULL)
{
wxFAIL_MSG( wxT("invalid brush") );
return wxNullColour;
}
return M_BRUSHDATA->m_colour;
}
wxBitmap *wxBrush::GetStipple() const
{
if (m_refData == NULL)
{
wxFAIL_MSG( wxT("invalid brush") );
return &wxNullBitmap;
}
return &M_BRUSHDATA->m_stipple;
}
void* wxBrush::GetMaskPattern() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
return (void*)&(M_BRUSHDATA->m_maskPattern);
}
void* wxBrush::GetPixPattern() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid brush") );
return (void*)&(M_BRUSHDATA->m_pixPattern);
}
void wxBrush::SetColour(const wxColour& col)
{
Unshare();
M_BRUSHDATA->m_colour = col;
}
void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
{
Unshare();
M_BRUSHDATA->m_colour.Set(r, g, b);
}
void wxBrush::SetStyle( int style )
{
Unshare();
M_BRUSHDATA->m_style = style;
}
void wxBrush::SetStipple(const wxBitmap& stipple)
{
Unshare();
wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
_T("stipple bitmap must be 8x8") );
M_BRUSHDATA->m_stipple = stipple;
wxBitmapToPixPattern(stipple, &(M_BRUSHDATA->m_pixPattern),
&(M_BRUSHDATA->m_maskPattern));
if (M_BRUSHDATA->m_stipple.GetMask())
M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
else
M_BRUSHDATA->m_style = wxSTIPPLE;
}
void wxBrush::Unshare()
{
if (!m_refData)
{
m_refData = new wxBrushRefData();
}
else
{
wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
UnRef();
m_refData = ref;
}
}

23
src/mgl/clipbrd.cpp Normal file
View File

@ -0,0 +1,23 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gtk/clipbrd.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "clipbrd.h"
#endif
#include "wx/clipbrd.h"
#if wxUSE_CLIPBOARD
IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
#endif
// wxUSE_CLIPBOARD

100
src/mgl/colour.cpp Normal file
View File

@ -0,0 +1,100 @@
/////////////////////////////////////////////////////////////////////////////
// Name: colour.cpp
// Purpose: wxColour class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "colour.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/gdicmn.h"
IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
// Colour
wxColour::wxColour()
{
m_red = m_blue = m_green = 0;
m_isInit = FALSE;
}
wxColour::wxColour(unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
}
wxColour::wxColour(const wxColour& col)
{
m_red = col.m_red;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
}
wxColour& wxColour::operator =(const wxColour& col)
{
m_red = col.m_red;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
return *this;
}
void wxColour::InitFromName(const wxString& col)
{
wxColour *the_colour = wxTheColourDatabase->FindColour (col);
if (the_colour)
{
m_red = the_colour->Red();
m_green = the_colour->Green();
m_blue = the_colour->Blue();
m_isInit = TRUE;
}
else
{
m_red = 0;
m_green = 0;
m_blue = 0;
m_isInit = FALSE;
}
}
wxColour::~wxColour()
{
}
void wxColour::Set(unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
}
// Obsolete
#if WXWIN_COMPATIBILITY
void wxColour::Get(unsigned char *r, unsigned char *g, unsigned char *b) const
{
*r = m_red;
*g = m_green;
*b = m_blue;
}
#endif

256
src/mgl/cursor.cpp Normal file
View File

@ -0,0 +1,256 @@
/////////////////////////////////////////////////////////////////////////////
// Name: cursor.cpp
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "cursor.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/cursor.h"
#include "wx/utils.h"
#include "wx/log.h"
#include "wx/intl.h"
#include <mgraph.hpp>
//-----------------------------------------------------------------------------
// wxCursor
//-----------------------------------------------------------------------------
class wxCursorRefData: public wxObjectRefData
{
public:
wxCursorRefData();
~wxCursorRefData();
MGLCursor *m_cursor;
};
wxCursorRefData::wxCursorRefData()
{
m_cursor = (MGLCursor*) NULL;
}
wxCursorRefData::~wxCursorRefData()
{
delete m_cursor;
}
//-----------------------------------------------------------------------------
#define M_CURSORDATA ((wxCursorRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
wxCursor::wxCursor()
{
}
wxCursor::wxCursor(int cursorId)
{
const char *cursorname = NULL;
m_refData = new wxCursorRefData();
switch (cursorId)
{
case wxCURSOR_ARROW: cursorname = "arrow.cur"; break;
case wxCURSOR_BULLSEYE: cursorname = "bullseye.cur"; break;
case wxCURSOR_CHAR: cursorname = "char.cur"; break;
case wxCURSOR_CROSS: cursorname = "cross.cur"; break;
case wxCURSOR_HAND: cursorname = "hand.cur"; break;
case wxCURSOR_IBEAM: cursorname = "ibeam.cur"; break;
case wxCURSOR_LEFT_BUTTON: cursorname = "leftbtn.cur"; break;
case wxCURSOR_MAGNIFIER: cursorname = "magnif1.cur"; break;
case wxCURSOR_MIDDLE_BUTTON: cursorname = "midbtn.cur"; break;
case wxCURSOR_NO_ENTRY: cursorname = "noentry.cur"; break;
case wxCURSOR_PAINT_BRUSH: cursorname = "pbrush.cur"; break;
case wxCURSOR_PENCIL: cursorname = "pencil.cur"; break;
case wxCURSOR_POINT_LEFT: cursorname = "pntleft.cur"; break;
case wxCURSOR_POINT_RIGHT: cursorname = "pntright.cur"; break;
case wxCURSOR_QUESTION_ARROW: cursorname = "query.cur"; break;
case wxCURSOR_RIGHT_BUTTON: cursorname = "rightbtn.cur"; break;
case wxCURSOR_SIZENESW: cursorname = "sizenesw.cur"; break;
case wxCURSOR_SIZENS: cursorname = "sizens.cur"; break;
case wxCURSOR_SIZENWSE: cursorname = "sizenwse.cur"; break;
case wxCURSOR_SIZEWE: cursorname = "sizewe.cur"; break;
case wxCURSOR_SIZING: cursorname = "size.cur"; break;
case wxCURSOR_SPRAYCAN: cursorname = "spraycan.cur"; break;
case wxCURSOR_WAIT: cursorname = "wait.cur"; break;
case wxCURSOR_WATCH: cursorname = "clock.cur"; break;
case wxCURSOR_BLANK: cursorname = "blank.cur"; break;
case wxCURSOR_NONE:
// FIXME_MGL - make sure wxWindow uses cursor with
// GetMGLCursor() == NULL correctly, i.e. calls MS_hide()
*this = wxNullCursor;
return;
break;
default:
wxFAIL_MSG(wxT("unsupported cursor type"));
break;
}
M_CURSORDATA->m_cursor = new MGLCursor(cursorname);
// if we cannot load arrow cursor, use MGL's default arrow cursor:
if ( !M_CURSORDATA->m_cursor->valid() && cursorId == wxCURSOR_ARROW )
{
delete M_CURSORDATA->m_cursor;
M_CURSORDATA->m_cursor = new MGLCursor(MGL_DEF_CURSOR);
}
if ( !M_CURSORDATA->m_cursor->valid() )
{
wxLogError(_("Couldn't create cursor."));
UnRef();
}
}
wxCursor::wxCursor(const char WXUNUSED(bits)[],
int WXUNUSED(width),
int WXUNUSED(height),
int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY),
const char WXUNUSED(maskBits)[],
wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) )
{
//FIXME_MGL
}
wxCursor::wxCursor(const wxString& cursor_file,
long flags,
int hotSpotX, int hotSpotY)
{
if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE )
{
m_refData = new wxCursorRefData();
M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str());
if ( !M_CURSORDATA->m_cursor->valid() )
{
wxLogError(_("Couldn't create cursor."));
UnRef();
}
}
else
{
wxLogError(wxT("Cannot load cursor resource of this type."));
}
}
wxCursor::wxCursor(const wxCursor &cursor)
{
Ref(cursor);
}
wxCursor::~wxCursor()
{
// wxObject unrefs data
}
wxCursor& wxCursor::operator = (const wxCursor& cursor)
{
if ( *this == cursor )
return (*this);
Ref(cursor);
return *this;
}
bool wxCursor::operator == (const wxCursor& cursor) const
{
return (m_refData == cursor.m_refData);
}
bool wxCursor::operator != (const wxCursor& cursor) const
{
return (m_refData != cursor.m_refData);
}
bool wxCursor::Ok() const
{
return (m_refData != NULL);
}
MGLCursor *wxCursor::GetMGLCursor() const
{
return M_CURSORDATA->m_cursor;
}
// ----------------------------------------------------------------------------
// Global cursor setting
// ----------------------------------------------------------------------------
void wxSetCursor(const wxCursor& cursor)
{
if ( cursor.Ok() )
{
//MGL_setGlobalCursor(cursor.GetMGLCursor());
// FIXME_MGL -- needs MGL WM first
}
}
//-----------------------------------------------------------------------------
// busy cursor routines
//-----------------------------------------------------------------------------
// FIXME_MGL -- do we need this? It may be better to incorporate
// support for it into MGL (a stack of global cursors?)
static wxCursor gs_savedCursor;
static wxCursor g_globalCursor;
static int gs_busyCount = 0;
const wxCursor &wxBusyCursor::GetStoredCursor()
{
return gs_savedCursor;
}
const wxCursor wxBusyCursor::GetBusyCursor()
{
return wxCursor(wxCURSOR_WAIT);
}
void wxEndBusyCursor()
{
if ( --gs_busyCount > 0 ) return;
wxSetCursor(gs_savedCursor);
gs_savedCursor = wxNullCursor;
//wxYield(); FIXME_MGL - needed?
}
void wxBeginBusyCursor(wxCursor *WXUNUSED(cursor))
{
if ( gs_busyCount++ > 0 ) return;
wxASSERT_MSG( !gs_savedCursor.Ok(),
wxT("forgot to call wxEndBusyCursor, will leak memory") );
gs_savedCursor = g_globalCursor;
wxSetCursor(wxCursor(wxCURSOR_WAIT));
//wxYield(); FIXME_MGL - needed?
}
bool wxIsBusy()
{
return (gs_busyCount > 0);
}

175
src/mgl/data.cpp Normal file
View File

@ -0,0 +1,175 @@
/////////////////////////////////////////////////////////////////////////////
// Name: data.cpp
// Purpose: wxMGL data
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// #pragma implementation
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/window.h"
#include "wx/dc.h"
#if wxUSE_ACCEL
#include "wx/accel.h"
#endif
#include "wx/dcps.h"
#include "wx/icon.h"
#define _MAXPATHLEN 500
/* Useful buffer, initialized in wxCommonInit */
wxChar *wxBuffer = (wxChar *) NULL;
/* Windows List */
wxWindowList wxTopLevelWindows;
/* List of windows pending deletion */
wxList wxPendingDelete;
/* Current cursor, in order to hang on to
* cursor handle when setting the cursor globally */
wxCursor g_globalCursor;
/* Don't allow event propagation during drag */
bool g_blockEventsOnDrag = FALSE;
/* Don't allow mouse event propagation during scroll */
bool g_blockEventsOnScroll = FALSE;
/* Don't allow window closing if there are open dialogs */
int g_openDialogs = 0;
/* TRUE when the message queue is empty. this gets set to
FALSE by all event callbacks before anything else is done */
bool g_isIdle = FALSE;
/* Message Strings for Internationalization */
char **wx_msg_str = (char**)NULL;
/* For printing several pages */
int wxPageNumber;
// Now in prntbase.cpp
// wxPrintPaperDatabase* wxThePrintPaperDatabase = (wxPrintPaperDatabase *) NULL;
/* GDI Object Lists */
wxBrushList *wxTheBrushList = (wxBrushList *) NULL;
wxPenList *wxThePenList = (wxPenList *) NULL;
wxFontList *wxTheFontList = (wxFontList *) NULL;
wxColourDatabase *wxTheColourDatabase = (wxColourDatabase *) NULL;
wxBitmapList *wxTheBitmapList = (wxBitmapList *) NULL;
/* X only font names */
/*
wxFontNameDirectory *wxTheFontNameDirectory;
*/
/* Stock objects */
wxFont *wxNORMAL_FONT;
wxFont *wxSMALL_FONT;
wxFont *wxITALIC_FONT;
wxFont *wxSWISS_FONT;
wxPen *wxRED_PEN;
wxPen *wxCYAN_PEN;
wxPen *wxGREEN_PEN;
wxPen *wxBLACK_PEN;
wxPen *wxWHITE_PEN;
wxPen *wxTRANSPARENT_PEN;
wxPen *wxBLACK_DASHED_PEN;
wxPen *wxGREY_PEN;
wxPen *wxMEDIUM_GREY_PEN;
wxPen *wxLIGHT_GREY_PEN;
wxBrush *wxBLUE_BRUSH;
wxBrush *wxGREEN_BRUSH;
wxBrush *wxWHITE_BRUSH;
wxBrush *wxBLACK_BRUSH;
wxBrush *wxTRANSPARENT_BRUSH;
wxBrush *wxCYAN_BRUSH;
wxBrush *wxRED_BRUSH;
wxBrush *wxGREY_BRUSH;
wxBrush *wxMEDIUM_GREY_BRUSH;
wxBrush *wxLIGHT_GREY_BRUSH;
wxColour *wxBLACK;
wxColour *wxWHITE;
wxColour *wxGREY;
wxColour *wxRED;
wxColour *wxBLUE;
wxColour *wxGREEN;
wxColour *wxCYAN;
wxColour *wxLIGHT_GREY;
wxCursor *wxSTANDARD_CURSOR = (wxCursor *) NULL;
wxCursor *wxHOURGLASS_CURSOR = (wxCursor *) NULL;
wxCursor *wxCROSS_CURSOR = (wxCursor *) NULL;
/* 'Null' objects */
#if wxUSE_ACCEL
wxAcceleratorTable wxNullAcceleratorTable;
#endif // wxUSE_ACCEL
wxBitmap wxNullBitmap;
wxIcon wxNullIcon;
wxCursor wxNullCursor;
wxPen wxNullPen;
wxBrush wxNullBrush;
wxFont wxNullFont;
wxColour wxNullColour;
wxPalette wxNullPalette;
/* Default window names */
const wxChar *wxControlNameStr = wxT("control");
const wxChar *wxButtonNameStr = wxT("button");
const wxChar *wxCanvasNameStr = wxT("canvas");
const wxChar *wxCheckBoxNameStr = wxT("check");
const wxChar *wxChoiceNameStr = wxT("choice");
const wxChar *wxComboBoxNameStr = wxT("comboBox");
const wxChar *wxDialogNameStr = wxT("dialog");
const wxChar *wxFrameNameStr = wxT("frame");
const wxChar *wxGaugeNameStr = wxT("gauge");
const wxChar *wxStaticBoxNameStr = wxT("groupBox");
const wxChar *wxListBoxNameStr = wxT("listBox");
const wxChar *wxStaticTextNameStr = wxT("message");
const wxChar *wxStaticBitmapNameStr = wxT("message");
const wxChar *wxMultiTextNameStr = wxT("multitext");
const wxChar *wxPanelNameStr = wxT("panel");
const wxChar *wxRadioBoxNameStr = wxT("radioBox");
const wxChar *wxRadioButtonNameStr = wxT("radioButton");
const wxChar *wxBitmapRadioButtonNameStr = wxT("radioButton");
const wxChar *wxScrollBarNameStr = wxT("scrollBar");
const wxChar *wxSliderNameStr = wxT("slider");
const wxChar *wxStaticNameStr = wxT("static");
const wxChar *wxTextCtrlWindowNameStr = wxT("textWindow");
const wxChar *wxTextCtrlNameStr = wxT("text");
const wxChar *wxVirtListBoxNameStr = wxT("virtListBox");
const wxChar *wxButtonBarNameStr = wxT("buttonbar");
const wxChar *wxEnhDialogNameStr = wxT("Shell");
const wxChar *wxToolBarNameStr = wxT("toolbar");
const wxChar *wxStatusLineNameStr = wxT("status_line");
const wxChar *wxGetTextFromUserPromptStr = wxT("Input Text");
const wxChar *wxMessageBoxCaptionStr = wxT("Message");
const wxChar *wxFileSelectorPromptStr = wxT("Select a file");
const wxChar *wxFileSelectorDefaultWildcardStr = wxT("*");
const wxChar *wxInternalErrorStr = wxT("wxWindows Internal Error");
const wxChar *wxFatalErrorStr = wxT("wxWindows Fatal Error");
const wxChar *wxDirDialogNameStr = wxT("wxDirCtrl");
const wxChar *wxDirDialogDefaultFolderStr = wxT("/");
const wxChar *wxTreeCtrlNameStr = wxT("wxTreeCtrl");
/* See wx/utils.h */
const wxChar *wxFloatToStringStr = wxT("%.2f");
const wxChar *wxDoubleToStringStr = wxT("%.2f");
/* Dafaults for wxWindow etc. */
const wxSize wxDefaultSize(-1, -1);
const wxPoint wxDefaultPosition(-1, -1);

1558
src/mgl/dc.cpp Normal file

File diff suppressed because it is too large Load Diff

19
src/mgl/dcclient.cpp Normal file
View File

@ -0,0 +1,19 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gtk/dcclient.cpp
// Purpose:
// Author: Robert Roebling
// RCS-ID: $Id$
// Copyright: (c) 1998 Robert Roebling, Markus Holzem, Chris Breeze
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcclient.h"
#endif
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC)
IMPLEMENT_DYNAMIC_CLASS(wxClientDC,wxWindowDC)

119
src/mgl/dcmemory.cpp Normal file
View File

@ -0,0 +1,119 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcmemory.cpp
// Purpose:
// Author: Robert Roebling, Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 1998 Robert Roebling, 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcmemory.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/dcmemory.h"
//-----------------------------------------------------------------------------
// wxMemoryDC
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC)
wxMemoryDC::wxMemoryDC() : wxDC()
{
m_isMemDC = TRUE;
}
wxMemoryDC::wxMemoryDC(wxDC *WXUNUSED(dc)) : wxDC()
{
m_isMemDC = TRUE;
}
wxMemoryDC::~wxMemoryDC()
{
}
void wxMemoryDC::SelectObject(const wxBitmap& bitmap)
{
SetMGLDC(NULL, TRUE);
m_selected = bitmap;
if ( bitmap.Ok() )
SetMGLDC(m_selected.CreateTmpDC(), TRUE);
}
void wxMemoryDC::SetPen(const wxPen &pen)
{
wxCHECK_RET( Ok(), wxT("invalid dc") );
if ( GetDepth() == 1 && *wxTRANSPARENT_PEN != pen )
{
if ( *wxWHITE_PEN == pen )
wxDC::SetPen(*wxBLACK_PEN);
else
wxDC::SetPen(*wxWHITE_PEN);
}
else
{
wxDC::SetPen(pen);
}
}
void wxMemoryDC::SetBrush(const wxBrush &brush)
{
wxCHECK_RET( Ok(), wxT("invalid dc") );
if ( GetDepth() == 1 && *wxTRANSPARENT_BRUSH != brush )
{
if ( *wxWHITE_BRUSH == brush )
wxDC::SetBrush(*wxBLACK_BRUSH);
else
wxDC::SetBrush(*wxWHITE_BRUSH);
}
else
{
wxDC::SetBrush(brush);
}
}
void wxMemoryDC::SetTextForeground(const wxColour &col)
{
wxCHECK_RET( Ok(), wxT("invalid dc") );
if ( GetDepth() == 1 )
{
if ( col == *wxWHITE )
wxDC::SetTextForeground(*wxBLACK);
else
wxDC::SetTextForeground(*wxWHITE);
}
else
{
wxDC::SetTextForeground(col);
}
}
void wxMemoryDC::SetTextBackground(const wxColour &col)
{
wxCHECK_RET( Ok(), wxT("invalid dc") );
if ( GetDepth() == 1 )
{
if ( col == *wxWHITE )
wxDC::SetTextBackground(*wxBLACK);
else
wxDC::SetTextBackground(*wxWHITE);
}
else
{
wxDC::SetTextBackground(col);
}
}

18
src/mgl/dcscreen.cpp Normal file
View File

@ -0,0 +1,18 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dcscreen.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dcscreen.h"
#endif
#include "wx/dcscreen.h"
#include "wx/window.h"
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC,wxPaintDC)

21
src/mgl/dialog.cpp Normal file
View File

@ -0,0 +1,21 @@
/////////////////////////////////////////////////////////////////////////////
// Name: dialog.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "dialog.h"
#endif
#include "wx/dialog.h"
#include "wx/frame.h"
#include "wx/app.h"
#include "wx/cursor.h"
IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel)

993
src/mgl/files.lst Normal file
View File

@ -0,0 +1,993 @@
# This file was automatically generated by tmake at 17:30, 2001/04/28
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE GTK.T!
ALL_SOURCES = \
generic/busyinfo.cpp \
generic/calctrl.cpp \
generic/caret.cpp \
generic/choicdgg.cpp \
generic/colrdlgg.cpp \
generic/dcpsg.cpp \
generic/dirctrlg.cpp \
generic/dirdlgg.cpp \
generic/dragimgg.cpp \
generic/filedlgg.cpp \
generic/grid.cpp \
generic/gridsel.cpp \
generic/helpext.cpp \
generic/helphtml.cpp \
generic/helpwxht.cpp \
generic/imaglist.cpp \
generic/laywin.cpp \
generic/listctrl.cpp \
generic/logg.cpp \
generic/msgdlgg.cpp \
generic/numdlgg.cpp \
generic/panelg.cpp \
generic/plot.cpp \
generic/printps.cpp \
generic/prntdlgg.cpp \
generic/progdlgg.cpp \
generic/prop.cpp \
generic/propform.cpp \
generic/proplist.cpp \
generic/sashwin.cpp \
generic/scrolwin.cpp \
generic/splash.cpp \
generic/splitter.cpp \
generic/statusbr.cpp \
generic/tabg.cpp \
generic/tbarsmpl.cpp \
generic/textdlgg.cpp \
generic/tipdlg.cpp \
generic/treectlg.cpp \
generic/treelay.cpp \
generic/wizard.cpp \
common/appcmn.cpp \
common/choiccmn.cpp \
common/clipcmn.cpp \
common/cmdline.cpp \
common/cmndata.cpp \
common/config.cpp \
common/ctrlcmn.cpp \
common/ctrlsub.cpp \
common/datetime.cpp \
common/datstrm.cpp \
common/db.cpp \
common/dbtable.cpp \
common/dcbase.cpp \
common/dlgcmn.cpp \
common/dndcmn.cpp \
common/dobjcmn.cpp \
common/docmdi.cpp \
common/docview.cpp \
common/dynarray.cpp \
common/dynlib.cpp \
common/effects.cpp \
common/encconv.cpp \
common/event.cpp \
common/extended.c \
common/ffile.cpp \
common/file.cpp \
common/fileconf.cpp \
common/filefn.cpp \
common/filesys.cpp \
common/fontcmn.cpp \
common/fontmap.cpp \
common/framecmn.cpp \
common/fs_inet.cpp \
common/fs_mem.cpp \
common/fs_zip.cpp \
common/ftp.cpp \
common/gdicmn.cpp \
common/geometry.cpp \
common/gifdecod.cpp \
common/hash.cpp \
common/helpbase.cpp \
common/http.cpp \
common/imagall.cpp \
common/imagbmp.cpp \
common/image.cpp \
common/imaggif.cpp \
common/imagjpeg.cpp \
common/imagpcx.cpp \
common/imagpng.cpp \
common/imagpnm.cpp \
common/imagtiff.cpp \
common/imagxpm.cpp \
common/intl.cpp \
common/ipcbase.cpp \
common/layout.cpp \
common/lboxcmn.cpp \
common/list.cpp \
common/log.cpp \
common/longlong.cpp \
common/memory.cpp \
common/menucmn.cpp \
common/mimecmn.cpp \
common/module.cpp \
common/mstream.cpp \
common/object.cpp \
common/objstrm.cpp \
common/paper.cpp \
common/prntbase.cpp \
common/process.cpp \
common/protocol.cpp \
common/quantize.cpp \
common/resource.cpp \
common/sckaddr.cpp \
common/sckfile.cpp \
common/sckipc.cpp \
common/sckstrm.cpp \
common/serbase.cpp \
common/sizer.cpp \
common/socket.cpp \
common/strconv.cpp \
common/stream.cpp \
common/string.cpp \
common/tbarbase.cpp \
common/textcmn.cpp \
common/textfile.cpp \
common/timercmn.cpp \
common/tokenzr.cpp \
common/treebase.cpp \
common/txtstrm.cpp \
common/unzip.c \
common/url.cpp \
common/utilscmn.cpp \
common/valgen.cpp \
common/validate.cpp \
common/valtext.cpp \
common/variant.cpp \
common/wfstream.cpp \
common/wincmn.cpp \
common/wxchar.cpp \
common/wxexpr.cpp \
common/xpmdecod.cpp \
common/zipstrm.cpp \
common/zstream.cpp \
mgl/app.cpp \
mgl/bitmap.cpp \
mgl/bmpbase.cpp \
mgl/brush.cpp \
mgl/clipbrd.cpp \
mgl/colour.cpp \
mgl/cursor.cpp \
mgl/data.cpp \
mgl/dc.cpp \
mgl/dcclient.cpp \
mgl/dcmemory.cpp \
mgl/dcscreen.cpp \
mgl/dialog.cpp \
mgl/font.cpp \
mgl/frame.cpp \
mgl/gdiobj.cpp \
mgl/icon.cpp \
mgl/palette.cpp \
mgl/pen.cpp \
mgl/region.cpp \
mgl/settings.cpp \
mgl/timer.cpp \
mgl/utils.cpp \
mgl/window.cpp \
unix/dialup.cpp \
unix/dir.cpp \
unix/fontenum.cpp \
unix/fontutil.cpp \
unix/gsocket.c \
unix/mimetype.cpp \
unix/threadpsx.cpp \
unix/utilsunx.cpp \
html/helpctrl.cpp \
html/helpdata.cpp \
html/helpfrm.cpp \
html/htmlcell.cpp \
html/htmlfilt.cpp \
html/htmlpars.cpp \
html/htmltag.cpp \
html/htmlwin.cpp \
html/htmprint.cpp \
html/m_dflist.cpp \
html/m_fonts.cpp \
html/m_hline.cpp \
html/m_image.cpp \
html/m_layout.cpp \
html/m_links.cpp \
html/m_list.cpp \
html/m_meta.cpp \
html/m_pre.cpp \
html/m_tables.cpp \
html/winpars.cpp
ALL_HEADERS = \
accel.h \
app.h \
arrimpl.cpp \
bitmap.h \
bmpbuttn.h \
brush.h \
buffer.h \
busyinfo.h \
button.h \
calctrl.h \
caret.h \
checkbox.h \
checklst.h \
choicdlg.h \
choice.h \
clipbrd.h \
cmdline.h \
cmndata.h \
colordlg.h \
colour.h \
combobox.h \
confbase.h \
config.h \
control.h \
ctrlsub.h \
cursor.h \
dataobj.h \
date.h \
datetime.h \
datetime.inl \
datstrm.h \
db.h \
dbtable.h \
dc.h \
dcclient.h \
dcmemory.h \
dcprint.h \
dcps.h \
dcscreen.h \
dde.h \
debug.h \
defs.h \
dialog.h \
dialup.h \
dir.h \
dirdlg.h \
dnd.h \
docmdi.h \
docview.h \
dragimag.h \
dynarray.h \
dynlib.h \
encconv.h \
event.h \
expr.h \
ffile.h \
file.h \
fileconf.h \
filedlg.h \
filefn.h \
filesys.h \
font.h \
fontdlg.h \
fontenc.h \
fontenum.h \
fontmap.h \
fontutil.h \
frame.h \
fs_inet.h \
fs_mem.h \
fs_zip.h \
gauge.h \
gdicmn.h \
gdiobj.h \
geometry.h \
gifdecod.h \
glcanvas.h \
grid.h \
gsocket.h \
hash.h \
help.h \
helpbase.h \
helpchm.h \
helphtml.h \
helpwin.h \
helpxlp.h \
icon.h \
imagbmp.h \
image.h \
imaggif.h \
imagjpeg.h \
imaglist.h \
imagpcx.h \
imagpng.h \
imagpnm.h \
imagtiff.h \
imagxpm.h \
intl.h \
ioswrap.h \
ipcbase.h \
isql.h \
isqlext.h \
joystick.h \
layout.h \
laywin.h \
list.h \
listbox.h \
listctrl.h \
listimpl.cpp \
log.h \
longlong.h \
matrix.h \
mdi.h \
memconf.h \
memory.h \
menu.h \
menuitem.h \
metafile.h \
mimetype.h \
minifram.h \
module.h \
msgdlg.h \
mstream.h \
notebook.h \
object.h \
objstrm.h \
odbc.h \
ownerdrw.h \
palette.h \
panel.h \
paper.h \
pen.h \
plot.h \
print.h \
printdlg.h \
prntbase.h \
process.h \
progdlg.h \
prop.h \
propform.h \
proplist.h \
radiobox.h \
radiobut.h \
region.h \
resource.h \
sashwin.h \
sckaddr.h \
sckipc.h \
sckstrm.h \
scrolbar.h \
scrolwin.h \
serbase.h \
settings.h \
setup.h \
sizer.h \
slider.h \
socket.h \
spinbutt.h \
spinctrl.h \
splitter.h \
statbmp.h \
statbox.h \
statline.h \
stattext.h \
statusbr.h \
strconv.h \
stream.h \
string.h \
tab.h \
tabctrl.h \
taskbar.h \
tbarbase.h \
tbarsmpl.h \
textctrl.h \
textdlg.h \
textfile.h \
thread.h \
time.h \
timer.h \
tipdlg.h \
tokenzr.h \
toolbar.h \
tooltip.h \
treebase.h \
treectrl.h \
txtstrm.h \
types.h \
url.h \
utils.h \
valgen.h \
validate.h \
valtext.h \
variant.h \
version.h \
wave.h \
wfstream.h \
window.h \
wizard.h \
wx.h \
wx_cw.h \
wx_cw_cm.h \
wx_cw_d.h \
wxchar.h \
wxexpr.h \
wxhtml.h \
wxprec.h \
xpmdecod.h \
xpmhand.h \
zipstrm.h \
zstream.h \
gtk/accel.h \
gtk/app.h \
gtk/bitmap.h \
gtk/bmpbuttn.h \
gtk/brush.h \
gtk/button.h \
gtk/checkbox.h \
gtk/checklst.h \
gtk/choice.h \
gtk/clipbrd.h \
gtk/colour.h \
gtk/combobox.h \
gtk/control.h \
gtk/cursor.h \
gtk/dataform.h \
gtk/dataobj.h \
gtk/dataobj2.h \
gtk/dc.h \
gtk/dcclient.h \
gtk/dcmemory.h \
gtk/dcscreen.h \
gtk/dialog.h \
gtk/dnd.h \
gtk/filedlg.h \
gtk/font.h \
gtk/fontdlg.h \
gtk/frame.h \
gtk/gauge.h \
gtk/gdiobj.h \
gtk/glcanvas.h \
gtk/icon.h \
gtk/joystick.h \
gtk/listbox.h \
gtk/mdi.h \
gtk/menu.h \
gtk/menuitem.h \
gtk/minifram.h \
gtk/notebook.h \
gtk/palette.h \
gtk/pen.h \
gtk/radiobox.h \
gtk/radiobut.h \
gtk/region.h \
gtk/scrolbar.h \
gtk/settings.h \
gtk/slider.h \
gtk/spinbutt.h \
gtk/spinctrl.h \
gtk/statbmp.h \
gtk/statbox.h \
gtk/statline.h \
gtk/stattext.h \
gtk/tbargtk.h \
gtk/textctrl.h \
gtk/timer.h \
gtk/tooltip.h \
gtk/treectrl.h \
gtk/wave.h \
gtk/win_gtk.h \
gtk/window.h \
generic/calctrl.h \
generic/caret.h \
generic/choicdgg.h \
generic/colrdlgg.h \
generic/dcpsg.h \
generic/dirctrlg.h \
generic/dirdlgg.h \
generic/dragimgg.h \
generic/filedlgg.h \
generic/fontdlgg.h \
generic/grid.h \
generic/gridg.h \
generic/helpext.h \
generic/helphtml.h \
generic/helpwxht.h \
generic/helpxlp.h \
generic/imaglist.h \
generic/laywin.h \
generic/listctrl.h \
generic/msgdlgg.h \
generic/notebook.h \
generic/panelg.h \
generic/plot.h \
generic/printps.h \
generic/prntdlgg.h \
generic/progdlgg.h \
generic/sashwin.h \
generic/scrolwin.h \
generic/splitter.h \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \
unix/fontutil.h \
unix/gsockunx.h \
unix/mimetype.h \
html/forcelnk.h \
html/helpctrl.h \
html/helpdata.h \
html/helpfrm.h \
html/htmlcell.h \
html/htmldefs.h \
html/htmlfilt.h \
html/htmlpars.h \
html/htmltag.h \
html/htmlwin.h \
html/htmprint.h \
html/m_templ.h \
html/winpars.h \
protocol/file.h \
protocol/ftp.h \
protocol/http.h \
protocol/protocol.h
COMMONOBJS = \
parser.o \
appcmn.o \
choiccmn.o \
clipcmn.o \
cmdline.o \
cmndata.o \
config.o \
ctrlcmn.o \
ctrlsub.o \
datetime.o \
datstrm.o \
db.o \
dbtable.o \
dcbase.o \
dlgcmn.o \
dndcmn.o \
dobjcmn.o \
docmdi.o \
docview.o \
dynarray.o \
dynlib.o \
effects.o \
encconv.o \
event.o \
extended.o \
ffile.o \
file.o \
fileconf.o \
filefn.o \
filesys.o \
fontcmn.o \
fontmap.o \
framecmn.o \
fs_inet.o \
fs_mem.o \
fs_zip.o \
ftp.o \
gdicmn.o \
geometry.o \
gifdecod.o \
hash.o \
helpbase.o \
http.o \
imagall.o \
imagbmp.o \
image.o \
imaggif.o \
imagjpeg.o \
imagpcx.o \
imagpng.o \
imagpnm.o \
imagtiff.o \
imagxpm.o \
intl.o \
ipcbase.o \
layout.o \
lboxcmn.o \
list.o \
log.o \
longlong.o \
memory.o \
menucmn.o \
mimecmn.o \
module.o \
mstream.o \
object.o \
objstrm.o \
paper.o \
prntbase.o \
process.o \
protocol.o \
quantize.o \
resource.o \
sckaddr.o \
sckfile.o \
sckipc.o \
sckstrm.o \
serbase.o \
sizer.o \
socket.o \
strconv.o \
stream.o \
string.o \
tbarbase.o \
textcmn.o \
textfile.o \
timercmn.o \
tokenzr.o \
treebase.o \
txtstrm.o \
unzip.o \
url.o \
utilscmn.o \
valgen.o \
validate.o \
valtext.o \
variant.o \
wfstream.o \
wincmn.o \
wxchar.o \
wxexpr.o \
xpmdecod.o \
zipstrm.o \
zstream.o
COMMONDEPS = \
parser.d \
appcmn.d \
choiccmn.d \
clipcmn.d \
cmdline.d \
cmndata.d \
config.d \
ctrlcmn.d \
ctrlsub.d \
datetime.d \
datstrm.d \
db.d \
dbtable.d \
dcbase.d \
dlgcmn.d \
dndcmn.d \
dobjcmn.d \
docmdi.d \
docview.d \
dynarray.d \
dynlib.d \
effects.d \
encconv.d \
event.d \
extended.d \
ffile.d \
file.d \
fileconf.d \
filefn.d \
filesys.d \
fontcmn.d \
fontmap.d \
framecmn.d \
fs_inet.d \
fs_mem.d \
fs_zip.d \
ftp.d \
gdicmn.d \
geometry.d \
gifdecod.d \
hash.d \
helpbase.d \
http.d \
imagall.d \
imagbmp.d \
image.d \
imaggif.d \
imagjpeg.d \
imagpcx.d \
imagpng.d \
imagpnm.d \
imagtiff.d \
imagxpm.d \
intl.d \
ipcbase.d \
layout.d \
lboxcmn.d \
list.d \
log.d \
longlong.d \
memory.d \
menucmn.d \
mimecmn.d \
module.d \
mstream.d \
object.d \
objstrm.d \
paper.d \
prntbase.d \
process.d \
protocol.d \
quantize.d \
resource.d \
sckaddr.d \
sckfile.d \
sckipc.d \
sckstrm.d \
serbase.d \
sizer.d \
socket.d \
strconv.d \
stream.d \
string.d \
tbarbase.d \
textcmn.d \
textfile.d \
timercmn.d \
tokenzr.d \
treebase.d \
txtstrm.d \
unzip.d \
url.d \
utilscmn.d \
valgen.d \
validate.d \
valtext.d \
variant.d \
wfstream.d \
wincmn.d \
wxchar.d \
wxexpr.d \
xpmdecod.d \
zipstrm.d \
zstream.d
GENERICOBJS = \
busyinfo.o \
calctrl.o \
caret.o \
choicdgg.o \
colrdlgg.o \
dcpsg.o \
dirctrlg.o \
dirdlgg.o \
dragimgg.o \
filedlgg.o \
grid.o \
gridsel.o \
helpext.o \
helphtml.o \
helpwxht.o \
imaglist.o \
laywin.o \
listctrl.o \
logg.o \
msgdlgg.o \
numdlgg.o \
panelg.o \
plot.o \
printps.o \
prntdlgg.o \
progdlgg.o \
prop.o \
propform.o \
proplist.o \
sashwin.o \
scrolwin.o \
splash.o \
splitter.o \
statusbr.o \
tabg.o \
tbarsmpl.o \
textdlgg.o \
tipdlg.o \
treectlg.o \
treelay.o \
wizard.o
GENERICDEPS = \
busyinfo.d \
calctrl.d \
caret.d \
choicdgg.d \
colrdlgg.d \
dcpsg.d \
dirctrlg.d \
dirdlgg.d \
dragimgg.d \
filedlgg.d \
grid.d \
gridsel.d \
helpext.d \
helphtml.d \
helpwxht.d \
imaglist.d \
laywin.d \
listctrl.d \
logg.d \
msgdlgg.d \
numdlgg.d \
panelg.d \
plot.d \
printps.d \
prntdlgg.d \
progdlgg.d \
prop.d \
propform.d \
proplist.d \
sashwin.d \
scrolwin.d \
splash.d \
splitter.d \
statusbr.d \
tabg.d \
tbarsmpl.d \
textdlgg.d \
tipdlg.d \
treectlg.d \
treelay.d \
wizard.d
GUIOBJS = \
app.o \
bitmap.o \
bmpbase.o \
brush.o \
clipbrd.o \
colour.o \
cursor.o \
data.o \
dc.o \
dcclient.o \
dcmemory.o \
dcscreen.o \
dialog.o \
font.o \
frame.o \
gdiobj.o \
icon.o \
palette.o \
pen.o \
region.o \
settings.o \
timer.o \
utils.o \
window.o
GUIDEPS = \
app.d \
bitmap.d \
bmpbase.d \
brush.d \
clipbrd.d \
colour.d \
cursor.d \
data.d \
dc.d \
dcclient.d \
dcmemory.d \
dcscreen.d \
dialog.d \
font.d \
frame.d \
gdiobj.d \
icon.d \
palette.d \
pen.d \
region.d \
settings.d \
timer.d \
utils.d \
window.d
GUI_LOWLEVEL_OBJS = \
app.o \
bitmap.o \
bmpbase.o \
brush.o \
clipbrd.o \
colour.o \
cursor.o \
data.o \
dc.o \
dcclient.o \
dcmemory.o \
dcscreen.o \
dialog.o \
font.o \
frame.o \
gdiobj.o \
icon.o \
palette.o \
pen.o \
region.o \
settings.o \
timer.o \
utils.o \
window.o
GUI_LOWLEVEL_DEPS = \
app.d \
bitmap.d \
bmpbase.d \
brush.d \
clipbrd.d \
colour.d \
cursor.d \
data.d \
dc.d \
dcclient.d \
dcmemory.d \
dcscreen.d \
dialog.d \
font.d \
frame.d \
gdiobj.d \
icon.d \
palette.d \
pen.d \
region.d \
settings.d \
timer.d \
utils.d \
window.d
UNIXOBJS = \
dialup.o \
dir.o \
fontenum.o \
fontutil.o \
gsocket.o \
mimetype.o \
threadpsx.o \
utilsunx.o
UNIXDEPS = \
dialup.d \
dir.d \
fontenum.d \
fontutil.d \
gsocket.d \
mimetype.d \
threadpsx.d \
utilsunx.d
HTMLOBJS = \
helpctrl.o \
helpdata.o \
helpfrm.o \
htmlcell.o \
htmlfilt.o \
htmlpars.o \
htmltag.o \
htmlwin.o \
htmprint.o \
m_dflist.o \
m_fonts.o \
m_hline.o \
m_image.o \
m_layout.o \
m_links.o \
m_list.o \
m_meta.o \
m_pre.o \
m_tables.o \
winpars.o
HTMLDEPS = \
helpctrl.d \
helpdata.d \
helpfrm.d \
htmlcell.d \
htmlfilt.d \
htmlpars.d \
htmltag.d \
htmlwin.d \
htmprint.d \
m_dflist.d \
m_fonts.d \
m_hline.d \
m_image.d \
m_layout.d \
m_links.d \
m_list.d \
m_meta.d \
m_pre.d \
m_tables.d \
winpars.d

324
src/mgl/font.cpp Normal file
View File

@ -0,0 +1,324 @@
/////////////////////////////////////////////////////////////////////////////
// Name: font.cpp
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001, Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "font.h"
#endif
#include "wx/font.h"
#include "wx/fontutil.h"
#include "wx/cmndata.h"
#include "wx/utils.h"
#include "wx/log.h"
#include "wx/gdicmn.h"
#include "wx/tokenzr.h"
#include "wx/settings.h"
#include <strings.h>
// ----------------------------------------------------------------------------
// wxFontRefData
// ----------------------------------------------------------------------------
class wxFontRefData : public wxObjectRefData
{
public:
wxFontRefData(int size = wxDEFAULT,
int family = wxDEFAULT,
int style = wxDEFAULT,
int weight = wxDEFAULT,
bool underlined = FALSE,
const wxString& faceName = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
wxFontRefData(const wxFontRefData& data);
virtual ~wxFontRefData();
protected:
// common part of all ctors
void Init(int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding);
private:
int m_pointSize;
int m_family,
m_style,
m_weight;
bool m_underlined;
wxString m_faceName;
wxFontEncoding m_encoding;
wxMGLFontLibrary *m_library;
bool m_valid;
friend class wxFont;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxFontRefData
// ----------------------------------------------------------------------------
void wxFontRefData::Init(int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding)
{
if ( family == wxDEFAULT )
m_family = wxSWISS;
else
m_family = family;
m_faceName = faceName;
if ( style == wxDEFAULT )
m_style = wxNORMAL;
else
m_style = style;
if ( weight == wxDEFAULT )
m_weight = wxNORMAL;
else
m_weight = weight;
if ( pointSize == wxDEFAULT )
m_pointSize = 12;
else
m_pointSize = pointSize;
m_underlined = underlined;
m_encoding = encoding;
m_library = NULL;
m_valid = FALSE;
}
wxFontRefData::wxFontRefData(const wxFontRefData& data)
{
Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
data.m_underlined, data.m_faceName, data.m_encoding);
m_library = data.m_library;
m_valid = data.m_valid;
if ( m_library )
m_library->IncRef();
}
wxFontRefData::wxFontRefData(int size, int family, int style,
int weight, bool underlined,
const wxString& faceName,
wxFontEncoding encoding)
{
Init(size, family, style, weight, underlined, faceName, encoding);
}
wxFontRefData::~wxFontRefData()
{
if ( m_library )
m_library->DecRef();
}
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
void wxFont::Init()
{
if (wxTheFontList)
wxTheFontList->Append(this);
}
bool wxFont::Create(const wxNativeFontInfo& info)
{
return Create(info.pointSize, info.family, info.style, info.weight,
info.underlined, info.faceName, info.encoding);
}
bool wxFont::Create(int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString& face,
wxFontEncoding encoding)
{
m_refData = new wxFontRefData(pointSize, family, style, weight,
underlined, face, encoding);
return TRUE;
}
struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased)
{
if ( !M_FONTDATA->m_valid )
{
wxMGLFontLibrary *old = M_FONTDATA->m_library;
M_FONTDATA->m_library = wxTheFontsManager->GetFontLibrary(this);
M_FONTDATA->m_library->IncRef();
if ( old )
old->DecRef();
}
wxMGLFontInstance *instance =
M_FONTDATA->m_library->GetFontInstance(this, scale, antialiased);
return instance->GetMGLfont_t();
}
void wxFont::Unshare()
{
if ( !m_refData )
{
m_refData = new wxFontRefData();
}
else
{
wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
UnRef();
m_refData = ref;
}
}
wxFont::~wxFont()
{
if (wxTheFontList)
wxTheFontList->DeleteObject(this);
}
// ----------------------------------------------------------------------------
// accessors
// ----------------------------------------------------------------------------
int wxFont::GetPointSize() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
return M_FONTDATA->m_pointSize;
}
wxString wxFont::GetFaceName() const
{
wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
return M_FONTDATA->m_faceName;
}
int wxFont::GetFamily() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
return M_FONTDATA->m_family;
}
int wxFont::GetStyle() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
return M_FONTDATA->m_style;
}
int wxFont::GetWeight() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
return M_FONTDATA->m_weight;
}
bool wxFont::GetUnderlined() const
{
wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
return M_FONTDATA->m_underlined;
}
wxFontEncoding wxFont::GetEncoding() const
{
wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
return M_FONTDATA->m_encoding;
}
// ----------------------------------------------------------------------------
// change font attributes
// ----------------------------------------------------------------------------
void wxFont::SetPointSize(int pointSize)
{
Unshare();
M_FONTDATA->m_pointSize = pointSize;
M_FONTDATA->m_valid = FALSE;
}
void wxFont::SetFamily(int family)
{
Unshare();
M_FONTDATA->m_family = family;
M_FONTDATA->m_valid = FALSE;
}
void wxFont::SetStyle(int style)
{
Unshare();
M_FONTDATA->m_style = style;
M_FONTDATA->m_valid = FALSE;
}
void wxFont::SetWeight(int weight)
{
Unshare();
M_FONTDATA->m_weight = weight;
M_FONTDATA->m_valid = FALSE;
}
void wxFont::SetFaceName(const wxString& faceName)
{
Unshare();
M_FONTDATA->m_faceName = faceName;
M_FONTDATA->m_valid = FALSE;
}
void wxFont::SetUnderlined(bool underlined)
{
Unshare();
M_FONTDATA->m_underlined = underlined;
}
void wxFont::SetEncoding(wxFontEncoding encoding)
{
Unshare();
M_FONTDATA->m_encoding = encoding;
M_FONTDATA->m_valid = FALSE;
}

141
src/mgl/fontenum.cpp Normal file
View File

@ -0,0 +1,141 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/unix/fontenum.cpp
// Purpose: wxFontEnumerator class for MGL
// Author: Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "fontenum.h"
#endif
#include "wx/defs.h"
#include "wx/dynarray.h"
#include "wx/string.h"
#include "wx/utils.h"
#include "wx/fontenum.h"
#include "wx/fontutil.h"
#include <mgraph.h>
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxFontEnumerator
// ----------------------------------------------------------------------------
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
bool fixedWidthOnly)
{
bool found = FALSE;
wxMGLFontFamilyList *list = wxTheFontsManager->GetFamilyList();
wxMGLFontFamilyList::Node *node;
wxMGLFontFamily *f = NULL;
wxNativeEncodingInfo info;
if ( encoding != wxFONTENCODING_SYSTEM )
wxGetNativeFontEncoding(encoding, &info);
for (node = list->GetFirst(); node; node = node->GetNext())
{
f = node->GetData();
info.facename = f->GetName();
if ( (!fixedWidthOnly || f->GetInfo()->isFixed) &&
(encoding == wxFONTENCODING_SYSTEM || wxTestFontEncoding(info)) )
{
found = TRUE;
if ( !OnFacename(f->GetName()) )
return TRUE;
}
}
return found;
}
bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
{
static wxFontEncoding encodings[] =
{
wxFONTENCODING_ISO8859_1,
wxFONTENCODING_ISO8859_2,
wxFONTENCODING_ISO8859_3,
wxFONTENCODING_ISO8859_4,
wxFONTENCODING_ISO8859_5,
wxFONTENCODING_ISO8859_6,
wxFONTENCODING_ISO8859_7,
wxFONTENCODING_ISO8859_8,
wxFONTENCODING_ISO8859_9,
wxFONTENCODING_ISO8859_10,
//wxFONTENCODING_ISO8859_11,
//wxFONTENCODING_ISO8859_12,
wxFONTENCODING_ISO8859_13,
wxFONTENCODING_ISO8859_14,
wxFONTENCODING_ISO8859_15,
wxFONTENCODING_CP1250,
wxFONTENCODING_CP1251,
wxFONTENCODING_CP1252,
wxFONTENCODING_CP1253,
wxFONTENCODING_CP1254,
wxFONTENCODING_CP1255,
wxFONTENCODING_CP1256,
wxFONTENCODING_CP1257,
wxFONTENCODING_KOI8,
wxFONTENCODING_SYSTEM
};
static const char *encodingNames[] =
{
"iso88590-1",
"iso88590-2",
"iso88590-3",
"iso88590-4",
"iso88590-5",
"iso88590-6",
"iso88590-7",
"iso88590-8",
"iso88590-9",
"iso88590-10",
"iso88590-13",
"iso88590-14",
"iso88590-15",
"windows-1250",
"windows-1251",
"windows-1252",
"windows-1253",
"windows-1254",
"windows-1255",
"windows-1256",
"windows-1257",
"koi-8",
NULL
};
wxNativeEncodingInfo info;
info.facename = family;
for (size_t i = 0; encodings[i] != wxFONTENCODING_SYSTEM; i++)
{
if ( !wxGetNativeFontEncoding(encodings[i], &info) ||
!wxTestFontEncoding(info) )
continue;
if ( !OnFontEncoding(family, encodingNames[i]) )
break;
}
return TRUE;
}

456
src/mgl/fontutil.cpp Normal file
View File

@ -0,0 +1,456 @@
/////////////////////////////////////////////////////////////////////////////
// Name: mgl/fontutil.cpp
// Purpose: Font helper functions for MGL
// Author: Vaclav Slavik
// Created: 2001/04/29
// RCS-ID: $Id$
// Copyright: (c) 2001, Vaclav Slavik
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "fontutil.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#endif // PCH
#include "wx/fontutil.h"
#include "wx/fontmap.h"
#include "wx/tokenzr.h"
#include "wx/hash.h"
#include "wx/module.h"
#include "wx/listimpl.cpp"
#include "wx/log.h"
#include "wx/mgl/private.h"
#include <mgraph.h>
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxNativeEncodingInfo
// ----------------------------------------------------------------------------
// convert to/from the string representation: format is
// encoding[;facename]
bool wxNativeEncodingInfo::FromString(const wxString& s)
{
wxStringTokenizer tokenizer(s, _T(";"));
wxString encid = tokenizer.GetNextToken();
long enc;
if ( !encid.ToLong(&enc) )
return FALSE;
encoding = (wxFontEncoding)enc;
// ok even if empty
facename = tokenizer.GetNextToken();
return TRUE;
}
wxString wxNativeEncodingInfo::ToString() const
{
wxString s;
s << (long)encoding;
if ( !!facename )
{
s << _T(';') << facename;
}
return s;
}
// ----------------------------------------------------------------------------
// common functions
// ----------------------------------------------------------------------------
bool wxGetNativeFontEncoding(wxFontEncoding encoding,
wxNativeEncodingInfo *info)
{
wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
if ( encoding == wxFONTENCODING_DEFAULT )
{
encoding = wxFont::GetDefaultEncoding();
}
switch ( encoding )
{
case wxFONTENCODING_ISO8859_1:
case wxFONTENCODING_ISO8859_2:
case wxFONTENCODING_ISO8859_3:
case wxFONTENCODING_ISO8859_4:
case wxFONTENCODING_ISO8859_5:
case wxFONTENCODING_ISO8859_6:
case wxFONTENCODING_ISO8859_7:
case wxFONTENCODING_ISO8859_8:
case wxFONTENCODING_ISO8859_9:
case wxFONTENCODING_ISO8859_10:
case wxFONTENCODING_ISO8859_11:
case wxFONTENCODING_ISO8859_13:
case wxFONTENCODING_ISO8859_14:
case wxFONTENCODING_ISO8859_15:
info->mglEncoding = MGL_ENCODING_ISO8859_1 +
(encoding - wxFONTENCODING_ISO8859_1);
break;
case wxFONTENCODING_KOI8:
info->mglEncoding = MGL_ENCODING_KOI8;
break;
case wxFONTENCODING_CP1250:
case wxFONTENCODING_CP1251:
case wxFONTENCODING_CP1252:
case wxFONTENCODING_CP1253:
case wxFONTENCODING_CP1254:
case wxFONTENCODING_CP1255:
case wxFONTENCODING_CP1256:
case wxFONTENCODING_CP1257:
info->mglEncoding = MGL_ENCODING_CP1250 +
(encoding - wxFONTENCODING_CP1250);
break;
case wxFONTENCODING_SYSTEM:
info->mglEncoding = MGL_ENCODING_ASCII;
break;
default:
// encoding not known to MGL
return FALSE;
}
info->encoding = encoding;
return TRUE;
}
bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
{
if ( !info.facename )
return TRUE;
wxMGLFontFamily *family = wxTheFontsManager->GetFamily(info.facename);
if ( !family )
return FALSE;
if ( family->GetInfo()->fontLibType == MGL_BITMAPFONT_LIB )
return (info.mglEncoding == MGL_ENCODING_ASCII ||
info.mglEncoding == MGL_ENCODING_ISO8859_1 ||
info.mglEncoding == MGL_ENCODING_ISO8859_15 ||
info.mglEncoding == MGL_ENCODING_CP1252);
else
return TRUE;
}
// ----------------------------------------------------------------------------
// wxFontFamily, wxMGLFontInstance, wxMGLFontLibrary
// ----------------------------------------------------------------------------
WX_DECLARE_LIST(wxMGLFontInstance, wxMGLFontInstanceList);
WX_DEFINE_LIST(wxMGLFontInstanceList);
WX_DEFINE_LIST(wxMGLFontFamilyList);
wxMGLFontInstance::wxMGLFontInstance(wxMGLFontLibrary *fontLib,
float pt, bool slant, bool aa)
{
m_fontLib = fontLib;
m_font = NULL;
m_pt = pt;
m_slant = slant;
m_aa = aa;
float slantAngle = m_slant ? 15.0 : 0.0;
wxLogTrace("mgl_font", "loading instance of '%s' slant=%i pt=%0.1f aa=%i",
m_fontLib->GetMGLfont_lib_t()->name, m_slant, m_pt, m_aa);
m_font = MGL_loadFontInstance(m_fontLib->GetMGLfont_lib_t(),
m_pt, slantAngle, 0.0, aa);
wxASSERT_MSG( m_font, wxT("Cannot create font instance.") );
}
wxMGLFontInstance::~wxMGLFontInstance()
{
wxLogTrace("mgl_font", "unloading instance of '%s' slant=%i pt=%0.1f aa=%i",
m_fontLib->GetMGLfont_lib_t()->name, m_slant, m_pt, m_aa);
if ( m_font )
MGL_unloadFontInstance(m_font);
}
wxMGLFontLibrary::wxMGLFontLibrary(const wxString& filename, int type)
{
m_type = type;
m_fileName = filename;
m_refs = 0;
m_fontLib = NULL;
m_instances = new wxMGLFontInstanceList;
m_instances->DeleteContents(TRUE);
}
wxMGLFontLibrary::~wxMGLFontLibrary()
{
wxLogTrace("mgl_font", "font library dtor '%s'", m_fileName.mb_str());
delete m_instances;
}
void wxMGLFontLibrary::IncRef()
{
wxLogTrace("mgl_font", "incRef(%u) '%s'", m_refs, m_fileName.c_str());
if ( m_refs++ == 0 )
{
wxLogTrace("mgl_font", "opening library '%s'", m_fileName.mb_str());
m_fontLib = MGL_openFontLib(m_fileName.mb_str());
}
}
void wxMGLFontLibrary::DecRef()
{
wxLogTrace("mgl_font", "decRef(%u) '%s'", m_refs, m_fileName.c_str());
if ( --m_refs == 0 )
{
wxLogTrace("mgl_font", "killing instances of '%s'", m_fileName.mb_str());
m_instances->Clear();
wxLogTrace("mgl_font", "closing library '%s'", m_fileName.mb_str());
MGL_closeFontLib(m_fontLib);
m_fontLib = NULL;
}
}
wxMGLFontInstance *wxMGLFontLibrary::GetFontInstance(wxFont *font,
float scale, bool aa)
{
wxASSERT_MSG(m_refs > 0 && m_fontLib, wxT("font library not loaded!"));
wxString facename;
bool slant;
bool antialiased =
(m_fontLib->fontLibType == MGL_BITMAPFONT_LIB) ? FALSE : aa;
float pt = (float)font->GetPointSize() * scale;
slant = (((m_type & wxFONTFACE_ITALIC) == 0) &&
(font->GetStyle() == wxSLANT || font->GetStyle() == wxITALIC));
// FIXME_MGL -- MGL does not yet support slant, although the API is there
slant = FALSE;
wxLogTrace("mgl_font", "requested instance of '%s' slant=%i pt=%0.1f aa=%i",
m_fileName.mb_str(), slant, pt, antialiased);
wxMGLFontInstance *i;
wxMGLFontInstanceList::Node *node;
for (node = m_instances->GetFirst(); node; node = node->GetNext())
{
i = node->GetData();
if ( i->GetPt() == pt && i->GetSlant() == slant &&
i->GetAA() == antialiased )
{
wxLogTrace("mgl_font", " got from cache: slant=%i pt=%0.1f aa=%i",
i->GetSlant(), i->GetPt(), i->GetAA());
return i;
}
}
i = new wxMGLFontInstance(this, pt, slant, antialiased);
m_instances->Append(i);
return i;
}
wxMGLFontFamily::wxMGLFontFamily(const font_info_t *info)
{
m_name = info->familyName;
m_fontInfo = info;
if ( info->regularFace[0] == '\0' )
m_fontLibs[wxFONTFACE_REGULAR] = NULL;
else
m_fontLibs[wxFONTFACE_REGULAR] =
new wxMGLFontLibrary(info->regularFace, wxFONTFACE_REGULAR);
if ( info->italicFace[0] == '\0' )
m_fontLibs[wxFONTFACE_ITALIC] = NULL;
else
m_fontLibs[wxFONTFACE_ITALIC] =
new wxMGLFontLibrary(info->italicFace, wxFONTFACE_ITALIC);
if ( info->boldFace[0] == '\0' )
m_fontLibs[wxFONTFACE_BOLD] = NULL;
else
m_fontLibs[wxFONTFACE_BOLD] =
new wxMGLFontLibrary(info->boldFace, wxFONTFACE_BOLD);
if ( info->boldItalicFace[0] == '\0' )
m_fontLibs[wxFONTFACE_BOLD_ITALIC] = NULL;
else
m_fontLibs[wxFONTFACE_BOLD_ITALIC] =
new wxMGLFontLibrary(info->boldItalicFace, wxFONTFACE_BOLD_ITALIC);
wxLogTrace("mgl_font", "new family '%s' (r=%s, i=%s, b=%s, bi=%s)\n",
info->familyName, info->regularFace, info->italicFace,
info->boldFace, info->boldItalicFace);
}
wxMGLFontFamily::~wxMGLFontFamily()
{
for (size_t i = 0; i < wxFONTFACE_MAX; i++)
delete m_fontLibs[i];
}
bool wxMGLFontFamily::HasFace(int type) const
{
return (m_fontLibs[type] != NULL);
}
// ----------------------------------------------------------------------------
// wxFontsManager
// ----------------------------------------------------------------------------
wxMGLFontLibrary *wxFontsManager::GetFontLibrary(wxFont *font)
{
wxMGLFontFamily *family;
wxString facename;
int type;
if ( facename )
family = GetFamily(font->GetFaceName());
else
family = NULL;
if ( family )
facename = font->GetFaceName();
else
facename.Empty();
if ( !family )
{
switch (font->GetFamily())
{
case wxSCRIPT:
facename = wxT("Script");
break;
case wxDECORATIVE:
facename = wxT("Charter");
break;
case wxROMAN:
facename = wxT("Times");
break;
case wxTELETYPE:
case wxMODERN:
facename = wxT("Courier");
break;
case wxSWISS:
facename = wxT("Helvetica");
break;
case wxDEFAULT:
default:
facename = wxT("Helvetica");
break;
}
family = GetFamily(facename);
if ( !family )
{
if ( m_list->GetFirst() )
family = m_list->GetFirst()->GetData();
else
wxFAIL_MSG(wxT("Fatal error, no fonts available!"));
}
}
type = wxFONTFACE_REGULAR;
if ( font->GetWeight() == wxBOLD )
type |= wxFONTFACE_BOLD;
// FIXME_MGL -- this should read "if ( font->GetStyle() == wxITALIC )",
// but since MGL does not yet support slant, we try to display it with
// italic face (better than nothing...)
if ( font->GetStyle() == wxITALIC || font->GetStyle() == wxSLANT )
{
if ( family->HasFace(type | wxFONTFACE_ITALIC) )
type |= wxFONTFACE_ITALIC;
}
if ( !family->HasFace(type) )
{
for (int i = 0; i < wxFONTFACE_MAX; i++)
if ( family->HasFace(i) )
{
type = i;
break;
}
}
return family->GetLibrary(type);
}
static ibool enum_callback(const font_info_t *info, void *cookie)
{
wxFontsManager *db = (wxFontsManager*)cookie;
db->AddFamily(info);
return TRUE;
}
wxFontsManager::wxFontsManager()
{
m_hash = new wxHashTable(wxKEY_STRING);
m_hash->DeleteContents(FALSE);
m_list = new wxMGLFontFamilyList;
m_list->DeleteContents(TRUE);
MGL_enumerateFonts(enum_callback, (void*)this);
}
wxFontsManager::~wxFontsManager()
{
delete m_hash;
delete m_list;
}
void wxFontsManager::AddFamily(const font_info_t *info)
{
wxMGLFontFamily *f = new wxMGLFontFamily(info);
m_hash->Put(f->GetName().Lower(), f);
m_list->Append(f);
}
wxMGLFontFamily *wxFontsManager::GetFamily(const wxString& name) const
{
return (wxMGLFontFamily*)m_hash->Get(name.Lower());
}
wxFontsManager *wxTheFontsManager = NULL;
// A module that takes care of fonts DB initialization and destruction:
class wxFontutilModule: public wxModule
{
DECLARE_DYNAMIC_CLASS(wxFontutilModule)
public:
wxFontutilModule() {}
bool OnInit()
{
wxTheFontsManager = new wxFontsManager;
return TRUE;
}
void OnExit()
{
delete wxTheFontsManager;
}
};
IMPLEMENT_DYNAMIC_CLASS(wxFontutilModule, wxModule)

23
src/mgl/frame.cpp Normal file
View File

@ -0,0 +1,23 @@
/////////////////////////////////////////////////////////////////////////////
// Name: frame.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "frame.h"
#endif
#include "wx/frame.h"
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)

36
src/mgl/gdiobj.cpp Normal file
View File

@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gdiobj.cpp
// Purpose: wxGDIObject class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "gdiobj.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/setup.h"
#include "wx/list.h"
#include "wx/utils.h"
#endif
#include "wx/gdiobj.h"
IMPLEMENT_DYNAMIC_CLASS(wxGDIObject, wxObject)

56
src/mgl/icon.cpp Normal file
View File

@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////
// Name: icon.cpp
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "icon.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/icon.h"
//-----------------------------------------------------------------------------
// wxIcon
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
wxIcon::wxIcon(const char **bits, int WXUNUSED(width), int WXUNUSED(height)) :
wxBitmap(bits)
{
}
wxIcon::wxIcon(char **bits, int WXUNUSED(width), int WXUNUSED(height)) :
wxBitmap(bits)
{
}
wxIcon::wxIcon(const wxIcon& icon) : wxBitmap()
{
Ref(icon);
}
wxIcon& wxIcon::operator = (const wxIcon& icon)
{
if (*this == icon)
return (*this);
Ref(icon);
return *this;
}
void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
{
wxIcon *icon = (wxIcon*)(&bmp);
*this = *icon;
}

169
src/mgl/palette.cpp Normal file
View File

@ -0,0 +1,169 @@
/////////////////////////////////////////////////////////////////////////////
// Name: palette.cpp
// Author: Vaclav Slavik
// Created: 2001/03/11
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "palette.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/palette.h"
#include <mgraph.h>
//-----------------------------------------------------------------------------
// wxPalette
//-----------------------------------------------------------------------------
class wxPaletteRefData: public wxObjectRefData
{
public:
wxPaletteRefData(void);
~wxPaletteRefData(void);
int m_count;
palette_t *m_entries;
};
wxPaletteRefData::wxPaletteRefData()
{
m_count = 0;
m_entries = NULL;
}
wxPaletteRefData::~wxPaletteRefData()
{
delete[] m_entries;
}
//-----------------------------------------------------------------------------
#define M_PALETTEDATA ((wxPaletteRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxPalette,wxGDIObject)
wxPalette::wxPalette()
{
m_refData = NULL;
}
wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
{
Create(n, red, green, blue);
}
wxPalette::wxPalette(const wxPalette& palette)
{
Ref(palette);
}
wxPalette::~wxPalette()
{
}
wxPalette& wxPalette::operator = (const wxPalette& palette)
{
if (*this == palette) return (*this);
Ref(palette);
return *this;
}
bool wxPalette::operator == (const wxPalette& palette) const
{
return m_refData == palette.m_refData;
}
bool wxPalette::operator != (const wxPalette& palette) const
{
return m_refData != palette.m_refData;
}
bool wxPalette::Ok(void) const
{
return (m_refData != NULL);
}
bool wxPalette::Create(int n,
const unsigned char *red,
const unsigned char *green,
const unsigned char *blue)
{
UnRef();
m_refData = new wxPaletteRefData();
M_PALETTEDATA->m_count = n;
M_PALETTEDATA->m_entries = new palette_t[n];
palette_t *e = M_PALETTEDATA->m_entries;
for (int i = 0; i < n; i++, e++)
{
e->red = red[i];
e->green = green[i];
e->blue = blue[i];
e->alpha = 0;
}
return TRUE;
}
int wxPalette::GetPixel(const unsigned char red,
const unsigned char green,
const unsigned char blue) const
{
if (!m_refData) return FALSE;
int closest = 0;
double d,distance = 1000.0; // max. dist is 256
palette_t *e = M_PALETTEDATA->m_entries;
for (int i = 0; i < M_PALETTEDATA->m_count; i++, e++)
{
if ((d = 0.299 * abs(red - e->red) +
0.587 * abs(green - e->green) +
0.114 * abs(blue - e->blue)) < distance) {
distance = d;
closest = i;
}
}
return closest;
}
bool wxPalette::GetRGB(int pixel,
unsigned char *red,
unsigned char *green,
unsigned char *blue) const
{
if (!m_refData) return FALSE;
if (pixel >= M_PALETTEDATA->m_count) return FALSE;
palette_t& p = M_PALETTEDATA->m_entries[pixel];
if (red) *red = p.red;
if (green) *green = p.green;
if (blue) *blue = p.blue;
return TRUE;
}
int wxPalette::GetColoursCount() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid palette") );
return M_PALETTEDATA->m_count;
}
palette_t *wxPalette::GetMGLpalette_t() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid palette") );
return M_PALETTEDATA->m_entries;
}

283
src/mgl/pen.cpp Normal file
View File

@ -0,0 +1,283 @@
/////////////////////////////////////////////////////////////////////////////
// Name: pen.cpp
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "pen.h"
#endif
#include "wx/pen.h"
#include "wx/bitmap.h"
#include "wx/mgl/private.h"
//-----------------------------------------------------------------------------
// wxPen
//-----------------------------------------------------------------------------
class wxPenRefData: public wxObjectRefData
{
public:
wxPenRefData();
wxPenRefData(const wxPenRefData& data);
int m_width;
int m_style;
wxColour m_colour;
wxBitmap m_stipple;
pixpattern24_t m_pixPattern;
// not used by wxMGL, but we want to preserve values
int m_joinStyle;
int m_capStyle;
int m_countDashes;
wxDash *m_dash;
};
wxPenRefData::wxPenRefData()
{
m_width = 1;
m_style = wxSOLID;
m_joinStyle = wxJOIN_ROUND;
m_capStyle = wxCAP_ROUND;
m_dash = (wxDash*) NULL;
m_countDashes = 0;
int x, y, c;
for (y = 0; y < 8; y++)
for (x = 0; x < 8; x++)
for (c = 0; c < 3; c++)
m_pixPattern.p[x][y][c] = 0;
}
wxPenRefData::wxPenRefData(const wxPenRefData& data)
{
m_style = data.m_style;
m_width = data.m_width;
m_joinStyle = data.m_joinStyle;
m_capStyle = data.m_capStyle;
m_colour = data.m_colour;
m_countDashes = data.m_countDashes;
m_dash = data.m_dash;
m_stipple = data.m_stipple;
int x, y, c;
for (y = 0; y < 8; y++)
for (x = 0; x < 8; x++)
for (c = 0; c < 3; c++)
m_pixPattern.p[x][y][c] = data.m_pixPattern.p[x][y][c];
}
//-----------------------------------------------------------------------------
#define M_PENDATA ((wxPenRefData *)m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
wxPen::wxPen()
{
if ( wxThePenList )
wxThePenList->AddPen(this);
}
wxPen::wxPen(const wxColour &colour, int width, int style)
{
m_refData = new wxPenRefData();
M_PENDATA->m_width = width;
M_PENDATA->m_style = style;
M_PENDATA->m_colour = colour;
if ( wxThePenList )
wxThePenList->AddPen(this);
}
wxPen::wxPen(const wxBitmap& stipple, int width)
{
wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
_T("stipple bitmap must be 8x8") );
m_refData = new wxPenRefData();
M_PENDATA->m_width = width;
M_PENDATA->m_style = wxSTIPPLE;
M_PENDATA->m_stipple = stipple;
wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
if ( wxThePenList )
wxThePenList->AddPen(this);
}
wxPen::wxPen(const wxPen& pen)
{
Ref(pen);
if ( wxThePenList )
wxThePenList->AddPen(this);
}
wxPen::~wxPen()
{
if ( wxThePenList )
wxThePenList->RemovePen(this);
}
wxPen& wxPen::operator = (const wxPen& pen)
{
if (*this == pen) return (*this);
Ref(pen);
return *this;
}
bool wxPen::operator == (const wxPen& pen) const
{
return m_refData == pen.m_refData;
}
bool wxPen::operator != (const wxPen& pen) const
{
return m_refData != pen.m_refData;
}
void wxPen::SetColour(const wxColour &colour)
{
Unshare();
M_PENDATA->m_colour = colour;
}
void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
{
Unshare();
M_PENDATA->m_countDashes = number_of_dashes;
M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
}
void wxPen::SetColour(int red, int green, int blue)
{
Unshare();
M_PENDATA->m_colour.Set(red, green, blue);
}
void wxPen::SetCap(int capStyle)
{
Unshare();
M_PENDATA->m_capStyle = capStyle;
}
void wxPen::SetJoin(int joinStyle)
{
Unshare();
M_PENDATA->m_joinStyle = joinStyle;
}
void wxPen::SetStyle(int style)
{
Unshare();
M_PENDATA->m_style = style;
}
void wxPen::SetStipple(const wxBitmap& stipple)
{
wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
_T("stipple bitmap must be 8x8") );
Unshare();
M_PENDATA->m_stipple = stipple;
wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
}
void wxPen::SetWidth(int width)
{
Unshare();
M_PENDATA->m_width = width;
}
int wxPen::GetDashes(wxDash **ptr) const
{
*ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
}
int wxPen::GetDashCount() const
{
return (M_PENDATA->m_countDashes);
}
wxDash* wxPen::GetDash() const
{
return (wxDash*)M_PENDATA->m_dash;
}
int wxPen::GetCap() const
{
wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
return M_PENDATA->m_capStyle;
}
int wxPen::GetJoin() const
{
wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
return M_PENDATA->m_joinStyle;
}
int wxPen::GetStyle() const
{
wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
return M_PENDATA->m_style;
}
int wxPen::GetWidth() const
{
wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
return M_PENDATA->m_width;
}
wxColour &wxPen::GetColour() const
{
wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
return M_PENDATA->m_colour;
}
wxBitmap *wxPen::GetStipple() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
return &(M_PENDATA->m_stipple);
}
void* wxPen::GetPixPattern() const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
return (void*)&(M_PENDATA->m_pixPattern);
}
bool wxPen::Ok() const
{
return (m_refData != NULL);
}
void wxPen::Unshare()
{
if (!m_refData)
{
m_refData = new wxPenRefData();
}
else
{
wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
UnRef();
m_refData = ref;
}
}

399
src/mgl/region.cpp Normal file
View File

@ -0,0 +1,399 @@
/////////////////////////////////////////////////////////////////////////////
// Name: region.cpp
// Purpose: Region handling for wxWindows/MGL
// Author: Vaclav Slavik
// RCS-ID: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "region.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/region.h"
#include "wx/gdicmn.h"
#include "wx/thread.h"
#include <mgraph.hpp>
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxRegionRectList)
IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject)
//-----------------------------------------------------------------------------
// wxRegionRefData implementation
//-----------------------------------------------------------------------------
class WXDLLEXPORT wxRegionRefData : public wxGDIRefData
{
public:
wxRegionRefData()
{
}
wxRegionRefData(const wxRegionRefData& data)
{
m_region = data.m_region;
}
~wxRegionRefData()
{
}
MGLRegion m_region;
};
#define M_REGION (((wxRegionRefData*)m_refData)->m_region)
#define M_REGION_OF(r) (((wxRegionRefData*)(r.m_refData))->m_region)
//-----------------------------------------------------------------------------
// wxRegion
//-----------------------------------------------------------------------------
/*
* Create an empty region.
*/
wxRegion::wxRegion()
{
m_refData = (wxRegionRefData *)NULL;
}
wxRegion::wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
{
m_refData = new wxRegionRefData;
MGLRect rect(x, y, x + w, y + h);
M_REGION = rect;
}
wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight)
{
m_refData = new wxRegionRefData;
MGLRect rect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
M_REGION = rect;
}
wxRegion::wxRegion(const wxRect& r)
{
m_refData = new wxRegionRefData;
MGLRect rect(r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
M_REGION = rect;
}
wxRegion::wxRegion(const MGLRegion& region)
{
m_refData = new wxRegionRefData;
M_REGION = region;
}
wxRegion::~wxRegion()
{
// m_refData unrefed in ~wxObject
}
const MGLRegion& wxRegion::GetMGLRegion() const
{
return M_REGION;
}
//-----------------------------------------------------------------------------
// Modify region
//-----------------------------------------------------------------------------
// Clear current region
void wxRegion::Clear()
{
UnRef();
}
//-----------------------------------------------------------------------------
// Information on region
//-----------------------------------------------------------------------------
// Outer bounds of region
void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const
{
if (m_refData)
{
rect_t rect;
rect = M_REGION.getBounds();
x = rect.left;
y = rect.top;
w = rect.right - rect.left;
h = rect.bottom - rect.top;
}
else
{
x = y = w = h = 0;
}
}
wxRect wxRegion::GetBox() const
{
wxCoord x, y, w, h;
GetBox(x, y, w, h);
return wxRect(x, y, w, h);
}
// Is region empty?
bool wxRegion::Empty() const
{
if (!m_refData) return TRUE;
return M_REGION.isEmpty();
}
//-----------------------------------------------------------------------------
// Modifications
//-----------------------------------------------------------------------------
// Union rectangle or region with this.
bool wxRegion::Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
Unshare();
M_REGION += MGLRect(x, y, x + width, y + height);
return TRUE;
}
bool wxRegion::Union(const wxRegion& region)
{
Unshare();
M_REGION += M_REGION_OF(region);
return TRUE;
}
// Intersect rectangle or region with this.
bool wxRegion::Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
Unshare();
M_REGION &= MGLRect(x, y, x + width, y + height);
return TRUE;
}
bool wxRegion::Intersect(const wxRegion& region)
{
Unshare();
M_REGION &= M_REGION_OF(region);
return TRUE;
}
// Subtract rectangle or region from this:
// Combines the parts of 'this' that are not part of the second region.
bool wxRegion::Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
Unshare();
M_REGION -= MGLRect(x, y, x + width, y + height);
return TRUE;
}
bool wxRegion::Subtract(const wxRegion& region)
{
Unshare();
M_REGION -= M_REGION_OF(region);
return TRUE;
}
// XOR: the union of two combined regions except for any overlapping areas.
bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
Unshare();
MGLRect rect(x, y, x + width, y + height);
MGLRegion rg1 = M_REGION + rect,
rg2 = M_REGION & rect;
M_REGION = rg1 - rg2;
return TRUE;
}
bool wxRegion::Xor(const wxRegion& region)
{
Unshare();
MGLRegion rg1 = M_REGION + M_REGION_OF(region),
rg2 = M_REGION & M_REGION_OF(region);
M_REGION = rg1 - rg2;
return TRUE;
}
//-----------------------------------------------------------------------------
// Tests
//-----------------------------------------------------------------------------
// Does the region contain the point (x,y)?
wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const
{
if (!m_refData)
return wxOutRegion;
if (M_REGION.includes((int)x, (int)y))
return wxInRegion;
else
return wxOutRegion;
}
// Does the region contain the point pt?
wxRegionContain wxRegion::Contains(const wxPoint& pt) const
{
return Contains(pt.x, pt.y);
}
// Does the region contain the rectangle (x, y, w, h)?
wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const
{
if (!m_refData)
return wxOutRegion;
MGLRect rect(x, y, x + w, y + h);
MGLRegion rg;
// 1) is the rectangle entirely covered by the region?
rg = MGLRegion(rect) - M_REGION;
if (rg.isEmpty()) return wxInRegion;
// 2) is the rectangle completely outside the region?
rg = M_REGION & rect; // intersection
if (rg.isEmpty()) return wxOutRegion;
// 3) neither case happened => it is partially covered:
return wxPartRegion;
}
// Does the region contain the rectangle rect
wxRegionContain wxRegion::Contains(const wxRect& rect) const
{
return Contains(rect.x, rect.y, rect.width, rect.height);
}
void wxRegion::Unshare()
{
if (!m_refData)
{
m_refData = new wxRegionRefData();
}
else
{
wxRegionRefData* ref = new wxRegionRefData(*(wxRegionRefData*)m_refData);
UnRef();
m_refData = ref;
}
}
///////////////////////////////////////////////////////////////////////////////
// wxRegionIterator //
///////////////////////////////////////////////////////////////////////////////
/*
* Initialize empty iterator
*/
wxRegionIterator::wxRegionIterator() : m_currentNode(NULL)
{
m_rects.DeleteContents(TRUE);
}
wxRegionIterator::~wxRegionIterator()
{
}
/*
* Initialize iterator for region
*/
wxRegionIterator::wxRegionIterator(const wxRegion& region)
{
m_rects.DeleteContents(TRUE);
Reset(region);
}
/*
* Reset iterator for a new /e region.
*/
static wxRegionRectList *gs_rectList;
static void wxMGL_region_callback(const rect_t *r)
{
gs_rectList->Append(new wxRect(r->left, r->top,
r->right - r->left, r->bottom - r->top));
}
void wxRegionIterator::Reset(const wxRegion& region)
{
m_currentNode = NULL;
m_rects.Clear();
if (!region.Empty())
{
wxMutexGuiEnter();
gs_rectList = &m_rects;
M_REGION_OF(region).traverse(wxMGL_region_callback);
wxMutexGuiLeave();
m_currentNode = m_rects.GetFirst();
}
}
/*
* Increment iterator. The rectangle returned is the one after the
* incrementation.
*/
void wxRegionIterator::operator ++ ()
{
if (m_currentNode)
m_currentNode = m_currentNode->GetNext();
}
/*
* Increment iterator. The rectangle returned is the one before the
* incrementation.
*/
void wxRegionIterator::operator ++ (int)
{
if (m_currentNode)
m_currentNode = m_currentNode->GetNext();
}
wxCoord wxRegionIterator::GetX() const
{
if (m_currentNode)
return m_currentNode->GetData()->x;
else
return 0;
}
wxCoord wxRegionIterator::GetY() const
{
if (m_currentNode)
return m_currentNode->GetData()->y;
else
return 0;
}
wxCoord wxRegionIterator::GetW() const
{
if (m_currentNode)
return m_currentNode->GetData()->width;
else
return 0;
}
wxCoord wxRegionIterator::GetH() const
{
if (m_currentNode)
return m_currentNode->GetData()->height;
else
return 0;
}

16
src/mgl/settings.cpp Normal file
View File

@ -0,0 +1,16 @@
/////////////////////////////////////////////////////////////////////////////
// Name: settings.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "settings.h"
#endif
#include "wx/settings.h"

23
src/mgl/timer.cpp Normal file
View File

@ -0,0 +1,23 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gtk/timer.cpp
// Purpose: wxTimer implementation
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "timer.h"
#endif
#include "wx/timer.h"
// ----------------------------------------------------------------------------
// wxTimer
// ----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)

98
src/mgl/utils.cpp Normal file
View File

@ -0,0 +1,98 @@
/////////////////////////////////////////////////////////////////////////////
// Name: utils.cpp
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/utils.h"
#include "wx/string.h"
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/process.h"
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <mgraph.hpp>
#ifdef __UNIX__
#include "wx/unix/execute.h"
#endif
//----------------------------------------------------------------------------
// misc.
//----------------------------------------------------------------------------
void wxBell()
{
// FIXME_MGL
}
// ----------------------------------------------------------------------------
// display characterstics
// ----------------------------------------------------------------------------
extern MGLDevCtx *g_displayDC;
void wxDisplaySize( int *width, int *height )
{
wxASSERT_MSG( g_displayDC, wxT("MGL display DC not created yet.") );
if (width) *width = g_displayDC->sizex();
if (height) *height = g_displayDC->sizey();
}
void wxGetMousePosition( int* x, int* y )
{
#if 0 // FIXME_MGL
gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
#endif
}
bool wxColourDisplay()
{
wxASSERT_MSG( g_displayDC, wxT("MGL display DC not created yet.") );
return (wxDisplayDepth() > 1);
}
int wxDisplayDepth()
{
wxASSERT_MSG( g_displayDC, wxT("MGL display DC not created yet.") );
return g_displayDC->getBitsPerPixel();
}
int wxGetOsVersion(int *majorVsn, int *minorVsn)
{
#if 0 // FIXME_MGL
// FIXME_MGL : wxGetOsVersion, too
if (majorVsn) *majorVsn = GTK_MAJOR_VERSION;
if (minorVsn) *minorVsn = GTK_MINOR_VERSION;
return wxGTK;
#endif
}
#ifdef __UNIX__
int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
{
#if 0 // FIXME_MGL -do we need it at all?
int tag = gdk_input_add(fd,
GDK_INPUT_READ,
GTK_EndProcessDetector,
(gpointer)proc_data);
return tag;
#endif
}
#endif

33
src/mgl/window.cpp Normal file
View File

@ -0,0 +1,33 @@
/////////////////////////////////////////////////////////////////////////////
// Name: gtk/window.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "window.h"
#endif
#include "wx/defs.h"
#include "wx/window.h"
IMPLEMENT_DYNAMIC_CLASS(wxWindowMGL, wxWindowBase)
wxWindow *g_captureWindow = NULL;
wxWindow *g_focusWindow = NULL;
/* static */
wxWindow *wxWindowBase::GetCapture()
{
return (wxWindow *)g_captureWindow;
}
wxWindow *wxWindowBase::FindFocus()
{
// the cast is necessary when we compile in wxUniversal mode
return (wxWindow *)g_focusWindow;
}