Пример #1
0
void WeatherRouting::Reset()
{
    if(m_bRunning)
        Stop();

    for(int i=0; i<m_lWeatherRoutes->GetItemCount(); i++)
    {
        WeatherRoute *weatherroute =
            reinterpret_cast<WeatherRoute*>(wxUIntToPtr(m_lWeatherRoutes->GetItemData(i)));
        weatherroute->routemapoverlay->Reset();
    }

    GetParent()->Refresh();
}
Пример #2
0
void WeatherRouting::UpdateRouteMap(RouteMapOverlay *routemapoverlay)
{
    for(int i=0; i<m_lWeatherRoutes->GetItemCount(); i++)
    {
        WeatherRoute *weatherroute =
            reinterpret_cast<WeatherRoute*>(wxUIntToPtr(m_lWeatherRoutes->GetItemData(i)));
        if(weatherroute->routemapoverlay == routemapoverlay)
        {
            weatherroute->Update();
            UpdateItem(i);
            return;
        }
    }
}
Пример #3
0
/* static */
const wxChar *wxApp::GetRegisteredClassName(const wxChar *name,
                                            int bgBrushCol,
                                            int extraStyles)
{
    const size_t count = gs_regClassesInfo.size();
    for ( size_t n = 0; n < count; n++ )
    {
        if ( gs_regClassesInfo[n].regname == name )
            return gs_regClassesInfo[n].regname.c_str();
    }

    // we need to register this class
    WNDCLASS wndclass;
    wxZeroMemory(wndclass);

    wndclass.lpfnWndProc   = (WNDPROC)wxWndProc;
    wndclass.hInstance     = wxGetInstance();
    wndclass.hCursor       = ::LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)wxUIntToPtr(bgBrushCol + 1);
    wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles;


    ClassRegInfo regClass(name);
    wndclass.lpszClassName = regClass.regname.t_str();
    if ( !::RegisterClass(&wndclass) )
    {
        wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"),
                       regClass.regname));
        return NULL;
    }

    wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW);
    wndclass.lpszClassName = regClass.regnameNR.t_str();
    if ( !::RegisterClass(&wndclass) )
    {
        wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"),
                       regClass.regname));
        ::UnregisterClass(regClass.regname.c_str(), wxGetInstance());
        return NULL;
    }

    gs_regClassesInfo.push_back(regClass);

    // take care to return the pointer which will remain valid after the
    // function returns (it could be invalidated later if new elements are
    // added to the vector and it's reallocated but this shouldn't matter as
    // this pointer should be used right now, not stored)
    return gs_regClassesInfo.back().regname.t_str();
}
Пример #4
0
void WeatherRouting::UpdateConfigurations()
{
    for(int i=0; i<m_lWeatherRoutes->GetItemCount(); i++)
    {
        WeatherRoute *weatherroute =
        reinterpret_cast<WeatherRoute*>(wxUIntToPtr(m_lWeatherRoutes->GetItemData(i)));

        /* get and set configuration to update start/end positions */
        RouteMapConfiguration c = weatherroute->routemapoverlay->GetConfiguration();
        weatherroute->routemapoverlay->SetConfiguration(c);

        weatherroute->Update(true);
        UpdateItem(i);
    }
}
Пример #5
0
void DialogAttachments::OnDelete(wxCommandEvent &) {
	int i = listView->GetFirstSelected();
	if (i == -1) return;

	while (i != -1) {
		delete (AssEntry*)wxUIntToPtr(listView->GetItemData(i));
		i = listView->GetNextSelected(i);
	}

	ass->Commit(_("remove attachment"), AssFile::COMMIT_ATTACHMENT);

	UpdateList();
	extractButton->Enable(false);
	deleteButton->Enable(false);
}
Пример #6
0
void bmx_wxlistitem_setdata(MaxListItem * item, BBObject * data) {
	if (item->Item().GetColumn() == 0) {
		// is there any data here already?
		BBObject * oldData = (BBObject *)wxUIntToPtr(item->Item().GetData());
		if (oldData && (oldData != &bbNullObject)) {
			BBRELEASE(oldData);
			item->Item().SetData((void*)NULL);
		}
	
		if (data != &bbNullObject) {
			BBRETAIN( data );
		}
		item->Item().SetData(wxPtrToUInt((void*)data));
	}
}
Пример #7
0
void WeatherRouting::OnNew( wxCommandEvent& event )
{
    RouteMapConfiguration configuration;
    if(CurrentRouteMap())
        configuration = CurrentRouteMap()->GetConfiguration();
    else
        configuration = DefaultConfiguration();

#if 0 /* to have a unique name */
    for(int idx = 0;;idx++)
    {
        wxString name = configuration.Name;
        wxString n1 = name.BeforeLast('-'), n2 = name.AfterLast('-');
        long l;
        if(n1.size() && n2.ToLong(&l))
            name = n1;

        if(idx > 0)
            name += wxString::Format(_T("-%d"), idx);
        for(int i=0; i<m_lWeatherRoutes->GetItemCount(); i++)
        {
            WeatherRoute *weatherroute =
                reinterpret_cast<WeatherRoute*>(wxUIntToPtr(m_lWeatherRoutes->GetItemData(i)));
            RouteMapConfiguration c = weatherroute->routemapoverlay->GetConfiguration();
            if(c.Name == name)
                goto outer_continue;
        }
        configuration.Name = name;
        break;
outer_continue:
    }
#endif

    AddConfiguration(configuration);

    m_lWeatherRoutes->SetItemState(m_lWeatherRoutes->GetItemCount() - 1,
                                   wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);

    OnEditConfiguration();
}

