2. LAS RELACIONES PROVEEDOR-CLIENTE
2.2. Aprendizaje Grupal
2.2.1. El papel de Aprendizaje Grupal en el éxito de Planificación
The rest of this chapter provides you with enough detailed information about the most commonly used window classes for you to apply them to your own applications. However, if you are reading this book for the first time, you may want to skip ahead to Chapter 5 and browse the window descriptions later.
Here’s a summary of the classes we cover, to help you navigate this chap- ter. For other window classes, see Chapter 12, “Advanced Window Classes,” and Appendix E, “Third-Party Tools for wxWidgets.”
Base Window Classes
These base classes implement functionality for derived concrete classes.
☞ wxWindow. The base class for all windows.
☞ wxControl. The base class for controls, such as wxButton. ☞ wxControlWithItems. The base class for multi-item controls. Top-Level Windows
Top-level windows usually exist independently on the desktop.
☞ wxFrame. A resizable window containing other windows. ☞ wxMDIParentFrame. A frame that manages other frames. ☞ wxMDIChildFrame. A frame managed by a parent frame. ☞ wxDialog. A resizable window for presenting choices.
☞ wxPopupWindow. A transient window with minimal decoration. Container Windows
Container windows manage child windows.
☞ wxPanel. A window for laying out controls.
☞ wxNotebook. A window for switching pages using tabs.
☞ wxScrolledWindow. A window that scrolls children and graphics. ☞ wxSplitterWindow. A window that manages two child windows. Non-Static Controls
These controls can be edited by the user.
☞ wxButton. A push-button control with a text label.
☞ wxBitmapButton. A push-button control with a bitmap label. ☞ wxChoice. A drop-down list of choices.
☞ wxComboBox. An editable field with a list of choices. ☞ wxCheckBox. A control representing a check box, on or off.
46 Window Basics Chapter 4
☞ wxListBox. A list of selectable string items. ☞ wxRadioBox. A grid of radio buttons.
☞ wxRadioButton. A control resembling a radio button, on or off. ☞ wxScrollBar. A scrollbar control.
☞ wxSpinButton. Arrows for incrementing/decrementing values. ☞ wxSpinCtrl. A text field and spin button for editing integers. ☞ wxSlider. A control for changing a value within a given range. ☞ wxTextCtrl. A single- or multiple-line text entry field.
☞ wxToggleButton. A button that can be toggled on and off.
Static Controls
These controls present information and cannot be edited by the user. ☞ wxGauge. A control showing a quantity.
☞ wxStaticText. A control that shows a text label. ☞ wxStaticBitmap. A control that shows a bitmap label. ☞ wxStaticLine. A control displaying a line.
☞ wxStaticBox. A control displaying a box around other controls.
Menus
Menus are transient windows containing lists of commands. ☞ wxMenu. A menu that can be used as a popup or in a menu bar.
Control Bars
Control bars present concise access to commands and information, usually within a wxFrame.
☞ wxMenuBar. A menu bar that presents commands in a wxFrame. ☞ wxToolBar. A toolbar that provides quick access to commands. ☞ wxStatusBar. A status bar that shows information in multiple fields.
B
ASEW
INDOWC
LASSESIt’s worth mentioning base classes that you may or may not be able use directly but that implement a lot of functionality for derived classes. Use the API reference for these (and other) base classes as well as the reference for the derived classes to get a full understanding of what’s available.
wxWindow
wxWindowis both an important base class and a concrete window class that you can instantiate. However, it’s more likely that you will derive classes from it (or use pre-existing derived classes) than use it on its own.
As we’ve seen, a wxWindowmay be created either in one step, using a non- default constructor, or two steps, using the default constructor followed by Create. For one-step construction, you use this constructor:
wxWindow(wxWindow* parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = wxT(“panel”));
For example:
wxWindow* win = new wxWindow(parent, wxID_ANY, wxPoint(100, 100), wxSize(200, 200));
wxWindowStyles
Each window class may add to the basic styles defined for wxWindow, listed in Table 4-1. Not all native controls support all border styles, and if no border is specified, a default style appropriate to that class will be used. For example, on Windows, most wxControl-derived classes use wxSUNKEN_BORDER by default, which will be interpreted as the border style for the current theme. An appli- cation may suppress the default border by using a style such aswxNO_BORDER. Table 4-1 Basic Window Styles
wxSIMPLE_BORDER Displays a thin border around the window. wxDOUBLE_BORDER Displays a double border.
wxSUNKEN_BORDER Displays a sunken border, or control border consis- tent with the current theme.
wxRAISED_BORDER Displays a raised border.
wxSTATIC_BORDER Displays a border suitable for a static control. Windows only.
wxNO_BORDER Displays no border. This overrides any attempt wxWidgets makes to add a suitable border. wxTRANSPARENT_WINDOW Specifies a transparent window (one that doesn’t
receive paint events). Windows only.
Base Window Classes 47
Table 4-1 Basic Window Styles (Continued)
wxTAB_TRAVERSAL Use this to enable tab traversal for non-dialog windows.
wxWANTS_CHARS Use this to indicate that the window wants to get all char/key events—even for keys like Tab or Enter, which are used for dialog navigation and which wouldn’t be generated without this style. wxFULL_REPAINT_ON_RESIZE By default on Windows, wxWidgets won’t repaint
the entire client area during a resize. This style ensures that the whole client area will be invali- dated during a resize.
wxVSCROLL Enables a vertical scrollbar. wxHSCROLL Enables a horizontal scrollbar.
wxALWAYS_SHOW_SB If a window has scrollbars, disables them instead of hiding them when they are not needed (when the size of the window is big enough to not require the scrollbars to navigate it). This style is currently only implemented for Windows and wxUniversal. wxCLIP_CHILDREN On Windows only, used to eliminate flicker caused
by a window erasing the background of its children. Table 4-2 lists extra styles that cannot be accommodated in the regular style and that are set using wxWindow::SetExtraStyle.
Table 4-2 Basic Extra Window Styles
wxWS_EX_VALIDATE_RECURSIVELY By default,Validate,TransferDataToWindow, and TransferDataFromWindowonly work on direct children of the window. Set this style to make them recursively descend into all subwindows.
wxWS_EX_BLOCK_EVENTS wxCommandEventsand the objects of derived classes are forwarded to the parent window and so on recursively by default. Using this style for the given window enables you to block this prop- agation at this window to prevent the events from being propagated further upwards. Dialogs have this style on by default, but note that if SetExtraStyleis called by the application, it may be reset.
wxWS_EX_TRANSIENT Don’t use this window as an implicit parent for other windows. This must be used with tran- sient windows; otherwise, there is the risk of creating a dialog or frame with this window as a parent, which would lead to a crash if the par- ent were destroyed before the child.
wxWS_EX_PROCESS_IDLE This window should always process idle events, even if the mode set by wxIdleEvent::SetMode is wxIDLE_PROCESS_SPECIFIED.
wxWS_EX_PROCESS_UI_UPDATES This window should always process UI update events, even if the mode set by wxUpdateUIEvent:: SetModeis wxUPDATE_UI_PROCESS_SPECIFIED
.
See Chapter 9 for more information on UI update events.wxWindowEvents
wxWindow and all its derived classes generate the events listed in Table 4-3. Events generated by mouse, keyboard, or joystick input are covered in Chapter 6. Table 4-3 wxWindowEvents
EVT_WINDOW_CREATE(func) Processes a wxEVT_CREATEpropagating event, generated when the underlying window has just been created. Handlers take a
wxWindowCreateEventobject.
EVT_WINDOW_DESTROY(func) Processes a wxEVT_DELETEpropagating event, generated when the window is about to be destroyed. Handlers take a wxWindowDestroyEventobject.
EVT_PAINT(func) Processes a wxEVT_PAINTevent, generated when the window needs updating. Handlers take a wxPaintEventobject.
EVT_ERASE_BACKGROUND(func) Processes a wxEVT_ERASE_BACKGROUNDevent, generated when the window background needs updating. Handlers take a wxEraseEventobject. EVT_MOVE(func) Processes a wxEVT_MOVEevent, generated when the window moves. Handlers take a wxMoveEventobject. EVT_SIZE(func) Processes a wxEVT_SIZEevent, generated when
the window is resized. Handlers take a wxSizeEventobject.
EVT_SET_FOCUS(func) Processes wxEVT_SET_FOCUSand wxEVT_KILL_ EVT_KILL_FOCUS(func) FOCUSevents, generated when the keyboard
focus is gained or lost for this window. Handlers take a wxFocusEventobject. EVT_SYS_COLOUR_CHANGED(func) Processes a wxEVT_SYS_COLOUR_CHANGED
event, generated when the user changed a color in the control panel (Windows only). Handlers take a wxSysColourChangedEventobject. EVT_IDLE(func) Processes a wxEVT_IDLEevent, generated in idle
time. Handlers take a wxIdleEventobject. EVT_UPDATE_UI(func) Processes a wxEVT_UPDATE_UI event, generated
in idle time to give the window a chance to update itself.
wxWindowMember Functions
Because wxWindow is the base class for all other window classes, it has the largest number of member functions. We can’t describe them all here in detail, so instead we present a summary of some of the most important functions. Browsing them should give you a good idea of the general capabilities of win- dows, and you can refer to the reference manual for details of parameters and usage.
CaptureMousecaptures all mouse input, and ReleaseMousereleases the cap- ture. This is useful in a drawing program, for example, so that moving to the edge of the canvas scrolls it rather than causing another window to be acti- vated. Use the static function GetCaptureto retrieve the window with the cur- rent capture (if it’s within the current application), and HasCapture to determine if this window is capturing input.
Centre (Center), CentreOnParent (CenterOnParent), and CentreOnScreen (CenterOnScreen) center the window relative to the screen or the parent window.
ClearBackground clears the window by filling it with the current back- ground color.
ClientToScreen and ScreenToClientconvert between coordinates relative to the top-left corner of this window, and coordinates relative to the top-left corner of the screen.
Close generates a wxCloseEventwhose handler usually tries to close the window. Although the default close event handler will destroy the window, calling Close may not actually close the window if a close event handler has been provided that doesn’tdestroy the window.
ConvertDialogToPixelsand ConvertPixelsToDialogconvert between dialog and pixel units, which is useful when basing size or position on font size in order to give more portable results.
Destroy destroys the window safely. Use this function instead of the deleteoperator because different window classes can be destroyed differently. Frames and dialogs are not destroyed immediately when this function is called but are added to a list of windows to be deleted on idle time, when all pending events have been processed. This prevents problems with events being sent to non-existent windows.
Enable enables or disables the window and its children for input. Some controls display themselves in a different color when disabled.Disablecan be used instead of passing falseto Enable.
FindFocus is a static function that can be used to find the window that currently has the keyboard focus.
FindWindowcan be used with an identifier or a name to find a window in this window’s hierarchy. It can return a descendant or the parent window itself. If you know the type of the window, you can use wxDynamicCastto safely cast to the correct type, returning either a pointer to that type or NULL:
MyWindow* window = wxDynamicCast(FindWindow(ID_MYWINDOW), MyWindow);
Fitresizes the window to fit its children. This should be used with sizer-based layout.FitInsideis similar, but it uses the virtual size (useful when the win- dow has scrollbars and contains further windows).
Freeze and Thaw are hints to wxWidgets that display updates between these two function calls should be optimized. For example, you could use this when adding a lot of lines to a text control separately. Implemented for wxTextCtrlon GTK+, and all windows on Windows and Mac OS X.
GetAcceleratorTableand SetAcceleratorTableget and set the accelerator table for this window.
GetBackgroundColour and SetBackgroundColour are accessors for the win- dow background color, used by the default wxEVT_ERASE_BACKGROUNDevent. After setting the color, you will need to call Refreshor ClearBackgroundto show the window with the new color. SetOwnBackgroundColour is the same as SetBackgroundColourbut the color is not inherited by the window’s children.
GetBackgroundStyleand SetBackgroundStyle are accessors for the window background style. By default, the background style is wxBG_STYLE_SYSTEM, which tells wxWidgets to draw the window background with whatever style is appro- priate, whether a texture drawn according to the current theme (for example, wxDialog), or a solid color (for example, wxListBox). If you set the style to wxBG_STYLE_COLOUR, wxWidgets will use a solid color for this window. If you set it to wxBG_STYLE_CUSTOM, wxWidgets will suppress the default background drawing, and the application can paint it from its erase or paint event handler. If you want to draw your own textured background, then setting the style to wxBG_STYLE_CUSTOMis recommended for flicker-free refreshes.
GetBestSizereturns the minimal size for the window in pixels (as imple- mented for each window by DoGetBestSize). This is a hint to the sizer system not to resize the window so small that it cannot be viewed or used properly. For example, for a static control, it will be the minimum size such that the con- trol label is not truncated. For windows containing subwindows (typically wxPanel), the size returned by this function will be the same as the size the window would have had after calling Fit.
GetCaretand SetCaretare accessors for the wxCaretobject associated with the window.
GetClientSize and SetClientSize are accessors for the size of the client area in pixels. The client area is the region within any borders and window decorations, inside which you can draw or place child windows.
GetCursorand SetCursorare accessors for the cursor associated with the window.
GetDefaultItemreturns a pointer to the child button that is the default for this window, or NULL. The default button is the one activated by pressing the Enter key. Use wxButton::SetDefaultto set the default button.
GetDropTargetand SetDropTargetare accessors for the wxDropTargetobject which handles dropped data objects for this window. Drag and drop is covered in Chapter 11, “Clipboard and Drag and Drop.”
GetEventHandlerand SetEventHandlerare accessors for the first event han- dler for the window. By default, the event handler is the window itself, but you can interpose a different event handler. You can also use PushEventHandlerand PopEventHandlerto set up a handler chain, with different handlers dealing with different events. wxWidgets will search along the chain for handlers that match incoming events (see Chapter 3, “Event Handling”).
GetExtraStyle and SetExtraStyleare accessors for the “extra” style bits. Extra styles normally start with wxWS_EX_.
GetFontand SetFontare accessors for the font associated with this win- dow.SetOwnFontis the same as SetFont, except that the font is not inherited by the window’s children.
GetForegroundColour and SetForegroundColour are accessors for the win- dow foreground color, whose meaning differs according to the type of window. SetOwnForegroundColouris the same as SetOwnForegroundColourbut the color is not inherited by the window’s children.
GetHelpText and SetHelpTextare accessors for the context-sensitive help string associated with the window. The text is actually stored by the current wxHelpProviderimplementation, and not in the window.
GetIdand SetIdare accessors for the window identifier.
GetLabel returns the label associated with the window. The interpreta- tion of this value depends on the particular window class.
GetNameand SetNameare accessors for the window name, which does not have to be unique. The window name has no special significance to wxWidgets, except under Motif where it is the resource name for the window.
GetParentreturns a pointer to the parent window.
GetPosition returns the position of the top-left corner of the window in pixels, relative to its parent.
GetRect returns a wxRect object (see Chapter 13, “Data Structure Classes”) representing the size and position of the window in pixels.
GetSize and SetSize retrieve and set the outer window dimensions in pixels.
GetSizer and SetSizer are accessors for the top-level sizer used for arranging child windows on this window.
GetTextExtentgets the dimensions of the string in pixels, as it would be drawn on the window with the currently selected font.
GetToolTipand SetToolTipare accessors for the window tooltip object. GetUpdateRegion returns the portion of the window that currently needs refreshing (since the last paint event was handled).
GetValidatorand SetValidatorare accessors for the optional wxValidator object associated with the window, to handle transfer and validation of data. See Chapter 9 for more about validators.
GetVirtualSizereturns the virtual size of the window in pixels, as deter- mined by setting the scrollbar dimensions.
GetWindowStyleand SetWindowStyleare accessors for the window style. InitDialogsends a wxEVT_INIT_DIALOGevent to initiate transfer of data to the window.
IsEnabledindicates whether the window is enabled or disabled.
IsExposed indicates whether a point or a part of the rectangle is in the update region.
IsShownindicates whether the window is shown.
IsTopLevel indicates whether the window is top-level (a wxFrame or a wxDialog).
Layoutinvokes the sizer-based layout system if there is a sizer associated with the window. See Chapter 7 for more about sizers.
Lowersends a window to the bottom of the window hierarchy, while Raise raises the window above all other windows. This works for top-level windows and child windows.
MakeModal disables all the other top-level windows in the application so that the user can only interact with this window.
Movemoves the window to a new position.
MoveAfterInTabOrdermoves the tab order of this window to a position just after the window passed as argument, and MoveBeforeInTabOrder is the same but moves the tab order in front of the window argument.
PushEventHandlerpushes an event handler onto the event stack for this window, and PopEventHandlerremoves and returns the top-most event handler on the event handler stack. RemoveEventHandlerfinds a handler in the event handler stack and removes it.
PopupMenushows a menu at the specified position.
Refresh and RefreshRect causes a paint event (and optionally an erase event) to be sent to the window.
SetFocusgives the window the current keyboard focus. SetScrollbarsets the properties for a built-in scrollbar.
SetSizeHintsallows specification of the minimum and maximum window sizes, and window size increments, in pixels. This is applicable to top-level windows only.
Show shows or hides the window;Hide is equivalent to passing false to