Ejemplo n.º 1
0
 /// <summary>
 /// Loop through the system tags looking for notebooks
 /// </summary>
 void NotebookManager::load_notebooks()
 {
   Gtk::TreeIter iter;
   std::list<Tag::Ptr> tags;
   ITagManager::obj().all_tags(tags);
   for(std::list<Tag::Ptr>::const_iterator tag_iter = tags.begin();
       tag_iter != tags.end(); ++tag_iter) {
     
     const Tag::Ptr & tag(*tag_iter);
     // Skip over tags that aren't notebooks
     if (!tag->is_system()
         || !Glib::str_has_prefix(tag->name(),
                                  std::string(Tag::SYSTEM_TAG_PREFIX)
                                  + Notebook::NOTEBOOK_TAG_PREFIX)) {
       continue;
     }
     Notebook::Ptr notebook(new Notebook(m_note_manager, tag));
     iter = m_notebooks->append ();
     iter->set_value(0, notebook);
     m_notebookMap [notebook->get_normalized_name()] = iter;
   }
 }
Ejemplo n.º 2
0
int main( int argc, char **argv )
{
	PG_Application app;
	
	app.LoadTheme( "default" );
	
	app.InitScreen( 640, 480, 0 );
	app.SetEmergencyQuit(true);
	
	PG_Label l( NULL, PG_Rect(10,50,250,25), NULL );
	l.Show();
	
	PG_TabBar bar( NULL, PG_Rect(10, 10, 300, 33) );
	bar.sigTabSelect.connect(slot(handleTab), &l);
	bar.Show();
	
	bar.AddTab("Tab1");
	bar.AddTab("Tab2");
	bar.AddTab("Tab3");
	bar.AddTab("MoreTab1");
	bar.AddTab("MoreTab2");
	bar.AddTab("MoreTab3");
	bar.AddTab("EvenLongerTab1");
	bar.AddTab("Tab4");
	
	PG_NoteBook notebook(NULL, PG_Rect(50, 100, 300, 200));
	
	notebook.sigPageSelect.connect(slot(handlePageSelect));
	
	PG_Button b(NULL, 1, PG_Rect(0,0,10,10), "Big fat button");
	b.sigButtonClick.connect(slot(handleBigFatButton));
	
	notebook.AddPage("button", &b, slot(handlePageButton));
	
	PG_Widget* custom = notebook.CreatePage("custom", slot(handlePageCustom));
	custom->SetID(2);
	PG_Label label(custom, PG_Rect(5,5,100,25), "My Page");
	PG_CheckButton check(custom, -1, PG_Rect(5,35,150,25), "Check me");
	
	PG_ListBox listpage(NULL, PG_Rect(0,0,300,100));
	listpage.AddItem(new PG_ListBoxItem(25, "Item1"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item2"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item3"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item4"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item5"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item6"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item7"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item8"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item9"));
	listpage.AddItem(new PG_ListBoxItem(25, "Item10"));
	listpage.SetID(3);
	
	notebook.AddPage("list", &listpage);

	PG_NoteBook subnotebook(NULL, PG_Rect(0,0,100,100));
	
	PG_Widget* complex = subnotebook.CreatePage("custom2");
	PG_Button b2(complex, -1, PG_Rect(10,10,100,25), "Button");
	
	subnotebook.AddPage("button2", new PG_Button(NULL, -1, 	PG_Rect(0,0,10,10), "Not so big button"));
	
	notebook.AddPage("complex", &subnotebook);
	
	notebook.Show();
	
	app.Run();
	
	return 0;
}
Ejemplo n.º 3
0
Controller::Controller(sf::Window &theWindow, sfg::Desktop &theDesktop, CallbackSystem &callbackSystem):
    desktop(theDesktop),
    boardWindow(sfg::Window::Create(sfg::Window::BACKGROUND)),
    settingsButton(sfg::Button::Create("Settings")),
    canvas(theWindow),
    m_whiteClock(Clock::Create()),
    m_blackClock(Clock::Create()),
    settingsWindow(desktop),
    premove({{0,0},{0,0}}), premoveOn(false),
    netWindow(m_currentEvent),
    player1(sfg::Label::Create()),
    player2(sfg::Label::Create())
{
    boardWindow->SetRequisition(static_cast<sf::Vector2f>(theWindow.getSize()));

    canvas.requestMove.connect(boost::bind(&Controller::requestMove, this,_1));
    settingsWindow.settingsDone.connect([this](const PieceToTexPos& pieceToTexPos){
        settingsWindow.enable(false);
        canvas.setPieceColors(pieceToTexPos);
    });
    messages.connect(Messages::ID::TextReady, [this](const Messages::Message& message){
        auto received = boost::polymorphic_downcast<const Messages::TextReady*>(&message);
        netWindow.addLine(received->text);
    });

    ButtonBox buttons;
    buttons.flip->GetSignal(sfg::Button::OnLeftClick).Connect(std::bind(&Canvas::flipBoard, &canvas));
    buttons.settings->GetSignal(sfg::Button::OnLeftClick).Connect([]{
        //settingsWindow.enable(true);
    });
    buttons.resign->GetSignal(sfg::Button::OnLeftClick).Connect([this]{
        messages.triggerEvent(Messages::TextToClient("resign"));
    });
    buttons.draw->GetSignal(sfg::Button::OnLeftClick).Connect([this]{
        messages.triggerEvent(Messages::TextToClient("draw"));
    });

    auto promotionLayout = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
    auto promotionGroup = sfg::RadioButtonGroup::Create();

    auto createPromotionButton = [this, promotionGroup, promotionLayout](const std::string& name, char letter){
        auto promotionButton = sfg::RadioButton::Create(name, promotionGroup);
        promotionLayout->Pack(promotionButton);
        promotionButton->GetSignal(sfg::ToggleButton::OnToggle).Connect([this, promotionButton, letter]{
            if (promotionButton->IsActive()){
                std::string promote("promote ");
                promote += letter;
                messages.triggerEvent(Messages::TextToClient(promote));
            }
        });
        return promotionButton;
    };

    auto promotionQueen = createPromotionButton("Queen", 'q');
    createPromotionButton("Bishop", 'b');
    createPromotionButton("Knight", 'n');
    createPromotionButton("Rook", 'r');

    auto promotionFrame = sfg::Frame::Create("Promotion");
    promotionFrame->Add(promotionLayout);

    auto sideLayout = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);

    sideLayout->Pack(player1);
    sideLayout->Pack(m_whiteClock);
    sideLayout->Pack(player2);
    sideLayout->Pack(m_blackClock);
    sideLayout->Pack(status.getView());

    sfg::Table::Ptr mainLayout(sfg::Table::Create());
    mainLayout->SetRowSpacings(2.f);
    mainLayout->SetColumnSpacings(2.f);
    mainLayout->Attach(canvas.getBoardWidget(),{0, 0, 3, 2},sfg::Table::EXPAND, sfg::Table::EXPAND, sf::Vector2f( 10.f, 0.f ));
    mainLayout->Attach(promotionFrame, {0, 2, 1, 1});
    mainLayout->Attach(sideLayout, {3,0, 3, 1});
    mainLayout->Attach(moveList.getView(),{3, 1, 3, 3});
    mainLayout->Attach(buttons.layout,{0,4,6,1});

    desktop.Add(settingsWindow.getWidget());

    sfg::Notebook::Ptr notebook(sfg::Notebook::Create());
    notebook->AppendPage(mainLayout,sfg::Label::Create("Board"));
    notebook->AppendPage(netWindow.getWidget(),sfg::Label::Create("Server"));
    notebook->GetSignal(sfg::Notebook::OnTabChange).Connect([this]{
        netWindow.grabEntryFocus();
    });

    callbackSystem.connect(Action::Tab, [notebook](thor::ActionContext<Action> context){
        if (context.event->key.control){
            if (context.event->key.shift)
                notebook->PreviousPage();
            else
                notebook->NextPage();
        }
    });

    boardWindow->Add(notebook);

    desktop.Add(boardWindow);

    buttons.connect->GetSignal(sfg::Button::OnLeftClick).Connect([this, notebook]{
        client.connect();
        notebook->SetCurrentPage(1);
    });

    messages.connect(Messages::ID::GameState, [this](const Messages::Message& message){
        auto received = boost::polymorphic_downcast<const Messages::GameState*>(&message);
        m_whiteClock->setTimeLeft(received->white_time);
        m_blackClock->setTimeLeft(received->black_time);
        if (received->turnColor == Color::White){
            m_blackClock->stop();
            m_whiteClock->start();
        }else{
            assert(received->turnColor==Color::Black);
            m_whiteClock->stop();
            m_blackClock->start();
        }


        if (premoveOn)
        {
            premoveOn = false;
            canvas.clearArrows();
            requestMove(premove);
        }
    });

    messages.connect(Messages::ID::GameStart, [this, promotionQueen, notebook](const Messages::Message& message){
        auto received = boost::polymorphic_downcast<const Messages::GameStart*>(&message);
        player1->SetText(received->p1);
        player2->SetText(received->p2);
        premoveOn = false;
        promotionQueen->SetActive(true);
        updateClocks();
        notebook->SetCurrentPage(0);
    });

    messages.connect(Messages::ID::GameEnd, [this](const Messages::Message&){
        //auto received = boost::polymorphic_downcast<const EndGameMessage*>(&message);
        premoveOn = false;
        canvas.clearArrows();
        m_whiteClock->stop();
        m_blackClock->stop();
    });

    callbackSystem.connect(Action::Scroll, [this](thor::ActionContext<Action> context){
        int delta = context.event->mouseWheelScroll.delta;
        netWindow.scroll(delta);
    });
}
/*------------------------------------------------------------------------------
| Dialog::createControlsFromTemplate                                           |
------------------------------------------------------------------------------*/
Dialog& Dialog :: createControlsFromTemplate( )
{
  PDLGTEMPLATE pdlgt;                /* Dialog Template Pointer         */
  void*        pvStart;              /* Dialog Template Item Pointer    */
  register unsigned long cItems,     /* Dialog Items Counter            */
                         ulRc,       /* Return code                     */
                         i;          /* Loop Counter                    */

                       /* Set mouse pointer to "wait" in case template  */
                       /* is large                                      */
  IPointerHandle oldPointer = mousePointer();
  ISystemPointerHandle systemPointer( ISystemPointerHandle::wait );
  setMousePointer( systemPointer );

                       /* Try reading in the dialog template for the    */
                       /* given dialog ID                               */
  ulRc = DosGetResource( 0, RT_DIALOG, this->ulId, (void **)&pdlgt );
  if ( ulRc != 0 )
  {
                       /* Dialog template not found;  reset mouse       */
                       /* pointer and throw exception                   */
    setMousePointer( oldPointer );
    ITHROWSYSTEMERROR( ulRc,
                       "DosGetResource",
                       IErrorInfo::accessError,
                       IException::recoverable );
  }
                       /* Save pointer to the start of the dlg template */
  pvStart = (void *)pdlgt;

                       /* Save the number of controls found within the  */
                       /* dialog template                               */
  cItems = pdlgt->adlgti[0].cChildren + 1;

                       /* Read in and create an Open Class Library C++  */
                       /* object for each of the controls within the    */
                       /* dialog template                               */
  for ( i = 1; i < cItems; i++ )
  {
                       /* Obtain the id of the control                  */
    unsigned long ulId = (unsigned long)(pdlgt->adlgti[i].id & 0xffff);

                       /* Skip the control if its id is -1              */
    if ( ulId != 0xffff )
    {
                       /* Check to see if a custom control is specified */
                       /* or if a standard PM control class is being    */
                       /* used                                          */
      if ( pdlgt->adlgti[i].cchClassName )
      {
                       /* Since a length for the class name present,    */
                       /* a custom control class name is being used for */
                       /* the control.  Point to the memory location    */
                       /* where the class name is found within the      */
                       /* dialog template information.                  */
        customControl( ulId,
                       ((char *)pvStart + pdlgt->adlgti[i].offClassName) );
      }
      else
      {
                       /* No class name length given indicating that a  */
                       /* standard PM class is being used.  The class   */
                       /* name is stored as an index value.  For        */
                       /* example, the class for static's is defined as */
                       /*                                               */
                       /* #define WC_STATIC ((PSZ)0xffff0005L)          */
                       /*                                               */
                       /* The values within the dialog template for     */
                       /* the static class would be                     */
                       /*                                               */
                       /* adlgti[i].cchClassName = 0                    */
                       /* adlgti[i].offClassName = 5                    */
                       /*                                               */
                       /* Therefore, the value of offClassName field    */
                       /* must be used as an index that is used to      */
                       /* actually select the class name.               */

        switch ( pdlgt->adlgti[i].offClassName )
        {
          case WINCLASS_BUTTON :
            {
              unsigned long ulStyle = pdlgt->adlgti[i].flStyle &
                                      BS_PRIMARYSTYLES;

              switch ( ulStyle )
              {
                case BS_PUSHBUTTON:
                  {
                    if ( pdlgt->adlgti[i].flStyle & (BS_BITMAP | BS_ICON) )
                    {
                      IGraphicPushButton*
                        pGraphicPushButton = new IGraphicPushButton( ulId,
                                                                     this );
                      pGraphicPushButton->setAutoDeleteObject( true );
                      graphicPushButton( pGraphicPushButton );
                    }
                    else
                    {
                      IPushButton*
                        pPushButton = new IPushButton( ulId, this );
                      pPushButton->setAutoDeleteObject( true );
                      this->pushButton( pPushButton );
                    }
                  }
                  break;

                case BS_CHECKBOX:
                case BS_AUTOCHECKBOX:
                  {
                    ICheckBox*
                      pCheckBox = new ICheckBox( ulId, this );
                    pCheckBox->setAutoDeleteObject( true );
                    checkBox( pCheckBox );
                  }
                  break;

                case BS_RADIOBUTTON:
                case BS_AUTORADIOBUTTON:
                  {
                    IRadioButton*
                      pRadioButton = new IRadioButton( ulId, this );
                    pRadioButton->setAutoDeleteObject( true );
                    radioButton( pRadioButton );
                  }
                  break;

                case BS_3STATE:
                case BS_AUTO3STATE:
                  {
                    I3StateCheckBox*
                      p3StateCheckBox = new I3StateCheckBox( ulId, this );
                    p3StateCheckBox->setAutoDeleteObject( true );
                    threeStateCheckBox( p3StateCheckBox );
                  }
                  break;

                case BS_USERBUTTON:
                  {
                    customButton( ulId );
                  }
                  break;
              } //end switch

            } //WINCLASS_BUTTON
            break;

          case WINCLASS_SCROLLBAR :
            {
              IScrollBar*
                pScrollBar = new IScrollBar( ulId, this );
              pScrollBar->setAutoDeleteObject( true );
              scrollBar( pScrollBar );
            }
            break;

          case WINCLASS_LISTBOX :
            {
              IListBox*
                pListBox = new IListBox( ulId, this );
              pListBox->setAutoDeleteObject( true );
              listBox( pListBox );
            }
            break;

          case WINCLASS_ENTRYFIELD :
            {
              IEntryField*
                pEntryField = new IEntryField( ulId, this );
              pEntryField->setAutoDeleteObject( true );
              entryField( pEntryField );
            }
            break;

          case WINCLASS_STATIC :
            {
              unsigned long ulStyle = pdlgt->adlgti[i].flStyle &
                                (SS_TEXT | SS_GROUPBOX | SS_ICON | SS_BITMAP);

              switch ( ulStyle )
              {
                case SS_TEXT:
                  {
                    IStaticText*
                      pStaticText = new IStaticText( ulId, this );
                    pStaticText->setAutoDeleteObject( true );
                    staticText( pStaticText );
                  }
                  break;

                case SS_GROUPBOX:
                  {
                    IGroupBox*
                      pGroupBox = new IGroupBox( ulId, this );
                    pGroupBox->setAutoDeleteObject( true );
                    groupBox( pGroupBox );
                  }
                  break;

                case SS_ICON:
                  {
                    IIconControl*
                      pIcon = new IIconControl( ulId, this );
                    pIcon->setAutoDeleteObject( true );
                    iconControl( pIcon );
                  }
                  break;

                case SS_BITMAP:
                  {
                    IBitmapControl*
                      pBitmap = new IBitmapControl( ulId, this );
                    pBitmap->setAutoDeleteObject( true );
                    bitmapControl( pBitmap );
                  }
                  break;
              } //end switch

            } //WINCLASS_STATIC
            break;

          case WINCLASS_COMBOBOX :
            {
              IComboBox*
                pComboBox = new IComboBox( ulId, this );
              pComboBox->setAutoDeleteObject( true );
              comboBox( pComboBox );
            }
            break;

          case WINCLASS_MLE :
            {
              IMultiLineEdit*
                pMLE = new IMultiLineEdit( ulId, this );
              pMLE->setAutoDeleteObject( true );
              mle( pMLE );
            }
            break;

          case WINCLASS_SPINBUTTON :
            {
              if ( pdlgt->adlgti[i].flStyle & SPBS_NUMERICONLY )
              {
                INumericSpinButton*
                  pNumericSpinButton = new INumericSpinButton( ulId, this );
                pNumericSpinButton->setAutoDeleteObject( true );
                numericSpinButton( pNumericSpinButton );
              }
              else
              {
                ITextSpinButton*
                  pTextSpinButton = new ITextSpinButton( ulId, this );
                pTextSpinButton->setAutoDeleteObject( true );
                textSpinButton( pTextSpinButton );
              }
            }
            break;

          case WINCLASS_CONTAINER :
            {
              IContainerControl*
                pContainer = new IContainerControl( ulId, this );
              pContainer->setAutoDeleteObject( true );
              container( pContainer );
            }
            break;

          case WINCLASS_SLIDER :
            {
              if ( pdlgt->adlgti[i].flStyle & SLS_READONLY )
              {
                IProgressIndicator*
                  pProgressIndicator = new IProgressIndicator( ulId, this );
                pProgressIndicator->setAutoDeleteObject( true );
                progressIndicator( pProgressIndicator );
              }
              else
              {
                ISlider*
                  pSlider = new ISlider( ulId, this );
                pSlider->setAutoDeleteObject( true );
                slider( pSlider );
              }
            }
            break;

          case WINCLASS_VALUESET :
            //No valueset class - see OS/2 C++ Class Library Power GUI
            //Programming with C Set++ for an implementation of a
            //valueset class.
            break;

          case WINCLASS_NOTEBOOK :
            {
              INotebook*
                pNotebook = new INotebook( ulId, this );
              pNotebook->setAutoDeleteObject( true );
              notebook( pNotebook );
            }
            break;

          case WINCLASS_CIRCULARSLIDER :
            {
              ICircularSlider*
                pCircularSlider = new ICircularSlider( ulId, this );
              pCircularSlider->setAutoDeleteObject( true );
              circularSlider( pCircularSlider );
            }
            break;
        } //end switch
      } //end if
    } //end if - id != -1

  } //end for
                       /* Release the memory allocated for the dlg      */
                       /* template before returning                     */
  DosFreeResource( pvStart );
                       /* Reset mouse pointer                           */
  setMousePointer( oldPointer );
  return( *this );
} //Dialog::createControlsFromTemplate