void WeatherRouting::OnBatch( wxCommandEvent& event )
{
    m_ConfigurationBatchDialog.Reset();
    m_ConfigurationBatchDialog.Show();
}
void InternetRetrievalDialog::UpdateItem(long index)
{
    FaxUrl *url = reinterpret_cast<FaxUrl*>
        (wxUIntToPtr(m_lUrls->GetItemData(index)));

    m_lUrls->SetItemImage(index, url->Selected ? 0 : -1);
    m_lUrls->SetColumnWidth(SELECTED, 50);

    m_lUrls->SetItem(index, SERVER, url->Server);
    m_lUrls->SetColumnWidth(SERVER, 100 /*wxLIST_AUTOSIZE*/);

    m_lUrls->SetItem(index, CONTENTS, url->Contents);
    m_lUrls->SetColumnWidth(CONTENTS, 350 /*wxLIST_AUTOSIZE*/);

    m_lUrls->SetItem(index, MAP_AREA, _T("")/*url->Area.AreaDescription()*/);
    m_lUrls->SetColumnWidth(MAP_AREA, 150);
}
Пример #9
0
RouteMapOverlay *WeatherRouting::CurrentRouteMap(bool messagedialog)
{
    long index = m_lWeatherRoutes->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
    RouteMapOverlay *routemapoverlay = NULL;
    if (index >= 0)
        routemapoverlay = reinterpret_cast<WeatherRoute*>
            (wxUIntToPtr(m_lWeatherRoutes->GetItemData(index)))->routemapoverlay;

    if(messagedialog && !routemapoverlay)
    {
        wxMessageDialog mdlg(this, _("No Weather Route selected"),
                             _("Weather Routing"), wxOK | wxICON_WARNING);
        mdlg.ShowModal();
    }

    return routemapoverlay;
}
void InternetRetrievalDialog::OnUrlsLeftDown( wxMouseEvent& event )
{
    wxPoint pos = event.GetPosition();
    int flags = 0;
    long index = m_lUrls->HitTest(pos, flags);
    
    if (index > -1 && event.GetX() < m_lUrls->GetColumnWidth(0))
    {
        // Process the clicked item
        FaxUrl *url =
            reinterpret_cast<FaxUrl*>(wxUIntToPtr(m_lUrls->GetItemData(index)));
        url->Selected = !url->Selected;

        m_lUrls->SetItemImage(index, url->Selected ? 0 : -1);
    }

    // Allow wx to process...
    event.Skip();
}
void CelestialNavigationDialog::OnEdit( )
{
    // Manipulate selected_index sight/track
    long selected_index = m_lSights->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
    if (selected_index < 0) return;

    Sight *psight = (Sight*)wxUIntToPtr(m_lSights->GetItemData(selected_index));
    Sight originalsight = *psight; /* in case of cancel */
    
    SightDialog dialog(GetParent(), *psight, m_ClockCorrectionDialog.m_sClockCorrection->GetValue());
    
    if( dialog.ShowModal() == wxID_OK ) {
        dialog.Recompute();
        psight->RebuildPolygons();
        UpdateSight(selected_index);
    } else
        *psight = originalsight;

    RequestRefresh( GetParent() );
}
Пример #12
0
void WeatherRouting::OnWeatherRoutesListLeftDown(wxMouseEvent &event)
{
    wxPoint pos = event.GetPosition();
    int flags = 0;
    long index = m_lWeatherRoutes->HitTest(pos, flags);

    //    Clicking Visibility column?
    if (index > -1 && event.GetX() < m_lWeatherRoutes->GetColumnWidth(0))
    {
        // Process the clicked item
        WeatherRoute *weatherroute =
            reinterpret_cast<WeatherRoute*>(wxUIntToPtr(m_lWeatherRoutes->GetItemData(index)));
        weatherroute->routemapoverlay->m_bEndRouteVisible =
            !weatherroute->routemapoverlay->m_bEndRouteVisible;
        UpdateItem(index);
        RequestRefresh( GetParent() );
    }

    // Allow wx to process...
    event.Skip();
}
void InternetRetrievalDialog::OnUrlsSort( wxListEvent& event )
{
    sortcol = event.GetColumn();
    sortorder = -sortorder;

    if(sortcol == 0) {
        for(int i=0; i < m_lUrls->GetItemCount(); i++) {
            FaxUrl *faxurl = reinterpret_cast<FaxUrl*>
                (wxUIntToPtr(m_lUrls->GetItemData(i)));

            faxurl->Scheduled = sortorder == 1;
            UpdateItem(i);
        }
    } else
        if(m_lUrls->GetItemCount() > 500)  {
            wxMessageDialog mdlg(this, _("Sorting this many urls might take too long"),
                                 _("weatherfax"), wxOK | wxICON_ERROR);
            mdlg.ShowModal();
        } else
            m_lUrls->SortItems(SortUrl, (long)m_lUrls);
}
Пример #14
0
	void onAnnouncement(Announcer* announcer, string event_name, MemChunk& event_data)
	{
		if (announcer != entry->getParent())
			return;

		bool finished = false;

		// Entry removed
		if (event_name == "entry_removed")
		{
			int index;
			wxUIntPtr ptr;
			event_data.read(&index, sizeof(int));
			event_data.read(&ptr, sizeof(wxUIntPtr));
			if (wxUIntToPtr(ptr) == entry)
				finished = true;
		}

		if (finished)
			delete this;
	}
