1 // TipWindow.cpp 2 3 #include "TipWindow.h" 4 #include "TipView.h" 5 6 #include <Debug.h> 7 8 __USE_CORTEX_NAMESPACE 9 10 // -------------------------------------------------------- // 11 // *** dtor/ctors 12 // -------------------------------------------------------- // 13 14 TipWindow::~TipWindow() {} 15 TipWindow::TipWindow( 16 const char* text) : 17 BWindow( 18 BRect(0,0,0,0), 19 "TipWindow", 20 B_NO_BORDER_WINDOW_LOOK, 21 B_FLOATING_ALL_WINDOW_FEEL, 22 B_NOT_MOVABLE|B_AVOID_FOCUS/*, 23 B_ALL_WORKSPACES*/), 24 // the TipView is created on demand 25 m_tipView(0) { 26 27 if(text) 28 m_text = text; 29 } 30 31 32 // -------------------------------------------------------- // 33 // *** operations (LOCK REQUIRED) 34 // -------------------------------------------------------- // 35 36 const char* TipWindow::text() const { 37 return m_text.Length() ? 38 m_text.String() : 39 0; 40 } 41 42 void TipWindow::setText( 43 const char* text) { 44 45 if(!m_tipView) 46 _createTipView(); 47 48 m_text = text; 49 m_tipView->setText(text); 50 51 // size to fit view 52 float width, height; 53 m_tipView->GetPreferredSize(&width, &height); 54 m_tipView->ResizeTo(width, height); 55 ResizeTo(width, height); 56 57 m_tipView->Invalidate(); 58 } 59 60 // -------------------------------------------------------- // 61 // *** hooks 62 // -------------------------------------------------------- // 63 64 // override to substitute your own view class 65 TipView* TipWindow::createTipView() { 66 return new TipView; 67 } 68 69 // -------------------------------------------------------- // 70 // *** BWindow 71 // -------------------------------------------------------- // 72 73 // initializes the tip view 74 void TipWindow::Show() { 75 76 // initialize the tip view if necessary 77 if(!m_tipView) 78 _createTipView(); 79 80 _inherited::Show(); 81 } 82 83 // remove tip view? +++++ 84 void TipWindow::Hide() { 85 _inherited::Hide(); 86 } 87 88 89 // hides the window when the user switches workspaces 90 // +++++ should it be restored when the user switches back? 91 void TipWindow::WorkspaceActivated( 92 int32 workspace, 93 bool active) { 94 95 // don't confuse the user 96 if(!IsHidden()) 97 Hide(); 98 99 _inherited::WorkspaceActivated(workspace, active); 100 } 101 102 // -------------------------------------------------------- // 103 // implementation 104 // -------------------------------------------------------- // 105 106 void TipWindow::_createTipView() { 107 if(m_tipView) 108 _destroyTipView(); 109 m_tipView = createTipView(); 110 ASSERT(m_tipView); 111 112 AddChild(m_tipView); 113 114 if(m_text.Length()) 115 m_tipView->setText(m_text.String()); 116 else 117 m_tipView->setText("(no info)"); 118 } 119 120 void TipWindow::_destroyTipView() { 121 if(!m_tipView) 122 return; 123 RemoveChild(m_tipView); 124 delete m_tipView; 125 m_tipView = 0; 126 } 127 128 // END -- TipWindow.cpp -- 129