Fixed wxToolBar for WinCE so normal bitmaps can be used;

no longer uses standard buttons.
wxToolBar under Smartphone no longer tries to create
buttons since a toolbar makes no sense on this platform.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32841 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2005-03-15 21:48:20 +00:00
parent 445511b3cd
commit ac1f013c40
5 changed files with 87 additions and 361 deletions

View File

@@ -6,14 +6,11 @@ The name wxToolBar is defined to be a synonym for one of the following classes:
\item {\bf wxToolBar95} The native Windows 95 toolbar. Used on Windows 95, NT 4 and above.
\item {\bf wxToolBarMSW} A Windows implementation. Used on 16-bit Windows.
\item {\bf wxToolBarGTK} The GTK toolbar.
\item {\bf wxToolBarSimple} A simple implementation, with scrolling.
Used on platforms with no native toolbar control, or where scrolling is required.
\end{itemize}
Note that the base class {\bf wxToolBarBase} defines
automatic scrolling management functionality which is similar
to \helpref{wxScrolledWindow}{wxscrolledwindow}, so please refer to this class also.
Not all toolbars support scrolling, but wxToolBarSimple does.
\wxheading{Derived from}
@@ -29,7 +26,6 @@ wxToolBarBase\\
<wx/tbarbase.h> (the base class)\\
<wx/tbarmsw.h> (the non-Windows 95 Windows toolbar class)\\
<wx/tbar95.h> (the Windows 95/98 toolbar class)\\
<wx/tbarsmpl.h> (the generic simple toolbar class)
\wxheading{Remarks}
@@ -206,7 +202,7 @@ Adds a separator for spacing groups of tools.
Adds a tool to the toolbar. The first (short and most commonly used) version
has fewer parameters than the full version at the price of not being able to
specify some of the more rarely used button features. The last version allows
to add an existing tool.
you to add an existing tool.
\wxheading{Parameters}
@@ -332,8 +328,7 @@ Enables or disables the tool.
\wxheading{Remarks}
For wxToolBarSimple, does nothing. Some other implementations
will change the visible state of the tool to indicate that it is disabled.
Some implementations will change the visible state of the tool to indicate that it is disabled.
\wxheading{See also}
@@ -660,6 +655,13 @@ change to take place, it will happen immediately.
\helpref{DeleteTool}{wxtoolbardeletetool}
\membersection{wxToolBar::SetBitmapResource}\label{wxtoolbarsetbitmapresource}
\func{void}{SetBitmapResource}{\param{int }{resourceId}}
Sets the bitmap resource identifier for specifying tool bitmaps as indices
into a custom bitmap. Windows CE only.
\membersection{wxToolBar::SetMargins}\label{wxtoolbarsetmargins}
\func{void}{SetMargins}{\param{const wxSize\&}{ size}}

View File

@@ -123,17 +123,13 @@ implemented in the future for PocketPC.
Menubars and toolbars can only be implemented using a combined control,
but you can use the same syntax as before; wxWidgets will combine the menubar
and toolbar. However, you cannot at present use arbitrary toolbar bitmaps
(since they have to be loaded from a Windows resource), so only standard
identifiers will work (wxID\_OPEN, wxID\_SAVE, wxID\_COPY and so on).
The wxWidgets API doesn't currently provide us with a method of passing resource
identifiers to AddTool, which is something that needs to be addressed.
and toolbar.
On PocketPC, a frame must always have a menubar, even if it's empty.
On Smartphone, there are only two menu buttons, so a menubar is simulated
using a nested menu on the right menu button.
using a nested menu on the right menu button. Toolbars are simply ignored on
Smartphone.
\subsubsection{Closing windows in wxWinCE}
@@ -163,9 +159,6 @@ to be supported.
\itemsep=0pt
\begin{itemize}
\item {\bf Custom toolbar buttons.} The bitmaps could be loaded from a resource
named using the string normally used for a tool caption. Currently only buttons with
standard identifiers can be used.
\item {\bf Font dialog.} The generic font dialog is currently used, which
needs to be simplified (and speeded up).
\item {\bf Sizer speed.} Particularly for dialogs containing notebooks,
@@ -185,9 +178,10 @@ indicating that drawing works a bit differently between desktop and mobile versi
Win32.
\item {\bf wxStaticBitmap.} The About box in the "Life!" demo shows a bitmap that is
the correct size on the emulator, but too small on a VGA Pocket Loox device.
\item {\bf wxStaticLine.} Lines don't show up, and the documentation suggests that
missing styles are implemented with WM\_PAINT.
\item {\bf OK button.} We should allow the OK button on a dialog to be optional, perhaps
by using wxCLOSE\_BOX to indicate when the OK button should be displayed.
\item {\bf Data storage.} Methods for saving data on Smartphone need to be supported and documented.
\item {\bf Dynamic adaptation.} We should probably be using run-time tests more
than preprocessor tests, so that the same WinCE application can run on different
versions of the operating system.

