Commit Graph

126 Commits

Author SHA1 Message Date
Vadim Zeitlin
bd05aea6c1 Fix stretchable separators in vertical toolbars under MSW
This partially reverts 44d732b8a5 (Use TB_SETBUTTONINFO when updating
stretchable toolbar separators, 2019-02-24) and restores the behaviour
before this commit for the vertical toolbars only, as the new code
doesn't work for them, even though like it seems it should (and we don't
get any error when using it).

Still keep the simpler path for horizontal toolbars, as there doesn't
seem to be any problems with it in this case.
2020-11-15 01:02:09 +01:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Vadim Zeitlin
93c580ccaf Don't mangle ampersands in wxToolBar tooltips under MSW
Preserve the ampersands in the string, which is consistent with wxGTK
behaviour and less surprising than the default behaviour, which creates
mnemonics in the tooltips that are, of course, perfectly useless, as
they can't be activated from keyboard anyhow.

Turn on TTS_NOPREFIX, which is already used by wxToolTip, to fix this.

Closes #18899.
2020-08-22 18:49:25 +02:00
Maarten Bent
e700a02964 Use correct toolbar tool index when determining best size
Closes #18652.

Closes https://github.com/wxWidgets/wxWidgets/pull/1708
2020-01-17 03:04:38 +01:00
Maarten Bent
6878a46725 Prevent spurious debug error messages in wxMSW wxToolBar code
When wxGetTBItemRect() is called on a control tool, it can cause a
TB_GETITEMRECT error message. Swap the if statements around so
wxGetTBItemRect is only called when it is needed.

Closes https://github.com/wxWidgets/wxWidgets/pull/1639
2019-11-07 00:55:46 +01:00
Vadim Zeitlin
059838f5ed Compilation fix for PCH-less build
Include wx/combobox.h as we use wxDynamicCast(wxComboBox).
2019-09-29 23:21:55 +02:00
Maarten Bent
2b41ba2702 Apply review comments 2019-09-29 19:30:39 +02:00
Maarten Bent
0a7c191e27 Fix wxChoice-based control height in wxToolBar on DPI change 2019-09-29 19:30:36 +02:00
Maarten Bent
8bff737438 Support DPI change in wxToolBar
Manually resize the embedded controls and Realize the toolbar again.
2019-09-28 23:37:01 +02:00
Artur Wieczorek
66b798692e Fix deleting "embedded" toolbar from its own event handler
When we create a toolbar from within the event handler of another toolbar several times (so we have a chain of embedded toolbars) and the last toolbar is destroyed, gs_liveToolbar variable is reset in its dtor what prevents from executing the part of code in MSWCommand() for other existing toolbars if they are still in their event handlers too (still executing OnLeftClick() function). This may happen when toolbars are created in the chain of modal dialog boxes.
To prevent this interference between the toolbars from occurring we have to keep track of all of active toolbars in the chain instead of keeping track of only the last one.

Closes #18309.
2019-07-22 18:57:49 +02:00
Maarten Bent
f74d756ca5 Use DPI Aware wxGetSystemMetrics
If no wxWindow is known, use wxTheApp->GetTopWindow().
Also use a wxWindow for all wxSystemSettings::GetMetric calls.
2019-07-15 00:00:18 +02:00
Maarten Bent
94907d3893 Do not limit label width in wxToolBar by control width
This removes irregular behaviour in setting the label of a control. Creating
a control with label now behaves the same as setting or changing the label
later on. And behaves the same as for other tools in the wxToolBar.

Closes https://github.com/wxWidgets/wxWidgets/pull/1289
2019-04-18 16:51:10 +02:00
Vadim Zeitlin
6cc1d63d68 Add a comment to wxToolBar::DoGetBestSize()
No real changes, just explain one of the changes done in the commit
909adbb6bf a bit better.
2019-04-14 18:25:56 +02:00
Vadim Zeitlin
909adbb6bf Use correct separator sizes in MSW wxToolBar best size calculation
Don't assume that all the items (except for the controls) have the same
size in wxToolBar::DoGetBestSize(), this is manifestly not true at least
for the separators and resulted in too much space left over at the end
of the toolbar.
2019-04-07 13:25:25 +02:00
Vadim Zeitlin
0dfe0d0a9c Don't add extra padding in wxMSW wxToolBar best size calculation
DoGetBestSize() mistakenly added extra (half of) padding for each tool
explicitly when the padding is already taken into account of by
GetToolSize() itself, so this resulted in extra space at the end of the
toolbar proportional to the number of buttons in it.
2019-04-05 13:39:31 +02:00
Paul Cornett
90ce6a4334 Remove unused variables 2019-04-04 10:40:45 -07:00
Vadim Zeitlin
b0ad9ccffd Use control current, not best, size in wxMSW wxToolBar layout code
Avoid allocating too much space to the control in the toolbar, it may
have been made smaller than its best size on purpose and, in any case,
we don't resize the control, so it's useless to allocate more space to
it than it's going to use.