Пример #15
0
void WeatherRouting::DeleteRouteMap(RouteMapOverlay *routemapoverlay)
{
    for(std::list<RouteMapOverlay*>::iterator it = m_WaitingRouteMaps.begin();
        it != m_WaitingRouteMaps.end(); it++)
        if(*it == routemapoverlay)
        {
            m_WaitingRouteMaps.erase(it);
            break;
        }

    for(std::list<RouteMapOverlay*>::iterator it = m_RunningRouteMaps.begin();
        it != m_RunningRouteMaps.end(); it++)
        if(*it == routemapoverlay)
        {
            m_RunningRouteMaps.erase(it);
            break;
        }

    for(int i=0; i<m_lWeatherRoutes->GetItemCount(); i++)
    {
        WeatherRoute *weatherroute =
            reinterpret_cast<WeatherRoute*>(wxUIntToPtr(m_lWeatherRoutes->GetItemData(i)));
        if(weatherroute->routemapoverlay == routemapoverlay)
        {
            m_lWeatherRoutes->DeleteItem(i);
            break;
        }
    }

    for(std::list<WeatherRoute*>::iterator it = m_WeatherRoutes.begin();
        it != m_WeatherRoutes.end(); it++)
        if((*it)->routemapoverlay == routemapoverlay)
        {
            delete *it;
            m_WeatherRoutes.erase(it);
            break;
        }

    SetEnableConfigurationMenu();
}
Пример #16
0
void ItemContainerTestCase::VoidData()
{
    wxItemContainer * const container = GetContainer();

    wxString item0data("item0data"), item1data("item0data"),
             item2data("item0data");

    void* item0 = &item0data;
    void* item1 = &item1data;
    void* item2 = &item2data;

    container->Append("item 0", item0);

    CPPUNIT_ASSERT_EQUAL(item0, container->GetClientData(0));

    container->Append("item 1");
    container->SetClientData(1, item1);

    CPPUNIT_ASSERT_EQUAL(item1, container->GetClientData(1));

    container->Insert("item 2", 2, item2);

    CPPUNIT_ASSERT_EQUAL(item2, container->GetClientData(2));

    WX_ASSERT_FAILS_WITH_ASSERT( container->SetClientData((unsigned)-1, NULL) );
    WX_ASSERT_FAILS_WITH_ASSERT( container->SetClientData(12345, NULL) );

    // wxMSW used to hace problems retrieving the client data of -1 from a few
    // standard controls, especially if the last error was set before doing it,
    // so test for this specially.
    const wxUIntPtr minus1 = static_cast<wxUIntPtr>(-1);
    container->Append("item -1", wxUIntToPtr(minus1));

#ifdef __WINDOWS__
    ::SetLastError(ERROR_INVALID_DATA);
#endif

    CPPUNIT_ASSERT_EQUAL( minus1, wxPtrToUInt(container->GetClientData(3)) );
}
Пример #17
0
void WeatherRouting::OnExportAll( wxCommandEvent& event )
{
    for(int i=0; i<m_lWeatherRoutes->GetItemCount(); i++)
        Export(*reinterpret_cast<WeatherRoute*>
               (wxUIntToPtr(m_lWeatherRoutes->GetItemData(i)))->routemapoverlay);
}
Пример #18
0
// log all kinds of messages
void wxLogGui::DoLogRecord(wxLogLevel level,
                           const wxString& msg,
                           const wxLogRecordInfo& info)
{
    switch ( level )
    {
        case wxLOG_Info:
        case wxLOG_Message:
            {
                m_aMessages.Add(msg);
                m_aSeverity.Add(wxLOG_Message);
                m_aTimes.Add((long)info.timestamp);
                m_bHasMessages = true;
            }
            break;

        case wxLOG_Status:
#if wxUSE_STATUSBAR
            {
                wxFrame *pFrame = NULL;

                // check if the frame was passed to us explicitly
                wxUIntPtr ptr = 0;
                if ( info.GetNumValue(wxLOG_KEY_FRAME, &ptr) )
                {
                    pFrame = static_cast<wxFrame *>(wxUIntToPtr(ptr));
                }

                // find the top window and set it's status text if it has any
                if ( pFrame == NULL ) {
                    wxWindow *pWin = wxTheApp->GetTopWindow();
                    if ( wxDynamicCast(pWin, wxFrame) ) {
                        pFrame = (wxFrame *)pWin;
                    }
                }

                if ( pFrame && pFrame->GetStatusBar() )
                    pFrame->SetStatusText(msg);
            }
#endif // wxUSE_STATUSBAR
            break;

        case wxLOG_Error:
            if ( !m_bErrors ) {
#if !wxUSE_LOG_DIALOG
                // discard earlier informational messages if this is the 1st
                // error because they might not make sense any more and showing
                // them in a message box might be confusing
                m_aMessages.Empty();
                m_aSeverity.Empty();
                m_aTimes.Empty();
#endif // wxUSE_LOG_DIALOG
                m_bErrors = true;
            }
            wxFALLTHROUGH;

        case wxLOG_Warning:
            if ( !m_bErrors ) {
                // for the warning we don't discard the info messages
                m_bWarnings = true;
            }

            m_aMessages.Add(msg);
            m_aSeverity.Add((int)level);
            m_aTimes.Add((long)info.timestamp);
            m_bHasMessages = true;
            break;

        case wxLOG_Debug:
        case wxLOG_Trace:
            // let the base class deal with debug/trace messages
            wxLog::DoLogRecord(level, msg, info);
            break;

        case wxLOG_FatalError:
        case wxLOG_Max:
            // fatal errors are shown immediately and terminate the program so
            // we should never see them here
            wxFAIL_MSG("unexpected log level");
            break;

        case wxLOG_Progress:
        case wxLOG_User:
            // just ignore those: passing them to the base class would result
            // in asserts from DoLogText() because DoLogTextAtLevel() would
            // call it as it doesn't know how to handle these levels otherwise
            break;
    }
}
void InternetRetrievalDialog::OnRetrieve( wxCommandEvent& event )
{
    int count = 0;
    for(int i=0; i < m_lUrls->GetItemCount(); i++) {
        FaxUrl *faxurl = reinterpret_cast<FaxUrl*>
            (wxUIntToPtr(m_lUrls->GetItemData(i)));

        if(event.GetEventObject() == m_bRetrieveScheduled) {
            if(!faxurl->Scheduled)
                continue;
        } else
            if(m_lUrls->GetNextItem(i - 1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != i)
                continue;

        count++;

        wxString path = weatherfax_pi::StandardPath();

        wxString filename = faxurl->Url;
        filename.Replace(_T("/"), _T("!"));
        filename.Replace(_T(":"), _T("!"));

        filename = path + wxFileName::GetPathSeparator() + filename;

        wxFileName fn(filename);
        if(fn.FileExists() && (wxDateTime::Now() - fn.GetModificationTime()).GetMinutes() < 180) {
            wxMessageDialog mdlg(this, _("Fax already retrieved less than 180 minutes ago.\n\
Use existing file?"), _("Weather Fax"), wxYES | wxNO | wxCANCEL);
            switch(mdlg.ShowModal()) {
            case wxID_YES:
                goto loadimage;
            case wxID_NO:
                break;
            default:
                return;
            }
        }

        {
#if 0
            wxProgressDialog progressdialog(_("WeatherFax InternetRetrieval"),
                                            _("Reading Headers: ") + faxurl->Contents, 1000, this,
                                            wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME);
            progressdialog.Update(0);
            
            DownloadThread *dl = new DownloadThread(faxurl->Url, filename);
            dl->Run();

            while(dl->IsRunning()) {
                bool ok;
                if(dl->size)
                    ok = progressdialog.Update(1000*dl->position / dl->size,
                                               _("Reading") + wxString(_T(": "))
                                               + faxurl->Contents);
                else
                    ok = progressdialog.Update(0);
                if(!ok) {
                    dl->please_quit = true;
                    return;
                }
                wxThread::Sleep(250);
            }

            dl->please_quit = true;

            switch(dl->exitcode) {
            case 1:
            case 2:
            {
                wxMessageDialog mdlg(this, _("Timed out waiting for headers for: ") +
                                     faxurl->Contents + _T("\n") + faxurl->Url + _T("\n") +
                                     _("Verify there is a working internet connection.") + _T("\n") +
                                     _("Possibly the server is down temporarily.") + _T("\n") +
                                     _("If the url is incorrect please edit the xml and/or post a bug report."),
                                     _("Weather Fax"), wxOK | wxICON_ERROR);
                mdlg.ShowModal();
            } return;
            case 3:
            { wxMessageDialog mdlg(this, _("Failed to read file size aborting."),
                                     _("Weather Fax"), wxOK | wxICON_INFORMATION);
                mdlg.ShowModal();
            } return;
            }
#else

        wxFileOutputStream output(filename);
        wxCurlDownloadDialog ddlg(faxurl->Url, &output, _("WeatherFax InternetRetrieval"),
                                  _("Reading Headers: ") + faxurl->Contents, wxNullBitmap, this,
                                  wxCTDS_CAN_PAUSE|wxCTDS_CAN_ABORT|wxCTDS_SHOW_ALL|wxCTDS_AUTO_CLOSE);

        switch(ddlg.RunModal()) {
        case wxCDRF_SUCCESS: break;
        case wxCDRF_FAILED:
        {
            wxMessageDialog mdlg(this, _("Failed to Download: ") +
                                 faxurl->Contents + _T("\n") +
                                 faxurl->Url + _T("\n") +
                                 _("Verify there is a working internet connection.") + _T("\n") +
                                 _("If the url is incorrect please edit the xml and/or post a bug report."),
                                 _("Weather Fax"), wxOK | wxICON_ERROR);
            mdlg.ShowModal();
            wxRemoveFile( filename );
        }
        case wxCDRF_USER_ABORTED: return;
        }
#endif
    }

    loadimage:
        m_weatherfax_pi.m_pWeatherFax->OpenImage
            (filename, faxurl->Server + _T(" - ") + faxurl->Region, faxurl->area_name, faxurl->Contents);

    }
Пример #20
0
void wxStackWalker::WalkFrom(const CONTEXT *pCtx, size_t skip, size_t maxDepth)
{
    if ( !wxDbgHelpDLL::Init() )
    {
        // don't log a user-visible error message here because the stack trace
        // is only needed for debugging/diagnostics anyhow and we shouldn't
        // confuse the user by complaining that we couldn't generate it
        wxLogDebug(wxT("Failed to get stack backtrace: %s"),
                   wxDbgHelpDLL::GetErrorMessage().c_str());
        return;
    }

    // according to MSDN, the first parameter should be just a unique value and
    // not process handle (although the parameter is prototyped as "HANDLE
    // hProcess") and actually it advises to use the process id and not handle
    // for Win9x, but then we need to use the same value in StackWalk() call
    // below which should be a real handle... so this is what we use
    const HANDLE hProcess = ::GetCurrentProcess();

    if ( !wxDbgHelpDLL::SymInitialize
                        (
                            hProcess,
                            NULL,   // use default symbol search path
                            TRUE    // load symbols for all loaded modules
                        ) )
    {
        wxDbgHelpDLL::LogError(wxT("SymInitialize"));

        return;
    }

    CONTEXT ctx = *pCtx; // will be modified by StackWalk()

    DWORD dwMachineType;

    // initialize the initial frame: currently we can do it for x86 only
    STACKFRAME sf;
    wxZeroMemory(sf);

#ifdef _M_IX86
    sf.AddrPC.Offset       = ctx.Eip;
    sf.AddrPC.Mode         = AddrModeFlat;
    sf.AddrStack.Offset    = ctx.Esp;
    sf.AddrStack.Mode      = AddrModeFlat;
    sf.AddrFrame.Offset    = ctx.Ebp;
    sf.AddrFrame.Mode      = AddrModeFlat;

    dwMachineType = IMAGE_FILE_MACHINE_I386;
#else
    #error "Need to initialize STACKFRAME on non x86"
#endif // _M_IX86

    // iterate over all stack frames
    for ( size_t nLevel = 0; nLevel < maxDepth; nLevel++ )
    {
        // get the next stack frame
        if ( !wxDbgHelpDLL::StackWalk
                            (
                                dwMachineType,
                                hProcess,
                                ::GetCurrentThread(),
                                &sf,
                                &ctx,
                                NULL,       // read memory function (default)
                                wxDbgHelpDLL::SymFunctionTableAccess,
                                wxDbgHelpDLL::SymGetModuleBase,
                                NULL        // address translator for 16 bit
                            ) )
        {
            if ( ::GetLastError() )
                wxDbgHelpDLL::LogError(wxT("StackWalk"));

            break;
        }

        // don't show this frame itself in the output
        if ( nLevel >= skip )
        {
            wxStackFrame frame(nLevel - skip,
                               wxUIntToPtr(sf.AddrPC.Offset),
                               sf.AddrFrame.Offset);

            OnStackFrame(frame);
        }
    }

    if ( !wxDbgHelpDLL::SymCleanup(hProcess) )
    {
        wxDbgHelpDLL::LogError(wxT("SymCleanup"));
    }
}
Пример #21
0
/* static */
const wxChar *wxApp::GetRegisteredClassName(const wxChar *name,
                                            int bgBrushCol,
                                            int extraStyles)
{
    const size_t count = gs_regClassesInfo.size();
    for ( size_t n = 0; n < count; n++ )
    {
        if ( gs_regClassesInfo[n].basename == name )
            return gs_regClassesInfo[n].regname.c_str();
    }

    // we need to register this class
    WNDCLASS wndclass;
    wxZeroMemory(wndclass);

    wndclass.lpfnWndProc   = (WNDPROC)wxWndProc;
    wndclass.hInstance     = wxGetInstance();
    wndclass.hCursor       = ::LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)wxUIntToPtr(bgBrushCol + 1);
    wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles;


    ClassRegInfo regClass;
    regClass.basename = name;

    // constuct a unique suffix to allow registering the class with the same
    // base name in a main application using wxWidgets and a DLL using
    // wxWidgets loaded into its address space: as gs_regClassesInfo variable
    // is different in them, we're going to obtain a unique prefix by using its
    // address here
    regClass.regname = regClass.basename +
                            wxString::Format(wxT("@%p"), &gs_regClassesInfo);
    wndclass.lpszClassName = regClass.regname.wx_str();
    if ( !::RegisterClass(&wndclass) )
    {
        wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"),
                       regClass.regname));
        return NULL;
    }

    // NB: remember that code elsewhere supposes that no redraw class names
    //     use the same names as normal classes with "NR" suffix so we must put
    //     "NR" at the end instead of using more natural basename+"NR"+suffix
    regClass.regnameNR = regClass.regname + GetNoRedrawClassSuffix();
    wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW);
    wndclass.lpszClassName = regClass.regnameNR.wx_str();
    if ( !::RegisterClass(&wndclass) )
    {
        wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"),
                       regClass.regname));
        ::UnregisterClass(regClass.regname.c_str(), wxGetInstance());
        return NULL;
    }

    gs_regClassesInfo.push_back(regClass);

    // take care to return the pointer which will remain valid after the
    // function returns (it could be invalidated later if new elements are
    // added to the vector and it's reallocated but this shouldn't matter as
    // this pointer should be used right now, not stored)
    return gs_regClassesInfo.back().regname.wx_str();
}
Пример #22
0
bool wxControl::MSWCreateControl(const wxChar *classname,
                                 WXDWORD style,
                                 const wxPoint& pos,
                                 const wxSize& size,
                                 const wxString& label,
                                 WXDWORD exstyle)
{
    // if no extended style given, determine it ourselves
    if ( exstyle == (WXDWORD)-1 )
    {
        exstyle = 0;
        (void) MSWGetStyle(GetWindowStyle(), &exstyle);
    }

    // all controls should have this style
    style |= WS_CHILD;

    // create the control visible if it's currently shown for wxWidgets
    if ( m_isShown )
    {
        style |= WS_VISIBLE;
    }

    // choose the position for the control: we have a problem with default size
    // here as we can't calculate the best size before the control exists
    // (DoGetBestSize() may need to use m_hWnd), so just choose the minimal
    // possible but non 0 size because 0 window width/height result in problems
    // elsewhere
    int x = pos.x == wxDefaultCoord ? 0 : pos.x,
        y = pos.y == wxDefaultCoord ? 0 : pos.y,
        w = size.x == wxDefaultCoord ? 1 : size.x,
        h = size.y == wxDefaultCoord ? 1 : size.y;

    // ... and adjust it to account for a possible parent frames toolbar
    AdjustForParentClientOrigin(x, y);

    m_hWnd = (WXHWND)::CreateWindowEx
                       (
                        exstyle,            // extended style
                        classname,          // the kind of control to create
                        label.t_str(),      // the window name
                        style,              // the window style
                        x, y, w, h,         // the window position and size
                        GetHwndOf(GetParent()),         // parent
                        (HMENU)wxUIntToPtr(GetId()),    // child id
                        wxGetInstance(),    // app instance
                        NULL                // creation parameters
                       );

    if ( !m_hWnd )
    {
        wxLogLastError(wxString::Format
                       (
                        wxT("CreateWindowEx(\"%s\", flags=%08lx, ex=%08lx)"),
                        classname, style, exstyle
                       ));

        return false;
    }

#if !wxUSE_UNICODE
    // Text labels starting with the character 0xff (which is a valid character
    // in many code pages) don't appear correctly as CreateWindowEx() has some
    // special treatment for this case, apparently the strings starting with -1
    // are not really strings but something called "ordinals". There is no
    // documentation about it but the fact is that the label gets mangled or
    // not displayed at all if we don't do this, see #9572.
    //
    // Notice that 0xffff is not a valid Unicode character so the problem
    // doesn't arise in Unicode build.
    if ( !label.empty() && label[0] == -1 )
        ::SetWindowText(GetHwnd(), label.t_str());
#endif // !wxUSE_UNICODE

    // saving the label in m_labelOrig to return it verbatim
    // later in GetLabel()
    m_labelOrig = label;

    // install wxWidgets window proc for this window
    SubclassWin(m_hWnd);

    // set up fonts and colours
    InheritAttributes();
    if ( !m_hasFont )
    {
        bool setFont = true;

        wxFont font = GetDefaultAttributes().font;

        // if we set a font for {list,tree}ctrls and the font size is changed in
        // the display properties then the font size for these controls doesn't
        // automatically adjust when they receive WM_SETTINGCHANGE

        // FIXME: replace the dynamic casts with virtual function calls!!
#if wxUSE_LISTCTRL || wxUSE_TREECTRL
        bool testFont = false;
#if wxUSE_LISTCTRL
        if ( wxDynamicCastThis(wxListCtrl) )
            testFont = true;
#endif // wxUSE_LISTCTRL
#if wxUSE_TREECTRL
        if ( wxDynamicCastThis(wxTreeCtrl) )
            testFont = true;
#endif // wxUSE_TREECTRL

        if ( testFont )
        {
            // not sure if we need to explicitly set the font here for Win95/NT4
            // but we definitely can't do it for any newer version
            // see wxGetCCDefaultFont() in src/msw/settings.cpp for explanation
            // of why this test works

            // TODO: test Win95/NT4 to see if this is needed or breaks the
            // font resizing as it does on newer versions
            if ( font != wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) )
            {
                setFont = false;
            }
        }
#endif // wxUSE_LISTCTRL || wxUSE_TREECTRL

        if ( setFont )
        {
            SetFont(GetDefaultAttributes().font);
        }
    }

    // set the size now if no initial size specified
    SetInitialSize(size);

    return true;
}
Пример #23
0
bool wxRadioBox::Create(wxWindow *parent,
                        wxWindowID id,
                        const wxString& title,
                        const wxPoint& pos,
                        const wxSize& size,
                        int n,
                        const wxString choices[],
                        int majorDim,
                        long style,
                        const wxValidator& val,
                        const wxString& name)
{
    // common initialization
    if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) )
        return false;

    // the code elsewhere in this file supposes that either wxRA_SPECIFY_COLS
    // or wxRA_SPECIFY_ROWS is set, ensure that this is indeed the case
    if ( !(style & (wxRA_SPECIFY_ROWS | wxRA_SPECIFY_COLS)) )
        style |= wxRA_SPECIFY_COLS;

