WxExtLib - WxMisc.h
00001: // -*- c++ -*-
00002: /*
00003: -------------------------------------------------------------------------
00004: This file is part of WxWidgetsExtensions library.
00005: -------------------------------------------------------------------------
00006:
00007: WxExtLib (WxWidgetsExtensions) library
00008: -----------------------------
00009:
00010: COPYRIGHT NOTICE:
00011:
00012: WxExtLib library Copyright (c) 2003-2007 Daniel Käps
00013:
00014: The WxWidgetsExtensions library and associated documentation files (the
00015: "Software") is provided "AS IS". The author(s) disclaim all
00016: warranties, expressed or implied, including, without limitation, the
00017: warranties of merchantability and of fitness for any purpose. The
00018: author(s) assume no liability for direct, indirect, incidental,
00019: special, exemplary, or consequential damages, which may result from
00020: the use of or other dealings in the Software, even if advised of the
00021: possibility of such damage.
00022:
00023: Permission is hereby granted, free of charge, to any person obtaining
00024: a copy of this Software, to deal in the Software without restriction,
00025: including without limitation the rights to use, copy, modify, merge,
00026: publish, distribute, sublicense, and/or sell copies of the Software,
00027: and to permit persons to whom the Software is furnished to do so,
00028: subject to the following conditions:
00029:
00030: 1. The origin of this source code must not be misrepresented.
00031: 2. Altered versions must be plainly marked as such and must not be
00032: misrepresented as being the original source.
00033: 3. This Copyright notice may not be removed or altered from any
00034: source or altered source distribution.
00035:
00036: End of WxExtLib library Copyright Notice
00037:
00038: -------------------------------------------------------------------------
00039: */
00040:
00041: #ifndef _INCLUDED_WxMisc_h
00042: #define _INCLUDED_WxMisc_h
00043:
00044: #if defined(__GNUG__) && (!defined(__APPLE__)) && (!defined(M_NoPragmaInterface))
00045: # pragma interface "WxMisc.h"
00046: #endif
00047:
00048: #include "WxExtLibConfig.h"
00049:
00050: #include <wx/defs.h>
00051:
00052: #ifndef WX_PRECOMP
00053: # include <wx/longlong.h>
00054: # if wxUSE_GUI
00055: # include <wx/gdicmn.h>
00056: # endif
00057: # include <wx/dynarray.h>
00058: # if wxUSE_GUI
00059: # include <wx/event.h>
00060: // HACK to avoid error "base class `wxWindow' has incomplete type": include
00061: // something which includes the necessary header files
00062: # include <wx/stattext.h>
00063: # endif
00064: #ifndef M_MinimalTimeInterval_UseGetTickCount
00065: # include <wx/timer.h>
00066: #endif
00067: #endif
00068:
00069: #if wxUSE_GUI
00070: # include <wx/image.h>
00071: #endif
00072:
00073: #include <wx/datetime.h>
00074:
00075: #if wxUSE_GUI
00076: # include <wx/html/htmltag.h>
00077: # include <wx/html/htmlwin.h>
00078: # include <wx/textctrl.h>
00079:
00080: # include <wx/brush.h> // for class definition of wxBrush
00081: # include <wx/dcclient.h>
00082: #endif // wxUSE_GUI
00083:
00084: #if defined(__WXMSW__)
00085: # include <windows.h> // WARN may not be the right include place here
00086: // # include <wx/msw/dibutils.h> // commented out for wxWindows 2.5.2
00087:
00088: #if wxUSE_GUI
00089: // NOTE
00090: // for wxWindows 2.5.2, dibutils.h disappeared so we provide an own
00091: // HDIB definition (now called WXHDIB for consistency with WXHWND etc.)
00092: typedef HGLOBAL WXHDIB;
00093: #endif // wxUSE_GUI
00094:
00095: #endif
00096:
00097: // wxMessageFormatter/wxFormat/wxFormatMessage has been moved into
00098: // extra header and source file
00099: #include "WxMessageFormat.h"
00100:
00101: //-------------------------------------------------------------------------
00102:
00103: #ifndef WX_DEFINE_ARRAY_PTR
00104: // under wxWindows 2.5.2, WX_DEFINE_ARRAY_PTR should be used, but it
00105: // doesn't seem to be available under wxWindows 2.4.1
00106: # define WX_DEFINE_ARRAY_PTR WX_DEFINE_ARRAY
00107: #endif
00108:
00109: //-------------------------------------------------------------------------
00110:
00111: WX_DEFINE_ARRAY_PTR(wxObject *, wxObjectPtrArray);
00112:
00113: WX_DEFINE_ARRAY_PTR(wxWindow *, wxWindowPtrArray);
00114:
00115: //-------------------------------------------------------------------------
00116:
00117: #ifndef for_once
00118: #define for_once for (int _for_once___ ## __LINE__=0; _for_once___ ## __LINE__ < 1; ++ _for_once___ ## __LINE__)
00119: #endif
00120:
00121: //-------------------------------------------------------------------------
00122:
00123: #define M_IsDefineExportMagic 1
00124: # include "WxExtLibAliases.h"
00125: #undef M_IsDefineExportMagic
00126:
00127: //-------------------------------------------------------------------------
00128: // wxMinimalTimeInterval
00129: //
00130: // Alternative implementations - and their problems (scope wxWidgets 2.4):
00131: // 0) wxStopWatch - timer overflow (calls wxLongLong.GetLo(),
00132: // uses wxGetLocalTimeMillis(), same problems as with wxGetLocalTimeMillis())
00133: // 1) wxGetLocalTimeMillis() - problem after adjusting the system clock (e.g. under Win98SE),
00134: // but quasi no timer overflow (wxLongLong is used)
00135: // 2) ::GetTickCount() (Win32) - timer overflow after about 48 hours
00136: // 3) ::timeGetTime() (Win32, winmm.lib) - timer overflow after about 48 hours
00137: //
00138: // Now done above where headers are included:
00139: // #ifdef __WIN32__
00140: // # define M_MinimalTimeInterval_UseGetTickCount
00141: // #endif
00142:
00143: class wxMinimalTimeInterval
00144: {
00145: public:
00146: wxMinimalTimeInterval ();
00147:
00148: void setMinimalTimeInterval (long MinimalTimeIntervalMS);
00149:
00150: void setBegin ();
00151: bool check ();
00152:
00153: private:
00154: #ifdef M_MinimalTimeInterval_UseGetTickCount
00155: DWORD m_BeginUpTimeMS;
00156: #else
00157: // wxStopWatch m_StopWatch;
00158: wxLongLong m_BeginTimeMSLongLong;
00159: #endif
00160: long m_MinimalTimeIntervalMS;
00161: bool m_IsInitialized;
00162: };
00163:
00164: //-------------------------------------------------------------------------
00165:
00166: class wxScopedSetToTrue
00167: {
00168: public:
00169: wxScopedSetToTrue (bool & IsLockedRef)
00170: : m_IsLockedRef (IsLockedRef)
00171: {
00172: m_PreviousIsLocked = IsLockedRef;
00173: m_IsLockedRef = true;
00174: }
00175: ~wxScopedSetToTrue ()
00176: {
00177: m_IsLockedRef = m_PreviousIsLocked;
00178: }
00179: private:
00180: bool & m_IsLockedRef;
00181: bool m_PreviousIsLocked;
00182: };
00183:
00184: //-------------------------------------------------------------------------
00185:
00186: extern bool convertStringToLong (const char * CharPtr, long & Long);
00187: extern bool convertStringToLong (const char * CharPtr, unsigned long & Long);
00188:
00189: //-------------------------------------------------------------------------
00190:
00191: // convertAsciiToHtml():
00192: // - useful when generating HTML code: will escape the
00193: // characters '<', '>', '"' (quotation mark) and '&' to their
00194: // HTML entities '<', '>', '"' and '&', respectively
00195: // (If this escaping isn't done, syntactically incorrect HTML code may
00196: // result).
00197: //
00198: // - NOTE translation of ISO 8859-1/Latin-1 specific characters (128-255)
00199: // (e.g. umlauts, accented characters etc.) is not needed if we specify
00200: // the ISO Latin-1 encoding/charset in the HTML header - example:
00201: // <head>
00202: // ...
00203: // <meta http-equiv="content-type" content="text/html; charset=iso-8559-1">
00204: // ...
00205: // </head>
00206: // If no charset was specified, possibly the (system) default charset is used.
00207: // Translation of characters (128-255) (for all different charsets) remains
00208: // as a to-do, however.
00209: //
00210: // - EWxAsciiToHtmlFlags:
00211: // - ConvertLeadingSpaces: replace leading space by " " (tab-char is treated as four spaces)
00212: // - ConvertAllSpaces: replace any space by " " (tab-char is treated as four spaces)
00213: //
00214: // - IsTranslateNewlines: replace newline char (LF) with "<br>" (HTML line break tag)
00215: enum EWxAsciiToHtmlFlags
00216: {
00217: wxAsciiToHtml_ConvertLeadingSpaces = 0x0001,
00218: wxAsciiToHtml_ConvertAllSpaces = 0x0002
00219: };
00220:
00221: extern void convertAsciiToHtml (const char * AsciiCharPtr, wxString & HtmlString,
00222: bool IsTranslateNewlines = false,
00223: long WxAsciiToHtmlFlags = 0);
00224: extern wxString convertAsciiToHtml (const char * AsciiStringCharPtr,
00225: bool IsTranslateNewlines = false,
00226: long WxAsciiToHtmlFlags = 0);
00227:
00228: extern wxString formatColourToHtmlParam (const wxColour & Colour);
00229:
00230: //-------------------------------------------------------------------------
00231:
00232: // get double parameter independent of the locale setting(for restrictions, see
00233: // comments in the implementation of parseDoubleFromAnyLocaleString())
00234: extern bool getHtmlTagParamAsDouble (const wxHtmlTag & HtmlTag,
00235: const wxString & ParamNameString, double * Double);
00236:
00237: // parseDoubleFromAnyLocaleString():
00238: // - get double from a string in current locale or C locale (this is possibly
00239: // useful if both variants were mixed for whatever reason)
00240: // Restrictions:
00241: // - currently only accepts ',' or '.' as decimal point separator character
00242: // - currently no thousand-separator is supported
00243: // - for details, see comments in the implementation of the function
00244: // TODO:
00245: // - make a test print of known double value to determine the decimal point
00246: // character for the current locale
00247: // - rename the function - the name parseDoubleFromAnyLocaleString() is wrong
00248: extern bool parseDoubleFromAnyLocaleString (const wxString & InputValueString, double * Double);
00249:
00250: //-------------------------------------------------------------------------
00251:
00252: // locale-dependent number formatting/parsing general problems:
00253: // - string 2.345 is not the same number in different locales: in English
00254: // this is a 2 and 0.345 fractional part, while in German and some other
00255: // European countries it could be 2345 (with grouping character point to
00256: // separate the thousand part)
00257: // - likewise, interpretation of 2,345 depends on locales
00258: // - used scanf() may not interpret what printf() has printed (e.g. if
00259: // scanf() and printf() use different libraries interpreting locale settings
00260: // differently)
00261: // - there seems to be no (generally available) OS or standard library function
00262: // to determine what the used grouping and decimal point characters are
00263: // - this is solved by using test data, which works at least for some or
00264: // most western country locales
00265: // - under certain circumstances it is desireable to force use of a certain
00266: // notation, even if user has set up environment variables or configured the
00267: // system to use a specific notation
00268: // - using environment variables to switch formatting behavior seems to be
00269: // clumsy (if this works at all) and is probably not thread-safe
00270:
00271: // wxNumberFormatOptions
00272: // - contain desired number format
00273: class wxNumberFormatOptions
00274: {
00275: public:
00276: wxNumberFormatOptions ();
00277: wxNumberFormatOptions (int GroupSize, char GroupSeparatorChar,
00278: char DecimalSeparatorChar);
00279: void set (int GroupSize, char GroupSeparatorChar, char DecimalSeparatorChar);
00280:
00281: int m_GroupSize;
00282: char m_GroupSeparatorChar;
00283: char m_DecimalSeparatorChar;
00284: };
00285:
00286: //-------------------------------------------------------------------------
00287:
00288: // wxNumberFormattingInternals:
00289: // - contain information internally used
00290: // - to avoid sample formatting for each call to formatDouble() etc.,
00291: // a pointer to an object of this class may be given as argument to
00292: // formatDouble()
00293: class wxNumberFormattingInternals
00294: {
00295: public:
00296: wxNumberFormattingInternals();
00297:
00298: bool m_IsOkay;
00299: // values used by the standard-library printf() function
00300: char m_DecimalSeparatorChar;
00301: };
00302:
00303: //-------------------------------------------------------------------------
00304:
00305: // detectNumberFormattingInternals():
00306: // - currently can only detect either point ('.') or comma (',') as
00307: // decimal separator characters
00308: extern void detectNumberFormattingInternals(wxNumberFormattingInternals * NumberFormattingInternals);
00309:
00310: // formatLong()/formatDouble()/formatNumberStringWithGrouping():
00311: // todo:
00312: // - HTML formatting (e.g. exponential display with superscript)
00313: // - alignment to decimal separator is changed because of inserted grouping
00314: // characters
00315: // - split off into length determination and string modification function
00316: // and make it work with simple C-strings to be able to avoid heap memory
00317: // usage of wxString for applications where performance is important
00318: // - NumberFormattingInternals() could be made a thread-local variable
00319: // - add support for grouping with hexadecimal digits (also see C99 %a
00320: // floating-point hexadecimal conversion)
00321: // - add parseDouble(), parseLong() that can deal with grouping characters
00322:
00323: extern void formatLong (const wxString & FormatString,
00324: wxNumberFormatOptions & NumberFormatOptions,
00325: long Long,
00326: wxString & String,
00327: wxNumberFormattingInternals * NumberFormattingInternals = NULL);
00328:
00329: extern void formatDouble (const wxString & FormatString,
00330: wxNumberFormatOptions & NumberFormatOptions,
00331: double Double,
00332: wxString & String,
00333: wxNumberFormattingInternals * NumberFormattingInternals = NULL);
00334:
00335: // formatNumberStringWithGrouping()
00336: // - insertion of grouping characters and decimal separator replacement is
00337: // only done on the first detected sequence of digits,
00338: // e.g. "123456.78 789012.34" -> "123.456,78 789012.34"
00339: extern void formatNumberStringWithGrouping (const wxString & NumberString,
00340: wxNumberFormatOptions & NumberFormatOptions,
00341: wxString & String,
00342: wxNumberFormattingInternals * NumberFormattingInternals);
00343:
00344: // test function checking a few sample values to see if formatting
00345: // works as expected
00346: extern bool testNumberFormat();
00347:
00348: //-------------------------------------------------------------------------
00349:
00350: // DEF MonthIndex starts from 1, _not_ 0!
00351: extern wxDateTime::Month getMonthFromMonthIndex (int MonthIndex);
00352: // DEF returned month index starts from 1, _not_ 0!
00353: extern int getMonthIndexFromMonth (wxDateTime::Month Month);
00354:
00355: //-------------------------------------------------------------------------
00356:
00357: // getDecomposedDateFormatString()
00358: // - return decomposed format string according to current locale setting
00359: // - example: when called with "%#x", the result may be "%a, %d %B %Y"
00360: // implementation notes:
00361: // - this uses a sample date to infer the decomposed format string
00362: // - (there is no standard or OS specific function for this as it seems)
00363: extern void getDecomposedDateFormatString (const wxString & InputFormatString,
00364: wxString & DecomposedDateFormatString);
00365:
00366: //-------------------------------------------------------------------------
00367:
00368: // formatDate()
00369: // TODO
00370: // - integrate into wxDateTime
00371: extern void formatDate (const wxDateTime & DateTime, wxString & String,
00372: bool IsLongFormat = true);
00373:
00374: /*
00375: use the following fix for a bug in wxDateTime::GetWeekDayName():
00376: // FIX (probably all wxWindows versions, problem verified with 2.4.1, 2.5.2)
00377: // tm.tm_mday = 28; is not good because for wday >= Wed
00378: // the day will become invalid (e.g. 31.11.99) and CallStrftime
00379: // won't return the right thing - so use 21 (seven days before)
00380: // instead
00381: tm.tm_mday = 21;
00382: tm.tm_mon = Nov;
00383: tm.tm_year = 99;
00384: */
00385:
00386: // parseDate()
00387: // - will try to parse date in short, long (alternative) and ISO 8601 date format
00388: // Notes
00389: // - parsing in short date format is tried with 2-digit and 4-digit year
00390: // - parsing in long date format is tried with and without weekday name
00391: // - therefore, five different format strings are tried
00392: // - the short and long (alternative) date format are according the
00393: // the current locale setting
00394: // possible improvements:
00395: // - allow abbreviations for month name and weekday name (could also
00396: // add a flag to allow abbreviations to wxDateTime class)
00397: // - allow 2-digit years in long/alternative format
00398: // - allow spaces to be used (implement in wxDateTime::ParseFormat())
00399: // - check for consistency of weekday with date (weekday
00400: // is parsed but ignored) (fix it in wxDateTime::ParseFormat())
00401: // TODO
00402: // - integrate into wxDateTime
00403: extern bool parseDate (const wxString & String, wxDateTime & DateTime);
00404:
00405: // TODO:
00406: // add support for time and date-time formatting and parsing
00407:
00408: //-------------------------------------------------------------------------
00409:
00410: // parse and format according to format string
00411: // - DateTimeFormatString placeholders: see strftime() description
00412: // - the parse function is very strict and may not allow additional spaces
00413: extern bool parseDateTimeWithFormat (const wxString & InputString, wxDateTime & DateTime,
00414: const wxString & DateTimeFormatString);
00415: extern void formatDateTimeWithFormat (const wxDateTime & DateTime, wxString & String,
00416: const wxString & DateTimeFormatString);
00417:
00418: //-------------------------------------------------------------------------
00419:
00420: // parse and format in simple ISO format (e.g. 2005-05-14 17:05:34)
00421: // - the parse function is very strict and may not allow additional spaces
00422: extern bool parseDateTimeFromISOFormat (const wxString & InputString, wxDateTime & DateTime);
00423: extern void formatDateTimeInISOFormat (const wxDateTime & DateTime, wxString & String);
00424:
00425: //-------------------------------------------------------------------------
00426:
00427: // fits object with ObjectSize extensions into FrameRect and returns
00428: // result into FittedObjectRect. AlignmentFlags can be a combination of
00429: // wxALIGN_CENTER_HORIZONTAL and wxALIGN_CENTER_VERTICAL
00430: extern void fitInside (const wxRect & FrameRect, const wxSize & ObjectSize,
00431: wxRect & FittedObjectRect, int AlignmentFlags);
00432:
00433: //-------------------------------------------------------------------------
00434:
00435: // makePath()
00436: // - concatenate LhsPathString and RhsPathString
00437: // - RhsPathString must be a relative path
00438: // - LhsPathString may have to be an absolute path (currently)
00439: // (if so, this should be extendend to non-absolute paths)
00440: // - Example:
00441: // wxString Path = makePath (InstallPrefix, "data/file.dat");
00442: extern void makePath (const wxString & LhsPathString,
00443: const wxString & RhsPathString,
00444: wxString & ResultPathString,
00445: wxPathFormat LhsPathFormat = wxPATH_NATIVE,
00446: wxPathFormat RhsPathFormat = wxPATH_UNIX,
00447: wxPathFormat ResultPathFormat = wxPATH_NATIVE);
00448: extern wxString makePath (const wxString & LhsPathString,
00449: const wxString & RhsPathString,
00450: wxPathFormat LhsPathFormat = wxPATH_NATIVE,
00451: wxPathFormat RhsPathFormat = wxPATH_UNIX,
00452: wxPathFormat ResultPathFormat = wxPATH_NATIVE);
00453:
00454: extern void makeAbsolutePath (const wxString & RelativeOrAbsolutePathString,
00455: const wxString & ReferenceDirString,
00456: wxString & AbsolutePathString,
00457: wxPathFormat RelativeOrAbsolutePathFormat = wxPATH_NATIVE,
00458: wxPathFormat ReferenceDirFormat = wxPATH_NATIVE,
00459: wxPathFormat AbsolutePathFormat = wxPATH_NATIVE);
00460:
00461: extern wxString makeAbsolutePath (const wxString & RelativeOrAbsolutePathString,
00462: const wxString & ReferenceDirString,
00463: wxPathFormat RelativeOrAbsolutePathFormat = wxPATH_NATIVE,
00464: wxPathFormat ReferenceDirFormat = wxPATH_NATIVE,
00465: wxPathFormat AbsolutePathFormat = wxPATH_NATIVE);
00466:
00467: extern void makeRelativePath (const wxString & RelativeOrAbsolutePathString,
00468: const wxString & ReferenceDirString,
00469: wxString & RelativePathString,
00470: bool IsUseRelativeParentDir = true,
00471: wxPathFormat RelativeOrAbsolutePathFormat = wxPATH_NATIVE,
00472: wxPathFormat ReferenceDirFormat = wxPATH_NATIVE,
00473: wxPathFormat AbsolutePathFormat = wxPATH_NATIVE);
00474:
00475: extern wxString makeRelativePath (const wxString & RelativeOrAbsolutePathString,
00476: const wxString & ReferenceDirString,
00477: bool IsUseRelativeParentDir = true,
00478: wxPathFormat RelativeOrAbsolutePathFormat = wxPATH_NATIVE,
00479: wxPathFormat ReferenceDirFormat = wxPATH_NATIVE,
00480: wxPathFormat RelativePathFormat = wxPATH_NATIVE);
00481:
00482: //-------------------------------------------------------------------------
00483:
00484: // addConcatenatedStrings()
00485: // - concatenates strings from given wxArrayString with specified
00486: // item prefix, item postfix, between-item infix strings
00487: // - adds elements in StringArray to OutputString, i.e. OutputString
00488: // is not deleted before
00489: extern void addConcatenatedStrings (const wxArrayString & StringArray,
00490: wxString & OutputString,
00491: const wxString & ElementPrefix = wxEmptyString,
00492: const wxString & ElementPostfix = wxEmptyString,
00493: const wxString & Infix = wxEmptyString);
00494:
00495: //-------------------------------------------------------------------------
00496:
00497: extern const char * wxGetIdTranslation(const char * MessageIdentCharPtr, const char * DefaultCharPtr);
00498:
00499: //-------------------------------------------------------------------------
00500:
00501: // wxGetCatalogMetaData()
00502: // - return NULL if key is not found, otherwise returns meta-data value
00503: // (translation)
00504: // - syntax for meta-data keys could be e.g. (so it can be distinguished
00505: // from normal keys/translations)
00506: // {meta:Scope:Key}
00507: const char * wxGetCatalogMetaData(const char * MessageIdentCharPtr);
00508:
00509: //-------------------------------------------------------------------------
00510:
00511: class wxLocale;
00512:
00513: // wxCatalogAddManag
00514: // - generate appropriate error messages if loading one or more catalogs
00515: // fails
00516: // - calls to addCatalog(), addCatalogWithVersionCheck() are ignored
00517: // if associated locale doesn't have a language set (or used language
00518: // could not be determined)
00519: // - reduce chances of forgotten catalog updates
00520: // - simple support for catalog-version-numbers:
00521: // - avoid accidental use of outdated catalogs by a new program version,
00522: // which is important, because "wrong" printf() format strings may
00523: // cause program crashs
00524: // - meta data version entry syntax: {meta:CATALOG-NAME:VERSION-IDENT}
00525: // - example: for a call to
00526: // addCatalogWithVersionCheck ("WxExtLib", "0.82.0003");
00527: // the following entry is expected:
00528: // {meta:WxExtLib:VersionIdent} having value 0.82.0003
00529: // - warning:
00530: // With the used meta-data version entry scheme, a wrong catalog
00531: // version can be detected only after the catalog has been loaded,
00532: // so possibly the wrong catalog is used nevertheless (and there
00533: // seems to be no way to remove a catalog from memory again).
00534: // For certains applications it may be preferable to terminate
00535: // the program soon in case of catalog version mismatch.
00536: class wxCatalogAddManag
00537: {
00538: public:
00539: wxCatalogAddManag();
00540: void init();
00541:
00542: // set locale to be used for calling AddCatalog()
00543: void setLocale (wxLocale * Locale);
00544:
00545: // addCatalog(), addCatalogWithVersionCheck()
00546: // - collects/appends error messages to m_MessageString, which
00547: // later can be obtained by calling getMessage()
00548: // - the request to add a catalog is ignored (with no error)
00549: // if no language is set for the associated locale (or if
00550: // used language could not be determined)
00551: bool addCatalog (const wxString & CatalogName);
00552: bool addCatalogWithVersionCheck (const wxString & CatalogName,
00553: const wxString & RequiredVersionString);
00554:
00555: // getIsError()
00556: // - indicate if any catalog could not be loaded with specified
00557: // version (or any version, if version is unspecified)
00558: bool getIsError();
00559:
00560: // getMessage()
00561: // - message returns language name used for specified locale
00562: // and accepted vs. encountered catalog version numbers
00563: bool getMessage (wxString & MessageString);
00564:
00565: protected:
00566: wxLocale * m_Locale;
00567: bool m_IsError;
00568: wxString m_MessageString;
00569: };
00570:
00571: #if 0
00572: extern bool checkCatalogueMetaData (wxString & MessageString,
00573: const char * CatalogueName,
00574: const char * VersionMessageIdentCharPtr,
00575: const char * RequiredVersionString);
00576: #endif
00577:
00578: //-------------------------------------------------------------------------
00579:
00580: // string_local_language(), string_internal_language(), string_no_localization():
00581: // notes on use of macro alias vs. inline function definition:
00582: // - it is not fully clear if should be declared as macro or as function,
00583: // - theoretically, use of function declaration instead of macro would seem
00584: // to be more safe somehow
00585: // - however, use of macro would have the advantage of being able to #undef
00586: // it temporarily if not desired or gives conflicts
00587: // - prefer using #define here, because _<single-char> is often defined as
00588: // macro (e.g. _L in MSVC to add Unicode prefix "L" to string literal)
00589: // - with inline-function declaration, conflicts cannot be detected
00590: // easily (typically confusing error message)
00591: // - with macro definition, compiler may report a meaningful warning (at least
00592: // with a high warning level, or if enable specifically)
00593:
00594: // string_local_language()
00595: // - tag strings as being in 'local' language already
00596: // - helps declaring strings which are already in local language
00597: // for parts of a program/source code which doesn't need to support
00598: // messages in more than one language
00599: // - _L() could be useful for an automated move to message catalogue
00600: // if internationalization is desired at some point in the future
00601: // - comment: sometimes the simple things are the most useful ;)
00602: // - implementation notes:
00603: // - would like to use _L(), but MSVC uses this to make argument a Unicode
00604: // string, so use _R (for Regionalized)
00605: // - don't use functional macro _R(Arg1), because _<single-char> is also used
00606: // as parameter-name in many headers of MSVC 6 STL header files
00607: // #define _R(Arg1) string_local_language(R)
00608: // - alternative would be to do
00609: // inline const char * _R(const char * CharPtr) { return CharPtr; }
00610: // but see above
00611:
00612: inline const char * string_local_language(const char * CharPtr) { return CharPtr; }
00613:
00614: #ifdef _R
00615: # error "cannot define alias _R() for function string_local_language(), because _R is used as macro already"
00616: #endif
00617: // #define _R string_local_language
00618: inline const char * _R(const char * CharPtr) { return CharPtr; }
00619:
00620: // string_internal_language()
00621: // - tag strings as being in internal default (normally English)
00622: // language, but no translation is desired
00623: // - _N() could be useful to tag internal error messages for which
00624: // translation is not required or desired
00625: inline const char * string_internal_language(const char * CharPtr) { return CharPtr; }
00626:
00627: #ifdef _N
00628: # error "cannot define alias _N() for function string_internal_language(), because _N is used as macro already"
00629: #endif
00630: // #define _N string_internal_language
00631: inline const char * _N(const char * CharPtr) { return CharPtr; }
00632:
00633: // string_no_localization()
00634: // - tag strings as being some hard coded string constant
00635: // (not localizable at all)
00636: inline const char * string_no_localization(const char * CharPtr) { return CharPtr; }
00637:
00638: #ifdef _C
00639: # error "cannot define alias _C() for function string_no_localization(), because _C is used as macro already"
00640: #endif
00641: // #define _C string_internal_language
00642: inline const char * _C(const char * CharPtr) { return CharPtr; }
00643:
00644: //-------------------------------------------------------------------------
00645:
00646: // WX_DEFINE_ARRAY_BYTE(unsigned char, wxByteArray);
00647: //
00648: // bool loadFile (const wxString & FileNameString,
00649: // wxByteArray & ByteArray);
00650:
00651: //-------------------------------------------------------------------------
00652:
00653: // NOTE semantics not well defined for Win16: there, some function like
00654: // releaseDataResource() or copying the data block would be required
00655: //
00656: // This function is similar to wxLoadUserResource(), but it is intended
00657: // to handle arbitrary data blocks; not just strings
00658: //
00659: // NOTE the 'ResourceTypeString' parameter must be a normal char pointer
00660: // (not 'const wxString &'), because the RT_* definitions may not
00661: // be pointers to valid memory
00662: extern bool loadDataResource (const wxString & ResourceNameString,
00663: const char * ResourceTypeString,
00664: unsigned char ** DataPtr, size_t * DataSize);
00665:
00666: //-------------------------------------------------------------------------
00667:
00668: extern bool loadImageFromMemory (const unsigned char * ImageData, size_t ImageDataSize,
00669: wxImage & Image);
00670: extern bool loadBitmapFromMemory (const unsigned char * ImageData, size_t ImageDataSize,
00671: wxBitmap ** Bitmap);
00672:
00673: #if defined(__WXMSW__)
00674:
00675: //-------------------------------------------------------------------------
00676: // to put e.g. a PNG type image as it is (raw) into a resource, use e.g.:
00677: // IDR_About RCDATA DISCARDABLE "images/About.png"
00678: // and then just call:
00679: // wxBitmap AboutBitmap;
00680: // loadBitmapFromResource ("IDR_About", & AboutBitmap);
00681: extern bool loadImageFromResource (const wxString & ImageDataResourceNameString,
00682: wxImage & Image);
00683: extern bool loadBitmapFromResource (const wxString & ImageDataResourceNameString,
00684: wxBitmap ** Bitmap);
00685:
00686: #endif // defined(__WXMSW__)
00687:
00688: //-------------------------------------------------------------------------
00689:
00690: #if (M_WxExtLib_IsUseGraphicsHelper == 1)
00691: # if wxUSE_GUI
00692:
00693: bool resizeImageVGrid (const wxImage & InputImage,
00694: wxImage & OutputImage,
00695: int OutputWidth, int OutputHeight);
00696:
00697: # endif
00698: #endif
00699:
00700: //-------------------------------------------------------------------------
00701:
00702: // doTextLineWrap
00703: // - automatic line-break (wrap) using the font selected for the given DC
00704: // - currently, line-break is possible only at character indices where
00705: // the input string contains a space (wxIsspace(char) used)
00706: extern void doTextLineWrap (const wxString & InputString,
00707: int MaxLineWidth,
00708: wxDC & DC,
00709: wxString & ResultString);
00710:
00711: extern void doTextLineWrap (const wxString & InputString,
00712: int MaxLineWidth,
00713: wxWindow * Window,
00714: wxString & ResultString);
00715:
00716: //-------------------------------------------------------------------------
00717:
00718: // wxVerifyWindowPtr()
00719: // - search list/tree of windows recursively, starting from specified
00720: // ParentWindow
00721: // - this realizes a depth-first search, no infinite recursions
00722: // should be possible with windows (tree-like structure),
00723: // unless windows are re-parented while running this function
00724: bool wxVerifyWindowPtr (wxWindow * ParentWindow, wxWindow * SearchedWindow);
00725:
00726: //-------------------------------------------------------------------------
00727:
00728: // wxFocusRestorer
00729: // - todo:
00730: // - optionally use wxVerifyWindowPtr() to make sure focus
00731: // window is still there (needs to specify or find the top-most parent
00732: // window first)
00733: // - also check that window is still enabled
00734: class wxFocusRestorer
00735: {
00736: public:
00737: wxFocusRestorer ();
00738: ~wxFocusRestorer ();
00739: private:
00740: wxWindow * m_OldFocusWindow;
00741: };
00742:
00743: //-------------------------------------------------------------------------
00744:
00745: // wxMultiLineText:
00746: // - use best suited control for output of possibly longer texts
00747: // (selected control depends on the used platform)
00748: // - control implementations that can be used are wxTextCtrl and wxHtmlWindow
00749: // - on platforms where wxTextCtrl doesn't support wrapping of long lines,
00750: // doTextLineWrap() is called automatically when calling setText()
00751: // Rationale:
00752: // - wxTextCtrl is under some platforms quite restricted:
00753: // - may not support wrapping of long lines (situation will change with
00754: // wxWindows 2.6.0)
00755: // - may not support setting background and text colour
00756: // - under Lesstif: may not support setting a different font or font size
00757: // - may not support copying to clipboard (copying to clipboard works
00758: // for Motif/Lesstif, MSW, GTK)
00759: // - wxHtmlWindow has everywhere the same functionality, but also
00760: // has some restrictions:
00761: // - copying to clipboard is not possible (situation will change with
00762: // wxWindows 2.6.0)
00763: // - probably lower performance than wxTextCtrl
00764: // (- might not have been compiled into the wxWindows library)
00765: class wxMultiLineText
00766: {
00767: public:
00768: enum EMultiLineTextStyle
00769: {
00770: wxFORCE_TEXTCTRL = 0x0001,
00771: wxFORCE_HTMLWINDOW = 0x0002,
00772:
00773: wxHTML_MODE = 0x0010
00774: };
00775:
00776: wxMultiLineText ();
00777: // CtrlStyle can be: wxBORDER_NONE, wxSIMPLE_BORDER, wxSUNKEN_BORDER
00778: void create (wxWindow * ParentWindow,
00779: int WindowIdent,
00780: int CtrlStyle,
00781: const wxSize & MinSize,
00782: int MultiLineTextStyle = 0);
00783:
00784: // wxMultiLineText::getWindow() -> SetBackgroundColour()/SetForegroundColour()
00785: // may be used _before_ calling setText() is used - for wxHtmlWindow, suitable HTML
00786: // code is generated to use those colors)
00787: // - if the wxHTML_MODE flag is specified, String must be in HTML
00788: // (but without the <html>, <body> tags - they are added automatically)
00789: void setText (const wxString & String);
00790: wxString getHtmlTextString ();
00791:
00792: wxWindow * getWindow ();
00793: wxTextCtrl * getTextCtrl ();
00794: wxStaticText * getStaticText ();
00795: wxHtmlWindow * getHtmlWindow ();
00796:
00797: void setTextCtrl (wxTextCtrl * TextCtrl, int MultiLineTextStyle = 0);
00798: void getStaticText (wxStaticText * StaticText, int MultiLineTextStyle = 0);
00799: void setHtmlWindow (wxHtmlWindow * HtmlWindow, int MultiLineTextStyle = 0);
00800:
00801: private:
00802: long m_MultiLineTextStyle;
00803:
00804: wxTextCtrl * m_TextCtrl;
00805: wxStaticText * m_StaticText; // never used - may not support scroll bar
00806: wxHtmlWindow * m_HtmlWindow;
00807: wxString m_HtmlTextString; // used only if type is wxHtmlWindow
00808: };
00809:
00810: //-------------------------------------------------------------------------
00811:
00812: class wxTransparentStaticText : public wxStaticText
00813: {
00814: public:
00815: enum ETransparentStaticTextFlags
00816: {
00817: // not really transparent :)
00818: IsOpaque = 0x0001,
00819:
00820: DefaultFlags = 0
00821: };
00822:
00823: wxTransparentStaticText();
00824: wxTransparentStaticText(wxWindow * ParentWindow,
00825: wxWindowID ControlIdent,
00826: const wxString& LabelString,
00827: const wxPoint& Position = wxDefaultPosition,
00828: const wxSize& Size = wxDefaultSize,
00829: long Style = 0,
00830: ETransparentStaticTextFlags Flags = DefaultFlags,
00831: const wxString& Name = "TransparentStaticTextControl")
00832: {
00833: Create(ParentWindow, ControlIdent, LabelString, Position, Size, Style, Flags, Name);
00834: }
00835:
00836: bool Create(wxWindow * ParentWindow,
00837: wxWindowID ControlIdent,
00838: const wxString& LabelString,
00839: const wxPoint& Position = wxDefaultPosition,
00840: const wxSize& Size = wxDefaultSize,
00841: long Style = 0,
00842: ETransparentStaticTextFlags Flags = DefaultFlags,
00843: const wxString& Name = "TransparentStaticTextControl");
00844:
00845: void OnEraseBackground (wxEraseEvent & EraseEvent);
00846: void OnPaint (wxPaintEvent & PaintEvent);
00847:
00848: protected:
00849: ETransparentStaticTextFlags m_TransparentStaticTextFlags;
00850:
00851: private:
00852: DECLARE_DYNAMIC_CLASS (wxTransparentStaticText)
00853: DECLARE_EVENT_TABLE()
00854: };
00855:
00856: //-------------------------------------------------------------------------
00857:
00858: // wxColourBarWindow:
00859: // - a control/rectangle filled with the specified colour
00860: // - the base class used has been switched from wxWindow to wxPanel,
00861: // because if a sizer and controls are placed "onto" the wxColourBarWindow,
00862: // sizing of the sizer doesn't seem to work correctly if base class is
00863: // just wxWindow
00864: class wxColourBarWindow : public wxPanel
00865: {
00866: public:
00867: wxColourBarWindow ();
00868: wxColourBarWindow (wxWindow * ParentWindow, int ControlIdent,
00869: const wxPoint & Position = wxDefaultPosition,
00870: const wxSize & Size = wxDefaultSize,
00871: long Style = wxTAB_TRAVERSAL | wxNO_BORDER, const wxString& Name = wxPanelNameStr);
00872: wxColourBarWindow (wxWindow * ParentWindow, int ControlIdent,
00873: const wxColour & Colour,
00874: const wxPoint & Position = wxDefaultPosition,
00875: const wxSize & Size = wxDefaultSize,
00876: long Style = wxTAB_TRAVERSAL | wxNO_BORDER, const wxString& Name = wxPanelNameStr);
00877:
00878: void setBrush (const wxBrush & Brush);
00879: void setPen (const wxPen & Pen);
00880: void setRoundedCornerRadius (double RoundedCornerRadius = 2.);
00881:
00882: void OnEraseBackground (wxEraseEvent & EraseEvent);
00883: void OnPaint (wxPaintEvent & PaintEvent);
00884:
00885: private:
00886: wxBrush m_Brush;
00887: wxPen m_Pen;
00888: double m_RoundedCornerRadius;
00889:
00890: DECLARE_DYNAMIC_CLASS (wxColourBarWindow)
00891: DECLARE_EVENT_TABLE()
00892: };
00893:
00894: //-------------------------------------------------------------------------
00895:
00896: #if (M_WxExtLib_IsUseGraphicsHelper == 1)
00897:
00898: // wxScaledImageWindow:
00899: // - a control/rectangle filled with the specified colour
00900: // - the base class used is wxPanel (see note in wxColourBarWindow)
00901: // - requires resizeImageVGrid() from GraphicsHelper (GraphicsMisc.h)
00902: class wxScaledImageWindow : public wxPanel
00903: {
00904: public:
00905: wxScaledImageWindow ();
00906: wxScaledImageWindow (wxWindow * ParentWindow, int ControlIdent,
00907: const wxPoint & Position = wxDefaultPosition,
00908: const wxSize & Size = wxDefaultSize,
00909: long Style = wxTAB_TRAVERSAL | wxNO_BORDER, const wxString& Name = wxPanelNameStr);
00910: wxScaledImageWindow (wxWindow * ParentWindow, int ControlIdent,
00911: const wxImage & Image,
00912: const wxPoint & Position = wxDefaultPosition,
00913: const wxSize & Size = wxDefaultSize,
00914: long Style = wxTAB_TRAVERSAL | wxNO_BORDER, const wxString& Name = wxPanelNameStr);
00915:
00916: void setImage (const wxImage & Image);
00917:
00918: void OnEraseBackground (wxEraseEvent & EraseEvent);
00919: void OnPaint (wxPaintEvent & PaintEvent);
00920:
00921: private:
00922: wxImage m_OriginalImage;
00923:
00924: bool m_IsCacheOkay;
00925: wxRect m_PreviousClientRect;
00926: wxBitmap m_ScaledBitmap;
00927:
00928: DECLARE_DYNAMIC_CLASS (wxScaledImageWindow)
00929: DECLARE_EVENT_TABLE()
00930: };
00931:
00932: #endif
00933:
00934: //-------------------------------------------------------------------------
00935:
00936: class wxStatusMessageTarget;
00937:
00938: // wxItemWindow:
00939: // A control which can be selected and focused. The selection and focus
00940: // states are visualized by drawing colored rectangles around the
00941: // actual item drawing area/rectangle. This kind of selection and focus
00942: // visualization may be useful for e.g. images (which may not look nice
00943: // when inverted, blue-ified etc.).
00944: //
00945: // Note that the focus state is (intentionally) independent of the
00946: // the wxWindow focus.
00947: //
00948: // Currently this class doesn't handle selection and focus state changes
00949: // from input events itself. However, a derived class may define e.g.
00950: // an OnMouseEvent() handler to handle these state changes.
00951: //
00952: class wxItemWindow : public wxWindow
00953: {
00954: public:
00955: wxItemWindow ();
00956: wxItemWindow (wxWindow * ParentWindow, int ControlIdent,
00957: const wxPoint & Position = wxDefaultPosition,
00958: const wxSize & Size = wxDefaultSize,
00959: bool IsSelectable = false, bool IsFocusable = false,
00960: wxStatusMessageTarget * StatusMessageTarget = NULL,
00961: long Style = 0, const wxString& Name = wxPanelNameStr);
00962:
00963: void init ();
00964:
00965: void setFocusedBackgroundBrush (const wxBrush & Brush);
00966:
00967: void OnEraseBackground (wxEraseEvent & EraseEvent);
00968: void OnPaint (wxPaintEvent & PaintEvent);
00969:
00970: virtual void handleItemPaint (wxPaintDC & PaintDC,
00971: const wxRect & ItemRect,
00972: const wxBrush * BackgroundBrush = NULL);
00973:
00974: wxStatusMessageTarget * m_StatusMessageTarget;
00975: bool m_IsSelectable;
00976: bool m_IsSelected;
00977: bool m_IsFocusable;
00978: bool m_IsFocused;
00979: bool m_IsBorder;
00980:
00981: bool m_IsUsingFocusedBackgroundBrush;
00982: wxBrush m_FocusedBackgroundBrush;
00983:
00984: private:
00985: DECLARE_DYNAMIC_CLASS (wxItemWindow)
00986: DECLARE_EVENT_TABLE()
00987: };
00988:
00989: //-------------------------------------------------------------------------
00990:
00991: // NOTE EResolutionIdent is not yet used
00992: enum EResolutionIdent
00993: {
00994: FullResolution,
00995: ThumbnailResolution
00996: };
00997:
00998: #if defined(__WXMSW__)
00999:
01000: // currently MSW only
01001: class wxImageProxy
01002: {
01003: public:
01004: wxImageProxy ();
01005: ~wxImageProxy ();
01006:
01007: virtual void getDIB (EResolutionIdent ResolutionIdent, WXHDIB & DIB) = 0;
01008: virtual void draw (wxDC & DC, int X, int Y, int Width, int Height,
01009: EResolutionIdent ResolutionIdent,
01010: const wxBrush * BackgroundBrush = NULL);
01011:
01012: virtual void updateFromFile (bool IsReadingForced = false) = 0;
01013: virtual void discard ();
01014:
01015: //-------------------------------------------------------------------------
01016: virtual void loadFromFile (const wxString & PathString) = 0;
01017: virtual void freeDIB ();
01018:
01019: WXHDIB m_DIBFromFile;
01020: };
01021:
01022: #endif // defined(__WXMSW__)
01023:
01024:
01025: //-------------------------------------------------------------------------
01026:
01027: #if defined(__WXMSW__)
01028:
01029: // wxBitmapPaintHelper:
01030: // - facilitate dealing with memory DCs under MSW (create a compatible DC,
01031: // automatic deselection of image from DC)
01032: //
01033: // currently MSW only:
01034: class wxBitmapPaintHelper
01035: {
01036: public:
01037: wxBitmapPaintHelper (const wxString & ResourceIdentString);
01038: wxBitmapPaintHelper (const wxString & ResourceIdentString, HDC PaintDCHandle);
01039: wxBitmapPaintHelper (wxBitmap & Bitmap);
01040: wxBitmapPaintHelper (wxBitmap & Bitmap, HDC PaintDCHandle);
01041: wxBitmapPaintHelper (int Width, int Height);
01042: wxBitmapPaintHelper (int Width, int Height, HDC PaintDCHandle);
01043: ~wxBitmapPaintHelper ();
01044:
01045: void createBitmap (int Width, int Height);
01046: void setBitmap (wxBitmap & Bitmap);
01047: void loadBitmap (const wxString & ResourceIdent);
01048: void prepare (HDC PaintDCHandle);
01049: void release ();
01050:
01051: int getWidth ();
01052: int getHeight ();
01053:
01054: wxBitmap m_Bitmap;
01055: wxBitmap * m_BitmapRef;
01056: HDC m_MemoryDCHandle;
01057: HBITMAP m_BitmapHandle;
01058: HBITMAP m_PreviousBitmapHandle;
01059: };
01060:
01061: #endif // defined(__WXMSW__)
01062:
01063: //-------------------------------------------------------------------------
01064:
01065: #if defined(__WXMSW__)
01066:
01067: // DIB only
01068: extern int getActualUsedColorCount (BITMAPINFO * BitmapInfo);
01069: extern void drawDIBFitted (wxDC & WxDC, int X, int Y, int Width, int Height,
01070: WXHDIB DIBHandle,
01071: const wxBrush * BackgroundBrush = NULL);
01072:
01073: #endif // defined(__WXMSW__)
01074:
01075: //-------------------------------------------------------------------------
01076:
01077: // WxBeep
01078: // - emit a beep for about the given number of milli-seconds
01079: extern void WxBeep (int MilliSeconds);
01080:
01081: //-------------------------------------------------------------------------
01082:
01083: // doRotateMirrorCoord() - rotates and mirrors points (x,y) around the
01084: // rotation center whose coordinates determine the mirroring axes
01085: // Notes:
01086: // 1) RotationAngle must be either 0, 90, 180 or 270 - otherwise the
01087: // behavior is undefined
01088: // 2) Vertical mirroring axis is a horizontal line at CentrePoint.y,
01089: // horizontal mirroring axis is a vertical line at CentrePoint.y
01090: // 3) Order of application: mirroring is applied after rotation,
01091: // not before
01092: extern void doRotateMirrorCoord (int RotationAngle,
01093: bool IsHorizontallyMirrored,
01094: bool IsVerticallyMirrored,
01095: const wxPoint & CentrePoint,
01096: const wxPoint & InputPoint,
01097: wxPoint & OutputPoint,
01098: bool IsRotateCenter = false);
01099:
01100: //-------------------------------------------------------------------------
01101:
01102: class wxRotationMirrorState
01103: {
01104: public:
01105: wxRotationMirrorState();
01106: ~wxRotationMirrorState();
01107:
01108: void reset ();
01109:
01110: // maybe just one mirroring axis would be sufficient
01111: void mirror (bool IsHorizontallyMirrored, bool IsVerticallyMirrored);
01112: void rotate (int RotationAngle);
01113: void handleMirrorRotation(int RotationAngle,
01114: bool & IsHorizontallyMirrored,
01115: bool & IsVerticallyMirrored);
01116:
01117: void getNormalizedState (int & RotationAngle,
01118: bool & IsHorizontallyMirrored,
01119: bool & IsVerticallyMirrored);
01120:
01121: void assign (const wxRotationMirrorState & RHSRotationMirrorState);
01122: void subtract (const wxRotationMirrorState & FirstRotationMirrorState,
01123: const wxRotationMirrorState & SecondRotationMirrorState);
01124:
01125: bool m_IsUpdateRequired;
01126:
01127: bool m_IsHorizontallyMirrored;
01128: bool m_IsVerticallyMirrored;
01129: int m_RotationAngle;
01130: };
01131:
01132: //-------------------------------------------------------------------------
01133:
01134: #ifdef M_WxExtLib_IsFilteredDIBEnabled
01135:
01136: // try to forward-declare ImageMagick's image and ExceptionInfo:
01137: extern "C"
01138: {
01139: struct _Image; // wxImageMagick image
01140: struct _ExceptionInfo; // wxImageMagick ExceptionInfo
01141: }
01142:
01143: // WX_DECLARE_EXPORTED_BASEARRAY(char, wxBaseArrayChar);
01144: // _WX_DEFINE_BASEARRAY (char, wxBaseArrayChar);
01145:
01146: // WX_DECLARE_BASEARRAY(unsigned char, wxBaseArrayUChar);
01147: // _WX_DEFINE_BASEARRAY (unsigned char, wxBaseArrayUChar);
01148:
01149: // WARN how will ExportMagic (redefined class, extern keywords)
01150: // interact with this wx-macro?
01151: //
01152: WX_DEFINE_ARRAY_LONG(long, wxFilteredDIBColorPaletteArray);
01153:
01154: #if defined(__WXMSW__)
01155:
01156: // currently DIB only:
01157:
01158: // wxFilteredDIB:
01159: // - input and output image format is DIB
01160: // - filtering may be realized by applying an ImageMagick filter
01161: // - rotation is done in DIB format and must be handled by a derived class
01162: // - wxFilteredDIB will manage required conversions (e.g. convert from a
01163: // palette-based DIB to 32 Bit color ImageMagick if any filter is to
01164: // be applied)
01165: // - for palette-based images, color adjustment is realized by modifying the
01166: // palette in-place which is much faster than modifying all pixels - the
01167: // old palette is stored for a later undo or a new modification
01168: // - image rotation must be 0, 90, 180 or 270 degree - if only the rotation
01169: // angle (or mirroring) has changed since last filtering,
01170: // rotation/mirroring will be made relative to the last result
01171: // (improves performance)
01172: // Notes:
01173: // - ImageMagick's image type also supports palette-based images, but
01174: // many filters will only work for 32 Bit images (or 64 Bit when using
01175: // 16-Bit color channel resolution)
01176: // - linking of the ImageMagick core library (the C-API) is required
01177: // to use wxFilteredDIB
01178: // - the files 'ImageMagickExtensions.{h,c}' are required for DIB <->
01179: // ImageMagick image and color depth conversions
01180: // Todo:
01181: // - implement better color adjustment function
01182: // - implement DIB rotation functions (or look for existing code)
01183: // - check new wxDIB class (new since wxWidgets 2.5.?)
01184: class wxFilteredDIB
01185: {
01186: public:
01187: wxFilteredDIB ();
01188: ~wxFilteredDIB ();
01189:
01190: // color adjustment
01191: // Brightness [-1.0, 1.0], Contrast [-1.0, 1.0]
01192: void setBrightnessContrast (double Brightness, double Contrast);
01193: void setColorAdjustment (double RedGamma, double GreenGamma,
01194: double BlueGamma);
01195: void setInversion (bool IsInverted);
01196:
01197: // palette based color adjustment
01198: // virtual void setPaletteBasedColorAdjustmentEnabled (bool IsEnable);
01199: virtual void rememberOriginalPalette ();
01200: virtual void rememberModifiedPalette ();
01201: virtual void setOriginalPaletteIntoSourceImage ();
01202: virtual void setModifiedPaletteIntoSourceImage ();
01203: bool rememberPalette (WXHDIB DIBHandle,
01204: wxFilteredDIBColorPaletteArray & ColorPaletteByteArray);
01205: bool restorePalette (WXHDIB DIBHandle,
01206: wxFilteredDIBColorPaletteArray & ColorPaletteByteArray);
01207: virtual bool getIsUsePaletteAlienation();
01208: virtual bool applyPaletteAlienation (wxFilteredDIBColorPaletteArray & ColorPaletteByteArray);
01209:
01210: // filtering related
01211: virtual void setIsFilteringModified ();
01212: virtual void setIsImageMagickFilteringRequired (bool IsRequired);
01213:
01214: // rotation and mirroring
01215: virtual void resetRotationMirror ();
01216: virtual void rotate (int RotationAngle);
01217: virtual void mirror (bool IsHorizontallyMirrored, bool IsVerticallyMirrored);
01218:
01219: // setting source image, obtaining result image
01220: virtual void setSourceImage (const WXHDIB & SourceDIBHandle);
01221: virtual void getResultImage (WXHDIB & ResultDIBHandle);
01222: virtual void setIsOwningSourceImage (bool IsOwningSourceImage);
01223: virtual void setIsOwningResultImage (bool IsOwningResultImage);
01224: void freeSourceImage();
01225: void freeResultImage();
01226:
01227: // updating result image
01228: virtual void updateResultImage ();
01229: virtual void handleResultImageChanged ();
01230:
01231: // handler which do actual image modifications/transformations
01232: virtual void applyColorAdjustment (struct _Image ** MagickImagePtrPtr,
01233: struct _ExceptionInfo * exceptionInfo);
01234: virtual void applyImageMagickFiltering (struct _Image ** MagickImagePtrPtr,
01235: struct _ExceptionInfo * exceptionInfo);
01236: virtual void applyImageRotationMirroring (int RotationAngle,
01237: bool IsHorizontallyMirrored,
01238: bool IsVerticallyMirrored,
01239: WXHDIB & InputDIBHandle,
01240: WXHDIB & OutputDIBHandle,
01241: bool & IsNewOutputDIBHandle);
01242:
01243: virtual WXHDIB applyDIBRotation (WXHDIB InputDIBHandle, int RotationAngle) = 0;
01244: virtual WXHDIB applyDIBMirroring (WXHDIB InputDIBHandle, bool IsVertically) = 0;
01245:
01246: protected:
01247: // color adjustment
01248: double m_Brightness;
01249: double m_Contrast;
01250: double m_RedGamma;
01251: double m_GreenGamma;
01252: double m_BlueGamma;
01253: bool m_IsInverted;
01254: bool m_IsColorAdjustmentModified;
01255: void levelGamma (double & Gamma);
01256:
01257: // palette based color adjustment
01258: bool m_IsPaletteBasedColorAdjustmentEnabled;
01259: wxFilteredDIBColorPaletteArray m_OriginalColorPaletteByteArray;
01260: bool m_IsOriginalColorPaletteRemembered;
01261: wxFilteredDIBColorPaletteArray m_ModifiedColorPaletteByteArray;
01262: bool m_IsModifiedColorPaletteRemembered;
01263:
01264: // filtering related
01265: bool m_IsImageMagickFilteringRequired;
01266: bool m_IsFilteringModified;
01267: int m_FilteredDIBBitsPerPixel;
01268:
01269: // rotation and mirroring
01270: wxRotationMirrorState m_PreviousRotationMirrorState;
01271: wxRotationMirrorState m_RotationMirrorState;
01272:
01273: // source image, result image handling
01274: void freeImage (WXHDIB & DIBHandle);
01275: WXHDIB m_SourceDIBHandle;
01276: bool m_IsOwningSourceImage;
01277: WXHDIB m_ResultDIBHandle;
01278: bool m_IsOwningResultImage;
01279: };
01280:
01281: #endif // defined(__WXMSW__)
01282:
01283: #endif
01284:
01285: //-------------------------------------------------------------------------
01286:
01287: // wxChoiceManager:
01288: // - manages selections from a set of source items into
01289: // choice items
01290: class wxChoiceManager
01291: {
01292: public:
01293: wxChoiceManager ();
01294:
01295: // high-level user interface interaction
01296: void OnSelect ();
01297: void OnDeselect ();
01298: void OnClearSelection ();
01299: void OnSourceLeftMouseButton (int SourceItemIndex);
01300: void OnSourceRightMouseButton (int SourceItemIndex);
01301: void OnChoiceLeftMouseButton (int ChoiceItemIndex);
01302: void OnChoiceRightMouseButton (int ChoiceItemIndex);
01303:
01304: //-------------------------------------------------------------------------
01305: // selection and focus managment
01306: // almost all functions accept '-1' as notion of 'no document' or
01307: // 'no item'
01308:
01309: void handleSelection (bool IsNewlyFocused, int ChoiceItemIndex,
01310: int SourceItemIndex);
01311:
01312: void selectIntoChoice (int ChoiceItemIndex, int SourceItemIndex,
01313: bool IsUpdateChoiceView = true);
01314: void deselectFromChoice (int ChoiceItemIndex, bool IsUpdateChoiceView = true);
01315:
01316: // focus management
01317: int getSourceFocus();
01318: void setSourceFocus (int SourceItemIndex);
01319: virtual void updateSourceFocus (int NewFocusedItemIndex, bool IsFocus) = 0;
01320: int getChoiceFocus();
01321: void setChoiceFocus (int ChoiceItemIndex);
01322: virtual void updateChoiceFocus (int NewFocusedItemIndex, bool IsFocus) = 0;
01323:
01324: // this should be kept in sync with m_IsFocused of e.g. wxItemWindow
01325: int m_FocusedChoiceItemIndex;
01326: int m_FocusedSourceItemIndex;
01327:
01328: // selection managment
01329: void redoSelections ();
01330: void setSelection (int SourceItemIndex, bool IsSelect);
01331: virtual void updateSelection (int SourceItemIndex, bool IsSelect) = 0;
01332:
01333: virtual void updateChoiceView () = 0;
01334:
01335: // functions for mapping from item index into document ident or vice
01336: // versa
01337: virtual int getSourceDocument (int SourceItemIndex) = 0;
01338: virtual int getChoiceDocument (int ChoiceItemIndex) = 0;
01339: virtual int getSourceItemCount () = 0;
01340: virtual int getChoiceItemCount () = 0;
01341:
01342: virtual int findSourceItemIndex (int DocumentIdent);
01343: virtual int findChoiceItemIndex (int DocumentIdent);
01344:
01345: virtual void insertChoiceDocument (int DocumentIdent, int ChoiceItemIndex, int Count) = 0;
01346: virtual void setChoiceDocument (int ChoiceItemIndex, int DocumentIdent) = 0;
01347: };
01348:
01349: //-------------------------------------------------------------------------
01350:
01351: typedef wxWindow * (* wxDefaultParentWindowFunc) (wxWindow *);
01352:
01353: // set or get global pointer to wxDefaultParentWindowFunc:
01354: void wxSetGlobalDefaultParentWindowFunc (wxDefaultParentWindowFunc Func);
01355: wxDefaultParentWindowFunc wxGetGlobalDefaultParentWindowFunc ();
01356:
01357: // wxGetDefaultParentWindow():
01358: // - just return ParentWindow if ParentWindow != NULL, or determine
01359: // a default parent window by calling wxGetGlobalDefaultParentWindowFunc
01360: // (if set)
01361: // - note: this function may still return NULL
01362: wxWindow * wxGetDefaultParentWindow (wxWindow * ParentWindow);
01363:
01364: //-------------------------------------------------------------------------
01365:
01366: #define M_IsUndefExportMagic 1
01367: # include "WxExtLibAliases.h"
01368: #undef M_IsUndefExportMagic
01369:
01370: //-------------------------------------------------------------------------
01371:
01372: #endif
01373: