wxFlatNotebook

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Infinity_77
Experienced Solver
Experienced Solver
Posts: 89
Joined: Tue Oct 03, 2006 6:30 pm
Location: London, UK
Contact:

Post by Infinity_77 »

Hello Jorgen,
To hop into the discussion for a minute, are you sure you want to do that Andrea? If I as developer select a different page I am not wanting to get an event fired which might trigger other functionality or in some case, execute a selection again for nothing.
Yes, your are right about that... I was thinking about my first illogical point in the list I posted above. However, I think that navigation with Ctrl+[Shift]+Tab *and* AddPage/InsertPage/DeletePage should trigger an event in any case. I agree that doing it also for SetSelection from code is useless :-D

Andrea.
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.alice.it/infinity77/
phonxe
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri May 06, 2005 12:37 pm

Post by phonxe »

Hello Eran,
eranif wrote:
Why not use xpm image like you do in wxFlatNotebook.h?
Well, the xpm I uses in wxFlatNotebook.h, are very simple images which I drawed by hand. The png file I use (you can see it by enabling the Smart tabbing option, and press Ctrl+T), as much higher quality, and I afraid I could not find any reasonable png->xpm converter that will keep the image quality.

I will however, sure that I can find an alternate way to load it into memory without using the lost son class wxMemoryInputStream :wink:

Eran
The png image contains alpha channel data,
so if only we combine the RGB data(the converted xpm image) and
the alpha channel data that is extracted from the png image,
we can reproduce the original image and it's quality.

This is the converted XPM image (without Mask color):

Code: Select all

/* XPM */
static char *xxxxx_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 104 2",
"   c Black",
"M  c #3FB524",
"3  c #4CBAFF",
"{  c #004C00",
"1  c #006BE9",
"P  c #007200",
"!  c #0065DD",
"-  c #003FE5",
"Q  c #0056BC",
"*  c #0062E4",
"t  c #0945A7",
"7  c #2BBF1F",
"W  c #0050B8",
")  c #D59700",
"L  c #0E8508",
"A  c #0047B0",
"u  c #3D93E5",
"x  c #0044AD",
":  c #46C733",
"(  c #B18800",
"X  c #E3C247",
"O. c #D69B00",
"E  c #0041B1",
"`  c #824400",
"|  c #C59200",
".. c #7B4000",
"*. c #763C00",
"G  c #056ED4",
"f  c #088806",
"[  c #005100",
"p  c #006DDF",
"g  c #007700",
"U  c #6D6A00",
"<  c #4A4357",
"Z  c #0038B7",
"%  c #E1B024",
"K  c #16A40B",
" . c #986500",
"h  c #007100",
"e  c #002C9F",
"J  c #018101",
"C  c #4A3D58",
";  c #009400",
"v  c #078BF0",
"$. c #AC6F00",
"F  c #0055BC",
"s  c #36B01A",
"D  c #0052B8",
",  c #138E00",
"=  c #0058D3",
"5  c #47A9FF",
"~  c #006500",
"S  c #004CB2",
"n  c #047F02",
"T  c #572E17",
"m  c #37BA1A",
"X. c #D89D00",
"}  c #E49C00",
"6  c #0084FF",
"+  c #D3990C",
"l  c #0040A6",
"a  c #008200",
"_  c #9C6700",
"d  c #86EA4D",
"O  c #DCC042",
"#  c #C7C334",
"&. c #835000",
"B  c #007900",
"k  c #0037A9",
"#. c #7B3F00",
"y  c #3879CB",
"%. c #A26F00",
"N  c #007300",
".  c #D0A000",
"&  c #626651",
"j  c #594855",
"'  c #0031B3",
"q  c #007000",
"2  c #31AAFF",
"Y  c #A96700",
"]  c #0034C6",
"R  c #0028A7",
"@. c #9B6800",
"o  c #EAD96A",
"V  c #006700",
"4  c #4CACFB",
"9  c #9EFF63",
"^  c #006400",
"o. c #7A4000",
"b  c #0080E5",
"z  c #0045AC",
">  c #66DD42",
"I  c #005E00",
"c  c #125EBE",
"H  c #0080F5",
"w  c #584955",
"8  c #8BF35A",
"@  c #8E9300",
"/  c #005800",
"+. c #CA9700",
"i  c #0071DE",
"0  c #2DA51D",
"$  c #FFDE65",
"r  c #003098",
/* pixels */
"                                ",
"                                ",
"        . X o O +               ",
"        @ # $ % & * = -         ",
"      ; : > , < 1 2 3 4 5 6     ",
"    7 8 9 0 q w e r t y u i p   ",
"  a s d f g h j k l z x c v b   ",
"  n m M N B V C Z A S D F G H   ",
"  J K L P I U Y T R E W Q !     ",
"  h ~ ^ / ( ) _ `     ' ]       ",
"      [ { } |  ...              ",
"          X.|  .o.              ",
"          O.+.@.#.              ",
"          $.%.&.*.              ",
"                                ",
"                                "
};