View File

@@ -124,9 +124,6 @@ protected:
// should be called whenever the toolbar size changes
void UpdateSize();
// the big bitmap containing all bitmaps of the toolbar buttons
WXHBITMAP m_hBitmap;
// the total number of toolbar elements
size_t m_nButtons;

View File

@@ -55,94 +55,27 @@ enum
#if wxUSE_TOOLBAR
#include "wx/tbarbase.h" // the base class for all toolbars
// Simple toolbar no longer available, so we will need to have
// a generic toolbar at some point (perhaps the wxUniv toolbar)
#if 0 // !wxUSE_TOOLBAR_NATIVE && !defined(__WXUNIVERSAL__)
#include "wx/tbarsmpl.h"
class WXDLLEXPORT wxToolBar : public wxToolBarSimple
{
public:
wxToolBar() { }
wxToolBar(wxWindow *parent,
wxWindowID winid,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr)
: wxToolBarSimple(parent, winid, pos, size, style, name) { }
// the most commonly used version of AddTool()
wxToolBarToolBase *AddTool(int toolid,
const wxBitmap& bitmap,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString)
{
return wxToolBarSimple::AddTool(toolid, bitmap, wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, NULL,
shortHelpString, longHelpString);
}
// old form
wxToolBarToolBase *AddTool
(
int toolid,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap,
bool toggle,
wxObject *clientData = NULL,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString
)
{
return wxToolBarSimple::AddTool(toolid, bitmap, pushedBitmap, toggle, wxDefaultCoord, wxDefaultCoord, clientData,
shortHelpString, longHelpString);
}
// virtual overridden
virtual wxToolBarToolBase *AddTool
(
int toolid,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap,
bool toggle,
wxCoord xPos,
wxCoord yPos = wxDefaultCoord,
wxObject *clientData = NULL,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString
)
{
return wxToolBarSimple::AddTool(toolid, bitmap, pushedBitmap, toggle, xPos, yPos, clientData,
shortHelpString, longHelpString);
}
private:
DECLARE_DYNAMIC_CLASS(wxToolBar)
};
#else // wxUSE_TOOLBAR_NATIVE
#if defined(__WXUNIVERSAL__)
#include "wx/univ/toolbar.h"
#elif defined(__WXPALMOS__)
#include "wx/palmos/toolbar.h"
#elif defined(__WXMSW__) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
#include "wx/msw/tbar95.h"
#elif defined(__WXWINCE__)
#include "wx/msw/wince/tbarwce.h"
#elif defined(__WXMSW__)
#include "wx/msw/tbarmsw.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/toolbar.h"
#elif defined(__WXGTK__)
#include "wx/gtk/tbargtk.h"
#elif defined(__WXMAC__)
#include "wx/mac/toolbar.h"
#elif defined(__WXCOCOA__)
#include "wx/cocoa/toolbar.h"
#elif defined(__WXPM__)
#include "wx/os2/toolbar.h"
#endif
#endif // !wxUSE_TOOLBAR_NATIVE/wxUSE_TOOLBAR_NATIVE
#if defined(__WXUNIVERSAL__)
#include "wx/univ/toolbar.h"
#elif defined(__WXPALMOS__)
#include "wx/palmos/toolbar.h"
#elif defined(__WXMSW__) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
#include "wx/msw/tbar95.h"
#elif defined(__WXWINCE__)
#include "wx/msw/wince/tbarwce.h"
#elif defined(__WXMSW__)
#include "wx/msw/tbarmsw.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/toolbar.h"
#elif defined(__WXGTK__)
#include "wx/gtk/tbargtk.h"
#elif defined(__WXMAC__)
#include "wx/mac/toolbar.h"
#elif defined(__WXCOCOA__)
#include "wx/cocoa/toolbar.h"
#elif defined(__WXPM__)
#include "wx/os2/toolbar.h"
#endif
#endif // wxUSE_TOOLBAR
#endif

