General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 01:55AM

I'm working on adding the macro tbtoggle() to the macros plugin.

Actually, I'm already done. It works great...but I can't figure something out, and it's really puzzling me.

I'm hoping asmpgmr or some else who is experienced with code can tell me what the heck is going on...


Ok, here's the deal...

In macros/macros.cpp:
------------------------------
1. Add "tbtoggle" to the bottom of enum commands {};

2. Add CMD_TEST(tbtoggle) to the bottom of int FindCommand(char *cmd) {}

3. Add the command after CMD(hostname) {} as follows:

/*
tbtoggle( idx, int );

Set visibility of toolband at (idx) to visible (int=1), or invisible (0).
*/

CMD(tbtoggle) {
if (nparam != 2) { // tbtoggle( $0, $1 )
parseError(WRONGARGS, "tbtoggle", data, 2, nparam);
return "";
}

int b = 0;
int idx = 80;

idx = atoi((char*)params[0].c_str());
b = atoi((char*)params[1].c_str());

kPlugin.kFuncs->ToolbarSetVisibility(idx, b);
return "";
}




Then over in Plugins.cpp:
-------------------------------------
1. Add the function:

void ToolbarSetVisibility (int idx, int b)
{
if(b==0)
theApp.m_pMostRecentBrowserFrame->m_wndReBar.SetVisibility(idx, FALSE);
else
theApp.m_pMostRecentBrowserFrame->m_wndReBar.SetVisibility(idx, TRUE);
}


2. Add "ToolbarSetVisibility" to the bottom of kmeleonFunctions kmelFuncs = {};



Last, in kmeleon_plugin.h
----------------------------------------
1. Add the definition as follows at the very bottom of the structure, typedef struct {} kmeleonFunctions;


// toggles toolbar visibility
void (*ToolbarSetVisibility)(int idx, int b);



Ok, now I make a macro as follows:
----------------------------------------------------
test{
$vis = "";
$tb_idx = getpref(INT,"kmeleon.toolband.Throbber.index");
getpref(BOOL, "kmeleon.toolband.Throbber.visibility")=="true" ? $vis="false" : $vis="true";
$vis == "true" ? setpref(BOOL, "kmeleon.toolband.Throbber.visibility", true) : setpref(BOOL, "kmeleon.toolband.Throbber.visibility", false);
$vis == "true" ? tbtoggle($tb_idx, 1) : tbtoggle($tb_idx, 0);
}


Now...expected behavior is that the Throbber would disapear, and the pref would be set to false, since it is visible by default and the pref is true...what actually happens is the pref is set to false and SOME OTHER toolband is hidden.

HUH?? That's what I said too...


So, after playing with this for a bit, I found out the correct index numbers that needed to be passed to m_wndReBar.SetVisibility()

0 for "Url Bar"
1 for "Throbber"
2 for "Layers"
3 for "Tool Bar"
4 for "QuickLaunch"
5 for "Menu"
6 for "Bookmarks"

and so on...

The problem is that these don't match the index in the pref file, which says:

user_pref("kmeleon.toolband.Menu.index", 0);
user_pref("kmeleon.toolband.Quicklaunch.index", 1);
user_pref("kmeleon.toolband.Tool Bar.index", 2);
user_pref("kmeleon.toolband.Bookmarks.index", 3);
user_pref("kmeleon.toolband.URL Bar.index", 4);
user_pref("kmeleon.toolband.Throbber.index", 5);
user_pref("kmeleon.toolband.Layers.index", 6);


And these values in Prefs.js change based on the z-order of the toolbars.

Now, I also tried unprotecting the function member FindByName() and using the value it returned as the index, but it returned the same value that is in the prefs file...

I am trying to figure out how to get this real index values above, as opposed to the z-order index values stored in the prefs file.

I'm thinking the order for the real index values go like this:

K-meleon defaults:
0 for "Url Bar"
1 for "Throbber"

If the layers plugin is loaded:
2 for "Layers"

Toolbar default toolband, plus any extra in toolbars.cfg:
3 for "Tool Bar"
4 for "QuickLaunch"

Menu defaults from menus.cfg:
5 for "Menu"

Any extra plugin toolbars:
6 for "Bookmarks"
(????) 7 for "Hotlist" (????)
(????) 8 for "Favorites" (????)

One good thing however, is that after you figure out the real index values they don't seem to change.


Any help would be greatly appreciated!!!


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 04:48AM

This is a bit cleaner code, but still got no idea about the index numbers...

In macros/macros.cpp:
------------------------------
1. Add "tbtoggle" to the bottom of enum commands {};

2. Add CMD_TEST(tbtoggle) to the bottom of int FindCommand(char *cmd) {}

3. Add the command after CMD(hostname) {} as follows:

/*
tbtoggle( idx );

Toggle visibility of toolband at (idx).
*/

