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