miscellaneous functions
wxconcat
wxconcatwxconcat(x, y) this macro returns the concatenation of two tokens x and y.
wxdynlib_functionwxdynlib_function(type, name, dynlib) when loading a function from a dll you always have to cast the returned void * pointer to the correct type and, even more annoyingly, you have to repeat this type twice if you want to declare and define a function pointer all in one line this macro makes this slightly less painful by allowing you to specify the type only once, as the first parameter, and creating a variable of this type named after the function but with pfn prefix and initialized with the function name from the wxdynamiclibrary dynlib. parameters type
name
dynlib
wxexplicitwxexplicit is a macro which expands to the c++ explicit keyword if the compiler supports it or nothing otherwise. thus, it can be used even in the code which might have to be compiled with an old compiler without support for this language feature but still take advantage of it when it is available.
::wxgetkeystatebool wxgetkeystate(wxkeycode key) for normal keys, returns true if the specified key is currently down. for togglable keys (caps lock, num lock and scroll lock), returns true if the key is toggled such that its led indicator is lit. there is currently no way to test whether togglable keys are up or down. even though there are virtual key codes defined for mouse buttons, they cannot be used with this function currently. include files <wx/utils.h>
wxllwxlonglong_t wxll(number) this macro is defined for the platforms with a native 64 bit integer type and allows to define 64 bit compile time constants:
#ifdef wxlonglong_t wxlonglong_t ll = wxll(0x1234567890abcdef); #endifinclude files <wx/longlong.h> see also
wxlonglongfmtspecthis macro is defined to contain the printf() format specifier using which 64 bit integer numbers (i.e. those of type wxlonglong_t) can be printed. example of using it:
#ifdef wxlonglong_t wxlonglong_t ll = wxll(0x1234567890abcdef); printf("long long = %" wxlonglongfmtspec "x\n", ll); #endifsee also include files <wx/longlong.h>
::wxnewidlong wxnewid() generates an integer identifier unique to this run of the program. include files <wx/utils.h>
wxon_block_exitwxon_block_exit0(func) wxon_block_exit1(func, p1) wxon_block_exit2(func, p1, p2) this family of macros allows to ensure that the global function func with 0, 1, 2 or more parameters (up to some implementaton-defined limit) is executed on scope exit, whether due to a normal function return or because an exception has been thrown. a typical example of its usage: void *buf = malloc(size); wxon_block_exit1(free, buf);please see the original article by andrei alexandrescu and petru marginean published in december 2000 issue of c/c++ users journal for more details. include files <wx/scopeguard.h> see also
wxon_block_exit_objwxon_block_exit_obj0(obj, method) wxon_block_exit_obj1(obj, method, p1) wxon_block_exit_obj2(obj, method, p1, p2) this family of macros is similar to wxon_block_exit but calls a method of the given object instead of a free function. include files <wx/scopeguard.h>
::wxregisteridvoid wxregisterid(long id) ensures that ids subsequently generated by newid do not clash with the given id. include files <wx/utils.h>
::wxddecleanupvoid wxddecleanup() called when wxwidgets exits, to clean up the dde system. this no longer needs to be called by the application. see also wxddeinitialize. include files <wx/dde.h>
::wxddeinitializevoid wxddeinitialize() initializes the dde system. may be called multiple times without harm. this no longer needs to be called by the application: it will be called by wxwidgets if necessary. see also wxddeserver, wxddeclient, wxddeconnection, wxddecleanup. include files <wx/dde.h>
::wxenabletoplevelwindowsvoid wxenabletoplevelwindows(bool enable = true) this function enables or disables all top level windows. it is used by ::wxsafeyield. include files <wx/utils.h>
::wxfindmenuitemidint wxfindmenuitemid(wxframe *frame, const wxstring& menustring, const wxstring& itemstring) find a menu item identifier associated with the given frame's menu bar. include files <wx/utils.h>
::wxfindwindowbylabelwxwindow * wxfindwindowbylabel(const wxstring& label, wxwindow *parent=null) nb: this function is obsolete, please use wxwindow::findwindowbylabel instead. find a window by its label. depending on the type of window, the label may be a window title or panel item label. if parent is null, the search will start from all top-level frames and dialog boxes; if non-null, the search will be limited to the given window hierarchy. the search is recursive in both cases. include files <wx/utils.h>
::wxfindwindowbynamewxwindow * wxfindwindowbyname(const wxstring& name, wxwindow *parent=null) nb: this function is obsolete, please use wxwindow::findwindowbyname instead. find a window by its name (as given in a window constructor or create function call). if parent is null, the search will start from all top-level frames and dialog boxes; if non-null, the search will be limited to the given window hierarchy. the search is recursive in both cases. if no such named window is found, wxfindwindowbylabel is called. include files <wx/utils.h>
::wxfindwindowatpointwxwindow * wxfindwindowatpoint(const wxpoint& pt) find the deepest window at the given mouse position in screen coordinates, returning the window if found, or null if not.
::wxfindwindowatpointerwxwindow * wxfindwindowatpointer(wxpoint& pt) find the deepest window at the mouse pointer position, returning the window and current pointer position in screen coordinates.
::wxgetactivewindowwxwindow * wxgetactivewindow() gets the currently active window (implemented for msw and gtk only currently, always returns null in the other ports). include files <wx/window.h>
::wxgetbatterystatewxbatterystate wxgetbatterystate() returns battery state as one of wxbattery_normal_state, wxbattery_low_state, wxbattery_critical_state, wxbattery_shutdown_state or wxbattery_unknown_state. wxbattery_unknown_state is also the default on platforms where this feature is not implemented (currently everywhere but ms windows). include files <wx/utils.h>
::wxgetdisplaynamewxstring wxgetdisplayname() under x only, returns the current display name. see also wxsetdisplayname. include files <wx/utils.h>
::wxgetpowertypewxpowertype wxgetpowertype() returns the type of power source as one of wxpower_socket, wxpower_battery or wxpower_unknown. wxpower_unknown is also the default on platforms where this feature is not implemented (currently everywhere but ms windows). include files <wx/utils.h>
::wxgetmousepositionwxpoint wxgetmouseposition() returns the mouse position in screen coordinates. include files <wx/utils.h>
::wxgetmousestatewxmousestate wxgetmousestate() returns the current state of the mouse. returns a wxmousestate instance that contains the current position of the mouse pointer in screen coordinants, as well as boolean values indicating the up/down status of the mouse buttons and the modifier keys. include files <wx/utils.h> wxmousestate has the following interface:
class wxmousestate { public: wxmousestate(); wxcoord getx(); wxcoord gety(); bool leftdown(); bool middledown(); bool rightdown(); bool controldown(); bool shiftdown(); bool altdown(); bool metadown(); bool cmddown(); void setx(wxcoord x); void sety(wxcoord y); void setleftdown(bool down); void setmiddledown(bool down); void setrightdown(bool down); void setcontroldown(bool down); void setshiftdown(bool down); void setaltdown(bool down); void setmetadown(bool down); }; ::wxgetresourcebool wxgetresource(const wxstring& section, const wxstring& entry, const wxstring& *value, const wxstring& file = null) bool wxgetresource(const wxstring& section, const wxstring& entry, float *value, const wxstring& file = null) bool wxgetresource(const wxstring& section, const wxstring& entry, long *value, const wxstring& file = null) bool wxgetresource(const wxstring& section, const wxstring& entry, int *value, const wxstring& file = null) gets a resource value from the resource database (for example, win.ini, or .xdefaults). if file is null, win.ini or .xdefaults is used, otherwise the specified file is used. under x, if an application class (wxapp::getclassname) has been defined, it is appended to the string /usr/lib/x11/app-defaults/ to try to find an applications default file when merging all resource databases. the reason for passing the result in an argument is that it can be convenient to define a default value, which gets overridden if the value exists in the resource file. it saves a separate test for that resource's existence, and it also allows the overloading of the function for different types. see also wxwriteresource, wxconfigbase. include files <wx/utils.h>
::wxgetstocklabelwxstring wxgetstocklabel(wxwindowid id, bool withcodes = true, const wxstring& accelerator = wxemptystring) returns label that should be used for given id element. parameters id
withcodes
accelerator
include files <wx/stockitem.h>
::wxgettoplevelparentwxwindow * wxgettoplevelparent(wxwindow *win) returns the first top level parent of the given window, or in other words, the frame or dialog containing it, or null. include files <wx/window.h>
::wxlaunchdefaultbrowserbool wxlaunchdefaultbrowser(const wxstring& url, int flags = 0) open the url in user's default browser. if flags parameter contains wxbrowser_new_window flag, a new window is opened for the url (currently this is only supported under windows). returns true if the application was successfully launched. note that for some configurations of the running user, the application which is launched to open the given url may be url-dependent (e.g. a browser may be used for local urls while another one may be used for remote urls). include files <wx/utils.h>
::wxloaduserresourcewxstring wxloaduserresource(const wxstring& resourcename, const wxstring& resourcetype="text") loads a user-defined windows resource as a string. if the resource is found, the function creates a new character array and copies the data into it. a pointer to this data is returned. if unsuccessful, null is returned. the resource must be defined in the .rc file using the following syntax:
myresource text file.extwhere file.ext is a file that the resource compiler can find. this function is available under windows only. include files <wx/utils.h>
::wxpostdeletevoid wxpostdelete(wxobject *object) tells the system to delete the specified object when all other events have been processed. in some environments, it is necessary to use this instead of deleting a frame directly with the delete operator, because some guis will still send events to a deleted window. now obsolete: use wxwindow::close instead. include files <wx/utils.h>
::wxposteventvoid wxpostevent(wxevthandler *dest, wxevent& event) in a gui application, this function posts event to the specified dest object using wxevthandler::addpendingevent. otherwise, it dispatches event immediately using wxevthandler::processevent. see the respective documentation for details (and caveats). include files <wx/app.h>
::wxsetdisplaynamevoid wxsetdisplayname(const wxstring& displayname) under x only, sets the current display name. this is the x host and display name such as "colonsay:0.0", and the function indicates which display should be used for creating windows from this point on. setting the display within an application allows multiple displays to be used. see also wxgetdisplayname. include files <wx/utils.h>
::wxstripmenucodeswxstring wxstripmenucodes(const wxstring& str, int flags = wxstrip_all) strips any menu codes from str and returns the result. by default, the functions strips both the mnemonics character ('&') which is used to indicate a keyboard shortkey, and the accelerators, which are used only in the menu items and are separated from the main text by the \t (tab) character. by using flags of wxstrip_mnemonics or wxstrip_accel to strip only the former or the latter part, respectively. notice that in most cases wxmenuitem::getlabelfromtext or wxcontrol::getlabeltext can be used instead. include files <wx/utils.h>
wxstringizewxstringize(x) returns the string representation of the given symbol which can be either a literal or a macro (hence the advantage of using this macro instead of the standard preprocessor # operator which doesn't work with macros). notice that this macro always produces a char string, use wxstringize_t to build a wide string unicode build. see also
wxstringize_twxstringize_t(x) returns the string representation of the given symbol as either an ascii or unicode string, depending on the current build. this is the unicode-friendly equivalent of wxstringize.
wxsuppress_gcc_private_dtor_warningwxsuppress_gcc_private_dtor_warning(name) gnu c++ compiler gives a warning for any class whose destructor is private unless it has a friend. this warning may sometimes be useful but it doesn't make sense for reference counted class which always delete themselves (hence destructor should be private) but don't necessarily have any friends, so this macro is provided to disable the warning in such case. the name parameter should be the name of the class but is only used to construct a unique friend class name internally. example of using the macro:
class refcounted { public: refcounted() { m_nref = 1; } void incref() { m_nref++ ; } void decref() { if ( !--m_nref ) delete this; } private: ~refcounted() { } wxsuppress_gcc_private_dtor(refcounted) };notice that there should be no semicolon after this macro.
wxullwxlonglong_t wxull(number) this macro is defined for the platforms with a native 64 bit integer type and allows to define unsigned 64 bit compile time constants:
#ifdef wxlonglong_t unsigned wxlonglong_t ll = wxull(0x1234567890abcdef); #endifinclude files <wx/longlong.h> see also
wxvacopyvoid wxvacopy(va_list argptrdst, va_list argptrsrc) this macro is the same as the standard c99 va_copy for the compilers which support it or its replacement for those that don't. it must be used to preserve the value of a va_list object if you need to use it after passing it to another function because it can be modified by the latter. as with va_start, each call to wxvacopy must have a matching va_end.
::wxwriteresourcebool wxwriteresource(const wxstring& section, const wxstring& entry, const wxstring& value, const wxstring& file = null) bool wxwriteresource(const wxstring& section, const wxstring& entry, float value, const wxstring& file = null) bool wxwriteresource(const wxstring& section, const wxstring& entry, long value, const wxstring& file = null) bool wxwriteresource(const wxstring& section, const wxstring& entry, int value, const wxstring& file = null) writes a resource value into the resource database (for example, win.ini, or .xdefaults). if file is null, win.ini or .xdefaults is used, otherwise the specified file is used. under x, the resource databases are cached until the internal function wxflushresources is called automatically on exit, when all updated resource databases are written to their files. note that it is considered bad manners to write to the .xdefaults file under unix, although the win.ini file is fair game under windows. see also wxgetresource, wxconfigbase. include files <wx/utils.h>
__wxfunction____wxfunction__() this macro expands to the name of the current function if the compiler supports any of __function__, __func__ or equivalent variables or macros or to null if none of them is available.
|