#if wxUSE_VALIDATORS
    SetValidator(val);
#else
    wxUnusedVar(val);
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS

    // We need an extra one to keep track of the 'dummy' item we
    // create to end the radio group, so it will be destroyed and
    // it's id will be released.  But we want it separate from the
    // other buttons since the wxSubwindows will operate on it as
    // well and we just want to ignore it until destroying it.
    // For instance, we don't want the bounding box of the radio
    // buttons to include the dummy button
    m_radioButtons = new wxSubwindows(n);

    m_radioWidth = new int[n];
    m_radioHeight = new int[n];

    for ( int i = 0; i < n; i++ )
    {
        m_radioWidth[i] =
        m_radioHeight[i] = wxDefaultCoord;
        long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
        if ( i == 0 )
            styleBtn |= WS_GROUP;

        wxWindowIDRef subid = NewControlId();

        HWND hwndBtn = ::CreateWindow(wxT("BUTTON"),
                                      choices[i].wx_str(),
                                      styleBtn,
                                      0, 0, 0, 0,   // will be set in SetSize()
                                      GetHwndOf(parent),
                                      (HMENU)wxUIntToPtr(subid.GetValue()),
                                      wxGetInstance(),
                                      NULL);

        if ( !hwndBtn )
        {
            wxLogLastError(wxT("CreateWindow(radio btn)"));

            return false;
        }

        // Keep track of the subwindow
        m_radioButtons->Set(i, hwndBtn, subid);

        SubclassRadioButton((WXHWND)hwndBtn);

        // Also, make it a subcontrol of this control
        m_subControls.Add(subid);
    }

    // Create a dummy radio control to end the group.
    m_dummyId = NewControlId();

    m_dummyHwnd = (WXHWND)::CreateWindow(wxT("BUTTON"),
                         wxEmptyString,
                         WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
                         0, 0, 0, 0, GetHwndOf(parent),
                         (HMENU)wxUIntToPtr(m_dummyId.GetValue()),
                         wxGetInstance(), NULL);


    m_radioButtons->SetFont(GetFont());

