From: <ma...@us...> - 2003-12-30 09:09:33
|
Update of /cvsroot/sharedaemon/ui-wx/src In directory sc8-pr-cvs1:/tmp/cvs-serv26176 Modified Files: MainDlg.cpp MainDlg.h Log Message: Moved actual toolbar button creation into GenerateToolBarButtons method and using somewhat more readable #ifdefing now. Index: MainDlg.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/MainDlg.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- MainDlg.cpp 30 Dec 2003 08:20:53 -0000 1.51 +++ MainDlg.cpp 30 Dec 2003 09:09:30 -0000 1.52 @@ -295,8 +295,8 @@ /* to restart the toolbar. Settings are read from m_config object, new */ /* MyToolBar object is created (note that we don't use wxToolBar but our */ /* derived class instead - needed to catch some events - see MyToolBar class).*/ -/* Continueing, after adding some standard buttons, we iterate on the `pages` */ -/* list and add all pages found there. */ +/* The actual buttons are added in GenerateMyToolBar method to keep this */ +/* function relativly clean. */ /* @gen_images If true, also (re)generates images */ /******************************************************************************/ void CMainDlg::CreateMyToolBar(bool gen_images) { @@ -305,7 +305,6 @@ unsigned int i; /* Loop counter */ wxArrayString names; /* Names for multibutton controls */ wxArrayString images; /* Images for multibutton controls */ -int ids[2]; /* Identifiers for multibutton controls */ MyToolBar *toolbar = (MyToolBar*)GetToolBar(); delete toolbar; @@ -344,16 +343,39 @@ ); tb->SetMargins(2, 2); + /* There we create actual buttons */ + GenerateToolBarButtons(tb, gen_images, tool_align); + + tb->Realize(); + SetToolBar(tb); + tb->Refresh(); /* Fix for wxMac issues */ + Layout(); /* Needed after deleting/creation */ + UpdateToolBar(); +} + +/***************************************************** GenerateToolBarButtons */ +/* Here we create the actual buttons. There's a lot of #ifdefing going around */ +/* here because wxControl objects in toolbar aren't supported on most */ +/* platforms. Only places where we can use our MMultiButton control is */ +/* horizontal toolbar on wxMSW, and horizontal/vertical toolbars on wxGTK. */ +/* @tb Toolbar to be created buttons on */ +/* @gen_images If true, images are generated also. */ +/* @tool_align Alignment of the toolbar in question */ +/******************************************************************************/ +void CMainDlg::GenerateToolBarButtons( + MyToolBar *tb, bool gen_images, int tool_align +) { +wxArrayString names, images; /* Names/images for multibuttons */ +int ids[2]; /* Identifiers for multibutton controls */ +unsigned int i; /* Loop counter */ + if (gen_images) { img->MakeToolImage(_("Connect"), wxT("btn_connect")); } -/* Neither the generic nor Motif native toolbars really support this :( */ -#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && \ - !defined(__WXX11__) && !defined(__WXMAC__) - #ifdef __WXMSW__ /* Doesn't work in vertical MSW toolbar either :(((( */ +/* On wxMSW, only use custom control in horizontal toolbar. */ +#ifdef __WXMSW__ if (tool_align == wxTB_HORIZONTAL) { - #endif names.Add(_("Connect")); names.Add(_("Log")); ids[1] = ID_BTN_CONNECT; @@ -363,12 +385,7 @@ tb->AddControl(new MMultiButton(tb, -1, 2, names, ids, images)); images.Clear(); names.Clear(); - #ifdef __WXMSW__ - } else - #endif -#endif -#if !defined(__WXGTK__) - { + } else { tb->AddTool( ID_BTN_CONNECT, _("Connect"), img->GetImage(wxT("btn_connect")), @@ -377,6 +394,26 @@ _("Connect to random server") ); } +/* On wxGTK, we can use custom control in both toolbar positions */ +#elif defined(__WXGTK__) { + names.Add(_("Connect")); + names.Add(_("Log")); + ids[1] = ID_BTN_CONNECT; + ids[1] = ID_BTN_LOG; + images.Add(wxT("connection")); + images.Add(wxT("log")); + tb->AddControl(new MMultiButton(tb, -1, 2, names, ids, images)); + images.Clear(); + names.Clear(); +/* Anywhere else, custom controls in toolbar aren't supported at all */ +#else + tb->AddTool( + ID_BTN_CONNECT, _("Connect"), + img->GetImage(wxT("btn_connect")), + img->GetImage(wxT("btn_connect")), + wxITEM_NORMAL, _("Connect to random server"), + _("Connect to random server") + ); #endif /* Go through list of our pages and add all of them */ @@ -406,12 +443,9 @@ _("Options"), wxT("btn_guisettings") ); } -/* Neither the generic nor Motif native toolbars really support this :( */ -#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && \ - !defined(__WXX11__) && !defined(__WXMAC__) - #ifdef __WXMSW__ /* Doesn't work in vertical MSW toolbar either :(((( */ +/* On wxMSW, only use custom control in horizontal toolbar. */ +#ifdef __WXMSW__ if (tool_align == wxTB_HORIZONTAL) { - #endif names.Add(_("Options")); names.Add(_("Help")); ids[0] = ID_BTN_GUISETTINGS; @@ -421,12 +455,7 @@ tb->AddControl(new MMultiButton(tb, -1, 2, names, ids, images)); images.Clear(); names.Clear(); - #ifdef __WXMSW__ - } else - #endif -#endif -#if !defined(__WXGTK__) - { + } else { tb->AddTool( ID_BTN_GUISETTINGS, _("Options"), img->GetImage(wxT("btn_guisettings")), @@ -435,13 +464,27 @@ wxT("Change GUI Settings") ); } +/* On wxGTK, we can use custom control in both toolbar positions */ +#elif defined(__WXGTK__) + names.Add(_("Options")); + names.Add(_("Help")); + ids[0] = ID_BTN_GUISETTINGS; + ids[1] = ID_BTN_HELP; + images.Add(wxT("options")); + images.Add(wxT("help")); + tb->AddControl(new MMultiButton(tb, -1, 2, names, ids, images)); + images.Clear(); + names.Clear(); +/* Anywhere else, custom controls in toolbar aren't supported at all */ +#else + tb->AddTool( + ID_BTN_GUISETTINGS, _("Options"), + img->GetImage(wxT("btn_guisettings")), + img->GetImage(wxT("btn_guisettings")), + wxITEM_NORMAL, wxT("Change GUI Settings"), + wxT("Change GUI Settings") + ); #endif - - tb->Realize(); - SetToolBar(tb); - tb->Refresh(); /* Fix for wxMac issues */ - Layout(); /* Needed after deleting/creation */ - UpdateToolBar(); } /************************************************************** OnCloseWindow */ Index: MainDlg.h =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/MainDlg.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- MainDlg.h 27 Dec 2003 12:38:55 -0000 1.18 +++ MainDlg.h 30 Dec 2003 09:09:30 -0000 1.19 @@ -180,6 +180,9 @@ ); /* `remove` is true */ void DetachCurPage(); /* Detaches current page into new frame */ void ShowToolPopupMenu(); /* Displays toolbar popup menu */ + void GenerateToolBarButtons( /* There the actual buttons are created */ + MyToolBar *tb, bool gen_images, int tool_align + ); /* Getters - small methods for retreiving various kinds of data */ Page* GetCurPage() { return cur_page;} /* Returns current active page */ |