Fix for bug 12878. Hack the viewer menubar into submission.

This commit is contained in:
ramiro%netscape.com 1999-09-01 10:48:28 +00:00
parent e92068f7aa
commit b0bda3ec10
13 changed files with 152 additions and 34 deletions

View File

@ -77,6 +77,16 @@ nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{

View File

@ -1381,6 +1381,19 @@ nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
return NS_OK;
}
// Overload this method in your nsNativeBrowserWindow if you need to
// have the logic in nsBrowserWindow::Layout() offset the menu within
// the parent window.
nsresult
nsBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
return NS_OK;
}
nsresult
nsBrowserWindow::CreateStatusBar(PRInt32 aWidth)
{
@ -1427,6 +1440,7 @@ void
nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
{
nscoord txtHeight;
nscoord menuBarHeight;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight);
@ -1435,6 +1449,9 @@ nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
txtHeight = 24;
}
// Find out the menubar height
GetMenuBarHeight(&menuBarHeight);
nsRect rr(0, 0, aWidth, aHeight);
// position location bar (it's stretchy)
@ -1446,15 +1463,15 @@ nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
if (mThrobber) {
PRInt32 width = PR_MAX(aWidth - (2*BUTTON_WIDTH + THROBBER_WIDTH), 0);
locationWidget->Resize(2*BUTTON_WIDTH, 0,
locationWidget->Resize(2*BUTTON_WIDTH, menuBarHeight,
width,
BUTTON_HEIGHT,
PR_TRUE);
mThrobber->MoveTo(aWidth - THROBBER_WIDTH, 0);
mThrobber->MoveTo(aWidth - THROBBER_WIDTH, menuBarHeight);
}
else {
PRInt32 width = PR_MAX(aWidth - 2*BUTTON_WIDTH, 0);
locationWidget->Resize(2*BUTTON_WIDTH, 0,
locationWidget->Resize(2*BUTTON_WIDTH, menuBarHeight,
width,
BUTTON_HEIGHT,
PR_TRUE);
@ -1462,6 +1479,20 @@ nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
locationWidget->Show(PR_TRUE);
NS_RELEASE(locationWidget);
nsIWidget* w = nsnull;
if (mBack &&
NS_SUCCEEDED(mBack->QueryInterface(kIWidgetIID, (void**)&w))) {
w->Move(0, menuBarHeight);
w->Show(PR_TRUE);
NS_RELEASE(w);
}
if (mForward &&
NS_SUCCEEDED(mForward->QueryInterface(kIWidgetIID, (void**)&w))) {
w->Move(BUTTON_WIDTH, menuBarHeight);
w->Show(PR_TRUE);
NS_RELEASE(w);
}
}
}
else {
@ -1473,11 +1504,13 @@ nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
}
if (mBack &&
NS_SUCCEEDED(mBack->QueryInterface(kIWidgetIID, (void**)&w))) {
w->Move(0, menuBarHeight);
w->Show(PR_FALSE);
NS_RELEASE(w);
}
if (mForward &&
NS_SUCCEEDED(mForward->QueryInterface(kIWidgetIID, (void**)&w))) {
w->Move(BUTTON_WIDTH, menuBarHeight);
w->Show(PR_FALSE);
NS_RELEASE(w);
}
@ -1512,9 +1545,9 @@ nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
}
rr.x += WEBSHELL_LEFT_INSET;
rr.y += WEBSHELL_TOP_INSET;
rr.y += WEBSHELL_TOP_INSET + menuBarHeight;
rr.width -= WEBSHELL_LEFT_INSET + WEBSHELL_RIGHT_INSET;
rr.height -= WEBSHELL_TOP_INSET + WEBSHELL_BOTTOM_INSET;
rr.height -= WEBSHELL_TOP_INSET + WEBSHELL_BOTTOM_INSET + menuBarHeight;
//Since allowing a negative height is a bad idea, let's condition this...
if(rr.height<0)

View File

@ -157,6 +157,7 @@ public:
// nsBrowserWindow
void SetWebCrawler(nsWebCrawler* aWebCrawler);
virtual nsresult CreateMenuBar(PRInt32 aWidth) = 0;
virtual nsresult GetMenuBarHeight(PRInt32 * aHeightOut);
virtual nsresult CreateToolBar(PRInt32 aWidth);
virtual nsresult CreateStatusBar(PRInt32 aWidth);
void Layout(PRInt32 aWidth, PRInt32 aHeight);
@ -312,6 +313,7 @@ public:
virtual nsresult CreateMenuBar(PRInt32 aWidth);
virtual nsEventStatus DispatchMenuItem(PRInt32 aID);
virtual nsresult GetMenuBarHeight(PRInt32 * aHeightOut);
protected:
NS_IMETHOD InitNativeWindow();

