Update of /cvsroot/sharedaemon/ui-wx/src
In directory sc8-pr-cvs1:/tmp/cvs-serv24868
Modified Files:
GUISettingsDlg.cpp Images.cpp Images.h MainDlg.cpp MainDlg.h
Makefile.am defines.h wxInterface.cpp wxInterface.h
Log Message:
Finalized dialog pages detaching/attaching engine. Now dialog pages are stored in a wxList for dynamic updating. No more hard-coded toolbar ID codes or page order. Also improved documentation of CMainDlg class.
Index: GUISettingsDlg.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/GUISettingsDlg.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- GUISettingsDlg.cpp 6 Dec 2003 00:45:36 -0000 1.26
+++ GUISettingsDlg.cpp 18 Dec 2003 04:25:36 -0000 1.27
@@ -244,8 +244,7 @@
/* Update static bitmaps */
img->UpdateImages(mainframe);
/* Recreate toolbar */
- img->MakeToolImages();
- mainframe->CreateMyToolBar();
+ mainframe->CreateMyToolBar(true);
/* Update server page logbook */
serverwnd->SetLogBookImages();
/* Update statistics tree */
@@ -255,9 +254,9 @@
wxIcon icon;
icon.CopyFromBitmap(img->GetImage(wxT("mule")));
mainframe->SetIcon(icon);
- #ifdef wxHAS_TASK_BAR_ICON
+#ifdef wxHAS_TASK_BAR_ICON
systray->SetIcon(icon);
- #endif
+#endif
}
}
Index: Images.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- Images.cpp 30 Nov 2003 23:19:59 -0000 1.32
+++ Images.cpp 18 Dec 2003 04:25:36 -0000 1.33
@@ -269,114 +269,6 @@
}
/**
- * Here we generate new toolbar button images. First we find out which of
- * our texts is longest, and make the bitmap size according to that. Then
- * we draw each bitmap with corresponding image and text and save to the
- * corresponding image object (note that we should never save it to disc!).
- * The main reason for this was wxMac where toolbar button texts were not
- * supported, but eventually, this approach proves nicer quality because of
- * possibility to later add custom background colour/borders to the images.
- */
-void CImages::MakeToolImages() {
- wxBitmap tmp, tmp_new;
- wxMemoryDC mdc;
- wxCoord x, y, width = 0, height = 0;
- wxArrayString btntxt, btnimg;
-
- /* List of button names */
- btntxt.Add(_("Connect"));
- btnimg.Add(wxT("btn_connect"));
- btntxt.Add(_("Servers"));
- btnimg.Add(wxT("btn_servers"));
- btntxt.Add(_("Search"));
- btnimg.Add(wxT("btn_search"));
- btntxt.Add(_("Transfer"));
- btnimg.Add(wxT("btn_transfer"));
- btntxt.Add(_("Shared Files"));
- btnimg.Add(wxT("btn_shared"));
- btntxt.Add(_("Messaging"));
- btnimg.Add(wxT("btn_messages"));
- btntxt.Add(_("Statistics"));
- btnimg.Add(wxT("btn_statistics"));
- btntxt.Add(_("Preferences"));
- btnimg.Add(wxT("btn_guisettings"));
-
- /**
- * Temporary bitmap for measuring text lengths.
- * 100 pixels should be enough.
- */
- tmp = wxBitmap(100, 100);
- mdc.SelectObject(tmp);
-
- /**
- * Set font to what it will be in final bitmaps and measre the lengths
- * of all button labels to find out the final width of the image.
- * wxMac seems to have problems with wxDECORATIVE and/or wxBOLD
- * fonts, we fall back to wxDEFAULT/wxNORMAL.
- */
- mdc.SetTextForeground(wxColour(10, 10, 10));
- #ifdef __WXMAC__
- mdc.SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL));
- #else
- mdc.SetFont(wxFont(10, wxDECORATIVE, wxNORMAL, wxBOLD));
- #endif
- for (unsigned int i=0;i<btntxt.GetCount();i++) {
- mdc.GetTextExtent(btntxt.Item(i), &x, &y);
- if (x > width) {
- width = x;
- }
- }
- /* local storage */
- width = width+6;
- height = y+38;
- /* global, for accessing from outside */
- tool_img_width = width;
- tool_img_height = height;
-
- /**
- * This forloop goes through all images previously named in btnimg
- * string array. It creates a new image with previously calculated
- * height and width, draws the found bitmap on it and the corresponding
- * text from imgtxt arraystring. To make the final image transparent,
- * wxLIGHT_GREY colour pointer is used on wxMSW which seems to give
- * system background colour on windows, on other platforms we use
- * simple transparency mask. Finally, the generated image is saved
- * back to images list by removing old image, creating new wxBitmap
- * type object and storing the pointer in the list.
- */
- mdc.BeginDrawing();
- for (unsigned int i=0;i<btntxt.GetCount();i++) {
- tmp_new = wxBitmap(width, height);
- mdc.SelectObject(tmp_new);
- #ifdef __WXMSW__
- mdc.SetPen(*wxTRANSPARENT_PEN);
- mdc.SetBrush(wxBrush(*wxLIGHT_GREY, wxSOLID));
- #else
- mdc.SetBrush(wxBrush(wxColour(0, 0, 0), wxSOLID));
- #endif
- mdc.DrawRectangle(
- 0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()
- );
- mdc.DrawBitmap(
- GetImage(btnimg.Item(i)),
- (tmp_new.GetWidth()-32)/2, 2, true
- );
- mdc.SetTextForeground( wxColour(1,1,1));
- mdc.GetTextExtent(btntxt.Item(i), &x, &y);
- mdc.DrawText(btntxt.Item(i), (tmp_new.GetWidth()-x)/2, 36);
- #ifndef __WXMSW__
- wxMask *tmp_mask;
- tmp_mask = new wxMask(tmp_new, wxColour(0,0,0));
- tmp_new.SetMask(tmp_mask);
- #endif
- images.DeleteObject(&(GetImage(btnimg.Item(i))));
- wxBitmap *new_image = new wxBitmap(tmp_new);
- images.Append(btnimg.Item(i), new_image);
- }
- mdc.EndDrawing();
-}
-
-/**
* This is an "Images Getter". It finds the requested image by searching
* the image list by name. If not found, error message is generated,
* but we still return the pointer (even if its illegal).
@@ -410,4 +302,60 @@
for (unsigned int i=0;i<controls.GetCount();i++) {
UpdateImages(controls.Item(i)->GetData());
}
+}
+
+/**
+ * This method makes a new toolbar image. `name` is the label to be printed on
+ * the final image, `image` is a name of the image in Images list. we create
+ * a new wxBitmap object with width according to the length of width of `name`,
+ * and draw the bitmap+text on it. Finally, the generated image is saved back
+ * to Images list under the same name (previous version is deleted).
+ */
+wxBitmap& CImages::MakeToolImage(const wxString &name, const wxString &image) {
+ wxMemoryDC mdc;
+ wxBitmap tmp, tmp_new;
+ int x, y;
+
+ tmp = wxBitmap(100, 100);
+ mdc.SelectObject(tmp);
+
+ mdc.SetTextForeground(wxColour(10, 10, 10));
+ #ifdef __WXMAC__
+ mdc.SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL));
+ #else
+ mdc.SetFont(wxFont(10, wxDECORATIVE, wxNORMAL, wxBOLD));
+ #endif
+ mdc.GetTextExtent(name, &x, &y);
+
+ tmp_new = wxBitmap(x+6, y+36);
+ mdc.SelectObject(tmp_new);
+
+ mdc.BeginDrawing();
+ #ifdef __WXMSW__ /* This gives transparent image on wxMSW */
+ mdc.SetPen(*wxTRANSPARENT_PEN);
+ mdc.SetBrush(wxBrush(*wxLIGHT_GREY, wxSOLID));
+ #else /* Elsewhere, it will be done with wxMask later */
+ mdc.SetBrush(wxBrush(wxColour(0, 0, 0), wxSOLID));
+ #endif
+ mdc.DrawRectangle(
+ 0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()
+ );
+ mdc.DrawBitmap(
+ GetImage(image),
+ (tmp_new.GetWidth()-32)/2, 2, true
+ );
+ mdc.SetTextForeground( wxColour(1,1,1));
+ mdc.GetTextExtent(name, &x, &y);
+ mdc.DrawText(name, (tmp_new.GetWidth()-x)/2, 36);
+ #ifndef __WXMSW__ /* Use wxMask for transparency */
+ wxMask *tmp_mask;
+ tmp_mask = new wxMask(tmp_new, wxColour(0,0,0));
+ tmp_new.SetMask(tmp_mask);
+ #endif
+ mdc.EndDrawing();
+
+ images.DeleteObject(&(GetImage(image)));
+ wxBitmap *new_image = new wxBitmap(tmp_new);
+ images.Append(image, new_image);
+ return *new_image;
}
Index: Images.h
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Images.h 27 Nov 2003 13:52:51 -0000 1.15
+++ Images.h 18 Dec 2003 04:25:36 -0000 1.16
@@ -37,10 +37,10 @@
public:
CImages();
virtual ~CImages();
- void MakeToolImages();
+ wxBitmap& MakeToolImage(const wxString &name, const wxString &image);
int tool_img_width, tool_img_height;
void LoadImages();
- wxBitmap& GetImage(const wxString &name);
+ inline wxBitmap& GetImage(const wxString &name);
void UpdateImages(wxWindow *parent);
private:
ListOfBitmaps images;
Index: MainDlg.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/MainDlg.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- MainDlg.cpp 17 Dec 2003 10:15:21 -0000 1.26
+++ MainDlg.cpp 18 Dec 2003 04:25:36 -0000 1.27
@@ -30,7 +30,7 @@
#include "MainDlg.h"
-/* Global classes */
+/* Forward delcaration of globally available classes */
class CServerWnd *serverwnd;
class CTransferWnd *transferwnd;
class CSearchWnd *searchwnd;
@@ -43,82 +43,124 @@
class CStatusBar *statusbar;
class CToolBar *toolbar;
[...1195 lines suppressed...]
+/* Second page adding method, this overloads previous one by using the */
+/* complete page structure as first argument. */
+/* IMPORTANT: This method does NOT generate toolbar image, while the other */
+/* method with same name does. */
+/* @new_page Pointer to Page structure - page to be added. */
+/* @update_bars If true, also updates toolbar/menubars as neccesery */
+/******************************************************************************/
+void CMainDlg::AddPage(Page *new_page, bool update_bars) {
+ if (new_page == NULL) {
+ wxFAIL_MSG(wxT("Empty page passed for adding!"));
+ return;
+ }
+
+ pages.Append(new_page->short_title, new_page);
+
+ if (update_bars) {
+ CreateMyToolBar();
+ CreateMyMenuBar();
+ }
}
Index: MainDlg.h
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/MainDlg.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- MainDlg.h 17 Dec 2003 09:47:35 -0000 1.11
+++ MainDlg.h 18 Dec 2003 04:25:36 -0000 1.12
@@ -47,6 +47,14 @@
#define ID_QUIT 100
#define ID_ABOUT wxID_ABOUT
+struct Page {
+ wxPanel *content;
+ wxString short_title;
+ wxString long_title;
+ wxString image;
+ wxWindowID id;
+};
+
/**
* This class is only needed for catching some specific events (see the event
* table. Actual event handling is still done in CMainDlg.
@@ -60,6 +68,7 @@
); /* Constructor */
private:
DECLARE_EVENT_TABLE() /* Event table declaration */
+ void RightClick(wxMouseEvent &event);
};
/* This very small class usually shows a frame with one dialog page as content*/
@@ -68,16 +77,18 @@
DetachedFrame(
wxWindow *parent, wxWindowID, const wxString &title,
const wxPoint& pos, const wxSize& size,
- long style, wxLocale &m_locale, wxWindow *content
+ long style, wxLocale &m_locale, Page *content
); /* Constructor */
wxLocale &m_locale; /* Localization variable */
private:
DECLARE_EVENT_TABLE() /* Event table declaration */
void OnClose(wxCommandEvent &event); /* Window closing event */
- wxWindow *cnt; /* Contents of the frame */
+ Page *cnt; /* Contents of the frame */
};
-/*
+WX_DECLARE_LIST(Page, PageList);
+
+/**
* MainDlg class. The main dialog functions like Toolbar and Statusbar
* stuff go in here.
*/
@@ -91,15 +102,17 @@
long style, wxLocale &m_locale
); /* Constructor */
~CMainDlg(); /* Destructor */
- inline void CreateMyToolBar(); /* (re)Creates toolbar */
+ inline void CreateMyToolBar(bool gen_images = false); /* Creates tbar */
inline void CreateMyMenuBar(); /* (re)Creates menubar */
+ void AddPage( /* Adds new page to frame */
+ wxPanel *page, const wxString &short_title, const wxString
+ &long_title, const wxString &image, wxWindowID = -1,
+ bool updatebars = false
+ );
+ void AddPage(Page *page, bool updatebars = false); /* Adds new page */
+ wxLocale &m_locale; /* Localization object */
- wxLocale &m_locale;
-
- /**
- * These need to be publically available, other classes
- * might need to access them.
- */
+ /* These need to be publically available */
wxStaticText* GetStatusText() { /* Statusbar text */
return (wxStaticText*) FindWindow( ID_STATUS_TXT );
}
@@ -126,22 +139,24 @@
void MenuEvent(wxCommandEvent &event); /* Menubar events */
void ToolEvent(wxCommandEvent &event); /* Toolbar events */
void OnCloseWindow(wxCloseEvent &event); /* Window closing event */
- void ToolRightClick(wxMouseEvent &event);/* Toolbar right-click event */
void PopUpMenuEvents(wxCommandEvent &event);/* Tbar popup-menu events */
/* Member functions */
void CreateSysTray(); /* Creates system tray icon */
void LoadAndShowDialogPages(); /* Loads dialog pages */
void ConnectToAnyServer(); /* Sends "connect" command to core */
- inline bool ShowPage(wxWindow* dlg); /* Displays page `dlg` */
+ inline bool SetActivePage(const wxString &to_show); /* Displays page */
void ShowGUISettingsDlg(); /* Displays GUI settings dialog */
- void UpdateToolButtons(); /* Updates toolbar buttons */
+ void UpdateToolBar(); /* Updates toolbar buttons */
void UpdateMenuBar(); /* Updates menubar objects */
- void RemovePage(wxWindow *page); /* Removes `page` from frame */
+ void RemovePage( /* Removes page `to_remove` */
+ Page *to_remove, bool remove = true /* deleting contents if */
+ ); /* `remove` is true */
void DetachCurPage(); /* Detaches current page into new frame */
+ void ShowToolPopupMenu(); /* Displays toolbar popup menu */
- /* Getters */
- wxWindow* GetCurPage() { return activewnd; }
+ /* Getters - small methods for retreiving various kinds of data */
+ Page* GetCurPage() { return cur_page;} /* Returns current active page */
wxMenuItem* GetViewMenuBar() { /* View menu object "View Menubar" */
return GetMenuBar()->FindItem(ID_VIEW_MENUBAR);
}
@@ -166,7 +181,6 @@
wxMenuItem* GetViewStatisticsWnd() {/* View menu object "Statisti..." */
return GetMenuBar()->FindItem(ID_VIEW_STATISTICS);
}
-
wxStaticBitmap* GetBmpStatusConnection() {/* Statusbar connection bmp */
return (wxStaticBitmap*) FindWindow( ID_BMP_STATUS_CONNECTION );
}
@@ -184,11 +198,10 @@
}
/* Member variables */
- bool show_tool; /* Wether toolbar should be shown or not. */
bool start_up; /* Should we remember last page between sessions */
- int m_lastbtn; /* Last toggled toolbar button */
wxFlexGridSizer *m_mainsizer; /* Main frame sizer */
- wxWindow *activewnd; /* Current active dialog page */
+ Page *cur_page; /* Current active dialog page */
+ PageList pages; /* List of loaded dialog pages */
};
#endif
Index: Makefile.am
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile.am 17 Dec 2003 09:47:35 -0000 1.3
+++ Makefile.am 18 Dec 2003 04:25:36 -0000 1.4
@@ -31,10 +31,18 @@
@echo -e -n "$(ACTIONCOLOR)Compiling $(INPUTCOLOR)$<$(ACTIONCOLOR) to "
@echo -e -n "$(OUTPUTCOLOR)$@$(ACTIONCOLOR)@PRINT_CPP_FLAGS@: $(ATTENTIONCOLOR)"
@if @CXX@ @CXX_FLAGS@ @CPP_FLAGS@ @INCLUDE@ -c -o $@ $< 2>.err; then \
- echo -e "$(WELLCOLOR)ok.$(ACTIONCOLOR)"; \
+ if test -s .err; then \
+ echo -e "$(WARNINGCOLOR)ok, but warnings:"; \
+ cat .err; \
+ rm -f .err; \
+ echo -e "$(DEFAULTCOLOR)"; \
+ else \
+ echo -e "$(WELLCOLOR)ok.$(ACTIONCOLOR)"; \
+ fi; \
else \
echo -e "failed:"; \
cat .err; \
+ rm -f .err; \
echo -e "$(DEFAULTCOLOR)"; \
false; \
fi;
@@ -52,7 +60,7 @@
@echo -e -n "$(ACTIONCOLOR)Linking $(INPUTCOLOR)$(WXINTERFACE_OBJECTS)"
@echo -e -n "$(ACTIONCOLOR)to $(OUTPUTCOLOR)$@$(ACTIONCOLOR)@PRINT_LINK_FLAGS@: "
@echo -e -n "$(ATTENTIONCOLOR)"
- @if @CXX@ -o $(PROGRAM) $(WXINTERFACE_OBJECTS) @LIBS@; then \
+ @if @CXX@ -o $(PROGRAM) $(WXINTERFACE_OBJECTS) @LIBS@ 2>.err; then \
echo -e "$(WELLCOLOR)ok."; \
echo -e -n "$(DEFAULTCOLOR)"; \
echo -e -n "$(WELLCOLOR)Successfully compiled "; \
@@ -60,6 +68,9 @@
echo -e -n "$(OUTPUTCOLOR)$@$(WELLCOLOR) binary!\n"; \
echo -e "$(DEFAULTCOLOR)Now cd to src/ dir and type $(OUTPUTCOLOR)./$@$(DEFAULTCOLOR) to start the application."; \
else \
+ echo -e "failed:"; \
+ cat .err; \
+ echo -e "$(DEFAULTCOLOR)"; \
false; \
fi
Index: defines.h
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/defines.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- defines.h 17 Dec 2003 09:47:35 -0000 1.41
+++ defines.h 18 Dec 2003 04:25:36 -0000 1.42
@@ -70,12 +70,13 @@
/* ID codes for our controls */
enum {
- ID_BTN_CONNECT = 1000, /* Toolbar buttons */
- ID_BTN_SERVERS,
- ID_BTN_TRANSFER,
- ID_BTN_SEARCH,
- ID_BTN_SHARED_FILES,
- ID_BTN_MESSAGES,
+ ID_SERVERWND = 1000, /* Dialog pages */
+ ID_SEARCHWND,
+ ID_TRANSFERWND,
+ ID_SHAREDFILESWND,
+ ID_MESSAGESWND,
+ ID_STATISTICSWND,
+ ID_BTN_CONNECT, /* Toolbar buttons */
ID_BTN_STATISTICS,
ID_BTN_GUISETTINGS,
ID_BTN_CORESETTINGS,
@@ -175,5 +176,6 @@
*/
M_LISTCOL = 2000
};
+
#endif
Index: wxInterface.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/wxInterface.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- wxInterface.cpp 8 Dec 2003 01:08:10 -0000 1.9
+++ wxInterface.cpp 18 Dec 2003 04:25:36 -0000 1.10
@@ -46,7 +46,8 @@
* main wxInterface Dialog drawn.
*/
bool wxInterface::OnInit() {
- int show_splash;
+int show_splash = true;
+ mainframe_active = false;
SetVendorName(wxT("ShareDaemon"));
SetAppName(wxT("wxInterface"));
Index: wxInterface.h
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/wxInterface.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- wxInterface.h 8 Dec 2003 01:39:02 -0000 1.3
+++ wxInterface.h 18 Dec 2003 04:25:36 -0000 1.4
@@ -55,6 +55,7 @@
virtual int OnExit(); // Application shutdown
CSplash *splash; // Pointer to splash screen
bool splash_active; // For detecting if splash is active
+ bool mainframe_active; // For detecting if mainframe still exists
protected:
wxLocale m_locale;
|