Latest Updates

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3974 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Webster
1999-10-13 22:34:18 +00:00
parent 9bfa7bfcbd
commit d88de032d3
8 changed files with 1339 additions and 424 deletions

View File

@@ -1,23 +1,18 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: accel.h // Name: accel.h
// Purpose: wxAcceleratorTable class // Purpose: wxAcceleratorTable class
// Author: AUTHOR // Author: David Webster
// Modified by: // Modified by:
// Created: ??/??/98 // Created: 10/13/99
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) AUTHOR // Copyright: (c) David Webster
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_ACCEL_H_ #ifndef _WX_ACCEL_H_
#define _WX_ACCEL_H_ #define _WX_ACCEL_H_
#ifdef __GNUG__
#pragma interface "accel.h"
#endif
#include "wx/object.h" #include "wx/object.h"
#include "wx/string.h"
class WXDLLEXPORT wxAcceleratorTable; class WXDLLEXPORT wxAcceleratorTable;

View File

@@ -1,25 +1,19 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: app.h // Name: app.h
// Purpose: wxApp class // Purpose: wxApp class
// Author: AUTHOR // Author: David Webster
// Modified by: // Modified by:
// Created: ??/??/98 // Created: 10/13/99
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) AUTHOR // Copyright: (c) David Webster
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_APP_H_ #ifndef _WX_APP_H_
#define _WX_APP_H_ #define _WX_APP_H_
#ifdef __GNUG__
#pragma interface "app.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
#include "wx/gdicmn.h"
#include "wx/event.h" #include "wx/event.h"
#include "wx/icon.h"
class WXDLLEXPORT wxFrame; class WXDLLEXPORT wxFrame;
class WXDLLEXPORT wxWindow; class WXDLLEXPORT wxWindow;
@@ -27,9 +21,6 @@ class WXDLLEXPORT wxApp ;
class WXDLLEXPORT wxKeyEvent; class WXDLLEXPORT wxKeyEvent;
class WXDLLEXPORT wxLog; class WXDLLEXPORT wxLog;
#define wxPRINT_WINDOWS 1
#define wxPRINT_POSTSCRIPT 2
WXDLLEXPORT_DATA(extern wxApp*) wxTheApp; WXDLLEXPORT_DATA(extern wxApp*) wxTheApp;
// Force an exit from main loop // Force an exit from main loop
@@ -40,116 +31,83 @@ bool WXDLLEXPORT wxYield();
// Represents the application. Derive OnInit and declare // Represents the application. Derive OnInit and declare
// a new App object to start application // a new App object to start application
class WXDLLEXPORT wxApp: public wxEvtHandler class WXDLLEXPORT wxApp : public wxAppBase
{ {
DECLARE_DYNAMIC_CLASS(wxApp) DECLARE_DYNAMIC_CLASS(wxApp)
wxApp();
inline ~wxApp() {}
static void SetInitializerFunction(wxAppInitializerFunction fn) { m_appInitFn = fn; }
static wxAppInitializerFunction GetInitializerFunction() { return m_appInitFn; }
virtual int MainLoop();
void ExitMainLoop();
bool Initialized();
virtual bool Pending() ;
virtual void Dispatch() ;
void OnIdle(wxIdleEvent& event);
// Generic
virtual bool OnInit() { return FALSE; };
// No specific tasks to do here.
virtual bool OnInitGui() { return TRUE; }
// Called to set off the main loop
virtual int OnRun() { return MainLoop(); };
virtual int OnExit() { return 0; }
/** Returns the standard icons for the msg dialogs, implemented in
src/generic/msgdlgg.cpp and src/gtk/app.cpp. */
virtual wxIcon GetStdIcon(int which) const;
inline void SetPrintMode(int mode) { m_printMode = mode; }
inline int GetPrintMode() const { return m_printMode; }
inline void SetExitOnFrameDelete(bool flag) { m_exitOnFrameDelete = flag; }
inline bool GetExitOnFrameDelete() const { return m_exitOnFrameDelete; }
inline wxString GetAppName() const {
if (m_appName != "")
return m_appName;
else return m_className;
}
inline void SetAppName(const wxString& name) { m_appName = name; };
inline wxString GetClassName() const { return m_className; }
inline void SetClassName(const wxString& name) { m_className = name; }
void SetVendorName(const wxString& vendorName) { m_vendorName = vendorName; }
const wxString& GetVendorName() const { return m_vendorName; }
wxWindow *GetTopWindow() const ;
inline void SetTopWindow(wxWindow *win) { m_topWindow = win; }
inline void SetWantDebugOutput(bool flag) { m_wantDebugOutput = flag; }
inline bool GetWantDebugOutput() { return m_wantDebugOutput; }
// Send idle event to all top-level windows.
// Returns TRUE if more idle time is requested.
bool SendIdleEvents();
// Send idle event to window and all subwindows
// Returns TRUE if more idle time is requested.
bool SendIdleEvents(wxWindow* win);
// Windows only, but for compatibility...
inline void SetAuto3D(bool flag) { m_auto3D = flag; }
inline bool GetAuto3D() const { return m_auto3D; }
// Creates a log object
virtual wxLog* CreateLogTarget();
public: public:
// Will always be set to the appropriate, main-style values. wxApp();
int argc; virtual ~wxApp();
char ** argv;
// override base class (pure) virtuals
virtual int MainLoop();
virtual void ExitMainLoop();
virtual bool Initialized();
virtual bool Pending() ;
virtual void Dispatch() ;
virtual wxIcon GetStdIcon(int which) const;
virtual void SetPrintMode(int mode) { m_printMode = mode; }
virtual int GetPrintMode() const { return m_printMode; }
// implementation only
void OnIdle(wxIdleEvent& event);
void OnEndSession(wxCloseEvent& event);
void OnQueryEndSession(wxCloseEvent& event);
// Send idle event to all top-level windows.
// Returns TRUE if more idle time is requested.
bool SendIdleEvents();
// Send idle event to window and all subwindows
// Returns TRUE if more idle time is requested.
bool SendIdleEvents(wxWindow* win);
void SetAuto3D(bool flag) { m_auto3D = flag; }
bool GetAuto3D() const { return m_auto3D; }
protected: protected:
bool m_wantDebugOutput ; bool m_showOnInit;
wxString m_className; int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT
wxString m_appName, bool m_auto3D ; // Always use 3D controls, except where overriden
m_vendorName;
wxWindow * m_topWindow; /* Windows-specific wxApp definitions */
bool m_exitOnFrameDelete;
bool m_showOnInit;
int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT
bool m_auto3D ; // Always use 3D controls, except
// where overriden
static wxAppInitializerFunction m_appInitFn;
public: public:
// Implementation // Implementation
static bool Initialize(); static bool Initialize();
static void CleanUp(); static void CleanUp();
void DeletePendingObjects(); static bool RegisterWindowClasses();
bool ProcessIdle(); // Convert Windows to argc, argv style
void ConvertToStandardCommandArgs(char* p);
virtual bool DoMessage();
virtual bool ProcessMessage(WXMSG* pMsg);
void DeletePendingObjects();
bool ProcessIdle();
#if wxUSE_THREADS
void ProcessPendingEvents();
#endif
int GetComCtl32Version() const;
public: public:
static long sm_lastMessageTime; int m_nCmdShow;
int m_nCmdShow;
protected: protected:
bool m_keepGoing ; bool m_keepGoing ;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
// TODO: add platform-specific arguments #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
int WXDLLEXPORT wxEntry( int argc, char *argv[] ); int WXDLLEXPORT wxEntry(WXHINSTANCE hInstance, WXHINSTANCE hPrevInstance, char *lpszCmdLine,
int nCmdShow, bool enterLoop = TRUE);
#else
int WXDLLEXPORT wxEntry(WXHINSTANCE hInstance);
#endif
#endif #endif
// _WX_APP_H_ // _WX_APP_H_

View File

@@ -1,21 +1,17 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: bitmap.h // Name: bitmap.h
// Purpose: wxBitmap class // Purpose: wxBitmap class
// Author: AUTHOR // Author: David Webster
// Modified by: // Modified by:
// Created: ??/??/98 // Created: 10/13/99
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) AUTHOR // Copyright: (c) David Webster
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_BITMAP_H_ #ifndef _WX_BITMAP_H_
#define _WX_BITMAP_H_ #define _WX_BITMAP_H_
#ifdef __GNUG__
#pragma interface "bitmap.h"
#endif
#include "wx/gdiobj.h" #include "wx/gdiobj.h"
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/palette.h" #include "wx/palette.h"
@@ -27,6 +23,7 @@ class WXDLLEXPORT wxBitmap;
class WXDLLEXPORT wxBitmapHandler; class WXDLLEXPORT wxBitmapHandler;
class WXDLLEXPORT wxIcon; class WXDLLEXPORT wxIcon;
class WXDLLEXPORT wxCursor; class WXDLLEXPORT wxCursor;
class WXDLLEXPORT wxControl;
// A mask is a mono bitmap used for drawing bitmaps // A mask is a mono bitmap used for drawing bitmaps
// transparently. // transparently.
@@ -54,13 +51,11 @@ public:
bool Create(const wxBitmap& bitmap, int paletteIndex); bool Create(const wxBitmap& bitmap, int paletteIndex);
bool Create(const wxBitmap& bitmap); bool Create(const wxBitmap& bitmap);
/* TODO: platform-specific data access
// Implementation // Implementation
inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
protected: protected:
WXHBITMAP m_maskBitmap; WXHBITMAP m_maskBitmap;
*/
}; };
class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
@@ -124,22 +119,18 @@ public:
wxBitmap(); // Platform-specific wxBitmap(); // Platform-specific
// Copy constructors // Copy constructors
inline wxBitmap(const wxBitmap& bitmap) wxBitmap(const wxBitmap& bitmap);
{ Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); }
// Initialize with raw data. // Initialize with raw data
wxBitmap(const char bits[], int width, int height, int depth = 1); wxBitmap(const char bits[], int width, int height, int depth = 1);
/* TODO: maybe implement XPM reading
// Initialize with XPM data // Initialize with XPM data
wxBitmap(const char **data); wxBitmap(char **data, wxControl *anItem = NULL);
*/
// Load a file or resource // Load a file or resource
// TODO: make default type whatever's appropriate for the platform.
wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
// Constructor for generalised creation from data // New constructor for generalised creation from data
wxBitmap(void *data, long type, int width, int height, int depth = 1); wxBitmap(void *data, long type, int width, int height, int depth = 1);
// If depth is omitted, will create a bitmap compatible with the display // If depth is omitted, will create a bitmap compatible with the display
@@ -162,6 +153,10 @@ public:
void SetQuality(int q); void SetQuality(int q);
void SetOk(bool isOk); void SetOk(bool isOk);
#if WXWIN_COMPATIBILITY
inline wxPalette *GetColourMap(void) const { return GetPalette(); }
void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
#endif
inline wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } inline wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); }
void SetPalette(const wxPalette& palette); void SetPalette(const wxPalette& palette);
@@ -169,6 +164,7 @@ public:
void SetMask(wxMask *mask) ; void SetMask(wxMask *mask) ;
inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; }
inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; } inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; } inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
@@ -186,13 +182,26 @@ public:
protected: protected:
static wxList sm_handlers; static wxList sm_handlers;
// TODO: Implementation // Implementation
public: public:
void SetHBITMAP(WXHBITMAP bmp); void SetHBITMAP(WXHBITMAP bmp);
inline WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); } inline WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); }
inline void SetSelectedInto(wxDC *dc) { if (M_BITMAPDATA) M_BITMAPDATA->m_selectedInto = dc; } inline void SetSelectedInto(wxDC *dc) { if (M_BITMAPDATA) M_BITMAPDATA->m_selectedInto = dc; }
inline wxDC *GetSelectedInto(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_selectedInto : (wxDC*) NULL); } inline wxDC *GetSelectedInto(void) const { return (M_BITMAPDATA ? M_BITMAPDATA->m_selectedInto : (wxDC*) NULL); }
// bool FreeResource(bool force = FALSE); bool FreeResource(bool force = FALSE);
// Creates a bitmap that matches the device context's depth, from
// an arbitray bitmap. At present, the original bitmap must have an
// associated palette. (TODO: use a default palette if no palette exists.)
// This function is necessary for you to Blit an arbitrary bitmap (which may have
// the wrong depth). wxDC::SelectObject will compare the depth of the bitmap
// with the DC's depth, and create a new bitmap if the depths differ.
// Eventually we should perhaps make this a public API function so that
// an app can efficiently produce bitmaps of the correct depth.
// The Windows solution is to use SetDibBits to blit an arbotrary DIB directly to a DC, but
// this is too Windows-specific, hence this solution of quietly converting the wxBitmap.
// Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
wxBitmap GetBitmapForDC(wxDC& dc) const;
}; };
#endif #endif
// _WX_BITMAP_H_ // _WX_BITMAP_H_

