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}
\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,
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.
#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
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)
// a control in the toolbar
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;
};
void wxToolBar::Init()
{
- m_hBitmap = 0;
-
m_nButtons = 0;
m_defaultWidth = DEFAULTBITMAPX;
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;
if (menuBar)
menuBar->Create();
+#endif
+ // __SMARTPHONE__
return true;
}
// 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
{
frame->SendSizeEvent();
}
-
- if ( m_hBitmap )
- {
- ::DeleteObject((HBITMAP) m_hBitmap);
- }
}
wxSize wxToolBar::DoGetBestSize() const
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 )
{
}
#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);
break;
case wxTOOL_STYLE_BUTTON:
-// if ( !HasFlag(wxTB_NOICONS) )
-// button.iBitmap = bitmapId;
-
+
if ( HasFlag(wxTB_TEXT) )
{
const wxString& label = tool->GetLabel();
}
}
- int winceId = wxFindIdForwxWinId(tool->GetId());
- if (winceId > -1)
+ const wxBitmap& bmp = tool->GetNormalBitmap();
+
+ wxBitmap bmpToUse = bmp;
+
+ if (bmp.GetWidth() < 16 || bmp.GetHeight() < 16)
+ {
+ 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);
+ }
+
+ int n = 0;
+ if ( bmpToUse.Ok() )
{
- button.idCommand = tool->GetId();
-// if ( !HasFlag(wxTB_NOICONS) )
- button.iBitmap = winceId;
+ n = ::CommandBar_AddBitmap( (HWND) GetHWND(), NULL, (int) (HBITMAP) bmpToUse.GetHBITMAP(),
+ 1, 16, 16 );
}
- else
- processedThis = false;
+
+ button.idCommand = tool->GetId();
+ button.iBitmap = n;
if ( tool->IsEnabled() )
button.fsState |= TBSTATE_ENABLED;
case wxITEM_NORMAL:
button.fsStyle = TBSTYLE_BUTTON;
}
-
-// bitmapId++;
break;
}
- 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);
+ BOOL bRc = ::CommandBar_AddButtons( (HWND) GetHWND(), 1, buttons );
+
+ wxASSERT_MSG( bRc, wxT("Could not add toolbar button."));
- // 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);
- }
+ lastWasRadio = isRadio;
}
-#endif // 0
return true;
+#endif
+ // __SMARTPHONE__
}
// ----------------------------------------------------------------------------