And this is the Alpha Channel data from the png image.

Code: Select all

unsigned char xxxxx_alpha[]={
  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   7, 174, 240, 238, 148,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,  43, 254, 255, 255, 253, 104,  48,   4,   0,   0,   0,   0, 
  0,   0,   0,  60, 221, 255, 255, 255, 254, 254, 254, 244, 193,  51,   0,   0, 
  0,   0, 126, 252, 255, 255, 255, 255, 255, 255, 254, 254, 254, 224,  20,   0, 
  0,  33, 252, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 183,   0, 
  0, 137, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 128,   0, 
  0, 211, 254, 254, 255, 255, 255, 255, 246, 147, 216, 254, 225,  81,   0,   0, 
  0,  20, 162, 246, 234, 248, 255, 255, 238,   0,   0,  29,  11,   0,   0,   0, 
  0,   0,   0,  11,  20, 231, 255, 255, 235,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0, 223, 255, 255, 233,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0, 214, 255, 255, 231,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0, 137, 240, 236, 131,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0 };
we just need to call SetAlpha() additionally:

Code: Select all

wxImage img(xxxxx_xpm);
img.SetAlpha(xxxxx_alpha, true);
m_bmp =  wxBitmap(img);
PNG == XPM + AlphaChannel
The quality of the two images are the same.
In my opinion, use xpm+alpha is a more simple and less space solution.

:)
MadEdit
This is a Text/Hex Editor for Linux & Win32
eranif
Moderator
Moderator
Posts: 610
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif »

Thanks alot!

I will add it as soon as I get home from work :D

BTW,
How did you extract the alpha channel from the PNG?
The only tool I am familiar with is XnView, do you recommend another tool?

Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org
phonxe
Earned a small fee
Earned a small fee
Posts: 18
Joined: Fri May 06, 2005 12:37 pm

Post by phonxe »

Hello Eran,

Here is a converter:
http://madedit.sourceforge.net/image2xpm.7z

This Image Converter was modified from wxWidgets\samples\image.

It can convert many image formats to another image format,
and if the image has alpha channel,
it will also save alpha data to *.alpha in C/C++ format like xpm file.

I think it's enough for the task.
:)
MadEdit
This is a Text/Hex Editor for Linux & Win32
rjmyst3
Knows some wx things
Knows some wx things
Posts: 49
Joined: Tue Oct 10, 2006 7:02 pm
Contact:

Post by rjmyst3 »

Eran,
wxflatnotebook 2 is fantastic. I really like the new drop-down page selector and ctrl+tab.

I've noticed that codeblocks uses wxflatnotebook, and has multiple flatnotebooks for different purposes. I can drag tabs to different places within a notebook, but not to another notebook.

This behaviour makes sense, but doesn't seem to be implemented in the "true" source - so I dug around in codeblocks' copy of flatnotebook, and found the changes that make this work.

I apply this patch manually to each new release, but it would be nice if you would consider implementing it. Its a small change, so I've pasted the diffs below.

Diff for wxFlatNotebook.h

Code: Select all

@@ -80,6 +80,7 @@
 #define wxFNB_DCLICK_CLOSES_TABS		0x00001000
 #define wxFNB_SMART_TABS				0x00002000
 #define wxFNB_DROPDOWN_TABS_LIST		0x00004000