View File

@@ -1,23 +1,18 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: button.h // Name: button.h
// Purpose: wxButton class // Purpose: wxButton class
// Author: AUTHOR // Author: David Webster
// Modified by: // Modified by:
// Created: ??/??/98 // Created: 10/13/99
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) AUTHOR // Copyright: (c) David Webster
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_BUTTON_H_ #ifndef _WX_BUTTON_H_
#define _WX_BUTTON_H_ #define _WX_BUTTON_H_
#ifdef __GNUG__
#pragma interface "button.h"
#endif
#include "wx/control.h" #include "wx/control.h"
#include "wx/gdicmn.h"
WXDLLEXPORT_DATA(extern const char*) wxButtonNameStr; WXDLLEXPORT_DATA(extern const char*) wxButtonNameStr;
@@ -44,14 +39,23 @@ class WXDLLEXPORT wxButton: public wxControl
virtual ~wxButton(); virtual ~wxButton();
virtual void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
virtual void SetDefault(); virtual void SetDefault();
virtual void SetLabel(const wxString& label);
virtual wxString GetLabel() const ;
static wxSize GetDefaultSize(); static wxSize GetDefaultSize();
virtual void Command(wxCommandEvent& event); virtual void Command(wxCommandEvent& event);
virtual bool OS2Command(WXUINT param, WXWORD id);
virtual WXHBRUSH OnCtlColor(WXHDC pDC,
WXHWND pWnd,
WXUINT nCtlColor,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam);
protected:
// send a notification event, return TRUE if processed
bool SendClickEvent();
virtual wxSize DoGetBestSize();
}; };
#endif #endif

