 So I made a similar talk on this very topic on last year's LibreOffice conference in Denmark and I got some positive feedback from guys that were just starting with the UI hacking, telling me yes, this is exactly what the newcomers need to get introduced to the UI hacking in LibreOffice. And one of the issues UI hacking is kind of pasted with is like a cute lack of documentation. In many cases, the only documentation is an old open office wiki. And if you are not really a fan of abstract computer science paper language, this documentation will be very hard to read for you. In the meantime, some new UI hack is appeared. Also some, I meant it to GSOC projects focused on UI hacking. And I realized, well, the situation with the documentation didn't improve at all. And perhaps I could make one more tutorial, one more talk on this very topic. And to begin with, let me quote some, or let me first explain why is this talk called The Revenge of SFX2 API. And let me quote some wise men in the process. Yes, so SFX2 API, the dispatch API is basically the driving force behind everything what happens in the LibreOffice user interface. Fortunately, we will not look what's inside because it's really scary. Perhaps you don't want to know but we will at least see how it looks from the outside. So is there anyone who ever wrote LibreOffice user interface code? Some hands raising. So I have a plea for all of you. Please don't copy paste the code. And the reason why you should not copy paste the code is that like this is, maybe it's not specific to user interface hackers, but that's what the people who somehow start with UI hacking frequently do, that they take the code that works somewhere else and they use control C and control V and copy paste this code to a different place. And in some cases it behaves okay, it works well. But then it fails in like very, very subtle ways, very strange ways and those ways are kind of, and it makes it somehow, somehow hard to debug and then people say, oh, but this code works somewhere else. Why doesn't it work here? So this is something also we will look at some common bugs or some some problems we can encounter when hacking on the UI and how to fix them. So let's start with some recap of you know commands. You know commands are some kind of like basic building block of the user interface. So there's this behind every toolbar button. There's some you know command as you can see. This is some kind of a sample snippet of XML. It's a configuration of toolbar and it references those dot you know colon something. Those are the you know commands. Also behind every almost every sidebar button or sidebar control. As you can see, you can all again see some snippets of sidebar configuration of the UI file. There is some you know command behind them. And all those commands are stored in a center place which is in office config folder. There are two kinds of them. There are generic commands that are shared by all applications. And then all the other applications like right click call can press. They have their specific set of commands that are used and only in this application and nowhere else. To make it a bit more visual, here is some snippet of XML config of the menu bar containing you know command. And then on the left, well, it's my left, it's your right. On the right, you can see how it maps to a particular command in the central storage of the you know commands. And as you might also know as well, all the you know commands have hotkeys. This is an example like in calc if you press F1, F9, it will execute this very you know command that is highlighted in red. The funny trick about those commands that they're localizable. So if the particular shortcut doesn't fit your language, fit your keyboard layout, there's a possibility to change it. So that's one end of pipe. There are toolbars. There's a sidebar. There are menus. There's some user interaction with those elements. And that's that's one end of the pipe. And on the other end of the pipe, there are some C++ functions, some methods that actually carry out the work that I don't know format the page, change the fill of the shape or I don't know insert some data somewhere. And what's in between? It's slots. Slots somehow connect those user interface elements with those functions. I put some funny image of an enigma blackboard so you can imagine it as some kind of blackboard with user interface on one end and the C++ function or like the code doing the heavy lifting like actually executing the work. Those slots if live in those funny SDI files. So if you ever found SDI file in the open in the liberal office code base, this is where the slots live. This is where they are. And for every you know command, there is a slot. It's a bit hidden. So the command has this you know prefix but the slot doesn't. Here's some clever trick. If you're looking, if you have a you know command and you want to find the slot for this particularly you know command, you can use this, you can then download my slides and copy paste this command line. Copy paste this command line and it will take you to the slot that's responsible for this command. So what are those SDI files? There are two types of SDI files and one of them contains slot definitions so that some description of how this particular slot behaves. And the other type of SDI files is some kind of interface. How slots are organized into some list or arrays. How those are organized into shells and how those shells somehow connect to the actual C++ classes and functions. And those SDI files are processed by something that's called SVIDL that crunches those files and then creates some huge arrays of pointers to C++ functions. Those live in work directory work there. And yeah, if you're brave, you can have a look at those files that are kind of, I don't know, very little human readable. So this is how an average slot definition looks like. As I say, all those entries like describe or define how does the slot behave if it can be assigned keyboard shortcut for example, if it can be used in menu entry, if it can be used in toolbox. And some clever tricks I can show. So if you ever wondered how, if you have a slot and if you have a toolbar button, you want to make a toolbar button some kind of binary toggle. This is how you do it. Just set this toggle attribute to true. Or if you have a toolbar, if you have a slot and you want to expose it on the toolbar button, make it accessible, allow to make it to be a part of a toolbar. This is how it is done. Again, this toolbox config can be set to true. This SFX SVX page item highlighted. Oh, I used to, in my previous job, I used to do some network programming. So I like to imagine those SFX SVX items as some kind of network packets, some data that travel, like from the user type of data that travel in small packets from the user interface to the C++ code. And those data can be of different type. It can be a color, it can be font, it can be, I don't know, cell border. And this particular example, this is a slot that's responsible for setting the attributes of the page. And the packets, the item that travels to the slot, some kind of main communication unit contains the attributes of the page. If it's a landscape or a portrait, which layout, which numbering, and so on. So this is what those items are for. And as I mentioned, there are some two types of those STI files. This was one of them with the slot definitions. On the right, we can see the other, the other STI file, which defines slot interfaces or shell interfaces. So every slot which is defined in one STI file is then a part of some interface. And then interface are organized into shells. So what's the shell? If we simplify that, it's some set of different functions for different objects or different contexts. And here we can see some example of calc spreadsheet, this pivot table, there are normal cells, there's a graph, a chart. And all of those like different types of objects are in fact different shells. So we can have a cell shell and some set of operations that are possible for a cell. So we can form a cell, we can delete its content, we can insert some image. And then yet another set of operation that are available for a pivot table, like edit its layout or insert subtotals. And yet another set of operation that is available for a chart. So those are somehow grouped in the chart shell. So we can format the data series or insert labels or I don't know format axis. And those arrays like of functions or groups of functions available in a particular shell are grouped in big arrays like this. It's the interface entry. And then interface other than parts of the shell. So every shell can contain multiple interfaces. Now we finally get to the meet. So how, where's actually the code carrying out the UI work? Like the, where's the C++ code? Where's the C++ class and method executing something, doing something when I click on a toolbar button or when I do something in UI. So this is a, as I said, this is the interface that's organized, that's put in the shell. And this stock shell is the name of the class. So if you're looking for a C++ code, implementing particularly UI function, look for this class. And if you are looking for a particular method, implementing the function, this is the method to find. And as you can see, there are two types of methods. One is the execute method and the other is the state method. What's the difference between them? I will show an example. So execute method is what happens when you, well, what's actually executed. So if I click on this funny area formatting button, an execute method will get called and the color of the object changes. But now the toolbar buttons should somehow, it would be nice if it would reflect the change I've just made. And that's for the state method is for. So the state method queries the state of the object and updates the toolbar button back. And this is where some, let's say, common errors or common problems happen. So I've listed couple of them on the next slide, which we encountered in the development during GSOC and implementing some UI features. So if you ever wondered why a toolbar sidebar control doesn't pick up the state, like something has changed in the spreadsheet or something has changed in the drawing and the sidebar button doesn't update by the method I outlined on the previous slides, try to locate the get state method for this particular slot and see what's happening there to the break point. Another issue is we once had, we correctly updated the slot definition and we exposed the tool bar, the slot in, we made it available for a toolbar, but it stayed disabled. Like no matter what was done, it was always grayed out. So a part of this SFX API is disabling the slot. So if you disable the slot, it means that the menu entry is grayed out or the toolbar button is grayed out, it's not accessible. So what you can try to do is to grab for the slot, locate the slot and find some code, try to find some code that is disabling it and find out why is that happening. And I think by that I came to the end of my talk.