See #18294.
2019-03-31 13:39:57 +02:00
Vadim Zeitlin
9cbc1a5fbf Merge branch 'msw-tbar-resize'
Many fixes for wxToolBar (re)sizing in wxMSW, partially addressing
toolbar size changes since the previous wxWidgets versions.

See https://github.com/wxWidgets/wxWidgets/pull/1241

Closes #18294.
2019-03-29 19:16:40 +01:00
Vadim Zeitlin
6b6fee8685 Avoid TB_DELETEBUTTON errors when recreating wxMSW wxToolBar
Reset the number of buttons to skip deleting the old buttons in
wxToolBar::Recreate() as these buttons don't exist any more (having been
created in the old control) and trying to delete them just results in
debug error messages from TB_DELETEBUTTON.
2019-03-29 19:13:45 +01:00
Vadim Zeitlin
876d0f293f Avoid querying wxToolBar size in wxMSW while it's being recreated
Recreating the toolbar tried to offset the new toolbar window being
created by the size of the existing toolbar, when it was set up as the
main frame toolbar. Luckily, this didn't work because getting the size
of a wxWindow without a valid HWND failed, but it resulted in debug
warning messages and was a wrong thing to do in the first place.

Fix this by hiding the old toolbar before destroying it, this suffices
for the parent frame not to use it for the client area calculations.
2019-03-29 19:09:49 +01:00
Vadim Zeitlin
d24f6f7916 Reduce the margins around toolbar controls by half
This wastes less space in the toolbar and looks better and is more
compatible with 3.0 (although not totally so, but this is intentional
as 3.0 didn't use any margins at all, which looked bad).
2019-03-21 14:20:48 +01:00
Vadim Zeitlin
07673fdb97 Fix toolbar size calculations in wxTB_NODIVIDER case
There is no 2px border separating the toolbar from the rest of the
window in this case, so don't overcompensate by accounting for it.
2019-03-21 04:45:49 +01:00
Vadim Zeitlin
50bbfedb31 Rewrite wxToolBar sizing code to avoid TB_AUTOSIZE
This message just seems too weird and unreliable, so get rid of it and
compute the toolbar size entirely on our own, which at the very least
gives predictable and reproducible results and makes GetSize()
consistent with GetBestSize().

The toolbar height doesn't remain exactly the same as before, with 1px
differences here and there, but now the height is the same initially and
after changing the toolbar styles, while previously the height changed
when doing this.
2019-03-09 16:17:53 +01:00
Vadim Zeitlin
b8a5276bc8 Use a symbolic constant for toolbar height adjustment hack value
No real changes, just avoid hard-coding this 3 as it's going to be used
in another place in the upcoming commit.
2019-02-28 23:50:41 +01:00
Vadim Zeitlin
acfd714743 Make toolbar height compatible with previous wx version
Restore the hack with making the toolbars with wxTB_FLAT style 3px less
tall than the value given to them by TB_AUTOSIZE.

There is no real explanation for doing this, this adjustment was added
by 98b9643647 back in 2002 with the
rationale "make flat toolbars look slightly better", but after doing it
for 17 years during which nobody complained about this, we probably
should keep doing it now.
2019-02-28 23:36:18 +01:00
Vadim Zeitlin
fa16db08c1 Remove the extra height hack from wxToolBar::DoGetBestSize()
There doesn't seem to be any good reason to add 3px to the vertical
component of the toolbar best size and it's not clear how can the
original problem be reproduced.

This basically reverts c118d8b06e.
2019-02-28 23:24:40 +01:00
Vadim Zeitlin
1661f277d5 Only use packing in horizontal direction for toolbar controls
Tool packing seems to be relevant only in the major toolbar direction,
i.e. horizontally when the controls are shown, and adding it in vertical
direction too made the toolbar too tall.
2019-02-28 23:23:15 +01:00
Vadim Zeitlin
385ebf2f4a Don't call UpdateSize() unnecessarily at the end of Realize()
SetRows(), called just above in most case, already calls UpdateSize(),
so there is no need to do it again.
2019-02-24 22:37:15 +01:00
Vadim Zeitlin
dc0586aad6 Remove a now unnecessary hack for vertical toolbars
Don't recompute their total fixed size and update them once again in
Realize() as the button heights seem to be just fine even without doing
this.
2019-02-24 22:37:15 +01:00
Vadim Zeitlin
1a79610361 Rewrite wxToolBar resizing logic in wxMSW
wxToolBar handled its size in a very unique way as it waited to be
resized and then set its size correctly from its own WM_SIZE handler.
This was very confusing and, worse, broke a very natural assumption that
after calling SetSize(size) on a window this window does have the
specified size -- which wasn't necessarily the case for wxToolBar,
resulting in problems such as the one in #18294.

The reason for doing it in such weird way is that the native toolbar
control is weird itself and uses a specific message (TB_AUTOSIZE) to
update its size and, moreover, doesn't always do it correctly (notably
for the vertical toolbars). It seems that we can make it work more or
less as wanted if we use TB_SETBUTTONSIZE _after_ TB_AUTOSIZE (why does
it need to be done in this order remains a complete mystery) and if we
correct the width of vertical toolbars in UpdateSize() (which is not
called from WM_SIZE handler but only from Realize() and other methods
modifying the toolbar, so it's not a problem for it to change the size).

The only known problem with this commit known at this time is that
stretchable separators in vertical don't work any longer, it seems that
the size passed to TB_SETBUTTONSIZE is just ignored in this case.
However stretchable toolbar separators are pretty rare nowadays and even
more so in vertical toolbars, so, arguably, this is not a big loss.

Also tweak the layout of the labels for the embedded controls to make
them more similar for the labels used for the normal tools and, notably,
allocate enough space if the label is longer than the control itself.

Closes #18294.
2019-02-24 22:32:22 +01:00
Vadim Zeitlin
7c8ba45705 Reuse helper MSWGetFittingtSizeForControl() in a couple of places
Refactor the code to reuse the same function for determining the size
needed by an embedded control in the toolbar, including its label.
2019-02-24 18:19:49 +01:00
Vadim Zeitlin
c7e8aac70f Explicitly skip expanding stretchable separators in MSW toolbars
When computing the fixed size of MSW toolbars, don't take stretchable
separators into account as this doesn't make sense and so, even if this
doesn't matter currently because the separators still have their
initial, fixed size when total fixed size is computed, but would start
mattering if UpdateStretchableSpacersSize() is ever called before this
is done and it also just makes more sense to skip them here.
2019-02-24 04:03:25 +01:00
Vadim Zeitlin
44d732b8a5 Use TB_SETBUTTONINFO when updating stretchable toolbar separators
This is simpler than TB_DELETEBUTTON followed by TB_INSERTBUTTON and
avoids weird side effects of using the old messages which affect the
toolbar size.

There should be no changes in behaviour with this change.
2019-02-24 03:38:52 +01:00
Vadim Zeitlin
82857cfa9d Add small helper function to wxMSW wxToolBar code
Encapsulate the logic for deciding whether we should show the labels for
the embedded controls or not in a small helper function, to make it
simpler to change it in the future if needed and also to have a single
place to explain why do we do what we do now.

No real changes.
2019-02-24 02:04:55 +01:00
Vadim Zeitlin
4a02b73a6a Use a symbolic constant instead of hardcoded 3
No real changes, just give a name to the constant used for the number of
pixels to leave between an embedded control and its label.
2019-02-23 19:03:51 +01:00
Vadim Zeitlin
44eb96b993 Get rid of unnecessary temporary variable in wxMSW wxToolBar
No real changes, just remove a variable only used once.
2019-02-23 18:38:52 +01:00
Artur Wieczorek
97f73acddb Set HBITMAP and its parameters in one call
To avoid separate calls to SetWidth/Height/Size/Depth functions after calling SetHBITMAP() use newly implemented InitFromHBITMAP() function which allows to set HBITMAP together with its parameters in one call.
2018-09-12 22:02:56 +02:00
Vadim Zeitlin
1417776d33 Make deleting toolbar from its own event handler work again
While it is not guaranteed in general that destroying a window from an
event handler for an event originating from this window itself works, it
did use to work in the case of wxToolBar and its event handlers. However
this stopped working since faffaaae29 as
it added a test using the now deleted object member fields after the
call to the event handler.

To fix this regression without reintroducing the bug fixed by that
commit (see #16762), add an ugly way to check if the toolbar is still
alive after a call to its event handler and do it explicitly after
OnLeftClick() returns.

Closes #17732.
2017-11-04 14:28:38 +01:00
Maarten Bent
f6f72449fe Resolve -Wmisleading-indentation warnings. 2017-02-24 23:37:38 +01:00
Vadim Zeitlin
d15bbcacd2 Merge branch 'rmv_symbols_3' of https://github.com/catalinr/wxWidgets
Remove obsolete mentions of Windows 9x, Windows CE and OS/2.
2017-02-20 17:46:45 +01:00
Václav Slavík
02276c6ebb Fix wxMSW toolbar if using mix of alpha and masks
If the user mixes bitmaps with alpha channel and without it, wxMSW
toolbar rendered the masked bitmap with black background due to changes
in 195df9af7f

In such case, convert bitmaps that don't have an alpha channel into ones
that do so that they are all consistent and can use the same rendering
method.

Fixes #17795.
2017-02-08 14:50:10 +01:00
Václav Slavík
195df9af7f Fix incorrect alpha rendering in wxToolBar (MSW)
wxToolBar::Realize() code for handling bitmaps with alpha channel was
incorrectly blending them with the toolbar’s background color, resulting
in much lighter appearance and broken antialiasing.

Fix it by clearing the composite bitmap to be initially transparent if
bitmaps with alpha channel are used. Doing so uncovered another bug in
how the composite RGBA bitmap was passed to native toolbar control, so
fix that as well.
2017-01-12 17:39:08 +01:00
Vadim Zeitlin
967bdbf994 Use equally-sized buttons in wxMSW horizontal toolbars
Only use TBSTYLE_AUTOSIZE, adjusting each button to the size it really needs,
for the toolbars with wxTB_HORZ_LAYOUT style as they don't have any uniform
button size anyhow.
2016-06-26 18:51:50 +02:00
Artur Wieczorek
1373241f21 Fixed implementation of wxToolBarTool::SetLabel (MSW).
Because label is implemented in the control tool as a separate wxStaticText object which exists only if label is non-empty so we need to handle appropriately also the cases when non-empty label is set to empty and vice versa.
Setting a new label for the button tool with TB_SETBUTTONINFO would require to do some additional actions for other items in the toolbar (manual re-positioning items in the control tools, updating stretchable spacers) so it is easier just to re-create the toolbar with Realize().

See #17567
2016-06-17 23:17:40 +02:00
Dimitri Schoolwerth
54e6f6e7b8 Make a public free function private
In 29cd13cc8f the free function
MSWShouldBeChecked was introduced in toolbar.cpp and mistakenly made
inline. Fix by making it static instead.
2016-06-08 00:59:53 +02:00
Vadim Zeitlin
25c9b032a8 Don't call CacheBestSize() from DoGetBestSize() implementations
This is unnecessary, wxWindow::GetBestSize() already does this, so calling it
from DoGetBestSize() called by it too is just useless.
2016-04-03 18:04:26 +02:00
Catalin
f6a314bd62 Included headers needed by GET_X_LPARAM and GET_Y_LPARAM macros. 2016-02-21 20:12:35 +02:00
Václav Slavík
3a7951db2b wxMSW: Fix wxToolBar rendering with double-buffering
An old check - used for reasons that no longer apply - was preventing
correct rendering of wxToolBar background in wxMSW. Fix this by removing
the obsolete check.

See #9666 for the original reason for the check.
2016-02-21 18:32:10 +01:00
Artur Wieczorek
68eae6ba5b Fix disabling control tools in wxMSW wxToolBar
Tools containing controls should be enabled/disabled in a different way from
the button tools in wxToolBar::DoEnableTool(). The control and its label (if
any) need to be explicitly enabled/disabled for wxToolBarBase::EnableTool() to
work properly.

Closes #17346.
2016-01-26 21:49:38 +01:00
pb101
a03df746f0 Fix harmless parameter shadowing warnings
Rename local variables to avoid clashes with the function parameters.

Closes #17343, #17344.
2016-01-22 14:41:23 +01:00