#ifdef __WXWINCE__
    // Set the z-order correctly
    SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
#endif

    SetMajorDim(majorDim == 0 ? n : majorDim, style);
    SetSelection(0);
    SetSize(pos.x, pos.y, size.x, size.y);

    // Now that we have items determine what is the best size and set it.
    SetInitialSize(size);

    return true;
}
Пример #24
0
bool wxToolTip::AdjustMaxWidth()
{
    // use TTM_SETMAXTIPWIDTH to make tooltip multiline using the
    // extent of its first line as max value
    HFONT hfont = (HFONT)
        SendTooltipMessage(GetToolTipCtrl(), WM_GETFONT, 0);

    if ( !hfont )
    {
        hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
        if ( !hfont )
        {
            wxLogLastError(wxT("GetStockObject(DEFAULT_GUI_FONT)"));
        }
    }

    MemoryHDC hdc;
    if ( !hdc )
    {
        wxLogLastError(wxT("CreateCompatibleDC(NULL)"));
    }

    if ( !SelectObject(hdc, hfont) )
    {
        wxLogLastError(wxT("SelectObject(hfont)"));
    }

    // find the width of the widest line
    int maxWidth = 0;
    wxStringTokenizer tokenizer(m_text, wxT("\n"));
    while ( tokenizer.HasMoreTokens() )
    {
        const wxString token = tokenizer.GetNextToken();

        SIZE sz;
        if ( !::GetTextExtentPoint32(hdc, token.t_str(),
                                     token.length(), &sz) )
        {
            wxLogLastError(wxT("GetTextExtentPoint32"));
        }

        if ( sz.cx > maxWidth )
            maxWidth = sz.cx;
    }

    // limit size to ms_maxWidth, if set
    if ( ms_maxWidth == 0 )
    {
        // this is more or less arbitrary but seems to work well
        static const int DEFAULT_MAX_WIDTH = 400;

        ms_maxWidth = wxGetClientDisplayRect().width / 2;

        if ( ms_maxWidth > DEFAULT_MAX_WIDTH )
            ms_maxWidth = DEFAULT_MAX_WIDTH;
    }

    if ( ms_maxWidth != -1 && maxWidth > ms_maxWidth )
        maxWidth = ms_maxWidth;

    // only set a new width if it is bigger than the current setting:
    // otherwise adding a tooltip with shorter line(s) than a previous
    // one would result in breaking the longer lines unnecessarily as
    // all our tooltips share the same maximal width
    if ( maxWidth > SendTooltipMessage(GetToolTipCtrl(),
                                       TTM_GETMAXTIPWIDTH, 0) )
    {
        SendTooltipMessage(GetToolTipCtrl(), TTM_SETMAXTIPWIDTH,
                           wxUIntToPtr(maxWidth));
    }

    return true;
}
Пример #25
0
void MakeKeyValuePair(size_t i, size_t count, T*& key, ValueT& value)
{
    key = (T*)wxUIntToPtr(MakeKey<wxUIntPtr, T*>(i, count));
    value = wx_truncate_cast(ValueT, key);
}
Пример #26
0
void wxToolTip::Add(WXHWND hWnd)
{
    HWND hwnd = (HWND)hWnd;

    wxToolInfo ti(hwnd, m_id, m_rect);

    // another possibility would be to specify LPSTR_TEXTCALLBACK here as we
    // store the tooltip text ourselves anyhow, and provide it in response to
    // TTN_NEEDTEXT (sent via WM_NOTIFY), but then we would be limited to 79
    // character tooltips as this is the size of the szText buffer in
    // NMTTDISPINFO struct -- and setting the tooltip here we can have tooltips
    // of any length
    ti.hwnd = hwnd;
    ti.lpszText = const_cast<wxChar *>(m_text.wx_str());

    if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL, &ti) )
    {
        wxLogDebug(wxT("Failed to create the tooltip '%s'"), m_text.c_str());

        return;
    }

