signs_gui.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "company_gui.h"
00014 #include "company_func.h"
00015 #include "signs_base.h"
00016 #include "signs_func.h"
00017 #include "debug.h"
00018 #include "command_func.h"
00019 #include "strings_func.h"
00020 #include "window_func.h"
00021 #include "map_func.h"
00022 #include "gfx_func.h"
00023 #include "viewport_func.h"
00024 #include "querystring_gui.h"
00025 #include "sortlist_type.h"
00026 #include "string_func.h"
00027 #include "core/geometry_func.hpp"
00028 #include "hotkeys.h"
00029 
00030 #include "table/strings.h"
00031 #include "table/sprites.h"
00032 
00038 struct FilterInfo {
00039   const char *string;  
00040   bool case_sensitive; 
00041 };
00042 
00043 struct SignList {
00048   typedef GUIList<const Sign *, FilterInfo> GUISignList;
00049 
00050   static const Sign *last_sign;
00051   GUISignList signs;
00052 
00053   char filter_string[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH]; 
00054   static bool match_case;                                           
00055 
00059   SignList()
00060   {
00061     filter_string[0] = '\0';
00062   }
00063 
00064   void BuildSignsList()
00065   {
00066     if (!this->signs.NeedRebuild()) return;
00067 
00068     DEBUG(misc, 3, "Building sign list");
00069 
00070     this->signs.Clear();
00071 
00072     const Sign *si;
00073     FOR_ALL_SIGNS(si) *this->signs.Append() = si;
00074 
00075     this->FilterSignList();
00076     this->signs.Compact();
00077     this->signs.RebuildDone();
00078   }
00079 
00081   static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
00082   {
00083     static char buf_cache[64];
00084     char buf[64];
00085 
00086     SetDParam(0, (*a)->index);
00087     GetString(buf, STR_SIGN_NAME, lastof(buf));
00088 
00089     if (*b != last_sign) {
00090       last_sign = *b;
00091       SetDParam(0, (*b)->index);
00092       GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache));
00093     }
00094 
00095     int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
00096 
00097     return r != 0 ? r : ((*a)->index - (*b)->index);
00098   }
00099 
00100   void SortSignsList()
00101   {
00102     if (!this->signs.Sort(&SignNameSorter)) return;
00103 
00104     /* Reset the name sorter sort cache */
00105     this->last_sign = NULL;
00106   }
00107 
00109   static bool CDECL SignNameFilter(const Sign * const *a, FilterInfo filter_info)
00110   {
00111     /* Get sign string */
00112     char buf1[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH];
00113     SetDParam(0, (*a)->index);
00114     GetString(buf1, STR_SIGN_NAME, lastof(buf1));
00115 
00116     return (filter_info.case_sensitive ? strstr(buf1, filter_info.string) : strcasestr(buf1, filter_info.string)) != NULL;
00117   }
00118 
00120   void FilterSignList()
00121   {
00122     FilterInfo filter_info = {this->filter_string, this->match_case};
00123     this->signs.Filter(&SignNameFilter, filter_info);
00124   }
00125 };
00126 
00127 const Sign *SignList::last_sign = NULL;
00128 bool SignList::match_case = false;
00129 
00131 enum SignListWidgets {
00132   SLW_CAPTION,
00133   SLW_LIST,
00134   SLW_SCROLLBAR,
00135   SLW_FILTER_TEXT,           
00136   SLW_FILTER_MATCH_CASE_BTN, 
00137   SLW_FILTER_CLEAR_BTN,      
00138 };
00139 
00141 enum SignListHotkeys {
00142   SLHK_FOCUS_FILTER_BOX, 
00143 };
00144 
00145 struct SignListWindow : QueryStringBaseWindow, SignList {
00146   int text_offset; 
00147   Scrollbar *vscroll;
00148 
00149   SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00150   {
00151     this->CreateNestedTree(desc);
00152     this->vscroll = this->GetScrollbar(SLW_SCROLLBAR);
00153     this->FinishInitNested(desc, window_number);
00154     this->SetWidgetLoweredState(SLW_FILTER_MATCH_CASE_BTN, SignList::match_case);
00155 
00156     /* Initialize the text edit widget */
00157     this->afilter = CS_ALPHANUMERAL;
00158     InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS);
00159     ClearFilterTextWidget();
00160 
00161     /* Initialize the filtering variables */
00162     this->SetFilterString("");
00163 
00164     /* Create initial list. */
00165     this->signs.ForceRebuild();
00166     this->signs.ForceResort();
00167     this->BuildSortSignList();
00168   }
00169 
00174   void ClearFilterTextWidget()
00175   {
00176     this->edit_str_buf[0] = '\0';
00177     UpdateTextBufferSize(&this->text);
00178 
00179     this->SetWidgetDirty(SLW_FILTER_TEXT);
00180   }
00181 
00188   void SetFilterString(const char *new_filter_string)
00189   {
00190     /* check if there is a new filter string */
00191     if (!StrEmpty(new_filter_string)) {
00192       /* Copy new filter string */
00193       strecpy(this->filter_string, new_filter_string, lastof(this->filter_string));
00194 
00195       this->signs.SetFilterState(true);
00196 
00197       this->EnableWidget(SLW_FILTER_CLEAR_BTN);
00198     } else {
00199       /* There is no new string -> clear this->filter_string */
00200       this->filter_string[0] = '\0';
00201 
00202       this->signs.SetFilterState(false);
00203       this->DisableWidget(SLW_FILTER_CLEAR_BTN);
00204     }
00205 
00206     /* Repaint the clear button since its disabled state may have changed */
00207     this->SetWidgetDirty(SLW_FILTER_CLEAR_BTN);
00208 
00209     /* Rebuild the list of signs */
00210     this->InvalidateData();
00211   }
00212 
00213   virtual void OnPaint()
00214   {
00215     if (this->signs.NeedRebuild()) this->BuildSortSignList();
00216     this->DrawWidgets();
00217     if (!this->IsShaded()) this->DrawEditBox(SLW_FILTER_TEXT);
00218   }
00219 
00220   virtual void DrawWidget(const Rect &r, int widget) const
00221   {
00222     switch (widget) {
00223       case SLW_LIST: {
00224         uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget.
00225         /* No signs? */
00226         if (this->vscroll->GetCount() == 0) {
00227           DrawString(r.left + WD_FRAMETEXT_LEFT, r.right, y, STR_STATION_LIST_NONE);
00228           return;
00229         }
00230 
00231         bool rtl = _current_text_dir == TD_RTL;
00232         int sprite_offset_y = (FONT_HEIGHT_NORMAL - 10) / 2 + 1;
00233         uint icon_left  = 4 + (rtl ? r.right - this->text_offset : r.left);
00234         uint text_left  = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
00235         uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
00236 
00237         /* At least one sign available. */
00238         for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
00239           const Sign *si = this->signs[i];
00240 
00241           if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, y + sprite_offset_y);
00242 
00243           SetDParam(0, si->index);
00244           DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
00245           y += this->resize.step_height;
00246         }
00247         break;
00248       }
00249     }
00250   }
00251 
00252   virtual void SetStringParameters(int widget) const
00253   {
00254     if (widget == SLW_CAPTION) SetDParam(0, this->vscroll->GetCount());
00255   }
00256 
00257   virtual void OnClick(Point pt, int widget, int click_count)
00258   {
00259     switch (widget) {
00260       case SLW_LIST: {
00261         uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SLW_LIST, WD_FRAMERECT_TOP);
00262         if (id_v == INT_MAX) return;
00263 
00264         const Sign *si = this->signs[id_v];
00265         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00266         break;
00267       }
00268       case SLW_FILTER_CLEAR_BTN:
00269         this->ClearFilterTextWidget(); // Empty the text in the EditBox widget
00270         this->SetFilterString("");     // Use empty text as filter text (= view all signs)
00271         break;
00272 
00273       case SLW_FILTER_MATCH_CASE_BTN:
00274         SignList::match_case = !SignList::match_case; // Toggle match case
00275         this->SetWidgetLoweredState(SLW_FILTER_MATCH_CASE_BTN, SignList::match_case); // Toggle button pushed state
00276         this->InvalidateData(); // Rebuild the list of signs
00277         break;
00278     }
00279   }
00280 
00281   virtual void OnResize()
00282   {
00283     this->vscroll->SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
00284   }
00285 
00286   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00287   {
00288     switch (widget) {
00289       case SLW_LIST: {
00290         Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
00291         this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
00292         resize->height = max<uint>(FONT_HEIGHT_NORMAL, spr_dim.height);
00293         Dimension d = {this->text_offset + WD_FRAMETEXT_RIGHT, WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
00294         *size = maxdim(*size, d);
00295         break;
00296       }
00297 
00298       case SLW_CAPTION:
00299         SetDParam(0, max<size_t>(1000, Sign::GetPoolSize()));
00300         *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
00301         size->height += padding.height;
00302         size->width  += padding.width;
00303         break;
00304     }
00305   }
00306 
00307   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00308   {
00309     EventState state = ES_NOT_HANDLED;
00310     switch (this->HandleEditBoxKey(SLW_FILTER_TEXT, key, keycode, state)) {
00311       case HEBR_EDITING:
00312         this->SetFilterString(this->text.buf);
00313         break;
00314 
00315       case HEBR_CONFIRM: // Enter pressed -> goto first sign in list
00316         if (this->signs.Length() >= 1) {
00317           const Sign *si = this->signs[0];
00318           ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00319         }
00320         return state;
00321 
00322       case HEBR_CANCEL: // ESC pressed, clear filter.
00323         this->OnClick(Point(), SLW_FILTER_CLEAR_BTN, 1); // Simulate click on clear button.
00324         this->UnfocusFocusedWidget();                    // Unfocus the text box.
00325         return state;
00326 
00327       case HEBR_NOT_FOCUSED: // The filter text box is not globaly focused.
00328         if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) {
00329           this->SetFocusedWidget(SLW_FILTER_TEXT);
00330           SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
00331           state = ES_HANDLED;
00332         }
00333         break;
00334 
00335       default:
00336         NOT_REACHED();
00337     }
00338 
00339     if (state == ES_HANDLED) OnOSKInput(SLW_FILTER_TEXT);
00340 
00341     return state;
00342   }
00343 
00344   virtual void OnOSKInput(int widget)
00345   {
00346     if (widget == SLW_FILTER_TEXT) this->SetFilterString(this->text.buf);
00347   }
00348 
00349   virtual void OnMouseLoop()
00350   {
00351     this->HandleEditBox(SLW_FILTER_TEXT);
00352   }
00353 
00354   void BuildSortSignList()
00355   {
00356     if (this->signs.NeedRebuild()) {
00357       this->BuildSignsList();
00358       this->vscroll->SetCount(this->signs.Length());
00359       this->SetWidgetDirty(SLW_CAPTION);
00360     }
00361     this->SortSignsList();
00362   }
00363 
00364   virtual void OnHundredthTick()
00365   {
00366     this->BuildSortSignList();
00367     this->SetDirty();
00368   }
00369 
00375   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00376   {
00377     /* When there is a filter string, we always need to rebuild the list even if
00378      * the amount of signs in total is unchanged, as the subset of signs that is
00379      * accepted by the filter might has changed. */
00380     if (data == 0 || !StrEmpty(this->filter_string)) { // New or deleted sign, or there is a filter string
00381       /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
00382       this->signs.ForceRebuild();
00383     } else { // Change of sign contents while there is no filter string
00384       this->signs.ForceResort();
00385     }
00386   }
00387 
00388   static Hotkey<SignListWindow> signlist_hotkeys[];
00389 };
00390 
00391 Hotkey<SignListWindow> SignListWindow::signlist_hotkeys[] = {
00392   Hotkey<SignListWindow>('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
00393   HOTKEY_LIST_END(SignListWindow)
00394 };
00395 Hotkey<SignListWindow> *_signlist_hotkeys = SignListWindow::signlist_hotkeys;
00396 
00397 static const NWidgetPart _nested_sign_list_widgets[] = {
00398   NWidget(NWID_HORIZONTAL),
00399     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00400     NWidget(WWT_CAPTION, COLOUR_GREY, SLW_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00401     NWidget(WWT_SHADEBOX, COLOUR_GREY),
00402     NWidget(WWT_STICKYBOX, COLOUR_GREY),
00403   EndContainer(),
00404   NWidget(NWID_HORIZONTAL),
00405     NWidget(NWID_VERTICAL),
00406       NWidget(WWT_PANEL, COLOUR_GREY, SLW_LIST), SetMinimalSize(WD_FRAMETEXT_LEFT + 16 + 255 + WD_FRAMETEXT_RIGHT, 50),
00407                 SetResize(1, 10), SetFill(1, 0), SetScrollbar(SLW_SCROLLBAR), EndContainer(),
00408       NWidget(NWID_HORIZONTAL),
00409         NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1),
00410           NWidget(WWT_EDITBOX, COLOUR_GREY, SLW_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
00411               SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
00412         EndContainer(),
00413         NWidget(WWT_TEXTBTN, COLOUR_GREY, SLW_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
00414         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SLW_FILTER_CLEAR_BTN), SetDataTip(STR_SIGN_LIST_CLEAR, STR_SIGN_LIST_CLEAR_TOOLTIP),
00415       EndContainer(),
00416     EndContainer(),
00417     NWidget(NWID_VERTICAL),
00418       NWidget(NWID_VERTICAL), SetFill(0, 1),
00419         NWidget(NWID_VSCROLLBAR, COLOUR_GREY, SLW_SCROLLBAR),
00420       EndContainer(),
00421       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00422     EndContainer(),
00423   EndContainer(),
00424 };
00425 
00426 static const WindowDesc _sign_list_desc(
00427   WDP_AUTO, 358, 138,
00428   WC_SIGN_LIST, WC_NONE,
00429   WDF_UNCLICK_BUTTONS,
00430   _nested_sign_list_widgets, lengthof(_nested_sign_list_widgets)
00431 );
00432 
00438 Window *ShowSignList()
00439 {
00440   return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
00441 }
00442 
00443 EventState SignListGlobalHotkeys(uint16 key, uint16 keycode)
00444 {
00445   int num = CheckHotkeyMatch<SignListWindow>(_signlist_hotkeys, keycode, NULL, true);
00446   if (num == -1) return ES_NOT_HANDLED;
00447   Window *w = ShowSignList();
00448   if (w == NULL) return ES_NOT_HANDLED;
00449   return w->OnKeyPress(key, keycode);
00450 }
00451 
00458 static bool RenameSign(SignID index, const char *text)
00459 {
00460   bool remove = StrEmpty(text);
00461   DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
00462   return remove;
00463 }
00464 
00466 enum QueryEditSignWidgets {
00467   QUERY_EDIT_SIGN_WIDGET_CAPTION,
00468   QUERY_EDIT_SIGN_WIDGET_TEXT,
00469   QUERY_EDIT_SIGN_WIDGET_OK,
00470   QUERY_EDIT_SIGN_WIDGET_CANCEL,
00471   QUERY_EDIT_SIGN_WIDGET_DELETE,
00472   QUERY_EDIT_SIGN_WIDGET_PREVIOUS,
00473   QUERY_EDIT_SIGN_WIDGET_NEXT,
00474 };
00475 
00476 struct SignWindow : QueryStringBaseWindow, SignList {
00477   SignID cur_sign;
00478 
00479   SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00480   {
00481     this->caption = STR_EDIT_SIGN_CAPTION;
00482     this->afilter = CS_ALPHANUMERAL;
00483 
00484     this->InitNested(desc);
00485 
00486     this->LowerWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
00487     UpdateSignEditWindow(si);
00488     this->SetFocusedWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
00489   }
00490 
00491   void UpdateSignEditWindow(const Sign *si)
00492   {
00493     char *last_of = &this->edit_str_buf[this->edit_str_size - 1]; // points to terminating '\0'
00494 
00495     /* Display an empty string when the sign hasnt been edited yet */
00496     if (si->name != NULL) {
00497       SetDParam(0, si->index);
00498       GetString(this->edit_str_buf, STR_SIGN_NAME, last_of);
00499     } else {
00500       GetString(this->edit_str_buf, STR_EMPTY, last_of);
00501     }
00502     *last_of = '\0';
00503 
00504     this->cur_sign = si->index;
00505     InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, this->max_chars);
00506 
00507     this->SetWidgetDirty(QUERY_EDIT_SIGN_WIDGET_TEXT);
00508     this->SetFocusedWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
00509   }
00510 
00516   const Sign *PrevNextSign(bool next)
00517   {
00518     /* Rebuild the sign list */
00519     this->signs.ForceRebuild();
00520     this->signs.NeedResort();
00521     this->BuildSignsList();
00522     this->SortSignsList();
00523 
00524     /* Search through the list for the current sign, excluding
00525      * - the first sign if we want the previous sign or
00526      * - the last sign if we want the next sign */
00527     uint end = this->signs.Length() - (next ? 1 : 0);
00528     for (uint i = next ? 0 : 1; i < end; i++) {
00529       if (this->cur_sign == this->signs[i]->index) {
00530         /* We've found the current sign, so return the sign before/after it */
00531         return this->signs[i + (next ? 1 : -1)];
00532       }
00533     }
00534     /* If we haven't found the current sign by now, return the last/first sign */
00535     return this->signs[next ? 0 : this->signs.Length() - 1];
00536   }
00537 
00538   virtual void SetStringParameters(int widget) const
00539   {
00540     switch (widget) {
00541       case QUERY_EDIT_SIGN_WIDGET_CAPTION:
00542         SetDParam(0, this->caption);
00543         break;
00544     }
00545   }
00546 
00547   virtual void OnPaint()
00548   {
00549     this->DrawWidgets();
00550     if (!this->IsShaded()) this->DrawEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
00551   }
00552 
00553   virtual void OnClick(Point pt, int widget, int click_count)
00554   {
00555     switch (widget) {
00556       case QUERY_EDIT_SIGN_WIDGET_PREVIOUS:
00557       case QUERY_EDIT_SIGN_WIDGET_NEXT: {
00558         const Sign *si = this->PrevNextSign(widget == QUERY_EDIT_SIGN_WIDGET_NEXT);
00559 
00560         /* Rebuild the sign list */
00561         this->signs.ForceRebuild();
00562         this->signs.NeedResort();
00563         this->BuildSignsList();
00564         this->SortSignsList();
00565 
00566         /* Scroll to sign and reopen window */
00567         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00568         UpdateSignEditWindow(si);
00569         break;
00570       }
00571 
00572       case QUERY_EDIT_SIGN_WIDGET_DELETE:
00573         /* Only need to set the buffer to null, the rest is handled as the OK button */
00574         RenameSign(this->cur_sign, "");
00575         /* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
00576         break;
00577 
00578       case QUERY_EDIT_SIGN_WIDGET_OK:
00579         if (RenameSign(this->cur_sign, this->text.buf)) break;
00580         /* FALL THROUGH */
00581 
00582       case QUERY_EDIT_SIGN_WIDGET_CANCEL:
00583         delete this;
00584         break;
00585     }
00586   }
00587 
00588   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00589   {
00590     EventState state = ES_NOT_HANDLED;
00591     switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, state)) {
00592       default: break;
00593 
00594       case HEBR_CONFIRM:
00595         if (RenameSign(this->cur_sign, this->text.buf)) break;
00596         /* FALL THROUGH */
00597 
00598       case HEBR_CANCEL: // close window, abandon changes
00599         delete this;
00600         break;
00601     }
00602     return state;
00603   }
00604 
00605   virtual void OnMouseLoop()
00606   {
00607     this->HandleEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
00608   }
00609 
00610   virtual void OnOpenOSKWindow(int wid)
00611   {
00612     ShowOnScreenKeyboard(this, wid, QUERY_EDIT_SIGN_WIDGET_CANCEL, QUERY_EDIT_SIGN_WIDGET_OK);
00613   }
00614 };
00615 
00616 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
00617   NWidget(NWID_HORIZONTAL),
00618     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00619     NWidget(WWT_CAPTION, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00620   EndContainer(),
00621   NWidget(WWT_PANEL, COLOUR_GREY),
00622     NWidget(WWT_EDITBOX, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_TEXT), SetMinimalSize(256, 12), SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL), SetPadding(2, 2, 2, 2),
00623   EndContainer(),
00624   NWidget(NWID_HORIZONTAL),
00625     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_OK), SetMinimalSize(61, 12), SetDataTip(STR_BUTTON_OK, STR_NULL),
00626     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_CANCEL), SetMinimalSize(60, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
00627     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_DELETE), SetMinimalSize(60, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_NULL),
00628     NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
00629     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_PREVIOUS), SetMinimalSize(11, 12), SetDataTip(AWV_DECREASE, STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP),
00630     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, QUERY_EDIT_SIGN_WIDGET_NEXT), SetMinimalSize(11, 12), SetDataTip(AWV_INCREASE, STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP),
00631   EndContainer(),
00632 };
00633 
00634 static const WindowDesc _query_sign_edit_desc(
00635   WDP_AUTO, 0, 0,
00636   WC_QUERY_STRING, WC_NONE,
00637   WDF_CONSTRUCTION | WDF_UNCLICK_BUTTONS,
00638   _nested_query_sign_edit_widgets, lengthof(_nested_query_sign_edit_widgets)
00639 );
00640 
00645 void HandleClickOnSign(const Sign *si)
00646 {
00647   if (_ctrl_pressed && si->owner == _local_company) {
00648     RenameSign(si->index, NULL);
00649     return;
00650   }
00651   ShowRenameSignWindow(si);
00652 }
00653 
00658 void ShowRenameSignWindow(const Sign *si)
00659 {
00660   /* Delete all other edit windows */
00661   DeleteWindowById(WC_QUERY_STRING, 0);
00662 
00663   new SignWindow(&_query_sign_edit_desc, si);
00664 }
00665 
00670 void DeleteRenameSignWindow(SignID sign)
00671 {
00672   SignWindow *w = dynamic_cast<SignWindow *>(FindWindowById(WC_QUERY_STRING, 0));
00673 
00674   if (w != NULL && w->cur_sign == sign) delete w;
00675 }

Generated on Sun Jun 5 04:20:03 2011 for OpenTTD by  doxygen 1.6.1