int wxSizerXmlHandler::GetSizerFlags()
{
const wxString s = GetParamValue(wxS("flag"));
if ( s.empty() )
return 0;
// Parse flags keeping track of invalid combinations. This is somewhat
// redundant with the checks performed in wxSizer subclasses themselves but
// doing it here allows us to give the exact line number at which the
// offending line numbers are given, which is very valuable.
//
// We also can detect invalid flags combinations involving wxALIGN_LEFT and
// wxALIGN_TOP here, while this is impossible at wxSizer level as both of
// these flags have value of 0.
// As the logic is exactly the same in horizontal and vertical
// orientations, use arrays and loops to avoid duplicating the code.
enum Orient
{
Orient_Horz,
Orient_Vert,
Orient_Max
};
const char* const orientName[] = { "horizontal", "vertical" };
// The already seen alignment flag in the given orientation or empty if
// none have been seen yet.
wxString alignFlagIn[] = { wxString(), wxString() };
// Either "wxEXPAND" or "wxGROW" depending on the string used in the input,
// or empty string if none is specified.
wxString expandFlag;
// Either "wxALIGN_CENTRE" or "wxALIGN_CENTER" if either flag was found or
// empty string.
wxString centreFlag;
// Indicates whether we can use alignment in the given orientation at all.
bool alignAllowedIn[] = { true, true };
// Find out the sizer orientation: it is the principal/major size direction
// for the 1D sizers and undefined/invalid for the 2D ones.
Orient orientSizer;
if ( wxBoxSizer* const boxSizer = wxDynamicCast(m_parentSizer, wxBoxSizer) )
{
orientSizer = boxSizer->GetOrientation() == wxHORIZONTAL
? Orient_Horz
: Orient_Vert;
// Alignment can be only used in the transversal/minor direction.
alignAllowedIn[orientSizer] = false;
}
else
{
orientSizer = Orient_Max;
}
int flags = 0;
wxStringTokenizer tkn(s, wxS("| \t\n"), wxTOKEN_STRTOK);
while ( tkn.HasMoreTokens() )
{
const wxString flagName = tkn.GetNextToken();
const int n = m_styleNames.Index(flagName);
if ( n == wxNOT_FOUND )
{
ReportParamError
(
"flag",
wxString::Format("unknown sizer flag \"%s\"", flagName)
);
continue;
}
// Flag description is the string that appears in the error messages,
// the main difference from the flag name is that it can indicate that
// wxALIGN_CENTRE_XXX flag could have been encountered as part of
// wxALIGN_CENTRE which should make the error message more clear as
// seeing references to e.g. wxALIGN_CENTRE_VERTICAL when it's never
// used could be confusing.
wxString flagDesc = wxS('"') + flagName + wxS('"');
int flag = m_styleValues[n];
bool flagSpecifiesAlignIn[] = { false, false };
switch ( flag )
{
case wxALIGN_CENTRE_HORIZONTAL:
case wxALIGN_RIGHT:
flagSpecifiesAlignIn[Orient_Horz] = true;
break;
case wxALIGN_CENTRE_VERTICAL:
case wxALIGN_BOTTOM:
flagSpecifiesAlignIn[Orient_Vert] = true;
break;
//.........这里部分代码省略.........
// same as AddPage() but does it at given position
bool wxNotebook::InsertPage(size_t nPage,
wxNotebookPage *pPage,
const wxString& strText,
bool bSelect,
int imageId)
{
wxCHECK_MSG( pPage != NULL, false, wxT("NULL page in wxNotebook::InsertPage") );
wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false,
wxT("invalid index in wxNotebook::InsertPage") );
wxASSERT_MSG( pPage->GetParent() == this,
wxT("notebook pages must have notebook as parent") );
// add a new tab to the control
// ----------------------------
// init all fields to 0
TC_ITEM tcItem;
wxZeroMemory(tcItem);
// set the image, if any
if ( imageId != -1 )
{
tcItem.mask |= TCIF_IMAGE;
tcItem.iImage = imageId;
}
// and the text
if ( !strText.empty() )
{
tcItem.mask |= TCIF_TEXT;
tcItem.pszText = wxMSW_CONV_LPTSTR(strText);
}
// hide the page: unless it is selected, it shouldn't be shown (and if it
// is selected it will be shown later)
HWND hwnd = GetWinHwnd(pPage);
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
// this updates internal flag too -- otherwise it would get out of sync
// with the real state
pPage->Show(false);
// fit the notebook page to the tab control's display area: this should be
// done before adding it to the notebook or TabCtrl_InsertItem() will
// change the notebooks size itself!
AdjustPageSize(pPage);
// finally do insert it
if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 )
{
wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
return false;
}
// need to update the bg brush when the first page is added
// so the first panel gets the correct themed background
if ( m_pages.empty() )
{
#if wxUSE_UXTHEME
UpdateBgBrush();
#endif // wxUSE_UXTHEME
}
// succeeded: save the pointer to the page
m_pages.Insert(pPage, nPage);
// we may need to adjust the size again if the notebook size changed:
// normally this only happens for the first page we add (the tabs which
// hadn't been there before are now shown) but for a multiline notebook it
// can happen for any page at all as a new row could have been started
if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) )
{
AdjustPageSize(pPage);
// Additionally, force the layout of the notebook itself by posting a
// size event to it. If we don't do it, notebooks with pages on the
// left or the right side may fail to account for the fact that they
// are now big enough to fit all all of their pages on one row and
// still reserve space for the second row of tabs, see #1792.
const wxSize s = GetSize();
::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(s.x, s.y));
}
// now deal with the selection
// ---------------------------
// if the inserted page is before the selected one, we must update the
// index of the selected page
if ( int(nPage) <= m_selection )
{
// one extra page added
m_selection++;
}
DoSetSelectionAfterInsertion(nPage, bSelect);
//.........这里部分代码省略.........
bool wxMaskController::SetInputData(wxString value, int nBeginPos/*=0*/, bool bAllowPrompt/*=TRUE*/)
{
wxString csFullInput;
m_bNeedValidation = TRUE;
m_bValidation = FALSE;
// Start with existing data and append the new data.
csFullInput = GetInputData();
csFullInput = csFullInput.Left(nBeginPos);
if(bAllowPrompt)
csFullInput += value;
else
{
// If the prompt symbol is not valid, then
// add the data one-by-one ignoring any prompt symbols.
for(unsigned int i = 0;i < value.Length();i++)
{
if(value[i] != m_chPromptSymbol)
csFullInput += value[i];
}
}
bool bCompleteSuccess=TRUE;
wxString pszReplaceData=csFullInput;
wxFieldMaskData* pobjData=NULL;
unsigned int posReplaceData=0;
for(unsigned long pos = 0; pos < m_listData.GetCount();pos++)
{
pobjData = (wxFieldMaskData *) (m_listData.Item(pos))->GetData();
// Ignore everything that is not data.
if(pobjData->IsInputData())
{
// If we run out of replacement data, then use the prompt symbol.
// Make sure we iterate through the entire list so that the
// prompt symbol is applied to any empty areas.
if(posReplaceData < pszReplaceData.Length())
{
// This inner while loop is so that we can re-apply input data
// after an error. This will allow us to skip over invalid
// input data and try the next character.
while(posReplaceData< pszReplaceData.Length())
{
wxChar chReplace = pszReplaceData[posReplaceData++];
// Make sure to follow the input validation.
// The prompt symbol is always valid at this level.
// This allows the user to erase a string by overtyping a space.
// On error, just skip the character being inserted.
// This will allow the DeleteRange() function to have the remaining
// characters validated.
if((chReplace == m_chPromptSymbol) || pobjData->IsValidInput(chReplace))
{
pobjData->m_chValue = pobjData->PreProcessChar(chReplace);
break;
}
else
bCompleteSuccess = FALSE;
}
}
else
pobjData->m_chValue = m_chPromptSymbol;
}
}
Update();
return bCompleteSuccess;
}
bool os_msw::is_named_process_running( const wxString& process_name )
{
// A more wxWindows type interface
const char *szToTerminate = process_name.c_str();
// Created: 6/23/2000 (RK)
// Last modified: 3/10/2002 (RK)
// Please report any problems or bugs to [email protected]
// The latest version of this routine can be found at:
// http://www.neurophys.wisc.edu/ravi/software/killproc/
// Terminate the process "szToTerminate" if it is currently running
// This works for Win/95/98/ME and also Win/NT/2000/XP
// The process name is case-insensitive, i.e. "notepad.exe" and "NOTEPAD.EXE"
// will both work (for szToTerminate)
// Return codes are as follows:
// 0 = Process was successfully terminated
// 603 = Process was not currently running
// 604 = No permission to terminate process
// 605 = Unable to load PSAPI.DLL
// 602 = Unable to terminate process for some other reason
// 606 = Unable to identify system type
// 607 = Unsupported OS
// 632 = Invalid process name
// 700 = Unable to get procedure address from PSAPI.DLL
// 701 = Unable to get process list, EnumProcesses failed
// 702 = Unable to load KERNEL32.DLL
// 703 = Unable to get procedure address from KERNEL32.DLL
// 704 = CreateToolhelp32Snapshot failed
// Change history:
// modified 3/8/2002 - Borland-C compatible if BORLANDC is defined as
// suggested by Bob Christensen
// modified 3/10/2002 - Removed memory leaks as suggested by
// Jonathan Richard-Brochu (handles to Proc and Snapshot
// were not getting closed properly in some cases)
BOOL bResult,bResultm;
DWORD aiPID[1000],iCb=1000,iNumProc,iV2000=0;
DWORD iCbneeded,i,iFound=0;
char szName[MAX_PATH],szToTermUpper[MAX_PATH];
HANDLE hProc,hSnapShot,hSnapShotm;
OSVERSIONINFO osvi;
HINSTANCE hInstLib;
int iLen,iLenP,indx;
HMODULE hMod;
PROCESSENTRY32 procentry;
MODULEENTRY32 modentry;
// Transfer Process name into "szToTermUpper" and
// convert it to upper case
iLenP=strlen(szToTerminate);
if(iLenP<1 || iLenP>MAX_PATH) return FALSE;
for(indx=0;indx<iLenP;indx++)
szToTermUpper[indx]=toupper(szToTerminate[indx]);
szToTermUpper[iLenP]=0;
// PSAPI Function Pointers.
BOOL (WINAPI *lpfEnumProcesses)( DWORD *, DWORD cb, DWORD * );
BOOL (WINAPI *lpfEnumProcessModules)( HANDLE, HMODULE *,
DWORD, LPDWORD );
DWORD (WINAPI *lpfGetModuleBaseName)( HANDLE, HMODULE,
LPTSTR, DWORD );
// ToolHelp Function Pointers.
HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;
BOOL (WINAPI *lpfProcess32First)(HANDLE,LPPROCESSENTRY32) ;
BOOL (WINAPI *lpfProcess32Next)(HANDLE,LPPROCESSENTRY32) ;
BOOL (WINAPI *lpfModule32First)(HANDLE,LPMODULEENTRY32) ;
BOOL (WINAPI *lpfModule32Next)(HANDLE,LPMODULEENTRY32) ;
// First check what version of Windows we're in
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
bResult=GetVersionEx(&osvi);
if(!bResult) // Unable to identify system version
return FALSE;
// At Present we only support Win/NT/2000/XP or Win/9x/ME
if((osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) &&
(osvi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS))
return FALSE;
if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
{
// Win/NT or 2000 or XP
// Load library and get the procedures explicitly. We do
// this so that we don't have to worry about modules using
// this code failing to load under Windows 9x, because
// it can't resolve references to the PSAPI.DLL.
hInstLib = LoadLibraryA("PSAPI.DLL");
if(hInstLib == NULL)
return FALSE;
// Get procedure addresses.
lpfEnumProcesses = (BOOL(WINAPI *)(DWORD *,DWORD,DWORD*))
GetProcAddress( hInstLib, "EnumProcesses" ) ;
lpfEnumProcessModules = (BOOL(WINAPI *)(HANDLE, HMODULE *,
DWORD, LPDWORD)) GetProcAddress( hInstLib,
"EnumProcessModules" ) ;
lpfGetModuleBaseName =(DWORD (WINAPI *)(HANDLE, HMODULE,
//.........这里部分代码省略.........
wxString wxTextBuffer::Translate(const wxString& text, wxTextFileType type)
{
// don't do anything if there is nothing to do
if ( type == wxTextFileType_None )
return text;
// nor if it is empty
if ( text.empty() )
return text;
wxString eol = GetEOL(type), result;
// optimization: we know that the length of the new string will be about
// the same as the length of the old one, so prealloc memory to avoid
// unnecessary relocations
result.Alloc(text.Len());
wxChar chLast = 0;
for ( wxString::const_iterator i = text.begin(); i != text.end(); ++i )
{
wxChar ch = *i;
switch ( ch ) {
case wxT('\n'):
// Dos/Unix line termination
result += eol;
chLast = 0;
break;
case wxT('\r'):
if ( chLast == wxT('\r') ) {
// Mac empty line
result += eol;
}
else {
// just remember it: we don't know whether it is just "\r"
// or "\r\n" yet
chLast = wxT('\r');
}
break;
default:
if ( chLast == wxT('\r') ) {
// Mac line termination
result += eol;
// reset chLast to avoid inserting another eol before the
// next character
chLast = 0;
}
// add to the current line
result += ch;
}
}
if ( chLast ) {
// trailing '\r'
result += eol;
}
return result;
}
请发表评论