Contents Up Previous Next

wxPanel: wxCanvas

A panel is a subwindow of a frame in which panel items can be placed to allow the user to view and set controls. Panel items include messages, text items, list items, and check boxes. Use Fit to fit the panel around its items.

Because wxPanel inherits from wxCanvas (in implementations that permit it, such as XView, Motif, and Windows) it has a device context, and can be drawn on. There are some restrictions, however:

wxPanel::wxPanel
wxPanel::~wxPanel
wxPanel::Create
wxPanel::CreateItem
wxPanel::DrawAllStaticItems
wxPanel::Fit
wxPanel::GetButtonFont
wxPanel::GetCursor
wxPanel::GetDefaultItem
wxPanel::GetHorizontalSpacing
wxPanel::GetBackgroundColour
wxPanel::GetButtonColour
wxPanel::GetLabelColour
wxPanel::GetLabelFont
wxPanel::GetPanelDC
wxPanel::GetVerticalSpacing
wxPanel::LoadFromResource
wxPanel::NewLine
wxPanel::OnCommand
wxPanel::OnDefaultAction
wxPanel::OnEvent
wxPanel::OnItemEvent
wxPanel::OnItemLeftClick
wxPanel::OnItemMove
wxPanel::OnItemRightClick
wxPanel::OnItemSize
wxPanel::OnLeftClick
wxPanel::OnRightClick
wxPanel::OnPaint
wxPanel::PaintSelectionHandles
wxPanel::SetHorizontalSpacing
wxPanel::SetLabelPosition
wxPanel::SetBackgroundColour
wxPanel::SetButtonColour
wxPanel::SetButtonFont
wxPanel::SetHorizontalSpacing
wxPanel::SetLabelColour
wxPanel::SetLabelFont
wxPanel::SetVerticalSpacing
wxPanel::Tab


wxPanel::wxPanel

void wxPanel(void)

Constructor, for deriving classes.

void wxPanel(wxWindow *parent, int x = -1, int y = -1, int width = -1, int height = -1,
long style = 0, char *name = "panel")

Constructor.

