wxApp:GetConfig() and storing window positions / size

96 views
Skip to first unread message

Jorgen Bodde

unread,
Jul 17, 2006, 8:18:32 AM7/17/06
to wx-u...@lists.wxwidgets.org
(sorry for the double post, the reply-to was invalid)

Hi Guys,

I am working on an app at work, and in Delphi (VCL) there are
components to store the state of a form and sub children if needed
(position / size etc).

That made me wonder, why isn't this in wxWidgets by default? It would
not require much to be done.

wxApp::AssignConfig(wxConfigBase *)

Which takes a pointer to a wxConfigBase * class to be owned by the
app. This seems to be the most logical place as the wxApp is the last
to be killed.

This way a wxConfig class is at least available for sub forms to be
used as there is wxGetApp() as macro to get the current app instance.

As last there needs to be wxApp::SaveWindowPos / wxApp::LoadWindowPos
where a relative key can be given like;

wxGetApp().SaveWindowPos(wxT("mainwindow"), this);

This would not require much change and can be used for all windows to
be stored. I am always hand coding the saving of windows states and
sizes so why not make that a wxApp method with a wxConfig class that
can be assigned to store the size / pos ?

With regards,
- Jorgen

klaas.holwerda

unread,
Jul 18, 2006, 3:31:00 PM7/18/06
to wx-u...@lists.wxwidgets.org
Jorgen Bodde wrote:
>
> That made me wonder, why isn't this in wxWidgets by default? It would
> not require much to be done.
Make a patch i would say, it looks very useful to save windows state.

Still i use this to have that wxConfigBase pointer which i can get to
from anywhere.

wxFileConfig *pConfig = new wxFileConfig("SlideComposer");
wxConfigBase::Set( pConfig );

would it not be better to include here:

SaveWindowPos(wxT("mainwindow"), this);

or maybe better:


wxConfigBase::Write(*const wxString <wx_wxstring.html#wxstring>&
*/key/, wxWindow*theWindow )

Maybe more interesting things/types to save?


wxConfigBase::Write(*const wxString <wx_wxstring.html#wxstring>&
*/key/, const wxSize& size )

regards,

Klaas


Thomas Zehbe

unread,
Jul 19, 2006, 6:43:24 AM7/19/06
to wx-u...@lists.wxwidgets.org
I simply use a subclass of wxFrame and wxDialog for building my app frames and
dialogs.
There's somthing like this
int x, y, w, h;
GetClientSize(&w, &h);
GetPosition(&x, &y);
wxString path = _T("/") + GetTitle();
pConfig->SetPath(path);
pConfig->Write(_T("x"), (long) x);
pConfig->Write(_T("y"), (long) y);
pConfig->Write(_T("w"), (long) w);
pConfig->Write(_T("h"), (long) h);
in the destructor of the subclass and this code in a method of the subclass
int x, y, w, h;
GetClientSize(&w, &h);
GetPosition(&x, &y);
wxString path = _T("/") + GetTitle();
pConfig->SetPath(path);
x = pConfig->Read(_T("x"), x),
y = pConfig->Read(_T("y"), y),
w = pConfig->Read(_T("w"), w),
h = pConfig->Read(_T("h"), h);
Move(x, y);
SetClientSize(w, h);
which I call in the app frames after the CreateControls call.
It works fine.
Regards
Thomas
Am Mittwoch, 19. Juli 2006 12:02 schrieb klaas.holwerda:
> Jorgen Bodde wrote:
> > I have no problam with making patches .... but I do not like to put
> > effort in things that are rejected, so I rather ask it here first.
>
> Yes that i understand, but even asking first, mostly ends up to be not
> answered or not clearly answered to make the effort.
>
> > Like ABX said, Vadim was working on this.
>
> In this thread??
>
> > Persistent controls e.g. controls that save their own state is a very
> > nice idea.
>
> I am not talking about that.
>
> > But in my case simply a wxApp:: method that saves the
> > position and size is all I need.
>
> I know, but why not use wxConfigBase::Set( pConfig ) for that, instead
> of adding it to wxApp ?
> Is it not a windowname and a size (wxSize) you want to save?
> If wxConfigBase can already write/read ( long string double and bool ),
> why not add wxSize and some other simple types?
>
> > For persistency through serialization
> > (what Vadim intended) probably another mechanism is needed, because it
> > has no real link with writing user settings, rather serialization
> > only.
>
> Agreed, that is not what is needed here.
>
> Klaas

--
Dipl.-Ing. Thomas Zehbe
INGENION GmbH
Kuhweide 6
31552 Apelern
Fon: 05043 / 40 57 90 4
Fax: 05043 / 40 57 90 7

Johan Vromans

unread,
Jul 20, 2006, 6:14:24 AM7/20/06
to wx-u...@lists.wxwidgets.org
Thomas Zehbe <t...@ingenion.de> writes:

> Am Mittwoch, 19. Juli 2006 22:23 schrieb Johan Vromans:


>> Thomas Zehbe <t...@ingenion.de> writes:
>> > wxString path = _T("/") + GetTitle();

>> > pConfig->Write(_T("x"), (long) x);
>>

>> I really wonder whether these strings should be i18n-ed.
> Because the Title is the human readable i18n-ed title of the frame and I use
> to code every literal string as _T() or _() except database columns and
> things like that.

I think your "/", "x" and "y" fall in the exception category as well.

-- Johan

Thomas Zehbe

unread,
Jul 20, 2006, 3:28:09 AM7/20/06
to wx-u...@lists.wxwidgets.org
Am Mittwoch, 19. Juli 2006 22:23 schrieb Johan Vromans:
> Thomas Zehbe <t...@ingenion.de> writes:
> > wxString path = _T("/") + GetTitle();
> > pConfig->Write(_T("x"), (long) x);
>
> I really wonder whether these strings should be i18n-ed.
Because the Title is the human readable i18n-ed title of the frame and I use
to code every literal string as _T() or _() except database columns and
things like that. Until now it works fine.
Regards
Thomsa
>
> -- Johan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
> For additional commands, e-mail: wx-use...@lists.wxwidgets.org
Reply all
Reply to author
Forward
0 new messages