+#define wxFNB_ALLOW_FOREIGN_DND			0x00008000
 
 /// General macros
 #define VERTICAL_BORDER_PADDING			4

Diff for wxFlatNotebook.cpp

Code: Select all

@@ -1496,7 +1495,7 @@
 			}
 		}
 	}
-	else
+	else if ( GetWindowStyleFlag() & wxFNB_ALLOW_FOREIGN_DND )
 	{
 #if defined(__WXMSW__) || defined(__WXGTK__)
 		if(nTabPage >= 0)
eranif
Moderator
Moderator
Posts: 610
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif »

Hi,

I implemented it, it is now in CVS.

BTW, your code does not work with wxFNB_ALLOW_FOREIGN_DND enabled, to make it work, change this line

Code: Select all

else if ( GetWindowStyleFlag() & wxFNB_ALLOW_FOREIGN_DND )
to:

Code: Select all

else if ( GetParent()->GetWindowStyleFlag() & wxFNB_ALLOW_FOREIGN_DND )
Since wxPageContainer is child of wxFlatNotebook, which holds the styles.

Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org
Infinity_77
Experienced Solver
Experienced Solver
Posts: 89
Joined: Tue Oct 03, 2006 6:30 pm
Location: London, UK
Contact:

Post by Infinity_77 »

I've noticed that codeblocks uses wxflatnotebook, and has multiple flatnotebooks for different purposes. I can drag tabs to different places within a notebook, but not to another notebook
Of course you can. Have you tried the demo of wxFlatNotebook 2.0 at SourceForge? I can drag the tabs from the top notebook to the bottom one without problems.
Well, actually there is a bug when you do that: the second notebook "thinks" not to have enough room to display all the tabs (even if it has only 3 tabs): it enables the left navigation arrow and shifts the first tab out of sight. I corrected this behavior in the wxPython version.
Moreover, to let it act more VS-like, the user should be able to drag a tab *wherever* in the notebook region and not only inside another tab. If it is on the right of the lst tab, just append the tab at the end. If it it at left of the first tab, insert the dragged tab in the first position. In wxPython it is implemented like that (HitTest method, sorry I don't know if the forum will highlight also wxPython code...):

if bFoundMatch:
return FNB_TAB, tabIdx

if self._isdragging:
# We are doing DND, so check also the region outside the tabs
# try before the first tab

fullrect = self.GetClientRect()

pgInfo = self._pagesInfoVec[0]
tabRect = wx.Rect(0, pgInfo.GetPosition().y, pgInfo.GetPosition().x,
self.GetParent().GetSize().y)
if tabRect.Contains(pt):
return FNB_TAB, 0

# try after the last tab
pgInfo = self._pagesInfoVec[-1]
startpos = pgInfo.GetPosition().x+pgInfo.GetSize().x
tabRect = wx.Rect(startpos, pgInfo.GetPosition().y,
fullrect.width-startpos, self.GetParent().GetSize().y)

if tabRect.Contains(pt):
return FNB_TAB, len(self._pagesInfoVec)

# Default
return FNB_NOWHERE, -1


I set the variable self._isdragging when the notebook realizes that it is receiving a tab from another notebook.

However, try the wxFlatNotebook executable here:

http://prdownloads.sourceforge.net/wxfl ... p?download

Andrea.
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.alice.it/infinity77/
Infinity_77
Experienced Solver
Experienced Solver
Posts: 89
Joined: Tue Oct 03, 2006 6:30 pm
Location: London, UK
Contact:

Post by Infinity_77 »

Hi,

I implemented it, it is now in CVS.

BTW, your code does not work with wxFNB_ALLOW_FOREIGN_DND enabled, to make it work, change this line
I must have missed something of the starting question... how comes that the 2.0 executable allows you to DND between different notebooks? I have surely misunderstood something.

Andrea.
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.alice.it/infinity77/
Infinity_77
Experienced Solver
Experienced Solver
Posts: 89
Joined: Tue Oct 03, 2006 6:30 pm
Location: London, UK
Contact:

Post by Infinity_77 »

Sorry, got it right now... you would like to *block* that behavior :-D

Sorry to waste your bandwidth, it's time for me to get some rest instead of coming here and asking stupid questions :-D

Andrea.
"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.alice.it/infinity77/
rjmyst3
Knows some wx things
Knows some wx things
Posts: 49
Joined: Tue Oct 10, 2006 7:02 pm
Contact:

oops

Post by rjmyst3 »

BTW, your code does not work with wxFNB_ALLOW_FOREIGN_DND enabled, to make it work, change this line
oops. good catch!
I implemented it, it is now in CVS.
Thanks. That was quick work![/quote]
framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer »

Thumbs up for the new version.
I see you fixed the problems with tabs sometimes not displaying t full height ^^.
But I think you should disable draging tabs and draging tabs to foreign notebooks because in my app I use the tabs to display sensitive data that is displayed there because of the internal logic.

There are still problems with drag/drop. You should somehow cancel the operation if the tabs is dropped on an invalid target.

Note: the makefile fails on linux if wxWidgets is not installed with the standard / prefix (i have it installed somewhere else :D)
Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds
eranif
Moderator
Moderator
Posts: 610
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif »

But I think you should disable draging tabs and draging tabs to foreign notebooks because in my app I use the tabs to display sensitive data that is displayed there because of the internal logic.
Beside the problem mentioned in previous post here (by Infinity_77), are you familiar with another one? if so please provide me with details.
Note: the makefile fails on linux if wxWidgets is not installed with the standard / prefix (i have it installed somewhere else Very Happy)
Regards
The makefile is pretty generic I think, I am using the standard wx-config tool, in the makefile the path to your installation is not mentioned anywhere.
So, I guess that the problem is in wx-config tool.

Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org
eranif
Moderator
Moderator
Posts: 610
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif »

Hi,

After releasing version 2.0 I got some feedback that convinced me that there are some bugs that cant wait ... so i released today v2.1 with mainly bug fixes.

From the log:
========================================================
Version 2.1
========================================================

This version is released shortly after 2.0 since v2.0 contained many code changes, I expected feedback from user
which came ... (as expected)

So, the following changes fixes applies to v2.1:

- 'x' button on tabs with VS8 style
- dropping page on foreign notebook that does not have image list, while the page does have caused a crash
- Drawing problems with VS71 & Fancy style when selecting the bottoms tabs
- DeletePage, RemovePage now accepts second argument to allow user to disable page closing events
- Page changing events are now fired from SetSelection, to fix a problem where only mouse left click allowed users to handle the page changes event (e.g. Ctrl + T did not fire page changes event ... )
- If no right click menu is provided, an event wxEVT_COMMAND_FLATNOTEBOOK_CONTEXT_MENU is fired (a bug that existed preveneted this event to be fired)
- wxFNB_ALLOW_FOREIGN_DND style added (check the demo)
- All xpm files are now located on a single resource file
- the smart tabbing dialog icon, was replaced from PNG to XPM.


http://sourceforge.net/projects/wxflatnotebook

Sorry for any inconvinience,
With regards,
Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org
Belgabor
I live to help wx-kind
I live to help wx-kind
Posts: 173
Joined: Mon Sep 25, 2006 1:12 pm

Post by Belgabor »

Hi eranif,

as a Code::Blocks user I've enjoyed working with you control for quite a while now. To improve it further I'd like to pose a feature request in regards to how it is rendered when tabs overflow (ie there are to many to accomodate at the current width).

To illustrate my suggestion, here's a current pic from C::B:
Image
If I glance at this, the big blank space between the second tab and the arrow controls makes me assume "This control has only two tabs, no more to see on the right", even though I know (now) that the dark arrow indicates otherwise. (I'm not alone with this, someone else posted in the C::B forum that he couldn't find the Resources tab).

What I suggest is to render something like "broken" or half tabs to show even at a glance that there is more to see. Here is a photoshopped example of what I approximately imagine:
Image

I hope this isn't too hard to add and you'll consider it, as I think it would be an important addition.

Cheers
rjmyst3
Knows some wx things
Knows some wx things
Posts: 49
Joined: Tue Oct 10, 2006 7:02 pm
Contact:

Post by rjmyst3 »

i agree with belgabor
Post Reply