wxString wxCmdLineParser::GetParam(size_t n) const { wxCHECK_MSG( n < GetParamCount(), wxEmptyString, _T("invalid param index") ); return m_data->m_parameters[n]; }
bool wxWrapperInputStream::IsSeekable() const { wxCHECK_MSG(m_parent_i_stream, false, "Stream not valid"); return m_parent_i_stream->IsSeekable(); }
wxFileOffset wxStreamBuffer::Seek(wxFileOffset pos, wxSeekMode mode) { wxFileOffset ret_off, diff; wxFileOffset last_access = GetLastAccess(); if ( !m_flushable ) { switch (mode) { case wxFromStart: diff = pos; break; case wxFromCurrent: diff = pos + GetIntPosition(); break; case wxFromEnd: diff = pos + last_access; break; default: wxFAIL_MSG( wxT("invalid seek mode") ); return wxInvalidOffset; } if (diff < 0 || diff > last_access) return wxInvalidOffset; size_t int_diff = wx_truncate_cast(size_t, diff); wxCHECK_MSG( (wxFileOffset)int_diff == diff, wxInvalidOffset, wxT("huge file not supported") ); SetIntPosition(int_diff); return diff; } switch ( mode ) { case wxFromStart: // We'll try to compute an internal position later ... ret_off = m_stream->OnSysSeek(pos, wxFromStart); ResetBuffer(); return ret_off; case wxFromCurrent: diff = pos + GetIntPosition(); if ( (diff > last_access) || (diff < 0) ) { // We must take into account the fact that we have read // something previously. ret_off = m_stream->OnSysSeek(diff-last_access, wxFromCurrent); ResetBuffer(); return ret_off; } else { size_t int_diff = wx_truncate_cast(size_t, diff); wxCHECK_MSG( (wxFileOffset)int_diff == diff, wxInvalidOffset, wxT("huge file not supported") ); SetIntPosition(int_diff); return diff; } case wxFromEnd: // Hard to compute: always seek to the requested position. ret_off = m_stream->OnSysSeek(pos, wxFromEnd); ResetBuffer(); return ret_off; } return wxInvalidOffset; }
bool wxTreeListCtrl::IsSelected(wxTreeListItem item) const { wxCHECK_MSG( m_view, false, "Must create first" ); return m_view->IsSelected(m_model->ToNonRootDVI(item)); }
wxTreeListModelNode* wxTreeListModel::InsertItem(Node* parent, Node* previous, const wxString& text, int imageClosed, int imageOpened, wxClientData* data) { wxCHECK_MSG( parent, NULL, "Must have a valid parent (maybe GetRootItem()?)" ); wxCHECK_MSG( previous, NULL, "Must have a valid previous item (maybe wxTLI_FIRST/LAST?)" ); if ( m_isFlat && parent != m_root ) { // Not flat any more, this is a second level child. m_isFlat = false; } wxScopedPtr<Node> newItem(new Node(parent, text, imageClosed, imageOpened, data)); // FIXME-VC6: This compiler refuses to compare "Node* previous" with // wxTLI_XXX without some help. const wxTreeListItem previousItem(previous); // If we have no children at all, then inserting as last child is the same // as inserting as the first one so check for it here too. if ( previousItem == wxTLI_FIRST || (previousItem == wxTLI_LAST && !parent->GetChild()) ) { parent->InsertChild(newItem.get()); } else // Not the first item, find the previous one. { if ( previousItem == wxTLI_LAST ) { previous = parent->GetChild(); // Find the last child. for ( ;; ) { Node* const next = previous->GetNext(); if ( !next ) break; previous = next; } } else // We already have the previous item. { // Just check it's under the correct parent. wxCHECK_MSG( previous->GetParent() == parent, NULL, "Previous item is not under the right parent" ); } previous->InsertNext(newItem.get()); } ItemAdded(ToDVI(parent), ToDVI(newItem.get())); // The item was successfully inserted in the tree and so will be deleted by // it, we can detach it now. return newItem.release(); }
wxTreeListItem wxTreeListCtrl::GetItemParent(wxTreeListItem item) const { wxCHECK_MSG( item.IsOk(), wxTreeListItem(), "Invalid item" ); return item->GetParent(); }
wxTreeListItem wxTreeListCtrl::GetNextItem(wxTreeListItem item) const { wxCHECK_MSG( item.IsOk(), wxTreeListItem(), "Invalid item" ); return item->NextInTree(); }
int wxListBox::DoListHitTest(const wxPoint& inpoint) const { OSStatus err; // There are few reasons why this is complicated: // 1) There is no native HitTest function for Mac // 2) GetDataBrowserItemPartBounds only works on visible items // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight // because what it returns is basically inaccurate in the context // of the coordinates we want here, but we use this as a guess // for where the first visible item lies wxPoint point = inpoint; // get column property ID (req. for call to itempartbounds) DataBrowserTableViewColumnID colId = 0; err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId); wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty")); // OK, first we need to find the first visible item we have - // this will be the "low" for our binary search. There is no real // easy way around this, as we will need to do a SLOW linear search // until we find a visible item, but we can do a cheap calculation // via the row height to speed things up a bit UInt32 scrollx, scrolly; err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly); wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition")); UInt16 height; err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height); wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight")); // these indices are 0-based, as usual, so we need to add 1 to them when // passing them to data browser functions which use 1-based indices int low = scrolly / height, high = GetCount() - 1; // search for the first visible item (note that the scroll guess above // is the low bounds of where the item might lie so we only use that as a // starting point - we should reach it within 1 or 2 iterations of the loop) while ( low <= high ) { Rect bounds; err = GetDataBrowserItemPartBounds( m_peer->GetControlRef(), low + 1, colId, kDataBrowserPropertyEnclosingPart, &bounds); // note +1 to translate to Mac ID if ( err == noErr ) break; // errDataBrowserItemNotFound is expected as it simply means that the // item is not currently visible -- but other errors are not wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserItemPartBounds") ); low++; } // NOW do a binary search for where the item lies, searching low again if // we hit an item that isn't visible while ( low <= high ) { int mid = (low + high) / 2; Rect bounds; err = GetDataBrowserItemPartBounds( m_peer->GetControlRef(), mid + 1, colId, kDataBrowserPropertyEnclosingPart, &bounds); //note +1 to trans to mac id wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserItemPartBounds") ); if ( err == errDataBrowserItemNotFound ) { // item not visible, attempt to find a visible one // search lower high = mid - 1; } else // visible item, do actual hitttest { // if point is within the bounds, return this item (since we assume // all x coords of items are equal we only test the x coord in // equality) if ((point.x >= bounds.left && point.x <= bounds.right) && (point.y >= bounds.top && point.y <= bounds.bottom) ) { // found! return mid; } if ( point.y < bounds.top ) // index(bounds) greater then key(point) high = mid - 1; else // index(bounds) less then key(point) low = mid + 1; } } return wxNOT_FOUND; }
static gboolean target_drag_drop( GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, wxDropTarget *drop_target ) { /* Owen Taylor: "if the drop is not in a drop zone, return FALSE, otherwise, if you aren't accepting the drop, call gtk_drag_finish() with success == FALSE otherwise call gtk_drag_data_get()" */ /* inform the wxDropTarget about the current GdkDragContext. this is only valid for the duration of this call */ drop_target->GTKSetDragContext( context ); // Does the source actually accept the data type? if (drop_target->GTKGetMatchingPair() == (GdkAtom) 0) { // cancel the whole thing gtk_drag_finish( context, FALSE, // no success FALSE, // don't delete data on dropping side time ); drop_target->GTKSetDragContext( NULL ); drop_target->m_firstMotion = true; return FALSE; } /* inform the wxDropTarget about the current drag widget. this is only valid for the duration of this call */ drop_target->GTKSetDragWidget( widget ); /* inform the wxDropTarget about the current drag time. this is only valid for the duration of this call */ drop_target->GTKSetDragTime( time ); /* reset the block here as someone might very well show a dialog as a reaction to a drop and this wouldn't work without events */ g_blockEventsOnDrag = false; bool ret = drop_target->OnDrop( x, y ); if (!ret) { wxLogTrace(TRACE_DND, wxT( "Drop target: OnDrop returned FALSE") ); /* cancel the whole thing */ gtk_drag_finish( context, FALSE, /* no success */ FALSE, /* don't delete data on dropping side */ time ); } else { wxLogTrace(TRACE_DND, wxT( "Drop target: OnDrop returned true") ); GdkAtom format = drop_target->GTKGetMatchingPair(); // this does happen somehow, see bug 555111 wxCHECK_MSG( format, FALSE, wxT("no matching GdkAtom for format?") ); /* this should trigger an "drag_data_received" event */ gtk_drag_get_data( widget, context, format, time ); } /* after this, invalidate the drop_target's GdkDragContext */ drop_target->GTKSetDragContext( NULL ); /* after this, invalidate the drop_target's drag widget */ drop_target->GTKSetDragWidget( NULL ); /* this has to be done because GDK has no "drag_enter" event */ drop_target->m_firstMotion = true; return ret; }
unsigned char wxColour::Blue() const { wxCHECK_MSG( Ok(), 0, wxT("invalid colour") ); return wxByte(M_COLDATA->m_blue >> SHIFT); }
unsigned char wxColour::Alpha() const { wxCHECK_MSG( Ok(), 0, wxT("invalid colour") ); return M_COLDATA->m_alpha; }
bool wxCheckListBox::IsChecked(unsigned int uiIndex) const { wxCHECK_MSG( IsValid(uiIndex), false, wxT("bad wxCheckListBox index") ); return GetItem(uiIndex)->IsChecked(); }
bool CodeLiteApp::OnInit() { #if defined(__WXMSW__) && !defined(NDEBUG) SetAppName(wxT("codelite-dbg")); #else SetAppName(wxT("codelite")); #endif #if defined(__WXGTK__) || defined(__WXMAC__) // block signal pipe sigset_t mask_set; sigemptyset(&mask_set); sigaddset(&mask_set, SIGPIPE); sigprocmask(SIG_SETMASK, &mask_set, NULL); // Handle sigchld CodeLiteBlockSigChild(); #ifdef __WXGTK__ // Insall signal handlers signal(SIGSEGV, WaitForDebugger); signal(SIGABRT, WaitForDebugger); #endif #endif wxSocketBase::Initialize(); #if wxUSE_ON_FATAL_EXCEPTION // trun on fatal exceptions handler wxHandleFatalExceptions(true); #endif #ifdef __WXMSW__ // as described in http://jrfonseca.dyndns.org/projects/gnu-win32/software/drmingw/ // load the exception handler dll so we will get Dr MinGW at runtime m_handler = LoadLibrary(wxT("exchndl.dll")); // Enable this process debugging priviliges // EnableDebugPriv(); #endif #ifdef USE_POSIX_LAYOUT clStandardPaths::Get().IgnoreAppSubDir("bin"); #endif // Init resources and add the PNG handler wxSystemOptions::SetOption(_T("msw.remap"), 0); wxSystemOptions::SetOption("msw.notebook.themed-background", 1); wxXmlResource::Get()->InitAllHandlers(); wxImage::AddHandler(new wxPNGHandler); wxImage::AddHandler(new wxCURHandler); wxImage::AddHandler(new wxICOHandler); wxImage::AddHandler(new wxXPMHandler); wxImage::AddHandler(new wxGIFHandler); wxImage::AddHandler(new wxJPEGHandler); InitXmlResource(); wxLog::EnableLogging(false); wxString homeDir(wxEmptyString); // parse command line wxCmdLineParser parser; parser.SetDesc(cmdLineDesc); parser.SetCmdLine(wxAppBase::argc, wxAppBase::argv); if(parser.Parse() != 0) { return false; } wxString newDataDir(wxEmptyString); if(parser.Found(wxT("d"), &newDataDir)) { clStandardPaths::Get().SetUserDataDir(newDataDir); } // check for single instance if(!IsSingleInstance(parser)) { return false; } if(parser.Found(wxT("h"))) { // print usage parser.Usage(); return false; } if(parser.Found(wxT("v"))) { // print version #ifdef __WXMSW__ ::wxMessageBox(wxString() << "CodeLite IDE v" << CODELITE_VERSION_STRING, "CodeLite"); #else wxPrintf("CodeLite IDE v%s\n", CODELITE_VERSION_STRING); #endif return false; } if(parser.Found(wxT("n"))) { // Load codelite without plugins SetPluginLoadPolicy(PP_None); } wxString plugins; if(parser.Found(wxT("p"), &plugins)) { wxArrayString pluginsArr = ::wxStringTokenize(plugins, wxT(",")); // Trim and make lower case for(size_t i = 0; i < pluginsArr.GetCount(); i++) { pluginsArr.Item(i).Trim().Trim(false).MakeLower(); } // Load codelite without plugins SetAllowedPlugins(pluginsArr); SetPluginLoadPolicy(PP_FromList); } wxString newBaseDir(wxEmptyString); if(parser.Found(wxT("b"), &newBaseDir)) { #if defined(__WXMSW__) homeDir = newBaseDir; #else wxLogDebug("Ignoring the Windows-only --basedir option as not running Windows"); #endif } // Set the log file verbosity. NB Doing this earlier seems to break wxGTK debug output when debugging CodeLite // itself :/ FileLogger::OpenLog("codelite.log", clConfig::Get().Read(kConfigLogVerbosity, FileLogger::Error)); CL_DEBUG(wxT("Starting codelite...")); // Copy gdb pretty printers from the installation folder to a writeable location // this is needed because python complies the files and in most cases the user // running codelite has no write permissions to /usr/share/codelite/... DoCopyGdbPrinters(); // Since GCC 4.8.2 gcc has a default colored output // which breaks codelite output parsing // to disable this, we need to set GCC_COLORS to an empty // string. // https://sourceforge.net/p/codelite/bugs/946/ // http://gcc.gnu.org/onlinedocs/gcc/Language-Independent-Options.html ::wxSetEnv("GCC_COLORS", ""); #if defined(__WXGTK__) if(homeDir.IsEmpty()) { homeDir = clStandardPaths::Get() .GetUserDataDir(); // By default, ~/Library/Application Support/codelite or ~/.codelite if(!wxFileName::Exists(homeDir)) { wxLogNull noLog; wxFileName::Mkdir(homeDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); wxCHECK_MSG(wxFileName::DirExists(homeDir), false, "Failed to create the requested data dir"); } // Create the directory structure wxLogNull noLog; wxMkdir(homeDir); wxMkdir(homeDir + wxT("/lexers/")); wxMkdir(homeDir + wxT("/rc/")); wxMkdir(homeDir + wxT("/images/")); wxMkdir(homeDir + wxT("/templates/")); wxMkdir(homeDir + wxT("/config/")); wxMkdir(homeDir + wxT("/tabgroups/")); // copy the settings from the global location if needed wxString installPath(INSTALL_DIR, wxConvUTF8); if(!CopySettings(homeDir, installPath)) return false; ManagerST::Get()->SetInstallDir(installPath); } else { wxFileName fn(homeDir); fn.MakeAbsolute(); ManagerST::Get()->SetInstallDir(fn.GetFullPath()); } #elif defined(__WXMAC__) homeDir = clStandardPaths::Get().GetUserDataDir(); if(!wxFileName::Exists(homeDir)) { wxLogNull noLog; wxFileName::Mkdir(homeDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); wxCHECK_MSG(wxFileName::DirExists(homeDir), false, "Failed to create the requested data dir"); } { wxLogNull noLog; // Create the directory structure wxMkdir(homeDir); wxMkdir(homeDir + wxT("/lexers/")); wxMkdir(homeDir + wxT("/rc/")); wxMkdir(homeDir + wxT("/images/")); wxMkdir(homeDir + wxT("/templates/")); wxMkdir(homeDir + wxT("/config/")); wxMkdir(homeDir + wxT("/tabgroups/")); } wxString installPath(MacGetBasePath()); ManagerST::Get()->SetInstallDir(installPath); // copy the settings from the global location if needed CopySettings(homeDir, installPath); #else //__WXMSW__ if(homeDir.IsEmpty()) { // did we got a basedir from user? #ifdef USE_POSIX_LAYOUT homeDir = clStandardPaths::Get().GetDataDir() + wxT(INSTALL_DIR); #else homeDir = ::wxGetCwd(); #endif } wxFileName fnHomdDir(homeDir + wxT("/")); // try to locate the menu/rc.xrc file wxFileName fn(homeDir + wxT("/rc"), wxT("menu.xrc")); if(!fn.FileExists()) { // we got wrong home directory wxFileName appFn(wxAppBase::argv[0]); homeDir = appFn.GetPath(); } if(fnHomdDir.IsRelative()) { fnHomdDir.MakeAbsolute(); homeDir = fnHomdDir.GetPath(); } ManagerST::Get()->SetInstallDir(homeDir); #endif // Use our persistence manager (which uses wxFileConfig instead of the registry...) m_persistencManager = new clPersistenceManager(); wxPersistenceManager::Set(*m_persistencManager); // Make sure we have an instance if the keyboard manager allocated before we create the main frame class // (the keyboard manager needs to connect to the main frame events) clKeyboardManager::Get(); ManagerST::Get()->SetOriginalCwd(wxGetCwd()); ::wxSetWorkingDirectory(homeDir); // Load all of the XRC files that will be used. You can put everything // into one giant XRC file if you wanted, but then they become more // diffcult to manage, and harder to reuse in later projects. // The menubar if(!wxXmlResource::Get()->Load(DoFindMenuFile(ManagerST::Get()->GetInstallDir(), wxT("2.0")))) return false; // keep the startup directory ManagerST::Get()->SetStartupDirectory(::wxGetCwd()); // set the performance output file name PERF_OUTPUT(wxString::Format(wxT("%s/codelite.perf"), wxGetCwd().c_str()).mb_str(wxConvUTF8)); // Initialize the configuration file locater ConfFileLocator::Instance()->Initialize(ManagerST::Get()->GetInstallDir(), ManagerST::Get()->GetStartupDirectory()); // set the CTAGS_REPLACEMENT environment variable wxSetEnv(wxT("CTAGS_REPLACEMENTS"), ManagerST::Get()->GetStartupDirectory() + wxT("/ctags.replacements")); long style = wxSIMPLE_BORDER; #if defined(__WXMSW__) || defined(__WXGTK__) style |= wxFRAME_NO_TASKBAR; #else // Mac wxUnusedVar(style); #endif // read the last frame size from the configuration file // Initialise editor configuration files #ifdef __WXMSW__ { wxLogNull noLog; wxFileName::Mkdir(clStandardPaths::Get().GetUserDataDir(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); } #endif Manager* mgr = ManagerST::Get(); EditorConfig* cfg = EditorConfigST::Get(); cfg->SetInstallDir(mgr->GetInstallDir()); // Update codelite revision and Version wxString strVersion = CODELITE_VERSION_STRING; cfg->Init(strVersion, wxT("2.0.2")); if(!cfg->Load()) { CL_ERROR(wxT("Failed to load configuration file: %s/config/codelite.xml"), wxGetCwd().c_str()); return false; } #if !defined(__WXMAC__) && defined(NDEBUG) // Now all image handlers have been added, show splash screen; but only when using Release builds of codelite GeneralInfo inf; cfg->ReadObject(wxT("GeneralInfo"), &inf); if(inf.GetFlags() & CL_SHOW_SPLASH) { wxBitmap bitmap; wxString splashName(clStandardPaths::Get().GetDataDir() + wxT("/images/splashscreen.png")); if(bitmap.LoadFile(splashName, wxBITMAP_TYPE_PNG)) { wxString mainTitle = CODELITE_VERSION_STRING; clSplashScreen::g_splashScreen = new clSplashScreen(clSplashScreen::CreateSplashScreenBitmap(bitmap), wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, -1, NULL, wxID_ANY); wxYield(); } } #endif #ifdef __WXGTK__ bool redirect = clConfig::Get().Read(kConfigRedirectLogOutput, true); if(redirect) { // Redirect stdout/error to a file wxFileName stdout_err(clStandardPaths::Get().GetUserDataDir(), "codelite-stdout-stderr.log"); FILE* new_stdout = ::freopen(stdout_err.GetFullPath().mb_str(wxConvISO8859_1).data(), "a+b", stdout); FILE* new_stderr = ::freopen(stdout_err.GetFullPath().mb_str(wxConvISO8859_1).data(), "a+b", stderr); wxUnusedVar(new_stderr); wxUnusedVar(new_stdout); } #endif //--------------------------------------------------------- // Set environment variable for CodeLiteDir (make it first // on the list so it can be used by other variables) //--------------------------------------------------------- EvnVarList vars; EnvironmentConfig::Instance()->Load(); EnvironmentConfig::Instance()->ReadObject(wxT("Variables"), &vars); vars.InsertVariable(wxT("Default"), wxT("CodeLiteDir"), ManagerST::Get()->GetInstallDir()); EnvironmentConfig::Instance()->WriteObject(wxT("Variables"), &vars); //--------------------------------------------------------- #ifdef __WXMSW__ // Read registry values MSWReadRegistry(); #endif // Set up the locale if appropriate if(EditorConfigST::Get()->GetOptions()->GetUseLocale()) { int preferredLocale = wxLANGUAGE_ENGLISH; // The locale had to be saved as the canonical locale name, as the wxLanguage enum wasn't consistent between wx // versions wxString preferredLocalename = EditorConfigST::Get()->GetOptions()->GetPreferredLocale(); if(!preferredLocalename.IsEmpty()) { const wxLanguageInfo* info = wxLocale::FindLanguageInfo(preferredLocalename); if(info) { preferredLocale = info->Language; if(preferredLocale == wxLANGUAGE_UNKNOWN) { preferredLocale = wxLANGUAGE_ENGLISH; } } } #if defined(__WXGTK__) // Cater for a --prefix= build. This gets added automatically to the search path for catalogues. // So hack in the standard ones too, otherwise wxstd.mo will be missed wxLocale::AddCatalogLookupPathPrefix(wxT("/usr/share/locale")); wxLocale::AddCatalogLookupPathPrefix(wxT("/usr/local/share/locale")); #elif defined(__WXMSW__) #ifdef USE_POSIX_LAYOUT wxLocale::AddCatalogLookupPathPrefix(clStandardPaths::Get().GetDataDir() + wxT("/share/locale")); #else wxLocale::AddCatalogLookupPathPrefix(ManagerST::Get()->GetInstallDir() + wxT("\\locale")); #endif #endif // This has to be done before the catalogues are added, as otherwise the wrong one (or none) will be found m_locale.Init(preferredLocale); bool codelitemo_found = m_locale.AddCatalog(wxT("codelite")); if(!codelitemo_found) { m_locale.AddCatalog(wxT("CodeLite")); // Hedge bets re our spelling } if(!codelitemo_found) { // I wanted to 'un-init' the locale if no translations were found // as otherwise, in a RTL locale, menus, dialogs etc will be displayed RTL, in English... // However I couldn't find a way to do this } } else { // For proper encoding handling by system libraries it's needed to inialize locale even if UI translation is // turned off m_locale.Init(wxLANGUAGE_ENGLISH, wxLOCALE_DONT_LOAD_DEFAULT); } // Append the binary's dir to $PATH. This makes codelite-cc available even for a --prefix= installation #if defined(__WXMSW__) wxChar pathsep(wxT(';')); #else wxChar pathsep(wxT(':')); #endif wxString oldpath; wxGetEnv(wxT("PATH"), &oldpath); wxFileName execfpath(clStandardPaths::Get().GetExecutablePath()); wxSetEnv(wxT("PATH"), oldpath + pathsep + execfpath.GetPath()); wxString newpath; wxGetEnv(wxT("PATH"), &newpath); // If running under Cygwin terminal, adjust the environment variables AdjustPathForCygwinIfNeeded(); // If running under Cygwin terminal, adjust the environment variables AdjustPathForMSYSIfNeeded(); // Make sure that the colours and fonts manager is instantiated ColoursAndFontsManager::Get().Load(); // Create the main application window clMainFrame::Initialize(parser.GetParamCount() == 0); m_pMainFrame = clMainFrame::Get(); m_pMainFrame->Show(TRUE); SetTopWindow(m_pMainFrame); long lineNumber(0); parser.Found(wxT("l"), &lineNumber); if(lineNumber > 0) { lineNumber--; } else { lineNumber = 0; } for(size_t i = 0; i < parser.GetParamCount(); i++) { wxString argument = parser.GetParam(i); // convert to full path and open it wxFileName fn(argument); fn.MakeAbsolute(ManagerST::Get()->GetOriginalCwd()); if(fn.GetExt() == wxT("workspace")) { ManagerST::Get()->OpenWorkspace(fn.GetFullPath()); } else { clMainFrame::Get()->GetMainBook()->OpenFile(fn.GetFullPath(), wxEmptyString, lineNumber); } } wxLogMessage(wxString::Format(wxT("Install path: %s"), ManagerST::Get()->GetInstallDir().c_str())); wxLogMessage(wxString::Format(wxT("Startup Path: %s"), ManagerST::Get()->GetStartupDirectory().c_str())); #ifdef __WXGTK__ // Needed on GTK if(clMainFrame::Get()->GetMainBook()->GetActiveEditor() == NULL) { clMainFrame::Get()->GetOutputPane()->GetBuildTab()->SetFocus(); } #endif // Especially with the OutputView open, CodeLite was consuming 50% of a cpu, mostly in updateui // The next line limits the frequency of UpdateUI events to every 100ms wxUpdateUIEvent::SetUpdateInterval(100); return TRUE; }
wxString wxCmdLineParser::GetUsageString() { wxString appname = wxTheApp->GetAppName(); if ( !appname ) { wxCHECK_MSG( m_data->m_arguments.size() != 0, wxEmptyString, _T("no program name") ); appname = wxFileNameFromPath(m_data->m_arguments[0]); wxStripExtension(appname); } // we construct the brief cmd line desc on the fly, but not the detailed // help message below because we want to align the options descriptions // and for this we must first know the longest one of them wxString usage; wxArrayString namesOptions, descOptions; if ( !m_data->m_logo.empty() ) { usage << m_data->m_logo << _T('\n'); } usage << wxString::Format(_("Usage: %s"), appname.c_str()); // the switch char is usually '-' but this can be changed with // SetSwitchChars() and then the first one of possible chars is used wxChar chSwitch = !m_data->m_switchChars ? _T('-') : m_data->m_switchChars[0u]; bool areLongOptionsEnabled = AreLongOptionsEnabled(); size_t n, count = m_data->m_options.GetCount(); for ( n = 0; n < count; n++ ) { wxCmdLineOption& opt = m_data->m_options[n]; usage << _T(' '); if ( !(opt.flags & wxCMD_LINE_OPTION_MANDATORY) ) { usage << _T('['); } if ( !opt.shortName.empty() ) { usage << chSwitch << opt.shortName; } else if ( areLongOptionsEnabled && !opt.longName.empty() ) { usage << _T("--") << opt.longName; } else { if (!opt.longName.empty()) { wxFAIL_MSG( wxT("option with only a long name while long ") wxT("options are disabled") ); } else { wxFAIL_MSG( _T("option without neither short nor long name") ); } } wxString option; if ( !opt.shortName.empty() ) { option << _T(" ") << chSwitch << opt.shortName; } if ( areLongOptionsEnabled && !opt.longName.empty() ) { option << (option.empty() ? _T(" ") : _T(", ")) << _T("--") << opt.longName; } if ( opt.kind != wxCMD_LINE_SWITCH ) { wxString val; val << _T('<') << GetTypeName(opt.type) << _T('>'); usage << _T(' ') << val; option << (!opt.longName ? _T(':') : _T('=')) << val; } if ( !(opt.flags & wxCMD_LINE_OPTION_MANDATORY) ) { usage << _T(']'); } namesOptions.push_back(option); descOptions.push_back(opt.description); } count = m_data->m_paramDesc.GetCount(); for ( n = 0; n < count; n++ ) { wxCmdLineParam& param = m_data->m_paramDesc[n]; usage << _T(' '); if ( param.flags & wxCMD_LINE_PARAM_OPTIONAL ) { usage << _T('['); } usage << param.description; if ( param.flags & wxCMD_LINE_PARAM_MULTIPLE ) { usage << _T("..."); } if ( param.flags & wxCMD_LINE_PARAM_OPTIONAL ) { usage << _T(']'); } } usage << _T('\n'); // now construct the detailed help message size_t len, lenMax = 0; count = namesOptions.size(); for ( n = 0; n < count; n++ ) { len = namesOptions[n].length(); if ( len > lenMax ) lenMax = len; } for ( n = 0; n < count; n++ ) { len = namesOptions[n].length(); usage << namesOptions[n] << wxString(_T(' '), lenMax - len) << _T('\t') << descOptions[n] << _T('\n'); } return usage; }
GdkColor *wxColour::GetColor() const { wxCHECK_MSG( IsOk(), NULL, wxT("invalid colour") ); return &M_COLDATA->m_color; }
wxDragResult wxDropSource::DoDragDrop(int flags) { wxCHECK_MSG( m_data && m_data->GetFormatCount(), wxDragNone, wxT("Drop source: no data") ); // still in drag if (g_blockEventsOnDrag) return wxDragNone; // don't start dragging if no button is down if (g_lastButtonNumber == 0) return wxDragNone; // we can only start a drag after a mouse event if (g_lastMouseEvent == NULL) return wxDragNone; GTKConnectDragSignals(); wxON_BLOCK_EXIT_OBJ0(*this, wxDropSource::GTKDisconnectDragSignals); m_waiting = true; GtkTargetList *target_list = gtk_target_list_new( NULL, 0 ); wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; m_data->GetAllFormats( array ); size_t count = m_data->GetFormatCount(); for (size_t i = 0; i < count; i++) { GdkAtom atom = array[i]; wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom )); gtk_target_list_add( target_list, atom, 0, 0 ); } delete[] array; int allowed_actions = GDK_ACTION_COPY; if ( flags & wxDrag_AllowMove ) allowed_actions |= GDK_ACTION_MOVE; // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad // to use a global to pass the flags to the drop target but I'd // surely prefer a better way to do it gs_flagsForDrag = flags; m_retValue = wxDragCancel; GdkDragContext *context = gtk_drag_begin( m_widget, target_list, (GdkDragAction)allowed_actions, g_lastButtonNumber, // number of mouse button which started drag (GdkEvent*) g_lastMouseEvent ); if ( !context ) { // this can happen e.g. if gdk_pointer_grab() failed return wxDragError; } m_dragContext = context; PrepareIcon( allowed_actions, context ); while (m_waiting) gtk_main_iteration(); g_signal_handlers_disconnect_by_func (m_iconWindow, (gpointer) gtk_dnd_window_configure_callback, this); return m_retValue; }
wxTreeListItem wxTreeListCtrl::GetRootItem() const { wxCHECK_MSG( m_model, wxTreeListItem(), "Must create first" ); return m_model->GetRootItem(); }
wxRibbonButtonBarButtonBase *wxRibbonButtonBar::GetItem(size_t n) const { wxCHECK_MSG(n < m_buttons.GetCount(), NULL, "wxRibbonButtonBar item's index is out of bound"); return m_buttons.Item(n); }
wxTreeListItem wxTreeListCtrl::GetFirstChild(wxTreeListItem item) const { wxCHECK_MSG( item.IsOk(), wxTreeListItem(), "Invalid item" ); return item->GetChild(); }
int wxRibbonButtonBar::GetItemId(wxRibbonButtonBarButtonBase *item) const { wxCHECK_MSG(item != NULL, wxNOT_FOUND, "wxRibbonButtonBar item should not be NULL"); return item->id; }
wxClientData* wxTreeListCtrl::GetItemData(wxTreeListItem item) const { wxCHECK_MSG( m_model, NULL, "Must create first" ); return m_model->GetItemData(item); }
int wxEventLoopManual::Run() { // event loops are not recursive, you need to create another loop! wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") ); // ProcessIdle() and ProcessEvents() below may throw so the code here should // be exception-safe, hence we must use local objects for all actions we // should undo wxEventLoopActivator activate(this); // we must ensure that OnExit() is called even if an exception is thrown // from inside ProcessEvents() but we must call it from Exit() in normal // situations because it is supposed to be called synchronously, // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or // something similar here) #if wxUSE_EXCEPTIONS for ( ;; ) { try { #endif // wxUSE_EXCEPTIONS // this is the event loop itself for ( ;; ) { // give them the possibility to do whatever they want OnNextIteration(); // generate and process idle events for as long as we don't // have anything else to do while ( !Pending() && ProcessIdle() ) ; // if the "should exit" flag is set, the loop should terminate // but not before processing any remaining messages so while // Pending() returns true, do process them if ( m_shouldExit ) { while ( Pending() ) ProcessEvents(); break; } // a message came or no more idle processing to do, dispatch // all the pending events and call Dispatch() to wait for the // next message if ( !ProcessEvents() ) { // we got WM_QUIT break; } } #if wxUSE_EXCEPTIONS // exit the outer loop as well break; } catch ( ... ) { try { if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() ) { OnExit(); break; } //else: continue running the event loop } catch ( ... ) { // OnException() throwed, possibly rethrowing the same // exception again: very good, but we still need OnExit() to // be called OnExit(); throw; } } } #endif // wxUSE_EXCEPTIONS return m_exitcode; }
wxCheckBoxState wxTreeListCtrl::GetCheckedState(wxTreeListItem item) const { wxCHECK_MSG( item.IsOk(), wxCHK_UNDETERMINED, "Invalid item" ); return item->m_checkedState; }
wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd) { wxCHECK_MSG( parent, NULL, _T("must have valid parent for a control") ); wxString str(wxGetWindowClass(hWnd)); str.UpperCase(); long id = wxGetWindowId(hWnd); long style = GetWindowLong((HWND) hWnd, GWL_STYLE); wxWindow* win = NULL; if (str == wxT("BUTTON")) { int style1 = (style & 0xFF); #if wxUSE_CHECKBOX if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) || (style1 == BS_CHECKBOX)) { win = new wxCheckBox; } else #endif #if wxUSE_RADIOBTN if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON)) { win = new wxRadioButton; } else #endif #if wxUSE_BMPBUTTON #if defined(__WIN32__) && defined(BS_BITMAP) if (style & BS_BITMAP) { // TODO: how to find the bitmap? win = new wxBitmapButton; wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button.")); } else #endif if (style1 == BS_OWNERDRAW) { // TODO: how to find the bitmap? // TODO: can't distinguish between bitmap button and bitmap static. // Change implementation of wxStaticBitmap to SS_BITMAP. // PROBLEM: this assumes that we're using resource-based bitmaps. // So maybe need 2 implementations of bitmap buttons/static controls, // with a switch in the drawing code. Call default proc if BS_BITMAP. win = new wxBitmapButton; } else #endif #if wxUSE_BUTTON if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON)) { win = new wxButton; } else #endif #if wxUSE_STATBOX if (style1 == BS_GROUPBOX) { win = new wxStaticBox; } else #endif { wxLogError(wxT("Don't know what kind of button this is: id = %ld"), id); } } #if wxUSE_COMBOBOX else if (str == wxT("COMBOBOX")) { win = new wxComboBox; } #endif #if wxUSE_TEXTCTRL // TODO: Problem if the user creates a multiline - but not rich text - text control, // since wxWin assumes RichEdit control for this. Should have m_isRichText in // wxTextCtrl. Also, convert as much of the window style as is necessary // for correct functioning. // Could have wxWindow::AdoptAttributesFromHWND(WXHWND) // to be overridden by each control class. else if (str == wxT("EDIT")) { win = new wxTextCtrl; } #endif #if wxUSE_LISTBOX else if (str == wxT("LISTBOX")) { win = new wxListBox; } #endif #if wxUSE_SCROLLBAR else if (str == wxT("SCROLLBAR")) { win = new wxScrollBar; } #endif #if wxUSE_SPINBTN else if (str == wxT("MSCTLS_UPDOWN32")) { win = new wxSpinButton; } #endif #if wxUSE_SLIDER else if (str == wxT("MSCTLS_TRACKBAR32")) { // Need to ascertain if it's horiz or vert win = new wxSlider; } #endif // wxUSE_SLIDER #if wxUSE_STATTEXT else if (str == wxT("STATIC")) { int style1 = (style & 0xFF); if ((style1 == SS_LEFT) || (style1 == SS_RIGHT) #ifndef __WXWINCE__ || (style1 == SS_SIMPLE) #endif ) win = new wxStaticText; #if wxUSE_STATBMP #if defined(__WIN32__) && defined(BS_BITMAP) else if (style1 == SS_BITMAP) { win = new wxStaticBitmap; // Help! this doesn't correspond with the wxWin implementation. wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons.")); } #endif #endif /* wxUSE_STATBMP */ } #endif else { wxString msg(wxT("Don't know how to convert from Windows class ")); msg += str; wxLogError(msg); } if (win) { parent->AddChild(win); win->SubclassWin(hWnd); win->AdoptAttributesFromHWND(); win->SetupColours(); } return win; }
wxClientData* wxTreeListModel::GetItemData(Node* item) const { wxCHECK_MSG( item, NULL, "Invalid item" ); return item->GetClientData(); }
unsigned char wxColour::Blue() const { wxCHECK_MSG( IsOk(), 0, wxT("invalid colour") ); return (unsigned char)(M_COLDATA->m_color.blue >> SHIFT); }
size_t wxStreamBuffer::Write(const void *buffer, size_t size) { wxASSERT_MSG( buffer, wxT("Warning: Null pointer is about to be send") ); if (m_stream) { // lasterror is reset before all new IO calls m_stream->Reset(); } size_t ret; if ( !HasBuffer() && m_fixed ) { wxOutputStream *outStream = GetOutputStream(); wxCHECK_MSG( outStream, 0, wxT("should have a stream in wxStreamBuffer") ); // no buffer, just forward the call to the stream ret = outStream->OnSysWrite(buffer, size); } else // we [may] have a buffer, use it { size_t orig_size = size; while ( size > 0 ) { size_t left = GetBytesLeft(); // if the buffer is too large to fit in the stream buffer, split // it in smaller parts // // NB: If stream buffer isn't fixed (as for wxMemoryOutputStream), // we always go to the second case. // // FIXME: fine, but if it fails we should (re)try writing it by // chunks as this will (hopefully) always work (VZ) if ( size > left && m_fixed ) { PutToBuffer(buffer, left); size -= left; buffer = (char *)buffer + left; if ( !FlushBuffer() ) { SetError(wxSTREAM_WRITE_ERROR); break; } m_buffer_pos = m_buffer_start; } else // we can do it in one gulp { PutToBuffer(buffer, size); size = 0; } } ret = orig_size - size; } if (m_stream) { // i am not entirely sure what we do this for m_stream->m_lastcount = ret; } return ret; }
int wxColour::GetPixel() const { wxCHECK_MSG( IsOk(), 0, wxT("invalid colour") ); return M_COLDATA->m_color.pixel; }
bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused) { wxCHECK_MSG( win, false, _T("wxSetFocusToChild(): invalid window") ); wxCHECK_MSG( childLastFocused, false, _T("wxSetFocusToChild(): NULL child poonter") ); if ( *childLastFocused ) { // It might happen that the window got reparented if ( (*childLastFocused)->GetParent() == win ) { wxLogTrace(TRACE_FOCUS, _T("SetFocusToChild() => last child (0x%p)."), (*childLastFocused)->GetHandle()); // not SetFocusFromKbd(): we're restoring focus back to the old // window and not setting it as the result of a kbd action (*childLastFocused)->SetFocus(); return true; } else { // it doesn't count as such any more *childLastFocused = (wxWindow *)NULL; } } // set the focus to the first child who wants it wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); while ( node ) { wxWindow *child = node->GetData(); node = node->GetNext(); #ifdef __WXMAC__ if ( child->GetParent()->MacIsWindowScrollbar( child ) ) continue; #endif if ( child->AcceptsFocusFromKeyboard() && !child->IsTopLevel() ) { #ifdef __WXMSW__ // If a radiobutton is the first focusable child, search for the // selected radiobutton in the same group wxRadioButton* btn = wxDynamicCast(child, wxRadioButton); if (btn) { wxRadioButton* selected = wxGetSelectedButtonInGroup(btn); if (selected) child = selected; } #endif wxLogTrace(TRACE_FOCUS, _T("SetFocusToChild() => first child (0x%p)."), child->GetHandle()); *childLastFocused = child; child->SetFocusFromKbd(); return true; } } return false; }
wxString wxFont::GetFaceName() const { wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") ); //knorr?? face?? // return fnt->Face(); }