Author Topic: BOUNTY: Notebook class with "close" button at the right  (Read 155138 times)

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
BOUNTY: Notebook class with "close" button at the right
« on: August 02, 2005, 04:09:03 am »
OK Guys. I think the solution's much easier than I thought. Still, it's going to be a hard work implementing it, and I need your help.


There *IS* a wxTabCtrl. What we need to do is replicate (and possibly EXTEND like with tab context menus) the exact functionality of a wxNotebook by having the following structure:

<wxPanel>
  <wxBoxSizer with vertical orientation>
    <sizeritem: wxPanel>
    <wxBoxSizer with horizontal orientation>
      <sizeritem: wxTabCtrl />
      <sizeritem: wxBitmapButton />
    </wxBoxSizer>
    </sizeritem: wxPanel>
    <sizeritem: wxPanel>   
     <wxBoxSizer>
     <content goes here>
     </wxBoxSizer>
    </sizeritem:wxPanel>
  </wxBoxSizer>
</wxPanel>

If ANYONE can provide us with such a class, we'd be REALLY grateful.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #1 on: August 02, 2005, 08:29:49 am »
Quote from: wxWidgets' wiki
wxTabCtrl is only supported under Win32, MacOS and OS/2.

And in fact, tabctrl.h hasn't include when using __WXGTK__:

Code
#if defined(__WXMSW__)
#include "wx/msw/tabctrl.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/tabctrl.h"
#elif defined(__WXGTK__)
#elif defined(__WXMAC__)
#include "wx/mac/tabctrl.h"
#elif defined(__WXPM__)
#include "wx/os2/tabctrl.h"
#endif

It seems like it won't help either.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #2 on: August 02, 2005, 09:45:39 am »
Bummer. :( It was doing so well...

HMMMMMMMMMM wait a minute....

:D I know! We'll implement the modified notebook if we're on windows, and the standard notebook if we're on Linux! Well, that solves half of the problem at least... :roll:

takeshimiya

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #3 on: August 08, 2005, 01:29:46 am »
Damn GTK and her native tab widgets :P
Well, from now C::B will use motif in linux :D (joke)

But seriously talking, I think that I saw some discussion about this in the wx mailing list, or it was a wx bounty (don't remember well)

Offline AkiraDev

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #4 on: August 08, 2005, 02:17:55 am »
How about having the main frame count the amount of open files, and if there is at least one, a small close button is drawn on top of the menu bar, to the right (emulating "classic" MDI) ?

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #5 on: August 08, 2005, 06:55:26 am »
On top of the menubar... hmmmm not bad.
Unfortunately my wxWidgets expertise isn't as broad as to try to implement that. Implementations welcome.

takeshimiya

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #6 on: August 10, 2005, 05:23:14 am »
On Wed, 3 Oct 2001 18:13:13 -0700 David Cuny <dcuny@xxxxxxxxxx> wrote:

DC> Has the wxTabCtrl deprecated for wxNotebook?

Yes, it is/was - and since a long time as well. Please don't use it in the
new code, it's old and unmaintained and has no advantages (but plenty of
problems) compared to wxNotebook.

It should still be in the source tree but it's not built into the library
by default.

Regards,
VZ
« Last Edit: August 10, 2005, 05:53:30 am by takeshimiya »

DreadNot

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #7 on: August 10, 2005, 06:50:04 pm »
Copy of post from http://forums.codeblocks.org/index.php/topic,633.msg4646.html#msg4646:

As far as the toolbar is concerned, add the following buttons after Save:
1] Save All
2] Close (current tab/file)
3] Close All

Did anyone notice that Mozilla also has a "New Tab" button on the left side as well as a "Close Tab" on the right.

The notebook code calls "wx/generic/tabg.h", so what I believe needs to be changed is "tabg.h" and "tabg.cpp" in wx to have a controlled left and right margin something like it has for the top margin.  I think these files are generic to all wx versions.  The left/right margin should act something like (and in addition to) the m_tabHorizontalOffset value.  These margins would allow the addition of the button(s) to the left and right sides of the notebook in the tabs area.

In addition, the left/right margin values should default to the current values (which I beleive are hardcoded to 4 in /msw/).  The values should be setable in wxNotebook [void SetMargins(const int &left, const int &right)], passed to the wxTabView via wxNotebookTabView in src/(whatever)/notebook.cpp, and used in wxTabView::LayoutTabs().
Adding the buttons in the margin could be done separately (via Yannis solution) or in a derived wxNotebook class as suggested.

