Adapting Dialogs for Small Devices

team bbl


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:

 #include "wx/settings.h" bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); 

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.

Table 9-1. Screen Types

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


If you need more detail about the display size, there are three ways to get it:

  1. Use wxSystemSettings::GetMetric, passing wxSYS_SCREEN_X or wxSYS_SCREEN_Y.

  2. Call wxGeTDisplaySize, which returns a wxSize object.

  3. Create a wxDisplay object and call GetGeometry, which returns a wxRect containing the bounding rectangle of the display.

When you know you may have a stunted display to run on, what can you do with this information? Here are some strategies you can use:

  1. 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.

  2. Reduce the number of controls and space.

  3. 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.

  4. Change the orientation of one or several sizers. Some small devices have a lot more space in one direction than in another.

Occasionally you will need to use API enhancements for particular platforms. Microsoft Smartphone has two special buttons that you can assign labels, such as "OK" and "Cancel". On this platform, instead of creating two wxButton objects, you should call wxDialog::SetLeftMenu and wxDialog::SetRightMenu with an identifier, label, and optional submenu to show. Because these functions only exist on the Smartphone port, you need to conditionally compile your code. For example:

 #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 

    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net