wx-subclass.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "wx-subclass.hpp"
  15. #ifndef WX_PRECOMP
  16. #include <wx/dcclient.h>
  17. #endif
  18. #ifdef _WIN32
  19. #include <wx/fontutil.h>
  20. #define WIN32_MEAN_AND_LEAN
  21. #include <windows.h>
  22. /* copied from the wx windows-specific stuff */
  23. wxFont wxCreateFontFromStockObject2(int index)
  24. {
  25. wxFont font;
  26. HFONT hFont = (HFONT)::GetStockObject(index);
  27. if (hFont) {
  28. LOGFONT lf;
  29. if (::GetObject(hFont, sizeof(LOGFONT), &lf) != 0) {
  30. wxNativeFontInfo info;
  31. info.lf = lf;
  32. #ifdef __WXMICROWIN__
  33. font.Create(info, (WXHFONT)hFont);
  34. #else
  35. font.Create(info);
  36. #endif
  37. } else {
  38. wxFAIL_MSG(wxT("failed to get LOGFONT"));
  39. }
  40. } else {
  41. wxFAIL_MSG(wxT("stock font not found"));
  42. }
  43. return font;
  44. }
  45. #endif
  46. DialogSubclass::DialogSubclass(wxWindow *parent, wxWindowID id,
  47. const wxString &title, const wxPoint &pos, const wxSize &size,
  48. long style, const wxString &name)
  49. : wxDialog(parent, id, title, pos, size, style, name)
  50. {
  51. #ifdef _WIN32
  52. this->SetFont(wxFont(wxCreateFontFromStockObject2(DEFAULT_GUI_FONT)));
  53. #endif
  54. }
  55. WindowSubclass::WindowSubclass(wxWindow* parent, wxWindowID id,
  56. const wxString& title, const wxPoint& pos, const wxSize& size,
  57. long style)
  58. : wxFrame(parent, id, title, pos, size, style)
  59. {
  60. #ifdef _WIN32
  61. this->SetFont(wxFont(wxCreateFontFromStockObject2(DEFAULT_GUI_FONT)));
  62. #endif
  63. }
  64. ListCtrlFixed::ListCtrlFixed(wxWindow *parent,
  65. wxWindowID id,
  66. const wxPoint& pos,
  67. const wxSize& size,
  68. long style,
  69. const wxValidator& validator,
  70. const wxString& name)
  71. : wxListCtrl(parent, id, pos, size, style, validator, name)
  72. {
  73. m_bestSizeCache.Set(wxDefaultCoord, wxDefaultCoord);
  74. SetInitialSize(size);
  75. }
  76. wxSize ListCtrlFixed::DoGetBestClientSize() const
  77. {
  78. if (!InReportView())
  79. return wxControl::DoGetBestClientSize();
  80. int totalWidth;
  81. wxClientDC dc(const_cast<ListCtrlFixed*>(this));
  82. const int columns = GetColumnCount();
  83. if (HasFlag(wxLC_NO_HEADER) || !columns) {
  84. totalWidth = 50*dc.GetCharWidth();
  85. } else {
  86. totalWidth = 0;
  87. for ( int col = 0; col < columns; col++ )
  88. totalWidth += GetColumnWidth(col);
  89. }
  90. /*
  91. * This is what we're fixing. Some.. very foolish person decided,
  92. * "Oh, let's give this an 'arbitrary' height! How about, let's see,
  93. * I don't know! LET'S USE 10 * FONT HEIGHT!" ..Unfortunately, this
  94. * person basically makes it impossible to use smaller sized list
  95. * views in report mode. It will always become tremendously large in
  96. * size, despite what constraints you originally have set with sizers.
  97. * brilliant job, whoever you are. 10 * character height.. just..
  98. * unbeleivably wow. I am ASTOUNDED.
  99. */
  100. return wxSize(totalWidth, 3*dc.GetCharHeight());
  101. }