View File

@ -206,6 +206,16 @@ nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{

View File

@ -47,6 +47,16 @@ nsresult nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
return NS_OK;
}
nsEventStatus nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{
return nsBrowserWindow::DispatchMenuItem(aID);

View File

@ -101,6 +101,16 @@ nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{

View File

@ -84,6 +84,16 @@ nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{

View File

@ -60,10 +60,27 @@ nsNativeBrowserWindow::InitNativeWindow()
return NS_OK;
}
static GtkWidget * sgHackMenuBar = nsnull;
nsresult
nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
{
CreateViewerMenus(mWindow,this);
CreateViewerMenus(mWindow,this,&sgHackMenuBar);
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
if (nsnull != sgHackMenuBar)
{
*aHeightOut = sgHackMenuBar->allocation.height;
}
return NS_OK;
}

View File

@ -126,48 +126,32 @@ GtkItemFactoryEntry menu_items[] =
{ "/Tools/_Editor Mode", nsnull, (GIFC)gtk_ifactory_cb, EDITOR_MODE, nsnull }
};
void CreateViewerMenus(nsIWidget *aParent, gpointer data)
void CreateViewerMenus(nsIWidget * aParent,
gpointer data,
GtkWidget ** aMenuBarOut)
{
NS_ASSERTION(nsnull != aParent,"null parent.");
NS_ASSERTION(nsnull != aMenuBarOut,"null out param.");
GtkItemFactory *item_factory;
GtkWidget *window;
GtkWidget *menubar;
GtkWidget *vbox;
GtkWidget *aNParent = (GtkWidget*)aParent->GetNativeData(NS_NATIVE_WIDGET);
GtkWidget *gtkLayout = (GtkWidget*)aParent->GetNativeData(NS_NATIVE_WIDGET);
int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", nsnull);
gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, data);
/* HACK HACK HACK */
// apprunner no longer needs a vbox, so we're going to remove it
// viewer still use native menus, so we need a vbox, so we'll do a little reparenting dance
// and hack a vbox in.
// we no longer listen to the actual sizes of windows, and instead only listen to the size requested.
// this causes the menu to push the layout down, but the main window stays the same size.
// this means the status area at the bottom is off the page
// to fix that, the layout engine needs to think that the GTK Layout widget is mBounds.height - menubarheight
// i'm not entirely sure how to do this correctly. you could try calling GetBounds on aParent,
// then look at menubar->allocation.height and subtract the two, then call
// gtk_widget_set_usize(aNParent, mBounds.width, newheight)
// or something like that. i'm not entirely sure. this may work
menubar = gtk_item_factory_get_widget (item_factory, "<main>");
gtk_widget_show(menubar);
gtk_menu_bar_set_shadow_type (GTK_MENU_BAR(menubar), GTK_SHADOW_NONE);
window = aNParent->parent;
NS_ASSERTION(GTK_IS_LAYOUT(gtkLayout),"code assumes a GtkLayout widget.");
vbox = gtk_vbox_new(PR_FALSE, PR_FALSE);
gtk_widget_reparent(aNParent, vbox);
gtk_layout_put(GTK_LAYOUT(gtkLayout),menubar,0,0);
gtk_box_pack_start(GTK_BOX(vbox), menubar, PR_FALSE, PR_FALSE, 0);
gtk_box_reorder_child(GTK_BOX(vbox), menubar, 0);
gtk_widget_show(menubar);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
*aMenuBarOut = menubar;
}

View File

@ -26,7 +26,9 @@ typedef void (*MenuCallbackProc)(
PRUint32
);
void CreateViewerMenus(nsIWidget *aParent, gpointer data);
void CreateViewerMenus(nsIWidget * aParent,
gpointer data,
GtkWidget ** aMenuBarOut);
#endif // _nsMotifMenu_h_

View File

@ -70,6 +70,16 @@ nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 0;
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{

View File

@ -74,6 +74,16 @@ nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 50;
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{

View File

@ -55,6 +55,16 @@ nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
return NS_OK;
}
nsresult
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
{
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
*aHeightOut = 50;
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{