1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
|
/////////////////////////////////////////////////////////////////////////////
// Name: utils.h
// Purpose: interface of various utility classes and functions
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
Signal constants used by wxProcess.
*/
enum wxSignal
{
wxSIGNONE = 0, //!< verify if the process exists under Unix
wxSIGHUP,
wxSIGINT,
wxSIGQUIT,
wxSIGILL,
wxSIGTRAP,
wxSIGABRT,
wxSIGEMT,
wxSIGFPE,
wxSIGKILL, //!< forcefully kill, dangerous!
wxSIGBUS,
wxSIGSEGV,
wxSIGSYS,
wxSIGPIPE,
wxSIGALRM,
wxSIGTERM //!< terminate the process gently
};
/**
Return values for wxProcess::Kill.
*/
enum wxKillError
{
wxKILL_OK, //!< no error
wxKILL_BAD_SIGNAL, //!< no such signal
wxKILL_ACCESS_DENIED, //!< permission denied
wxKILL_NO_PROCESS, //!< no such process
wxKILL_ERROR //!< another, unspecified error
};
enum wxKillFlags
{
wxKILL_NOCHILDREN = 0, //!< don't kill children
wxKILL_CHILDREN = 1 //!< kill children
};
enum wxShutdownFlags
{
wxSHUTDOWN_FORCE = 1, //!< can be combined with other flags (MSW-only)
wxSHUTDOWN_POWEROFF = 2, //!< power off the computer
wxSHUTDOWN_REBOOT = 4, //!< shutdown and reboot
wxSHUTDOWN_LOGOFF = 8 //!< close session (currently MSW-only)
};
/**
@class wxWindowDisabler
This class disables all windows of the application (may be with the
exception of one of them) in its constructor and enables them back in its
destructor.
This is useful when you want to indicate to the user that the application
is currently busy and cannot respond to user input.
@library{wxcore}
@category{misc}
@see wxBusyCursor
*/
class wxWindowDisabler
{
public:
/**
Disables all top level windows of the applications.
If @a disable is @c false nothing is done. This can be convenient if
the windows should be disabled depending on some condition.
@since 2.9.0
*/
wxWindowDisabler(bool disable = true);
/**
Disables all top level windows of the applications with the exception
of @a winToSkip if it is not @NULL.
Notice that under MSW if @a winToSkip appears in the taskbar, the user
will be able to close the entire application (even though its main
window is disabled) by right clicking on the taskbar icon and selecting
the appropriate "Close" command from the context menu. To prevent this
from happening you may want to use wxFRAME_TOOL_WINDOW, if applicable,
or wxFRAME_NO_TASKBAR style when creating the window that will remain
enabled.
*/
wxWindowDisabler(wxWindow* winToSkip);
/**
Reenables the windows disabled by the constructor.
*/
~wxWindowDisabler();
};
/**
@class wxBusyCursor
This class makes it easy to tell your user that the program is temporarily
busy. Just create a wxBusyCursor object on the stack, and within the
current scope, the hourglass will be shown.
For example:
@code
wxBusyCursor wait;
for (int i = 0; i < 100000; i++)
DoACalculation();
@endcode
It works by calling wxBeginBusyCursor() in the constructor, and
wxEndBusyCursor() in the destructor.
@library{wxcore}
@category{misc}
@see wxBeginBusyCursor(), wxEndBusyCursor(), wxWindowDisabler
*/
class wxBusyCursor
{
public:
/**
Constructs a busy cursor object, calling wxBeginBusyCursor().
*/
wxBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR);
/**
Destroys the busy cursor object, calling wxEndBusyCursor().
*/
~wxBusyCursor();
};
// ============================================================================
// Global functions/macros
// ============================================================================
/** @addtogroup group_funcmacro_dialog */
//@{
/**
Changes the cursor to the given cursor for all windows in the application.
Use wxEndBusyCursor() to revert the cursor back to its previous state.
These two calls can be nested, and a counter ensures that only the outer
calls take effect.
@see wxIsBusy(), wxBusyCursor
@header{wx/utils.h}
*/
void wxBeginBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR);
/**
Changes the cursor back to the original cursor, for all windows in the
application. Use with wxBeginBusyCursor().
@see wxIsBusy(), wxBusyCursor
@header{wx/utils.h}
*/
void wxEndBusyCursor();
/**
Returns @true if between two wxBeginBusyCursor() and wxEndBusyCursor()
calls.
@see wxBusyCursor.
@header{wx/utils.h}
*/
bool wxIsBusy();
/**
Ring the system bell.
@note This function is categorized as a GUI one and so is not thread-safe.
@header{wx/utils.h}
@library{wxcore}
*/
void wxBell();
/**
Shows a message box with the information about the wxWidgets build used,
including its version, most important build parameters and the version of
the underlying GUI toolkit. This is mainly used for diagnostic purposes
and can be invoked by Ctrl-Alt-middle clicking on any wxWindow which
doesn't otherwise handle this event.
@since 2.9.0
@see wxGetLibraryVersionInfo()
@header{wx/utils.h}
*/
void wxInfoMessageBox(wxWindow* parent);
//@}
/** @addtogroup group_funcmacro_version */
//@{
/**
Get wxWidgets version information.
@since 2.9.2
@see wxVersionInfo
@header{wx/utils.h}
@library{wxcore}
*/
wxVersionInfo wxGetLibraryVersionInfo();
//@}
/** @addtogroup group_funcmacro_env */
//@{
/**
A map type containing environment variables names and values.
This type is used with wxGetEnvMap() function and wxExecuteEnv structure
optionally passed to wxExecute().
@since 2.9.2
@header{wx/utils.h}
*/
typedef wxStringToStringHashMap wxEnvVariableHashMap;
/**
This is a macro defined as @c getenv() or its wide char version in Unicode
mode.
Note that under Win32 it may not return correct value for the variables set
with wxSetEnv(), use wxGetEnv() function instead.
@header{wx/utils.h}
*/
wxChar* wxGetenv(const wxString& var);
/**
Returns the current value of the environment variable @a var in @a value.
@a value may be @NULL if you just want to know if the variable exists and
are not interested in its value.
Returns @true if the variable exists, @false otherwise.
@header{wx/utils.h}
*/
bool wxGetEnv(const wxString& var, wxString* value);
/**
Sets the value of the environment variable @a var (adding it if necessary)
to @a value.
Notice that under Windows platforms the program may have two different
environment blocks: the first one is that of a Windows process and is
always present, but the CRT may maintain its own independent copy of the
environment. wxSetEnv() will always update the first copy, which means that
wxGetEnv(), which uses it directly, will always return the expected value
after this call. But wxSetEnv() only updates the second copy for some
compilers/CRT implementations (currently only MSVC and MinGW which uses the
same MSVC CRT) and so using wxGetenv() (notice the difference in case) may
not return the updated value.
@param var
The environment variable to be set, must not contain @c '=' character.
@param value
New value of the variable.
@return
@true on success or @false if changing the value failed.
@see wxUnsetEnv()
@header{wx/utils.h}
*/
bool wxSetEnv(const wxString& var, const wxString& value);
/**
Removes the variable @a var from the environment.
wxGetEnv() will return @NULL after the call to this function.
Returns @true on success.
@header{wx/utils.h}
*/
bool wxUnsetEnv(const wxString& var);
/**
Fill a map with the complete content of current environment.
The map will contain the environment variable names as keys and their
values as values.
@param map
The environment map to fill, must be non-@NULL.
@return
@true if environment was successfully retrieved or @false otherwise.
@header{wx/utils.h}
@since 2.9.2
*/
bool wxGetEnvMap(wxEnvVariableHashMap *map);
//@}
/** @addtogroup group_funcmacro_misc */
//@{
/**
Returns battery state as one of @c wxBATTERY_NORMAL_STATE,
@c wxBATTERY_LOW_STATE, @c wxBATTERY_CRITICAL_STATE,
@c wxBATTERY_SHUTDOWN_STATE or @c wxBATTERY_UNKNOWN_STATE.
@c wxBATTERY_UNKNOWN_STATE is also the default on platforms where this
feature is not implemented (currently everywhere but MS Windows).
@header{wx/utils.h}
*/
wxBatteryState wxGetBatteryState();
/**
Returns the type of power source as one of @c wxPOWER_SOCKET,
@c wxPOWER_BATTERY or @c wxPOWER_UNKNOWN. @c wxPOWER_UNKNOWN is also the
default on platforms where this feature is not implemented (currently
everywhere but MS Windows).
@header{wx/utils.h}
*/
wxPowerType wxGetPowerType();
/**
Under X only, returns the current display name.
@see wxSetDisplayName()
@header{wx/utils.h}
*/
wxString wxGetDisplayName();
/**
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.
@header{wx/utils.h}
*/
bool wxGetKeyState(wxKeyCode key);
/**
Returns the mouse position in screen coordinates.
@header{wx/utils.h}
*/
wxPoint wxGetMousePosition();
/**
Returns the current state of the mouse. Returns a wxMouseState instance
that contains the current position of the mouse pointer in screen
coordinates, as well as boolean values indicating the up/down status of the
mouse buttons and the modifier keys.
@header{wx/utils.h}
*/
wxMouseState wxGetMouseState();
/**
This function enables or disables all top level windows. It is used by
wxSafeYield().
@header{wx/utils.h}
*/
void wxEnableTopLevelWindows(bool enable = true);
/**
Find the deepest window at the given mouse position in screen coordinates,
returning the window if found, or @NULL if not.
This function takes child windows at the given position into account even
if they are disabled. The hidden children are however skipped by it.
@header{wx/utils.h}
*/
wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
/**
@deprecated Replaced by wxWindow::FindWindowByLabel().
Find a window by its label. Depending on the type of window, the label may
be a window title or panel item label. If @a 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.
@header{wx/utils.h}
*/
wxWindow* wxFindWindowByLabel(const wxString& label,
wxWindow* parent = NULL);
/**
@deprecated Replaced by wxWindow::FindWindowByName().
Find a window by its name (as given in a window constructor or @e Create
function call). If @a 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.
@header{wx/utils.h}
*/
wxWindow* wxFindWindowByName(const wxString& name, wxWindow* parent = NULL);
/**
Find a menu item identifier associated with the given frame's menu bar.
@header{wx/utils.h}
*/
int wxFindMenuItemId(wxFrame* frame, const wxString& menuString,
const wxString& itemString);
/**
@deprecated Ids generated by it can conflict with the Ids defined by the
user code, use @c wxID_ANY to assign ids which are guaranteed
to not conflict with the user-defined ids for the controls and
menu items you create instead of using this function.
Generates an integer identifier unique to this run of the program.
@header{wx/utils.h}
*/
int wxNewId();
/**
Ensures that Ids subsequently generated by wxNewId() do not clash with the
given @a id.
@header{wx/utils.h}
*/
void wxRegisterId(int id);
/**
Opens the @a document in the application associated with the files of this
type.
The @a flags parameter is currently not used
Returns @true if the application was successfully launched.
@see wxLaunchDefaultBrowser(), wxExecute()
@header{wx/utils.h}
*/
bool wxLaunchDefaultApplication(const wxString& document, int flags = 0);
/**
Opens the @a url in user's default browser.
If the @a flags parameter contains @c wxBROWSER_NEW_WINDOW flag, a new
window is opened for the URL (currently this is only supported under
Windows).
And unless the @a flags parameter contains @c wxBROWSER_NOBUSYCURSOR flag,
a busy cursor is shown while the browser is being launched (using
wxBusyCursor).
The parameter @a url is interpreted as follows:
- if it has a valid scheme (e.g. @c "file:", @c "http:" or @c "mailto:")
it is passed to the appropriate browser configured in the user system.
- if it has no valid scheme (e.g. it's a local file path without the @c "file:"
prefix), then ::wxFileExists and ::wxDirExists are used to test if it's a
local file/directory; if it is, then the browser is called with the
@a url parameter eventually prefixed by @c "file:".
- if it has no valid scheme and it's not a local file/directory, then @c "http:"
is prepended and the browser is called.
Returns @true if the application was successfully launched.
@note 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).
@see wxLaunchDefaultApplication(), wxExecute()
@header{wx/utils.h}
*/
bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0);
/**
Loads an object from Windows resource file.
This function loads the resource with the given name and type from the
resources embedded into a Windows application.
The typical use for it is to load some data from the data files embedded
into the program itself. For example, you could have the following fragment
in your @c .rc file
@code
mydata MYDATA "myfile.dat"
@endcode
and then use it in the following way:
@code
const void* data = NULL;
size_t size = 0;
if ( !wxLoadUserResource(&data, &size, "mydata", "MYDATA") ) {
... handle error ...
}
else {
// Use the data in any way, for example:
wxMemoryInputStream is(data, size);
... read the data from stream ...
}
@endcode
@param outData Filled with the pointer to the data on successful return.
Notice that this pointer does @em not need to be freed by the caller.
@param outLen Filled with the length of the data in bytes.
@param resourceName The name of the resource to load.
@param resourceType The type of the resource in usual Windows format, i.e.
either a real string like "MYDATA" or an integer created by the
standard Windows @c MAKEINTRESOURCE() macro, including any constants
for the standard resources types like @c RT_RCDATA.
@param module The @c HINSTANCE of the module to load the resources from.
The current module is used by default.
@return true if the data was loaded from resource or false if it couldn't
be found (in which case no error is logged) or was found but couldn't
be loaded (which is unexpected and does result in an error message).
This function is available under Windows only.
@library{wxbase}
@header{wx/utils.h}
@since 2.9.1
*/
bool
wxLoadUserResource(const void **outData,
size_t *outLen,
const wxString& resourceName,
const wxChar* resourceType = "TEXT",
WXHINSTANCE module = 0);
/**
Loads a user-defined Windows resource as a string.
This is a wrapper for the general purpose overload wxLoadUserResource(const
void**, size_t*, const wxString&, const wxChar*, WXHINSTANCE) and can be
more convenient for the string data, but does an extra copy compared to the
general version.
@param resourceName The name of the resource to load.
@param resourceType The type of the resource in usual Windows format, i.e.
either a real string like "MYDATA" or an integer created by the
standard Windows @c MAKEINTRESOURCE() macro, including any constants
for the standard resources types like @c RT_RCDATA.
@param pLen Filled with the length of the returned buffer if it is
non-@NULL. This parameter should be used if NUL characters can occur in
the resource data. It is new since wxWidgets 2.9.1
@param module The @c HINSTANCE of the module to load the resources from.
The current module is used by default. This parameter is new since
wxWidgets 2.9.1.
@return A pointer to the data to be <tt>delete[]</tt>d by caller on success
or @NULL on error.
This function is available under Windows only.
@library{wxbase}
@header{wx/utils.h}
*/
char* wxLoadUserResource(const wxString& resourceName,
const wxChar* resourceType = "TEXT",
int* pLen = NULL,
WXHINSTANCE module = 0);
/**
@deprecated Replaced by wxWindow::Close(). See the
@ref overview_windowdeletion "window deletion overview".
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.
@header{wx/utils.h}
*/
void wxPostDelete(wxObject* object);
/**
Compare function type for use with wxQsort()
@header{wx/utils.h}
*/
typedef int (*wxSortCallback)(const void* pItem1, const void* pItem2, const void* user_data);
/**
Function implementing quick sort algorithm.
This function sorts @a total_elems objects of size @a size located at @a
pbase. It uses @a cmp function for comparing them and passes @a user_data
pointer to the comparison function each time it's called.
@header{wx/utils.h}
*/
void wxQsort(void* pbase, size_t total_elems,
size_t size, wxSortCallback cmp, const void* user_data);
/**
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 wxGetDisplayName()
@header{wx/utils.h}
*/
void wxSetDisplayName(const wxString& displayName);
/**
flags for wxStripMenuCodes
*/
enum
{
// strip '&' characters
wxStrip_Mnemonics = 1,
// strip everything after '\t'
wxStrip_Accel = 2,
// strip everything (this is the default)
wxStrip_All = wxStrip_Mnemonics | wxStrip_Accel
};
/**
Strips any menu codes from @a str and returns the result.
By default, the functions strips both the mnemonics character (@c '&')
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
@c \\t (TAB) character. By using @a flags of @c wxStrip_Mnemonics or
@c 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.
@header{wx/utils.h}
*/
wxString wxStripMenuCodes(const wxString& str, int flags = wxStrip_All);
//@}
/** @addtogroup group_funcmacro_networkuseros */
//@{
/**
Copies the user's email address into the supplied buffer, by concatenating
the values returned by wxGetFullHostName() and wxGetUserId().
@return @true if successful, @false otherwise.
@header{wx/utils.h}
*/
wxString wxGetEmailAddress();
/**
@deprecated Use wxGetEmailAddress() instead.
@param buf Buffer to store the email address in.
@param sz Size of the buffer.
@return @true if successful, @false otherwise.
@header{wx/utils.h}
*/
bool wxGetEmailAddress(char* buf, int sz);
/**
Returns the amount of free memory in bytes under environments which support
it, and -1 if not supported or failed to perform measurement.
@header{wx/utils.h}
*/
wxMemorySize wxGetFreeMemory();
/**
Return the (current) user's home directory.
@see wxGetUserHome(), wxStandardPaths
@header{wx/utils.h}
*/
wxString wxGetHomeDir();
/**
Copies the current host machine's name into the supplied buffer. Please
note that the returned name is @e not fully qualified, i.e. it does not
include the domain name.
Under Windows or NT, this function first looks in the environment variable
SYSTEM_NAME; if this is not found, the entry @b HostName in the wxWidgets
section of the WIN.INI file is tried.
@return The hostname if successful or an empty string otherwise.
@see wxGetFullHostName()
@header{wx/utils.h}
*/
wxString wxGetHostName();
/**
@deprecated Use wxGetHostName() instead.
@param buf Buffer to store the host name in.
@param sz Size of the buffer.
@return @true if successful, @false otherwise.
@header{wx/utils.h}
*/
bool wxGetHostName(char* buf, int sz);
/**
Returns the FQDN (fully qualified domain host name) or an empty string on
error.
@see wxGetHostName()
@header{wx/utils.h}
*/
wxString wxGetFullHostName();
/**
Returns the home directory for the given user. If the @a user is empty
(default value), this function behaves like wxGetHomeDir() (i.e. returns
the current user home directory).
If the home directory couldn't be determined, an empty string is returned.
@header{wx/utils.h}
*/
wxString wxGetUserHome(const wxString& user = wxEmptyString);
/**
This function returns the "user id" also known as "login name" under Unix
(i.e. something like "jsmith"). It uniquely identifies the current user (on
this system). Under Windows or NT, this function first looks in the
environment variables USER and LOGNAME; if neither of these is found, the
entry @b UserId in the @b wxWidgets section of the WIN.INI file is tried.
@return The login name if successful or an empty string otherwise.
@see wxGetUserName()
@header{wx/utils.h}
*/
wxString wxGetUserId();
/**
@deprecated Use wxGetUserId() instead.
@param buf Buffer to store the login name in.
@param sz Size of the buffer.
@return @true if successful, @false otherwise.
@header{wx/utils.h}
*/
bool wxGetUserId(char* buf, int sz);
/**
This function returns the full user name (something like "Mr. John Smith").
Under Windows or NT, this function looks for the entry UserName in the
wxWidgets section of the WIN.INI file. If PenWindows is running, the entry
Current in the section User of the PENWIN.INI file is used.
@return The full user name if successful or an empty string otherwise.
@see wxGetUserId()
@header{wx/utils.h}
*/
wxString wxGetUserName();
/**
@deprecated Use wxGetUserName() instead.
@param buf Buffer to store the full user name in.
@param sz Size of the buffer.
@return @true if successful, @false otherwise.
@header{wx/utils.h}
*/
bool wxGetUserName(char* buf, int sz);
/**
Returns the string containing the description of the current platform in a
user-readable form. For example, this function may return strings like
"Windows NT Version 4.0" or "Linux 2.2.2 i386".
@see wxGetOsVersion()
@header{wx/utils.h}
*/
wxString wxGetOsDescription();
/**
Gets the version and the operating system ID for currently running OS.
The returned wxOperatingSystemId value can be used for a basic categorization
of the OS family; the major and minor version numbers allows to detect a specific
system.
For Unix-like systems (@c wxOS_UNIX) the major and minor version integers will
contain the kernel major and minor version numbers (as returned by the
'uname -r' command); e.g. "2" and "6" if the machine is using kernel 2.6.19.
For Mac OS X systems (@c wxOS_MAC) the major and minor version integers are the
natural version numbers associated with the OS; e.g. "10" and "6" if the machine
is using Mac OS X Snow Leopard.
For Windows-like systems (@c wxOS_WINDOWS) the major and minor version integers will
contain the following values:
@beginTable
@row3col{<b>Windows OS name</b>, <b>Major version</b>, <b>Minor version</b>}
@row3col{Windows 7, 6, 1}
@row3col{Windows Server 2008 R2, 6, 1}
@row3col{Windows Server 2008, 6, 0}
@row3col{Windows Vista, 6, 0}
@row3col{Windows Server 2003 R2, 5, 2}
@row3col{Windows Server 2003, 5, 2}
@row3col{Windows XP, 5, 1}
@row3col{Windows 2000, 5, 0}
@endDefList
See the <a href="http://msdn.microsoft.com/en-us/library/ms724832(VS.85).aspx">MSDN</a>
for more info about the values above.
@see wxGetOsDescription(), wxPlatformInfo
@header{wx/utils.h}
*/
wxOperatingSystemId wxGetOsVersion(int* major = NULL, int* minor = NULL);
/**
Returns @true if the operating system the program is running under is 64
bit. The check is performed at run-time and may differ from the value
available at compile-time (at compile-time you can just check if
<tt>sizeof(void*) == 8</tt>) since the program could be running in
emulation mode or in a mixed 32/64 bit system (bi-architecture operating
system).
@note This function is not 100% reliable on some systems given the fact
that there isn't always a standard way to do a reliable check on the
OS architecture.
@header{wx/utils.h}
*/
bool wxIsPlatform64Bit();
/**
Returns @true if the current platform is little endian (instead of big
endian). The check is performed at run-time.
@see @ref group_funcmacro_byteorder "Byte Order Functions and Macros"
@header{wx/utils.h}
*/
bool wxIsPlatformLittleEndian();
/**
Returns a structure containing information about the currently running
Linux distribution.
This function uses the @c lsb_release utility which is part of the
<tt>Linux Standard Base Core</tt> specification
(see http://refspecs.linux-foundation.org/lsb.shtml) since the very first LSB
release 1.0 (released in 2001).
The @c lsb_release utility is very common on modern Linux distributions but in
case it's not available, then this function will return a ::wxLinuxDistributionInfo
structure containing empty strings.
This function is Linux-specific and is only available when the @c __LINUX__
symbol is defined.
*/
wxLinuxDistributionInfo wxGetLinuxDistributionInfo();
//@}
/** @addtogroup group_funcmacro_procctrl */
//@{
/**
@struct wxExecuteEnv
This structure can optionally be passed to wxExecute() to specify
additional options to use for the child process.
@since 2.9.2
@header{wx/utils.h}
*/
struct wxExecuteEnv
{
/**
The initial working directory for the new process.
If this field is empty, the current working directory of this process
is used.
*/
wxString cwd;
/**
The environment variable map.
If the map is empty, the environment variables of the current process
are also used for the child one, otherwise only the variables defined
in this map are used.
*/
wxEnvVariableHashMap env;
};
/**
Bit flags that can be used with wxExecute().
*/
enum
{
/**
Execute the process asynchronously.
Notice that, due to its value, this is the default.
*/
wxEXEC_ASYNC = 0,
/**
Execute the process synchronously.
*/
wxEXEC_SYNC = 1,
/**
Always show the child process console under MSW.
The child console is hidden by default if the child IO is redirected,
this flag allows to change this and show it nevertheless.
This flag is ignored under the other platforms.
*/
wxEXEC_SHOW_CONSOLE = 2,
/**
Make the new process a group leader.
Under Unix, if the process is the group leader then passing
wxKILL_CHILDREN to wxKill() kills all children as well as pid.
Under MSW, applies only to console applications and is only supported
under NT family (i.e. not under Windows 9x). It corresponds to the
native @c CREATE_NEW_PROCESS_GROUP and, in particular, ensures that
Ctrl-Break signals will be sent to all children of this process as well
to the process itself. Support for this flag under MSW was added in
version 2.9.4 of wxWidgets.
*/
wxEXEC_MAKE_GROUP_LEADER = 4,
/**
Don't disable the program UI while running the child synchronously.
By default synchronous execution disables all program windows to avoid
that the user interacts with the program while the child process is
running, you can use this flag to prevent this from happening.
This flag can only be used with ::wxEXEC_SYNC.
*/
wxEXEC_NODISABLE = 8,
/**
Don't dispatch events while the child process is executed.
By default, the event loop is run while waiting for synchronous
execution to complete and this flag can be used to simply block the
main process until the child process finishes
This flag can only be used with ::wxEXEC_SYNC.
*/
wxEXEC_NOEVENTS = 16,
/**
Hide child process console under MSW.
Under MSW, hide the console of the child process if it has one,
even if its IO is not redirected.
This flag is ignored under the other platforms.
*/
wxEXEC_HIDE_CONSOLE = 32,
/**
Convenient synonym for flags given system()-like behaviour.
*/
wxEXEC_BLOCK = wxEXEC_SYNC | wxEXEC_NOEVENTS
};
/**
Executes another program in Unix or Windows.
In the overloaded versions of this function, if @a flags parameter contains
@c wxEXEC_ASYNC flag (the default), flow of control immediately returns. If
it contains @c wxEXEC_SYNC, the current application waits until the other
program has terminated.
In the case of synchronous execution, the return value is the exit code of
the process (which terminates by the moment the function returns) and will
be -1 if the process couldn't be started and typically 0 if the process
terminated successfully. Also, while waiting for the process to terminate,
wxExecute() will call wxYield(). Because of this, by default this function
disables all application windows to avoid unexpected reentrancies which
could result from the users interaction with the program while the child
process is running. If you are sure that it is safe to not disable the
program windows, you may pass @c wxEXEC_NODISABLE flag to prevent this
automatic disabling from happening.
For asynchronous execution, however, the return value is the process id and
zero value indicates that the command could not be executed. As an added
complication, the return value of -1 in this case indicates that we didn't
launch a new process, but connected to the running one (this can only
happen when using DDE under Windows for command execution). In particular,
in this case only, the calling code will not get the notification about
process termination.
If @a callback isn't @NULL and if execution is asynchronous,
wxProcess::OnTerminate() will be called when the process finishes.
Specifying this parameter also allows you to redirect the standard input
and/or output of the process being launched by calling
wxProcess::Redirect().
Under Windows, when launching a console process its console is shown by
default but hidden if its IO is redirected. Both of these default
behaviours may be overridden: if ::wxEXEC_HIDE_CONSOLE is specified, the
console will never be shown. If ::wxEXEC_SHOW_CONSOLE is used, the console
will be shown even if the child process IO is redirected. Neither of these
flags affect non-console Windows applications or does anything under the
other systems.
Under Unix the flag @c wxEXEC_MAKE_GROUP_LEADER may be used to ensure that
the new process is a group leader (this will create a new session if
needed). Calling wxKill() passing wxKILL_CHILDREN will kill this process as
well as all of its children (except those which have started their own
session). Under MSW, this flag can be used with console processes only and
corresponds to the native @c CREATE_NEW_PROCESS_GROUP flag.
The @c wxEXEC_NOEVENTS flag prevents processing of any events from taking
place while the child process is running. It should be only used for very
short-lived processes as otherwise the application windows risk becoming
unresponsive from the users point of view. As this flag only makes sense
with @c wxEXEC_SYNC, @c wxEXEC_BLOCK equal to the sum of both of these
flags is provided as a convenience.
@note Currently wxExecute() can only be used from the main thread, calling
this function from another thread will result in an assert failure in
debug build and won't work.
@param command
The command to execute and any parameters to pass to it as a single
string, i.e. "emacs file.txt".
@param flags
Must include either wxEXEC_ASYNC or wxEXEC_SYNC and can also include
wxEXEC_SHOW_CONSOLE, wxEXEC_HIDE_CONSOLE, wxEXEC_MAKE_GROUP_LEADER (in
either case) or wxEXEC_NODISABLE and wxEXEC_NOEVENTS or wxEXEC_BLOCK,
which is equal to their combination, in wxEXEC_SYNC case.
@param callback
An optional pointer to wxProcess.
@param env
An optional pointer to additional parameters for the child process,
such as its initial working directory and environment variables. This
parameter is available in wxWidgets 2.9.2 and later only.
@see wxShell(), wxProcess, @ref page_samples_exec,
wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
@header{wx/utils.h}
@beginWxPerlOnly
In wxPerl this function is called @c Wx::ExecuteCommand.
@endWxPerlOnly
*/
long wxExecute(const wxString& command, int flags = wxEXEC_ASYNC,
wxProcess* callback = NULL,
const wxExecuteEnv* env = NULL);
//@}
/** @addtogroup group_funcmacro_procctrl */
//@{
/**
This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
please see its documentation for general information.
This version takes an array of values: a command, any number of arguments,
terminated by @NULL.
@param argv
The command to execute should be the first element of this array, any
additional ones are the command parameters and the array must be
terminated with a @NULL pointer.
@param flags
Same as for wxExecute(const wxString&,int,wxProcess*) overload.
@param callback
An optional pointer to wxProcess.
@param env
An optional pointer to additional parameters for the child process,
such as its initial working directory and environment variables. This
parameter is available in wxWidgets 2.9.2 and later only.
@see wxShell(), wxProcess, @ref page_samples_exec,
wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
@header{wx/utils.h}
@beginWxPerlOnly
In wxPerl this function is called @c Wx::ExecuteArgs.
@endWxPerlOnly
*/
long wxExecute(char** argv, int flags = wxEXEC_ASYNC,
wxProcess* callback = NULL,
const wxExecuteEnv *env = NULL);
long wxExecute(wchar_t** argv, int flags = wxEXEC_ASYNC,
wxProcess* callback = NULL,
const wxExecuteEnv *env = NULL);
//@}
/** @addtogroup group_funcmacro_procctrl */
//@{
/**
This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
please see its documentation for general information.
This version can be used to execute a process (always synchronously, the
contents of @a flags is or'd with @c wxEXEC_SYNC) and capture its output in
the array @e output.
@param command
The command to execute and any parameters to pass to it as a single
string.
@param output
The string array where the stdout of the executed process is saved.
@param flags
Combination of flags to which ::wxEXEC_SYNC is always implicitly added.
@param env
An optional pointer to additional parameters for the child process,
such as its initial working directory and environment variables. This
parameter is available in wxWidgets 2.9.2 and later only.
@see wxShell(), wxProcess, @ref page_samples_exec,
wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
@header{wx/utils.h}
@beginWxPerlOnly
This function is called @c Wx::ExecuteStdout: it only takes the
@a command argument, and returns a 2-element list (@c status, @c output),
where @c output in an array reference.
@endWxPerlOnly
*/
long wxExecute(const wxString& command, wxArrayString& output, int flags = 0,
const wxExecuteEnv *env = NULL);
/**
This is an overloaded version of wxExecute(const wxString&,int,wxProcess*),
please see its documentation for general information.
This version adds the possibility to additionally capture the messages from
standard error output in the @a errors array. As with the above overload
capturing standard output only, execution is always synchronous.
@param command
The command to execute and any parameters to pass to it as a single
string.
@param output
The string array where the stdout of the executed process is saved.
@param errors
The string array where the stderr of the executed process is saved.
@param flags
Combination of flags to which ::wxEXEC_SYNC is always implicitly added.
@param env
An optional pointer to additional parameters for the child process,
such as its initial working directory and environment variables. This
parameter is available in wxWidgets 2.9.2 and later only.
@see wxShell(), wxProcess, @ref page_samples_exec,
wxLaunchDefaultApplication(), wxLaunchDefaultBrowser()
@header{wx/utils.h}
@beginWxPerlOnly
This function is called @c Wx::ExecuteStdoutStderr: it only takes the
@a command argument, and returns a 3-element list (@c status, @c output,
@c errors), where @c output and @c errors are array references.
@endWxPerlOnly
*/
long wxExecute(const wxString& command, wxArrayString& output,
wxArrayString& errors, int flags = 0,
const wxExecuteEnv *env = NULL);
/**
Returns the number uniquely identifying the current process in the system.
If an error occurs, 0 is returned.
@header{wx/utils.h}
*/
unsigned long wxGetProcessId();
/**
Equivalent to the Unix kill function: send the given signal @a sig to the
process with PID @a pid.
The valid signal values are:
@code
enum wxSignal
{
wxSIGNONE = 0, // verify if the process exists under Unix
wxSIGHUP,
wxSIGINT,
wxSIGQUIT,
wxSIGILL,
wxSIGTRAP,
wxSIGABRT,
wxSIGEMT,
wxSIGFPE,
wxSIGKILL, // forcefully kill, dangerous!
wxSIGBUS,
wxSIGSEGV,
wxSIGSYS,
wxSIGPIPE,
wxSIGALRM,
wxSIGTERM // terminate the process gently
};
@endcode
@c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning under
both Unix and Windows but all the other signals are equivalent to
@c wxSIGTERM under Windows. Moreover, under Windows, @c wxSIGTERM is
implemented by posting a message to the application window, so it only
works if the application does have windows. If it doesn't, as is notably
always the case for the console applications, you need to use @c wxSIGKILL
to actually kill the process. Of course, this doesn't allow the process to
shut down gracefully and so should be avoided if possible.
Returns 0 on success, -1 on failure. If the @a rc parameter is not @NULL,
it will be filled with a value from the @c wxKillError enum:
@code
enum wxKillError
{
wxKILL_OK, // no error
wxKILL_BAD_SIGNAL, // no such signal
wxKILL_ACCESS_DENIED, // permission denied
wxKILL_NO_PROCESS, // no such process
wxKILL_ERROR // another, unspecified error
};
@endcode
The @a flags parameter can be wxKILL_NOCHILDREN (the default), or
wxKILL_CHILDREN, in which case the child processes of this process will be
killed too. Note that under Unix, for wxKILL_CHILDREN to work you should
have created the process by passing wxEXEC_MAKE_GROUP_LEADER to
wxExecute().
@see wxProcess::Kill(), wxProcess::Exists(), @ref page_samples_exec
@header{wx/utils.h}
*/
int wxKill(long pid, wxSignal sig = wxSIGTERM,
wxKillError* rc = NULL, int flags = wxKILL_NOCHILDREN);
/**
Executes a command in an interactive shell window. If no command is
specified, then just the shell is spawned.
@see wxExecute(), @ref page_samples_exec
@header{wx/utils.h}
*/
bool wxShell(const wxString& command = wxEmptyString);
/**
This function shuts down or reboots the computer depending on the value of
the @a flags.
@note Note that performing the shutdown requires the corresponding access
rights (superuser under Unix, SE_SHUTDOWN privilege under Windows NT)
and that this function is only implemented under Unix and MSW.
@param flags
One of @c wxSHUTDOWN_POWEROFF, @c wxSHUTDOWN_REBOOT or
@c wxSHUTDOWN_LOGOFF (currently implemented only for MSW) possibly
combined with @c wxSHUTDOWN_FORCE which forces shutdown under MSW by
forcefully terminating all the applications. As doing this can result
in a data loss, this flag shouldn't be used unless really necessary.
@return @true on success, @false if an error occurred.
@header{wx/utils.h}
*/
bool wxShutdown(int flags = wxSHUTDOWN_POWEROFF);
//@}
/** @addtogroup group_funcmacro_time */
//@{
/**
Sleeps for the specified number of microseconds. The microsecond resolution
may not, in fact, be available on all platforms (currently only Unix
platforms with nanosleep(2) may provide it) in which case this is the same
as calling wxMilliSleep() with the argument of @e microseconds/1000.
@header{wx/utils.h}
*/
void wxMicroSleep(unsigned long microseconds);
/**
Sleeps for the specified number of milliseconds. Notice that usage of this
function is encouraged instead of calling usleep(3) directly because the
standard @e usleep() function is not MT safe.
@header{wx/utils.h}
*/
void wxMilliSleep(unsigned long milliseconds);
/**
Returns a string representing the current date and time.
@header{wx/utils.h}
*/
wxString wxNow();
/**
Sleeps for the specified number of seconds.
@header{wx/utils.h}
*/
void wxSleep(int secs);
/**
@deprecated This function is deprecated because its name is misleading:
notice that the argument is in milliseconds, not microseconds.
Please use either wxMilliSleep() or wxMicroSleep() depending on
the resolution you need.
Sleeps for the specified number of milliseconds.
@header{wx/utils.h}
*/
void wxUsleep(unsigned long milliseconds);
//@}
|