View File

@@ -1,11 +1,11 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: accel.cpp // Name: accel.cpp
// Purpose: wxAcceleratorTable // Purpose: wxAcceleratorTable
// Author: AUTHOR // Author: David Webster
// Modified by: // Modified by:
// Created: ??/??/98 // Created: 10/13/99
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) AUTHOR // Copyright: (c) David Webster
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -37,6 +37,7 @@ public:
inline HACCEL GetHACCEL() const { return m_hAccel; } inline HACCEL GetHACCEL() const { return m_hAccel; }
protected: protected:
HACCEL m_hAccel; HACCEL m_hAccel;
bool m_ok;
}; };
#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
@@ -80,6 +81,8 @@ wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
*/ */
} }
extern int wxCharCodeWXToOS2(int id, bool *isVirtual);
// Create from an array // Create from an array
wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[])
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -9,17 +9,28 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ // For compilers that support precompilation, includes "wx.h".
#pragma implementation "bitmap.h" #include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/list.h"
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/palette.h"
#include "wx/dcmemory.h"
#include "wx/bitmap.h"
#include "wx/icon.h"
#endif #endif
#include "wx/setup.h" #include "wx/os2/private.h"
#include "wx/utils.h"
#include "wx/palette.h"
#include "wx/bitmap.h"
#include "wx/icon.h"
#include "wx/log.h" #include "wx/log.h"
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARIES #if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
@@ -32,15 +43,25 @@ wxBitmapRefData::wxBitmapRefData()
m_height = 0; m_height = 0;
m_depth = 0; m_depth = 0;
m_quality = 0; m_quality = 0;
m_hBitmap = 0 ;
m_selectedInto = NULL;
m_numColors = 0; m_numColors = 0;
m_bitmapMask = NULL; m_bitmapMask = NULL;
} }
wxBitmapRefData::~wxBitmapRefData() wxBitmapRefData::~wxBitmapRefData()
{ {
/* if (m_selectedInto)
* TODO: delete the bitmap data here. {
*/ wxChar buf[200];
wxSprintf(buf, wxT("Bitmap was deleted without selecting out of wxMemoryDC %lX."), (unsigned long) m_selectedInto);
wxFatalError(buf);
}
if (m_hBitmap)
{
// TODO: DeleteObject((HBITMAP) m_hBitmap);
}
m_hBitmap = 0 ;
if (m_bitmapMask) if (m_bitmapMask)
delete m_bitmapMask; delete m_bitmapMask;
@@ -57,12 +78,68 @@ wxBitmap::wxBitmap()
wxTheBitmapList->AddBitmap(this); wxTheBitmapList->AddBitmap(this);
} }
wxBitmap::wxBitmap(const wxBitmap& bitmap)
{
// TODO:
/*
wxIcon *icon = wxDynamicCast(&bitmap, wxIcon);
if ( icon )
{
HDC hdc = ::CreateCompatibleDC(NULL); // screen DC
HBITMAP hbitmap = ::CreateCompatibleBitmap(hdc,
icon->GetWidth(),
icon->GetHeight());
::SelectObject(hdc, hbitmap);
::DrawIcon(hdc, 0, 0, (HICON)icon->GetHICON());
::DeleteDC(hdc);
SetHBITMAP((WXHBITMAP)hbitmap);
}
else
{
Ref(bitmap);
}
if ( wxTheBitmapList )
wxTheBitmapList->AddBitmap(this);
*/
}
wxBitmap::~wxBitmap() wxBitmap::~wxBitmap()
{ {
if (wxTheBitmapList) if (wxTheBitmapList)
wxTheBitmapList->DeleteObject(this); wxTheBitmapList->DeleteObject(this);
} }
bool wxBitmap::FreeResource(bool WXUNUSED(force))
{
if ( !M_BITMAPDATA )
return FALSE;
if (M_BITMAPDATA->m_selectedInto)
{
wxChar buf[200];
wxSprintf(buf, wxT("Bitmap %lX was deleted without selecting out of wxMemoryDC %lX."), (unsigned long) this, (unsigned long) M_BITMAPDATA->m_selectedInto);
wxFatalError(buf);
}
if (M_BITMAPDATA->m_hBitmap)
{
// TODO: DeleteObject((HBITMAP) M_BITMAPDATA->m_hBitmap);
}
M_BITMAPDATA->m_hBitmap = 0 ;
/*
if (M_BITMAPDATA->m_bitmapPalette)
delete M_BITMAPDATA->m_bitmapPalette;
M_BITMAPDATA->m_bitmapPalette = NULL ;
*/
return TRUE;
}
wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits) wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
{ {
m_refData = new wxBitmapRefData; m_refData = new wxBitmapRefData;
@@ -78,6 +155,12 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
wxTheBitmapList->AddBitmap(this); wxTheBitmapList->AddBitmap(this);
} }
// Create from XPM data
wxBitmap::wxBitmap(char **data, wxControl *WXUNUSED(anItem))
{
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
}
wxBitmap::wxBitmap(int w, int h, int d) wxBitmap::wxBitmap(int w, int h, int d)
{ {
(void)Create(w, h, d); (void)Create(w, h, d);
@@ -102,14 +185,6 @@ wxBitmap::wxBitmap(const wxString& filename, long type)
wxTheBitmapList->AddBitmap(this); wxTheBitmapList->AddBitmap(this);
} }
/* TODO: maybe allow creation from XPM
// Create from data
wxBitmap::wxBitmap(const char **data)
{
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
}
*/
bool wxBitmap::Create(int w, int h, int d) bool wxBitmap::Create(int w, int h, int d)
{ {
UnRef(); UnRef();
@@ -228,6 +303,14 @@ void wxBitmap::SetMask(wxMask *mask)
M_BITMAPDATA->m_bitmapMask = mask ; M_BITMAPDATA->m_bitmapMask = mask ;
} }
void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
{
if (!M_BITMAPDATA)
m_refData = new wxBitmapRefData;
M_BITMAPDATA->m_hBitmap = bmp;
}
void wxBitmap::AddHandler(wxBitmapHandler *handler) void wxBitmap::AddHandler(wxBitmapHandler *handler)
{ {
sm_handlers.Append(handler); sm_handlers.Append(handler);
@@ -290,24 +373,77 @@ wxBitmapHandler *wxBitmap::FindHandler(long bitmapType)
return NULL; return NULL;
} }
// Creates a bitmap that matches the device context, from
// an arbitray bitmap. At present, the original bitmap must have an
// associated palette. TODO: use a default palette if no palette exists.
// Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const
{
wxBitmap tmpBitmap(this->GetWidth(), this->GetHeight(), dc.GetDepth());
// TODO:
/*
wxMemoryDC memDC;
HPALETTE hPal = (HPALETTE) NULL;
LPBITMAPINFO lpDib;
void *lpBits = (void*) NULL;
wxASSERT( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != 0) );
tmpBitmap.SetPalette(this->GetPalette());
memDC.SelectObject(tmpBitmap);
memDC.SetPalette(this->GetPalette());
hPal = (HPALETTE) this->GetPalette()->GetHPALETTE();
if( this->GetPalette() && this->GetPalette()->Ok() && (this->GetPalette()->GetHPALETTE() != 0) )
{
tmpBitmap.SetPalette(* this->GetPalette());
memDC.SelectObject(tmpBitmap);
memDC.SetPalette(* this->GetPalette());
hPal = (HPALETTE) this->GetPalette()->GetHPALETTE();
}
else
{
hPal = (HPALETTE) ::GetStockObject(DEFAULT_PALETTE);
wxPalette palette;
palette.SetHPALETTE( (WXHPALETTE)hPal );
tmpBitmap.SetPalette( palette );
memDC.SelectObject(tmpBitmap);
memDC.SetPalette( palette );
}
// set the height negative because in a DIB the order of the lines is reversed
createDIB(this->GetWidth(), -this->GetHeight(), this->GetDepth(), hPal, &lpDib);
lpBits = malloc(lpDib->bmiHeader.biSizeImage);
::GetBitmapBits((HBITMAP)GetHBITMAP(), lpDib->bmiHeader.biSizeImage, lpBits);
::SetDIBitsToDevice((HDC) memDC.GetHDC(), 0, 0, this->GetWidth(), this->GetHeight(),
0, 0, 0, this->GetHeight(), lpBits, lpDib, DIB_RGB_COLORS);
free(lpBits);
freeDIB(lpDib);
*/
return (tmpBitmap);
}
/* /*
* wxMask * wxMask
*/ */
wxMask::wxMask() wxMask::wxMask()
{ {
/* TODO
m_maskBitmap = 0; m_maskBitmap = 0;
*/
} }
// Construct a mask from a bitmap and a colour indicating // Construct a mask from a bitmap and a colour indicating
// the transparent area // the transparent area
wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
{ {
/* TODO
m_maskBitmap = 0; m_maskBitmap = 0;
*/
Create(bitmap, colour); Create(bitmap, colour);
} }
@@ -315,20 +451,14 @@ wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
// the transparent area // the transparent area
wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex) wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
{ {
/* TODO
m_maskBitmap = 0; m_maskBitmap = 0;
*/
Create(bitmap, paletteIndex); Create(bitmap, paletteIndex);
} }
// Construct a mask from a mono bitmap (copies the bitmap). // Construct a mask from a mono bitmap (copies the bitmap).
wxMask::wxMask(const wxBitmap& bitmap) wxMask::wxMask(const wxBitmap& bitmap)
{ {
/* TODO
m_maskBitmap = 0; m_maskBitmap = 0;
*/
Create(bitmap); Create(bitmap);
} }
@@ -429,11 +559,3 @@ void wxBitmap::InitStandardHandlers()
*/ */
} }
void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
{
if (!M_BITMAPDATA)
m_refData = new wxBitmapRefData;
M_BITMAPDATA->m_hBitmap = bmp;
}

