changes_since28.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: changes_since28.h
  3. // Purpose: topic overview
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-05-08
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. /**
  9. @page overview_changes_since28 Changes Since wxWidgets 2.8
  10. This topic describes backwards-incompatible changes in wxWidgets 3.0 compared
  11. to the last stable release and is very important to read if you are updating
  12. from the 2.8 or an older version. And even if you hadn't used any previous
  13. version of wxWidgets and are starting directly with 3.0, it can still be useful
  14. to have at least a quick look at it just to know that some of the older
  15. examples and tutorials may not be applicable any more to wxWidgets 3.0.
  16. The incompatible changes can be grouped into the following categories:
  17. @li @ref overview_changes_unicode
  18. @li @ref overview_changes_other
  19. <hr>
  20. @section overview_changes_unicode Unicode-related Changes
  21. If you used Unicode build of wxWidgets 2.8 or previous version, please read
  22. @ref overview_unicode for the details about how the API changed in 3.0 as a lot
  23. of the information which was correct before doesn't apply any longer.
  24. For example, the notorious (due to the confusion they created) macros @c wxT()
  25. and @c _T() are not needed at all any longer. Basically, you can remove them
  26. from any code which used them. On the other hand, there is no particular harm
  27. in leaving them neither as the code will still compile and work correctly --
  28. you only need to remove them if you think that your code looks tidier without
  29. them. You also don't need to use @c wxChar any longer but can directly use the
  30. standard @c wchar_t type even if, again, @c wxChar continues to work.
  31. The most serious backwards-incompatible change is related to the change of
  32. return type of wxString::c_str() method: it returns a special proxy object
  33. instead of a simple @c char* or @c wchar_t* now. Because of this, you cannot
  34. pass its result to any standard vararg functions such as @c printf() any more
  35. as described in @ref overview_unicode_compilation_errors. All wxWidgets
  36. functions, such as wxPrintf(), wxLogMessage() &c still work with it, but
  37. passing it to @c printf() will now result in a crash. It is strongly advised to
  38. recompile your code with a compiler warning about passing non-POD objects to
  39. vararg functions, such as g++.
  40. The change of the type of wxString::c_str() can also result in compilation
  41. errors when passing its result to a function overloaded to take both narrow and
  42. wide strings and in this case you must select the version which you really want
  43. to use, e.g.:
  44. @code
  45. void OpenLogFile(const char *filename);
  46. void OpenLogFile(const wchar_t *filename);
  47. wxString s;
  48. OpenLogFile(s); // ERROR: ambiguity
  49. OpenLogFile(s.c_str()); // ERROR: ambiguity
  50. OpenLogFile(s.wx_str()); // OK: function called depends on the build
  51. OpenLogFile(s.mb_str()); // OK: always calls narrow string overload
  52. OpenLogFile(s.wc_str()); // OK: always calls wide string overload
  53. @endcode
  54. A common example of such problem arises with @c std::fstream class constructor
  55. in Microsoft Visual C++ standard library implementation. In addition to a
  56. constructor from @c const @c char * which this class must have, it also
  57. provides a constructor taking a wide character file name. Because of this, code
  58. like the following
  59. @code
  60. #include <fstream>
  61. void MyFunc(const wxString& filename)
  62. {
  63. std::ifstream ifs(filename.c_str());
  64. ...
  65. }
  66. @endcode
  67. does not compile when using Microsoft Visual C++ and needs to be changed to use
  68. mb_str() (which will not work for file names containing Unicode characters,
  69. consider using wxWidgets classes and functions to work with such file names as
  70. they are not supported by standard C++ library).
  71. The other class of incompatible changes is due to modifying some virtual
  72. methods to use @c wxString parameters instead of @c const @c wxChar* ones to
  73. make them accept both narrow and wide strings. This is not a problem if you
  74. simply call these functions but you need to change the signature of the derived
  75. class versions if you override them as otherwise they wouldn't be called any
  76. more. Again, the best way to ensure that this problem doesn't arise is to
  77. rebuild your code using a compiler which warns about function signature
  78. mismatch (you can use @c -Woverloaded-virtual g++ option).
  79. Finally, a few structure fields, notable @c wxCmdLineEntryDesc::shortName,
  80. @c longName and @c description fields have been changed to be of type @c const
  81. @c char* instead of @c const @c wxChar* so you will need to remove @c wxT() or
  82. @c _T() if you used it with their initializers.
  83. @section overview_changes_other Miscellaneous Other Changes
  84. - Default location of wxFileConfig files has changed under Windows, you will
  85. need to update your code if you access these files directly.
  86. - wxWindow::IsEnabled() now returns false if a window parent (and not
  87. necessarily the window itself) is disabled, new function IsThisEnabled()
  88. with the same behaviour as old IsEnabled() was added.
  89. - Generating wxNavigationKeyEvent events doesn't work any more under wxGTK (and
  90. other platforms in the future), use wxWindow::Navigate() or NavigateIn()
  91. instead.
  92. - Sizers distribute only the extra space between the stretchable items
  93. according to their proportions and not all available space. We believe the
  94. new behaviour corresponds better to user expectations but if you did rely
  95. on the old behaviour you will have to update your code to set the minimal
  96. sizes of the sizer items to be in the same proportion as the items
  97. proportions to return to the old behaviour.
  98. - wxWindow::Freeze/Thaw() are not virtual any more, if you overrode them in
  99. your code you need to override DoFreeze/Thaw() instead now.
  100. - wxCalendarCtrl has native implementation in wxGTK, but it has less features
  101. than the generic one. The native implementation is used by default, but you
  102. can still use wxGenericCalendarCtrl instead of wxCalendarCtrl in your code if
  103. you need the extra features.
  104. - wxDocument::FileHistoryLoad() and wxFileHistory::Load() now take const
  105. reference to wxConfigBase argument and not just a reference, please update
  106. your code if you overrode these functions and change the functions in the
  107. derived classes to use const reference as well.
  108. - Calling wxConfig::Write() with an enum value will fail to compile because
  109. wxConfig now tries to convert all unknown types to wxString automatically
  110. using wxToString() function.
  111. The simplest solution is to cast the enum value to int, e.g.
  112. @code
  113. enum Colour { Red, Green, Blue };
  114. wxConfig conf;
  115. conf.Write("MyFavouriteColour", Red); // ERROR: no match
  116. conf.Write("MyFavouriteColour", int(Red)); // OK
  117. @endcode
  118. Another possibility which exists now is to provide an overload of
  119. wxToString() (and wxFromString()) for your own type, e.g.
  120. @code
  121. wxString wxToString(Colour col)
  122. {
  123. return col == Red ? "R" : col == Green ? "G" : "B";
  124. }
  125. bool wxFromString(const wxString& s, Colour* col)
  126. {
  127. if ( s.length() != 1 )
  128. return false;
  129. switch ( s[0].GetValue() )
  130. {
  131. case 'R': *col = Red; return true;
  132. case 'G': *col = Green; return true;
  133. case 'B': *col = Blue; return true;
  134. }
  135. return false;
  136. }
  137. @endcode
  138. Of course, this will change the format of the wxConfig output which may be
  139. undesirable.
  140. - wxTE_AUTO_SCROLL style is deprecated as it's always on by default anyhow in
  141. the ports which support it so you should simply remove any mentions of it
  142. from your code.
  143. - If you use wxScrolled<T>::SetTargetWindow() you must override
  144. wxScrolled<T>::GetSizeAvailableForScrollTarget() method to compute the size
  145. available for the scroll target as function of the main window size, please
  146. see the documentation of this method for more details.
  147. - Signature of wxDataViewCustomRenderer::StartDrag() virtual method changed.
  148. You will need to change it in your derived renderer class too if you override
  149. it.
  150. - wxDataViewCustomRenderer::Activate() and
  151. wxDataViewCustomRenderer::LeftClick() were replaced with the new
  152. wxDataViewCustomRenderer::ActivateCell() method. You will need to change it
  153. in your derived renderer class accordingly.
  154. */