Also, should we consider moving tabs (drag-n-drop) in the wxNotebook class?  Maybe add a bool m_bMovablePages.  If true, tabs in the tablist can be rearranged via mouse using RemovePage()/InsertPage().

UPDATE: Sorry, most of this is only good for MOTIF.  Windows would have to somehow resize the tab area width to be less than the page width.
« Last Edit: August 10, 2005, 08:12:09 pm by DreadNot »

kimastergeorge

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #8 on: August 11, 2005, 12:09:37 am »
I have an idea that might work:

Make a subclass of wxControl that has some sort of wxSizer or something just to keep the different widgets on top of each other. Then put a wxNotebook with all the wxPanels blank/empty inside the control (this way, we avoid using wxTabCtrl and its bugs/non-portability). Make sure all the wxPanels have a height of 0. Somehow, you'd have to make wxNotebook only as high as the tabs. Then, below, you'd put whatever wxPanel you want shown. You could add whatever buttons you want on the left and right of the wxNotebook (with a sizer). Then, to switch pages, you just use wxNotebook's EVT_NOTEBOOK_PAGE_CHANGED/EVT_NOTEBOOK_PAGE_CHANGING to detect when to change the panel that is shown (and then create new events for your new control which mirror those events). You could also combine this with the middle-click-close etc. ideas.

aMule (http://www.amule.org/) also has a different way to make closable notebook pages, although you can't have any images in the tabs if you use their way. Their method is having a close button as the image for each tab, and when the image is clicked, that tab is closed. It also has a right-click menu on the tabs that allow you to close that tab, close all tabs, or close all except that tab.

BTW, I'm not a developer for Code::Blocks, and I probably will never touch the code, it's just I want this control just as much as you do. I'll give you the code I come up with, if I come up with a result first.
« Last Edit: August 11, 2005, 12:23:03 am by kimastergeorge »

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #9 on: August 11, 2005, 02:31:43 am »
I have an idea that might work:

...Somehow, you'd have to make wxNotebook only as high as the tabs.

Brilliant! That would be the perfect replacement! Will you do it please? :D (we're too busy fixing bugs, youknow)

kimastergeorge

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #10 on: August 11, 2005, 04:12:40 am »
Yeah, I've already started. My goal is to make it look almost exactly like Firefox's tabs (although that might be impossible) and behave just like a wxNotebook.

takeshimiya

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #11 on: August 11, 2005, 06:08:38 am »
Yeah! I vote for exactly Firefox tabs!  :D

kimastergeorge

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #12 on: August 12, 2005, 02:07:20 am »
So...

I've got one. It doesn't have middle-click-close or right-click menus yet, but it does switch pages and close them with the button. The code might not be totally readable... but it should work.

The code is attached.

If anybody knows how to make it behave more like a real wxControl (currently it's just a wxPanel), I'd appreciate it if they'd tell me... or do it for me (for example, styles?).

Also, it looks a bit.... not right. I tried overloading wxWindow's Layout() to move the sizer which contains the displayed panel up 2 pixels, to remove that little bit of space between the wxNotebook and the panels, but that just ends up with the screen flashing a bunch, even if I do use Freeze/Thaw.

The syntax is pretty obvious; just like any other wxWindow, except, after the id, there's an argument of the bitmap for the close button. Currently, the close button doesn't have any borders, so it really doesn't look like a button at all (you can add in some code to change the image when it's clicked, if you want). You could add borders, too, by removing the wxNO_BORDERS for the wxBitmapButton.

[attachment deleted by admin]
« Last Edit: August 12, 2005, 02:09:17 am by kimastergeorge »

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #13 on: August 12, 2005, 09:04:37 am »
Mind attaching some screenshots, so we can see how it looks?

kimastergeorge

  • Guest
Re: BOUNTY: Notebook class with "close" button at the right
« Reply #14 on: August 12, 2005, 09:47:31 pm »
Yeah... I developed it on Windows, and I found a big, huge bug on wxGTK (which might occur on other systems, too).

It is a wxGTK bug, actually: when the wxNotebook isn't shown yet, and you change tabs (through SetSelection) it doesn't call the event handler, so I changed the SetSelection function. I've attached the new version.

A screenshot on wxGTK is attached. I'll add a Windows screenshot later.

The little black dot in the upper-left corner is the close button. I just used a random bitmap I had on my machine for it. On wxGTK, though, the button, even without borders, pops up when you select it, so it ends up only showing a little bit of the picture.

[attachment deleted by admin]