#ifdef TTM_SETMAXTIPWIDTH
    if ( wxApp::GetComCtl32Version() >= 470 )
    {
        // use TTM_SETMAXTIPWIDTH to make tooltip multiline using the
        // extent of its first line as max value
        HFONT hfont = (HFONT)
            SendTooltipMessage(GetToolTipCtrl(), WM_GETFONT, 0);

        if ( !hfont )
        {
            hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            if ( !hfont )
            {
                wxLogLastError(wxT("GetStockObject(DEFAULT_GUI_FONT)"));
            }
        }

        MemoryHDC hdc;
        if ( !hdc )
        {
            wxLogLastError(wxT("CreateCompatibleDC(NULL)"));
        }

        if ( !SelectObject(hdc, hfont) )
        {
            wxLogLastError(wxT("SelectObject(hfont)"));
        }

        // find the width of the widest line
        int maxWidth = 0;
        wxStringTokenizer tokenizer(m_text, wxT("\n"));
        while ( tokenizer.HasMoreTokens() )
        {
            const wxString token = tokenizer.GetNextToken();

            SIZE sz;
            if ( !::GetTextExtentPoint32(hdc, token.wx_str(),
                                         token.length(), &sz) )
            {
                wxLogLastError(wxT("GetTextExtentPoint32"));
            }

            if ( sz.cx > maxWidth )
                maxWidth = sz.cx;
        }

        // limit size to ms_maxWidth, if set
        if ( ms_maxWidth == 0 )
        {
            // this is more or less arbitrary but seems to work well
            static const int DEFAULT_MAX_WIDTH = 400;

            ms_maxWidth = wxGetClientDisplayRect().width / 2;

            if ( ms_maxWidth > DEFAULT_MAX_WIDTH )
                ms_maxWidth = DEFAULT_MAX_WIDTH;
        }

        if ( ms_maxWidth != -1 && maxWidth > ms_maxWidth )
            maxWidth = ms_maxWidth;

        // only set a new width if it is bigger than the current setting:
        // otherwise adding a tooltip with shorter line(s) than a previous
        // one would result in breaking the longer lines unnecessarily as
        // all our tooltips share the same maximal width
        if ( maxWidth > SendTooltipMessage(GetToolTipCtrl(),
                                           TTM_GETMAXTIPWIDTH, 0) )
        {
            SendTooltipMessage(GetToolTipCtrl(), TTM_SETMAXTIPWIDTH,
                               wxUIntToPtr(maxWidth));
        }
    }
    else