CMD(tbtoggle) {
if (nparam != 1) { // tbtoggle( $0 )
parseError(WRONGARGS, "tbtoggle", data, 1, nparam);
return "";
}

int idx = 80;
idx = atoi((char*)params[0].c_str());

kPlugin.kFuncs->ToggleToolbarVisibility(idx);
return "";
}




Then over in Plugins.cpp:
-------------------------------------
1. Add the function:

void ToggleToolbarVisibility (int idx)
{
if (idx >= 0)
theApp.m_pMostRecentBrowserFrame->m_wndReBar.ToggleVisibility(idx);
else
return;
}


2. Add "ToggleToolbarVisibility" to the bottom of kmeleonFunctions kmelFuncs = {};



Last, in kmeleon_plugin.h
----------------------------------------
1. Add the definition as follows at the very bottom of the structure, typedef struct {} kmeleonFunctions;


// toggles toolbar visibility
void (*ToggleToolbarVisibility)(int idx);



The macro can now be:
---------------------------------
test{
getpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility")=="true" ? setpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility", false) : setpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility", true);
tbtoggle(4);
}


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: asmpgmr
Date: March 29, 2003 05:04AM

MonkeeSage,

In accel.cfg use the values 2000 - 2049 instead of ID strings. In my setup I have the menu bar (which is static) and on the next row, the toolbar (back,forward,reload,stop), url bar, and throbber. 2000 = url bar, 2001 = throbber, 2002 = tool bar.
So ALT 1 = 2002 in accel.cfg toggles the tool bar. I have no idea (yet) what the deal is with the order. In prefs.js they're in screen order (0 = tool bar, 1 = url bar, 2 = throbber). Note there is a ID_VIEW_STATUS_BAR command which toggles the status bar.

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 05:10AM

I'm also playing around with thess macros based on the tbtoggle command....

macros.cfg:
----------------

hide_all {
getpref(BOOL, "kmeleon.toolband.URL Bar.index")=="true" ? tbtoggle(0) : 0;
getpref(BOOL, "kmeleon.toolband.Throbber.index")=="true" ? tbtoggle(1) : 0;
getpref(BOOL, "kmeleon.toolband.Layers.index")=="true" ? tbtoggle(2) : 0;
getpref(BOOL, "kmeleon.toolband.Tool Bar.index")=="true" ? tbtoggle(3) : 0;
getpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility")=="true" ? tbtoggle(4) : 0;
getpref(BOOL, "kmeleon.toolband.Menu.index")=="true" ? tbtoggle(5) : 0;
getpref(BOOL, "kmeleon.toolband.Bookmarks.index")=="true" ? tbtoggle(6) : 0;
}

show_all {
getpref(BOOL, "kmeleon.toolband.URL Bar.index")=="false" ? tbtoggle(0) : 0;
getpref(BOOL, "kmeleon.toolband.Throbber.index")=="false" ? tbtoggle(1) : 0;
getpref(BOOL, "kmeleon.toolband.Layers.index")=="false" ? tbtoggle(2) : 0;
getpref(BOOL, "kmeleon.toolband.Tool Bar.index")=="false" ? tbtoggle(3) : 0;
getpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility")=="false" ? tbtoggle(4) : 0;
getpref(BOOL, "kmeleon.toolband.Menu.index")=="false" ? tbtoggle(5) : 0;
getpref(BOOL, "kmeleon.toolband.Bookmarks.index")=="false" ? tbtoggle(6) : 0;
}


I then have them linked to accels...kind of a cool effect...a pseudo-fullscreen mode if you will, without having the whole frame maximized... smiling smiley


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 05:22AM

LOL...yeah, that's gonna work well heh...I copied the wrong one, that wasn't the finished macro...here it is:

hide_all {
getpref(BOOL, "kmeleon.toolband.URL Bar.visibility")=="true" ? tbtoggle(0) : 0;
getpref(BOOL, "kmeleon.toolband.Throbber.visibility")=="true" ? tbtoggle(1) : 0;
getpref(BOOL, "kmeleon.toolband.Layers.visibility")=="true" ? tbtoggle(2) : 0;
getpref(BOOL, "kmeleon.toolband.Tool Bar.visibility")=="true" ? tbtoggle(3) : 0;
getpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility")=="true" ? tbtoggle(4) : 0;
getpref(BOOL, "kmeleon.toolband.Menu.visibility")=="true" ? tbtoggle(5) : 0;
getpref(BOOL, "kmeleon.toolband.Bookmarks.visibility")=="true" ? tbtoggle(6) : 0;
}

show_all {
getpref(BOOL, "kmeleon.toolband.URL Bar.visibility")=="false" ? tbtoggle(0) : 0;
getpref(BOOL, "kmeleon.toolband.Throbber.visibility")=="false" ? tbtoggle(1) : 0;
getpref(BOOL, "kmeleon.toolband.Layers.visibility")=="false" ? tbtoggle(2) : 0;
getpref(BOOL, "kmeleon.toolband.Tool Bar.visibility")=="false" ? tbtoggle(3) : 0;
getpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility")=="false" ? tbtoggle(4) : 0;
getpref(BOOL, "kmeleon.toolband.Menu.visibility")=="false" ? tbtoggle(5) : 0;
getpref(BOOL, "kmeleon.toolband.Bookmarks.visibility")=="false" ? tbtoggle(6) : 0;
}


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 05:27AM

