Adapting Dialogs for Small Devices
wxWidgets can be used on mobile and other embedded devices, using GTK+, X11, and Windows CE ports (and others in the future). The most obvious limitation associated with many of these devices is the size of the display, which for a smartphone may be as little as 176x220 pixels.Many dialogs will need an alternative dialog layout for small displays; some controls may be omitted altogether, especially as the functionality of the application may be reduced compared with a desktop application. You can detect the size of the device with wxSystemSettings::GetScreenType, for example:
GetScreenType returns one of the values listed in Table 9-1. Because the types increase in value as the screen size increases, you can use integer comparison operators to deal with classes of devices with screens below a certain size, as in the example we've just seen.
#include "wx/settings.h"
bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
wxSYS_SCREEN_NONE | Undefined screen type |
wxSYS_SCREEN_TINY | Tiny screen, less than 320x240 |
wxSYS_SCREEN_PDA | PDA screen, 320x240 or more but less than 640x480 |
wxSYS_SCREEN_SMALL | Small screen, 640x480 or more but less than 800x600 |
wxSYS_SCREEN_DESKTOP | Desktop screen, 800x600 or more |
Use wxSystemSettings::GetMetric,
passing wxSYS_SCREEN_X or wxSYS_SCREEN_Y.- Call wxGeTDisplaySize, which returns a wxSize object.
- Create a wxDisplay object and call GetGeometry,
which returns a wxRect
containing the bounding rectangle of the display.
- Replace the whole layout by loading a different XRC file or executing different control creation code. If the controls don't change type, you may not need to change the event handling code at all.
- Reduce the number of controls and space.
- Change the type of some controls to take less space (for example, from wxListBox to wxComboBox). This will need some modification of the associated event handler.
- Change the orientation of one or several sizers. Some small devices have a lot more space in one direction than in another.
#ifdef __SMARTPHONE__
SetLeftMenu(wxID_OK, wxT("OK"));
SetRightMenu(wxID_OK, wxT("Cancel"));
#else
wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
GetTopSizer()->Add(buttonSizer, 0, wxALL|wxGROW, 0);
buttonSizer->Add(new wxButton(this, wxID_OK), 0, wxALL, 5);
buttonSizer->Add(new wxButton(this, wxID_CANCEL), 0, wxALL, 5);
#endif