--- /dev/null
+/*
+ * File: pngread.h
+ * Purpose: PNG file reader
+ * Author: Alejandro Aguilar Sierra/Julian Smart
+ * Created: 1995
+ * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
+ *
+ *
+ */
+
+#ifndef _WX_PNGREAD__
+#define _WX_PNGREAD__
+
+#ifndef byte
+typedef unsigned char byte;
+#endif
+
+#define WXIMA_COLORS DIB_PAL_COLORS
+
+typedef byte* ImagePointerType;
+
+typedef struct
+{
+ byte red;
+ byte green;
+ byte blue;
+} rgb_color_struct;
+
+
+#define COLORTYPE_PALETTE 1
+#define COLORTYPE_COLOR 2
+#define COLORTYPE_ALPHA 4
+
+class wxPNGReader
+{
+protected:
+ int filetype;
+ wxChar filename[255];
+ ImagePointerType RawImage; // Image data
+
+ int Width, Height; // Dimensions
+ int Depth; // (bits x pixel)
+ int ColorType; // Bit 1 = Palette used
+ // Bit 2 = Color used
+ // Bit 3 = Alpha used
+
+ long EfeWidth; // Efective Width
+
+ LPBITMAPINFOHEADER lpbi;
+ int bgindex;
+ wxPalette* Palette;
+ bool imageOK;
+friend class wxPNGReaderIter;
+public:
+ wxPNGReader(void);
+ wxPNGReader (wxChar* ImageFileName); // Read an image file
+ ~wxPNGReader ();
+
+ void Create(int width, int height, int deep, int colortype=-1);
+
+ bool ReadFile( wxChar* ImageFileName=0 );
+ bool SaveFile( wxChar* ImageFileName=0 );
+ bool SaveXPM(wxChar *filename, wxChar *name = 0);
+ int GetWidth( void ) const { return Width; };
+ int GetHeight( void ) const { return Height; };
+ int GetDepth( void ) const { return Depth; };
+ int GetColorType( void ) const { return ColorType; };
+
+ int GetIndex(int x, int y);
+ bool GetRGB(int x, int y, byte* r, byte* g, byte* b);
+
+ bool SetIndex(int x, int y, int index);
+ bool SetRGB(int x, int y, byte r, byte g, byte b);
+
+ // ColorMap settings
+ bool SetPalette(wxPalette* colourmap);
+ bool SetPalette(int n, rgb_color_struct *rgb_struct);
+ bool SetPalette(int n, byte *r, byte *g=0, byte *b=0);
+ wxPalette* GetPalette() const { return Palette; }
+
+ void NullData();
+ inline int GetBGIndex(void) { return bgindex; }
+
+ inline bool Inside(int x, int y)
+ { return (0<=y && y<Height && 0<=x && x<Width); }
+
+ virtual wxBitmap *GetBitmap(void);
+ virtual bool InstantiateBitmap(wxBitmap *bitmap);
+ wxMask *CreateMask(void);
+
+ inline bool Ok(void) { return imageOK; }
+};
+
+class wxPNGReaderIter
+{
+protected:
+ int Itx, Ity; // Counters
+ int Stepx, Stepy;
+ ImagePointerType IterImage; // Image pointer
+ wxPNGReader *ima;
+public:
+// Constructors
+ wxPNGReaderIter ( void );
+ wxPNGReaderIter ( wxPNGReader *imax );
+ operator wxPNGReader* ();
+
+// Iterators
+ bool ItOK ();
+ void reset ();
+ void upset ();
+ void SetRow(byte *buf, int n);
+ void GetRow(byte *buf, int n);
+ byte GetByte( ) { return IterImage[Itx]; }
+ void SetByte(byte b) { IterImage[Itx] = b; }
+ ImagePointerType GetRow(void);
+ bool NextRow();
+ bool PrevRow();
+ bool NextByte();
+ bool PrevByte();
+
+ void SetSteps(int x, int y=0) { Stepx = x; Stepy = y; }
+ void GetSteps(int *x, int *y) { *x = Stepx; *y = Stepy; }
+ bool NextStep();
+ bool PrevStep();
+
+////////////////////////// AD - for interlace ///////////////////////////////
+ void SetY(int y);
+/////////////////////////////////////////////////////////////////////////////
+};
+
+
+inline
+wxPNGReaderIter::wxPNGReaderIter(void)
+{
+ ima = 0;
+ IterImage = 0;
+ Itx = Ity = 0;
+ Stepx = Stepy = 0;
+}
+
+inline
+wxPNGReaderIter::wxPNGReaderIter(wxPNGReader *imax): ima(imax)
+{
+ if (ima)
+ IterImage = ima->RawImage;
+ Itx = Ity = 0;
+ Stepx = Stepy = 0;
+}
+
+inline
+wxPNGReaderIter::operator wxPNGReader* ()
+{
+ return ima;
+}
+
+inline
+bool wxPNGReaderIter::ItOK ()
+{
+ if (ima)
+ return ima->Inside(Itx, Ity);
+ else
+ return FALSE;
+}
+
+
+inline void wxPNGReaderIter::reset()
+{
+ IterImage = ima->RawImage;
+ Itx = Ity = 0;
+}
+
+inline void wxPNGReaderIter::upset()
+{
+ Itx = 0;
+ Ity = ima->Height-1;
+ IterImage = ima->RawImage + ima->EfeWidth*(ima->Height-1);
+}
+
+inline bool wxPNGReaderIter::NextRow()
+{
+ if (++Ity >= ima->Height) return 0;
+ IterImage += ima->EfeWidth;
+ return 1;
+}
+
+inline bool wxPNGReaderIter::PrevRow()
+{
+ if (--Ity < 0) return 0;
+ IterImage -= ima->EfeWidth;
+ return 1;
+}
+
+////////////////////////// AD - for interlace ///////////////////////////////
+inline void wxPNGReaderIter::SetY(int y)
+{
+ if ((y < 0) || (y > ima->Height)) return;
+ Ity = y;
+ IterImage = ima->RawImage + ima->EfeWidth*y;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+inline void wxPNGReaderIter::SetRow(byte *buf, int n)
+{
+// Here should be bcopy or memcpy
+ //_fmemcpy(IterImage, (void far *)buf, n);
+ if (n<0)
+ n = ima->GetWidth();
+
+ for (int i=0; i<n; i++) IterImage[i] = buf[i];
+}
+
+inline void wxPNGReaderIter::GetRow(byte *buf, int n)
+{
+ for (int i=0; i<n; i++) buf[i] = IterImage[i];
+}
+
+inline ImagePointerType wxPNGReaderIter::GetRow()
+{
+ return IterImage;
+}
+
+inline bool wxPNGReaderIter::NextByte()
+{
+ if (++Itx < ima->EfeWidth)
+ return 1;
+ else
+ if (++Ity < ima->Height)
+ {
+ IterImage += ima->EfeWidth;
+ Itx = 0;
+ return 1;
+ } else
+ return 0;
+}
+
+inline bool wxPNGReaderIter::PrevByte()
+{
+ if (--Itx >= 0)
+ return 1;
+ else
+ if (--Ity >= 0)
+ {
+ IterImage -= ima->EfeWidth;
+ Itx = 0;
+ return 1;
+ } else
+ return 0;
+}
+
+inline bool wxPNGReaderIter::NextStep()
+{
+ Itx += Stepx;
+ if (Itx < ima->EfeWidth)
+ return 1;
+ else {
+ Ity += Stepy;
+ if (Ity < ima->Height)
+ {
+ IterImage += ima->EfeWidth;
+ Itx = 0;
+ return 1;
+ } else
+ return 0;
+ }
+}
+
+inline bool wxPNGReaderIter::PrevStep()
+{
+ Itx -= Stepx;
+ if (Itx >= 0)
+ return 1;
+ else {
+ Ity -= Stepy;
+ if (Ity >= 0 && Ity < ima->Height)
+ {
+ IterImage -= ima->EfeWidth;
+ Itx = 0;
+ return 1;
+ } else
+ return 0;
+ }
+}
+
+#endif
+
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: printdlg.h
-// Purpose: wxPrintDialog, wxPageSetupDialog classes
-// Author: Julian Smart
-// Modified by:
-// Created: 01/02/97
-// RCS-ID: $Id$
-// Copyright: (c) Julian Smart
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef _WX_PRINTDLG_H_
-#define _WX_PRINTDLG_H_
-
-#ifdef __GNUG__
-#pragma interface "printdlg.h"
-#endif
-
-#if wxUSE_PRINTING_ARCHITECTURE
-
-#include "wx/dialog.h"
-#include "wx/cmndata.h"
-
-class WXDLLEXPORT wxDC;
-
-// ---------------------------------------------------------------------------
-// wxPrinterDialog: the common dialog for printing.
-// ---------------------------------------------------------------------------
-
-class WXDLLEXPORT wxPrintDialog : public wxDialog
-{
- DECLARE_DYNAMIC_CLASS(wxPrintDialog)
-
-public:
- wxPrintDialog();
- wxPrintDialog(wxWindow *parent, wxPrintDialogData* data = NULL);
- wxPrintDialog(wxWindow *parent, wxPrintData* data);
- virtual ~wxPrintDialog();
-
- bool Create(wxWindow *parent, wxPrintDialogData* data = NULL);
- virtual int ShowModal();
-
- wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; }
- wxPrintData& GetPrintData() { return m_printDialogData.GetPrintData(); }
- virtual wxDC *GetPrintDC();
-
-private:
- wxPrintDialogData m_printDialogData;
- wxDC* m_printerDC;
- bool m_destroyDC;
- wxWindow* m_dialogParent;
-};
-
-class WXDLLEXPORT wxPageSetupDialog: public wxDialog
-{
- DECLARE_DYNAMIC_CLASS(wxPageSetupDialog)
-
-public:
- wxPageSetupDialog();
- wxPageSetupDialog(wxWindow *parent, wxPageSetupData *data = NULL);
- virtual ~wxPageSetupDialog();
-
- bool Create(wxWindow *parent, wxPageSetupData *data = NULL);
- virtual int ShowModal();
-
- wxPageSetupData& GetPageSetupData() { return m_pageSetupData; }
-
-private:
- wxPageSetupData m_pageSetupData;
- wxWindow* m_dialogParent;
-};
-
-#endif // wxUSE_PRINTING_ARCHITECTURE
-
-#endif
- // _WX_PRINTDLG_H_
// ---------------------------------------------------------------------------
// headers
// ---------------------------------------------------------------------------
+#define INCL_DOS
+#define INCL_PM
+#define INCL_GPI
+#include <os2.h>
+
// ---------------------------------------------------------------------------
// forward declarations
bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
DECLARE_NO_COPY_CLASS(wxWindow);
DECLARE_EVENT_TABLE()
+private:
+ // Virtual function hiding supression
+ inline virtual bool Reparent( wxWindowBase *newParent )
+ { return(wxWindowBase::Reparent(newParent));};
};
// ---------------------------------------------------------------------------
void wxButton::SetDefault()
{
- wxWindow *parent = (wxWindow *)GetParent();
- if (parent)
- parent->SetDefaultItem(this);
+ wxWindow *parent = GetParent();
+ wxButton *btnOldDefault = NULL;
+ wxPanel *panel = wxDynamicCast(parent, wxPanel);
+ if (panel)
+ panel->SetDefaultItem(this);
// TODO: make button the default
}
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: nativdlg.cpp
+// Purpose: Native dialog loading code (part of wxWindow)
+// Author: David Webster
+// Modified by:
+// Created: 10/12/99
+// RCS-ID: $Id$
+// Copyright: (c) David Webster
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+// ===========================================================================
+// declarations
+// ===========================================================================
+
+// ---------------------------------------------------------------------------
+// headers
+// ---------------------------------------------------------------------------
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+ #include <stdio.h>
+ #include "wx/wx.h"
+#endif
+
+#include "wx/os2/private.h"
+#include "wx/spinbutt.h"
+
+// ---------------------------------------------------------------------------
+// global functions
+// ---------------------------------------------------------------------------
+
+extern wxWindow* wxWndHook;
+extern MRESULT wxDlgProc(HWND hWnd, UINT message,
+ MPARAM wParam, MPARAM lParam);
+
+// ===========================================================================
+// implementation
+// ===========================================================================
+
+bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id)
+{
+ m_windowId = id;
+ wxWndHook = this;
+
+ m_hWnd = 0; // TODO (WXHWND)::CreateDialog((HINSTANCE)wxGetInstance(),
+ // MAKEINTRESOURCE(id),
+ // parent ? (HWND)parent->GetHWND() : 0,
+ // (DLGPROC) wxDlgProc);
+ wxWndHook = NULL;
+
+ if ( !m_hWnd )
+ return FALSE;
+
+ SubclassWin(GetHWND());
+
+ if ( parent )
+ parent->AddChild(this);
+ else
+ wxTopLevelWindows.Append(this);
+
+ // Enumerate all children
+ HWND hWndNext;
+// TODO hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
+
+ wxWindow* child = NULL;
+ if (hWndNext)
+ child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
+
+ while (hWndNext != (HWND) NULL)
+ {
+// TODO: hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
+ if (hWndNext)
+ child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
+ }
+
+ return TRUE;
+}
+
+bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name)
+{
+ SetName(name);
+
+ wxWndHook = this;
+ m_hWnd = 0; //TODO: (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(),
+ // name.c_str(),
+ // parent ? (HWND)parent->GetHWND() : 0,
+ // (DLGPROC)wxDlgProc);
+ wxWndHook = NULL;
+
+ if ( !m_hWnd )
+ return FALSE;
+
+ SubclassWin(GetHWND());
+
+ if ( parent )
+ parent->AddChild(this);
+ else
+ wxTopLevelWindows.Append(this);
+
+ // FIXME why don't we enum all children here?
+
+ return TRUE;
+}
+
+// ---------------------------------------------------------------------------
+// look for child by id
+// ---------------------------------------------------------------------------
+
+wxWindow* wxWindow::GetWindowChild1(wxWindowID id)
+{
+ if ( m_windowId == id )
+ return this;
+
+ wxWindowList::Node *node = GetChildren().GetFirst();
+ while ( node )
+ {
+ wxWindow* child = node->GetData();
+ wxWindow* win = child->GetWindowChild1(id);
+ if ( win )
+ return win;
+
+ node = node->GetNext();
+ }
+
+ return NULL;
+}
+
+wxWindow* wxWindow::GetWindowChild(wxWindowID id)
+{
+ wxWindow* win = GetWindowChild1(id);
+ if ( !win )
+ {
+ HWND hWnd = 0; // TODO: ::GetDlgItem((HWND) GetHWND(), id);
+
+ if (hWnd)
+ {
+ wxWindow* child = CreateWindowFromHWND(this, (WXHWND) hWnd);
+ if (child)
+ {
+ child->AddChild(this);
+ return child;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+// ---------------------------------------------------------------------------
+// create wxWin window from a native HWND
+// ---------------------------------------------------------------------------
+
+wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
+{
+ wxString str(wxGetWindowClass(hWnd));
+ str.UpperCase();
+
+ long id = wxGetWindowId(hWnd);
+ long style = 0; // TODO: GetWindowLong((HWND) hWnd, GWL_STYLE);
+
+ wxWindow* win = NULL;
+
+// TODO:
+/*
+ if (str == wxT("BUTTON"))
+ {
+ int style1 = (style & 0xFF);
+ if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) ||
+ (style1 == BS_CHECKBOX))
+ {
+ win = new wxCheckBox;
+ }
+ else if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON))
+ {
+ win = new wxRadioButton;
+ }
+ else if (style & BS_BITMAP)
+ {
+ // TODO: how to find the bitmap?
+ win = new wxBitmapButton;
+ wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
+ }
+ else if (style1 == BS_OWNERDRAW)
+ {
+ // TODO: how to find the bitmap?
+ // TODO: can't distinguish between bitmap button and bitmap static.
+ // Change implementation of wxStaticBitmap to SS_BITMAP.
+ // PROBLEM: this assumes that we're using resource-based bitmaps.
+ // So maybe need 2 implementations of bitmap buttons/static controls,
+ // with a switch in the drawing code. Call default proc if BS_BITMAP.
+ win = new wxBitmapButton;
+ }
+ else if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON))
+ {
+ win = new wxButton;
+ }
+ else if (style1 == BS_GROUPBOX)
+ {
+ win = new wxStaticBox;
+ }
+ else
+ {
+ wxLogError(wxT("Don't know what kind of button this is: id = %d"),
+ id);
+ }
+ }
+ else if (str == wxT("COMBOBOX"))
+ {
+ win = new wxComboBox;
+ }
+ // TODO: Problem if the user creates a multiline - but not rich text - text control,
+ // since wxWin assumes RichEdit control for this. Should have m_isRichText in
+ // wxTextCtrl. Also, convert as much of the window style as is necessary
+ // for correct functioning.
+ // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
+ // to be overridden by each control class.
+ else if (str == wxT("EDIT"))
+ {
+ win = new wxTextCtrl;
+ }
+ else if (str == wxT("LISTBOX"))
+ {
+ win = new wxListBox;
+ }
+ else if (str == wxT("SCROLLBAR"))
+ {
+ win = new wxScrollBar;
+ }
+ else if (str == wxT("MSCTLS_UPDOWN32"))
+ {
+ win = new wxSpinButton;
+ }
+ else if (str == wxT("MSCTLS_TRACKBAR32"))
+ {
+ // Need to ascertain if it's horiz or vert
+ win = new wxSlider;
+ }
+ else if (str == wxT("STATIC"))
+ {
+ int style1 = (style & 0xFF);
+
+ if ((style1 == SS_LEFT) || (style1 == SS_RIGHT) || (style1 == SS_SIMPLE))
+ win = new wxStaticText;
+ else if (style1 == SS_BITMAP)
+ {
+ win = new wxStaticBitmap;
+
+ // Help! this doesn't correspond with the wxWin implementation.
+ wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
+ }
+ }
+ else
+ {
+ wxString msg(wxT("Don't know how to convert from Windows class "));
+ msg += str;
+ wxLogError(msg);
+ }
+*/
+ if (win)
+ {
+ parent->AddChild(win);
+ win->SetEventHandler(win);
+ win->SetHWND(hWnd);
+ win->SetId(id);
+ win->SubclassWin(hWnd);
+ win->AdoptAttributesFromHWND();
+ win->SetupColours();
+
+ return win;
+ }
+ else
+ return NULL;
+}
+
+// Make sure the window style (etc.) reflects the HWND style (roughly)
+void wxWindow::AdoptAttributesFromHWND(void)
+{
+ HWND hWnd = (HWND) GetHWND();
+// TODO:
+/*
+ long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
+
+ if (style & WS_VSCROLL)
+ m_windowStyle |= wxVSCROLL;
+ if (style & WS_HSCROLL)
+ m_windowStyle |= wxHSCROLL;
+*/
+}
+
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: msw/ownerdrw.cpp
+// Purpose: implementation of wxOwnerDrawn class
+// Author: David Webster
+// Modified by:
+// Created: 10/12/99
+// RCS-ID: $Id$
+// Copyright: (c) David Webster
+// Licence: wxWindows license
+///////////////////////////////////////////////////////////////////////////////
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/window.h"
+ #include "wx/msw/private.h"
+ #include "wx/font.h"
+ #include "wx/bitmap.h"
+ #include "wx/dcmemory.h"
+ #include "wx/menu.h"
+ #include "wx/utils.h"
+#endif
+
+#include "wx/ownerdrw.h"
+#include "wx/menuitem.h"
+
+
+// ============================================================================
+// implementation of wxOwnerDrawn class
+// ============================================================================
+
+// ctor
+// ----
+wxOwnerDrawn::wxOwnerDrawn(const wxString& str,
+ bool bCheckable, bool bMenuItem)
+ : m_strName(str)
+{
+ m_bCheckable = bCheckable;
+ m_bOwnerDrawn = FALSE;
+ m_nHeight = 0;
+ m_nMarginWidth = ms_nLastMarginWidth;
+}
+
+ size_t wxOwnerDrawn::ms_nDefaultMarginWidth = 15;
+
+size_t wxOwnerDrawn::ms_nLastMarginWidth = ms_nDefaultMarginWidth;
+
+// drawing
+// -------
+
+// get size of the item
+bool wxOwnerDrawn::OnMeasureItem(size_t *pwidth, size_t *pheight)
+{
+ wxMemoryDC dc;
+ dc.SetFont(GetFont());
+
+ // ## ugly...
+ wxChar *szStripped = new wxChar[m_strName.Len()];
+ wxStripMenuCodes((wxChar *)m_strName.c_str(), szStripped);
+ wxString str = szStripped;
+ delete [] szStripped;
+
+ // # without this menu items look too tightly packed (at least under Windows)
+ str += wxT('W'); // 'W' is typically the widest letter
+
+ dc.GetTextExtent(str, (long *)pwidth, (long *)pheight);
+
+ // JACS: items still look too tightly packed, so adding 2 pixels.
+ (*pheight) = (*pheight) + 2;
+
+ m_nHeight = *pheight; // remember height for use in OnDrawItem
+
+ return TRUE;
+}
+
+// searching for this macro you'll find all the code where I'm using the native
+// Win32 GDI functions and not wxWindows ones. Might help to whoever decides to
+// port this code to X. (VZ)
+
+// JACS: TODO. Why does a disabled but highlighted item still
+// get drawn embossed? How can we tell DrawState that we don't want the
+// embossing?
+
+// draw the item
+bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus st)
+{
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Might want to check the native drawing apis for here and doo something like MSW does for WIN95
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+ // we do nothing on focus change
+ if ( act == wxODFocusChanged )
+ return TRUE;
+
+ // wxColor <-> RGB
+ #define ToRGB(col) RGB(col.Red(), col.Green(), col.Blue())
+ #define UnRGB(col) GetRValue(col), GetGValue(col), GetBValue(col)
+
+ // set the colors
+ // --------------
+ DWORD colBack, colText;
+ if ( st & wxODSelected ) {
+ colBack = GetSysColor(COLOR_HIGHLIGHT);
+ colText = GetSysColor(COLOR_HIGHLIGHTTEXT);
+ }
+ else {
+ // fall back to default colors if none explicitly specified
+ colBack = m_colBack.Ok() ? ToRGB(m_colBack) : GetSysColor(COLOR_WINDOW);
+ colText = m_colText.Ok() ? ToRGB(m_colText) : GetSysColor(COLOR_WINDOWTEXT);
+ }
+
+ dc.SetTextForeground(wxColor(UnRGB(colText)));
+ dc.SetTextBackground(wxColor(UnRGB(colBack)));
+
+ // select the font and draw the text
+ // ---------------------------------
+
+ // determine where to draw and leave space for a check-mark.
+ int x = rc.x + GetMarginWidth();
+
+ dc.SetFont(GetFont());
+ dc.DrawText(m_strName, x, rc.y);
+
+ // draw the bitmap
+ // ---------------
+ if ( IsCheckable() && !m_bmpChecked.Ok() ) {
+ if ( st & wxODChecked ) {
+ // using native APIs for performance and simplicity
+// TODO:
+/*
+ HDC hdcMem = CreateCompatibleDC(hdc);
+ HBITMAP hbmpCheck = CreateBitmap(GetMarginWidth(), m_nHeight, 1, 1, 0);
+ SelectObject(hdcMem, hbmpCheck);
+ // then draw a check mark into it
+ RECT rect = { 0, 0, GetMarginWidth(), m_nHeight };
+
+ // finally copy it to screen DC and clean up
+ BitBlt(hdc, rc.x, rc.y, GetMarginWidth(), m_nHeight,
+ hdcMem, 0, 0, SRCCOPY);
+ DeleteDC(hdcMem);
+*/
+#else
+ // #### to do: perhaps using Marlett font (create equiv. font under X)
+// wxFAIL("not implemented");
+#endif //O_DRAW_NATIVE_API
+ }
+ }
+ else {
+ // for uncheckable item we use only the 'checked' bitmap
+ wxBitmap bmp(GetBitmap(IsCheckable() ? ((st & wxODChecked) != 0) : TRUE));
+ if ( bmp.Ok() ) {
+ wxMemoryDC dcMem(&dc);
+ dcMem.SelectObject(bmp);
+
+ // center bitmap
+ int nBmpWidth = bmp.GetWidth(),
+ nBmpHeight = bmp.GetHeight();
+
+ // there should be enough place!
+ wxASSERT((nBmpWidth <= rc.GetWidth()) && (nBmpHeight <= rc.GetHeight()));
+
+ //MT: blit with mask enabled.
+ dc.Blit(rc.x + (GetMarginWidth() - nBmpWidth) / 2,
+ rc.y + (m_nHeight - nBmpHeight) /2,
+ nBmpWidth, nBmpHeight,
+ &dcMem, 0, 0, wxCOPY,true);
+
+ if ( st & wxODSelected ) {
+// TODO:
+/*
+ #ifdef O_DRAW_NATIVE_API
+ RECT rectBmp = { rc.GetLeft(), rc.GetTop(),
+ rc.GetLeft() + GetMarginWidth(),
+ rc.GetTop() + m_nHeight };
+ SetBkColor(hdc, colBack);
+ DrawEdge(hdc, &rectBmp, EDGE_RAISED, BF_SOFT | BF_RECT);
+*/
+ }
+ }
+ }
+/*
+ #ifdef O_DRAW_NATIVE_API
+ ::SetTextColor(hdc, colOldText);
+ ::SetBkColor(hdc, colOldBack);
+
+ #undef hdc
+ #endif //O_DRAW_NATIVE_API
+*/
+ return TRUE;
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: pnghand.cpp
+// Purpose: Implements a PNG reader class + handler
+// Author: David Webster
+// Modified by:
+// Created: 10/10/99
+// RCS-ID: $Id$
+// Copyright: (c) David Webster
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#if wxUSE_IOSTREAMH
+# include <fstream.h>
+#else
+# include <fstream>
+#endif
+
+#define INCL_DOS
+#define INCL_PM
+#define INCL_GPI
+#include <os2.h>
+#include "wx/palette.h"
+#include "wx/bitmap.h"
+#include "wx/utils.h"
+#include "wx/msw/pngread.h"
+#include "wx/msw/dibutils.h"
+
+extern "C" {
+#include "../png/png.h"
+}
+
+extern "C" void png_read_init PNGARG((png_structp png_ptr));
+extern "C" void png_write_init PNGARG((png_structp png_ptr));
+
+#ifndef GlobalAllocPtr
+#define GlobalPtrHandle(lp) \
+ ((HGLOBAL)GlobalHandle(lp))
+
+#define GlobalLockPtr(lp) \
+ ((BOOL)GlobalLock(GlobalPtrHandle(lp)))
+#define GlobalUnlockPtr(lp) \
+ GlobalUnlock(GlobalPtrHandle(lp))
+
+#define GlobalAllocPtr(flags, cb) \
+ (GlobalLock(GlobalAlloc((flags), (cb))))
+#define GlobalReAllocPtr(lp, cbNew, flags) \
+ (GlobalUnlockPtr(lp), GlobalLock(GlobalReAlloc(GlobalPtrHandle(lp) , (cbNew), (flags))))
+#define GlobalFreePtr(lp) \
+ (GlobalUnlockPtr(lp), (BOOL)GlobalFree(GlobalPtrHandle(lp)))
+#endif
+
+
+void
+ima_png_error(png_struct *png_ptr, char *message)
+{
+// wxMessageBox(message, "PNG error");
+
+ longjmp(png_ptr->jmpbuf, 1);
+}
+
+
+// static wxGifReaderIter* iter;
+wxPalette *wxCopyPalette(const wxPalette *cmap);
+
+wxPNGReader::wxPNGReader()
+{
+ filetype = 0;
+ RawImage = NULL; // Image data
+
+ Width = 0; Height = 0; // Dimensions
+ Depth = 0; // (bits x pixel)
+ ColorType = 0; // Bit 1 = Palette used
+ // Bit 2 = Color used
+ // Bit 3 = Alpha used
+
+ EfeWidth = 0; // Efective Width
+
+ lpbi = NULL;
+ bgindex = -1;
+ Palette = 0;
+ imageOK = FALSE;
+}
+
+wxPNGReader::wxPNGReader ( wxChar* ImageFileName )
+{
+ imageOK = FALSE;
+ filetype = 0;
+ RawImage = NULL; // Image data
+
+ Width = 0; Height = 0; // Dimensions
+ Depth = 0; // (bits x pixel)
+ ColorType = 0; // Bit 1 = Palette used
+ // Bit 2 = Color used
+ // Bit 3 = Alpha used
+
+ EfeWidth = 0; // Efective Width
+
+ lpbi = NULL;
+ bgindex = -1;
+ Palette = 0;
+
+ imageOK = ReadFile (ImageFileName);
+}
+
+void
+wxPNGReader::Create(int width, int height, int depth, int colortype)
+{
+ Width = width; Height = height; Depth = depth;
+ ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0);
+
+ if (lpbi) {
+#ifdef __WIN16__
+ GlobalFreePtr((unsigned int) lpbi);
+#else
+ GlobalFreePtr(lpbi);
+#endif
+// delete Palette;
+ }
+ RawImage = 0;
+ Palette = 0;
+ lpbi = wxDibCreate(Depth, Width, Height);
+ if (lpbi) {
+ RawImage = (ImagePointerType)wxDibPtr(lpbi);
+ EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4;
+ imageOK = TRUE;
+ }
+}
+
+wxPNGReader::~wxPNGReader ( )
+{
+ if (lpbi) {
+#ifdef __WIN16__
+ GlobalFreePtr((unsigned int) lpbi);
+#else
+ GlobalFreePtr(lpbi);
+#endif
+ delete Palette;
+ }
+}
+
+
+int wxPNGReader::GetIndex(int x, int y)
+{
+ if (!Inside(x, y) || (Depth>8)) return -1;
+
+ ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
+ int index = (int)(*ImagePointer);
+ return index;
+}
+
+bool wxPNGReader::GetRGB(int x, int y, byte* r, byte* g, byte* b)
+{
+ if (!Inside(x, y)) return FALSE;
+
+ if (Palette) {
+ return Palette->GetRGB(GetIndex(x, y), r, g, b);
+/* PALETTEENTRY entry;
+ ::GetPaletteEntries((HPALETTE) Palette->GetHPALETTE(), GetIndex(x, y), 1, &entry);
+ *r = entry.peRed;
+ *g = entry.peGreen;
+ *b = entry.peBlue; */
+ } else {
+ ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
+ *b = ImagePointer[0];
+ *g = ImagePointer[1];
+ *r = ImagePointer[2];
+ }
+ return TRUE;
+}
+
+
+bool wxPNGReader::SetIndex(int x, int y, int index)
+{
+ if (!Inside(x, y) || (Depth>8)) return FALSE;
+
+ ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
+ *ImagePointer = index;
+
+ return TRUE;
+}
+
+bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b)
+{
+ if (!Inside(x, y)) return FALSE;
+
+ if (ColorType & COLORTYPE_PALETTE)
+ {
+ if (!Palette) return FALSE;
+ SetIndex(x, y, Palette->GetPixel(r, g, b));
+
+ } else {
+ ImagePointerType ImagePointer = RawImage + EfeWidth*y + (x*Depth >> 3);
+ ImagePointer[0] = b;
+ ImagePointer[1] = g;
+ ImagePointer[2] = r;
+ }
+
+ return TRUE;
+}
+
+bool wxPNGReader::SetPalette(wxPalette* colourmap)
+{
+ if (!colourmap)
+ return FALSE;
+ ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
+ Palette = colourmap;
+ return (wxDibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
+}
+
+bool
+wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b)
+{
+ Palette = new wxPalette();
+ if (!Palette)
+ return FALSE;
+
+ if (!g) g = r;
+ if (!b) b = g;
+ Palette->Create(n, r, g, b);
+ ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
+ return (wxDibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
+}
+
+bool
+wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct)
+{
+ Palette = new wxPalette();
+ if (!Palette)
+ return FALSE;
+
+ byte r[256], g[256], b[256];
+
+ for(int i=0; i<n; i++)
+ {
+ r[i] = rgb_struct[i].red;
+ g[i] = rgb_struct[i].green;
+ b[i] = rgb_struct[i].blue;
+ }
+ // Added by JACS copying from Andrew Davison's additions
+ // to GIF-reading code
+ // Make transparency colour black...
+ if (bgindex != -1)
+ r[bgindex] = g[bgindex] = b[bgindex] = 0;
+
+ Palette->Create(n, r, g, b);
+ ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR);
+ return (wxDibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0);
+}
+
+void wxPNGReader::NullData()
+{
+ lpbi = NULL;
+ Palette = NULL;
+}
+
+wxBitmap* wxPNGReader::GetBitmap()
+{
+ wxBitmap *bitmap = new wxBitmap;
+ if ( InstantiateBitmap(bitmap) )
+ return bitmap;
+ else
+ {
+ delete bitmap;
+ return NULL;
+ }
+}
+
+bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap)
+{
+ HDC dc = ::CreateCompatibleDC(NULL);
+
+ if (dc)
+ {
+ // tmpBitmap is a dummy, to satisfy ::CreateCompatibleDC (it
+ // is a memory dc that must have a bitmap selected into it)
+ HDC dc2 = GetDC(NULL);
+ HBITMAP tmpBitmap = ::CreateCompatibleBitmap(dc2, GetWidth(), GetHeight());
+ ReleaseDC(NULL, dc2);
+ HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, tmpBitmap);
+
+ if ( Palette )
+ {
+ ::SelectPalette(dc, (HPALETTE) Palette->GetHPALETTE(), FALSE);
+ ::RealizePalette(dc);
+ }
+
+ HBITMAP hBitmap = ::CreateDIBitmap(dc, lpbi,
+ CBM_INIT, RawImage, (LPBITMAPINFO) lpbi, DIB_PAL_COLORS);
+
+ ::SelectPalette(dc, NULL, TRUE);
+ ::SelectObject(dc, oldBitmap);
+ ::DeleteObject(tmpBitmap);
+ ::DeleteDC(dc);
+
+ if ( hBitmap )
+ {
+ bitmap->SetHBITMAP((WXHBITMAP) hBitmap);
+ bitmap->SetWidth(GetWidth());
+ bitmap->SetHeight(GetHeight());
+ bitmap->SetDepth(GetDepth());
+ if ( GetDepth() > 1 && Palette )
+ bitmap->SetPalette(*Palette);
+ bitmap->SetOk(TRUE);
+
+
+ // Make a mask if appropriate
+ if ( bgindex > -1 )
+ {
+ wxMask *mask = CreateMask();
+ bitmap->SetMask(mask);
+ }
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+wxPalette *wxCopyPalette(const wxPalette *cmap)
+{
+ // To get number of entries...
+ WORD count = 0;
+ ::GetObject((HPALETTE) cmap->GetHPALETTE(), sizeof(WORD), &count);
+
+ LOGPALETTE* logPal = (LOGPALETTE*)
+ new BYTE[sizeof(LOGPALETTE) + count*sizeof(PALETTEENTRY)];
+ logPal->palVersion = 0x300;
+ logPal->palNumEntries = count;
+ ::GetPaletteEntries((HPALETTE) cmap->GetHPALETTE(), 0, count, logPal->palPalEntry);
+
+ HPALETTE hPalette = ::CreatePalette(logPal);
+ delete[] logPal;
+
+ wxPalette *newCmap = new wxPalette;
+ newCmap->SetHPALETTE((WXHPALETTE) hPalette);
+ return newCmap;
+}
+
+wxMask *wxPNGReader::CreateMask()
+{
+ HBITMAP hBitmap = ::CreateBitmap(GetWidth(), GetHeight(), 1, 1, NULL);
+
+ HDC dc = ::CreateCompatibleDC(NULL);
+ HBITMAP oldBitmap = (HBITMAP) ::SelectObject(dc, hBitmap);
+
+ int bgIndex = GetBGIndex();
+
+ int x,y;
+
+ for (x=0; x<GetWidth(); x++)
+ {
+ for (y=0; y<GetHeight(); y++)
+ {
+ int index = GetIndex(x, y);
+ if ( index == bgIndex )
+ ::SetPixel(dc, x, GetHeight() - y - 1, RGB(0, 0, 0));
+ else
+ ::SetPixel(dc, x, GetHeight() - y - 1, RGB(255, 255, 255));
+
+ }
+ }
+ ::SelectObject(dc, oldBitmap);
+ wxMask *mask = new wxMask;
+ mask->SetMaskBitmap((WXHBITMAP) hBitmap);
+ return mask;
+}
+
+bool wxPNGReader::ReadFile(wxChar * ImageFileName)
+{
+ if (ImageFileName)
+ wxStrcpy(filename, ImageFileName);
+
+ /* open the file */
+ FILE *fp = fopen(wxConvFile.cWX2MB(filename), "rb");
+ if (!fp)
+ return FALSE;
+
+ /* allocate the necessary structures */
+ png_struct *png_ptr = new (png_struct);
+ if (!png_ptr)
+ {
+ fclose(fp);
+ return FALSE;
+ }
+
+ png_info *info_ptr = new (png_info);
+ if (!info_ptr)
+ {
+ fclose(fp);
+ delete(png_ptr);
+ return FALSE;
+ }
+
+ /* set error handling */
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_read_destroy(png_ptr, info_ptr, (png_info *)0);
+ fclose(fp);
+ delete(png_ptr);
+ delete(info_ptr);
+
+ /* If we get here, we had a problem reading the file */
+ return FALSE;
+ }
+ //png_set_error(ima_png_error, NULL);
+
+ /* initialize the structures, info first for error handling */
+ png_info_init(info_ptr);
+ png_read_init(png_ptr);
+
+ /* set up the input control */
+ png_init_io(png_ptr, fp);
+
+ /* read the file information */
+ png_read_info(png_ptr, info_ptr);
+
+ /* allocate the memory to hold the image using the fields
+ of png_info. */
+ png_color_16 my_background={ 0, 31, 127, 255, 0 };
+
+ if (info_ptr->valid & PNG_INFO_bKGD)
+ {
+ png_set_background(png_ptr, &(info_ptr->background),
+ PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
+ if ( info_ptr->num_palette > 0 )
+ bgindex = info_ptr->background.index;
+ }
+ else {
+ png_set_background(png_ptr, &my_background,
+ PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+
+ // Added by JACS: guesswork!
+ if ( info_ptr->num_trans != 0 )
+ bgindex = info_ptr->num_trans - 1 ;
+ }
+
+ /* tell libpng to strip 16 bit depth files down to 8 bits */
+ if (info_ptr->bit_depth == 16)
+ png_set_strip_16(png_ptr);
+
+ int pixel_depth=(info_ptr->pixel_depth<24) ? info_ptr->pixel_depth: 24;
+ Create(info_ptr->width, info_ptr->height, pixel_depth,
+ info_ptr->color_type);
+
+ if (info_ptr->num_palette>0)
+ {
+ SetPalette((int)info_ptr->num_palette, (rgb_color_struct*)info_ptr->palette);
+ }
+
+ int row_stride = info_ptr->width * ((pixel_depth+7)>>3);
+ // printf("P = %d D = %d RS= %d ", info_ptr->num_palette, info_ptr->pixel_depth,row_stride);
+ // printf("CT = %d TRS = %d BD= %d ", info_ptr->color_type, info_ptr->valid & PNG_INFO_tRNS,info_ptr->bit_depth);
+
+ byte *row_pointers = new byte[row_stride];
+
+ /* turn on interlace handling */
+ int number_passes;
+ if (info_ptr->interlace_type)
+ number_passes = png_set_interlace_handling(png_ptr);
+ else
+ number_passes = 1;
+ // printf("NP = %d ", number_passes);
+
+ // don't use the object to prevent warnings from VC++ about "unportable
+ // interaction between setjmp and C++ object destruction" (this is a correct
+ // warning, of course!)
+ wxPNGReaderIter *iter = new wxPNGReaderIter(this);
+ for (int pass=0; pass< number_passes; pass++)
+ {
+ iter->upset();
+ int y=0;
+ do {
+ //(unsigned char *)iter.GetRow();
+ if (info_ptr->interlace_type) {
+ if (pass>0)
+ iter->GetRow(row_pointers, row_stride);
+ png_read_row(png_ptr, row_pointers, NULL);
+ }
+ else
+ png_read_row(png_ptr, row_pointers, NULL);
+
+ iter->SetRow(row_pointers, row_stride);
+ y++;
+ } while(iter->PrevRow());
+ // printf("Y=%d ",y);
+ }
+
+ delete iter;
+ delete[] row_pointers;
+
+ /* read the rest of the file, getting any additional chunks
+ in info_ptr */
+ png_read_end(png_ptr, info_ptr);
+
+ /* clean up after the read, and free any memory allocated */
+ png_read_destroy(png_ptr, info_ptr, (png_info *)0);
+
+ /* free the structures */
+ delete(png_ptr);
+ delete(info_ptr);
+
+ /* close the file */
+ fclose(fp);
+
+ /* that's it */
+ return TRUE;
+}
+
+
+/* write a png file */
+
+bool wxPNGReader::SaveFile(wxChar * ImageFileName)
+{
+ if (ImageFileName)
+ wxStrcpy(filename, ImageFileName);
+
+ wxPNGReaderIter iter(this);
+ FILE *fp;
+ png_struct *png_ptr;
+ png_info *info_ptr;
+
+ /* open the file */
+ fp = fopen(wxConvFile.cWX2MB(filename), "wb");
+ if (!fp)
+ return FALSE;
+
+ /* allocate the necessary structures */
+ png_ptr = new (png_struct);
+ if (!png_ptr)
+ {
+ fclose(fp);
+ return FALSE;
+ }
+
+ info_ptr = new (png_info);
+ if (!info_ptr)
+ {
+ fclose(fp);
+ delete(png_ptr);
+ return FALSE;
+ }
+
+ /* set error handling */
+ if (setjmp(png_ptr->jmpbuf))
+ {
+ png_write_destroy(png_ptr);
+ fclose(fp);
+ delete(png_ptr);
+ delete(info_ptr);
+
+ /* If we get here, we had a problem reading the file */
+ return FALSE;
+ }
+ //png_set_error(ima_png_error, NULL);
+
+// printf("writig pg %s ", filename);
+ /* initialize the structures */
+ png_info_init(info_ptr);
+ png_write_init(png_ptr);
+
+ int row_stride = GetWidth() * ((GetDepth()+7)>>3);
+ /* set up the output control */
+ png_init_io(png_ptr, fp);
+
+ /* set the file information here */
+ info_ptr->width = GetWidth();
+ info_ptr->height = GetHeight();
+ info_ptr->pixel_depth = GetDepth();
+ info_ptr->channels = (GetDepth()>8) ? 3: 1;
+ info_ptr->bit_depth = GetDepth()/info_ptr->channels;
+ info_ptr->color_type = GetColorType();
+ info_ptr->compression_type = info_ptr->filter_type = info_ptr->interlace_type=0;
+ info_ptr->valid = 0;
+ info_ptr->rowbytes = row_stride;
+
+
+// printf("P = %d D = %d RS= %d GD= %d CH= %d ", info_ptr->pixel_depth, info_ptr->bit_depth, row_stride, GetDepth(), info_ptr->channels);
+ /* set the palette if there is one */
+ if ((GetColorType() & COLORTYPE_PALETTE) && GetPalette())
+ {
+// printf("writing paleta[%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
+ info_ptr->valid |= PNG_INFO_PLTE;
+ info_ptr->palette = new png_color[256];
+ info_ptr->num_palette = 256;
+ for (int i=0; i<256; i++)
+ GetPalette()->GetRGB(i, &info_ptr->palette[i].red, &info_ptr->palette[i].green, &info_ptr->palette[i].blue);
+ }
+// printf("Paleta [%d %d %x]",GetColorType() ,COLORTYPE_PALETTE, GetPalette());
+
+
+ /* optional significant bit chunk */
+// info_ptr->valid |= PNG_INFO_sBIT;
+// info_ptr->sig_bit = true_bit_depth;
+
+ /* optional gamma chunk */
+// info_ptr->valid |= PNG_INFO_gAMA;
+// info_ptr->gamma = gamma;
+
+ /* other optional chunks */
+
+ /* write the file information */
+ png_write_info(png_ptr, info_ptr);
+
+ /* set up the transformations you want. Note that these are
+ all optional. Only call them if you want them */
+
+ /* shift the pixels up to a legal bit depth and fill in
+ as appropriate to correctly scale the image */
+// png_set_shift(png_ptr, &(info_ptr->sig_bit));
+
+ /* pack pixels into bytes */
+// png_set_packing(png_ptr);
+
+ /* flip bgr pixels to rgb */
+// png_set_bgr(png_ptr);
+
+ /* swap bytes of 16 bit files to most significant bit first */
+// png_set_swap(png_ptr);
+
+ /* get rid of filler bytes, pack rgb into 3 bytes */
+// png_set_rgbx(png_ptr);
+
+/* If you are only writing one row at a time, this works */
+
+ byte *row_pointers = new byte[row_stride];
+ iter.upset();
+ do {
+// (unsigned char *)iter.GetRow();
+ iter.GetRow(row_pointers, row_stride);
+ png_write_row(png_ptr, row_pointers);
+ } while(iter.PrevRow());
+
+ delete[] row_pointers;
+
+/* write the rest of the file */
+ png_write_end(png_ptr, info_ptr);
+
+ /* clean up after the write, and free any memory allocated */
+ png_write_destroy(png_ptr);
+
+ /* if you malloced the palette, free it here */
+ if (info_ptr->palette)
+ delete[] (info_ptr->palette);
+
+ /* free the structures */
+ delete(png_ptr);
+ delete(info_ptr);
+
+ /* close the file */
+ fclose(fp);
+
+ /* that's it */
+ return TRUE;
+}
+
+static int Power(int x, int y)
+{
+ int z = 1;
+ int i;
+ for ( i = 0; i < y; i++)
+ {
+ z *= x;
+ }
+ return z;
+}
+
+static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F' };
+
+static void DecToHex(int dec, char *buf)
+{
+ int firstDigit = (int)(dec/16.0);
+ int secondDigit = (int)(dec - (firstDigit*16.0));
+ buf[0] = hexArray[firstDigit];
+ buf[1] = hexArray[secondDigit];
+ buf[2] = 0;
+}
+
+
+bool wxPNGReader::SaveXPM(wxChar *filename, wxChar *name)
+{
+ wxChar nameStr[256];
+ if ( name )
+ wxStrcpy(nameStr, name);
+ else
+ {
+ wxStrcpy(nameStr, filename);
+ wxStripExtension(nameStr);
+ }
+
+ if ( GetDepth() > 4 )
+ {
+ // Only a depth of 4 and below allowed
+ return FALSE;
+ }
+
+ if ( !GetPalette() )
+ return FALSE;
+
+ ofstream str(wxConvFile.cWX2MB(filename));
+ if ( str.bad() )
+ return FALSE;
+
+ int noColours = Power(2, GetDepth());
+
+ // Output header
+ str << "/* XPM */\n";
+ str << "static char * " << nameStr << "_xpm[] = {\n";
+ str << "\"" << GetWidth() << " " << GetHeight() << " " << noColours << " 1\",\n";
+
+ // Output colourmap
+ int base = 97 ; // start from 'a'
+
+ unsigned char red, green, blue;
+ char hexBuf[4];
+ int i;
+ for ( i = 0; i < noColours; i ++)
+ {
+ str << "\"" << (char)(base + i) << " c #";
+ GetPalette()->GetRGB(i, &red, &green, &blue);
+ DecToHex(red, hexBuf);
+ str << hexBuf;
+ DecToHex(green, hexBuf);
+ str << hexBuf;
+ DecToHex(blue, hexBuf);
+ str << hexBuf;
+ str << "\",\n";
+ }
+
+ // Output the data
+ int x, y;
+ for ( y = 0; y < GetHeight(); y++)
+ {
+ str << "\"";
+ for ( x = 0; x < GetWidth(); x++)
+ {
+ int index = GetIndex(x, y);
+ str << (char)(base + index) ;
+ }
+ str << "\",\n";
+ }
+
+ str << "};\n";
+ str.flush();
+
+ return TRUE;
+}
+
+#include <wx/os2/pnghand.h>
+
+IMPLEMENT_DYNAMIC_CLASS(wxPNGFileHandler, wxBitmapHandler)
+
+bool wxPNGFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
+ int desiredWidth, int desiredHeight)
+{
+ wxPNGReader reader;
+ if (reader.ReadFile(WXSTRINGCAST name))
+ {
+ return reader.InstantiateBitmap(bitmap);
+ }
+ else
+ return FALSE;
+}
+
+bool wxPNGFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *pal)
+{
+ return FALSE;
+}
+
+
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: printdlg.cpp
-// Purpose: wxPrintDialog, wxPageSetupDialog
-// Author: AUTHOR
-// Modified by:
-// Created: ??/??/98
-// RCS-ID: $Id$
-// Copyright: (c) AUTHOR
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifdef __GNUG__
-#pragma implementation "printdlg.h"
-#endif
-
-#include "wx/object.h"
-#include "wx/stubs/printdlg.h"
-#include "wx/dcprint.h"
-
-// Use generic page setup dialog: use your own native one if one exists.
-#include "wx/generic/prntdlgg.h"
-
-#if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
-IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
-#endif
-
-wxPrintDialog::wxPrintDialog():
- wxDialog()
-{
- m_dialogParent = NULL;
- m_printerDC = NULL;
-}
-
-wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data):
- wxDialog()
-{
- Create(p, data);
-}
-
-bool wxPrintDialog::Create(wxWindow *p, wxPrintData* data)
-{
- m_dialogParent = p;
- m_printerDC = NULL;
-
- if ( data )
- m_printData = *data;
-
- return TRUE;
-}
-
-wxPrintDialog::~wxPrintDialog()
-{
- if (m_printerDC)
- delete m_printerDC;
-}
-
-int wxPrintDialog::ShowModal()
-{
- // TODO
- return wxID_CANCEL;
-}
-
-wxDC *wxPrintDialog::GetPrintDC()
-{
- if (m_printerDC)
- {
- wxDC* dc = m_printerDC;
- m_printerDC = NULL;
- return dc;
- }
- else
- return NULL;
-}
-
-/*
- * wxPageSetupDialog
- */
-
-wxPageSetupDialog::wxPageSetupDialog():
- wxDialog()
-{
- m_dialogParent = NULL;
-}
-
-wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data):
- wxDialog()
-{
- Create(p, data);
-}
-
-bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
-{
- m_dialogParent = p;
-
- if (data)
- m_pageSetupData = (*data);
-
- return TRUE;
-}
-
-wxPageSetupDialog::~wxPageSetupDialog()
-{
-}
-
-int wxPageSetupDialog::ShowModal()
-{
- // Uses generic page setup dialog
- wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData);
- int ret = genericPageSetupDialog->ShowModal();
- m_pageSetupData = genericPageSetupDialog->GetPageSetupData();
- genericPageSetupDialog->Close(TRUE);
- return ret;
-}
-