View File

@@ -142,12 +142,14 @@ public:
clientData, shortHelp, longHelp)
{
m_nSepCount = 0;
m_bitmapIndex = -1;
}
wxToolBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
m_nSepCount = 1;
m_bitmapIndex = -1;
}
virtual void SetLabel(const wxString& label)
@@ -168,8 +170,12 @@ public:
void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
size_t GetSeparatorsCount() const { return m_nSepCount; }
void SetBitmapIndex(int idx) { m_bitmapIndex = idx; }
int GetBitmapIndex() const { return m_bitmapIndex; }
private:
size_t m_nSepCount;
int m_bitmapIndex;
};
@@ -205,8 +211,6 @@ wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
void wxToolBar::Init()
{
m_hBitmap = 0;
m_nButtons = 0;
m_defaultWidth = DEFAULTBITMAPX;
@@ -249,6 +253,10 @@ bool wxToolBar::MSWCreateToolbar(const wxPoint& WXUNUSED(pos), const wxSize& WXU
if (m_menuBar)
m_menuBar->SetToolBar(this);
// Smartphone doesn't show a toolbar, it uses menu buttons.
#if !defined(__SMARTPHONE__)
#if defined(WINCE_WITHOUT_COMMANDBAR)
// Create the menubar.
SHMENUBARINFO mbi;
@@ -283,6 +291,8 @@ bool wxToolBar::MSWCreateToolbar(const wxPoint& WXUNUSED(pos), const wxSize& WXU
if (menuBar)
menuBar->Create();
#endif
// __SMARTPHONE__
return true;
}
@@ -325,13 +335,6 @@ void wxToolBar::Recreate()
// reparented
::DestroyWindow(hwndOld);
// it is for the old bitmap control and can't be used with the new one
if ( m_hBitmap )
{
::DeleteObject((HBITMAP) m_hBitmap);
m_hBitmap = 0;
}
Realize();
UpdateSize();
#endif
@@ -349,11 +352,6 @@ wxToolBar::~wxToolBar()
{
frame->SendSizeEvent();
}
if ( m_hBitmap )
{
::DeleteObject((HBITMAP) m_hBitmap);
}
}
wxSize wxToolBar::DoGetBestSize() const
@@ -517,57 +515,11 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
return true;
}
struct wxToolBarIdMapping
{
int m_wxwinId;
int m_winceId;
};
static wxToolBarIdMapping sm_ToolBarIdMappingArray[] =
{
{ wxID_COPY, STD_COPY },
{ wxID_CUT, STD_CUT },
{ wxID_FIND, STD_FIND },
{ wxID_PASTE, STD_PASTE },
{ wxID_NEW, STD_FILENEW },
{ wxID_OPEN, STD_FILEOPEN },
{ wxID_SAVE, STD_FILESAVE },
{ wxID_PRINT, STD_PRINT },
{ wxID_PREVIEW, STD_PRINTPRE },
{ wxID_UNDO, STD_UNDO },
{ wxID_REDO, STD_REDOW },
{ wxID_HELP, STD_HELP },
{ wxID_DELETE, STD_DELETE },
{ wxID_REPLACE, STD_REPLACE },
{ wxID_PROPERTIES, STD_PROPERTIES },
{ wxID_VIEW_DETAILS, VIEW_DETAILS },
{ wxID_VIEW_SORTDATE, VIEW_SORTDATE },
{ wxID_VIEW_LARGEICONS, VIEW_LARGEICONS },
{ wxID_VIEW_SORTNAME, VIEW_SORTNAME },
{ wxID_VIEW_LIST, VIEW_LIST },
{ wxID_VIEW_SORTSIZE, VIEW_SORTSIZE },
{ wxID_VIEW_SMALLICONS, VIEW_SMALLICONS },
{ wxID_VIEW_SORTTYPE, VIEW_SORTTYPE },
{ 0, 0},
};
static int wxFindIdForwxWinId(int id)
{
int i = 0;
while (true)
{
if (sm_ToolBarIdMappingArray[i].m_wxwinId == 0)
return -1;
else if (sm_ToolBarIdMappingArray[i].m_wxwinId == id)
return sm_ToolBarIdMappingArray[i].m_winceId;
i ++;
}
return -1;
}
bool wxToolBar::Realize()
{
#if defined(__SMARTPHONE__)
return true;
#else
const size_t nTools = GetToolsCount();
if ( nTools == 0 )
{
@@ -586,28 +538,15 @@ bool wxToolBar::Realize()
}
#endif // 0
// add the buttons and separators
// ------------------------------
// Use standard buttons
CommandBar_AddBitmap((HWND) GetHWND(), HINST_COMMCTRL,
IDB_STD_SMALL_COLOR, 0, 16, 16);
TBBUTTON *buttons = new TBBUTTON[nTools];
// this array will hold the indices of all controls in the toolbar
wxArrayInt controlIds;
bool lastWasRadio = false;
int i = 0;
wxToolBarToolsList::Node* node;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarToolBase *tool = node->GetData();
wxToolBarTool *tool = (wxToolBarTool*) node->GetData();
bool processedThis = true;
TBBUTTON buttons[1] ;
TBBUTTON& button = buttons[i];
TBBUTTON& button = buttons[0];
wxZeroMemory(button);
@@ -624,8 +563,6 @@ bool wxToolBar::Realize()
break;
case wxTOOL_STYLE_BUTTON:
// if ( !HasFlag(wxTB_NOICONS) )
// button.iBitmap = bitmapId;
if ( HasFlag(wxTB_TEXT) )
{
@@ -636,15 +573,35 @@ bool wxToolBar::Realize()
}
}
int winceId = wxFindIdForwxWinId(tool->GetId());
if (winceId > -1)
const wxBitmap& bmp = tool->GetNormalBitmap();
wxBitmap bmpToUse = bmp;
if (bmp.GetWidth() < 16 || bmp.GetHeight() < 16)
{
button.idCommand = tool->GetId();
// if ( !HasFlag(wxTB_NOICONS) )
button.iBitmap = winceId;
wxMemoryDC memDC;
wxBitmap b(16,16);
memDC.SelectObject(b);
memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
memDC.Clear();
int x = (16 - bmp.GetWidth())/2;
int y = (16 - bmp.GetHeight())/2;
memDC.DrawBitmap(bmp, x, y, true);
memDC.SelectObject(wxNullBitmap);
bmpToUse = b;
tool->SetNormalBitmap(b);
}
else
processedThis = false;
int n = 0;
if ( bmpToUse.Ok() )
{
n = ::CommandBar_AddBitmap( (HWND) GetHWND(), NULL, (int) (HBITMAP) bmpToUse.GetHBITMAP(),
1, 16, 16 );
}
button.idCommand = tool->GetId();
button.iBitmap = n;
if ( tool->IsEnabled() )
button.fsState |= TBSTATE_ENABLED;
@@ -680,176 +637,19 @@ bool wxToolBar::Realize()
case wxITEM_NORMAL:
button.fsStyle = TBSTYLE_BUTTON;
}
// bitmapId++;
break;
}
BOOL bRc = ::CommandBar_AddButtons( (HWND) GetHWND(), 1, buttons );
wxASSERT_MSG( bRc, wxT("Could not add toolbar button."));
lastWasRadio = isRadio;
if (processedThis)
i++;
}
// Add buttons to Commandbar
if (!CommandBar_AddButtons(GetHwnd(), i, buttons))
{
wxLogLastError(wxT("CommandBar_AddButtons"));
}
delete [] buttons;
#if 0
const bool isVertical = HasFlag(wxTB_VERTICAL);
// Deal with the controls finally
// ------------------------------
// adjust the controls size to fit nicely in the toolbar
int y = 0;
size_t index = 0;
for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ )
{
wxToolBarToolBase *tool = node->GetData();
// we calculate the running y coord for vertical toolbars so we need to
// get the items size for all items but for the horizontal ones we
// don't need to deal with the non controls
bool isControl = tool->IsControl();
if ( !isControl && !isVertical )
continue;
// note that we use TB_GETITEMRECT and not TB_GETRECT because the
// latter only appeared in v4.70 of comctl32.dll
RECT r;
if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT,
index, (LPARAM)(LPRECT)&r) )
{
wxLogLastError(wxT("TB_GETITEMRECT"));
}
if ( !isControl )
{
// can only be control if isVertical
y += r.bottom - r.top;
continue;
}
wxControl *control = tool->GetControl();
wxSize size = control->GetSize();
// the position of the leftmost controls corner
int left = -1;
// TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
// available in headers, now check whether it is available now
// (during run-time)
if ( wxTheApp->GetComCtl32Version() >= 471 )
{
// set the (underlying) separators width to be that of the
// control
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_SIZE;
tbbi.cx = size.x;
if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO,
tool->GetId(), (LPARAM)&tbbi) )
{
// the id is probably invalid?
wxLogLastError(wxT("TB_SETBUTTONINFO"));
}
}
else
#endif // comctl32.dll 4.71
// TB_SETBUTTONINFO unavailable
{
// try adding several separators to fit the controls width
int widthSep = r.right - r.left;
left = r.left;
TBBUTTON tbb;
wxZeroMemory(tbb);
tbb.idCommand = 0;
tbb.fsState = TBSTATE_ENABLED;
tbb.fsStyle = TBSTYLE_SEP;
size_t nSeparators = size.x / widthSep;
for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
{
if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON,
index, (LPARAM)&tbb) )
{
wxLogLastError(wxT("TB_INSERTBUTTON"));
}
index++;
}
// remember the number of separators we used - we'd have to
// delete all of them later
((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators);
// adjust the controls width to exactly cover the separators
control->SetSize((nSeparators + 1)*widthSep, wxDefaultCoord);
}
// position the control itself correctly vertically
int height = r.bottom - r.top;
int diff = height - size.y;
if ( diff < 0 )
{
// the control is too high, resize to fit
control->SetSize(wxDefaultCoord, height - 2);
diff = 2;
}
int top;
if ( isVertical )
{
left = 0;
top = y;
y += height + 2*GetMargins().y;
}
else // horizontal toolbar
{
if ( left == -1 )
left = r.left;
top = r.top;
}
control->Move(left, top + (diff + 1) / 2);
}
// the max index is the "real" number of buttons - i.e. counting even the
// separators which we added just for aligning the controls
m_nButtons = index;
if ( !isVertical )
{
if ( m_maxRows == 0 )
{
// if not set yet, only one row
SetRows(1);
}
}
else if ( m_nButtons > 0 ) // vertical non empty toolbar
{
if ( m_maxRows == 0 )
{
// if not set yet, have one column
SetRows(m_nButtons);
}
}
#endif // 0
return true;
#endif
// __SMARTPHONE__
}
// ----------------------------------------------------------------------------