Hello Andrzej !
<snip>
b)
On the other side you should not listen on the new created tab windows
... you should listen on the parent window only. This parent window is
provided by the TabControl.
Idea behind: You listen for resizes on one parent window and resize all
tabbed child windows.
Yes, I thought about that, but since I didn't have the parent window for
the control
I attached the listener to any window I had ;-)
Another hint: You must be carefull by using a reference to your own
object inside the ctor.
Why ?
If you create a reference to your own object your ref count will be
increased by 1 (from 0 to 1). And if these temp. reference will be run
out of scope it will be destructed. Means your ref count will be
decreased from 1 to 0. But then UNO calls "delete this" on your object
and during executing your ctor you will reach your own dtor ... .-)
How can it be avoided ?
Patch your factory method and use a "late init function" !
Currently your factory method looks like this:
Reference< XInterface > SAL_CALL cMyWindow_create(
const Reference< XMultiServiceFactory > & xMgr )
{
return Reference<XInterface>(
static_cast< XSingleServiceFactory* >(
new cMyWindow(xMgr)));
}
and your ctor:
cMyWindow::cMyWindow(const Reference< XMultiServiceFactory >& xMgr)
{
...
{
Reference< XInterface > xThis(
static_cast< XSingleServiceFactory* >(this),
UNO_QUERY);
... do something with xThis
}
// <- here you are dead .-)
...
}
You should change it to:
Reference< XInterface > SAL_CALL cMyWindow_create(
const Reference< XMultiServiceFactory > & xMgr )
{
cMyWindow* pNew = new cMyWindow(xMgr);
pNew->implLateInit();
return Reference<XInterface>(
static_cast< XSingleServiceFactory* >(
pNew);
}
cMyWindow::cMyWindow(const Reference< XMultiServiceFactory >& xMgr)
{
...
{
// => moved to implLateInit() !
// Reference< XInterface > xThis(
// static_cast< XSingleServiceFactory*>(this),
// UNO_QUERY);
// ... do something with xThis
}
...
}
void cMyWindow::implLateInit()
{
Reference< XInterface > xThis(
static_cast< XSingleServiceFactory*>(this),
UNO_QUERY);
... do something with xThis
}
"TabWindowFactory" isnt a valid interface.
You must differ between:
a)
An UNO service name, which is a string value only and can be used to
specify a service on creation time.
b)
An UNO implementation name, which is similar to an UNO service name, but
describe the implementation class instead of a generic service.
c)
An UNO interface, which can be used inside your implementation as:
- include
- baseclass
- for quering
this is a little confusing for me, but I think I'll get used to it
You use service and implementation names for creating new services
instances at runtime:
Reference< XInterface > xNew = xMgr->createInstance("servicename" or
"implementation name");
And you use interface to "cast" such instance and use the interface methods:
Reference< XAnyInterface > xNewCasted(xNew, UNO_QUERY);
xNewCasted->doSomething();
A service or an implementation name is nothing more then a string value,
used by uno to identify an implementation (locating the right library
and tusing the right factory to create it).
And interface must be defined by an IDL file; will be generated as
stub/skeleton inside a header file (hdl/hpp); such stubs/skeletons will
be used as "base classes" for your implementation; and your objects can
be "casted" to such interfaces.
Reference< XMultiServiceFactory > m_xSMGR = xSMGR; // provided during
creation of your service
Why can't I use the xSMGR ?
You can use it ... but you should cache it (using a class member).
Otherwise you are not able to create new services later during runtime.
Because the UNO service manager will be provided to you only one time ..
on creation time of your instance.
Reference< XPropertySet > xProps(m_xSMGR, UNO_QUERY);
At this point I finally understood ( at least so I think... ;-) )
what's going on here.
Each time I want some interface from a component I have to query it to
get it, right?
Yes.
like here - I want an XPropertySet interface, so I query the
MultiServiceFactory object
which returns a XPropertySet reference. Why can't I use casts? Like :
(XPropertySet(m_xSMGR))->somePropertySetSpecificMethod() ?
> I guess it's a design concept, but is my understanding correct ?
That's done inside the Reference<...>(..., UNO_QUERY); construct !
Normaly such cast you mentioned is possible ... but do you know all
interfaces provided by an implementation ? May be some of them are
marked as optional ...
So quering an interface instead of casting it is more type safe.
The reference template does the following inside:
{
XInterface* xInt = (XInterface*)aObject;
if (xInt->queryInterface(xQueriedInterface))
return (XQueriedInterface*)aObject;
return 0;
}
You should do the following:
- You have to copy the IDL files we provieded to you
(XSimpleTabController.idl and XTabListener.idl) into your SDK
("<sdkroot>/idl/com/sun/star/awt/").
- Add the new used interfaces to your window.uno.xml file.
(e.g. XComponentContext, XPropertySet, XSingleComponentFactory,
XSimpleTabController, XTabListener)
- Add all neded includes for these interfaces to your window.cxx file.
- Retrieve the default component context from the UNO service manager as
shown above.
- Create the services TabWindowFactory and TabControl as shown above.
- Get the parent window from the TabControl by using the interface
XPropertySet and retrieving the property "ParentWindow".
- Use this parent window at creation time of your child windows.
done.
I added the eventlistener to that component.
Now I'll try to make the tabcontrol visible somewhere in the window,
and then add a TabListener for it.
Wow ... the first tab is filled with a document .-)
Congratulation - you are on the right way.
Regards
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]