lltoolbar.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "lltoolbar.h"
00036 
00037 #include "imageids.h"
00038 #include "llfontgl.h"
00039 #include "llrect.h"
00040 #include "llparcel.h"
00041 
00042 #include "llagent.h"
00043 #include "llbutton.h"
00044 #include "llfocusmgr.h"
00045 #include "llviewercontrol.h"
00046 #include "llmenucommands.h"
00047 #include "llimview.h"
00048 #include "lluiconstants.h"
00049 #include "llvoavatar.h"
00050 #include "lltooldraganddrop.h"
00051 #include "llinventoryview.h"
00052 #include "llfloaterchatterbox.h"
00053 #include "llfloaterfriends.h"
00054 #include "llfloatersnapshot.h"
00055 #include "lltoolmgr.h"
00056 #include "llui.h"
00057 #include "llviewermenu.h"
00058 #include "llfirstuse.h"
00059 #include "llviewerparcelmgr.h"
00060 #include "lluictrlfactory.h"
00061 #include "llviewerwindow.h"
00062 #include "lltoolgrab.h"
00063 #include "llcombobox.h"
00064 #include "llfloaterchat.h"
00065 #include "llfloatermute.h"
00066 #include "llimpanel.h"
00067 #include "llscrolllistctrl.h"
00068 
00069 #if LL_DARWIN
00070 
00071         #include "llresizehandle.h"
00072 
00073         // This class draws like an LLResizeHandle but has no interactivity.
00074         // It's just there to provide a cue to the user that the lower right corner of the window functions as a resize handle.
00075         class LLFakeResizeHandle : public LLResizeHandle
00076         {
00077         public:
00078                 LLFakeResizeHandle(const LLString& name, const LLRect& rect, S32 min_width, S32 min_height, ECorner corner = RIGHT_BOTTOM )
00079                 : LLResizeHandle(name, rect, min_width, min_height, corner )
00080                 {
00081                         
00082                 }
00083 
00084                 virtual BOOL    handleHover(S32 x, S32 y, MASK mask)   { return FALSE; };
00085                 virtual BOOL    handleMouseDown(S32 x, S32 y, MASK mask)  { return FALSE; };
00086                 virtual BOOL    handleMouseUp(S32 x, S32 y, MASK mask)   { return FALSE; };
00087 
00088         };
00089 
00090 #endif // LL_DARWIN
00091 
00092 //
00093 // Globals
00094 //
00095 
00096 LLToolBar *gToolBar = NULL;
00097 S32 TOOL_BAR_HEIGHT = 20;
00098 
00099 //
00100 // Statics
00101 //
00102 F32     LLToolBar::sInventoryAutoOpenTime = 1.f;
00103 
00104 //
00105 // Functions
00106 //
00107 
00108 LLToolBar::LLToolBar()
00109 :       LLPanel()
00110 #if LL_DARWIN
00111         , mResizeHandle(NULL)
00112 #endif // LL_DARWIN
00113 {
00114         setIsChrome(TRUE);
00115         setFocusRoot(TRUE);
00116 }
00117 
00118 
00119 BOOL LLToolBar::postBuild()
00120 {
00121         childSetCommitCallback("communicate_btn", onClickCommunicate, this);
00122         childSetControlName("communicate_btn", "ShowCommunicate");
00123 
00124         childSetAction("chat_btn", onClickChat, this);
00125         childSetControlName("chat_btn", "ChatVisible");
00126 
00127         childSetAction("appearance_btn", onClickAppearance, this);
00128         childSetControlName("appearance_btn", "");
00129 
00130         childSetAction("clothing_btn", onClickClothing, this);
00131         childSetControlName("clothing_btn", "ClothingBtnState");
00132 
00133         childSetAction("fly_btn", onClickFly, this);
00134         childSetControlName("fly_btn", "FlyBtnState");
00135 
00136         childSetAction("sit_btn", onClickSit, this);
00137         childSetControlName("sit_btn", "SitBtnState");
00138 
00139         childSetAction("snapshot_btn", onClickSnapshot, this);
00140         childSetControlName("snapshot_btn", "");
00141 
00142         childSetAction("directory_btn", onClickDirectory, this);
00143         childSetControlName("directory_btn", "ShowDirectory");
00144 
00145         childSetAction("build_btn", onClickBuild, this);
00146         childSetControlName("build_btn", "BuildBtnState");
00147 
00148         childSetAction("radar_btn", onClickRadar, this);
00149         childSetControlName("radar_btn", "ShowMiniMap");
00150 
00151         childSetAction("map_btn", onClickMap, this);
00152         childSetControlName("map_btn", "ShowWorldMap");
00153 
00154         childSetAction("inventory_btn", onClickInventory, this);
00155         childSetControlName("inventory_btn", "ShowInventory");
00156 
00157         for (child_list_const_iter_t child_iter = getChildList()->begin();
00158                  child_iter != getChildList()->end(); ++child_iter)
00159         {
00160                 LLView *view = *child_iter;
00161                 LLButton* buttonp = dynamic_cast<LLButton*>(view);
00162                 if(buttonp)
00163                 {
00164                         buttonp->setSoundFlags(LLView::SILENT);
00165                 }
00166         }
00167 
00168 #if LL_DARWIN
00169         if(mResizeHandle == NULL)
00170         {
00171                 LLRect rect(0, 0, RESIZE_HANDLE_WIDTH, RESIZE_HANDLE_HEIGHT);
00172                 mResizeHandle = new LLFakeResizeHandle(LLString(""), rect, RESIZE_HANDLE_WIDTH, RESIZE_HANDLE_HEIGHT);
00173                 this->addChildAtEnd(mResizeHandle);
00174                 LLLayoutStack* toolbar_stack = getChild<LLLayoutStack>("toolbar_stack");
00175                 toolbar_stack->reshape(toolbar_stack->getRect().getWidth() - RESIZE_HANDLE_WIDTH, toolbar_stack->getRect().getHeight());
00176         }
00177 #endif // LL_DARWIN
00178 
00179         layoutButtons();
00180 
00181         return TRUE;
00182 }
00183 
00184 LLToolBar::~LLToolBar()
00185 {
00186         // LLView destructor cleans up children
00187 }
00188 
00189 
00190 BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
00191                                                                          EDragAndDropType cargo_type,
00192                                                                          void* cargo_data,
00193                                                                          EAcceptance* accept,
00194                                                                          LLString& tooltip_msg)
00195 {
00196         LLButton* inventory_btn = getChild<LLButton>("inventory_btn");
00197         if (!inventory_btn) return FALSE;
00198 
00199         LLInventoryView* active_inventory = LLInventoryView::getActiveInventory();
00200 
00201         if(active_inventory && active_inventory->getVisible())
00202         {
00203                 mInventoryAutoOpen = FALSE;
00204         }
00205         else if (inventory_btn->getRect().pointInRect(x, y))
00206         {
00207                 if (mInventoryAutoOpen)
00208                 {
00209                         if (!(active_inventory && active_inventory->getVisible()) && 
00210                         mInventoryAutoOpenTimer.getElapsedTimeF32() > sInventoryAutoOpenTime)
00211                         {
00212                                 LLInventoryView::showAgentInventory();
00213                         }
00214                 }
00215                 else
00216                 {
00217                         mInventoryAutoOpen = TRUE;
00218                         mInventoryAutoOpenTimer.reset();
00219                 }
00220         }
00221 
00222         return LLPanel::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
00223 }
00224 
00225 // static
00226 void LLToolBar::toggle(void*)
00227 {
00228         BOOL show = gSavedSettings.getBOOL("ShowToolBar");                      
00229         gSavedSettings.setBOOL("ShowToolBar", !show);                           
00230         gToolBar->setVisible(!show);
00231 }
00232 
00233 
00234 // static
00235 BOOL LLToolBar::visible(void*)
00236 {
00237         return gToolBar->getVisible();
00238 }
00239 
00240 
00241 void LLToolBar::layoutButtons()
00242 {
00243 #if LL_DARWIN
00244         const S32 FUDGE_WIDTH_OF_SCREEN = 4;                                    
00245         S32 width = gViewerWindow->getWindowWidth() + FUDGE_WIDTH_OF_SCREEN;   
00246         S32 pad = 2;
00247 
00248         // this function may be called before postBuild(), in which case mResizeHandle won't have been set up yet.
00249         if(mResizeHandle != NULL)
00250         {
00251                 if(!gViewerWindow->getWindow()->getFullscreen())
00252                 {
00253                         // Only when running in windowed mode on the Mac, leave room for a resize widget on the right edge of the bar.
00254                         width -= RESIZE_HANDLE_WIDTH;
00255 
00256                         LLRect r;
00257                         r.mLeft = width - pad;
00258                         r.mBottom = 0;
00259                         r.mRight = r.mLeft + RESIZE_HANDLE_WIDTH;
00260                         r.mTop = r.mBottom + RESIZE_HANDLE_HEIGHT;
00261                         mResizeHandle->setRect(r);
00262                         mResizeHandle->setVisible(TRUE);
00263                 }
00264                 else
00265                 {
00266                         mResizeHandle->setVisible(FALSE);
00267                 }
00268         }
00269 #endif // LL_DARWIN
00270 }
00271 
00272 
00273 // virtual
00274 void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent)
00275 {
00276         LLPanel::reshape(width, height, called_from_parent);
00277 
00278         layoutButtons();
00279 }
00280 
00281 
00282 // Per-frame updates of visibility
00283 void LLToolBar::refresh()
00284 {
00285         BOOL show = gSavedSettings.getBOOL("ShowToolBar");
00286         BOOL mouselook = gAgent.cameraMouselook();
00287         setVisible(show && !mouselook);
00288 
00289         // Clothing button updated inside LLFloaterClothing
00290 
00291         BOOL sitting = FALSE;
00292         if (gAgent.getAvatarObject())
00293         {
00294                 sitting = gAgent.getAvatarObject()->mIsSitting;
00295         }
00296 
00297         childSetEnabled("fly_btn", (gAgent.canFly() || gAgent.getFlying()) && !sitting );
00298 
00299         childSetEnabled("build_btn", LLViewerParcelMgr::getInstance()->agentCanBuild() );
00300 
00301         // Check to see if we're in build mode
00302         BOOL build_mode = LLToolMgr::getInstance()->inEdit();
00303         // And not just clicking on a scripted object
00304         if (LLToolGrab::getInstance()->getHideBuildHighlight())
00305         {
00306                 build_mode = FALSE;
00307         }
00308         gSavedSettings.setBOOL("BuildBtnState", build_mode);
00309 
00310         updateCommunicateList();
00311 }
00312 
00313 void LLToolBar::updateCommunicateList()
00314 {
00315         LLFlyoutButton* communicate_button = getChild<LLFlyoutButton>("communicate_btn");
00316         LLSD selected = communicate_button->getValue();
00317 
00318         communicate_button->removeall();
00319 
00320         LLFloater* frontmost_floater = LLFloaterChatterBox::getInstance()->getActiveFloater();
00321         LLScrollListItem* itemp = NULL;
00322 
00323         itemp = communicate_button->add(LLFloaterMyFriends::getInstance()->getShortTitle(), LLSD("contacts"), ADD_TOP);
00324         if (LLFloaterMyFriends::getInstance() == frontmost_floater)
00325         {
00326                 ((LLScrollListText*)itemp->getColumn(0))->setFontStyle(LLFontGL::BOLD);
00327                 // make sure current tab is selected in list
00328                 if (selected.isUndefined())
00329                 {
00330                         selected = itemp->getValue();
00331                 }
00332         }
00333         itemp = communicate_button->add(LLFloaterChat::getInstance()->getShortTitle(), LLSD("local chat"), ADD_TOP);
00334         if (LLFloaterChat::getInstance() == frontmost_floater)
00335         {
00336                 ((LLScrollListText*)itemp->getColumn(0))->setFontStyle(LLFontGL::BOLD);
00337                 if (selected.isUndefined())
00338                 {
00339                         selected = itemp->getValue();
00340                 }
00341         }
00342         communicate_button->addSeparator(ADD_TOP);
00343         communicate_button->add(getUIString("Redock Windows"), LLSD("redock"), ADD_TOP);
00344         communicate_button->addSeparator(ADD_TOP);
00345         communicate_button->add(LLFloaterMute::getInstance()->getShortTitle(), LLSD("mute list"), ADD_TOP);
00346         
00347         std::set<LLHandle<LLFloater> >::const_iterator floater_handle_it;
00348 
00349         if (gIMMgr->getIMFloaterHandles().size() > 0)
00350         {
00351                 communicate_button->addSeparator(ADD_TOP);
00352         }
00353 
00354         for(floater_handle_it = gIMMgr->getIMFloaterHandles().begin(); floater_handle_it != gIMMgr->getIMFloaterHandles().end(); ++floater_handle_it)
00355         {
00356                 LLFloaterIMPanel* im_floaterp = (LLFloaterIMPanel*)floater_handle_it->get();
00357                 if (im_floaterp)
00358                 {
00359                         LLString floater_title = im_floaterp->getNumUnreadMessages() > 0 ? "*" : "";
00360                         floater_title.append(im_floaterp->getShortTitle());
00361                         itemp = communicate_button->add(floater_title, im_floaterp->getSessionID(), ADD_TOP);
00362                         if (im_floaterp  == frontmost_floater)
00363                         {
00364                                 ((LLScrollListText*)itemp->getColumn(0))->setFontStyle(LLFontGL::BOLD);
00365                                 if (selected.isUndefined())
00366                                 {
00367                                         selected = itemp->getValue();
00368                                 }
00369                         }
00370                 }
00371         }
00372 
00373         communicate_button->setToggleState(gSavedSettings.getBOOL("ShowCommunicate"));
00374         communicate_button->setValue(selected);
00375 }
00376 
00377 
00378 // static
00379 void LLToolBar::onClickCommunicate(LLUICtrl* ctrl, void* user_data)
00380 {
00381         LLToolBar* toolbar = (LLToolBar*)user_data;
00382         LLFlyoutButton* communicate_button = toolbar->getChild<LLFlyoutButton>("communicate_btn");
00383         
00384         LLSD selected_option = communicate_button->getValue();
00385     
00386         if (selected_option.asString() == "contacts")
00387         {
00388                 LLFloaterMyFriends::showInstance();
00389         }
00390         else if (selected_option.asString() == "local chat")
00391         {
00392                 LLFloaterChat::showInstance();
00393         }
00394         else if (selected_option.asString() == "redock")
00395         {
00396                 LLFloaterChatterBox::getInstance()->addFloater(LLFloaterMyFriends::getInstance(), FALSE);
00397                 LLFloaterChatterBox::getInstance()->addFloater(LLFloaterChat::getInstance(), FALSE);
00398                 LLUUID session_to_show;
00399                 
00400                 std::set<LLHandle<LLFloater> >::const_iterator floater_handle_it;
00401                 for(floater_handle_it = gIMMgr->getIMFloaterHandles().begin(); floater_handle_it != gIMMgr->getIMFloaterHandles().end(); ++floater_handle_it)
00402                 {
00403                         LLFloater* im_floaterp = floater_handle_it->get();
00404                         if (im_floaterp)
00405                         {
00406                                 if (im_floaterp->isFrontmost())
00407                                 {
00408                                         session_to_show = ((LLFloaterIMPanel*)im_floaterp)->getSessionID();
00409                                 }
00410                                 LLFloaterChatterBox::getInstance()->addFloater(im_floaterp, FALSE);
00411                         }
00412                 }
00413 
00414                 LLFloaterChatterBox::showInstance(session_to_show);
00415         }
00416         else if (selected_option.asString() == "mute list")
00417         {
00418                 LLFloaterMute::showInstance();
00419         }
00420         else if (selected_option.isUndefined()) // user just clicked the communicate button, treat as toggle
00421         {
00422                 if (LLFloaterChatterBox::getInstance()->getFloaterCount() == 0)
00423                 {
00424                         LLFloaterMyFriends::toggleInstance();
00425                 }
00426                 else
00427                 {
00428                         LLFloaterChatterBox::toggleInstance();
00429                 }
00430         }
00431         else // otherwise selection_option is a specific IM session id
00432         {
00433                 LLFloaterChatterBox::showInstance(selected_option);
00434         }
00435 }
00436 
00437 
00438 // static
00439 void LLToolBar::onClickChat(void* user_data)
00440 {
00441         handle_chat(NULL);
00442 }
00443 
00444 // static
00445 void LLToolBar::onClickAppearance(void*)
00446 {
00447         if (gAgent.getWearablesLoaded())
00448         {
00449                 gAgent.changeCameraToCustomizeAvatar();
00450         }
00451 }
00452 
00453 
00454 // static
00455 void LLToolBar::onClickClothing(void*)
00456 {
00457         handle_clothing(NULL);
00458 }
00459 
00460 
00461 // static
00462 void LLToolBar::onClickFly(void*)
00463 {
00464         gAgent.toggleFlying();
00465 }
00466 
00467 
00468 // static
00469 void LLToolBar::onClickSit(void*)
00470 {
00471         if (!(gAgent.getControlFlags() & AGENT_CONTROL_SIT_ON_GROUND))
00472         {
00473                 // sit down
00474                 gAgent.setFlying(FALSE);
00475                 gAgent.setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
00476 
00477                 // Might be first sit
00478                 LLFirstUse::useSit();
00479         }
00480         else
00481         {
00482                 // stand up
00483                 gAgent.setFlying(FALSE);
00484                 gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
00485         }
00486 }
00487 
00488 
00489 // static
00490 void LLToolBar::onClickSnapshot(void*)
00491 {
00492         LLFloaterSnapshot::show (0);
00493 }
00494 
00495 
00496 // static
00497 void LLToolBar::onClickDirectory(void*)
00498 {
00499         handle_find(NULL);
00500 }
00501 
00502 
00503 // static
00504 void LLToolBar::onClickBuild(void*)
00505 {
00506         toggle_build_mode();
00507 }
00508 
00509 
00510 // static
00511 void LLToolBar::onClickRadar(void*)
00512 {
00513         handle_mini_map(NULL);
00514 }
00515 
00516 
00517 // static
00518 void LLToolBar::onClickMap(void*)
00519 {
00520         handle_map(NULL);
00521 }
00522 
00523 
00524 // static
00525 void LLToolBar::onClickInventory(void*)
00526 {
00527         handle_inventory(NULL);
00528 }
00529 

Generated on Fri May 16 08:34:05 2008 for SecondLife by  doxygen 1.5.5