The parameters x, y, width and height can be omitted on construction if the position and size will later be set (for example by a application frame's OnSize callback, or if there is only one subwindow for the frame, in which case the subwindow fills the frame).

The style parameter may be a combination of the following, using the bitwise 'or' operator.

wxBORDER Draws a thin border around the panel.
wxUSER_COLOURS Under Windows, overrides standard control processing to allow setting of the panel background colour.
wxVSCROLL Gives the dialog box a vertical scrollbar (XView only).

The name parameter is used to associate a name with the item, allowing the application user to set Motif resource values for individual panels.

The parent window may be a panel in Motif and Windows, but not XView.


wxPanel::~wxPanel

void ~wxPanel(void)

Destructor. Deletes any panel items before deleting the physical window.


wxPanel::Create

void Create(wxWindow *parent, int x = -1, int y = -1, int width = -1, int height = -1,
long style = 0, char *name = "panel")

Used in two-step panel construction. See wxPanel::wxPanel for further details.


wxPanel::CreateItem

wxItem * CreateItem(wxItemResource *resource, wxResourceTable *table)

Virtual function that is called by wxPanel::LoadFromResource to create an item from a resource. Override this is if you must create items of different class from the usual ones.


wxPanel::DrawAllStaticItems

void DrawAllStaticItems(void)

Draws all the wxWindows static items associated with this panel. This is experimental code.


wxPanel::Fit

void Fit(void)

Resize the panel to just fit around the panel items. Also works for dialog boxes.


wxPanel::GetButtonFont

wxFont * GetButtonFont(void)

Get the current font for drawing panel item values.


wxPanel::GetCursor

void GetCursor(int *x, int *y)

Gets the current panel 'cursor' position, i.e. where the next panel item will be placed.


wxPanel::GetDefaultItem

wxButton * GetDefaultItem(void)

Retrieves the default button, previously set with wxButton::SetDefault.


wxPanel::GetHorizontalSpacing

int GetHorizontalSpacing(void)

Gets the horizontal spacing for placing items on a panel.


wxPanel::GetBackgroundColour

wxColour * GetBackgroundColour(void)

Gets the default item background colour.


wxPanel::GetButtonColour

wxColour * GetButtonColour(void)

Gets the default item button colour.


wxPanel::GetLabelColour

wxColour * GetLabelColour(void)

Gets the default item label colour.


wxPanel::GetLabelFont

wxFont * GetLabelFont(void)

Get the current font for drawing panel item labels.


wxPanel::GetPanelDC

wxPanelDC * GetPanelDC(void)

Returns the panel device context. You may also get the device context using wxCanvasDC::GetDC. Since wxCanvasDC and wxPanelDC offer the same interface, either call will be adequate to get a suitable device context.


wxPanel::GetVerticalSpacing

int GetVerticalSpacing(void)

Gets the vertical spacing for placing items on a panel.


wxPanel::LoadFromResource

Bool LoadFromResource(wxWindow *parent, char *name)

Loads the contents of a panel or dialog box from a wxWindows resource.

See also wxWindows resource functions and the wxWindows resource system.


wxPanel::NewLine

void NewLine(void)

Cause the next item to be positioned at the beginning of the next line, using the current vertical spacing. More than one new line in succession causes extra vertical spacing to be inserted.


wxPanel::OnCommand

void OnCommand(wxWindow &win, wxCommandEvent &event)

This member is called for panel items that do not have a callback function of their own. It must be overridden when using wxWindows resources, for example.

See also wxWindows resource formats.


wxPanel::OnDefaultAction

void OnDefaultAction(wxItem *item)

Called when the user initiates the default action for a panel or dialog box, for example by double clicking on a listbox. item is the panel item which caused the default action.

The default behaviour for this member is to either send a double click event to the item if it is a listbox, or to retrieve the default button for the panel, and send it a command event as if the user had clicked on the button. This gives default listbox double-click behaviour under Motif and MS Windows. The default code is as follows:

void wxbPanel::OnDefaultAction(wxItem *initiatingItem)
{
  if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)) &&
     initiatingItem.callback)
  {
    wxListBox *lbox = (wxListBox *)initiatingItem;
    wxCommandEvent event(wxEVENT_TYPE_LISTBOX_DCLICK_COMMAND);
    event.commandInt = -1;
    if ((lbox->GetWindowStyleFlag() & wxLB_SINGLE) ||
        (lbox->GetSelectionMode() == wxSINGLE))
    {
      event.commandString = copystring(lbox->GetStringSelection());
      event.commandInt = lbox->GetSelection();
      event.clientData =
        lbox->wxListBox::GetClientData(event.commandInt);
    }
    event.eventObject = lbox;

    lbox->ProcessCommand(event);

    if (event.commandString)
      delete[] event.commandString;
    return;
  }
  
  wxButton *but = GetDefaultItem();
  if (but)
  {
    wxCommandEvent event(wxEVENT_TYPE_BUTTON_COMMAND);
    but->Command(event);
  }
}


wxPanel::OnEvent

void OnEvent(wxMouseEvent & event)

Called when the panel receives a mouse event. The default implementation manages panel item dragging and sizing if in user-interface edit mode. It also sends panel mouse clicks to the application-overridable member functions OnLeftClick and OnRightClick, again only in user-interface edit mode.

See also wxWindow::SetUserEditMode.


wxPanel::OnItemEvent

void OnItemEvent(wxItem * item, wxMouseEvent & event)

Called in user-interface edit mode when the item receives a mouse event. The default implementation manages panel item dragging and sizing.

See also wxWindow::SetUserEditMode.


wxPanel::OnItemLeftClick

void OnItemLeftClick(int x, int y, int keys)

Called in user-interface edit mode when the user left-clicks on a panel item. The coordinates (relative to the item) and a flag indicating shift and control key status are passed. keys is a bit list of wxKEY_SHIFT and wxKEY_CTRL.

See also wxWindow::SetUserEditMode.


