window.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/private/window.h
  3. // Purpose: misc wxWindow helpers
  4. // Author: Vaclav Slavik
  5. // Created: 2010-01-21
  6. // Copyright: (c) 2010 Vaclav Slavik
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_PRIVATE_WINDOW_H_
  10. #define _WX_PRIVATE_WINDOW_H_
  11. #include "wx/gdicmn.h"
  12. namespace wxPrivate
  13. {
  14. // Windows' computes dialog units using average character width over upper-
  15. // and lower-case ASCII alphabet and not using the average character width
  16. // metadata stored in the font; see
  17. // http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
  18. //
  19. // This helper function computes font dimensions in the same way. It works with
  20. // either wxDC or wxWindow argument.
  21. template<typename T>
  22. inline wxSize GetAverageASCIILetterSize(const T& of_what)
  23. {
  24. const wxStringCharType *TEXT_TO_MEASURE =
  25. wxS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
  26. wxSize s = of_what.GetTextExtent(TEXT_TO_MEASURE);
  27. s.x = (s.x / 26 + 1) / 2;
  28. return s;
  29. }
  30. } // namespace wxPrivate
  31. #endif // _WX_PRIVATE_WINDOW_H_