Actually, only one is needed...

toggle_all_visible {
getpref(BOOL, "kmeleon.toolband.URL Bar.visibility")=="true" ? tbtoggle(0) : 0;
getpref(BOOL, "kmeleon.toolband.Throbber.visibility")=="true" ? tbtoggle(1) : 0;
getpref(BOOL, "kmeleon.toolband.Layers.visibility")=="true" ? tbtoggle(2) : 0;
getpref(BOOL, "kmeleon.toolband.Tool Bar.visibility")=="true" ? tbtoggle(3) : 0;
getpref(BOOL, "kmeleon.toolband.Quicklaunch.visibility")=="true" ? tbtoggle(4) : 0;
getpref(BOOL, "kmeleon.toolband.Menu.visibility")=="true" ? tbtoggle(5) : 0;
getpref(BOOL, "kmeleon.toolband.Bookmarks.visibility")=="true" ? tbtoggle(6) : 0;
}


That will set all the visible to invisible, but since we're not changing the perf file there, they will still all have the same settings, so running the same macro again will reshow the originally showing toolbands--exactly like the fullscreen plugin does. grinning smiley


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 05:48AM

asmpgmr:

I just saw your note, thanks for the tips!


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 06:28AM

asmpgmr:

OK, this appears to be the rundown on the index values:

From what I can gather all values are relative to 0.

If any particular toolband is not LOADED (I don't mean not showing, I mean the plugin is not loaded or, the plugin is loaded but the toolbar option is not enabled), then the values change relatively.

Here are the values with all the toolbars possible, as well as an extra one from toolbars.cfg (namely, Quicklaunch):

0 - toolband.URL Bar
1 - toolband.Throbber

2 - toolband.Layers

3 - toolband.Hotlist
4 - toolband.Favorites

5 - toolband.Winamp

6 - toolband.Tool Bar
7 - toolband.Quicklaunch

8 - toolband.Menu

9 - toolband.Bookmarks


Here is what they look like without the Hotlist or Favorites plugins loaded:

0 - toolband.URL Bar
1 - toolband.Throbber

2 - toolband.Layers

3 - toolband.Winamp

4 - toolband.Tool Bar
5 - toolband.Quicklaunch

6 - toolband.Menu

7 - toolband.Bookmarks


Here is what they look like without the Hotlist or Favorites or Winamp plugins loaded, and without the Quicklaunch definition in toolbars.cfg:

0 - toolband.URL Bar
1 - toolband.Throbber

2 - toolband.Layers

3 - toolband.Tool Bar

4 - toolband.Menu

5 - toolband.Bookmarks


Can you please confirm this, and also test out the tbtoggle() functionality?

http://monkeesage.d2g.com/k-meleon.exe
http://monkeesage.d2g.com/macros.dll

Thanks!


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 06:58AM

Ps. Here's a simple macro for testing the different index values:

test{
$n=prompt("Index:", "Toggle TB index", "");
tbtoggle($n);
}

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 29, 2003 09:03AM

I added both the toggle and set...

Syntax:
-----------
tbtoggle(idx)

- Toggle the visible / hidden state of toolband with index of idx


tbset(idx, vis)

- Set the visible state of toolband with index of idx to vis (1=visible, 0=hidden)


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: asmpgmr
Date: March 29, 2003 02:53PM

MonkeeSage,

The index numbers are assigned in toolbar creation order so the URL bar will always be first (0) and the throbber second (1), then the plugins, most likely in the order they are in the kplugins subdirectory.

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: asmpgmr
Date: March 29, 2003 06:10PM

On the issue of accelerators here's a minor update - currently the pgup and pgdn keys are VK_PRIOR and VK_NEXT (apparently a win32 thing). There should be aliases VK_PAGE_UP and VK_PAGE_DOWN. Adding the following to AccelParser.cpp addresses this (bug 376):

After the VK_OEM definitions add:

#define VK_PAGE_UP VK_PRIOR
#define VK_PAGE_DOWN VK_NEXT

and in routine Parse:

VK_TEST(PRIOR) // page up
VK_TEST(NEXT) // page down
VK_TEST(PAGE_UP)
VK_TEST(PAGE_DOWN)

Options: ReplyQuote
Re: Hiding toolbars with a macro...
Posted by: MonkeeSage
Date: March 30, 2003 02:25AM

asmpgmr:

Yup, that worked. Bug 376 is fixed. In a few minutes I'll update the binary at http://monkeesage.d2g.com/k-meleon.exe for this fix and the prefs panel fix.


Shelumi`El
Jordan

S.D.G

Options: ReplyQuote


K-Meleon forum is powered by Phorum.