wxPanel::OnItemMove

void OnItemMove(wxItem * item, int x, int y)

Called in user-interface edit mode when the item has been moved by the user.

See also wxWindow::SetUserEditMode.


wxPanel::OnItemRightClick

void OnItemRightClick(int x, int y, int keys)

Called in user-interface edit mode when the user right-clicks on a panel item. The coordinates (relative to the item) and a flag indicating shift and control key status are passed. keys is a bit list of wxKEY_SHIFT and wxKEY_CTRL.

See also wxWindow::SetUserEditMode.


wxPanel::OnItemSize

void OnItemSize(wxItem * item, int width, int height)

Called in user-interface edit mode when the item has been resized by the user.

See also wxWindow::SetUserEditMode.


wxPanel::OnLeftClick

void OnLeftClick(int x, int y, int keys)

Called in user-interface edit mode when the user left-clicks on the panel background. The coordinates and a flag indicating shift and control key status are passed. keys is a bit list of wxKEY_SHIFT and wxKEY_CTRL.

See also wxWindow::SetUserEditMode.


wxPanel::OnRightClick

void OnRightClick(int x, int y, int keys)

Called in user-interface edit mode when the user right-clicks on the panel background. The coordinates and a flag indicating shift and control key status are passed. keys is a bit list of wxKEY_SHIFT and wxKEY_CTRL.

See also wxWindow::SetUserEditMode.


wxPanel::OnPaint

void OnPaint(void)

Sent to the panel when it receives an expose event. If you wish to drawn on the panel, you may derive your own class to handle this message.

The standard wxPanel::OnPaint implementation contains code to draw custom static items on the panel, and also to draw selection handles for panel items if necessary. If you wish to use this functionality, call wxPanel::OnPaint from your own OnPaint handler, or call the individual DrawAllStaticItems and PaintSelectionHandles functions.


wxPanel::PaintSelectionHandles

void PaintSelectionHandles(void)

Paints the selection handles for panel items if user interface editing mode is on. This function is called automatically by the default wxPanel::OnPaint handler.

See wxWindow::SetUserEditMode.


wxPanel::SetHorizontalSpacing

void SetHorizontalSpacing(int sp)

Sets the horizontal spacing for placing items on a panel.


wxPanel::SetLabelPosition

void SetLabelPosition(int position)

Determines the current method of placing labels on panel items: if position is wxHORIZONTAL, labels are placed to the left of the item value. If position is wxVERTICAL, the label is placed above the item value. The default behaviour is to have horizontal label placing.

Under MS Windows, this function words for wxText, wxChoice and wxListBox. Under XView, absolute positioning must be used for the wxVERTICAL position to work in some cases. This is because of some strange behaviour in XView where setting a horizontal layout orientation but a vertical label position causes items after list box to appear too low on the panel. So, where it is necessary to have vertical labels, use absolute positioning where results are not as expected.


wxPanel::SetBackgroundColour

void SetBackgroundColour(wxColour& colour)

Specifies the default colour for drawing panel item backgrounds (Motif and Windows).


wxPanel::SetButtonColour

void SetButtonColour(wxColour& colour)

Specifies the default colour for drawing value text (Motif and Windows). wxButton items do not respond to this setting under Windows.


wxPanel::SetButtonFont

void SetButtonFont(wxFont *font)

Specifies the default font for drawing panel item values (Motif and Windows).


wxPanel::SetHorizontalSpacing

void SetHorizontalSpacing(int sp)

Sets the horizontal spacing for placing items on a panel.


wxPanel::SetLabelColour

void SetLabelColour(wxColour& colour)

Specifies the default colour for drawing panel item labels (Motif and Windows).


wxPanel::SetLabelFont

void SetLabelFont(wxFont *font)

Specifies the font for drawing panel item labels (Motif and Windows).


wxPanel::SetVerticalSpacing

void SetVerticalSpacing(int sp)

Sets the vertical spacing for placing items on a panel.


wxPanel::Tab

void Tab(int pixels)

Tabs by the given number of pixels.