View File

@@ -1,19 +1,27 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: button.cpp // Name: button.cpp
// Purpose: wxButton // Purpose: wxButton
// Author: AUTHOR // Author: David Webster
// Modified by: // Modified by:
// Created: ??/??/98 // Created: 10/13/99
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) AUTHOR // Copyright: (c) David Webster
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ // For compilers that support precompilation, includes "wx.h".
#pragma implementation "button.h" #include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/button.h"
#include "wx/brush.h"
#include "wx/panel.h"
#include "wx/bmpbuttn.h"
#include "wx/settings.h"
#include "wx/dcscreen.h"
#endif #endif
#include "wx/button.h" #include "wx/os2/private.h"
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
@@ -43,9 +51,81 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
return FALSE; return FALSE;
} }
void wxButton::SetSize(int x, int y, int width, int height, int sizeFlags) wxButton::~wxButton()
{ {
// TODO wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
if ( panel )
{
if ( panel->GetDefaultItem() == this )
{
// don't leave the panel with invalid default item
panel->SetDefaultItem(NULL);
}
}
}
// ----------------------------------------------------------------------------
// size management including autosizing
// ----------------------------------------------------------------------------
wxSize wxButton::DoGetBestSize()
{
wxString label = wxGetWindowText(GetHWND());
int wBtn;
GetTextExtent(label, &wBtn, NULL);
int wChar, hChar;
wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont());
// add a margin - the button is wider than just its label
wBtn += 3*wChar;
// the button height is proportional to the height of the font used
int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
return wxSize(wBtn, hBtn);
}
/* static */
wxSize wxButton::GetDefaultSize()
{
static wxSize s_sizeBtn;
if ( s_sizeBtn.x == 0 )
{
wxScreenDC dc;
dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
// the size of a standard button in the dialog units is 50x14,
// translate this to pixels
// NB1: the multipliers come from the Windows convention
// NB2: the extra +1/+2 were needed to get the size be the same as the
// size of the buttons in the standard dialog - I don't know how
// this happens, but on my system this size is 75x23 in pixels and
// 23*8 isn't even divisible by 14... Would be nice to understand
// why these constants are needed though!
s_sizeBtn.x = (50 * (dc.GetCharWidth() + 1))/4;
s_sizeBtn.y = ((14 * dc.GetCharHeight()) + 2)/8;
}
return s_sizeBtn;
}
void wxButton::Command (wxCommandEvent & event)
{
ProcessCommand (event);
}
// ----------------------------------------------------------------------------
// helpers
// ----------------------------------------------------------------------------
bool wxButton::SendClickEvent()
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
event.SetEventObject(this);
return ProcessCommand(event);
} }
void wxButton::SetDefault() void wxButton::SetDefault()
@@ -59,19 +139,36 @@ void wxButton::SetDefault()
// TODO: make button the default // TODO: make button the default
} }
wxString wxButton::GetLabel() const // ----------------------------------------------------------------------------
// event/message handlers
// ----------------------------------------------------------------------------
bool wxButton::OS2Command(WXUINT param, WXWORD id)
{ {
bool processed = FALSE;
// TODO // TODO
return wxString(""); /*
switch ( param )
{
case 1: // 1 for accelerator
case BN_CLICKED:
processed = SendClickEvent();
break;
}
*/
return processed;
} }
void wxButton::SetLabel(const wxString& label) WXHBRUSH wxButton::OnCtlColor(WXHDC pDC,
WXHWND pWnd,
WXUINT nCtlColor,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam)
{ {
// TODO wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
} }
void wxButton::Command (wxCommandEvent & event)
{
ProcessCommand (event);
}