From d3362370f5e8f440d2233629cc57e6f355b17b11 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 2 May 2005 01:17:08 +0000 Subject: cleaning, create and delete tabs with FbWinFrame createTab/removeTab --- src/FbWinFrame.cc | 37 ++++++++++++++++---------- src/FbWinFrame.hh | 16 +++++++---- src/Window.cc | 79 ++++++++++++++++++------------------------------------- 3 files changed, 59 insertions(+), 73 deletions(-) diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index a1745ef..fe33c09 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -331,33 +331,41 @@ void FbWinFrame::removeAllButtons() { } } -void FbWinFrame::addLabelButton(FbTk::TextButton &btn) { - LabelList::iterator found_it = find(m_labelbuttons.begin(), - m_labelbuttons.end(), - &btn); +FbWinFrame::ButtonId FbWinFrame::createTab(const std::string &title, FbTk::Command *command) { + FbTk::TextButton *button = new FbTk::TextButton(label(), + theme().font(), + title); + button->show(); + button->setEventMask(ExposureMask | ButtonPressMask | + ButtonReleaseMask | ButtonMotionMask | + EnterWindowMask); - if (found_it != m_labelbuttons.end()) - return; - - btn.setTextPadding(Fluxbox::instance()->getTabsPadding()); - m_labelbuttons.push_back(&btn); + FbTk::RefCount refcmd(command); + button->setOnClick(refcmd); + + button->setTextPadding(Fluxbox::instance()->getTabsPadding()); + button->setJustify(theme().justify()); + + m_labelbuttons.push_back(button); if (currentLabel() == 0) - setLabelButtonFocus(btn); + setLabelButtonFocus(*button); + + return button; } -void FbWinFrame::removeLabelButton(FbTk::TextButton &btn) { +void FbWinFrame::removeTab(ButtonId btn) { LabelList::iterator erase_it = remove(m_labelbuttons.begin(), m_labelbuttons.end(), - &btn); + btn); if (erase_it == m_labelbuttons.end()) return; - if (&btn == m_current_label) + if (btn == m_current_label) m_current_label = 0; m_labelbuttons.erase(erase_it); - + delete btn; } @@ -550,6 +558,7 @@ void FbWinFrame::setClientWindow(FbTk::FbWindow &win) { m_clientarea.raise(); win.raise(); m_window.showSubwindows(); + } bool FbWinFrame::hideTitlebar() { diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh index 9bff974..1335694 100644 --- a/src/FbWinFrame.hh +++ b/src/FbWinFrame.hh @@ -51,6 +51,7 @@ class Texture; /// (see: image) class FbWinFrame:public FbTk::EventHandler { public: + typedef FbTk::TextButton *ButtonId; ///< defines a button id /// create a top level window FbWinFrame(FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl, @@ -81,10 +82,14 @@ public: void resizeForClient(unsigned int width, unsigned int height, int win_gravity=ForgetGravity); // for when there needs to be an atomic move+resize operation - void moveResizeForClient(int x, int y, unsigned int width, unsigned int height, bool move = true, bool resize = true, int win_gravity=ForgetGravity); + void moveResizeForClient(int x, int y, + unsigned int width, unsigned int height, + bool move = true, bool resize = true, int win_gravity=ForgetGravity); // can elect to ignore move or resize (mainly for use of move/resize individual functions - void moveResize(int x, int y, unsigned int width, unsigned int height, bool move = true, bool resize = true, int win_gravity=ForgetGravity); + void moveResize(int x, int y, + unsigned int width, unsigned int height, + bool move = true, bool resize = true, int win_gravity=ForgetGravity); /// some outside move/resize happened, and we need to notify all of our windows /// in case of transparency @@ -101,10 +106,11 @@ public: void addRightButton(FbTk::Button *btn); /// remove all buttons from titlebar void removeAllButtons(); - /// adds a button to label window - void addLabelButton(FbTk::TextButton &btn); + /// adds a button to label window with specified title and command + ButtonId createTab(const std::string &title, FbTk::Command *cmd); + // void addLabelButton(FbTk::TextButton &btn); /// removes a specific button from label window - void removeLabelButton(FbTk::TextButton &btn); + void removeTab(ButtonId id); /// move label button to the left void moveLabelButtonLeft(const FbTk::TextButton &btn); /// move label button to the right diff --git a/src/Window.cc b/src/Window.cc index e899300..50b6f53 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -338,10 +338,9 @@ FluxboxWindow::~FluxboxWindow() { Client2ButtonMap::iterator it = m_labelbuttons.begin(); Client2ButtonMap::iterator it_end = m_labelbuttons.end(); - for (; it != it_end; ++it) { - frame().removeLabelButton(*(*it).second); - delete (*it).second; - } + for (; it != it_end; ++it) + frame().removeTab((*it).second); + m_labelbuttons.clear(); m_timer.stop(); @@ -420,21 +419,14 @@ void FluxboxWindow::init() { frame().gripRight().setCursor(frame().theme().lowerRightAngleCursor()); - FbTk::TextButton *btn = new FbTk::TextButton(frame().label(), - frame().theme().font(), - m_client->title()); - btn->setJustify(frame().theme().justify()); + FbWinFrame::ButtonId btn = frame().createTab(m_client->title(), + new SetClientCmd(*m_client)); + m_labelbuttons[m_client] = btn; - frame().addLabelButton(*btn); frame().setLabelButtonFocus(*btn); - btn->show(); + FbTk::EventManager &evm = *FbTk::EventManager::instance(); - // we need motion notify so we mask it - btn->setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | EnterWindowMask); - FbTk::RefCount set_client_cmd(new SetClientCmd(*m_client)); - btn->setOnClick(set_client_cmd); evm.add(*this, btn->window()); // we take care of button events for this evm.add(*this, m_client->window()); @@ -668,11 +660,10 @@ void FluxboxWindow::attachClient(WinClient &client, int x, int y) { if (client.fbwindow() != 0) { FluxboxWindow *old_win = client.fbwindow(); // store old window - ClientList::iterator client_insert_pos=getClientInsertPosition(x,y); - FbTk::TextButton *button_insert_pos=NULL; - if(client_insert_pos!=m_clientlist.end()) - button_insert_pos=m_labelbuttons[*client_insert_pos]; - + ClientList::iterator client_insert_pos = getClientInsertPosition(x, y); + FbTk::TextButton *button_insert_pos = NULL; + if(client_insert_pos != m_clientlist.end()) + button_insert_pos = m_labelbuttons[*client_insert_pos]; // make sure we set new window search for each client ClientList::iterator client_it = old_win->clientList().begin(); @@ -693,29 +684,18 @@ void FluxboxWindow::attachClient(WinClient &client, int x, int y) { frame().clientArea().height()); (*client_it)->setFluxboxWindow(this); + // create a labelbutton for this client and // associate it with the pointer - FbTk::TextButton *btn = new FbTk::TextButton(frame().label(), - frame().theme().font(), - (*client_it)->title()); - btn->setJustify(frame().theme().justify()); + FbWinFrame::ButtonId btn = frame().createTab((*client_it)->title(), + new SetClientCmd(*(*client_it))); m_labelbuttons[(*client_it)] = btn; - frame().addLabelButton(*btn); - if(x >= 0) { - if(button_insert_pos){ //null if we want the new button at the end of the list - frame().moveLabelButtonLeftOf(*btn, *button_insert_pos); - } - } - btn->show(); - // we need motion notify so we mask it - btn->setEventMask(ExposureMask | ButtonPressMask | - ButtonReleaseMask | ButtonMotionMask | - EnterWindowMask); - - - FbTk::RefCount - set_client_cmd(new SetClientCmd(*(*client_it))); - btn->setOnClick(set_client_cmd); + + //null if we want the new button at the end of the list + if(x >= 0 && button_insert_pos) + frame().moveLabelButtonLeftOf(*btn, *button_insert_pos); + + evm.add(*this, btn->window()); // we take care of button events for this (*client_it)->saveBlackboxAttribs(m_blackbox_attrib); @@ -731,25 +711,17 @@ void FluxboxWindow::attachClient(WinClient &client, int x, int y) { } else { // client.fbwindow() == 0 // create a labelbutton for this client and associate it with the pointer - FbTk::TextButton *btn = new FbTk::TextButton(frame().label(), - frame().theme().font(), - client.title()); + FbWinFrame::ButtonId btn = frame().createTab(client.title(), + new SetClientCmd(client)); m_labelbuttons[&client] = btn; - frame().addLabelButton(*btn); - btn->show(); - FbTk::EventManager &evm = *FbTk::EventManager::instance(); - // we need motion notify so we mask it - btn->setEventMask(ExposureMask | ButtonPressMask | - ButtonReleaseMask | ButtonMotionMask | - EnterWindowMask); + FbTk::EventManager &evm = *FbTk::EventManager::instance(); - FbTk::RefCount set_client_cmd(new SetClientCmd(client)); - btn->setOnClick(set_client_cmd); evm.add(*this, btn->window()); // we take care of button events for this if (&client == focused_win) was_focused = focused_win; + client.setFluxboxWindow(this); client.saveBlackboxAttribs(m_blackbox_attrib); @@ -871,9 +843,8 @@ bool FluxboxWindow::removeClient(WinClient &client) { FbTk::TextButton *label_btn = m_labelbuttons[&client]; if (label_btn != 0) { - frame().removeLabelButton(*label_btn); + frame().removeTab(label_btn); evm.remove(label_btn->window()); - delete label_btn; label_btn = 0; } -- cgit v0.11.2