Skip to content
wxWidgets - Cross-Platform GUI Library
Stop Russia agression of Ukraine
Stop the War in Ukraine

wxWidgets is united with the people of Ukraine and the international community.

Developer Blog

Addressing wxWebRequest Requests

Posted on

wxWebRequest is a very useful class if you need to perform some HTTPS requests from a GUI application: it’s, perhaps, not the fastest nor the most full-featured, but it doesn’t have any dependencies and provides a very simple way to do it without blocking the normal event handling of the GUI program, i.e. without making it “unresponsive”, thanks to its asynchronous nature.

However, ever since it was added, there were requests to add an even simpler way to use it in blocking, or synchronous, way, when this is affordable, for example in simple console applications or in background threads of a GUI application. And this is finally possible with wxWebRequestSync, which can be used as simply as

wxWebRequestSync request = wxWebSessionSync::GetDefault().CreateRequest("https://www.wxwidgets.org");
auto const result = request.Execute();
if ( !result ) {
    wxLogError("Request failed: %s", result.error);
} else {
    if ( request.GetStatusCode() == 200 ) {
        // Do something with the response data in request.GetResponse()
        ...
    }
}

If you’re familiar with wxWebRequest itself, you can see that the new class is similar to it as it’s still created by wxWebSessionSync very similar to wxWebSession used with asynchronous requests, but instead of starting the request and waiting to get its results at some later time via an event you can just execute it in a blocking way and get the results in the same function.

By the way, note that, because the results are provided in the same wxWebResponse object, it is possible to write console and GUI versions of the same program that execute the requests differently, but share the code handling responses.

Finally, while adding support for synchronous operation, a few other things, some of which had been also requested before, and others just looked like a good idea, were added too:

  1. It is now possible to set a common base URL to use for all requests created by the same session using either wxWebSession::SetBaseURL() or wxWebSessionSync::SetBaseURL() depending on the kind of the requests used. This is handy when sending requests to some web API.
  2. It is now also possible to disable the proxy or specify a proxy different from the system default with wxWebSession::SetProxy() (which also exists in wxWebSessionSync, of course). Special thanks to Apple for making it apparently impossible to do this under iOS – so this function does nothing there.
  3. Because the world wide web is dark and full of dangers and misconfigured servers, it is also possible to disable the host name verification in the TLS certificate by calling wxWebRequest::MakeInsecure(). Hopefully you will never need to do it, but the function is there if you do.

And there was some other minor cleanup and bug fixes: notably, credentials can now be specified directly in the URL under all platforms now, including when using WinHTTP under MSW.

Of course, as with any change, all these new features could have introduced their own bugs, so if you use wxWebRequest in your applications (or maybe have just been waiting to start to do it!), please let us know if they broke anything, preferably before the 3.3.0 release which is bound to happen at some moment in the future.

Comments

Great Grid Upgrades

Posted on

There have been a couple of changes to wxGrid in wx master that are important enough to deserve their own blog post.

First of all, Dietmar Schwertberger has implemented basic accessibility support for it (see #24368), which makes it usable when using a screen reader.

Dietmar has also enhanced wxGrid in other ways, by implementing drag-resizing its row and column label windows (#24362) and making several improvements to row/column reordering (see #24303, #24363, #24619).

And, second, Ali Kettab has modified selection drawing to use much nicer “overlay” effect instead of simply changing the background colour (see #24561), here is how it now looks under Linux:

Screenshot of wxGrid using overlay selection under Linux

and macOS, in dark mode:

Screenshot of wxGrid using overlay selection under macOS

Of course, as with any changes, there is always a possibility that the new features could have changed the existing behaviour, even if we are not aware of any incompatible changes right now, so if you use grids in your application, please check how they work with the latest wx master and let us know about any regressions!

Comments

More Resourceful Property Grid

Posted on

Just a quick note to say that it is now possible to define wxPropertyGrid controls in XRC, e.g. here is a minimal example:

<object class="wxPropertyGrid" name="grid_music">
    <property class="wxStringProperty">
        <label>Name</label>
        <value>Now And Then</value>
    </property>
    <property class="wxIntProperty">
        <label>Year</label>
        <value>2023</value>
    </property>
</object>

Support for wxPropertyGrid must be explicitly enabled by registering the XRC handler for it, so the code loading the XRC file including the fragment above would look like this:

// Include declaration of the XRC handler for wxPropertyGrid.
#include "wx/xrc/xh_propgrid.h"

bool MyApp::OnInit() {
    auto xrc = wxXmlResource::Get();

    // Initialize all standard handlers.
    xrc->InitAllHandlers();

    // And add this one which is not standard.
    xrc->AddHandler(new wxPropertyGridXmlHandler);

    if ( !xrc->Load("propgrid.xrc") )
    {
        wxLogError("XRC file couldn't be loaded.");
        return false;
    }

    ...
}

The updated sample contains a more complex example of wxPropertyGridManager defined in XRC and the documentation has been updated to describe the supported elements.

Comments

Blog Archive