#endif // TTM_SETMAXTIPWIDTH
    {
        // replace the '\n's with spaces because otherwise they appear as
        // unprintable characters in the tooltip string
        m_text.Replace(wxT("\n"), wxT(" "));
        ti.lpszText = const_cast<wxChar *>(m_text.wx_str());

        if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL, &ti) )
        {
            wxLogDebug(wxT("Failed to create the tooltip '%s'"), m_text.c_str());
        }
    }
}
Пример #27
0
bool wxRadioBox::Create(wxWindow *parent,
                        wxWindowID id,
                        const wxString& title,
                        const wxPoint& pos,
                        const wxSize& size,
                        int n,
                        const wxString choices[],
                        int majorDim,
                        long style,
                        const wxValidator& val,
                        const wxString& name)
{
    // common initialization
    if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) )
        return false;

    // the code elsewhere in this file supposes that either wxRA_SPECIFY_COLS
    // or wxRA_SPECIFY_ROWS is set, ensure that this is indeed the case
    if ( !(style & (wxRA_SPECIFY_ROWS | wxRA_SPECIFY_COLS)) )
        style |= wxRA_SPECIFY_COLS;

#if wxUSE_VALIDATORS
    SetValidator(val);
#else
    wxUnusedVar(val);
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS

    // We need an extra one to keep track of the 'dummy' item we
    // create to end the radio group, so it will be destroyed and
    // it's id will be released.  But we want it separate from the
    // other buttons since the wxSubwindows will operate on it as
    // well and we just want to ignore it until destroying it.
    // For instance, we don't want the bounding box of the radio
    // buttons to include the dummy button
    m_radioButtons = new wxSubwindows(n);

    m_radioWidth = new int[n];
    m_radioHeight = new int[n];

    for ( int i = 0; i < n; i++ )
    {
        m_radioWidth[i] =
        m_radioHeight[i] = wxDefaultCoord;
        long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
        if ( i == 0 )
            styleBtn |= WS_GROUP;

        wxWindowIDRef subid = NewControlId();

        HWND hwndBtn = ::CreateWindow(wxT("BUTTON"),
                                      choices[i].t_str(),
                                      styleBtn,
                                      0, 0, 0, 0,   // will be set in SetSize()
                                      GetHwndOf(parent),
                                      (HMENU)wxUIntToPtr(subid.GetValue()),
                                      wxGetInstance(),
                                      NULL);

        if ( !hwndBtn )
        {
            wxLogLastError(wxT("CreateWindow(radio btn)"));

            return false;
        }

        // Keep track of the subwindow
        m_radioButtons->Set(i, hwndBtn, subid);

        SubclassRadioButton((WXHWND)hwndBtn);

        // Also, make it a subcontrol of this control
        m_subControls.Add(subid);
    }

    // Create a dummy radio control to end the group.
    m_dummyId = NewControlId();

    m_dummyHwnd = (WXHWND)::CreateWindow(wxT("BUTTON"),
                         wxEmptyString,
                         WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
                         0, 0, 0, 0, GetHwndOf(parent),
                         (HMENU)wxUIntToPtr(m_dummyId.GetValue()),
                         wxGetInstance(), NULL);


    m_radioButtons->SetFont(GetFont());

    SetMajorDim(majorDim == 0 ? n : majorDim, style);
    // Select the first radio button if we have any buttons at all.
    if ( n > 0 )
        SetSelection(0);
    SetSize(pos.x, pos.y, size.x, size.y);

    // Now that we have items determine what is the best size and set it.
    SetInitialSize(size);

    // And update all the buttons positions to match it.
    const wxSize actualSize = GetSize();
    PositionAllButtons(pos.x, pos.y, actualSize.x, actualSize.y);

    // The base wxStaticBox class never accepts focus, but we do because giving
    // focus to a wxRadioBox actually gives it to one of its buttons, which are
    // not visible at wx level and hence are not taken into account by the
    // logic in wxControlContainer code.
    m_container.EnableSelfFocus();

    return true;
}
Пример #28
0
bool wxSlider::Create(wxWindow *parent,
                      wxWindowID id,
                      int value,
                      int minValue,
                      int maxValue,
                      const wxPoint& pos,
                      const wxSize& size,
                      long style,
                      const wxValidator& validator,
                      const wxString& name)
{
    wxCHECK_MSG( minValue < maxValue, false,
        wxT("Slider minimum must be strictly less than the maximum.") );

    // our styles are redundant: wxSL_LEFT/RIGHT imply wxSL_VERTICAL and
    // wxSL_TOP/BOTTOM imply wxSL_HORIZONTAL, but for backwards compatibility
    // reasons we can't really change it, instead try to infer the orientation
    // from the flags given to us here
    switch ( style & (wxSL_LEFT | wxSL_RIGHT | wxSL_TOP | wxSL_BOTTOM) )
    {
        case wxSL_LEFT:
        case wxSL_RIGHT:
            style |= wxSL_VERTICAL;
            break;

        case wxSL_TOP:
        case wxSL_BOTTOM:
            style |= wxSL_HORIZONTAL;
            break;

        case 0:
            // no specific direction, do we have at least the orientation?
            if ( !(style & (wxSL_HORIZONTAL | wxSL_VERTICAL)) )
            {
                // no, choose default
                style |= wxSL_BOTTOM | wxSL_HORIZONTAL;
            }
    };

    wxASSERT_MSG( !(style & wxSL_VERTICAL) || !(style & wxSL_HORIZONTAL),
                    wxT("incompatible slider direction and orientation") );


    // initialize everything
    if ( !CreateControl(parent, id, pos, size, style, validator, name) )
        return false;

    // ensure that we have correct values for GetLabelsSize()
    m_rangeMin = minValue;
    m_rangeMax = maxValue;

    // create the labels first, so that our DoGetBestSize() could take them
    // into account
    //
    // note that we could simply create 3 wxStaticTexts here but it could
    // result in some observable side effects at wx level (e.g. the parent of
    // wxSlider would have 3 more children than expected) and so we prefer not
    // to do it like this
    if ( m_windowStyle & wxSL_LABELS )
    {
        m_labels = new wxSubwindows(SliderLabel_Last);

        HWND hwndParent = GetHwndOf(parent);
        for ( size_t n = 0; n < SliderLabel_Last; n++ )
        {
            wxWindowIDRef lblid = NewControlId();

            HWND wnd = ::CreateWindow
                         (
                            wxT("STATIC"),
                            NULL,
                            WS_CHILD | WS_VISIBLE | SS_CENTER,
                            0, 0, 0, 0,
                            hwndParent,
                            (HMENU)wxUIntToPtr(lblid.GetValue()),
                            wxGetInstance(),
                            NULL
                         );

            m_labels->Set(n, wnd, lblid);
        }
        m_labels->SetFont(GetFont());
    }

    // now create the main control too
    if ( !MSWCreateControl(TRACKBAR_CLASS, wxEmptyString, pos, size) )
        return false;

    // and initialize everything
    SetRange(minValue, maxValue);
    SetValue(value);
    SetPageSize( wxMax(1, (maxValue - minValue)/10) );

    // we need to position the labels correctly if we have them and if
    // SetSize() hadn't been called before (when best size was determined by
    // MSWCreateControl()) as in this case they haven't been put in place yet
    if ( m_labels && size.x != wxDefaultCoord && size.y != wxDefaultCoord )
    {
        SetSize(size);
    }

    return true;
}