From 716cd4107bb8a5f37dea34507453be6870aaef3a Mon Sep 17 00:00:00 2001 From: Kendall Bennett Date: Tue, 12 Jun 2001 18:52:03 +0000 Subject: [PATCH] Commited latest SciTech changes into CVS. This includes updates to the applet code (with changes copyright headers) as well as updates to the wxImage and dib.cpp modules to use virtual file systems so that we can load these objects from ZIP files correctly. The dib.cpp module was also extensively cleaned up (although the DIB writing code does not presently use file streams as we couldn't figure out if it was possible to write to a ZIP file stream). The code has been tested and functions correctly for both regular files and ZIP files. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10551 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/applet/applet.h | 32 +- contrib/include/wx/applet/echovar.h | 95 ++ contrib/include/wx/applet/ifelsevar.h | 95 ++ contrib/include/wx/applet/loadpage.h | 109 +++ contrib/include/wx/applet/prepecho.h | 59 ++ contrib/include/wx/applet/prepifelse.h | 59 ++ contrib/include/wx/applet/prepinclude.h | 63 ++ contrib/include/wx/applet/window.h | 41 +- contrib/samples/applet/applet.cpp | 21 +- contrib/samples/applet/applet.h | 17 +- contrib/samples/applet/combobox.cpp | 27 +- contrib/samples/applet/combobox.h | 37 +- contrib/samples/applet/monitorapplet.cpp | 60 +- contrib/samples/applet/monitorapplet.h | 62 +- contrib/src/applet/applet.cpp | 32 +- contrib/src/applet/appletwindow.cpp | 92 +- contrib/src/applet/echovar.cpp | 180 ++++ contrib/src/applet/ifelsevar.cpp | 159 ++++ contrib/src/applet/loadpage.cpp | 98 ++ contrib/src/applet/prepecho.cpp | 128 +++ contrib/src/applet/prepifelse.cpp | 171 ++++ contrib/src/applet/prepinclude.cpp | 146 +++ src/common/image.cpp | 47 +- src/msw/dib.cpp | 1053 ++++++++++------------ 24 files changed, 2099 insertions(+), 784 deletions(-) create mode 100644 contrib/include/wx/applet/echovar.h create mode 100644 contrib/include/wx/applet/ifelsevar.h create mode 100644 contrib/include/wx/applet/loadpage.h create mode 100644 contrib/include/wx/applet/prepecho.h create mode 100644 contrib/include/wx/applet/prepifelse.h create mode 100644 contrib/include/wx/applet/prepinclude.h create mode 100644 contrib/src/applet/echovar.cpp create mode 100644 contrib/src/applet/ifelsevar.cpp create mode 100644 contrib/src/applet/loadpage.cpp create mode 100644 contrib/src/applet/prepecho.cpp create mode 100644 contrib/src/applet/prepifelse.cpp create mode 100644 contrib/src/applet/prepinclude.cpp diff --git a/contrib/include/wx/applet/applet.h b/contrib/include/wx/applet/applet.h index c67272baca..f51a370497 100644 --- a/contrib/include/wx/applet/applet.h +++ b/contrib/include/wx/applet/applet.h @@ -5,23 +5,19 @@ * Copyright (C) 1991-2001 SciTech Software, Inc. * All rights reserved. * -* ====================================================================== -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* | | -* |This copyrighted computer code is a proprietary trade secret of | -* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 | -* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, | -* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS | -* |STRICTLY PROHIBITED BY LAW. Unless you have current, express | -* |written authorization from SciTech to possess or use this code, you | -* |may be subject to civil and/or criminal penalties. | -* | | -* |If you received this code in error or you would like to report | -* |improper use, please immediately contact SciTech Software, Inc. at | -* |530-894-8400. | -* | | -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* ====================================================================== +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== * * Language: ANSI C++ * Environment: Any @@ -51,7 +47,7 @@ private: DECLARE_EVENT_TABLE(); protected: - wxHtmlAppletWindow *m_parent; + //wxHtmlAppletWindow *m_parent; // Special handler for background erase messages void OnEraseBackground(wxEraseEvent&); diff --git a/contrib/include/wx/applet/echovar.h b/contrib/include/wx/applet/echovar.h new file mode 100644 index 0000000000..27fb78cb6b --- /dev/null +++ b/contrib/include/wx/applet/echovar.h @@ -0,0 +1,95 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: Header file for wxEchoVariable Class, Dynamically constructed +* objects representing variables in SSI #echo directive +* +****************************************************************************/ + +#ifndef __WX_ECHOVAR_H +#define __WX_ECHOVAR_H + +/*--------------------------- Class Definitions ---------------------------*/ + +/**************************************************************************** +REMARKS: +wxEchoVariable class Definition +****************************************************************************/ +class wxEchoVariable : public wxObject { +private: + DECLARE_ABSTRACT_CLASS(wxEchoVariable); + +public: + wxEchoVariable() : wxObject() {} + ~wxEchoVariable() {} + + /**************************************************************************** + RETURNS: + The boolean value of the variable + + PARAMETERS: + parms - Optional parameter string passed from parm= field in HTML + + REMARKS: + To create new variables for the #echo HTML preprocessing directives + you need to derive classes from wxEchoVariable and override the + pure virtual GetValue function. However this should not be done directly + but by using the BEGIN_ECHO_VARIABLE and END_ECHO_VARIABLE macros + + SEE ALSO: + wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE + ****************************************************************************/ + virtual wxString GetValue(const char *parms = NULL) const = 0; + + +public: + // static function to retrieve any variable avaliable + static wxString GetValue(const wxString &cls, const char *parms = NULL); +}; + +/*--------------------------------- MACROS --------------------------------*/ + +#define ECHO_PARM (_BEV_parm) +#define BEGIN_ECHO_VARIABLE(name) \ + class wxEchoVariable##name : public wxEchoVariable { \ + private: \ + DECLARE_DYNAMIC_CLASS(wxEchoVariable##name##); \ + public: \ + wxEchoVariable##name##() : wxEchoVariable() {} \ + virtual wxString GetValue(const char *parms = NULL) const; \ + }; \ + IMPLEMENT_DYNAMIC_CLASS(wxEchoVariable##name##, wxEchoVariable); \ + wxString wxEchoVariable##name :: GetValue(const char *parms) const { \ + wxString _BEV_parm = wxString(parms); + +#define END_ECHO_VARIABLE(name, returnval) \ + return returnval; \ + } + +#define STRING_ECHO_VARIABLE(name, string) \ + BEGIN_ECHO_VARIABLE(##name##); \ + END_ECHO_VARIABLE(##name##, wxString(##string##)) + +#endif // __WX_ECHOVAR_H + diff --git a/contrib/include/wx/applet/ifelsevar.h b/contrib/include/wx/applet/ifelsevar.h new file mode 100644 index 0000000000..851cc82a53 --- /dev/null +++ b/contrib/include/wx/applet/ifelsevar.h @@ -0,0 +1,95 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: Header file for wxIfElseVariable Class, Dynamically constructed +* objects representing variables in SSI #if, #else and #endif directives +* +****************************************************************************/ + +#ifndef __WX_IFELSEVAR_H +#define __WX_IFELSEVAR_H + +/*--------------------------- Class Definitions ---------------------------*/ + +/**************************************************************************** +REMARKS: +This class is used to create variables for the HTML preprocessor #if, #else, +and #endif directives. + +SEE ALSO: +wxIfElsePrep +****************************************************************************/ +class wxIfElseVariable : public wxObject { +private: + DECLARE_ABSTRACT_CLASS(wxIfElseVariable); + +public: + wxIfElseVariable() : wxObject() {} + ~wxIfElseVariable() {} + + /**************************************************************************** + RETURNS: + The boolean value of the variable + + REMARKS: + To create new variables for the #if, #else and #endif HTML preprocessing + blocks you need to derive classes from wxIfElseVariable and override the + pure virtual GetValue function. However this should not be done directly + but by using the BEGIN_IFELSE_VARIABLE and END_IFELSE_VARIABLE macros + + SEE ALSO: + wxIfElsePrep, BEGIN_IFELSE_VARIABLE, END_IFELSE_VARIABLE + ****************************************************************************/ + virtual bool GetValue() const = 0; + + +public: + // static function to retrieve any variable avaliable + static bool GetValue(const wxString &cls); +}; + +/*--------------------------------- MACROS --------------------------------*/ + +#define BEGIN_IFELSE_VARIABLE(name) \ + class wxIfElseVariable##name : public wxIfElseVariable { \ + private: \ + DECLARE_DYNAMIC_CLASS(wxIfElseVariable##name##); \ + public: \ + wxIfElseVariable##name##() : wxIfElseVariable() {} \ + virtual bool GetValue() const; \ + }; \ + IMPLEMENT_DYNAMIC_CLASS(wxIfElseVariable##name##, wxIfElseVariable); \ + bool wxIfElseVariable##name :: GetValue() const { + +#define END_IFELSE_VARIABLE(name, returnval) \ + return returnval; \ + } + +#define IFELSE_VARIABLE(name, state) \ + BEGIN_IFELSE_VARIABLE(##name##); \ + END_IFELSE_VARIABLE(##name##, bool (state)) + + +#endif // __WX_IFELSEVAR_H + diff --git a/contrib/include/wx/applet/loadpage.h b/contrib/include/wx/applet/loadpage.h new file mode 100644 index 0000000000..f20cd0c3fe --- /dev/null +++ b/contrib/include/wx/applet/loadpage.h @@ -0,0 +1,109 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: Header file for the wxLoadPage Event class +* +****************************************************************************/ + +#ifndef __WX_LOAD_PAGE_H +#define __WX_LOAD_PAGE_H + +#include "wx/html/htmlwin.h" + +// Forward declaration +class wxHtmlAppletWindow; + +// If we are compiling this code into a library that links against +// the DLL, we need to remove all the __declspec(dllimports) that +// would declare our classes below incorrectly. + +#ifndef WXMAKINGDLL +#undef WXDLLEXPORT +#define WXDLLEXPORT +#endif +// Declare our local load page event type +BEGIN_DECLARE_EVENT_TYPES() + DECLARE_EVENT_TYPE(wxEVT_LOAD_PAGE, wxEVT_USER_FIRST+1) + DECLARE_EVENT_TYPE(wxEVT_PAGE_LOADED, wxEVT_USER_FIRST+2) +END_DECLARE_EVENT_TYPES() + +/*--------------------------- Class Definitions ---------------------------*/ + +/**************************************************************************** +REMARKS: +Defines the class for load page events. +****************************************************************************/ +class wxLoadPageEvent : public wxEvent { + DECLARE_DYNAMIC_CLASS(wxLoadPageEvent); + +protected: + wxString m_hRef; + wxHtmlAppletWindow *m_htmlWindow; + +public: + // Constructor + wxLoadPageEvent(const wxString &hRef = "",wxHtmlAppletWindow *htmlWindow = NULL); + + // Destructor + ~wxLoadPageEvent() {} + + // Return the hmtl window for the load page operation + wxHtmlAppletWindow *GetHtmlWindow() { return m_htmlWindow; }; + + // Get the hRef string for the load page operation + const wxString & GetHRef() { return m_hRef; }; + + // Copy constructor for the object + void CopyObject(wxObject& obj) const; + }; + + +// Define the macro to create our event type +typedef void (wxEvtHandler::*wxLoadPageEventFunction)(wxLoadPageEvent&); +#define EVT_LOAD_PAGE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_LOAD_PAGE, -1, -1, (wxObjectEventFunction)(wxEventFunction)(wxLoadPageEventFunction) & fn, (wxObject *) NULL ), + +/**************************************************************************** +REMARKS: +Defines the class for pageloaded events. +****************************************************************************/ +class wxPageLoadedEvent : public wxEvent { + DECLARE_DYNAMIC_CLASS(wxPageLoadedEvent); + +public: + // Constructor + wxPageLoadedEvent(); + + // Destructor + ~wxPageLoadedEvent() {} + + // Copy constructor for the object + void CopyObject(wxObject& obj) const; + }; + +// Define the macro to create our event type +typedef void (wxEvtHandler::*wxPageLoadedEventFunction)(wxPageLoadedEvent&); +#define EVT_PAGE_LOADED(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_PAGE_LOADED, -1, -1, (wxObjectEventFunction)(wxEventFunction)(wxPageLoadedEventFunction) & fn, (wxObject *) NULL ), + + +#endif // __WX_LOAD_PAGE_H diff --git a/contrib/include/wx/applet/prepecho.h b/contrib/include/wx/applet/prepecho.h new file mode 100644 index 0000000000..50cde400b0 --- /dev/null +++ b/contrib/include/wx/applet/prepecho.h @@ -0,0 +1,59 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: Header file for the Preprocessor of the #echo directive +* in wxHTML. +* +****************************************************************************/ + +#ifndef __WX_PREPECHO_H +#define __WX_PREPECHO_H + +#include "wx/html/htmlproc.h" + +/*--------------------------- Class Definitions ---------------------------*/ + +/**************************************************************************** +REMARKS: +Echo Preprocessor class Definition +****************************************************************************/ +class wxEchoPrep : public wxHtmlProcessor { +private: + //DECLARE_DYNAMIC_CLASS(wxEchoPrep); + +public: + wxEchoPrep() : wxHtmlProcessor() {} + ~wxEchoPrep() {} + + // Process input text and return processed result + wxString Process(const wxString& text) const; + + // Return priority value of this processor. The higher, the sooner + // is the processor applied to the text. + int GetPriority() const { return wxHTML_PRIORITY_SYSTEM-2; } + }; + + +#endif // __WX_PREPECHO_H + diff --git a/contrib/include/wx/applet/prepifelse.h b/contrib/include/wx/applet/prepifelse.h new file mode 100644 index 0000000000..216f5d5ba5 --- /dev/null +++ b/contrib/include/wx/applet/prepifelse.h @@ -0,0 +1,59 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: Header file for the Preprocessor of the #if SSI directive +* in wxHTML. +* +****************************************************************************/ + +#ifndef __WX_PREPIFELSE_H +#define __WX_PREPIFELSE_H + +#include "wx/html/htmlproc.h" + +/*--------------------------- Class Definitions ---------------------------*/ + +/**************************************************************************** +REMARKS: +If Else Preprocessor class Definition +****************************************************************************/ +class wxIfElsePrep : public wxHtmlProcessor { +private: + //DECLARE_DYNAMIC_CLASS(wxIfElsePrep); + +public: + wxIfElsePrep() : wxHtmlProcessor() {} + ~wxIfElsePrep() {} + + // Process input text and return processed result + wxString Process(const wxString& text) const; + + // Return priority value of this processor. The higher, the sooner + // is the processor applied to the text. + int GetPriority() const { return wxHTML_PRIORITY_SYSTEM-2; } + }; + + +#endif // __WX_PREPECHO_H + diff --git a/contrib/include/wx/applet/prepinclude.h b/contrib/include/wx/applet/prepinclude.h new file mode 100644 index 0000000000..12cb6d7e79 --- /dev/null +++ b/contrib/include/wx/applet/prepinclude.h @@ -0,0 +1,63 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: Header file for the Preprocessor of the #include directive +* in wxHTML. +* +****************************************************************************/ + +#ifndef __WX_PREPINCLUDE_H +#define __WX_PREPINCLUDE_H + +#include "wx/html/htmlproc.h" + +/*--------------------------- Class Definitions ---------------------------*/ + +/**************************************************************************** +REMARKS: +wxIncludePrep class Definition +****************************************************************************/ +class wxIncludePrep : public wxHtmlProcessor { +private: + //DECLARE_DYNAMIC_CLASS(wxIncludePrep); + wxString DOC_ROOT; + +public: + wxIncludePrep() : wxHtmlProcessor() {DOC_ROOT = wxString("");} + ~wxIncludePrep() {} + + // Process input text and return processed result + wxString Process(const wxString& text) const; + + // Return priority value of this processor. The higher, the sooner + // is the processor applied to the text. + int GetPriority() const { return wxHTML_PRIORITY_SYSTEM; } + + void ChangeDirectory(const wxString &dir); + wxString GetDirectory() { return DOC_ROOT; } + }; + + +#endif // __WX_PREPINCLUDE_H + diff --git a/contrib/include/wx/applet/window.h b/contrib/include/wx/applet/window.h index 6ac0fcc72b..97ff94d869 100644 --- a/contrib/include/wx/applet/window.h +++ b/contrib/include/wx/applet/window.h @@ -5,23 +5,19 @@ * Copyright (C) 1991-2001 SciTech Software, Inc. * All rights reserved. * -* ====================================================================== -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* | | -* |This copyrighted computer code is a proprietary trade secret of | -* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 | -* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, | -* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS | -* |STRICTLY PROHIBITED BY LAW. Unless you have current, express | -* |written authorization from SciTech to possess or use this code, you | -* |may be subject to civil and/or criminal penalties. | -* | | -* |If you received this code in error or you would like to report | -* |improper use, please immediately contact SciTech Software, Inc. at | -* |530-894-8400. | -* | | -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* ====================================================================== +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== * * Language: ANSI C++ * Environment: Any @@ -85,6 +81,7 @@ private: DECLARE_CLASS(wxHtmlAppletWindow); DECLARE_EVENT_TABLE(); + bool m_mutexLock; wxIncludePrep *incPreprocessor; // deleted by list it is added too in constructor protected: wxAppletList m_AppletList; @@ -152,6 +149,16 @@ public: // Event handlers to load a new page void OnPageLoaded(wxPageLoadedEvent &event); + // LoadPage mutex locks + void Lock() { m_mutexLock = true;}; + void UnLock() { m_mutexLock = false;}; + + // Returns TRUE if the mutex is locked, FALSE otherwise. + bool IsLocked() { return m_mutexLock;}; + + // Tries to lock the mutex. If it can't, returns immediately with false. + bool TryLock(); + }; #endif // __WX_APPLET_WINDOW_H diff --git a/contrib/samples/applet/applet.cpp b/contrib/samples/applet/applet.cpp index 86907e99f6..7046f7c5db 100644 --- a/contrib/samples/applet/applet.cpp +++ b/contrib/samples/applet/applet.cpp @@ -2,22 +2,21 @@ * * wxWindows HTML Applet Package * +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* * ======================================================================== * -* The contents of this file are subject to the wxWindows licence; you -* may not use this file except in compliance with the License. You may -* obtain a copy of the License at http://www.wxwindows.org/licence.htm +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt * * Software distributed under the License is distributed on an * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * -* The Original Code is Copyright (C) 2001 SciTech Software, Inc. -* -* The Initial Developer of the Original Code is SciTech Software, Inc. -* All Rights Reserved. -* * ======================================================================== * * Language: ANSI C++ @@ -77,17 +76,17 @@ MyFrame::MyFrame( menuFile->Append(Minimal_Quit, "E&xit"); menuNav->Append(Minimal_Back, "Go &back"); menuNav->Append(Minimal_Forward, "Go &forward"); - + // Now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); menuBar->Append(menuNav, "&Navigate"); - + // ... and attach this menu bar to the frame SetMenuBar(menuBar); CreateStatusBar(2); - // Create the HTML window + // Create the HTML window html = new wxHtmlAppletWindow(this); html->SetRelatedFrame(this, "wxApplet Demo: '%s'"); html->SetRelatedStatusBar(1); diff --git a/contrib/samples/applet/applet.h b/contrib/samples/applet/applet.h index 72a1b422c4..cd5cd9a1d3 100644 --- a/contrib/samples/applet/applet.h +++ b/contrib/samples/applet/applet.h @@ -2,22 +2,21 @@ * * wxWindows HTML Applet Package * +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* * ======================================================================== * -* The contents of this file are subject to the wxWindows licence; you -* may not use this file except in compliance with the License. You may -* obtain a copy of the License at http://www.wxwindows.org/licence.htm +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt * * Software distributed under the License is distributed on an * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * -* The Original Code is Copyright (C) 2001 SciTech Software, Inc. -* -* The Initial Developer of the Original Code is SciTech Software, Inc. -* All Rights Reserved. -* * ======================================================================== * * Language: ANSI C++ @@ -37,7 +36,7 @@ enum { Minimal_About, Minimal_Back, Minimal_Forward, - + // Controls start here (the numbers are, of course, arbitrary) Minimal_Text = 1000, }; diff --git a/contrib/samples/applet/combobox.cpp b/contrib/samples/applet/combobox.cpp index 60ed0948bc..b7dcac51cc 100644 --- a/contrib/samples/applet/combobox.cpp +++ b/contrib/samples/applet/combobox.cpp @@ -2,22 +2,21 @@ * * wxWindows HTML Applet Package * +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* * ======================================================================== * -* The contents of this file are subject to the wxWindows licence; you -* may not use this file except in compliance with the License. You may -* obtain a copy of the License at http://www.wxwindows.org/licence.htm +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt * * Software distributed under the License is distributed on an * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * -* The Original Code is Copyright (C) 2001 SciTech Software, Inc. -* -* The Initial Developer of the Original Code is SciTech Software, Inc. -* All Rights Reserved. -* * ======================================================================== * * Language: ANSI C++ @@ -77,7 +76,7 @@ void ComboBox::Select(int n) m_ListBox->Select(n); m_TextCtrl->SetValue(GetStringSelection()); } - + void ComboBox::Deselect(int n) { m_ListBox->Deselect(n); @@ -86,7 +85,7 @@ void ComboBox::Deselect(int n) void ComboBox::Insert(const wxString& item, int pos) { m_ListBox->Insert(item,pos); -} +} void ComboBox::Insert(const wxString& item, int pos, void *clientData) { @@ -130,13 +129,13 @@ void ComboBox::SetFirstItem(int n) m_ListBox->SetFirstItem(n); m_TextCtrl->SetValue(GetStringSelection()); } - + void ComboBox::SetFirstItem(const wxString &s) { m_ListBox->SetFirstItem(s); m_TextCtrl->SetValue(GetStringSelection()); } - + void ComboBox::Append(const wxString &item) { m_ListBox->Append(item); @@ -155,12 +154,12 @@ void ComboBox::Append(const wxString& item, wxClientData *clientData) m_TextCtrl->SetValue(GetStringSelection()); } -void ComboBox::Clear() +void ComboBox::Clear() { m_ListBox->Clear(); m_TextCtrl->SetValue(GetStringSelection()); } - + void ComboBox::Delete(int n) { m_ListBox->Delete(n); diff --git a/contrib/samples/applet/combobox.h b/contrib/samples/applet/combobox.h index f05df23c93..3592cae3fe 100644 --- a/contrib/samples/applet/combobox.h +++ b/contrib/samples/applet/combobox.h @@ -2,22 +2,21 @@ * * wxWindows HTML Applet Package * +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* * ======================================================================== * -* The contents of this file are subject to the wxWindows licence; you -* may not use this file except in compliance with the License. You may -* obtain a copy of the License at http://www.wxwindows.org/licence.htm +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt * * Software distributed under the License is distributed on an * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * -* The Original Code is Copyright (C) 2001 SciTech Software, Inc. -* -* The Initial Developer of the Original Code is SciTech Software, Inc. -* All Rights Reserved. -* * ======================================================================== * * Language: ANSI C++ @@ -52,45 +51,45 @@ private: public: // Constructor ComboBox(wxWindow *parent, int,int); - + // Returns the id of the listbox: listBoxId. int GetListBoxId(); - + // Inserts: Used to insert items into the listbox void Insert(const wxString& item, int pos); void Insert(const wxString& item, int pos, void *clientData); void Insert(const wxString& item, int pos, wxClientData *clientData); void InsertItems(int nItems, const wxString *items, int pos); void InsertItems(const wxArrayString& items, int pos); - + // Sets: Used to set items in the combo box void Set(int n, const wxString* items, void **clientData ); void Set(const wxArrayString& items, void **clientData); int FindString(const wxString &s); - + // Selections: Used to get/de/select items in the listbox void Select(int n); void Deselect(int n); - int GetSelection(); + int GetSelection(); wxString GetStringSelection(); bool SetStringSelection(const wxString& s, bool select); - + // Set the specified item at the first visible item or scroll to max // range. void SetFirstItem(int n); void SetFirstItem(const wxString& s); - + // Append items to the listbox void Append(const wxString& item); void Append(const wxString& item, void *clientData); void Append(const wxString& item, wxClientData *clientData); - + // Deleting items from the list box - void Clear(); + void Clear(); void Delete(int n); - + // OnChange event function (called from SDD dialog box code, see: dialog.h) Mimic - // msw combobox behavior: Click on listbox item it shows in textbox. + // msw combobox behavior: Click on listbox item it shows in textbox. void OnChange(wxCommandEvent &event); }; diff --git a/contrib/samples/applet/monitorapplet.cpp b/contrib/samples/applet/monitorapplet.cpp index 7310c30616..6fcd1fb041 100644 --- a/contrib/samples/applet/monitorapplet.cpp +++ b/contrib/samples/applet/monitorapplet.cpp @@ -5,23 +5,19 @@ * Copyright (C) 1991-2001 SciTech Software, Inc. * All rights reserved. * -* ====================================================================== -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* | | -* |This copyrighted computer code is a proprietary trade secret of | -* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 | -* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, | -* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS | -* |STRICTLY PROHIBITED BY LAW. Unless you have current, express | -* |written authorization from SciTech to possess or use this code, you | -* |may be subject to civil and/or criminal penalties. | -* | | -* |If you received this code in error or you would like to report | -* |improper use, please immediately contact SciTech Software, Inc. at | -* |530-894-8400. | -* | | -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* ====================================================================== +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== * * Language: ANSI C++ * Environment: Any @@ -41,7 +37,7 @@ // Implement the dynamic class so it can be constructed dynamically IMPLEMENT_DYNAMIC_CLASS(MonitorApplet, wxApplet); - + // Event handler table. BEGIN_EVENT_TABLE(MonitorApplet, wxApplet) EVT_LISTBOX(ID_LISTBOX_MFTR, MonitorApplet::OnChange) @@ -51,8 +47,8 @@ END_EVENT_TABLE() // Include database of known monitors. Normally this would come from a // real database on disk, but for this simple example we hard code all // the values into a table. -#include "monitors.c" - +#include "monitors.c" + /*------------------------- Implementation --------------------------------*/ /**************************************************************************** @@ -62,7 +58,7 @@ internal values for the class so that it can be properly created later via the virtual Create member function. ****************************************************************************/ MonitorApplet::MonitorApplet() -{ +{ m_Mfr = NULL; m_Model = NULL; m_Data = NULL; @@ -85,7 +81,7 @@ bool MonitorApplet::Create( memset(&m_Data->m_Monitor,0,sizeof(m_Data->m_Monitor)); parent->RegisterCookie(MONITOR_COOKIE_NAME,m_Data); } - + // Create all the controls and initialise them MonitorDialogFunc(this,true,true); if ((m_Mfr = new ComboBox(this , ID_LISTBOX_MFTR, ID_TEXTCTRL_MFTR)) == NULL) @@ -97,7 +93,7 @@ bool MonitorApplet::Create( } return ret; } - + /**************************************************************************** REMARKS: Destructor for the MonitorApplet class. @@ -124,11 +120,11 @@ REMARKS: Handles user navigation away from the applet via an HTML link ****************************************************************************/ void MonitorApplet::OnLinkClicked( - const wxHtmlLinkInfo&) + const wxHtmlLinkInfo&) { SaveCurrentState(); } - + /**************************************************************************** REMARKS: Handles user navigation away from the applet via the history forward command @@ -137,7 +133,7 @@ void MonitorApplet::OnHistoryForward() { SaveCurrentState(); } - + /**************************************************************************** REMARKS: Handles user navigation away from the applet via the history back command @@ -146,12 +142,12 @@ void MonitorApplet::OnHistoryBack() { SaveCurrentState(); } - + /**************************************************************************** REMARKS: Handles inter applet communication messages ****************************************************************************/ -void MonitorApplet::OnMessage( +void MonitorApplet::OnMessage( wxEvent& msg) { msg.Skip(true); @@ -168,7 +164,7 @@ void MonitorApplet::OnChange( ReadModelList(true); } else if (evt.GetId() == m_Model->GetListBoxId()) { - m_Model->OnChange(evt); + m_Model->OnChange(evt); } } @@ -177,7 +173,7 @@ REMARKS: Updates the manufacturer list for the dialog box from the database. ****************************************************************************/ void MonitorApplet::ReadMfrList() -{ +{ char buf[80] = ""; int i,selected = 0; MonitorEntry *m; @@ -202,11 +198,11 @@ manufacturer type. ****************************************************************************/ void MonitorApplet::ReadModelList( bool selectCurrent) -{ +{ int i,selected = 0; MonitorEntry *m; wxString mfrStr; - + mfrStr = m_Mfr->GetStringSelection(); m_Model->Clear(); for (m = m_Monitors,i = 0; m->m_Mfr[0] != 0; m++) { diff --git a/contrib/samples/applet/monitorapplet.h b/contrib/samples/applet/monitorapplet.h index a2fea2d98a..0ab778ab4a 100644 --- a/contrib/samples/applet/monitorapplet.h +++ b/contrib/samples/applet/monitorapplet.h @@ -1,25 +1,23 @@ /**************************************************************************** * +* wxWindows HTML Applet Package +* * Copyright (C) 1991-2001 SciTech Software, Inc. * All rights reserved. * -* ====================================================================== -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* | | -* |This copyrighted computer code is a proprietary trade secret of | -* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 | -* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, | -* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS | -* |STRICTLY PROHIBITED BY LAW. Unless you have current, express | -* |written authorization from SciTech to possess or use this code, you | -* |may be subject to civil and/or criminal penalties. | -* | | -* |If you received this code in error or you would like to report | -* |improper use, please immediately contact SciTech Software, Inc. at | -* |530-894-8400. | -* | | -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* ====================================================================== +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== * * Language: ANSI C++ * Environment: Any @@ -56,9 +54,9 @@ public: MonitorEntry m_Monitor; }; -// Name used to track the monitor data cookie -#define MONITOR_COOKIE_NAME "MonitorData" - +// Name used to track the monitor data cookie +#define MONITOR_COOKIE_NAME "MonitorData" + /**************************************************************************** REMARKS: Defines our wxMonitor applet class @@ -67,16 +65,16 @@ class MonitorApplet : public wxApplet { private: DECLARE_DYNAMIC_CLASS(MonitorApplet); DECLARE_EVENT_TABLE(); - + protected: - ComboBox *m_Mfr; + ComboBox *m_Mfr; ComboBox *m_Model; - MonitorData *m_Data; + MonitorData *m_Data; static MonitorEntry m_Monitors[]; - + // Flush the current state to a cookie void SaveCurrentState(); - + public: // Constructor (called during dynamic creation) MonitorApplet(); @@ -86,19 +84,19 @@ public: wxHtmlAppletWindow *parent, const wxSize& size, long style); - + // Virtual destructor virtual ~MonitorApplet(); // Handle HTML navigation to a new URL - virtual void OnLinkClicked(const wxHtmlLinkInfo& link); - + virtual void OnLinkClicked(const wxHtmlLinkInfo& link); + // Handle HTML navigation forward command in applet virtual void OnHistoryForward(); - + // Handle HTML navigation back command in applet virtual void OnHistoryBack(); - + // Handle messages from the wxAppletManager and other applets virtual void OnMessage(wxEvent& msg); @@ -106,9 +104,9 @@ public: void ReadMfrList(); void ReadModelList(bool selectCurrent); - // Event handlers + // Event handlers void OnChange(wxCommandEvent &event); }; - + #endif // __WX_MONITORAPPLET_H diff --git a/contrib/src/applet/applet.cpp b/contrib/src/applet/applet.cpp index 69f8f2620f..660f609ae2 100644 --- a/contrib/src/applet/applet.cpp +++ b/contrib/src/applet/applet.cpp @@ -5,23 +5,19 @@ * Copyright (C) 1991-2001 SciTech Software, Inc. * All rights reserved. * -* ====================================================================== -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* | | -* |This copyrighted computer code is a proprietary trade secret of | -* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 | -* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, | -* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS | -* |STRICTLY PROHIBITED BY LAW. Unless you have current, express | -* |written authorization from SciTech to possess or use this code, you | -* |may be subject to civil and/or criminal penalties. | -* | | -* |If you received this code in error or you would like to report | -* |improper use, please immediately contact SciTech Software, Inc. at | -* |530-894-8400. | -* | | -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* ====================================================================== +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== * * Language: ANSI C++ * Environment: Any @@ -72,7 +68,7 @@ Destructor for the wxApplet class. ****************************************************************************/ wxApplet::~wxApplet() { - m_parent->RemoveApplet(this); + ((wxHtmlAppletWindow *) m_parent)->RemoveApplet(this); } /**************************************************************************** diff --git a/contrib/src/applet/appletwindow.cpp b/contrib/src/applet/appletwindow.cpp index b7effb3bd0..82c5f851ba 100644 --- a/contrib/src/applet/appletwindow.cpp +++ b/contrib/src/applet/appletwindow.cpp @@ -5,23 +5,19 @@ * Copyright (C) 1991-2001 SciTech Software, Inc. * All rights reserved. * -* ====================================================================== -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* | | -* |This copyrighted computer code is a proprietary trade secret of | -* |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 | -* |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, | -* |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS | -* |STRICTLY PROHIBITED BY LAW. Unless you have current, express | -* |written authorization from SciTech to possess or use this code, you | -* |may be subject to civil and/or criminal penalties. | -* | | -* |If you received this code in error or you would like to report | -* |improper use, please immediately contact SciTech Software, Inc. at | -* |530-894-8400. | -* | | -* |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW| -* ====================================================================== +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== * * Language: ANSI C++ * Environment: Any @@ -82,7 +78,10 @@ wxHtmlAppletWindow::wxHtmlAppletWindow( const wxString& name) : wxHtmlWindow(parent,id,pos,size,style,name) { - //setup client navbars + // Init our locks + UnLock(); + + // setup client navbars if (navBar) { m_NavBar = navBar; m_NavBackId = navBackId; @@ -92,7 +91,7 @@ wxHtmlAppletWindow::wxHtmlAppletWindow( m_NavBar = NULL; } - //Add HTML preprocessors + // Add HTML preprocessors // deleting preprocessors is done by the code within the window incPreprocessor = new wxIncludePrep(); // #include preprocessor @@ -102,8 +101,6 @@ wxHtmlAppletWindow::wxHtmlAppletWindow( this->AddProcessor(incPreprocessor); this->AddProcessor(echoPreprocessor); this->AddProcessor(ifPreprocessor); - - } /**************************************************************************** @@ -240,23 +237,21 @@ bool wxHtmlAppletWindow::LoadPage( } } - // Grab the directory from the string for use in the include preprocessor - // make sure we get either type of / or \. - int ch = link.Find('\\', true); - if (ch == -1) ch = link.Find('/', true); - if (ch != -1) { - wxFileSystem fs; - wxString tmp = link.Mid(0, ch+1); - fs.ChangePathTo(incPreprocessor->GetDirectory(), true); - fs.ChangePathTo(tmp, true); - incPreprocessor->ChangeDirectory(fs.GetPath()); - } + // Make a copy of the current path the translate for "); + if (end == -1) { +#ifdef CHECKED + wxMessageBox("wxHTML #echo error: Premature end of file while parsing #echo.","Error",wxICON_ERROR); +#endif + break; + } + + end += 3; + tag = output.Mid(i, end); + output.Remove(i, end); + + n = (tag.Lower()).Find(" parm="); + c = tag.Find("-->"); + if (n == -1) { + n = c; + // find the classname + c = (tag.Mid(10, n-10)).Find(" "); + if (c == -1) n -= 10; + else n = c; + cname = tag.Mid(10, n); + + // grab the value from the class, put it in tag since the data is no longer needed + tag = wxEchoVariable::GetValue(cname, NULL); + } + else { + // Find the parms + parms = tag.Mid(n+6, c-n-6); + // Clip off any quotation marks if they exist. (don't die if there arn't any) + c = parms.Find("\""); + if (c != -1) parms = parms.Mid(c+1); + c = parms.Find("\""); + if (c != -1) parms = parms.Mid(0, c); + // find the classname + c = (tag.Mid(10, n-10)).Find(" "); + if (c == -1) n -= 10; + else n = c; + cname = tag.Mid(10, n); + + // grab the value from the class, put it in tag since the data is no longer needed + tag = wxEchoVariable::GetValue(cname, parms.c_str()); + } + + + output = (output.Mid(0,i) + tag + output.Mid(i)); + } + + return output; +} + +FORCE_LINK(echovar) + diff --git a/contrib/src/applet/prepifelse.cpp b/contrib/src/applet/prepifelse.cpp new file mode 100644 index 0000000000..06e12bdcd8 --- /dev/null +++ b/contrib/src/applet/prepifelse.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: This file is the implementation of the Preprocessor object +* for parsing the + int end, c, n; + wxString usecode, code; + wxString cname; + wxString tag; + bool value; + + code = wxString(""); + + // grab the tag and get the name of the variable + end = (output.Mid(b)).Find("-->"); + if (end == -1) { +#ifdef CHECKED + wxMessageBox("wxHTML #if error: Premature end of file while parsing #if.","Error",wxICON_ERROR); +#endif + break; + } + + end += 3; + tag = output.Mid(b, end); + output.Remove(b, end); + + c = tag.Find("-->"); + n = c; + + // find the classname + c = (tag.Mid(8, n-8)).Find(" "); + if (c == -1) n -= 8; + else n = c; + cname = tag.Mid(8, n); + + cname.Trim(false); + c = cname.Find("\""); + if (c != -1) cname = cname.Mid(c+1); + c = cname.Find("\""); + if (c != -1) cname = cname.Mid(0, c); + + // Grab the value from the variable class identified by cname + value = wxIfElseVariable::GetValue(cname); + + // Find the end of the tag () and copy it all into the variable code + end = ((output.Mid(b)).Lower()).Find(""); + if (end == -1) { +#ifdef CHECKED + wxMessageBox("wxHTML #if error: Premature end of file while searching for matching #endif.","Error",wxICON_ERROR); +#endif + break; + } + + code = output.Mid(b, end); + output.Remove(b, end+13); // remove the entire #if block from original document + + // Find out if there is an else statement + end = (code.Lower()).Find(""); + if (end != -1) { + if (!value) { + // Use the else statement + usecode = code.Mid(end+12); + } + else { + // Use statement before #else + usecode = code.Mid(0, end); + } + } + else if (value) { + // There is no #else statement + usecode = code; + } + + if (usecode != wxString("")) + output = (output.Mid(0,b) + usecode + output.Mid(b)); + } + + return output; +} + +FORCE_LINK(ifelsevar) diff --git a/contrib/src/applet/prepinclude.cpp b/contrib/src/applet/prepinclude.cpp new file mode 100644 index 0000000000..74d85e5962 --- /dev/null +++ b/contrib/src/applet/prepinclude.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +* +* wxWindows HTML Applet Package +* +* Copyright (C) 1991-2001 SciTech Software, Inc. +* All rights reserved. +* +* ======================================================================== +* +* The contents of this file are subject to the wxWindows License +* Version 3.0 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.wxwindows.org/licence3.txt +* +* Software distributed under the License is distributed on an +* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* ======================================================================== +* +* Language: ANSI C++ +* Environment: Any +* +* Description: This file is the implementation of the Preprocessor object +* for parsing the "); + + if (n == -1) { +#ifdef CHECKED + wxMessageBox("wxHTML #include error: Could not read filename. Premature end of file.","Error",wxICON_ERROR); +#endif + break; + } + + fname = output.Mid(i+21, n); + + // Clip off any quotation marks if they exist. (don't die if there arn't any) + c = fname.Find("\""); + if (c != -1) fname = fname.Mid(c+1); + c = fname.Find("\""); + if (c != -1) fname = fname.Mid(0, c); + + // remove the #include tag + output.Remove(i, n+21+3); + + wxFSFile * file = fs->OpenFile(fname); + + if (!file) { +#ifdef CHECKED + wxMessageBox(wxString("wxHTML #include error: File not Found ") + fname + wxString("."),"Error",wxICON_ERROR); +#endif + continue; + } + + wxString tmp; + + + do { + char tmp2[257]; + (file->GetStream())->Read(tmp2, 256); + c = (file->GetStream())->LastRead(); + tmp2[c] = 0; + tmp += wxString(tmp2); + } while (c == 256); + + output = (output.Mid(0,i) + tmp + output.Mid(i)); + + #ifdef CHECKED + if (openedcount > RECURSE_LIMIT) { + wxMessageBox(wxString("wxHTML #include error: More than RECURSE_LIMIT files have been #included you may have a file that is directly or indirectly including itself, causing an endless loop"), "Error" ,wxICON_ERROR); + break; + } + #endif + + openedcount++; + delete file; + } + + delete fs; + return output; +} + +/**************************************************************************** +PARAMETERS: +dir - Default directory to get included HTML files from + +REMARKS: +This function sets the directory to get included HTML files from. The default +value is the current directory. Directorys may be given as a relative path. +****************************************************************************/ +void wxIncludePrep::ChangeDirectory( + const wxString &dir) +{ + + DOC_ROOT = dir; +} + diff --git a/src/common/image.cpp b/src/common/image.cpp index d1767d1d04..5045805f8b 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -28,6 +28,7 @@ #include "wx/log.h" #include "wx/app.h" #include "wx/filefn.h" +#include "wx/filesys.h" #include "wx/wfstream.h" #include "wx/intl.h" #include "wx/module.h" @@ -762,18 +763,19 @@ bool wxImage::HasOption(const wxString& name) const bool wxImage::LoadFile( const wxString& filename, long type ) { #if wxUSE_STREAMS - if (wxFileExists(filename)) - { - wxFileInputStream stream(filename); - wxBufferedInputStream bstream( stream ); - return LoadFile(bstream, type); - } - else - { - wxLogError( _("Can't load image from file '%s': file does not exist."), filename.c_str() ); - + // We want to use wxFileSystem for virtual FS compatibility + wxFileSystem fsys; + wxFSFile *file = fsys.OpenFile(filename); + if (!file) { + wxLogError(_("Can't open file '%s'"), filename); return FALSE; - } + } + wxInputStream *stream = file->GetStream(); + if (!stream) { + wxLogError(_("Can't open stream for file '%s'"), filename); + return FALSE; + } + return LoadFile(*stream, type); #else // !wxUSE_STREAMS return FALSE; #endif // wxUSE_STREAMS @@ -782,18 +784,19 @@ bool wxImage::LoadFile( const wxString& filename, long type ) bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype ) { #if wxUSE_STREAMS - if (wxFileExists(filename)) - { - wxFileInputStream stream(filename); - wxBufferedInputStream bstream( stream ); - return LoadFile(bstream, mimetype); - } - else - { - wxLogError( _("Can't load image from file '%s': file does not exist."), filename.c_str() ); - + // We want to use wxFileSystem for virtual FS compatibility + wxFileSystem fsys; + wxFSFile *file = fsys.OpenFile(filename); + if (!file) { + wxLogError(_("Can't open file '%s'"), filename); return FALSE; - } + } + wxInputStream *stream = file->GetStream(); + if (!stream) { + wxLogError(_("Can't open stream for file '%s'"), filename); + return FALSE; + } + return LoadFile(*stream, mimetype); #else // !wxUSE_STREAMS return FALSE; #endif // wxUSE_STREAMS diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index 5a9017faf0..b1dc71542f 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -1,29 +1,21 @@ -/******************************************************************************* - * * - * MODULE : DIB.CC * - * * - * DESCRIPTION : Routines for dealing with Device Independent Bitmaps. * - * * - * FUNCTIONS : * - * * - * wxReadDIB() - Reads a DIB * - * * - * WriteDIB() - Writes a global handle in CF_DIB format* - * to a file. * - * * - * wxPaletteSize() - Calculates the palette size in bytes * - * of given DIB * - * * - * DibNumColors() - Determines the number of colors in DIB * - * * - * DibFromBitmap() - Creates a DIB repr. the DDB passed in. * - * * - * * - * lread() - Private routine to read more than 64k * - * * - * lwrite() - Private routine to write more than 64k * - * * - *******************************************************************************/ +///////////////////////////////////////////////////////////////////////////// +// Name: dib.cpp +// Purpose: Routines for dealing with Device Independent Bitmaps. +// Author: +// Modified by: Jason Quijano 06/06/2001 +// Created: 01/02/97 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +///////////////////////////////////////////////////////////////////////////// +// FUNCTIONS : +// wxReadDIB() - Reads a DIB +// WriteDIB() - Writes a global handle in CF_DIB format to a file. +// wxPaletteSize() - Calculates the palette size in bytes of given DIB * +// DibNumColors() - Determines the number of colors in DIB +// DibFromBitmap() - Creates a DIB repr. the DDB passed in. +// lread() - Private routine to read more than 64k +// lwrite() - Private routine to write more than 64k +///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -47,396 +39,339 @@ #endif #include "wx/msw/dib.h" +#include "wx/filesys.h" #ifdef __GNUWIN32_OLD__ #include "wx/msw/gnuwin32/extra.h" #endif #ifndef SEEK_CUR -/* flags for _lseek */ +// flags for _lseek #define SEEK_CUR 1 #define SEEK_END 2 #define SEEK_SET 0 #endif -#define MAXREAD 32768 /* Number of bytes to be read during */ - /* each read operation. */ +// Number of bytes to be read during each read operation. +#define MAXREAD 32768 -/* Header signatutes for various resources */ -#define BFT_ICON 0x4349 /* 'IC' */ -#define BFT_BITMAP 0x4d42 /* 'BM' */ -#define BFT_CURSOR 0x5450 /* 'PT(' */ +// Header signatutes for various resources +#define BFT_ICON 0x4349 // 'IC' +#define BFT_BITMAP 0x4d42 // 'BM' +#define BFT_CURSOR 0x5450 // 'PT(' -/* macro to determine if resource is a DIB */ -#define ISDIB(bft) ((bft) == BFT_BITMAP) +// macro to determine if resource is a DIB +#define ISDIB(bft) ((bft) == BFT_BITMAP) -/* Macro to align given value to the closest DWORD (unsigned long ) */ -#define ALIGNULONG(i) ((i+3)/4*4) +// Macro to align given value to the closest DWORD (unsigned long ) +#define ALIGNULONG(i) ((i+3)/4*4) -/* Macro to determine to round off the given value to the closest byte */ -#define WIDTHBYTES(i) ((i+31)/32*4) +// Macro to determine to round off the given value to the closest byte +#define WIDTHBYTES(i) ((i+31)/32*4) -#define PALVERSION 0x300 -#define MAXPALETTE 256 /* max. # supported palette entries */ +#define PALVERSION 0x300 +#define MAXPALETTE 256 // max. # supported palette entries -static DWORD PASCAL lread(int fh, VOID FAR *pv, DWORD ul); static DWORD PASCAL lwrite(int fh, VOID FAR *pv, DWORD ul); -static BOOL WriteDIB (LPTSTR szFile,HANDLE hdib); -WORD wxPaletteSize (VOID FAR * pv); // This is non-static as some apps use it externally -static WORD DibNumColors (VOID FAR * pv); -// HANDLE DibFromBitmap (HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal); +static BOOL WriteDIB (LPTSTR szFile,HANDLE hdib); +WORD wxPaletteSize (VOID FAR * pv); // This is non-static as some apps use it externally +static WORD DibNumColors (VOID FAR * pv); +// HANDLE DibFromBitmap (HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal); static BOOL PASCAL MakeBitmapAndPalette(HDC,HANDLE,HPALETTE *,HBITMAP *); -/**************************************************************************** - * * - * FUNCTION : WriteDIB(LPSTR szFile,HANDLE hdib) * - * * - * PURPOSE : Write a global handle in CF_DIB format to a file. * - * * - * RETURNS : TRUE - if successful. * - * FALSE - otherwise * - * * - ****************************************************************************/ - -static BOOL WriteDIB(LPTSTR szFile, HANDLE hdib) +// ---------------------------------------------------------------------------- +// FUNCTION : WriteDIB(LPSTR szFile,HANDLE hdib) +// PURPOSE : Write a global handle in CF_DIB format to a file. +// RETURNS : TRUE - if successful. FALSE - otherwise +// ---------------------------------------------------------------------------- +static BOOL WriteDIB( + LPTSTR szFile, + HANDLE hdib ) { - BITMAPFILEHEADER hdr; - LPBITMAPINFOHEADER lpbi; - int fh; - OFSTRUCT of; - - if (!hdib) - return FALSE; + BITMAPFILEHEADER hdr; + LPBITMAPINFOHEADER lpbi; + int fh; + OFSTRUCT of; - fh = OpenFile(wxConvertWX2MB(szFile), &of, OF_CREATE | OF_READWRITE); - if (fh == -1) - return FALSE; + if (!hdib) + return FALSE; + fh = OpenFile(wxConvertWX2MB(szFile), &of, OF_CREATE | OF_READWRITE); + if (fh == -1) + return FALSE; #ifdef __WINDOWS_386__ - lpbi = (LPBITMAPINFOHEADER) MK_FP32(GlobalLock(hdib)); + lpbi = (LPBITMAPINFOHEADER) MK_FP32(GlobalLock(hdib)); #else - lpbi = (LPBITMAPINFOHEADER) GlobalLock(hdib); + lpbi = (LPBITMAPINFOHEADER) GlobalLock(hdib); #endif - /* Fill in the fields of the file header */ - hdr.bfType = BFT_BITMAP; - hdr.bfSize = GlobalSize(hdib) + sizeof(BITMAPFILEHEADER); - hdr.bfReserved1 = 0; - hdr.bfReserved2 = 0; - hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + lpbi->biSize + - wxPaletteSize(lpbi); + // Fill in the fields of the file header + hdr.bfType = BFT_BITMAP; + hdr.bfSize = GlobalSize(hdib) + sizeof(BITMAPFILEHEADER); + hdr.bfReserved1 = 0; + hdr.bfReserved2 = 0; + hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + lpbi->biSize + wxPaletteSize(lpbi); - /* Write the file header */ - _lwrite(fh, (LPSTR) &hdr, sizeof(BITMAPFILEHEADER)); + // Write the file header + _lwrite(fh, (LPSTR) &hdr, sizeof(BITMAPFILEHEADER)); - /* Write the DIB header and the bits */ - lwrite(fh, (LPSTR) lpbi, GlobalSize(hdib)); + //Write the DIB header and the bits + lwrite(fh, (LPSTR) lpbi, GlobalSize(hdib)); - GlobalUnlock(hdib); - _lclose(fh); - return TRUE; + GlobalUnlock(hdib); + _lclose(fh); + return TRUE; } -/**************************************************************************** - * * - * FUNCTION : wxPaletteSize(VOID FAR * pv) * - * * - * PURPOSE : Calculates the palette size in bytes. If the info. block * - * is of the BITMAPCOREHEADER type, the number of colors is * - * multiplied by 3 to give the palette size, otherwise the * - * number of colors is multiplied by 4. * - * * - * RETURNS : Palette size in number of bytes. * - * * - ****************************************************************************/ - -WORD wxPaletteSize(VOID FAR * pv) +// ---------------------------------------------------------------------------- +// FUNCTION : wxPaletteSize(VOID FAR * pv) +// PURPOSE : Calculates the palette size in bytes. If the info. block +// is of the BITMAPCOREHEADER type, the number of colors is +// multiplied by 3 to give the palette size, otherwise the +// number of colors is multiplied by 4. +// RETURNS : Palette size in number of bytes. +// ---------------------------------------------------------------------------- +WORD wxPaletteSize( + VOID FAR * pv ) { - LPBITMAPINFOHEADER lpbi; - WORD NumColors; + LPBITMAPINFOHEADER lpbi; + WORD NumColors; - lpbi = (LPBITMAPINFOHEADER) pv; - NumColors = DibNumColors(lpbi); + lpbi = (LPBITMAPINFOHEADER) pv; + NumColors = DibNumColors(lpbi); - if (lpbi->biSize == sizeof(BITMAPCOREHEADER)) - return (WORD)(NumColors * sizeof(RGBTRIPLE)); - else - return (WORD)(NumColors * sizeof(RGBQUAD)); + if (lpbi->biSize == sizeof(BITMAPCOREHEADER)) + return (WORD)(NumColors * sizeof(RGBTRIPLE)); + else + return (WORD)(NumColors * sizeof(RGBQUAD)); } -/**************************************************************************** - * * - * FUNCTION : DibNumColors(VOID FAR * pv) * - * * - * PURPOSE : Determines the number of colors in the DIB by looking at * - * the BitCount filed in the info block. * - * * - * RETURNS : The number of colors in the DIB. * - * * - ****************************************************************************/ - -static WORD DibNumColors(VOID FAR *pv) +// ---------------------------------------------------------------------------- +// FUNCTION : DibNumColors(VOID FAR * pv) +// PURPOSE : Determines the number of colors in the DIB by looking at +// the BitCount filed in the info block. +// RETURNS : The number of colors in the DIB. +// ---------------------------------------------------------------------------- +static WORD DibNumColors( + VOID FAR *pv ) { - int bits; - BITMAPINFOHEADER *lpbi; - BITMAPCOREHEADER *lpbc; - - lpbi = ((BITMAPINFOHEADER*) pv); - lpbc = ((BITMAPCOREHEADER*) pv); - - /* With the BITMAPINFO format headers, the size of the palette - * is in biClrUsed, whereas in the BITMAPCORE - style headers, it - * is dependent on the bits per pixel ( = 2 raised to the power of - * bits/pixel). - */ - if (lpbi->biSize != sizeof(BITMAPCOREHEADER)) { - if (lpbi->biClrUsed != 0) - return (WORD) lpbi->biClrUsed; - bits = lpbi->biBitCount; - } - else - bits = lpbc->bcBitCount; - - switch (bits) { - case 1: - return 2; - case 4: - return 16; - case 8: - return 256; - default: - /* A 24 bitcount DIB has no color table */ - return 0; - } + int bits; + BITMAPINFOHEADER *lpbi; + BITMAPCOREHEADER *lpbc; + lpbi = ((BITMAPINFOHEADER*) pv); + lpbc = ((BITMAPCOREHEADER*) pv); + + // With the BITMAPINFO format headers, the size of the palette + // is in biClrUsed, whereas in the BITMAPCORE - style headers, it + // is dependent on the bits per pixel ( = 2 raised to the power of + // bits/pixel). + + if (lpbi->biSize != sizeof(BITMAPCOREHEADER)) { + if (lpbi->biClrUsed != 0) + return (WORD) lpbi->biClrUsed; + bits = lpbi->biBitCount; + } + else + bits = lpbc->bcBitCount; + + switch (bits) { + case 1: + return 2; + case 4: + return 16; + case 8: + return 256; + default: + // A 24 bitcount DIB has no color table + return 0; + } } -/**************************************************************************** - * * - * FUNCTION : DibFromBitmap() * - * * - * PURPOSE : Will create a global memory block in DIB format that * - * represents the Device-dependent bitmap (DDB) passed in. * - * * - * RETURNS : A handle to the DIB * - * * - ****************************************************************************/ - +// ---------------------------------------------------------------------------- +// FUNCTION : DibFromBitmap() +// PURPOSE : Will create a global memory block in DIB format that +// represents the Device-dependent bitmap (DDB) passed in. +// RETURNS : A handle to the DIB +// ---------------------------------------------------------------------------- #if NOTHING -static HANDLE DibFromBitmap(HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal) +static HANDLE DibFromBitmap( + HBITMAP hbm, + DWORD biStyle, + WORD biBits, + HPALETTE hpal) { - BITMAP bm; - BITMAPINFOHEADER bi; - BITMAPINFOHEADER FAR *lpbi; - DWORD dwLen; - HANDLE hdib; - HANDLE h; - HDC hdc; - - if (!hbm) - return NULL; - - if (hpal == NULL) - hpal = GetStockObject(DEFAULT_PALETTE); - - GetObject(hbm, sizeof (bm), (LPSTR) &bm); - - if (biBits == 0) - biBits = bm.bmPlanes * bm.bmBitsPixel; - - bi.biSize = sizeof(BITMAPINFOHEADER); - bi.biWidth = bm.bmWidth; - bi.biHeight = bm.bmHeight; - bi.biPlanes = 1; - bi.biBitCount = biBits; - bi.biCompression = biStyle; - bi.biSizeImage = 0; - bi.biXPelsPerMeter = 0; - bi.biYPelsPerMeter = 0; - bi.biClrUsed = 0; - bi.biClrImportant = 0; - - dwLen = bi.biSize + wxPaletteSize(&bi); - - hdc = GetDC((HWND) NULL); - hpal = SelectPalette(hdc, hpal, FALSE); - RealizePalette(hdc); - - hdib = GlobalAlloc(GHND, dwLen); - - if (!hdib) { - SelectPalette(hdc, hpal, FALSE); - ReleaseDC(NULL, hdc); - return NULL; - } + BITMAP bm; + BITMAPINFOHEADER bi; + BITMAPINFOHEADER FAR *lpbi; + DWORD dwLen; + HANDLE hdib; + HANDLE h; + HDC hdc; + + if (!hbm) + return NULL; + if (hpal == NULL) + hpal = GetStockObject(DEFAULT_PALETTE); + + GetObject(hbm, sizeof (bm), (LPSTR) &bm); + + if (biBits == 0) + biBits = bm.bmPlanes * bm.bmBitsPixel; + + bi.biSize = sizeof(BITMAPINFOHEADER); + bi.biWidth = bm.bmWidth; + bi.biHeight = bm.bmHeight; + bi.biPlanes = 1; + bi.biBitCount = biBits; + bi.biCompression = biStyle; + bi.biSizeImage = 0; + bi.biXPelsPerMeter = 0; + bi.biYPelsPerMeter = 0; + bi.biClrUsed = 0; + bi.biClrImportant = 0; + + dwLen = bi.biSize + wxPaletteSize(&bi); + + hdc = GetDC((HWND) NULL); + hpal = SelectPalette(hdc, hpal, FALSE); + RealizePalette(hdc); + + hdib = GlobalAlloc(GHND, dwLen); + + if (!hdib) { + SelectPalette(hdc, hpal, FALSE); + ReleaseDC(NULL, hdc); + return NULL; + } #ifdef __WINDOWS_386__ - lpbi = (BITMAPINFOHEADER FAR *) MK_FP32(GlobalLock(hdib)); + lpbi = (BITMAPINFOHEADER FAR *) MK_FP32(GlobalLock(hdib)); #else - lpbi = (BITMAPINFOHEADER FAR *) GlobalLock(hdib); + lpbi = (BITMAPINFOHEADER FAR *) GlobalLock(hdib); #endif - *lpbi = bi; + *lpbi = bi; - /* call GetDIBits with a NULL lpBits param, so it will calculate the - * biSizeImage field for us - */ - GetDIBits(hdc, hbm, 0, (WORD) bi.biHeight, - NULL, (LPBITMAPINFO) lpbi, DIB_RGB_COLORS); + // call GetDIBits with a NULL lpBits param, so it will calculate the + // biSizeImage field for us + GetDIBits(hdc, hbm, 0, (WORD) bi.biHeight, NULL, (LPBITMAPINFO) lpbi, DIB_RGB_COLORS); + bi = *lpbi; + GlobalUnlock(hdib); - bi = *lpbi; - GlobalUnlock(hdib); + // If the driver did not fill in the biSizeImage field, make one up + if (bi.biSizeImage == 0) { + bi.biSizeImage = WIDTHBYTES((DWORD)bm.bmWidth * biBits) * bm.bmHeight; + if (biStyle != BI_RGB) + bi.biSizeImage = (bi.biSizeImage * 3) / 2; + } + + // realloc the buffer big enough to hold all the bits + dwLen = bi.biSize + wxPaletteSize(&bi) + bi.biSizeImage; + if (h = GlobalReAlloc(hdib, dwLen, 0)) + hdib = h; + else { + GlobalFree(hdib); + hdib = NULL; + SelectPalette(hdc, hpal, FALSE); + ReleaseDC(NULL, hdc); + return hdib; + } + + // call GetDIBits with a NON-NULL lpBits param, and actualy get the + // bits this time - /* If the driver did not fill in the biSizeImage field, make one up */ - if (bi.biSizeImage == 0) { - bi.biSizeImage = WIDTHBYTES((DWORD)bm.bmWidth * biBits) * bm.bmHeight; - - if (biStyle != BI_RGB) - bi.biSizeImage = (bi.biSizeImage * 3) / 2; - } - - /* realloc the buffer big enough to hold all the bits */ - dwLen = bi.biSize + wxPaletteSize(&bi) + bi.biSizeImage; - if (h = GlobalReAlloc(hdib, dwLen, 0)) - hdib = h; - else { - GlobalFree(hdib); - hdib = NULL; - - SelectPalette(hdc, hpal, FALSE); - ReleaseDC(NULL, hdc); - return hdib; - } - - /* call GetDIBits with a NON-NULL lpBits param, and actualy get the - * bits this time - */ #ifdef __WINDOWS_386__ lpbi = (BITMAPINFOHEADER FAR *) MK_FP32(GlobalLock(hdib)); #else lpbi = (BITMAPINFOHEADER FAR *) GlobalLock(hdib); #endif - if (GetDIBits(hdc, - hbm, - 0, - (WORD) bi.biHeight, - (LPSTR) lpbi + (WORD) lpbi->biSize + wxPaletteSize(lpbi), - (LPBITMAPINFO) lpbi, DIB_RGB_COLORS) == 0) { - GlobalUnlock(hdib); - hdib = NULL; - SelectPalette(hdc, hpal, FALSE); - ReleaseDC((HWND) NULL, hdc); - return NULL; - } + if (GetDIBits(hdc, + hbm, + 0, + (WORD) bi.biHeight, + (LPSTR) lpbi + (WORD) lpbi->biSize + wxPaletteSize(lpbi), + (LPBITMAPINFO) lpbi, DIB_RGB_COLORS) == 0) { + GlobalUnlock(hdib); + hdib = NULL; + SelectPalette(hdc, hpal, FALSE); + ReleaseDC((HWND) NULL, hdc); + return NULL; + } bi = *lpbi; GlobalUnlock(hdib); - SelectPalette(hdc, hpal, FALSE); ReleaseDC(NULL, hdc); return hdib; } #endif - /************* PRIVATE ROUTINES TO READ/WRITE MORE THAN 64K ***************/ -/**************************************************************************** - * * - * FUNCTION : lread(int fh, VOID FAR *pv, DWORD ul) * - * * - * PURPOSE : Reads data in steps of 32k till all the data has been read.* - * * - * RETURNS : 0 - If read did not proceed correctly. * - * number of bytes read otherwise. * - * * - ****************************************************************************/ - -static DWORD PASCAL lread(int fh, void far *pv, DWORD ul) -{ - DWORD ulT = ul; -#if defined(WINNT) || defined(__WIN32__) || defined(__WIN32__) || defined(__WXWINE__) - BYTE *hp = (BYTE *) pv; -#else - BYTE huge *hp = (BYTE huge *) pv; -#endif - while (ul > (DWORD) MAXREAD) { - if (_lread(fh, (LPSTR) hp, (WORD) MAXREAD) != MAXREAD) - return 0; - ul -= MAXREAD; - hp += MAXREAD; - } - if (_lread(fh, (LPSTR) hp, (WXUINT) ul) != (WXUINT) ul) - return 0; - return ulT; -} -/**************************************************************************** - * * - * FUNCTION : lwrite(int fh, VOID FAR *pv, DWORD ul) * - * * - * PURPOSE : Writes data in steps of 32k till all the data is written. * - * * - * RETURNS : 0 - If write did not proceed correctly. * - * number of bytes written otherwise. * - * * - ****************************************************************************/ - -static DWORD PASCAL lwrite(int fh, VOID FAR *pv, DWORD ul) +//************* PRIVATE ROUTINES TO WRITE MORE THAN 64K ****************** +// ---------------------------------------------------------------------------- +// FUNCTION : lwrite(int fh, VOID FAR *pv, DWORD ul) +// PURPOSE : Writes data in steps of 32k till all the data is written. +// RETURNS : 0 - If write did not proceed correctly. number of bytes written otherwise. +// ---------------------------------------------------------------------------- +static DWORD PASCAL lwrite( + int fh, + VOID FAR *pv, + DWORD ul) { - DWORD ulT = ul; + DWORD ulT = ul; #if defined(WINNT) || defined(__WIN32__) || defined(__WIN32__) || defined(__WXWINE__) - BYTE *hp = (BYTE *) pv; + BYTE *hp = (BYTE *) pv; #else - BYTE huge *hp = (BYTE huge *) pv; + BYTE huge *hp = (BYTE huge *) pv; #endif - while (ul > MAXREAD) { - if (_lwrite(fh, (LPSTR) hp, (WORD) MAXREAD) != MAXREAD) - return 0; - ul -= MAXREAD; - hp += MAXREAD; - } - if (_lwrite(fh, (LPSTR) hp, (WXUINT) ul) != (WXUINT) ul) - return 0; - return ulT; + while (ul > MAXREAD) { + if (_lwrite(fh, (LPSTR) hp, (WORD) MAXREAD) != MAXREAD) + return 0; + ul -= MAXREAD; + hp += MAXREAD; + } + if (_lwrite(fh, (LPSTR) hp, (WXUINT) ul) != (WXUINT) ul) + return 0; + return ulT; } -/**************************************************************************** - * - * FUNCTION : ReadDIB(hWnd) - * - * PURPOSE : Reads a DIB from a file, obtains a handle to its - * BITMAPINFO struct. and loads the DIB. Once the DIB - * is loaded, the function also creates a bitmap and - * palette out of the DIB for a device-dependent form. - * - * RETURNS : TRUE - DIB loaded and bitmap/palette created - * The DIBINIT structure pointed to by pInfo is - * filled with the appropriate handles. - * FALSE - otherwise - * - ****************************************************************************/ -BOOL wxReadDIB(LPTSTR lpFileName, HBITMAP *bitmap, HPALETTE *palette) +// ---------------------------------------------------------------------------- +// FUNCTION : ReadDIB(hWnd) +// PURPOSE : Reads a DIB from a file, obtains a handle to its +// BITMAPINFO struct. and loads the DIB. Once the DIB +// is loaded, the function also creates a bitmap and +// palette out of the DIB for a device-dependent form. +// RETURNS : TRUE - DIB loaded and bitmap/palette created +// The DIBINIT structure pointed to by pInfo is +// filled with the appropriate handles. +// FALSE - otherwise +// ---------------------------------------------------------------------------- +BOOL wxReadDIB( + LPTSTR lpFileName, + HBITMAP *bitmap, + HPALETTE *palette) { - int fh; LPBITMAPINFOHEADER lpbi; - OFSTRUCT of; - BITMAPFILEHEADER bf; - WORD nNumColors; + BITMAPFILEHEADER bf; + WORD nNumColors; BOOL result = FALSE; WORD offBits; HDC hDC; BOOL bCoreHead = FALSE; HANDLE hDIB = 0; - /* Open the file and get a handle to it's BITMAPINFO */ - - fh = OpenFile (wxConvertWX2MB(lpFileName), &of, OF_READ); - if (fh == -1) { + // JQ: We want to use wxFileSystem here in stead of Openfile so + // that we can use other FS types like a zip files. + wxFileSystem fsys; + wxFSFile *file = fsys.OpenFile(lpFileName); + wxInputStream *dibs = file->GetStream(); + if (!dibs) { wxLogError(_("Can't open file '%s'"), lpFileName); return (0); - } + } - hDIB = GlobalAlloc(GHND, (DWORD)(sizeof(BITMAPINFOHEADER) + - 256 * sizeof(RGBQUAD))); + hDIB = GlobalAlloc(GHND, (DWORD)(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD))); if (!hDIB) return(0); @@ -446,57 +381,69 @@ BOOL wxReadDIB(LPTSTR lpFileName, HBITMAP *bitmap, HPALETTE *palette) lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB); #endif - /* read the BITMAPFILEHEADER */ - if (sizeof (bf) != _lread (fh, (LPSTR)&bf, sizeof (bf))) + // JQ: read from the wxInputStream dibs instead of fh so + // that we can use other FS types like zip files. + dibs->Read((LPSTR)&bf,sizeof(bf)); + if (sizeof(bf) != dibs->LastRead()) goto ErrExit; - if (bf.bfType != 0x4d42) /* 'BM' */ + if (bf.bfType != 0x4d42) // 'BM' goto ErrExit; - if (sizeof(BITMAPCOREHEADER) != _lread (fh, (LPSTR)lpbi, sizeof(BITMAPCOREHEADER))) + // JQ: read from the wxInputStream dibs instead of fh so + // that we can use other FS types like zip files. + dibs->Read((LPSTR)lpbi,sizeof(BITMAPCOREHEADER)); + if (sizeof(BITMAPCOREHEADER) != dibs->LastRead()) goto ErrExit; - if (lpbi->biSize == sizeof(BITMAPCOREHEADER)) - { + if (lpbi->biSize == sizeof(BITMAPCOREHEADER)){ lpbi->biSize = sizeof(BITMAPINFOHEADER); lpbi->biBitCount = ((LPBITMAPCOREHEADER)lpbi)->bcBitCount; lpbi->biPlanes = ((LPBITMAPCOREHEADER)lpbi)->bcPlanes; lpbi->biHeight = ((LPBITMAPCOREHEADER)lpbi)->bcHeight; lpbi->biWidth = ((LPBITMAPCOREHEADER)lpbi)->bcWidth; bCoreHead = TRUE; - } - else - { - // get to the start of the header and read INFOHEADER - _llseek(fh,sizeof(BITMAPFILEHEADER),SEEK_SET); - if (sizeof(BITMAPINFOHEADER) != _lread (fh, (LPSTR)lpbi, sizeof(BITMAPINFOHEADER))) + } + else { + + // JQ: Get to the start of the header and read INFOHEADER + // using dibs wxInputStream + dibs->SeekI(sizeof(BITMAPFILEHEADER),wxFromStart); + if (dibs->LastError() != wxSTREAM_NO_ERROR) + goto ErrExit; + + // JQ: read from the wxInputStream dibs instead of fh so + // that we can use other FS types like zip files. + // Can I do error checking with this? + dibs->Read((LPSTR)lpbi,sizeof(BITMAPINFOHEADER)); + if (sizeof(BITMAPINFOHEADER) != dibs->LastRead()) goto ErrExit; - } + + } nNumColors = (WORD)lpbi->biClrUsed; - if ( nNumColors == 0 ) - { - /* no color table for 24-bit, default size otherwise */ + if ( nNumColors == 0 ) { + // no color table for 24-bit, default size otherwise if (lpbi->biBitCount != 24) - nNumColors = 1 << lpbi->biBitCount; /* standard size table */ - } + nNumColors = 1 << lpbi->biBitCount; // standard size table + } - /* fill in some default values if they are zero */ + // fill in some default values if they are zero if (lpbi->biClrUsed == 0) lpbi->biClrUsed = nNumColors; - if (lpbi->biSizeImage == 0) - { + if (lpbi->biSizeImage == 0){ lpbi->biSizeImage = ((((lpbi->biWidth * (DWORD)lpbi->biBitCount) + 31) & ~31) >> 3) - * lpbi->biHeight; - } + * lpbi->biHeight; + } - /* get a proper-sized buffer for header, color table and bits */ + // get a proper-sized buffer for header, color table and bits GlobalUnlock(hDIB); - hDIB = GlobalReAlloc(hDIB, lpbi->biSize + - nNumColors * sizeof(RGBQUAD) + - lpbi->biSizeImage, 0); - if (!hDIB) /* can't resize buffer for loading */ + hDIB = GlobalReAlloc(hDIB, lpbi->biSize + nNumColors * sizeof(RGBQUAD) + + lpbi->biSizeImage, 0); + + // can't resize buffer for loading + if (!hDIB) goto ErrExit2; #ifdef __WINDOWS_386__ @@ -505,43 +452,36 @@ BOOL wxReadDIB(LPTSTR lpFileName, HBITMAP *bitmap, HPALETTE *palette) lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB); #endif - /* read the color table */ + // read the color table if (!bCoreHead) - _lread(fh, (LPSTR)(lpbi) + lpbi->biSize, nNumColors * sizeof(RGBQUAD)); - else - { + dibs->Read((LPSTR)lpbi + lpbi->biSize, nNumColors * sizeof(RGBQUAD)); + else { signed int i; RGBQUAD FAR *pQuad; RGBTRIPLE FAR *pTriple; - - _lread(fh, (LPSTR)(lpbi) + lpbi->biSize, nNumColors * sizeof(RGBTRIPLE)); - + dibs->Read((LPSTR)lpbi + lpbi->biSize, nNumColors * sizeof(RGBTRIPLE)); pQuad = (RGBQUAD FAR *)((LPSTR)lpbi + lpbi->biSize); pTriple = (RGBTRIPLE FAR *) pQuad; - for (i = nNumColors - 1; i >= 0; i--) - { + for (i = nNumColors - 1; i >= 0; i--){ pQuad[i].rgbRed = pTriple[i].rgbtRed; pQuad[i].rgbBlue = pTriple[i].rgbtBlue; pQuad[i].rgbGreen = pTriple[i].rgbtGreen; pQuad[i].rgbReserved = 0; + } } - } - /* offset to the bits from start of DIB header */ + // offset to the bits from start of DIB header offBits = (WORD)(lpbi->biSize + nNumColors * sizeof(RGBQUAD)); if (bf.bfOffBits != 0L) - { - _llseek(fh,bf.bfOffBits,SEEK_SET); - } + dibs->SeekI(bf.bfOffBits, wxFromStart); - if (lpbi->biSizeImage == lread(fh, (LPSTR)lpbi + offBits, lpbi->biSizeImage)) + dibs->Read((LPSTR)lpbi + offBits,lpbi->biSizeImage); + if (lpbi->biSizeImage == dibs->LastRead()) { GlobalUnlock(hDIB); - hDC = GetDC(NULL); - if (!MakeBitmapAndPalette(hDC, hDIB, palette, - bitmap)) + if (!MakeBitmapAndPalette(hDC, hDIB, palette, bitmap)) { ReleaseDC(NULL,hDC); goto ErrExit2; @@ -560,28 +500,23 @@ ErrExit: ErrExit2: GlobalFree(hDIB); } - - _lclose(fh); return(result); } -/**************************************************************************** - * - * FUNCTION : MakeBitmapAndPalette - * - * PURPOSE : Given a DIB, creates a bitmap and corresponding palette - * to be used for a device-dependent representation of - * of the image. - * - * RETURNS : TRUE --> success. phPal and phBitmap are filled with - * appropriate handles. Caller is responsible - * for freeing objects. - * FALSE --> unable to create objects. both pointer are - * not valid - * - ****************************************************************************/ -static BOOL PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB, - HPALETTE * phPal, HBITMAP * phBitmap) +// ---------------------------------------------------------------------------- +// FUNCTION : MakeBitmapAndPalette +// PURPOSE : Given a DIB, creates a bitmap and corresponding palette +// to be used for a device-dependent representation of +// of the image. +// RETURNS : TRUE --> success. phPal and phBitmap are filled with +// appropriate handles. Caller is responsible for freeing objects. +// FALSE --> unable to create objects. both pointer are not valid +// ---------------------------------------------------------------------------- +static BOOL PASCAL MakeBitmapAndPalette( + HDC hDC, + HANDLE hDIB, + HPALETTE * phPal, + HBITMAP * phBitmap) { LPBITMAPINFOHEADER lpInfo; BOOL result = FALSE; @@ -621,35 +556,29 @@ static BOOL PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB, } GlobalUnlock (hDIB); // glt - return(result); } -/**************************************************************************** - * * - * FUNCTION : wxMakeDIBPalette(lpInfo) * - * * - * PURPOSE : Given a BITMAPINFOHEADER, create a palette based on - * the color table. - * - * * - * RETURNS : non-zero - handle of a corresponding palette - * zero - unable to create palette - * * - ****************************************************************************/ -HPALETTE wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo) +// ---------------------------------------------------------------------------- +// FUNCTION : wxMakeDIBPalette(lpInfo) +// PURPOSE : Given a BITMAPINFOHEADER, create a palette based on +// the color table. +// RETURNS : non-zero - handle of a corresponding palette +// zero - unable to create palette +// ---------------------------------------------------------------------------- +HPALETTE wxMakeDIBPalette( + LPBITMAPINFOHEADER lpInfo ) { #ifdef __WXWINE__ - return (FALSE); + return (FALSE); #else LPLOGPALETTE npPal; RGBQUAD far *lpRGB; HPALETTE hLogPal; WORD i; - /* since biClrUsed field was filled during the loading of the DIB, - ** we know it contains the number of colors in the color table. - */ + // since biClrUsed field was filled during the loading of the DIB, + // we know it contains the number of colors in the color table. if (lpInfo->biClrUsed) { /* @@ -664,10 +593,10 @@ HPALETTE wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo) npPal->palVersion = 0x300; npPal->palNumEntries = (WORD)lpInfo->biClrUsed; - /* get pointer to the color table */ + // get pointer to the color table lpRGB = (RGBQUAD FAR *)((LPSTR)lpInfo + lpInfo->biSize); - /* copy colors from the color table to the LogPalette structure */ + // copy colors from the color table to the LogPalette structure for (i = 0; (DWORD)i < lpInfo->biClrUsed; i++, lpRGB++) { npPal->palPalEntry[i].peRed = lpRGB->rgbRed; @@ -679,110 +608,118 @@ HPALETTE wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo) hLogPal = CreatePalette((LPLOGPALETTE)npPal); // LocalFree((HANDLE)npPal); free(npPal); - return(hLogPal); } - /* 24-bit DIB with no color table. return default palette. Another - ** option would be to create a 256 color "rainbow" palette to provide - ** some good color choices. - */ + // 24-bit DIB with no color table. return default palette. Another + // option would be to create a 256 color "rainbow" palette to provide + // some good color choices. else return((HPALETTE) GetStockObject(DEFAULT_PALETTE)); #endif - } -bool wxLoadIntoBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette **pal) +// ---------------------------------------------------------------------------- +// FUNCTION : +// PURPOSE : +// RETURNS : +// ---------------------------------------------------------------------------- +bool wxLoadIntoBitmap( + wxChar *filename, + wxBitmap *bitmap, + wxPalette **pal) { - HBITMAP hBitmap; - HPALETTE hPalette; - - bool success = (wxReadDIB(filename, &hBitmap, &hPalette) != 0); + HBITMAP hBitmap; + HPALETTE hPalette; - if (!success) - { - DeleteObject(hPalette); - return FALSE; - } + bool success = (wxReadDIB(filename, &hBitmap, &hPalette) != 0); + if (!success) + { + DeleteObject(hPalette); + return FALSE; + } - if (hPalette) - { - if (pal) + if (hPalette) { - *pal = new wxPalette; - (*pal)->SetHPALETTE((WXHPALETTE) hPalette); + if (pal) + { + *pal = new wxPalette; + (*pal)->SetHPALETTE((WXHPALETTE) hPalette); + } + else + DeleteObject(hPalette); } - else - DeleteObject(hPalette); - } - else if (pal) - *pal = NULL; + else if (pal) + *pal = NULL; - if (hBitmap) - { - BITMAP bm; - GetObject(hBitmap, sizeof(bm), (LPSTR)&bm); + if (hBitmap) + { + BITMAP bm; + GetObject(hBitmap, sizeof(bm), (LPSTR)&bm); - bitmap->SetHBITMAP((WXHBITMAP) hBitmap); - bitmap->SetWidth(bm.bmWidth); - bitmap->SetHeight(bm.bmHeight); - bitmap->SetDepth(bm.bmPlanes * bm.bmBitsPixel); + bitmap->SetHBITMAP((WXHBITMAP) hBitmap); + bitmap->SetWidth(bm.bmWidth); + bitmap->SetHeight(bm.bmHeight); + bitmap->SetDepth(bm.bmPlanes * bm.bmBitsPixel); #if WXWIN_COMPATIBILITY_2 - bitmap->SetOk(TRUE); + bitmap->SetOk(TRUE); #endif // WXWIN_COMPATIBILITY_2 - return TRUE; - } - else return FALSE; + return TRUE; + } + else return FALSE; } -wxBitmap *wxLoadBitmap(wxChar *filename, wxPalette **pal) +// ---------------------------------------------------------------------------- +// FUNCTION : +// PURPOSE : +// RETURNS : +// ---------------------------------------------------------------------------- +wxBitmap *wxLoadBitmap( + wxChar *filename, + wxPalette **pal) { - wxBitmap *bitmap = new wxBitmap; - if (wxLoadIntoBitmap(filename, bitmap, pal)) - return bitmap; - else - { - delete bitmap; - return NULL; - } + wxBitmap *bitmap = new wxBitmap; + if (wxLoadIntoBitmap(filename, bitmap, pal)) + return bitmap; + else + { + delete bitmap; + return NULL; + } } //--------------------------------------------------------------------- +// FUNCTION : InitBitmapInfoHeader +// PURPOSE : Does a "standard" initialization of a BITMAPINFOHEADER, +// given the Width, Height, and Bits per Pixel for the DIB. // -// Function: InitBitmapInfoHeader -// -// Purpose: Does a "standard" initialization of a BITMAPINFOHEADER, -// given the Width, Height, and Bits per Pixel for the -// DIB. +// By standard, I mean that all the relevant fields are set +// to the specified values. biSizeImage is computed, the +// biCompression field is set to "no compression," and all +// other fields are 0. // -// By standard, I mean that all the relevant fields are set -// to the specified values. biSizeImage is computed, the -// biCompression field is set to "no compression," and all -// other fields are 0. +// Note that DIBs only allow BitsPixel values of 1, 4, 8, or +// 24. This routine makes sure that one of these values is +// used (whichever is most appropriate for the specified +// nBPP). // -// Note that DIBs only allow BitsPixel values of 1, 4, 8, or -// 24. This routine makes sure that one of these values is -// used (whichever is most appropriate for the specified -// nBPP). -// -// Parms: lpBmInfoHdr == Far pointer to a BITMAPINFOHEADER structure +// PARMS : lpBmInfoHdr == Far pointer to a BITMAPINFOHEADER structure // to be filled in. -// dwWidth == Width of DIB (not in Win 3.0 & 3.1, high +// dwWidth == Width of DIB (not in Win 3.0 & 3.1, high // word MUST be 0). -// dwHeight == Height of DIB (not in Win 3.0 & 3.1, high +// dwHeight == Height of DIB (not in Win 3.0 & 3.1, high // word MUST be 0). -// nBPP == Bits per Pixel for the DIB. +// nBPP == Bits per Pixel for the DIB. // // History: Date Reason // 11/07/91 Created // //--------------------------------------------------------------------- - -static void InitBitmapInfoHeader (LPBITMAPINFOHEADER lpBmInfoHdr, - DWORD dwWidth, - DWORD dwHeight, - int nBPP) +static void InitBitmapInfoHeader ( + LPBITMAPINFOHEADER lpBmInfoHdr, + DWORD dwWidth, + DWORD dwHeight, + int nBPP ) { // _fmemset (lpBmInfoHdr, 0, sizeof (BITMAPINFOHEADER)); memset (lpBmInfoHdr, 0, sizeof (BITMAPINFOHEADER)); @@ -809,16 +746,17 @@ static void InitBitmapInfoHeader (LPBITMAPINFOHEADER lpBmInfoHdr, lpBmInfoHdr->biSizeImage = WIDTHBYTES (dwWidth * nBPP) * dwHeight; } - - - +// ---------------------------------------------------------------------------- +// FUNCTION : +// PURPOSE : +// RETURNS : +// ---------------------------------------------------------------------------- LPSTR wxFindDIBBits (LPSTR lpbi) { return (lpbi + *(LPDWORD)lpbi + wxPaletteSize (lpbi)); } //--------------------------------------------------------------------- -// // Function: BitmapToDIB // // Purpose: Given a device dependent bitmap and a palette, returns @@ -836,20 +774,21 @@ LPSTR wxFindDIBBits (LPSTR lpbi) // 6/01/91 Created // //--------------------------------------------------------------------- - -HANDLE wxBitmapToDIB (HBITMAP hBitmap, HPALETTE hPal) +HANDLE wxBitmapToDIB ( + HBITMAP hBitmap, + HPALETTE hPal) { - BITMAP Bitmap; - BITMAPINFOHEADER bmInfoHdr; - LPBITMAPINFOHEADER lpbmInfoHdr; - LPSTR lpBits; - HDC hMemDC; - HANDLE hDIB; - HPALETTE hOldPal = NULL; - - // Do some setup -- make sure the Bitmap passed in is valid, - // get info on the bitmap (like its height, width, etc.), - // then setup a BITMAPINFOHEADER. + BITMAP Bitmap; + BITMAPINFOHEADER bmInfoHdr; + LPBITMAPINFOHEADER lpbmInfoHdr; + LPSTR lpBits; + HDC hMemDC; + HANDLE hDIB; + HPALETTE hOldPal = NULL; + + // Do some setup -- make sure the Bitmap passed in is valid, + // get info on the bitmap (like its height, width, etc.), + // then setup a BITMAPINFOHEADER. if (!hBitmap) return NULL; @@ -863,82 +802,82 @@ HANDLE wxBitmapToDIB (HBITMAP hBitmap, HPALETTE hPal) Bitmap.bmPlanes * Bitmap.bmBitsPixel); - // Now allocate memory for the DIB. Then, set the BITMAPINFOHEADER - // into this memory, and find out where the bitmap bits go. + // Now allocate memory for the DIB. Then, set the BITMAPINFOHEADER + // into this memory, and find out where the bitmap bits go. - hDIB = GlobalAlloc (GHND, sizeof (BITMAPINFOHEADER) + - wxPaletteSize ((LPSTR) &bmInfoHdr) + bmInfoHdr.biSizeImage); + hDIB = GlobalAlloc (GHND, sizeof (BITMAPINFOHEADER) + + wxPaletteSize ((LPSTR) &bmInfoHdr) + bmInfoHdr.biSizeImage); - if (!hDIB) - return NULL; + if (!hDIB) + return NULL; #ifdef __WINDOWS_386__ - lpbmInfoHdr = (LPBITMAPINFOHEADER) MK_FP32(GlobalLock (hDIB)); + lpbmInfoHdr = (LPBITMAPINFOHEADER) MK_FP32(GlobalLock (hDIB)); #else - lpbmInfoHdr = (LPBITMAPINFOHEADER) GlobalLock (hDIB); + lpbmInfoHdr = (LPBITMAPINFOHEADER) GlobalLock (hDIB); #endif - *lpbmInfoHdr = bmInfoHdr; - lpBits = wxFindDIBBits ((LPSTR) lpbmInfoHdr); - - - // Now, we need a DC to hold our bitmap. If the app passed us - // a palette, it should be selected into the DC. + *lpbmInfoHdr = bmInfoHdr; + lpBits = wxFindDIBBits ((LPSTR) lpbmInfoHdr); - hMemDC = GetDC (NULL); + // Now, we need a DC to hold our bitmap. If the app passed us + // a palette, it should be selected into the DC. + hMemDC = GetDC (NULL); - if (hPal) - { - hOldPal = SelectPalette (hMemDC, hPal, FALSE); - RealizePalette (hMemDC); - } - - - - // We're finally ready to get the DIB. Call the driver and let - // it party on our bitmap. It will fill in the color table, - // and bitmap bits of our global memory block. + if (hPal) + { + hOldPal = SelectPalette (hMemDC, hPal, FALSE); + RealizePalette (hMemDC); + } - if (!GetDIBits (hMemDC, + // We're finally ready to get the DIB. Call the driver and let + // it party on our bitmap. It will fill in the color table, + // and bitmap bits of our global memory block. + if (!GetDIBits (hMemDC, hBitmap, 0, Bitmap.bmHeight, lpBits, (LPBITMAPINFO) lpbmInfoHdr, DIB_RGB_COLORS)) - { - GlobalUnlock (hDIB); - GlobalFree (hDIB); - hDIB = NULL; - } - else - GlobalUnlock (hDIB); - - - // Finally, clean up and return. + { + GlobalUnlock (hDIB); + GlobalFree (hDIB); + hDIB = NULL; + } + else + GlobalUnlock (hDIB); + // Finally, clean up and return. if (hOldPal) - SelectPalette (hMemDC, hOldPal, FALSE); + SelectPalette (hMemDC, hOldPal, FALSE); ReleaseDC (NULL, hMemDC); - return hDIB; } -bool wxSaveBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette *colourmap) +// ---------------------------------------------------------------------------- +// FUNCTION : +// PURPOSE : +// RETURNS : +// ---------------------------------------------------------------------------- +bool wxSaveBitmap( + wxChar *filename, + wxBitmap *bitmap, + wxPalette *colourmap) { - HPALETTE hPalette = 0; - if (colourmap) - hPalette = (HPALETTE) colourmap->GetHPALETTE(); - - HANDLE dibHandle = wxBitmapToDIB((HBITMAP) bitmap->GetHBITMAP(), hPalette); - if (dibHandle) - { - bool success = (WriteDIB(filename, dibHandle) != 0); - GlobalFree(dibHandle); - return success; - } - else return FALSE; + HPALETTE hPalette = 0; + if (colourmap) + hPalette = (HPALETTE) colourmap->GetHPALETTE(); + + HANDLE dibHandle = wxBitmapToDIB((HBITMAP) bitmap->GetHBITMAP(), hPalette); + if (dibHandle) + { + bool success = (WriteDIB(filename, dibHandle) != 0); + GlobalFree(dibHandle); + return success; + } + else return FALSE; } -- 2.45.2